[pygtk] How to write 'motion_notify_event' callback correctly
chenkai036 at gmail.com
Fri Jan 18 14:14:46 WST 2008
I am trying to writing a custom widget inherited from gtk.Widget which
responds the 'motion_notify_event'.
And I found something
confusing in the implementation of 'motion_notify_event' callback.
At first, I use 'do_motion_notify_event_cb' as its callback. According to
the specification in pygtk class reference, I wrote the connection
statement and the callback like this:
# do_realize method in my widget
self.connect( 'motion_notify_event', self.do_motion_notify_event_cb ) #
No extra user_para being added
# And my callback definition is here
def do_motion_notify_event_cb( self, widget, event ) :
When I run my application, error always occurred, showing
that the number of arguments does not match the definition.
So, I changed the arguments in callback to see how many arguments does
'do_motion_notify_event_cb' exactly have:
# Modified callback definition for testing
def do_motion_notify_even_cb( self, *data ) :
print len( data )
The result showed if the callback are called, '1' and '2' has been printed
alternatively in the console. When print '1', only GtkEvent is passed.
While print '2', GtkWidget and GtkEvent are passed both. That causes the
error all the time. But I don't know why pygtk signal handling will act
like this. It is strange for a beginner like me. Or did I do something
wrong? Could anyone give any hint? ;-)
Another problem related to 'motion_notify_event' callback. When I changed
the callback to the following:
def motion_notify_event_cb( self, widget, event ) :
Everything worked perfectly. Could some one tell me the differences between
do_method and method. It seemed pygtk doesn't give any clue about it.
Thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the pygtk