Thank you Giuseppe for your quick reply. I'm looking through your code right now, but it's not evident to me how this solves my problem. If I understand your code correctly, you call gtk.Builder.connect_signals() only once in the __init__ method of the GladeWidgetsWrapper class.
Further connections are explicit and happen at module level like for example in the audacious plugin (line 75): item.connect('activate', self.run, source_path_list) Maybe it's just me that don't understand it [in which case I apologise and will be grateful for any further clarification] but I am under the impression my scenario is quite different than the one in the nautilus pyextension program. My situation looks like follows: 1. Single glade file that contains various top-level containers (windows, dialogues...) 2. The glade file also define the expected callbacks for a few events (like "on_mybutton_clicked", etc...) 3. I have various modules (= different files = different classes) each of them containing *some* of these callbacks. For example I have a mainwindow.py module that have handlers like "on_main_destroy_event" or "on_main_resize", but I also have a mainmenu.py one with handlers like "on_file_open_activated" or "on_quite_activated". What I am doing right now, is to pass to the __init__ of each of these classes the same instance of gtk.Builder that I created in the class acting as "facade" for the controller class. In the each of these __init__ methods, the gtk.Builder instance is queried for widgets: mywidget = mybuilder.get_object(widget_name) and this work fine. But when I try to "automagically" connect the callbacks by issuing: mybuilder.connect_signals(self) it only works in the first module (it returns - correctly - the list of unconnected signals), but when I call it again from within the __init__ of my second module, it returns None, as if it connected all signals, but this is not true: not even the callbacks in the second module have been connected correctly.... :( Any idea of how to get around this problem // explanation on how the code in the pyextension would solve this? Thank you in advance for your time and support! :) /mac On Mon, 27 Jun 2011 17:33:18 +0200 Giuseppe Penone <gius...@gmail.com> wrote: > I invite you to take a look to the source code of my simplest > application http://www.giuspen.com/nautilus-pyextensions/ > where as you can see gtk.Builder() is called only once and there's no > need for further calls. > > the code that you have to look for: > > class GladeWidgetsWrapper: > """Handles the retrieval of glade widgets""" > > def __init__(self, glade_file_path, gui_instance): > try: > self.glade_widgets = gtk.Builder() > self.glade_widgets.set_translation_domain(cons.APP_NAME) > self.glade_widgets.add_from_file(glade_file_path) > self.glade_widgets.connect_signals(gui_instance) > except: print "Failed to load the glade file" > > def __getitem__(self, key): > """Gives us the ability to do: > wrapper['widget_name'].action()""" return > self.glade_widgets.get_object(key) > > def __getattr__(self, attr): > """Gives us the ability to do: wrapper.widget_name.action()""" > new_widget = self.glade_widgets.get_object(attr) > if new_widget is None: raise AttributeError, 'Widget %r not > found' % attr > setattr(self, attr, new_widget) > return new_widget > > ..... > > class NautilusPyExtensions: > """The application's main window""" > > def __init__(self, store): > ... > # instantiate the Glade Widgets Wrapper > self.glade = GladeWidgetsWrapper(cons.GLADE_PATH + > 'nautilus-pyextensions.glade', self) > > ..... > > furthermode in the code you access the widgets with > "self.glade.widgetname", all signals are connected. > > Hope this helps. > Giuseppe. > > > > > > > > On Mon, Jun 27, 2011 at 17:02, Mac Ryan <quasipe...@gmail.com> wrote: > > > I posted the same question on Stack Overflow, but so far it only > > got 3 views and no answers... :( > > > > http://stackoverflow.com/questions/6492000 > > > > In the design of my program I would like to pass around the > > gkt.Builder() instance to various modules (each of them has > > some of the handlers for managing the GUI), but I found out > > that once the builder is instantiated one can only call the > > connect_signals() method once: if called more than once, any > > call after the second will return None (which would mean: > > all signals have been connected, which is a blatant lie!). > > > > I tried to see if I could understand how/where gtk.Builder > > stores the handler names that are assigned within the Glade > > GUI, in order to write my own method to overcome this limitation, > > but after more than an hour of console experiments I still > > haven't understand where this information is stored. > > > > Is there anybody on the list that is able to advice me? Basically I > > would be happy in any of these scenarios: > > > > * Find a way to re-use the same builder over and over. > > * Find an alternative method to *AUTO-assign* methods of various > > modules as callbacks to GUI-emitted signals (with the GUI being > > defined in a monolithic Glade Builder XML file). > > * Find a way to extract from the from the gtk.Builder (or in some > > other way) the pairs widget-instance<->expected-handler-name as > > defined in the Glade editor. > > > > As for my previous mail on this list: I solved the problem myself: > > what I misunderstood was the correct use of the method > > dialogue.run(). > > > > Thanks in advance for your time, > > /mac > > _______________________________________________ > > pygtk mailing list pygtk@daa.com.au > > http://www.daa.com.au/mailman/listinfo/pygtk > > Read the PyGTK FAQ: http://faq.pygtk.org/ > > _______________________________________________ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/