On Thu, 2002-03-14 at 16:21, Han-Wen Nienhuys wrote:
> Subject: pygtk2 and GC?
> X-Mailer: VM 6.96 under Emacs 20.7.1
> FCC: ~/persoonlijk/Mail/sent
>
>
>
> Hi,
>
> I installed pygtk2 this morning, and am now trying to sort-of port my
> gtk dribbling to gtk2, but I'm having lots of problems with managing
> GdkGC objects.
>
> The examples in the distribution are not of much help, since they are
> outdated. FWIW, i've tried to get scribble.py up and running, but
> failed: at some point, I must come up with a GC object, and in pygtk
> for gtk1, you could do
>
> get_style().white_gc
>
> but this no longer seems to work. How should I proceed?
>
>
I have attached a script that show how much I have figured out. If you
place a file 'image.png' in pwd, then you can load it by pressing mouse
button 3.
I have no idea if I use the api correctly. Also, I have not figured out
how to draw into a invisible bacup image, draw that image to the screen
on expose events. James.. ?
--
Tom Cato Amundsen <[EMAIL PROTECTED]>
GNU Solfege - free eartraining, http://www.gnu.org/software/solfege/
#!/usr/bin/env python2.2
import sys
sys.path.append("/home/tom/pygtk2/lib/python2.2/site-packages")
import gtk
GDK = gtk.gdk
def configure_event(widget, event):
print "CONFIGURE does nothing!"
def expose_event(widget, event):
print "EXPOSE does nothing!"
def draw_brush(widget, x, y):
rect = (x-5, y-5, 10, 10)
widget.window.draw_rectangle(widget.get_style().black_gc, gtk.TRUE,
x-5, y-5, 10, 10)
def button_press_event(widget, event):
if event.button == 1:
draw_brush(widget, event.x, event.y)
elif event.button == 3:
im = gtk.Image()
im.set_from_file("image.png")
im.get_pixbuf().render_to_drawable(widget.window, widget.get_style().black_gc,
0, 0, event.x, event.y, 30, 30, gtk.gdk.RGB_DITHER_NORMAL, 0, 0)
print 2
return gtk.TRUE
def motion_notify_event(widget, event):
if event.is_hint:
x, y, state = event.window.get_pointer()
else:
x = event.x; y = event.y
state = event.state
if state & GDK.BUTTON1_MASK:
draw_brush(widget, x, y)
return gtk.TRUE
def main():
win = gtk.Window()
win.set_name("Test Input")
win.connect("destroy", gtk.mainquit)
win.set_border_width(5)
vbox = gtk.VBox(spacing=3)
win.add(vbox)
vbox.show()
drawing_area = gtk.DrawingArea()
drawing_area.set_size_request(200, 200)
vbox.pack_start(drawing_area)
drawing_area.show()
drawing_area.connect("expose_event", expose_event)
drawing_area.connect("configure_event", configure_event)
drawing_area.connect("motion_notify_event", motion_notify_event)
drawing_area.connect("button_press_event", button_press_event)
drawing_area.set_events(GDK.EXPOSURE_MASK |
GDK.LEAVE_NOTIFY_MASK |
GDK.BUTTON_PRESS_MASK |
GDK.POINTER_MOTION_MASK |
GDK.POINTER_MOTION_HINT_MASK)
button = gtk.Button("Quit")
vbox.pack_start(button, expand=gtk.FALSE, fill=gtk.FALSE)
button.connect("clicked", lambda widget, win=win: win.destroy())
button.show()
win.show()
gtk.mainloop()
if __name__ == '__main__':
main()