Intro to PyObjC (Bob Ippolito).notes

Wednesday, March 23, 2005

TITLE OF PAPER: Introduction to PyObjC
URL OF PRESENTATION: http://bob.pythonmac.org/
PRESENTED BY: Bob Ippolito
REPRESENTING: _name_of_the_company_they_represent_

CONFERENCE: PyCon 2005
DATE: 23 March 2005
LOCATION: 307

--------------------------------------------------------------------------
REAL-TIME NOTES / ANNOTATIONS OF THE PAPER:
{If you've contributed, add your name, e-mail & URL at the bottom}

Installing PyObjC
    Install XCode
    Install PyObjC <http://pyobjc.sf.net/>

Why bother?
    The tools kick ass
    Python and Objective-C work together well
    The tools kick ass

Objective C
    Superset of C
    Flat Namespace (no modules)
        Leads to prefixes e.g. NSBlah
    Classes only support single inheritance, can be worked around via categories and protocols
    Classes are first-class objects
    Instances have instance variables; no class variables
    Interfaces (similar to header files in C)
    You have accessors for every instance variable
        (implements key-value coding)
    Two-phase object creation
        First you allocate the object
        Second you initialize the contents
        In ObjC you need to return self, since you're coding more of a __new__ than an __init__ method
    Everything is an accessor except when using key-value coding
    Objects are reference-counted
    Usually it's automatic
    Messages
        Have a target
            Can be nil, which will always return nil
        Have a selector (mixed with the arguments)
        Have arguments
    Exceptions are truly exceptional
        Typically you return error values
        Expect bad code to crash (even if the bad code is written in Python)

Crossing the Python/Objective C bridge
    Unicode, int, long, float all work magically
    str is not safely bridged since all ObjC strings are Unicode
    None is just like nil (except you can't send messages to it)
    @"..." in ObjC is like u'...' in Python, except you can't have non-ASCII in ObjC source code; should use .strings files for localization
    Translating messages
        Replace colons with underscores
        Arguments are passed as in Objective C
    Key-Value coding is like Python's getattr and properties combined
        you can say valueForKey: @"foo" which will access things like a 'foo' instance variable, or a '- foo' method, or ... (the lookup order is documented, see Apple's docs)
        can use valueForKeyPath: @"foo.bar" which will do hierarchical lookups, can do neat stuff with arrays

Interface builder
    Design your interface using a great tool
    You don't write much code.
    You actually manipulate serialized objects, not a textual description of objects.  This is an important distinction from other systems (e.g. Glade)

[Example: Currency converter]
    Drag out text fields
    Set types for contents of fields
    Data driven binding of "model" to "views"
    Don't really subclass things; we delegate to another object
        This is preferable to / instead of multiple inheritance
    Subclass NSObject -- this creates an actual Objective C class
        This means your class names need to be unique - single global namespace
        Write the init() method (Objective C initialization method, must return self)
        Write the accessor functions using the ObjC naming convention
    Run an event loop to make everything go: AppHelper.runEventLoop()
    Run a script to make the app directory with all your stuff in it
        Example uses py2app, which makes things really easy
        Build using setup.py like any distutils project
            need to supply py2app argument

Some applications that already use PyObjC
    ReSTedit
    Flame - Rendezvous browser
    NodeBox - Generate a quick (vector) PDF based on your Python code

--------------------------------------------------------------------------
REFERENCES: {as documents / sites are referenced add them below}


--------------------------------------------------------------------------
QUOTES:



--------------------------------------------------------------------------
CONTRIBUTORS: {add your name, e-mail address and URL below}
Ted Leung <twl@sauria.com>
Abhay Saxena <ark3@email.com>
Nicholas Riley <nriley@sabi.net>


--------------------------------------------------------------------------
E-MAIL BOUNCEBACK: {add your e-mail address separated by commas }


--------------------------------------------------------------------------
NOTES ON / KEY TO THIS TEMPLATE:
A headline (like a field in a database) will be CAPITALISED
    This differentiates from the text that follows
A variable that you can change will be surrounded by _underscores_
    Spaces in variables are also replaced with under_scores
    This allows people to select the whole variable with a simple double-click
A tool-tip is lower case and surrounded by {curly brackets / parentheses}
    These supply helpful contextual information.

--------------------------------------------------------------------------
Copyright shared between all the participants unless otherwise stated...