Hello James,
GtkObject types compare on identity of the corresponding gtk objects,
but there is no hash function defined (so they can't be used as
dictionary keys). It could be trivially defined like in the appended
patch (line numbers don't correspond to cvs version!).
Would you accept such a patch, also for the other types in gtkmodule.c
which compare on identity?
ciao
Andreas
--- gtkmodule.c Wed Nov 10 10:51:20 1999
+++ gtkmodule.c.neu Wed Nov 10 10:50:31 1999
@@ -129,6 +129,11 @@
return PyString_FromString(buf);
}
+static long
+PyGtk_hash(PyGtk_Object *self) {
+ return (long)PyGtk_Get(self);
+}
+
static char PyGtk_Type__doc__[] = "This is the type of GTK Objects";
static PyTypeObject PyGtk_Type = {
@@ -146,7 +151,7 @@
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
- (hashfunc)0, /*tp_hash*/
+ (hashfunc)PyGtk_hash, /*tp_hash*/
(ternaryfunc)0, /*tp_call*/
(reprfunc)0, /*tp_str*/
0L,0L,0L,0L,
--- gtk.py Wed Sep 29 03:18:42 1999
+++ /usr/lib/python1.5/site-packages/gtk.py Tue Nov 9 11:21:31 1999
@@ -57,6 +70,11 @@
return cmp(self._o, other._o)
else:
return cmp(id(self), id(other))
+ def __hash__(self):
+ if hasattr(self,'_o'):
+ return hash(self._o)
+ else:
+ raise TypeError, "unhashable instance of GtkObject"
def __getattr__(self, attr):
# this function allows setting attributes on an object so that
# they will always be available with the object. Due to
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]