[PyObjC-svn] r2236 - in trunk/pyobjc/pyobjc-framework-Cocoa: . Doc Lib/Foundation Modules PyObjCTest
[email protected] Sat, 23 May 2009 05:01:24 -0500
| Newsgroups | gmane.comp.python.pyobjc.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: ronaldoussoren
Date: Sat May 23 05:01:24 2009
New Revision: 2236
Log:
Improve the support for NSInvocation. It is now possible to get/set
the argument and return value fields of an invocation.
Added:
trunk/pyobjc/pyobjc-framework-Cocoa/Modules/_Foundation_nsinvocation.m
Modified:
trunk/pyobjc/pyobjc-framework-Cocoa/Doc/api-notes-Foundation.txt
trunk/pyobjc/pyobjc-framework-Cocoa/Lib/Foundation/__init__.py
trunk/pyobjc/pyobjc-framework-Cocoa/PyObjCTest/test_nsinvocation.py
trunk/pyobjc/pyobjc-framework-Cocoa/setup.py
Modified: trunk/pyobjc/pyobjc-framework-Cocoa/Doc/api-notes-Foundation.txt
==============================================================================
--- trunk/pyobjc/pyobjc-framework-Cocoa/Doc/api-notes-Foundation.txt (original)
+++ trunk/pyobjc/pyobjc-framework-Cocoa/Doc/api-notes-Foundation.txt Sat May 23 05:01:24 2009
@@ -99,6 +99,22 @@
* Struct ``NSObjCValue`` and related constants (such as ``NSObjCNoType``) are not available in
Python.
+* It is possible to get and set argument values and the return value of an invocation, but only
+ for the simple cases, that is when the value is a single value and not a pointer to value or
+ an array of values.
+
+ That is, the following methods cannot be accessed through an ``NSInvocation`` at the moment:
+
+ * `NSArray.arrayWithObjects_count_`: The first argument is a C-array of values
+
+ * `NSFormatter.getObjectValue_forString_range_error_`: The first and last arguments are a by-reference arguments.
+
+ It is possible to get/set values whose type is a basic C type, that is the return value ``NSArray.count`` can
+ be extracted from an ``NSInvocation`` object.
+
+ This limitation should be fine for most usecases of ``NSInvocation``, please let us know if you
+ run into cases where this limitation is a problem.
+
NSMapTable
----------
Modified: trunk/pyobjc/pyobjc-framework-Cocoa/Lib/Foundation/__init__.py
==============================================================================
--- trunk/pyobjc/pyobjc-framework-Cocoa/Lib/Foundation/__init__.py (original)
+++ trunk/pyobjc/pyobjc-framework-Cocoa/Lib/Foundation/__init__.py Sat May 23 05:01:24 2009
@@ -21,6 +21,7 @@
# Import the various manually maintained bits:
from Foundation._functiondefines import *
from Foundation._NSDecimal import *
+from Foundation._nsinvocation import *
from Foundation._functioncallbacks import *
from Foundation._typecode import *
from Foundation._nscoder import *
Modified: trunk/pyobjc/pyobjc-framework-Cocoa/PyObjCTest/test_nsinvocation.py
==============================================================================
--- trunk/pyobjc/pyobjc-framework-Cocoa/PyObjCTest/test_nsinvocation.py (original)
+++ trunk/pyobjc/pyobjc-framework-Cocoa/PyObjCTest/test_nsinvocation.py Sat May 23 05:01:24 2009
@@ -5,11 +5,28 @@
class TestNSInvocation (TestCase):
def test_dummy(self):
- self.fail("NSInvocation tests")
- self.fail("getArgument:atIndex:")
- self.fail("setArgument:atIndex:")
- self.fail("getReturnValue:")
- self.fail("setReturnValue:")
+ value = NSMutableArray.arrayWithArray_([1, 2, 3])
+
+ invocation = NSInvocation.invocationWithMethodSignature_(value.methodSignatureForSelector_('count'))
+ invocation.setSelector_('count')
+ invocation.setTarget_(value)
+ invocation.invoke()
+
+ v = invocation.getReturnValue_(None)
+ self.failUnlessIsInstance(v, (int, long))
+ self.failUnlessEqual(v, 3)
+
+ invocation = NSInvocation.invocationWithMethodSignature_(value.methodSignatureForSelector_('addObject:'))
+ invocation.setSelector_('addObject:')
+ invocation.setTarget_(value)
+ invocation.setArgument_atIndex_(u"hello", 2)
+ v = invocation.getArgument_atIndex_(None, 2)
+ self.failUnlessEqual(v, u"hello")
+ invocation.invoke()
+
+ self.failUnlessEqual(value.count(), 4)
+
+
def testMethods(self):
self.failUnlessResultIsBOOL(NSInvocation.argumentsRetained)
Modified: trunk/pyobjc/pyobjc-framework-Cocoa/setup.py
==============================================================================
--- trunk/pyobjc/pyobjc-framework-Cocoa/setup.py (original)
+++ trunk/pyobjc/pyobjc-framework-Cocoa/setup.py Sat May 23 05:01:24 2009
@@ -142,6 +142,10 @@
extra_link_args=CFLAGS + ['-framework', 'CoreFoundation']),
# Foundation
+ Extension('Foundation._nsinvocation',
+ [ 'Modules/_Foundation_NSInvocation.m' ],
+ extra_compile_args=CFLAGS,
+ extra_link_args=CFLAGS + ['-framework', 'Foundation']),
Extension('Foundation._NSDecimal',
[ 'Modules/_Foundation_NSDecimal.m' ],
extra_compile_args=CFLAGS,
@@ -212,6 +216,11 @@
[ "Modules/_AppKit_carbon.m"],
extra_compile_args=CFLAGS,
extra_link_args=CFLAGS + ["-framework", "AppKit"]),
+
+
+ #
+ # Test support
+ #
Extension("PyObjCTest.testhelper",
[ "Modules/testhelper.m"],
extra_compile_args=CFLAGS,
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com