Formatter
=========

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

A PyObjC Example without documentation

.. rst-class:: tabber

Sources
-------

.. rst-class:: tabbertab

main.py
.......

.. sourcecode:: python

    from AppKit import NSFormatter, NSString
    from PyObjCTools import AppHelper
    
    try:
        unicode
    except NameError:
        unicode = str
    
    
    class MyFormatter(NSFormatter):
        def stringForObjectValue_(self, product):
            if isinstance(product, (str, unicode)):
                return product
            return str(product)
    
        def getObjectValue_forString_errorDescription_(self, value, upc, error):
            print(self, upc)
    
            if not upc:
                print("No data")
                return True, None, None
    
            print("Have data")
            return False, None, NSString.stringWithString_("Foo the {}".format("bar"))
    
    
    AppHelper.runEventLoop()

.. rst-class:: tabbertab

setup.py
........

.. sourcecode:: python

    """
    Script for building the example.
    
    Usage:
        python3 setup.py py2app
    """
    from setuptools import setup
    
    setup(
        name="Formatter",
        app=["main.py"],
        data_files=["MainMenu.nib"],
        setup_requires=["py2app", "pyobjc-framework-Cocoa"],
    )

