summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Henstridge <james@daa.com.au>2000-01-25 09:16:40 +0000
committerJames Henstridge <jamesh@src.gnome.org>2000-01-25 09:16:40 +0000
commit791ec6e44ba24fad732fefec11195c3301748bf2 (patch)
tree1e4efc616b57dc7c596d3fa480b47828fb9bbc5e
parent8dd13267ebec4c06965731a3ca5c8a7cc49a5839 (diff)
downloadpygtk-791ec6e44ba24fad732fefec11195c3301748bf2.tar.gz
use C level GtkObject for hash function. (GtkAccelGroup.__cmp__): use C
2000-01-26 James Henstridge <james@daa.com.au> * gtk.py (GtkObject.__hash__): use C level GtkObject for hash function. (GtkAccelGroup.__cmp__): use C level object for comparisons. (GtkAccelGroup.__hash__): use C level object for hashing. * gtkmodule.c: added hash functions for many object types.
-rw-r--r--ChangeLog9
-rw-r--r--gtk.py9
-rw-r--r--gtkmodule.c85
3 files changed, 89 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index aafe6fa2..2c9d8a33 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2000-01-26 James Henstridge <james@daa.com.au>
+
+ * gtk.py (GtkObject.__hash__): use C level GtkObject for hash
+ function.
+ (GtkAccelGroup.__cmp__): use C level object for comparisons.
+ (GtkAccelGroup.__hash__): use C level object for hashing.
+
+ * gtkmodule.c: added hash functions for many object types.
+
2000-01-25 Kelly Lynn Martin <kelly@poverty.bloomington.in.us>
* gtk.py (gdk_beep): new wrapper
diff --git a/gtk.py b/gtk.py
index 9aaf9833..14b0bc11 100644
--- a/gtk.py
+++ b/gtk.py
@@ -60,6 +60,8 @@ class GtkObject:
return cmp(self._o, other._o)
else:
return cmp(id(self), id(other))
+ def __hash__(self):
+ return hash(self._o)
def __getattr__(self, attr):
# this function allows setting attributes on an object so that
# they will always be available with the object. Due to
@@ -2466,6 +2468,13 @@ class GtkAccelGroup:
def __init__(self, _obj=None):
if _obj: self._ag = _obj; return
self._ag = _gtk.gtk_accel_group_new()
+ def __cmp__(self, other):
+ if hasattr(other, '_ag'):
+ return cmp(self._ag, other._ag)
+ else:
+ return cmp(id(self), id(other))
+ def __hash__(self):
+ return hash(self._ag)
def activate(self, key, mods):
_gtk.gtk_accel_group_activate(self._ag, key, mods)
def attach(self, obj):
diff --git a/gtkmodule.c b/gtkmodule.c
index bd44d412..17744f07 100644
--- a/gtkmodule.c
+++ b/gtkmodule.c
@@ -121,6 +121,11 @@ PyGtk_compare(PyGtk_Object *self, PyGtk_Object *v) {
return 1;
}
+static long
+PyGtk_hash(PyGtk_Object *self) {
+ return (long)self->obj;
+}
+
static PyObject *
PyGtk_repr(PyGtk_Object *self) {
char buf[100];
@@ -147,7 +152,7 @@ static PyTypeObject PyGtk_Type = {
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,
@@ -387,6 +392,10 @@ PyGtkAccelGroup_Compare(PyGtkAccelGroup_Object *self,
return 1;
}
+static long PyGtkAccelGroup_Hash(PyGtkAccelGroup_Object *self) {
+ return (long)self->obj;
+}
+
static PyTypeObject PyGtkAccelGroup_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0,
@@ -402,7 +411,7 @@ static PyTypeObject PyGtkAccelGroup_Type = {
0,
0,
0,
- (hashfunc)0,
+ (hashfunc)PyGtkAccelGroup_Hash,
(ternaryfunc)0,
(reprfunc)0,
0L,0L,0L,0L,
@@ -563,6 +572,10 @@ PyGtkStyle_Compare(PyGtkStyle_Object *self, PyGtkStyle_Object *v) {
return 1;
}
+static long PyGtkStyle_Hash(PyGtkStyle_Object *self) {
+ return (long)self->obj;
+}
+
static PyObject *PyGtkStyle_copy(PyGtkStyle_Object *self, PyObject *args) {
GtkStyle *style;
PyObject *ret;
@@ -705,7 +718,7 @@ static PyTypeObject PyGtkStyle_Type = {
0,
0,
0,
- (hashfunc)0,
+ (hashfunc)PyGtkStyle_Hash,
(ternaryfunc)0,
(reprfunc)0,
0L,0L,0L,0L,
@@ -787,6 +800,10 @@ PyGdkFont_Compare(PyGdkFont_Object *self, PyGdkFont_Object *v) {
return 1;
}
+static long PyGdkFont_Hash(PyGdkFont_Object *self) {
+ return (long)self->obj;
+}
+
static PyTypeObject PyGdkFont_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0,
@@ -802,7 +819,7 @@ static PyTypeObject PyGdkFont_Type = {
0,
0,
0,
- (hashfunc)0,
+ (hashfunc)PyGdkFont_Hash,
(ternaryfunc)0,
(reprfunc)0,
0L,0L,0L,0L,
@@ -849,6 +866,10 @@ PyGdkColor_Compare(PyGdkColor_Object *self, PyGdkColor_Object *v) {
return 1;
}
+static long PyGdkColor_Hash(PyGdkColor_Object *self) {
+ return (long)self->obj.pixel;
+}
+
static PyObject *
PyGdkColor_Repr(PyGdkColor_Object *self) {
char buf[80];
@@ -873,7 +894,7 @@ static PyTypeObject PyGdkColor_Type = {
0,
0,
0,
- (hashfunc)0,
+ (hashfunc)PyGdkColor_Hash,
(ternaryfunc)0,
(reprfunc)0,
0L,0L,0L,0L,
@@ -1253,6 +1274,10 @@ PyGdkEvent_Compare(PyGdkEvent_Object *self, PyGdkEvent_Object *v) {
return 1;
}
+static long PyGdkEvent_Hash(PyGdkEvent_Object *self) {
+ return (long)self->obj;
+}
+
static PyTypeObject PyGdkEvent_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0,
@@ -1268,7 +1293,7 @@ static PyTypeObject PyGdkEvent_Type = {
0,
0,
0,
- (hashfunc)0,
+ (hashfunc)PyGdkEvent_Hash,
(ternaryfunc)0,
(reprfunc)0,
0L,0L,0L,0L,
@@ -1291,6 +1316,10 @@ PyGdkWindow_Compare(PyGdkWindow_Object *self, PyGdkWindow_Object *v) {
return 1;
}
+static long PyGdkWindow_Hash(PyGdkWindow_Object *self) {
+ return (long)self->obj;
+}
+
static PyObject *
PyGdkWindow_Repr(PyGdkWindow_Object *self) {
char buf[100];
@@ -1730,7 +1759,7 @@ static PyTypeObject PyGdkWindow_Type = {
0,
0,
0,
- (hashfunc)0,
+ (hashfunc)PyGdkWindow_Hash,
(ternaryfunc)0,
(reprfunc)0,
0L,0L,0L,0L,
@@ -1901,6 +1930,10 @@ PyGdkGC_Compare(PyGdkGC_Object *self, PyGdkGC_Object *v) {
return 1;
}
+static long PyGdkGC_Hash(PyGdkGC_Object *self) {
+ return (long)self->obj;
+}
+
static PyTypeObject PyGdkGC_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0,
@@ -1916,7 +1949,7 @@ static PyTypeObject PyGdkGC_Type = {
0,
0,
0,
- (hashfunc)0,
+ (hashfunc)PyGdkGC_Hash,
(ternaryfunc)0,
(reprfunc)0,
0L,0L,0L,0L,
@@ -1967,6 +2000,10 @@ PyGdkColormap_Compare(PyGdkColormap_Object *self, PyGdkColormap_Object *v) {
return 1;
}
+static long PyGdkColormap_Hash(PyGdkColormap_Object *self) {
+ return (long)self->obj;
+}
+
static int
PyGdkColormap_Length(PyGdkColormap_Object *self) {
return self->obj->size;
@@ -2022,7 +2059,7 @@ static PyTypeObject PyGdkColormap_Type = {
0,
&PyGdkColormap_Sequence,
0,
- (hashfunc)0,
+ (hashfunc)PyGdkColormap_Hash,
(ternaryfunc)0,
(reprfunc)0,
0L,0L,0L,0L,
@@ -2043,6 +2080,10 @@ PyGdkDragContext_Compare(PyGdkDragContext_Object *self,
return 1;
}
+static long PyGdkDragContext_Hash(PyGdkDragContext_Object *self) {
+ return (long)self->obj;
+}
+
static PyObject *
PyGdkDragContext_GetAttr(PyGdkDragContext_Object *self, char *key) {
if (!strcmp(key, "__members__"))
@@ -2109,7 +2150,7 @@ static PyTypeObject PyGdkDragContext_Type = {
0,
0,
0,
- (hashfunc)0,
+ (hashfunc)PyGdkDragContext_Hash,
(ternaryfunc)0,
(reprfunc)0,
0L,0L,0L,0L,
@@ -2129,6 +2170,10 @@ PyGtkSelectionData_Compare(PyGtkSelectionData_Object *self,
return 1;
}
+static long PyGtkSelectionData_Hash(PyGtkSelectionData_Object *self) {
+ return (long)self->obj;
+}
+
static PyObject *
PyGtkSelectionData_Set(PyGtkSelectionData_Object *self, PyObject *args) {
GdkAtom type;
@@ -2181,7 +2226,7 @@ static PyTypeObject PyGtkSelectionData_Type = {
0,
0,
0,
- (hashfunc)0,
+ (hashfunc)PyGtkSelectionData_Hash,
(ternaryfunc)0,
(reprfunc)0,
0L,0L,0L,0L,
@@ -2201,6 +2246,10 @@ PyGdkAtom_Compare(PyGdkAtom_Object *self, PyGdkAtom_Object *v) {
return 1;
}
+static long PyGdkAtom_Hash(PyGdkAtom_Object *self) {
+ return (long)self->atom;
+}
+
static PyObject *
PyGdkAtom_Repr(PyGdkAtom_Object *self) {
char buf[256];
@@ -2317,7 +2366,7 @@ static PyTypeObject PyGdkAtom_Type = {
&PyGdkAtom_Number,
0,
0,
- (hashfunc)0,
+ (hashfunc)PyGdkAtom_Hash,
(ternaryfunc)0,
(reprfunc)PyGdkAtom_Str,
0L,0L,0L,0L,
@@ -2337,6 +2386,10 @@ PyGdkCursor_Compare(PyGdkCursor_Object *self, PyGdkCursor_Object *v) {
return 1;
}
+static long PyGdkCursor_Hash(PyGdkCursor_Object *self) {
+ return (long)self->obj;
+}
+
static PyObject *
PyGdkCursor_Repr(PyGdkCursor_Object *self) {
char buf[256], *cname = NULL;
@@ -2385,7 +2438,7 @@ static PyTypeObject PyGdkCursor_Type = {
0,
0,
0,
- (hashfunc)0,
+ (hashfunc)PyGdkCursor_Hash,
(ternaryfunc)0,
(reprfunc)0,
0L,0L,0L,0L,
@@ -2403,6 +2456,10 @@ static int PyGtkCTreeNode_Compare(PyGtkCTreeNode_Object *self,
return 1;
}
+static long PyGtkCTreeNode_Hash(PyGtkCTreeNode_Object *self) {
+ return (long)self->node;
+}
+
static PyObject *PyGtkCTreeNode_GetAttr(PyGtkCTreeNode_Object *self,
char *key) {
if (!strcmp(key, "__members__"))
@@ -2461,7 +2518,7 @@ static PyTypeObject PyGtkCTreeNode_Type = {
0,
0,
0,
- (hashfunc)0,
+ (hashfunc)PyGtkCTreeNode_Hash,
(ternaryfunc)0,
(reprfunc)0,
0L,0L,0L,0L,