World Library  
Flag as Inappropriate
Email this Article

PyObjC

Article Id: WHEBN0002843493
Reproduction Date:

Title: PyObjC  
Author: World Heritage Encyclopedia
Language: English
Subject: Cocoa (API), Cocoa Sharp, NObjective, Python libraries, Monobjc
Collection: Os X Programming Tools, Python Libraries
Publisher: World Heritage Encyclopedia
Publication
Date:
 

PyObjC

PyObjC
Developer(s) Ronald Oussoren, Bill Bumgarner, Steve Majewski, Lele Gaifax, et al.
Stable release 2.5.1 / January 22, 2013
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.

Contents

  • For Python programmers 1
  • For Objective-C programmers 2
  • History 3
  • Messages and methods 4
  • Classes 5
  • See also 6
  • External links 7

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 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

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.

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.

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

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

External links

  • Official website
  • Ronald Oussoren's warning on Xcode 4.0
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and USA.gov, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for USA.gov and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
 
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
 
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.
 


Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.