Ronald Oussoren avatar Ronald Oussoren committed 61b1725

- Minor documentation updates
- Wrapper for -getTIFFCompressionTypes:count: in NSBitmapImageRep, solves
bug #789205
- Fix regexp used in strconst_generator.py, which means we can now access
even more constants from Python :-)

Comments (0)

Files changed (9)

pyobjc/Doc/api-notes-macosx.html

         mysheetDidEnd = PyObjCTools.AppHelper.endSheetMethod(
                 mysheetDidEnd)
 </pre>
+<p>Unless otherwise noted, all <code><span>contextInfo</span></code> arguments are passed as integers,
+not as arbitrary pointers.</p>
 <h3><a href="#id7" name="class-nsapplication">Class NSApplication</a></h3>
 <p><code><span>NSModalSession</span></code> objects are wrapped as opaque values. You can check if
 two wrapper objects refer to the same session object by comparing their

pyobjc/Doc/api-notes-macosx.txt

 		mysheetDidEnd = PyObjCTools.AppHelper.endSheetMethod(
 			mysheetDidEnd)
 
+Unless otherwise noted, all ``contextInfo`` arguments are passed as integers,
+not as arbitrary pointers.
+
 
 Class NSApplication
 ...................

pyobjc/Doc/intro.html

 <li><a href="#cocoa-for-python-programmers" id="id10" name="id10">Cocoa for Python programmers</a></li>
 <li><a href="#notes-on-specific-tasks" id="id11" name="id11">Notes on specific tasks</a><ul>
 <li><a href="#working-with-threads" id="id12" name="id12">Working with threads</a></li>
+<li><a href="#finalizers" id="id13" name="id13">Finalizers</a></li>
 </ul>
 </li>
-<li><a href="#building-applications" id="id13" name="id13">Building applications</a><ul>
-<li><a href="#pure-python-buildapp-py" id="id14" name="id14">&quot;Pure Python&quot; :  buildapp.py</a></li>
-<li><a href="#ide-approach-project-builder" id="id15" name="id15">&quot;IDE approach&quot; : Project builder</a></li>
+<li><a href="#building-applications" id="id14" name="id14">Building applications</a><ul>
+<li><a href="#pure-python-buildapp-py" id="id15" name="id15">&quot;Pure Python&quot; :  buildapp.py</a></li>
+<li><a href="#ide-approach-project-builder" id="id16" name="id16">&quot;IDE approach&quot; : Project builder</a></li>
 </ul>
 </li>
 </ul>
 thread that owns the Python GIL (that's also the reason for not being able 
 to use <code><span>NSThread</span></code> to create new threads).  This restriction will be lifted
 in a future version of PyObjC (at least when using Python 2.3).</p>
-<h2><a href="#id13" name="building-applications">Building applications</a></h2>
+<h3><a href="#id13" name="finalizers">Finalizers</a></h3>
+<p>In Python you can use the method <code><span>__del__</span></code> to clean up resources when your
+object is garbage collected. In Objective-C/Cocoa this is done with a method 
+named <code><span>dealloc</span></code>.</p>
+<p>In PyObjC you should always use the <code><span>__del__</span></code> method, the <code><span>dealloc</span></code> method
+can safely be ignored and the bridge will complain when you try to override
+this method.</p>
+<h2><a href="#id14" name="building-applications">Building applications</a></h2>
 <p>There are two different ways to build applications with PyObjC. There are no
 major advantages to using either one of them, use the one that is most 
 convenient to you.</p>
-<h3><a href="#id14" name="pure-python-buildapp-py">&quot;Pure Python&quot; :  buildapp.py</a></h3>
+<h3><a href="#id15" name="pure-python-buildapp-py">&quot;Pure Python&quot; :  buildapp.py</a></h3>
 <p>PyObjC includes a copy of the <code><span>bundlebuilder</span></code> module. This module will be
 part of the Python 2.3 MacPython release and offers a way to build
 distutils-style scripts  for building (standalone) applications.</p>
 <p>The online documentation for <code><span>bundlebuilder</span></code> contains more information on 
 building <code><span>buildapp.py</span></code> scripts and how to invoke them. There are plenty of
 example <code><span>buildapp.py</span></code> scripts in the various <a href="../Examples/00ReadMe.txt">Examples</a> subfolders.</p>
-<h3><a href="#id15" name="ide-approach-project-builder">&quot;IDE approach&quot; : Project builder</a></h3>
+<h3><a href="#id16" name="ide-approach-project-builder">&quot;IDE approach&quot; : Project builder</a></h3>
 <p>PyObjC includes a number of Project Builder templates that can be used to 
 build (standalone) applications. Those templates are used like any other
 Project Builder template. The only non-obvious detail is that you have to

pyobjc/Doc/intro.txt

 to use ``NSThread`` to create new threads).  This restriction will be lifted
 in a future version of PyObjC (at least when using Python 2.3).
 
+Finalizers
+..........
+
+In Python you can use the method ``__del__`` to clean up resources when your
+object is garbage collected. In Objective-C/Cocoa this is done with a method 
+named ``dealloc``. 
+
+In PyObjC you should always use the ``__del__`` method, the ``dealloc`` method
+can safely be ignored and the bridge will complain when you try to override
+this method.
 
 Building applications
 ---------------------

pyobjc/Lib/AppKit/test_nsbitmap.py

+import unittest
+import AppKit
+
+class TestNSBitmapImageRep (unittest.TestCase):
+
+    def test_getTIFFCompressionTypes(self):
+        r = AppKit.NSBitmapImageRep.getTIFFCompressionTypes_count_()
+
+        self.assert_(isinstance(r, tuple))
+        self.assertEquals(len(r), 2)
+
+        lst, ln = r
+
+        self.assert_(isinstance(lst, tuple))
+        self.assert_(isinstance(ln, int))
+
+        self.assertEquals(len(lst), ln)
+        self.assert_(reduce(lambda x, y: x and isinstance(x, int), lst, True))
+
+if __name__ == "__main__":
+    unittest.main()

pyobjc/Modules/AppKit/_AppKitMapping.m

 #include "_AppKitMapping_NSApplication.m"
 #include "_AppKitMapping_NSBezierPath.m"
 #include "_AppKitMapping_NSBitmap.m"
+#include "_AppKitMapping_NSBitmapImageRep.m"
 #include "_AppKitMapping_NSFont.m"
 #include "_AppKitMapping_NSMatrix.m"
 #include "_AppKitMapping_NSLayoutManager.m"
 	_pyobjc_install_NSApplication();
 	_pyobjc_install_NSBezierPath();
 	_pyobjc_install_NSBitmap();
+	_pyobjc_install_NSBitmapImageRep();
 	_pyobjc_install_NSFont();
 	_pyobjc_install_NSLayoutManager();
 	_pyobjc_install_NSMatrix();

pyobjc/Modules/AppKit/_AppKitMapping_NSBitmapImageRep.m

 /*
  * NSBitmapImageRep mappings for difficult methods:
  *
+ * -getTIFFCompressionTypes:count:	[call]
+ *
  * TODO:
- * -getBitMapDataPlanes:
- * -getTIFFCompressionTypes:count:
+ * * Merge with _AppKitMapping_NSBitMap.m
  * -initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:
  */
 #include <Python.h>
 #include <Foundation/Foundation.h>
 #include "pyobjc-api.h"
 
+static PyObject* call_NSBitmapImageRep_getTIFFCompressionTypes_count_(
+		PyObject* method, PyObject* self, PyObject* arguments)
+{
+	PyObject* result;
+	struct objc_super super;
+	NSTIFFCompression* list;
+	int numTypes;
+
+	if  (!PyArg_ParseTuple(arguments, "")) {
+		return NULL;
+	}
+
+	NS_DURING
+		PyObjC_InitSuperCls(&super,
+			PyObjCSelector_GetClass(method),
+			PyObjCClass_GetClass(self));
+
+		(void)objc_msgSendSuper(&super,
+				PyObjCSelector_GetSelector(method),
+				&list, &numTypes);
+	NS_HANDLER
+		PyObjCErr_FromObjC(localException);
+		list = NULL; numTypes = -1;
+	NS_ENDHANDLER
+
+	if (list == NULL && PyErr_Occurred()) {
+		return NULL;
+	}
+
+	result = PyTuple_New(2);
+	if (result == NULL) {
+		return NULL;
+	}
+
+	PyTuple_SET_ITEM(result, 1, PyInt_FromLong(numTypes));
+	if (PyTuple_GET_ITEM(result, 1) == NULL) {
+		Py_DECREF(result);
+		return NULL;
+	}
+
+	if (numTypes < 0) {
+		PyTuple_SET_ITEM(result, 0, Py_None);
+		Py_INCREF(Py_None);
+	} else {
+		int i;
+		PyObject* v = PyTuple_New(numTypes);
+
+		if (v == NULL) {
+			Py_DECREF(result);
+			return NULL;
+		}
+
+		PyTuple_SET_ITEM(result, 0, v);
+
+		for (i = 0; i < numTypes; i++) {
+			PyObject* o = PyObjC_ObjCToPython(
+				@encode(NSTIFFCompression), 
+				list + i);
+			if (o == NULL) {
+				Py_DECREF(result);
+				return NULL;
+			}
+			PyTuple_SET_ITEM(v, i, o);
+		}
+	}
+
+	return result;
+}
+
 static int 
 _pyobjc_install_NSBitmapImageRep(void)
 {
-	if (PyObjC_RegisterMethodMapping(objc_lookUpClass("NSBitMapImageRep"), 
-		@selector(getBitMapDataPlanes:),
-		PyObjCUnsupportedMethod_Caller,
+	Class class_NSBitmapImageRep = objc_lookUpClass("NSBitmapImageRep");
+
+	if (PyObjC_RegisterMethodMapping(class_NSBitmapImageRep, 
+		@selector(getTIFFCompressionTypes:count:),
+		call_NSBitmapImageRep_getTIFFCompressionTypes_count_,
 		PyObjCUnsupportedMethod_IMP) < 0 ) {
 
 		return -1;
 	}
 
-	if (PyObjC_RegisterMethodMapping(objc_lookUpClass("NSBitMapImageRep"), 
-		@selector(getTIFFCompressionTypes:count:),
-		PyObjCUnsupportedMethod_Caller,
-		PyObjCUnsupportedMethod_IMP) < 0 ) {
-
-		return -1;
-	}
-
-	if (PyObjC_RegisterMethodMapping(objc_lookUpClass("NSBitMapImageRep"), 
+	if (PyObjC_RegisterMethodMapping(class_NSBitmapImageRep, 
 		@selector(initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:),
 		PyObjCUnsupportedMethod_Caller,
 		PyObjCUnsupportedMethod_IMP) < 0 ) {

pyobjc/Scripts/CodeGenerators/strconst_generator.py

 import os
 from dupfile import *
 
-MATCH_RE=re.compile('NSString \*([ ]*const[ ]+)?([A-Za-z_][A-Za-z0-9_]*([ ]*,[ ]*\*[ ]*[A-Za-z_][A-Za-z0-9_]*)*);')
+MATCH_RE=re.compile(r'NSString\s*\*\s*(const\s+)?([A-Za-z_][A-Za-z0-9_]*(\s*,\s\*\s*[A-Za-z_][A-Za-z0-9_]*)*);')
 
 def entry(fp, val, ignore):
     vals = val.split(',')

pyobjc/Scripts/CodeGenerators/var_generator.py

 
 def process_file(outfp, filename, match_prefix='', ignore_list=()):
 
-    MATCH_RE=re.compile('%(match_prefix)s[ ]+(const[ ]+)?(%(IDENT)s)[ ]+(%(IDENT)s[ ]*(,[ ]*%(IDENT)s)*)[ ]*;'%{'match_prefix':match_prefix, 'IDENT':IDENT})
+    MATCH_RE=re.compile(r'%(match_prefix)s\s+(const\s+)?(%(IDENT)s)\s+(%(IDENT)s\s*(,\s*%(IDENT)s)*)\s*;'%{'match_prefix':match_prefix, 'IDENT':IDENT})
 
     fp = open(filename, 'r')
 
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.