[pygtk] gtk.DrawingArea mouse move event
Luigi Paioro
luigi at lambrate.inaf.it
Thu Feb 9 23:33:44 WST 2006
Hi to all!
I'm new to PyGTK development, so excuse me if the question is naive.
I'd like to write a canvas area with two lines (one vertical and the
other horizontal) that draw my mouse pointer as a "target" on a
gtk.DrawingArea. This is my code:
###########
import pygtk
pygtk.require('2.0')
import gtk
import operator
import time
import string
class DrawingAreaExample:
def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Drawing Area Example")
window.connect("destroy", lambda w: gtk.main_quit())
self.area = gtk.DrawingArea()
self.pangolayout = self.area.create_pango_layout("")
self.area.set_size_request(400, 300)
self.area.set_events(gtk.gdk.POINTER_MOTION_MASK |
gtk.gdk.POINTER_MOTION_HINT_MASK )
self.area.connect("motion_notify_event", self.draw_cursor)
self.area.connect("expose-event", self.area_expose_cb)
window.add(self.area)
self.area.show()
window.show()
def draw_cursor(self, area, event):
area.window.draw_line(self.gc, 0, event.y, 400, event.y)
area.window.draw_line(self.gc, event.x, 0, event.x, 300)
def area_expose_cb(self, area, event):
self.style = self.area.get_style()
self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
def main():
gtk.main()
return 0
if __name__ == "__main__":
DrawingAreaExample()
main()
###########
The problem is that the pointer doesn't follow the mouse unless I click
with the mouse. Moreover I have to delete the previous lines too...
How can I do?
Thanks a lot.
Luigi
More information about the pygtk
mailing list