Bernhard Herzog wrote:

While porting Sketch to PyGTK2 I came across a strange change in the
behavior of event objects in PyGTK2. The sample program below connects
to the button press, motion and release events and stores the event
object of the button_press event in an instance variable. In the motion
event handler the coordinates of the mouse in the saved press event are
always the same as the coordinates returned by get_pointer()!


I haven't followed all the C code yet, but it seems as though PyGTK
reuses the same underlying gdk event struct. Storing an explicit copy of
the press event works around the problem.


This is unfortunately unavoidable. The event objects (and any other boxed types for that matter) passed to the signal handle do no actually own the underlying C object now (they use the same pointer as in the GValue for the argument). The object is not guaranteed to be valid after the signal handler has finished running. Copying the event object is the correct way to handle this case.

The reason for this change is that some GTK APIs will not function correctly if the boxed value is copied (since they require modifying the original copy of the boxed object, which sort of violates the rules for boxed types, but is the way things turned out).

James.

--
Email: [EMAIL PROTECTED]
WWW:   http://www.daa.com.au/~james/



_______________________________________________
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