1. Ronald Oussoren
  2. pyobjc

Commits

Ronald Oussoren  committed c8ea5ac

- Struct types created by the framework wrappers once again create class
methods on :class:`objc.ivar` to generate instance variables of that type::

myLocation = objc.ivar.NSPoint()

This has the same result as::

myLocation = objc.ivar(typer=NSPoint.__typestr__)

- Added :func:`objc.createStructAlias`, and deprecated
:func:`objc.registerStructAlias`. The new function has a "name" argument
and can register types with the :class:`objc.ivar` type (see previous item)

NOTE: This restores some (undocumented) functionality from PyObjC 2.3 that
got lost in the migration to a new metadata system in PyObjC 2.4.

  • Participants
  • Parent commits fc705b4
  • Branches default

Comments (0)

Files changed (5)

File pyobjc-core/Doc/lib/module-objc.rst

View file
    Create a type to wrap structs with a given name and type signature, this
    type will be used by the bridge to convert values of this structure to Python.
 
+   This also adds a class method named *name* to :class:`objc.ivar`. This class
+   method creates a new instance variable with the struct type as its type.
+
    * *name* is a string with the name of the structure, for example "NSPoint".
 
    * *typestr* is the encoded type of the structure and can optionally 
    * *pack* can be used to specify the value of "#pragma pack" for the structure
      (default is to use the default platform packing for structures).
 
+   .. versionchanged:: 2.5
+      The function creates a class method on :class:`objc.ivar`.
+
 .. function:: registerStructAlias(typestr, structType)
 
    Tell the brige that structures with encoding *typestr* should also be 
    coverted to Python using *structType* (a type created using :func:`createStructType`).
 
+   .. deprecated:: 2.5
+      Use :func:`createStructAlias` instead.
+
+.. function:: createStructAlias(name, typestr, structType)
+
+   Tell the brige that structures with encoding *typestr* should also be 
+   coverted to Python using *structType* (a type created using 
+   :func:`createStructType`).
+
+   This also adds a class method named *name* to :class:`objc.ivar`. This class
+   method creates a new instance variable with the struct type as its type.
+
+   .. versionadded: 2.5
+
 .. function:: registerMetaDataForSelector(class\_, selector, metadata)
 
    Register a metadata structure for the given selector.

File pyobjc-core/Lib/objc/_bridgesupport.py

View file
 import ctypes
 import objc
 import re
+import warnings
+import functools
 
 from objc import registerMetaDataForSelector, error
 
 _structConvenience("UniChar", objc._C_UNICHAR)
 _structConvenience("char_text", objc._C_CHAR_AS_TEXT)
 _structConvenience("char_int", objc._C_CHAR_AS_INT)
+
+_orig_createStructType = objc.createStructType
+
+@functools.wraps(objc.createStructType)
+def createStructType(name, typestr, fieldnames, doc=None, pack=-1):
+    result = _orig_createStructType(name, typestr, fieldnames, doc, pack)
+    _structConvenience(name, result)
+    return result
+
+objc.createStructType = createStructType
+
+
+_orig_registerStructAlias = objc.registerStructAlias
+@functools.wraps(objc.registerStructAlias)
+def registerStructAlias(typestr, structType):
+    warning.warn(DeprecationWarning, "use createStructAlias instead")
+    return _orig_registerStructAlias(typestr, structType)
+
+def createStructAlias(name, typestr, structType):
+    result = _orig_registerStructAlias(typestr, structType)
+    _structConvenience(name, result)
+    return result
+
+objc.createStructAlias = createStructAlias
+objc.registerStructAlias = registerStructAlias

File pyobjc-core/Modules/objc/module.m

View file
 	if (PyObjC_RegisterStructAlias(typestr, structType) == -1) {
 		return NULL;
 	}
+
 	Py_INCREF(structType);
 	return structType;
 }

File pyobjc-core/NEWS.txt

View file
      The implementation is currently barely tested and therefore likely
      contains bugs.
 
+- Struct types created by the framework wrappers once again create class
+  methods on :class:`objc.ivar` to generate instance variables of that type::
+
+     myLocation = objc.ivar.NSPoint()
+
+  This has the same result as::
+
+    myLocation = objc.ivar(typer=NSPoint.__typestr__)
+
+- Added :func:`objc.createStructAlias`, and deprecated 
+  :func:`objc.registerStructAlias`. The new function has a "name" argument
+  and can register types with the :class:`objc.ivar` type (see previous item)
+
 - Add explicit deprecation warnings to ``objc.CFToObject`` and
   ``objc.ObjectToCF``. Both functions barely function at all and will
   be removed with PyObjC 3.0.

File pyobjc-core/PyObjCTest/test_bridgesupport.py

View file
             self.assertEqual(set(meta.keys()) - {"arguments", "retval", "variadic", "suggestion" }, set())
 
     def assert_valid_bridgesupport(self, framework_name, xmldata):
-        print framework_name
         prs = bridgesupport._BridgeSupportParser(xmldata, framework_name)
 
         for item in prs.cftypes: