How disconnect signals in gtk.builder?
Question
I connect all signals in gtk.builder with this:
ui_builder = gtk.Builder()
ui_builder.add_from_file('main.ui')
self.win_main = builder.get_object('win_main')
ui_builder.connect_signals(self)
How could I block/disconnect any/all signals, please? (And reconnect?)
Thanks in advance!
Solution
gtk.builder provides connect_signals() as a convenience, once the signals are connected it's up to you to programatically block or disconnect signals.
Here is the PyGTK documentation for both blocking signals and disconnecting handlers:
http://www.pygtk.org/pygtktutorial/ch-advancedeventsandsignals.html
OTHER TIPS
What I do in such case, is to connect manually the signal, not with gtk.Builder.connect_signals
because this method doesn't return their
handlers ids, and without that handler you cannot manipulate the signal.
In my case was just a couple of signals not big deal.
what I am doing right now: forget about gtk.builder.connect_signals
.
so after your code:
ui_builder = gtk.Builder()
ui_builder.add_from_file('main.ui')
self.win_main = builder.get_object('win_main')
I would have something similar to this:
list_of_handler_ids = []
import libxml2
doc = libxml2.parseFile('main.ui')
ctxt = doc.xpathNewContext()
signals = ctxt.xpathEval('//signal')
for s in signals:
handler = getattr(self, s.prop('handler'))
signaller = getattr(self.win_main, s.parent.prop('id'))
handler_id = signaller.connect(s.prop('name'), handler)
list_of_handler_ids.append(handler_id)
which seems to sort of work after a first quick check.