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!