hi,

This might be a stupid question, but I have spend hours playing with
things, looking at docs etc.  Basically, I want to capture a
configure_event for some Gtk widget that I derive a class from.  I
find that apart from the GtDrawingArea none of the other widgets are
able to emit the 'configure_event'.  Each widget seems to have its own
quirks.  I did do a

         self.add_events (GDK.ALL_EVENTS_MASK)

so that it can handle all events.  Attached at the end is the code.
Change TESTWID at the top to look at the events that the particular
widget can handle.

Would appreciate if someone could explain why it behaves like this.
Believe me, I have looked far and wide for explanations!  I am not on
the pyGtk list so please CC me in on any messages.

I am sorry that this mail is long, I thought that the code might be
useful to some folks.

thanks,
prabhu


# ----------------------------------------
import gtk
import GDK

TESTWID = gtk.GtkEventBox

class Test (TESTWID):
    def __init__ (self, *args):
        l = list (args)
        l.insert (0, self)
        apply (TESTWID.__init__, l)
        self.connect_signals ()
        
        # need this to be able to handle key_press events.
        # I looked at other flags too but they didnt seem to be any use.
        self.set_flags (gtk.CAN_FOCUS)
        # default size
        self.set_usize (300, 300)
        
    def connect_signals (self):
        print "In connect_signals"
        
        self.connect ("map_event", self.Map)
        self.connect ("configure_event", self.Configure)
        self.connect ("expose_event", self.Expose)
        self.connect ("visibility_notify_event", self.Visibility)
        self.connect ("key_press_event", self.KeyPress)
        self.connect ("button_press_event", self.ButtonPress)
        self.connect ("button_release_event", self.ButtonRelease)
        self.connect ("motion_notify_event", self.MouseMotion)
        self.connect ("destroy", self.Destroy) 
        self.connect ("enter_notify_event", self.Enter)
        self.connect ("leave_notify_event", self.Leave)
        self.connect ("delete_event", self.Destroy)
        self.add_events (GDK.ALL_EVENTS_MASK)

    def Map (self, *args):
        print "In Test::Map"
        return gtk.TRUE

    def Configure (self, *args):
        print "In Test::Configure"
        return gtk.TRUE

    def Expose (self, *args):
        print "In Test::Expose"
        return gtk.TRUE

    def Visibility (self, *args):
        print "In Test::Visibility"
        return gtk.TRUE

    def KeyPress (self, *args):
        print "In Test::KeyPress"
        return gtk.TRUE
        
    def ButtonPress (self, *args):
        print "In Test::ButtonPress"
        return gtk.TRUE

    def ButtonRelease (self, *args):
        print "In Test::ButtonRelease"
        return gtk.TRUE

    def MouseMotion (self, *args):
        print "In Test::MouseMotion"
        return gtk.TRUE
    
    def Enter (self, *args):
        print "In Test::Enter"
        self.grab_focus ()
        return gtk.TRUE

    def Leave (self, *args):
        print "In Test::Leave"
        #self.remove_grab ()        
        return gtk.TRUE
    
    def Destroy (self, *args):
        print "In Test::Destroy"

            
def main ():
    # The main window
    window = gtk.GtkWindow (gtk.WINDOW_TOPLEVEL)
    window.set_title ("A pyGtk event test!")
    window.connect ("destroy", gtk.mainquit)
    window.connect ("delete_event", gtk.mainquit)
    window.set_border_width (10)

    # A VBox into which I pack widgets.
    vbox = gtk.GtkVBox (spacing=3)
    window.add (vbox)
    vbox.show ()

    test = Test ()
    test.set_usize (400, 400)
    vbox.pack_start (test)
    test.show ()
    
    # A simple quit button
    quit = gtk.GtkButton ("Quit!")
    quit.connect ("clicked", window.destroy)
    vbox.pack_start (quit)
    quit.show ()

    # show the main window and start event processing.
    window.show ()
    gtk.mainloop ()


if __name__ == "__main__":
    main ()
    
# ----------------------------------------


_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to