Alexei Gilchrist wrote:

Hi, I'm trying to set a customised cursor for a drawing application. I want the cursor to reflect the size and color of the selected pen.

  pm=gtk.gdk.Pixmap(page.canvas.window,10,10,1)
  gc = pm.new_gc(foreground=gtk.gdk.color_parse('black'))
  pm.draw_rectangle(gc, True, 0, 0, 9, 9)

  mask=gtk.gdk.Pixmap(page.canvas.window,10,10,1)
  gc = mask.new_gc(foreground = gtk.gdk.color_parse('white'))
  mask.draw_rectangle(gc, False, 0, 0, 9, 9)

  cur=gtk.gdk.Cursor(pm, mask,  gtk.gdk.color_parse('white'), 
gtk.gdk.color_parse('black'), 5, 5)
  page.canvas.window.set_cursor(cur)


What I get is a whole lot of random garbage in a square roughly the right size. If I set the depth of pm to -1, I get an X error ('BadMatch (invalid parameter attributes)') and the program crashes.

Could anyone give me some pointers to fix this?

Also, I'm not very clear on the role's of the fg and bg in the Cursor 
contructor, the documentation
is not very illuminating:

 fg : the unallocated foreground gtk.gdk.Color
 bg : the unallocated background gtk.gdk.Color

'unallocated' ??
You need to use an allocated color for the gc foreground color - first get a colormap and then allocate the colors black and white for drawing on the bitmaps:

w=gtk.Window()
pm = gtk.gdk.Pixmap(None,10,10,1)
mask = gtk.gdk.Pixmap(None,10,10,1)
colormap = gtk.gdk.colormap_get_system()
black = colormap.alloc_color('black')
white = colormap.alloc_color('white')

Create two GCs - one each for black and white:

bgc = pm.new_gc(foreground=black)
wgc = pm.new_gc(foreground=white)

Use the black gc to clear the pixmap and mask:

mask.draw_rectangle(bgc,True,0,0,10,10)
pm.draw_rectangle(bgc,True,0,0,10,10)

Use the white gc to set the bits in the pixmap and mask:

pm.draw_arc(wgc,True,0,2,10,5,0,360*64)
mask.draw_rectangle(wgc,True,0,0,10,10)

Then create and set the cursor using unallocated colors:

cur=gtk.gdk.Cursor(pm,mask,gtk.gdk,color_parse('green'), gtk.gdk.color_parse('red'),5,5)
w.window.set_cursor(cur)

Should have a green oval in a red background for the window cursor.

John
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to