self.signals shouldn't be a class variable. add helper functions to connect child widget signals and disconnect them.

This commit is contained in:
Chris Jones 2009-11-14 22:57:35 +00:00
parent 6e0718c829
commit 29d661b26a

View File

@ -22,11 +22,14 @@ class Container(object):
'zoomed' : 1,
'maximised' : 2 }
signals = []
signals = None
cnxids = None
def __init__(self):
"""Class initialiser"""
self.children = []
self.signals = []
self.cnxids = {}
self.config = Config()
self.state_zoomed = self.states_zoom['none']
@ -49,6 +52,28 @@ class Container(object):
err('Container:: registering signal for %s on %s failed' %
(signal['name'], widget))
def connect_child(self, widget, signal, handler, data=None):
"""Register the requested signal and record its connection ID"""
if not self.cnxids.has_key(widget):
self.cnxids[widget] = []
if data is not None:
self.cnxids[widget].append(widget.connect(signal, handler, data))
dbg('Container::connect_child: registering %s(%s) to handle %s::%s' %
(handler.__name__, data, widget.__class__.__name__, signal))
else:
self.cnxids[widget].append(widget.connect(signal, handler))
dbg('Container::connect_child: registering %s to handle %s::%s' %
(handler.__name__, widget.__class__.__name__, signal))
def disconnect_child(self, widget):
"""De-register the signals for a child"""
if self.cnxids.has_key(widget):
for cnxid in self.cnxids[widget]:
# FIXME: Look up the IDs to print a useful debugging message
widget.disconnect(cnxid)
del(self.cnxids[widget])
def get_offspring(self):
"""Return a list of child widgets, if any"""
return(self.children)