[Skencil-commits] r688 - in skencil/branches/skencil-0.6: . Pax Sketch/UI

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Jun 14 23:13:19 CEST 2006


Author: bh
Date: 2006-06-14 23:13:18 +0200 (Wed, 14 Jun 2006)
New Revision: 688

Modified:
   skencil/branches/skencil-0.6/ChangeLog
   skencil/branches/skencil-0.6/Pax/paxmodule.c
   skencil/branches/skencil-0.6/Sketch/UI/tkext.py
Log:

Make Skencil work with Python 2.5.  In 2.5, the id of an object is
always positive and may be a python long.  This breaks some
assumptions made in paxtkinter.

* Pax/paxmodule.c (register_object, unregister_object)
(key_for_object): Refactor the creation of the string for the
object registry into the new function key_for_object
(register_object): return the key used for the object in the
registry.

* Sketch/UI/tkext.py (PyWidget.__init__, MakeMethodCommand): Pass
the key returned by register_object to the tcl functions.


Modified: skencil/branches/skencil-0.6/ChangeLog
===================================================================
--- skencil/branches/skencil-0.6/ChangeLog	2006-06-13 22:18:39 UTC (rev 687)
+++ skencil/branches/skencil-0.6/ChangeLog	2006-06-14 21:13:18 UTC (rev 688)
@@ -1,5 +1,20 @@
 2006-06-14  Bernhard Herzog  <bh at intevation.de>
 
+	Make Skencil work with Python 2.5.  In 2.5, the id of an object is
+	always positive and may be a python long.  This breaks some
+	assumptions made in paxtkinter.
+
+	* Pax/paxmodule.c (register_object, unregister_object)
+	(key_for_object): Refactor the creation of the string for the
+	object registry into the new function key_for_object
+	(register_object): return the key used for the object in the
+	registry.
+
+	* Sketch/UI/tkext.py (PyWidget.__init__, MakeMethodCommand): Pass
+	the key returned by register_object to the tcl functions.
+
+2006-06-14  Bernhard Herzog  <bh at intevation.de>
+
 	* Sketch/Modules/_sketchmodule.c (init_sketch): Silence a compiler
 	warning.
 

Modified: skencil/branches/skencil-0.6/Pax/paxmodule.c
===================================================================
--- skencil/branches/skencil-0.6/Pax/paxmodule.c	2006-06-13 22:18:39 UTC (rev 687)
+++ skencil/branches/skencil-0.6/Pax/paxmodule.c	2006-06-14 21:13:18 UTC (rev 688)
@@ -675,12 +675,18 @@
     return PyInt_FromLong(Tcl_DoOneEvent(flags));
 }
 
+static PyObject *
+key_for_object(PyObject *obj)
+{
+    char id[20];
+    sprintf(id, "%ld", (long)obj);
+    return PyString_FromString(id);
+}
 
 static PyObject *
 register_object(PyObject * self, PyObject * args)
 {
-    PyObject * obj;
-    char id[20];
+    PyObject * obj, *key;
     int result;
 
     if (!PyArg_ParseTuple(args, "O", &obj))
@@ -693,21 +699,22 @@
 	    return NULL;
     }
 
-    sprintf(id, "%ld", (long)obj);
-    result = PyDict_SetItemString(object_registry, id, obj);
+    key = key_for_object(obj);
+    result = PyDict_SetItem(object_registry, key, obj);
 
     if (result < 0)
+    {
+	Py_DECREF(key);
 	return NULL;
+    }
 
-    Py_INCREF(Py_None);
-    return Py_None;
+    return key;
 }
 
 static PyObject *
 unregister_object(PyObject * self, PyObject * args)
 {
     PyObject * obj;
-    char id[20];
     int result;
 
     if (!PyArg_ParseTuple(args, "O", &obj))
@@ -715,10 +722,11 @@
 
     if (object_registry)
     {
-	sprintf(id, "%ld", (long)obj);
-	result = PyDict_DelItemString(object_registry, id);
+	PyObject *key = key_for_object(obj);
+	result = PyDict_DelItem(object_registry, key);
 	if (result < 0)
 	    PyErr_Clear();
+	Py_DECREF(key);
     }
     Py_INCREF(Py_None);
     return Py_None;

Modified: skencil/branches/skencil-0.6/Sketch/UI/tkext.py
===================================================================
--- skencil/branches/skencil-0.6/Sketch/UI/tkext.py	2006-06-13 22:18:39 UTC (rev 687)
+++ skencil/branches/skencil-0.6/Sketch/UI/tkext.py	2006-06-14 21:13:18 UTC (rev 688)
@@ -665,8 +665,8 @@
 class PyWidget(Widget, SketchDropTarget):
 
     def __init__(self, master=None, **kw):
-	pax.register_object(self)
-	kw['pyobject'] = id(self)
+	key = pax.register_object(self)
+	kw['pyobject'] = key
 	kw['class'] = self.__class__.__name__
 	Widget.__init__(self, master, 'paxwidget', kw = kw)
 
@@ -904,8 +904,8 @@
 def MakeMethodCommand(method, *args):
     obj = method.im_self
     name = method.__name__
-    pax.register_object(obj) # assuming that obj unregisters itself
-    return ('call_py_method', id(obj), name) + args
+    key = pax.register_object(obj) # assuming that obj unregisters itself
+    return ('call_py_method', key, name) + args
 
 
 _tcl_commands_created = 0



More information about the Skencil-commits mailing list