Jump to content

PyObjC: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
NSCoder (talk | contribs)
m Classes: Minor clarification.
See also: Adding wikilink
 
(39 intermediate revisions by 22 users not shown)
Line 1: Line 1:
{{More citations needed|date=November 2014}}
{{ Infobox Software
{{Infobox software
| logo =
| logo =
| screenshot =
| screenshot =
| caption = The Python <-> Objective-C Bridge
| caption = The Python <-> Objective-C Bridge
| developer = Ronald Oussoren, Bill Bumgarner, Steve Majewski, Lele Gaifax, et al.
| author = Lele Gaifax
| developer = Ronald Oussoren, Bill Bumgarner, Steve Majewski, et al.
| released = {{Start date and age|1996|09}}
| latest release version = 2.3.2a (as part of OS X 10.8)
| latest release date = July 25, 2012
| latest release version = 5.2
| latest release date = {{Start date and age|2019|04|03}}<ref>{{cite web |title=pyobjc |url=https://pypi.python.org/pypi/pyobjc |website=[[Python Package Index]] |accessdate=2019-04-21}}</ref>
| latest preview version =
| latest preview version =
| latest preview date =
| latest preview date =
Line 11: Line 14:
| programming language = [[Python (programming language)|Python]]
| programming language = [[Python (programming language)|Python]]
| genre =
| genre =
| license = [http://pyobjc.sourceforge.net/license.html MIT License]
| license = [[MIT License]]
| website = http://pyobjc.sourceforge.net/
| website = {{URL|https://pyobjc.readthedocs.io/en/latest/}}
}}
}}
'''PyObjC''' is a bidirectional bridge between the [[Python (programming language)|Python]] and [[Objective-C]] programming languages, allowing programmers to use and extend existing Objective-C [[library (computer science)|libraries]], such as [[Apple Inc.|Apple]]'s [[Cocoa (API)|Cocoa]] [[Application framework|framework]], using Python.
{{Portal|Free software}}


PyObjC is used to develop [[macOS]] applications in pure Python.
'''PyObjC''' is a bidirectional bridge between the [[Python (programming language)|Python]] and [[Objective-C]] programming languages, allowing programmers to use and extend existing Objective-C [[library (computer science)|libraries]], such as [[Apple_Inc.|Apple]]'s [[Cocoa_(API)|Cocoa]] [[Application_framework|framework]], using Python.


There is also limited support for [[GNUstep]], an open source, cross-platform [[Implementation#Computer Science|implementation]] of Cocoa.
PyObjC is used to develop [[OS X]] applications in pure Python.


==For Python programmers==
There is also limited support for [[GNUstep]], an open source, cross-platform [[Implementation#Computer_Science|implementation]] of Cocoa.
The most important usage of PyObjC is enabling programmers to create [[GUI]] applications using Cocoa libraries in pure Python.<ref>{{cite web |url = https://pyobjc.readthedocs.io/en/latest/ |title = PyObjC Introduction |accessdate = 2018-08-05}}</ref> Moreover, as an effect of Objective-C's close relationship with the [[C (programming language)|C]] programming language (it is a pure superset), developers are also able to incorporate any C-based [[API]] by [[Adapter pattern|wrapping it]] with an Objective-C wrapper and then using the wrapped code over the PyObjC bridge. Using [[Objective-C#Objective-C.2B.2B|Objective-C++]], the same can be done with [[C%2B%2B]] libraries.


==For Python Programmers==
==For Objective-C 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)|C]] programming language (it is a pure superset), developers are also able incorporate any C-based [[API]] by [[Adapter_pattern|wrapping it]] with an Objective-C wrapper and then using the wrapped code over the PyObjC bridge. Using [[Objective-C#Objective-C.2B.2B|Objective-C++]], the same can be done with [[C%2B%2B]] 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.
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.
PyObjC's origins date back to 1996, when Lele Gaifax built the original module in September of that year.<ref>{{cite web |url = https://opensource.apple.com/source/pyobjc/pyobjc-32/2.5/pyobjc/pyobjc-core/HISTORIC.txt.auto.html |title = PyObjC HISTORIC.txt |date = 2002-10-12 |accessdate = 2017-09-29}}</ref> 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.
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|Project Builder]], the predecessor to the current Apple platform [[Integrated_development_environment|IDE]], [[Xcode]].
Later the same year, support was added for non-framework Python builds, as well as subsequent support for the Python distribution included with [[macOS|Mac 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 [[Integrated development environment|IDE]], [[Xcode]].


Apple incorporated PyObjC into OS X in 2007, with the release of [[Mac_OS_X_Leopard |Mac OS X 10.5 Leopard]].
Apple incorporated PyObjC into Mac OS X in 2007, with the release of [[Mac OS X Leopard |Mac OS X 10.5 Leopard]].<ref>{{cite web |url = https://opensource.apple.com/source/pyobjc/pyobjc-26/pyobjc/pyobjc-website/enwiki/static/downloads.rst.auto.html |title = PyObjC downloads.rst |accessdate = 2017-09-29 }}</ref>


==Messages and Methods==
==Messages and methods==
In Objective-C, objects communicate with each other by sending messages, which is analogous to method calls in other object-oriented languages. When an object receives a message, it looks up the message's name, or selector, and matches it up with a method designated the same selector, which it then invokes.
In Objective-C, objects communicate with each other by sending messages, which is analogous to method calls in other object-oriented languages. When an object receives a message, it looks up the message's name, or selector, and matches it up with a method designated the same selector, which it then invokes.


The syntax for these message expressions is inherited from Smalltalk, and appears as an object, called the receiver, placed next to the name of the message, or selector, which are placed within a pair of square brackets (the latter of which is not inherited from Smalltalk). Colons within a selector indicate it accepts one or more arguments, one for each colon. Intended to improve code readability, colons are placed within the selector such that when the required arguments are in place, the expression's intent is unambiguous:
The syntax for these message expressions is inherited from Smalltalk, and appears as an object, called the receiver, placed to the left of the name of the message, or selector, and both are enclosed within a pair of square brackets (the square bracket syntax is not inherited from Smalltalk). Colons within a selector indicate that it accepts one or more arguments, one for each colon. Intended to improve code readability, colons are placed within the selector such that when the required arguments are in place, the expression's intent is unambiguous:


<source lang ="objc">
<syntaxhighlight lang ="objc">
[myLittleDuck makeSomeNoise:quack eyesClosed:@YES onOneFoot:@YES];
[myLittleDuck makeSomeNoise:quack eyesClosed:@YES onOneFoot:@YES];
</syntaxhighlight>
</source>


This is distinct from the syntax used in Python, as in many other languages, where an equivalent expression would read:
This is distinct from the syntax used in Python, and in many other languages, where an equivalent expression would read:


<source lang="python">
<syntaxhighlight lang="python">
myLittleDuck.makeSomeNoise_eyesClosed_onOneFoot_(quack, True, True)
myLittleDuck.makeSomeNoise_eyesClosed_onOneFoot_(quack, True, True)
</syntaxhighlight>
</source>


Translating Objective-C selectors to Python method names is accomplished by replacing each colon with a single underscore and listing the arguments within a pair of parentheses at the end, as demonstrated above.
Translating Objective-C selectors to Python method names is accomplished by replacing each colon with a single underscore and listing the arguments within a pair of parentheses at the end, as demonstrated above.
Line 57: Line 58:
Objective-C classes are subclassed in the same manner as a normal Python class:
Objective-C classes are subclassed in the same manner as a normal Python class:


<source lang="python">
<syntaxhighlight lang="python">
class MyDuck(NSObject): # NSObject is a base Objective-C class.
def init(self):
self = super(MyDuck, self).init() # An Objective-C idiom, wherein the
# subclass instance, self, is instantiated
# by sending the superclass its
# designated initializer.
return self


myLittleDuckOne = MyDuck.alloc().init()
class MyDuck(NSObject): # NSObject is a base Objective-C class.
</syntaxhighlight>
def init(self):
self = super(MyDuck, self).init() # An Objective-C idiom, wherein the
# subclass instance, self, is instantiated
# by sending the superclass its
# designated initializer.
return self


==See also==
myLittleDuckOne = MyDuck.alloc().init()
{{Portal|Free and open-source software}}
* [[libffi]]
* [[RubyCocoa]]


==References==
</source>
{{Reflist}}


==External links==
==External links==
*{{official website|http://pyobjc.sourceforge.net/}}
*{{official website}}
*[http://developer.apple.com/cocoa/pyobjc.html Apple's Description of PyObjC]
*[http://python.6.n6.nabble.com/a-word-of-warning-for-pyobjc-users-td2154477.html Ronald Oussoren's warning on Xcode 4.0]
*[http://python.6.n6.nabble.com/a-word-of-warning-for-pyobjc-users-td2154477.html Ronald Oussoren's warning on Xcode 4.0]
{{DEFAULTSORT:Pyobjc}}
[[Category:Python libraries]]
[[Category:Mac OS X programming tools]]




{{DEFAULTSORT:Pyobjc}}
{{prog-lang-stub}}
[[Category:Python (programming language) libraries]]

[[Category:MacOS programming tools]]
[[de:PyObjC]]
[[es:PyObjC]]
[[ja:PyObjC]]
[[ru:PyObjC]]

Latest revision as of 06:54, 25 November 2021

PyObjC
Original author(s)Lele Gaifax
Developer(s)Ronald Oussoren, Bill Bumgarner, Steve Majewski, et al.
Initial releaseSeptember 1996; 28 years ago (1996-09)
Stable release
5.2 / April 3, 2019; 5 years ago (2019-04-03)[1]
Repository
Written inPython
Operating systemCross-platform
LicenseMIT License
Websitepyobjc.readthedocs.io/en/latest/

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 macOS applications in pure Python.

There is also limited support for GNUstep, an open source, cross-platform implementation of Cocoa.

For Python programmers

[edit]

The most important usage of PyObjC is enabling programmers to create GUI applications using Cocoa libraries in pure Python.[2] Moreover, as an effect of Objective-C's close relationship with the C programming language (it is a pure superset), developers are also able to 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

[edit]

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

[edit]

PyObjC's origins date back to 1996, when Lele Gaifax built the original module in September of that year.[3] 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 Mac 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 Mac OS X in 2007, with the release of Mac OS X 10.5 Leopard.[4]

Messages and methods

[edit]

In Objective-C, objects communicate with each other by sending messages, which is analogous to method calls in other object-oriented languages. When an object receives a message, it looks up the message's name, or selector, and matches it up with a method designated the same selector, which it then invokes.

The syntax for these message expressions is inherited from Smalltalk, and appears as an object, called the receiver, placed to the left of the name of the message, or selector, and both are enclosed within a pair of square brackets (the square bracket syntax is not inherited from Smalltalk). Colons within a selector indicate that it accepts one or more arguments, one for each colon. Intended to improve code readability, colons are placed within the selector such that when the required arguments are in place, the expression's intent is unambiguous:

   [myLittleDuck makeSomeNoise:quack eyesClosed:@YES onOneFoot:@YES];

This is distinct from the syntax used in Python, and in many other languages, where an equivalent expression would read:

    myLittleDuck.makeSomeNoise_eyesClosed_onOneFoot_(quack, True, True)

Translating Objective-C selectors to Python method names is accomplished by replacing each colon with a single underscore and listing the arguments within a pair of parentheses at the end, as demonstrated above.

Classes

[edit]

Objective-C classes are subclassed in the same manner as a normal Python class:

class MyDuck(NSObject):                   # NSObject is a base Objective-C class.
    def init(self):
        self = super(MyDuck, self).init() # An Objective-C idiom, wherein the
                                          # subclass instance, self, is instantiated
                                          # by sending the superclass its
                                          # designated initializer.
        return self

myLittleDuckOne = MyDuck.alloc().init()

See also

[edit]

References

[edit]
  1. ^ "pyobjc". Python Package Index. Retrieved 2019-04-21.
  2. ^ "PyObjC Introduction". Retrieved 2018-08-05.
  3. ^ "PyObjC HISTORIC.txt". 2002-10-12. Retrieved 2017-09-29.
  4. ^ "PyObjC downloads.rst". Retrieved 2017-09-29.
[edit]