Commits

Ronald Oussoren  committed 9307cf3

- Add a function to find the NSBundle for a Python based plugin
- Use this in the PrefPane example, and use AutoBaseClass

  • Participants
  • Parent commits f804950

Comments (0)

Files changed (3)

File pyobjc/Doc/api-notes-macosx.txt

 
 .. :author: Ronald Oussoren
 
+.. Contents::
+
 Introduction
 ------------
 
 accessed although without access to constants and global functions defined
 by those frameworks.
 
+
 Addressbook framework
 ---------------------
 
 using the python function ``apply``. The ``performv::`` method is also not
 supported, with a simular work-around.
 
+Class NSBundle
+..............
+
+* ``bundleForClass:``
+  This method does not work correctly for classes defined in Python, these
+  all seem be defined in the ``mainBundle()``. As a workaround you can use
+  the function ``objc.pluginBundle(name)`` to find the NSBundle for your
+  Python based bundle. See Examples/PrefPane for an example of its usage.
+
+
 Class NSDictionary
 ..................
 

File pyobjc/Examples/PrefPane/main.py

 print "loading python prefpane"
 
 from AppKit import *
+from Foundation import NSBundle
 from PreferencePanes import *
 import objc
+from PyObjCTools import NibClassBuilder
 
-class SimplePreferencePane (NSPreferencePane):
-    value1Field = objc.IBOutlet('value1Field')
-    value2Field = objc.IBOutlet('value2Field')
-    resultField = objc.IBOutlet('resultField')
-    button = objc.IBOutlet('button')
+# NibClassBuilder needs to read our Nib files to do its work,
+# we need to specify the optional second argument to extractClasses
+# because we're not in the main bundle.
+NibClassBuilder.extractClasses("SimplePreferencePane", 
+    objc.pluginBundle("SimplePreferencePane"))
+
+class SimplePreferencePane (NibClassBuilder.AutoBaseClass):
 
     def doIt_(self, sender):
         v1 = self.value1Field.floatValue()

File pyobjc/Lib/objc/__init__.py

     """
     return selector(func, signature="v@:@")
 
-
+def pluginBundle(pluginName):
+    """
+    Return the main bundle for the named plugin. This should be used
+    in combination with ``PyObjCTools.pluginbuilder``.
+    """
+    cls = 'PyObjC_Bundle_' + pluginName 
+    return runtime.NSBundle.bundleForClass_(getattr(runtime, cls))
 
 from _convenience import CONVENIENCE_METHODS, CLASS_METHODS