[pygtk] gtk.DrawingArea mouse move event

John Pye john.pye at student.unsw.edu.au
Fri Feb 10 08:41:26 WST 2006


Hi,

I don't know if this is the solution but it sounds similar to a problem
that I had. I had a gtk.Image inside a viewport inside a scrolling
window. In order to capture the 'motion-notify-event' on my gtk.Image, I
needed to add an EventBox on the image, and capture the events to that.
I used Glade to do that, and it worked fine. Have you tried an EventBox yet?

There was something in the PyGTK FAQ about this.

Cheers
JP

Luigi Paioro wrote:

> 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
> _______________________________________________
> pygtk mailing list   pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
>

-- 
John Pye
School of Mechanical and Manufacturing Engineering
The University of New South Wales
Sydney  NSW 2052  Australia
t +61 2 9385 5127
f +61 2 9663 1222
mailto:john.pye_AT_student_DOT_unsw.edu.au
http://pye.dyndns.org/



More information about the pygtk mailing list