![]() |
Drawing on gtk.Image
Hello all,
I apologise for asking a basic question. Suppose I have the code: Code:
PixBuf = gtk.gdk.pixbuf_new_from_file("image.png") and suppose I want to draw a rectangle (say) on top of the displayed PNG. How do I get round to doing this? Thanks! |
Re: Drawing on gtk.Image
I think you need a gtk.DrawingArea, AFAIK it's not possible draw directly in a gtk.Image (I could be wrong though).
You can check Mirage source code (search the "crop_image" function), in the cropping functions it draws a rectangle on top of a image that's stored in a DrawingArea. It's a bit difficult to understand this code if it's the first time that you play with a DrawingArea but probably you'll be able to purge most of the code in those Mirage functions. |
Re: Drawing on gtk.Image
Hello, and thanks for finding the time to reply. I managed to draw on the image by: loading it as a pixbuf, getting the pixmap from that pixbuf, drawing on the pixmap and then creating a gtk.Image from the pixmap. Not elegant (horribly inelegant in fact) but seems to work. If only people documented this sort of thing better!
Thus, my (possibly optimisable) code reads: Code:
pixbuf = gtk.gdk.pixbuf_new_from_file("image.png") |
Re: Drawing on gtk.Image
2 Attachment(s)
Thanks for the code.
A gtk.Image is a gtk.Widget, and gtk.Widget's have the attribute "window." "window," if not none, is the gtk.gdk.Window of the widget. gtk.gdk.Window and gtk.gdk.Pixmap are both gtk.gdk.Drawables. So, for gtk.Images you can do the following after you've realized them in a container: Code:
aWindow = gtk.Window() Attachment 4813 |
Re: Drawing on gtk.Image
Thanks for that! If there's one objection I have towards python it's the quality of documentation available, especially where GTK is involved (yes, yes I know they're separate projects of course, but someone ported the GTK libraries and therefore -- presumably -- he/she cares enough; or maybe I haven't looked hard enough). Anyway, my Image is inside an EventBox inside a Hildon PannableArea, and Image.window is set to None.
Eventually, I'll do this properly, but my aim is for Tubes 0.2.0-1 to "just work" and not be elegant under the hood. That might have to wait until 1.0.0 :) |
All times are GMT. The time now is 04:24. |
vBulletin® Version 3.8.8