[pygtk] handling events

Radomir Dopieralski pygtk at sheep.art.pl
Sun Oct 22 16:36:23 WST 2006

Dnia Sun, Oct 22, 2006 at 09:57:47AM +0200, napisale(a)s: 
> Hi,
>  I am looking for a way to handle events through classes.
>  I have a main window with a statusbar at the bottom.
>  In the window I put a notebook to which I can add/remove pages (they are instances of a notebook_page_class).
>  Each page contains a set of widgets that can be clicked and handled by connected methods/functions belonging to the notebook_page_class.
>  My question is : when the widgets contained in these notebook pages are clicked and handled, how can the result(s) generated by the callback meth/func be passed to the main window statusbar ?
>  I could add a status bar to each notebook page but this is no elegent way...

If you want the notebook pages to be able to affect something
outside them, you need to give them a reference to it...

For example, you could pass the status bar as a parameter to
the notebook page constructor, and save the reference in the
notebook page.


class MainWindow:
    def __init__(self):
        self.status = gtk.StatusBar()

    def add_notebook_page(self):
        page = NotebookPage(self.status)

class NotebookPage:
    def __init__(self, status=None):
        self.status = status

    def on_widgets_clicked(self, widget):
            self.status.get_context_id('page cliked'),

Radomir `The Sheep' Dopieralski

"When in doubt, use brute force." [Ken Thompson]

More information about the pygtk mailing list