CurrencyConvBinding
===================

* :download:`Download example <PyObjCExample-CurrencyConvBinding.zip>`

A PyObjC Example without documentation

.. rst-class:: tabber

Sources
-------

.. rst-class:: tabbertab

Converter.py
............

.. sourcecode:: python

    import objc
    from Foundation import NSObject
    from objc import super  # noqa: A004
    
    
    class Converter(NSObject):
        exchangeRate = objc.ivar.double()
        dollarsToConvert = objc.ivar.double()
    
        def init(self):
            self = super().init()
            self.exchangeRate = 3
            self.dollarsToConvert = 4
            return self
    
        def amountInOtherCurrency(self):
            return self.dollarsToConvert * self.exchangeRate
    
    
    Converter.setKeys_triggerChangeNotificationsForDependentKey_(
        ["dollarsToConvert", "exchangeRate"], "amountInOtherCurrency"
    )

.. rst-class:: tabbertab

CurrencyConvBinding.py
......................

.. sourcecode:: python

    # import classes required to start application
    import Converter  # noqa: F401
    import CurrencyConvBindingDocument  # noqa: F401
    from PyObjCTools import AppHelper
    
    if __name__ == "__main__":
        AppHelper.runEventLoop()

.. rst-class:: tabbertab

CurrencyConvBindingDocument.py
..............................

.. sourcecode:: python

    from Cocoa import NSDocument
    
    
    class CurrencyConvBindingDocument(NSDocument):
        def windowNibName(self):
            return "CurrencyConvBindingDocument"

.. rst-class:: tabbertab

setup.py
........

.. sourcecode:: python

    """
    Script for building the example:
    
    Usage:
        python3 setup.py py2app
    """
    
    from setuptools import setup
    
    plist = {
        "CFBundleDocumentTypes": [
            {
                "CFBundleTypeExtensions": ["CurrencyConvBinding", "*"],
                "CFBundleTypeName": "CurrencyConvBinding File",
                "CFBundleTypeRole": "Editor",
                "NSDocumentClass": "CurrencyConvBindingDocument",
            }
        ]
    }
    
    setup(
        name="CurrencyConvBinding",
        app=["CurrencyConvBinding.py"],
        data_files=["English.lproj"],
        options={"py2app": {"plist": plist}},
        setup_requires=["py2app", "pyobjc-framework-Cocoa"],
    )

