1. Dwayne Litzenberger
  2. pyobjc


Ronald Oussoren  committed 4c3983c

- More documentation updates
- Remove unnecessary comment from addressbook.py
- Cleanup iClass example
- method-accessor.py now recognizes special attributes ('__name') and shortcuts
there evaluation (only __class__ is really supported, others will raise an
AttributeError. Needed for iClass: type(NSFault.pyobjc_instanceMethods) would
- AppHelper: Move call to NSLog inside the if-statement, for slightly nicer
end-user behaviour.

  • Participants
  • Parent commits 808e656
  • Branches default

Comments (0)

Files changed (8)

File pyobjc/Doc/TODO

View file
  • Ignore whitespace
 Luckily there are not many varargs methods and most (if no all) of them can
 be easily avoided.
+Cleanup Examples
+The CurrentConvertor example should be removed, this should be the same as the
+final step of the tutorial. It isn't at the moment because additional cruft in
+the example.
+The TableModel and TableModel2 examples should be merged, the contain the same
+python code and only differ in the build method.
+* method-weirdness.py
+  Not really a suitable example, but shows a strange feature of Apple's 
+  implementation of Cocoa. Move to a unittest.
+* addressbook.py
+  Cleanup, maybe transform this into a usefull utility (import/export from/to
+  CSV springs to mind).
+* autoreadme.py
+  Add documentation
+* dictionary.py
+  Should be a unittest, and should be added to the (non-existing) manual
+* objc-vars.py
+  Move to unittests (and documentation)
+* pydict-to-objcdict.py
+  Move to unittests
+* subclassing-objective-c.py
+  Move to documentation (unittest?)
+* super-call.py
+  Move to documentation  (unittest?)
+* using-nscoder.py
+  Move to unittest (and expand)
+* using-nsscanner.py
+  Move to unitest

File pyobjc/Examples/addressbook.py

View file
  • Ignore whitespace
 #!/usr/bin/env python
 # Using the AddressBook framework on MacOS X
-# I didn't add a single line of C code for this!
 import AddressBook
 book = AddressBook.ABAddressBook.sharedAddressBook()

File pyobjc/Examples/iClass/datasource.py

View file
  • Ignore whitespace
 from Foundation import NSObject, NSBundle
-from AppKit import NSOutlineViewDataSource, NSTableDataSource, 
+from AppKit import NSOutlineViewDataSource, NSTableDataSource
 from PyObjCTools import NibClassBuilder
 from objc import selector, getClassList, objc_object, IBOutlet
     def description(self):
         return str(self)
+def wrap_object(obj):
+    if WRAPPED.has_key(obj):
+        return WRAPPED[obj]
+    else:
+        WRAPPED[obj] = Wrapper.alloc().init_(obj)
+        return WRAPPED[obj]
+def unwrap_object(obj):
+    if obj is None:
+        return obj
+    return obj.value
 methodIdentifier = {
     __slots__ = ('_classList', '_classTree', '_methodInfo')
     def clearClassInfo(self):
-        print "clearClassInfo"
         self._methodInfo = []
     def setClassInfo(self, cls):
-        print "setClassInfo for",cls
         self.window.setTitle_('iClass: %s'%cls.__name__)
-        print (classPath(cls))
         self._methodInfo = []
         for nm in dir(cls):
     def selectClass_(self, event):
-        print "selectClass:"
         rowNr = self.classTable.selectedRow()
         if rowNr == -1:
             item = self.classTable.itemAtRow_(rowNr)
-            item = item.value
-            self.setClassInfo(item)
+            self.setClassInfo(unwrap_object(item))
     def showClass(self, cls):
-        print "showClass:", cls
         # First expand the tree (to make item visible)
         super = cls.__bases__[0]
         if  super == objc_object:
-        item = WRAPPED[super]
+        item = wrap_object[super]
         rowNr = self.classTable.rowForItem_(item)
     def selectClass(self, cls):
-        print "selectClass"
-        item = WRAPPED[cls]
+        item = wrap_object[cls]
         rowNr = self.classTable.rowForItem_(item)
     def searchClass_(self, event):
-        print "searchClass:"
         val = self.searchBox.stringValue()
         if not val:
-        print "Searching", val
         found = None
         for cls in self._classTree.keys():
     def refreshClasses(self):
-        print "refreshClasses"
         self._classList = getClassList()
         self._classTree = {}
         self._methodInfo = []
         for lst in self._classTree.values():
-        #print self._classTree
     def init(self):
-        print "Init", self
         self._classInfo = getClassList()
         return self
     def awakeFromNib(self):
-        print "Awaking", self
         self._classInfo = getClassList()
     def outlineView_child_ofItem_(self, outlineview, index, item):
-        print "childOfItem:", index, item
-        if not (item is None):
-            item = item.value
-        v = self._classTree[item][index]
-        #print 'child is', v
-        if not WRAPPED.has_key(v):
-            print "Make Wrapper for", v
-            WRAPPED[v] = Wrapper.alloc().init_(v)
-        return WRAPPED[v]
+        return wrap_object(self._classTree[unwrap_object(item)][index])
     def outlineView_isItemExpandable_(self, outlineview, item):
-        print "isItemExpandable:", item
-        if not (item is None):
-            item = item.value
-        return len(self._classTree[item]) != 0
+        return len(self._classTree[unwrap_object(item)]) != 0
     def outlineView_numberOfChildrenOfItem_(self, outlineview, item):
-        print "numChildren:", item
-        if not (item is None):
-            item = item.value
-        return len(self._classTree[item])
+        return len(self._classTree[unwrap_object(item)])
     def outlineView_objectValueForTableColumn_byItem_(self, outlineview, column, item):
-        print "objectValue:", item
         if item is None:
             return '<None>'
-            #print "value:", item.value
             v = item.value
             return v.__name__
     def numberOfRowsInTableView_(self, aTableView):
-        print "numberOfRows", aTableView
         return len(self._methodInfo)
     def tableView_objectValueForTableColumn_row_(self,    
                              aTableView, aTableColumn, rowIndex):  
-        print "objectValue", aTableView, aTableColumn, rowIndex
         return self._methodInfo[rowIndex][methodIdentifier[aTableColumn.identifier()]]

File pyobjc/Install.txt

View file
  • Ignore whitespace
 The ``Project Templates`` directory contains project templates for
-project builder.  Currently, there is one project builder template;  a
-Cocoa-Python Application project template.   When installed, this adds
-a project to Project Builder's project menu that allows new Cocoa
-applications implemented entirely in Python to be created from within
-Project Builder (in the same fashion as any other project).
+project builder.  These have to be copied to
+``/Developer/ProjectBuilder Extras/Project Templates/Application`` before
+they are useable from Project Builder.
-To install, simply copy the project template into the Project Builder
-project templates directory (or create a symlink).
+There are three templates available:
+* Cocoa-Python Application
+  A project created from this template is designed to implement standalone,
+  pure-Python, applications that are compatible with Apple's build of Python as
+  well as all other builds of python that support PyObjC.
+  When building the 'install' target, the resulting application wrapper will
+  included the PyObjC module and can be launched on any stock OS X 10.2 system
+  without requiring PyObjC to be preinstalled.
+* Cocoa-Python-ObjC Application
+  A project created from this template includes an embedded framework project
+  into which all compiled (Objective-C) code can be placed.  Upon launch, 
+  the application automatically dynamically loads the embedded framework 
+  containing the compiled code.
+  Each Framework's Resources directory is automatically added to sys.path.
+* Cocoa-Python Document-based Application
+  This template works like the `Cocoa-Python Application`_ template in that it
+  is compatible with the Apple build of Python.   It creates an application 
+  that uses Cocoa's Multiple Document Architecture in the same fashion as the
+  default Cocoa Document-based Application supplied with Project Builder. 
 More information on project templates can be found in the Project
 Builder documentation and/or release notes.

File pyobjc/Lib/PyObjCTools/AppHelper.py

View file
  • Ignore whitespace
-            NSLog("An exception has occured:")
             if not unexpectedErrorAlert():
+                NSLog("An exception has occured:")
+                NSLog("An exception has occured:")

File pyobjc/Modules/objc/method-accessor.m

View file
  • Ignore whitespace
 	int   unbound_instance_method = 0;
 	char* flattened;
+	if (strcmp(name, "__class__") == 0) {
+		/* Someone does 'type(object.pybojc_instanceMethods)' */
+		Py_INCREF(self->ob_type);
+		return self->ob_type;
+	}
+	if (name[0] == '_' && name[1] == '_') {
+		/*
+		 * FIXME: Some classes (NSFault, NSFinalProxy) crash hard
+		 * on these names
+		 */
+		ObjCErr_Set(PyExc_AttributeError,
+			"No selector %s", name);
+		return NULL;
+	}
 	if (PyObjCClass_Check(self)) {
 		objc_object = (id)PyObjCClass_GetClass(self);

File pyobjc/ReadMe.txt

View file
  • Ignore whitespace
 Welcome to PyObjC
-.. :authors: Ronald Oussoren, Bill Bumgarner
 The PyObjC package provides the glue needed to interface the Python interpreter with the Objective-C language. At its core is the ``objc`` module makes 
 Objective-C objects and classes available as first-class Python citizens, it is 
 not only possible to use Objective-C objects but you can also subclass 

File pyobjc/Scripts/make_distrib.py

View file
  • Ignore whitespace
 print "Copying readme and license"
 shutil.copyfile("ReadMe.txt", os.path.join(OUTPUTDIR, "ReadMe.txt"))
 shutil.copyfile("License.txt", os.path.join(OUTPUTDIR, "License.txt"))
-shutil.copyfile("ChangeLog", os.path.join(OUTPUTDIR, "ChangeLog"))
 print "Setting up developer templates"