PyObjC: Difference between revisions
mNo edit summary |
→History and Contributors: The contributor's list is nearly all red. Not very appealing and it makes the page look incomplete. Also fixed some grammar issues. |
||
Line 28: | Line 28: | ||
Cocoa developers may also benefit, as tasks written in Python generally take fewer lines than the Objective-C equivalent. This can be used to their advantage as it enables faster prototyping. |
Cocoa developers may also benefit, as tasks written in Python generally take fewer lines than the Objective-C equivalent. This can be used to their advantage as it enables faster prototyping. |
||
==History |
==History== |
||
PyObjC's origins date back to 1996, when Lele Gaifax built the original module in September of that year. Among the credited contributors were Guido van Rossum, creator of the Python programming language. |
|||
The history of PyObjC before 2000 is quite fuzzy and here are some parts referenced from different sites: |
|||
PyObjC was rewritten in 2002. Notable additions include the ability to directly subclass Objective-C classes from Python and nearly complete support for the Foundation, App Kit and Address Book frameworks. |
|||
The “objc” module has been found as part of the 1.3 release of Python (released in 1995), claimed to be written by [[Jon M. Kutemeier]] and maintained by [[Guido van Rossum]]. But later been removed from core since the 1.4 release. |
|||
Later the same year, support was added for non-framework Python builds, as well as subsequent support for the Python distribution included with OS X. Along with these changes came project templates for standalone Cocoa applications for use with [[Project_Builder|Project Builder]], the predecessor to the current Apple platform [[Integrated_development_environment|IDE]], [[Xcode]]. |
|||
[[Lele Gaifax]] built the original module of PyObjC in September 1996. And Lele’s contributors list can be found in official website [http://pyobjc.sourceforge.net/people.html here]. |
|||
Apple incorporated PyObjC into OS X in 2007, with the release of [[Mac_OS_X_Leopard |Mac OS X 10.5 Leopard]]. |
|||
[[Steve Majewski]] and [[Bill Bumgarner]] started to handle this work since 2000. And since PyObjC is maintain and developed by [[Ronald Oussoren]], Bill Bumgarner, Just van Rossum, and Jack Jansen. |
|||
Apple started to support PyObjC since [[Mac OS X 10.4 Tiger]], and PyObjC 2.0 was shipped as component of [[Mac OS X 10.5 Leopard]] by Apple. |
|||
As to the integrated development environment support, [[Xcode]] 2.5 provided templates and is fully supported with PyObjC. Templates had been removed since Xcode 3.0, but Xcode 3.0 is still providing support to Python, therefore the [[Interface Builder]], which is shipped with Xcode 3.0, understands Python scripts and syntax. |
|||
According to Ronald Oussoren, Interface Builder since Xcode 4.0 is no longer compatible with PyObjC anymore. |
|||
==Principle Behind Bridge== |
==Principle Behind Bridge== |
Revision as of 22:52, 26 September 2012
Developer(s) | Ronald Oussoren, Bill Bumgarner, Steve Majewski, Lele Gaifax, et al. |
---|---|
Stable release | 2.3.2a (as part of OS X 10.8)
/ July 25, 2012 |
Repository | |
Written in | Python |
Operating system | Cross-platform |
License | MIT License |
Website | http://pyobjc.sourceforge.net/ |
PyObjC is a bidirectional bridge between the Python and Objective-C programming languages, allowing programmers to use and extend existing Objective-C libraries, such as Apple's Cocoa framework, using Python.
PyObjC is used to develop OS X applications in pure Python.
There is also limited support for GNUstep, an open source, cross-platform implementation of Cocoa.
For Python Programmers
The most important usage of PyObjC is enabling programmers to create GUI applications using Cocoa libraries in pure Python. Moreover, as an effect of Objective-C's close relationship with the C programming language (it is a pure superset), developers are also able incorporate any C-based API by wrapping it with an Objective-C wrapper and then using the wrapped code over the PyObjC bridge. Using Objective-C++, the same can be done with C++ libraries.
For Objective-C Programmers
Cocoa developers may also benefit, as tasks written in Python generally take fewer lines than the Objective-C equivalent. This can be used to their advantage as it enables faster prototyping.
History
PyObjC's origins date back to 1996, when Lele Gaifax built the original module in September of that year. Among the credited contributors were Guido van Rossum, creator of the Python programming language.
PyObjC was rewritten in 2002. Notable additions include the ability to directly subclass Objective-C classes from Python and nearly complete support for the Foundation, App Kit and Address Book frameworks.
Later the same year, support was added for non-framework Python builds, as well as subsequent support for the Python distribution included with OS X. Along with these changes came project templates for standalone Cocoa applications for use with Project Builder, the predecessor to the current Apple platform IDE, Xcode.
Apple incorporated PyObjC into OS X in 2007, with the release of Mac OS X 10.5 Leopard.
Principle Behind Bridge
The implementation of bridging between Python and Objective-C is by BridgeSupport and libffi. The core concept of connection is based on that Objective-C uses messages for communication between its objects. And PyObjC provides translation from these messages to Python methods by replacing the colons with underscores. Following is the sample for translation.
Messages and Methods
For the syntax conversion, simply change the colons from original Objective-C code to underscores. Such like following examples:
[myLittleDuck makeSomeNoise:quack]
the above code should be changed like following
myLittleDuck.makeSomeNoise_(quack)
And for more than one parameter messages, one can follow the same principle:
[myLittleDuck flyToward:east flyWithSpeed:10]
should be converted as:
myLittleDuck.flyToward_flyWithSpeed_(east,10)
Classes
The classes of Objective-C could be simply subclassed like normal Python classes. following can be referenced as example of class initiation:
class MyDuck(NSObject):
def init(self):
self = super(MyDuck, self).init()
#ALWAYS call initializer from super class
return self
#Unlike Python, one can even return any other object in initializer.
MyLittleDuckOne = MyDuck.alloc().init()
External links