Attached is a patch against pygtk 0.6.5 that:
 * adds wrappers for gdk keyval functions
 * changes the gdk window's set_cursor method so it accepts None as a
   valid cursor value (& maps it to NULL when calling the C function)
 * eliminates a memory leak in PyGtk_item_factory_cb when the Python
   callback raise an exception.

I looked at pygtk 0.6.5 briefly and it looks like this patch should still
be work with it, but unfortunately I don't have the time to upgrade and
test against it right now.  I can do this in a few weeks if needed and
I can also split the patch up into 3 pieces if that will make it easier to
review.

Thanks,

John

------------------------------------------------------------------------
Archaeopteryx Software, Inc.                        Wing IDE for Python 
www.archaeopteryx.com                               Take Flight!

*** /home/jpe/down/pygtk-0.6.5/gtk.py   Mon Mar 13 04:04:14 2000
--- ./gtk.py    Wed Jul  5 18:18:21 2000
***************
*** 2729,2734 ****
--- 2731,2742 ----
        def draw_array(drawable, gc, x, y, dither, array):
                _gtk.gdk_draw_array(drawable, gc, x, y, dither, array)
  
+ # keyval functions
+ keyval_name = _gtk.gdk_keyval_name
+ keyval_is_upper = _gtk.gdk_keyval_is_upper
+ keyval_is_lower = _gtk.gdk_keyval_is_lower
+ keyval_to_upper = _gtk.gdk_keyval_to_upper
+ keyval_to_lower = _gtk.gdk_keyval_to_lower
  
  # screen size
  def screen_width():
*** /home/jpe/down/pygtk-0.6.5/gtkmodule.c      Mon Mar 13 04:04:14 2000
--- ./gtkmodule.c       Wed Jul 12 11:32:43 2000
***************
*** 1446,1455 ****
                                       PyObject *args) {
    PyObject *cursor;
  
!   if (!PyArg_ParseTuple(args, "O!:GdkWindow.set_cursor", &PyGdkCursor_Type,
!                       &cursor))
      return NULL;
!   gdk_window_set_cursor(self->obj, PyGdkCursor_Get(cursor));
    Py_INCREF(Py_None);
    return Py_None;
  }
--- 1446,1463 ----
                                       PyObject *args) {
    PyObject *cursor;
  
!   if (!PyArg_ParseTuple(args, "O:GdkWindow.set_cursor", &cursor))
      return NULL;
!   if (PyGdkCursor_Check(cursor))
!     gdk_window_set_cursor(self->obj, PyGdkCursor_Get(cursor));
!   else if (cursor == Py_None)
!     gdk_window_set_cursor(self->obj, NULL);
!   else {
!     PyErr_SetString(PyExc_TypeError, 
!                     "cursor must either be a GdkCursor instance or None");
!     return NULL;
!   }
! 
    Py_INCREF(Py_None);
    return Py_None;
  }
***************
*** 4733,4752 ****
  
  static void PyGtk_item_factory_cb(PyObject *callback, guint action,
                                  GtkWidget *widget) {
!   PyObject *ret;
  
    PyGTK_BLOCK_THREADS
!   ret = PyObject_CallFunction(callback, "iO", action,
!                             PyGtk_New((GtkObject *)widget));
!   if (ret == NULL) {
      if (PyGtk_FatalExceptions)
        gtk_main_quit();
      else {
        PyErr_Print();
        PyErr_Clear();
      }
!   } else
!     Py_DECREF(ret);
    PyGTK_UNBLOCK_THREADS
  }
  
--- 4741,4764 ----
  
  static void PyGtk_item_factory_cb(PyObject *callback, guint action,
                                  GtkWidget *widget) {
!   PyObject *ret = NULL;
!   PyObject *py_widget = NULL;
  
    PyGTK_BLOCK_THREADS
! 
!   py_widget = PyGtk_New((GtkObject *)widget);
!   if ( py_widget != NULL ) 
!     ret = PyObject_CallFunction(callback, "iO", action, py_widget);
!   if (ret == NULL || py_widget == NULL) {
      if (PyGtk_FatalExceptions)
        gtk_main_quit();
      else {
        PyErr_Print();
        PyErr_Clear();
      }
!   }
!   Py_XDECREF(ret);
!   Py_XDECREF(py_widget);
    PyGTK_UNBLOCK_THREADS
  }
  
***************
*** 6387,6392 ****
--- 6399,6473 ----
  }
  #endif
  
+ static PyObject* _wrap_gdk_keyval_name(PyObject* self, PyObject* args) {
+     unsigned int keyval;
+     const char* name;
+ 
+     if (!PyArg_ParseTuple(args, "i:gdk_keyval_name", &keyval))
+         return NULL;
+ 
+     name = gdk_keyval_name(keyval);
+     return Py_BuildValue("s", name);
+ }
+ 
+ static PyObject* _wrap_gdk_keyval_is_upper(PyObject* self, PyObject* args) {
+     unsigned int keyval;
+     int is_upper;
+ 
+     if (!PyArg_ParseTuple(args, "i:gdk_keyval_is_upper", &keyval))
+         return NULL;
+ 
+     is_upper = gdk_keyval_is_upper(keyval);
+     if ( is_upper ) {
+         Py_INCREF(Py_True);
+       return Py_True;
+     }
+     else {
+         Py_INCREF(Py_False);
+       return Py_False;
+     }
+ }
+ 
+ static PyObject* _wrap_gdk_keyval_is_lower(PyObject* self, PyObject* args) {
+     unsigned int keyval;
+     int is_lower;
+ 
+     if (!PyArg_ParseTuple(args, "i:gdk_keyval_is_lower", &keyval))
+         return NULL;
+ 
+     is_lower = gdk_keyval_is_lower(keyval);
+     if ( is_lower ) {
+         Py_INCREF(Py_True);
+       return Py_True;
+     }
+     else {
+         Py_INCREF(Py_False);
+       return Py_False;
+     }
+ }
+ 
+ static PyObject* _wrap_gdk_keyval_to_upper(PyObject* self, PyObject* args) {
+     unsigned int keyval;
+     unsigned int upper_val;
+ 
+     if (!PyArg_ParseTuple(args, "i:gdk_keyval_to_upper", &keyval))
+         return NULL;
+ 
+     upper_val = gdk_keyval_to_upper(keyval);
+     return Py_BuildValue("i", upper_val);
+ }
+ 
+ static PyObject* _wrap_gdk_keyval_to_lower(PyObject* self, PyObject* args) {
+     unsigned int keyval;
+     unsigned int lower_val;
+ 
+     if (!PyArg_ParseTuple(args, "i:gdk_keyval_to_lower", &keyval))
+         return NULL;
+ 
+     lower_val = gdk_keyval_to_lower(keyval);
+     return Py_BuildValue("i", lower_val);
+ }
+ 
  static PyMethodDef _gtkmoduleMethods[] = {
      { "gtk_signal_connect", _wrap_gtk_signal_connect, 1 },
      { "gtk_signal_connect_after", _wrap_gtk_signal_connect_after, 1 },
***************
*** 6527,6532 ****
--- 6608,6618 ----
  #ifdef HAVE_NUMPY
      { "gdk_draw_array", _wrap_gdk_draw_array, 1 },
  #endif
+     { "gdk_keyval_name", _wrap_gdk_keyval_name, 1 },
+     { "gdk_keyval_is_upper", _wrap_gdk_keyval_is_upper, 1 },
+     { "gdk_keyval_is_lower", _wrap_gdk_keyval_is_lower, 1 },
+     { "gdk_keyval_to_upper", _wrap_gdk_keyval_to_upper, 1 },
+     { "gdk_keyval_to_lower", _wrap_gdk_keyval_to_lower, 1 },
      { NULL, NULL }
  };
  

Reply via email to