Creating and using a wxCursor under GTK?

Has anyone done this successfully? I have code that can do it under Windows,
but I'm not sure where the problem is with GTK.

(I have an XBM version of the image, I create a wxCursor instance, but when
passing it to SetCursor, I get "Expected _wxCursor_p.")

Thanks!
Robb

Robb Shecter wrote:

Has anyone done this successfully? I have code that can do it under Windows, but I'm not sure where the problem is with GTK.

(I have an XBM version of the image, I create a wxCursor instance, but when passing it to SetCursor, I get "Expected _wxCursor_p.")

Apparently sometime in the distant past that constructor caused a compile error so I had it ifdef'd out for wxPython. I've added it back in for 2.4.1.

Have you tried wxCursorFromImage?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Robb Shecter wrote:

Has anyone done this successfully? I have code that can do it under Windows, but I'm not sure where the problem is with GTK.

(I have an XBM version of the image, I create a wxCursor instance, but when passing it to SetCursor, I get "Expected _wxCursor_p.")

Apparently sometime in the distant past that constructor caused a compile error so I had it ifdef'd out for wxPython. I've added it back in for 2.4.1.

Seems I was a bit hasty. wxGTK still doesn't have the wxCursor constructor to load from a file. All the platforms do have a ctor that can use XBM style data though, so I'll add this:

wxCursor* wxCursorFromBits(PyObject* bits, int width, int height,
                            int hotSpotX=-1, int hotSpotY=-1,
                            PyObject* maskBits=0);

Where bits and maskBits are strings. XBM files normally look something like this:

#define caution_width 32
#define caution_height 32
static char caution_bits = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x10,0x01,
0x00,0x00,0x08,0x07,0x00,0x00,0x08,0x0e,0x00,0x00,0x04,0x0e,0x00,0x00,0x04,
0x1c,0x00,0x00,0x02,0x1c,0x00,0x00,0xe2,0x38,0x00,0x00,0xf1,0x39,0x00,0x00,
0xf1,0x71,0x00,0x80,0xf0,0x71,0x00,0x80,0xf0,0xe1,0x00,0x40,0xf0,0xe1,0x00,
0x40,0xf0,0xc1,0x01,0x20,0xf0,0xc1,0x01,0x20,0xf0,0x81,0x03,0x10,0xe0,0x80,
0x03,0x10,0xe0,0x00,0x07,0x08,0xe0,0x00,0x07,0x08,0xe0,0x00,0x0e,0x04,0x00,
0x00,0x0e,0x04,0xe0,0x00,0x1c,0x02,0xf0,0x01,0x1c,0x02,0xf0,0x01,0x38,0x01,
0xe0,0x00,0x38,0x01,0x00,0x00,0x70,0x01,0x00,0x00,0x70,0xff,0xff,0xff,0x7f,
0xf8,0xff,0xff,0x3f,0x00,0x00,0x00,0x00};

So if you convert the C array of bytes to a Python list of integers:

cdata = [
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x10,0x01,
0x00,0x00,0x08,0x07,0x00,0x00,0x08,0x0e,0x00,0x00,0x04,0x0e,0x00,0x00,0x04,
0x1c,0x00,0x00,0x02,0x1c,0x00,0x00,0xe2,0x38,0x00,0x00,0xf1,0x39,0x00,0x00,
0xf1,0x71,0x00,0x80,0xf0,0x71,0x00,0x80,0xf0,0xe1,0x00,0x40,0xf0,0xe1,0x00,
0x40,0xf0,0xc1,0x01,0x20,0xf0,0xc1,0x01,0x20,0xf0,0x81,0x03,0x10,0xe0,0x80,
0x03,0x10,0xe0,0x00,0x07,0x08,0xe0,0x00,0x07,0x08,0xe0,0x00,0x0e,0x04,0x00,
0x00,0x0e,0x04,0xe0,0x00,0x1c,0x02,0xf0,0x01,0x1c,0x02,0xf0,0x01,0x38,0x01,
0xe0,0x00,0x38,0x01,0x00,0x00,0x70,0x01,0x00,0x00,0x70,0xff,0xff,0xff,0x7f,
0xf8,0xff,0xff,0x3f,0x00,0x00,0x00,0x00]

then you can make a cursor like this:

bits = "".join(map(chr, cdata))
cursor = wxCursorFromBits(bits, 32, 32)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

I've been trying to make custom cursors which look the same under wxGTK
and wxMSW. I'm using the wxCursorFromImage() function. I'm loading the
image from a (16x16) *.png file which uses transparency around the
cursor icon. This looks fine on wxGTK, but on wxMSW the cursor is drawn
at double the size and with the transparent regions "inverted".

Can anyone with experience on this give me some hints or tips!

Also, is there a way of setting the "offset" for cursors made using
wxCursorFromImage()? The active-point is stuck at the top-left of my
icon.

thanks,

Bryan

···

--
Bryan Cole
Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge CB4 0WG, United Kingdom.
tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382

bryan cole wrote:

I've been trying to make custom cursors which look the same under wxGTK
and wxMSW. I'm using the wxCursorFromImage() function. I'm loading the
image from a (16x16) *.png file which uses transparency around the
cursor icon. This looks fine on wxGTK, but on wxMSW the cursor is drawn
at double the size and with the transparent regions "inverted".

Can anyone with experience on this give me some hints or tips!

MSW cursors can only be 32x32, so the image is probably being scaled to that size. Also, the meaning of the set bits and clear bits in the image are opposite on MSW from the other platforms. wxWindows should be inverting the image before handing it off to the platform API... Please enter a bug report about this.

Also, is there a way of setting the "offset" for cursors made using
wxCursorFromImage()? The active-point is stuck at the top-left of my
icon.

Not with this constructor unfortunatly...

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!