Commits

Bob Ippolito committed bd464bb

update news, kvc to support __pyobjc_object__

Comments (0)

Files changed (3)

Lib/PyObjCTools/KeyValueCoding.py

 
 class kvc(object):
     def __init__(self, obj):
-        self._obj = obj
+        self.__pyobjc_object__ = obj
     
     def __getattr__(self, attr):
-        return getKey(self._obj, attr)
+        return getKey(self.__pyobjc_object__, attr)
 
     def __repr__(self):
-        return repr(self._obj)
+        return repr(self.__pyobjc_object__)
 
     def __setattr__(self, attr, value):
         if not attr.startswith('_'):
-            setKey(self._obj, attr, value)
+            setKey(self.__pyobjc_object__, attr, value)
         object.__setattr__(self, attr, value)
 
     def __getitem__(self, item):
         if not isinstance(item, basestring):
             raise TypeError, 'Keys must be strings'
-        return getKeyPath(self._obj, item)
+        return getKeyPath(self.__pyobjc_object__, item)
 
     def __setitem__(self, item, value):
         if not isinstance(item, basestring):
             raise TypeError, 'Keys must be strings'
-        setKeyPath(self._obj, item, value)
-
-objc.lookUpClass('OC_PythonObject').depythonifyTable().insert(0, (kvc, lambda o:o._obj))
+        setKeyPath(self.__pyobjc_object__, item, value)
 <ul>
 <li>(UNFINISHED) New RemotePyInterpreter example that demonstrates an
 out-of-process Python interpreter (primarily for IDE uses).</li>
+<li>PyObjCTools.KeyValueCoding has a new <code><span>kvc</span></code> class that allows
+Pythonic Key-Value Coding.<ul>
+<li><code><span>__getitem__</span></code> is mapped to <code><span>valueForKeyPath:</span></code></li>
+<li><code><span>__setitem__</span></code> is mapped to <code><span>setValue:forKeyPath:</span></code></li>
+<li><code><span>__getattr__</span></code> is mapped to <code><span>valueForKey:</span></code></li>
+<li><code><span>__setattr__</span></code> is mapped to <code><span>setValue:forKey:</span></code></li>
+</ul>
+<p>The <code><span>kvc</span></code> class uses <code><span>__pyobjc_object</span></code>, so it may cross the bridge
+as the wrapped object.</p>
+</li>
+<li><code><span>NSNumber</span></code> instances are bridged to a <code><span>float</span></code>, <code><span>long</span></code>, or <code><span>int</span></code>
+subclass that uses <code><span>__pyobjc_object__</span></code>.  <code><span>NSDecimalNumber</span></code> is bridged
+to <code><span>Foundation.NSDecimal</span></code>, which now supports <code><span>__pyobjc_object__</span></code>.
+This eliminates a HUGE amount of cruft in <code><span>objc._conveniences</span></code>.</li>
+<li>The Python to Objective-C bridge now looks for a <code><span>__pyobjc_object__</span></code> 
+attribute to get a PyObjC object from a Python object.</li>
 <li>New IDNSnitch example in Inject that demonstrates how to write an
 monitor for the launch of another application,
 use <code><span>objc.inject</span></code> to load code into a target process,
 - (UNFINISHED) New RemotePyInterpreter example that demonstrates an
   out-of-process Python interpreter (primarily for IDE uses).
 
+- PyObjCTools.KeyValueCoding has a new ``kvc`` class that allows
+  Pythonic Key-Value Coding.
+
+  - ``__getitem__`` is mapped to ``valueForKeyPath:``
+  - ``__setitem__`` is mapped to ``setValue:forKeyPath:``
+  - ``__getattr__`` is mapped to ``valueForKey:``
+  - ``__setattr__`` is mapped to ``setValue:forKey:``
+
+  The ``kvc`` class uses ``__pyobjc_object``, so it may cross the bridge
+  as the wrapped object.
+
+- ``NSNumber`` instances are bridged to a ``float``, ``long``, or ``int``
+  subclass that uses ``__pyobjc_object__``.  ``NSDecimalNumber`` is bridged
+  to ``Foundation.NSDecimal``, which now supports ``__pyobjc_object__``.
+  This eliminates a HUGE amount of cruft in ``objc._conveniences``.
+
+- The Python to Objective-C bridge now looks for a ``__pyobjc_object__`` 
+  attribute to get a PyObjC object from a Python object.
+
 - New IDNSnitch example in Inject that demonstrates how to write an
   monitor for the launch of another application,
   use ``objc.inject`` to load code into a target process,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.