Hello,
Attached is a patch for gtk.py and gtkmodule.c made against the
pygtk-0.6.4 source distribution. The fixes the following problems:
* __getattr__ for a GtkTreeItem had a typo and would return an extension
object for subtree instead of a Python class instance.
* GtkNotebook.set_menu_label_text was calling down to
_gtk.gtk_notebook_set_menu_label instead of
_gtk.gtk_notebook_set_menu_label_text.
* GtkToolbar was not wrapping callbacks passed to
{append|insert|prepend}_item so the callbacks were receiving references
to extension objects rather than class instances.
* In GtkArg_AsPyObject, the code for GTK_TYPE_OBJECT was not checking
to see if the object pointer was NULL.
* The {clist|ctree}_get_{pixmap|pixtext} now check to see if the pixmap
pointer is NULL and return None if it is.
Please let me know if there are any questions about these changes or if I
should break this patch up into smaller pieces.
Thanks,
John
diff -c -r /home/jpe/down/pygtk-0.6.4/gtk.py ./gtk.py
*** /home/jpe/down/pygtk-0.6.4/gtk.py Wed Feb 16 09:57:02 2000
--- ./gtk.py Mon Feb 28 13:32:39 2000
***************
*** 786,795 ****
else:
self._o = _gtk.gtk_tree_item_new_with_label(label)
def __getattr__(self, attr):
attrs = {
! 'subtree': _gtk.gtk_tree_item_get_subtree,
}
! if attrs.has_key(attrs):
return attrs[attr](self._o)
return GtkItem.__getattr__(self, attr)
def set_subtree(self, subtree):
--- 786,798 ----
else:
self._o = _gtk.gtk_tree_item_new_with_label(label)
def __getattr__(self, attr):
+ def get_subtree_wrap(o):
+ if o == None: return None
+ else: return _obj2inst(o)
attrs = {
! 'subtree': get_subtree_wrap,
}
! if attrs.has_key(attr):
return attrs[attr](self._o)
return GtkItem.__getattr__(self, attr)
def set_subtree(self, subtree):
***************
*** 1707,1713 ****
_gtk.gtk_notebook_set_menu_label(self._o, child._o,
menu_label._o)
def set_menu_label_text(self, child, menu_text):
! _gtk.gtk_notebook_set_menu_label(self._o, child._o, menu_text)
def query_tab_label_packing(self, child):
# returns (expand,fill,pack_type)
return _gtk.gtk_notebook_query_tab_label_packing(self._o,
--- 1710,1717 ----
_gtk.gtk_notebook_set_menu_label(self._o, child._o,
menu_label._o)
def set_menu_label_text(self, child, menu_text):
! _gtk.gtk_notebook_set_menu_label_text(self._o, child._o,
! menu_text)
def query_tab_label_packing(self, child):
# returns (expand,fill,pack_type)
return _gtk.gtk_notebook_query_tab_label_packing(self._o,
***************
*** 1898,1924 ****
class GtkToolbar(GtkContainer):
get_type = _gtk.gtk_toolbar_get_type
def __init__(self, orientation=ORIENTATION_HORIZONTAL,
style=TOOLBAR_ICONS, _obj=None):
if _obj: self._o = _obj; return
self._o = _gtk.gtk_toolbar_new(orientation, style)
def append_item(self, text, tooltip, tp, icon, callback):
return _obj2inst(_gtk.gtk_toolbar_append_item(
! self._o, text, tooltip, tp, icon._o, callback))
def append_space(self):
_gtk.gtk_toolbar_append_space(self._o)
def append_widget(self, w, tooltip, tp):
_gtk.gtk_toolbar_append_widget(self._o, w._o, tooltip, tp)
def insert_item(self, text, tooltip, tp, icon, callback, pos):
return _obj2inst(_gtk.gtk_toolbar_insert_item(
! self._o, text, tooltip, tp, icon._o, callback, pos))
def insert_space(self, pos):
_gtk.gtk_toolbar_insert_space(self._o, pos)
def insert_widget(self, w, tooltip, tp, pos):
_gtk.gtk_toolbar_insert_widget(self._o, w._o, tooltip, tp, pos)
def prepend_item(self, text, tooltip, tp, icon, callback):
return _obj2inst(_gtk.gtk_toolbar_prepend_item(
! self._o, text, tooltip, tp, icon._o, callback))
def prepend_space(self):
_gtk.gtk_toolbar_prepend_space(self._o)
def prepend_widget(self, w, tooltip, tp):
--- 1902,1936 ----
class GtkToolbar(GtkContainer):
get_type = _gtk.gtk_toolbar_get_type
+ class __wrap_cb:
+ def __init__(self, cb):
+ self.cb = cb
+ def __call__(self, widget):
+ self.cb(_obj2inst(widget))
def __init__(self, orientation=ORIENTATION_HORIZONTAL,
style=TOOLBAR_ICONS, _obj=None):
if _obj: self._o = _obj; return
self._o = _gtk.gtk_toolbar_new(orientation, style)
def append_item(self, text, tooltip, tp, icon, callback):
return _obj2inst(_gtk.gtk_toolbar_append_item(
! self._o, text, tooltip, tp, icon._o,
! self.__wrap_cb(callback)))
def append_space(self):
_gtk.gtk_toolbar_append_space(self._o)
def append_widget(self, w, tooltip, tp):
_gtk.gtk_toolbar_append_widget(self._o, w._o, tooltip, tp)
def insert_item(self, text, tooltip, tp, icon, callback, pos):
return _obj2inst(_gtk.gtk_toolbar_insert_item(
! self._o, text, tooltip, tp, icon._o,
! self.__wrap_cb(callback), pos))
def insert_space(self, pos):
_gtk.gtk_toolbar_insert_space(self._o, pos)
def insert_widget(self, w, tooltip, tp, pos):
_gtk.gtk_toolbar_insert_widget(self._o, w._o, tooltip, tp, pos)
def prepend_item(self, text, tooltip, tp, icon, callback):
return _obj2inst(_gtk.gtk_toolbar_prepend_item(
! self._o, text, tooltip, tp, icon._o,
! self.__wrap_cb(callback)))
def prepend_space(self):
_gtk.gtk_toolbar_prepend_space(self._o)
def prepend_widget(self, w, tooltip, tp):
diff -c -r /home/jpe/down/pygtk-0.6.4/gtkmodule.c ./gtkmodule.c
*** /home/jpe/down/pygtk-0.6.4/gtkmodule.c Wed Feb 16 09:57:02 2000
--- ./gtkmodule.c Mon Feb 28 13:45:29 2000
***************
*** 2813,2819 ****
return GtkArgs_AsTuple(GTK_VALUE_ARGS(*arg).n_args,
GTK_VALUE_ARGS(*arg).args);
case GTK_TYPE_OBJECT:
! return PyGtk_New(GTK_VALUE_OBJECT(*arg));
case GTK_TYPE_POINTER:
return PyCObject_FromVoidPtr(GTK_VALUE_POINTER(*arg), NULL);
case GTK_TYPE_BOXED:
--- 2813,2824 ----
return GtkArgs_AsTuple(GTK_VALUE_ARGS(*arg).n_args,
GTK_VALUE_ARGS(*arg).args);
case GTK_TYPE_OBJECT:
! if ( GTK_VALUE_OBJECT(*arg) != NULL )
! return PyGtk_New(GTK_VALUE_OBJECT(*arg));
! else {
! Py_INCREF(Py_None);
! return Py_None;
! }
case GTK_TYPE_POINTER:
return PyCObject_FromVoidPtr(GTK_VALUE_POINTER(*arg), NULL);
case GTK_TYPE_BOXED:
***************
*** 4401,4407 ****
}
static PyObject *_wrap_gtk_clist_get_pixmap(PyObject *self, PyObject *args) {
! PyObject *o, *mask;
int r, c;
GdkPixmap *p;
GdkBitmap *m;
--- 4406,4412 ----
}
static PyObject *_wrap_gtk_clist_get_pixmap(PyObject *self, PyObject *args) {
! PyObject *o, *mask, *pixmap;
int r, c;
GdkPixmap *p;
GdkBitmap *m;
***************
*** 4419,4429 ****
Py_INCREF(Py_None);
mask = Py_None;
}
! return Py_BuildValue("(NN)", PyGdkWindow_New(p), mask);
}
static PyObject *_wrap_gtk_clist_get_pixtext(PyObject *self, PyObject *args) {
! PyObject *o, *mask;
int r, c;
guint8 spacing;
char *text;
--- 4424,4441 ----
Py_INCREF(Py_None);
mask = Py_None;
}
! if ( p != None )
! pixmap = PyGdkWindow_New(p);
! else {
! Py_INCREF(Py_None);
! pixmap = Py_None;
! }
!
! return Py_BuildValue("(NN)", pixmap, mask);
}
static PyObject *_wrap_gtk_clist_get_pixtext(PyObject *self, PyObject *args) {
! PyObject *o, *mask, *pixmap;
int r, c;
guint8 spacing;
char *text;
***************
*** 4444,4451 ****
Py_INCREF(Py_None);
mask = Py_None;
}
! return Py_BuildValue("(siNN)", text, (int)spacing,
! PyGdkWindow_New(p), mask);
}
static PyObject *_wrap_gtk_clist_prepend(PyObject *self, PyObject *args) {
--- 4456,4469 ----
Py_INCREF(Py_None);
mask = Py_None;
}
! if ( p != None )
! pixmap = PyGdkWindow_New(p);
! else {
! Py_INCREF(Py_None);
! pixmap = Py_None;
! }
!
! return Py_BuildValue("(siNN)", text, (int)spacing, pixmap, mask);
}
static PyObject *_wrap_gtk_clist_prepend(PyObject *self, PyObject *args) {
***************
*** 6035,6041 ****
}
static PyObject *_wrap_gtk_ctree_node_get_pixmap(PyObject *self, PyObject *args) {
! PyObject *ctree, *node, *mask;
int col;
GdkPixmap *p;
GdkBitmap *m;
--- 6053,6059 ----
}
static PyObject *_wrap_gtk_ctree_node_get_pixmap(PyObject *self, PyObject *args) {
! PyObject *ctree, *node, *mask, *pixmap;
int col;
GdkPixmap *p;
GdkBitmap *m;
***************
*** 6054,6064 ****
Py_INCREF(Py_None);
mask = Py_None;
}
! return Py_BuildValue("(NN)", PyGdkWindow_New(p), mask);
}
static PyObject *_wrap_gtk_ctree_node_get_pixtext(PyObject *self, PyObject *args) {
! PyObject *ctree, *node, *mask;
int col;
guint8 spacing;
char *text;
--- 6072,6089 ----
Py_INCREF(Py_None);
mask = Py_None;
}
! if ( p != None )
! pixmap = PyGdkWindow_New(p);
! else {
! Py_INCREF(Py_None);
! pixmap = Py_None;
! }
!
! return Py_BuildValue("(NN)", pixmap, mask);
}
static PyObject *_wrap_gtk_ctree_node_get_pixtext(PyObject *self, PyObject *args) {
! PyObject *ctree, *node, *mask, *pixmap;
int col;
guint8 spacing;
char *text;
***************
*** 6080,6087 ****
Py_INCREF(Py_None);
mask = Py_None;
}
! return Py_BuildValue("(siNN)", text, (int)spacing,
! PyGdkWindow_New(p), mask);
}
static PyObject *_wrap_gtk_ctree_get_node_info(PyObject *self, PyObject *args) {
--- 6105,6118 ----
Py_INCREF(Py_None);
mask = Py_None;
}
! if ( p != None )
! pixmap = PyGdkWindow_New(p);
! else {
! Py_INCREF(Py_None);
! pixmap = Py_None;
! }
!
! return Py_BuildValue("(siNN)", text, (int)spacing, pixmap, mask);
}
static PyObject *_wrap_gtk_ctree_get_node_info(PyObject *self, PyObject *args) {