[pygtk] GdkColormap.alloc()

Frank Warmerdam warmerda@home.com
Tue, 22 Aug 2000 22:39:57 -0500


James,

I have encountered a problem using GdkColormap.alloc() on IRIX and Sun systems, 
and I believe it is because of your unwarranted assumption that the red, green,
and blue components of a GdkColor are ints, when they are in fact shorts.

struct _GdkColor
{
  gulong  pixel;
  gushort red;
  gushort green;
  gushort blue;
};

While I actually applied my patch against pygtk-0.6.4, the code for the
function seems identical in 0.6.6 which is the most recent release (right?).
Anyways, here is one patch.  I would really appreciate this making it into
the next pygtk release.  In the meantime I will need to hand build pygtk for
distribution with OpenEV (openev.sourceforge.net). 

static PyObject *
PyGdkColor_Alloc(PyGdkColormap_Object *self, PyObject *args) {
  GdkColor color = {0, 0, 0, 0};
  int   red, green, blue;
  gchar *color_name;
  if (!PyArg_ParseTuple(args, "iii:GdkColormap.alloc",
                        &(red), &(green), &(blue))) {
    PyErr_Clear();
    if (!PyArg_ParseTuple(args, "s:GdkColormap.alloc", &color_name))
      return NULL;
    if (!gdk_color_parse(color_name, &color)) {
      PyErr_SetString(PyExc_TypeError, "unable to parse color specification");
      return NULL;
    }
  }
  else
  {
    color.red = red;
    color.green = green;
    color.blue = blue;
  }

  if (!gdk_color_alloc(self->obj, &color)) {
    PyErr_SetString(PyExc_RuntimeError, "couldn't allocate color");
    return NULL;
  }
  return PyGdkColor_New(&color);
}

Finally, I really appreciate the excellent work you have done with pygtk.

Best regards,

---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerda@home.com
light and sound - activate the windows | http://members.home.com/warmerda
and watch the world go round - Rush    | Geospatial Programmer for Rent