def __init__(self, gladefile, toplevel, controller = None):
        """Loads a glade file and connects signal handlers to widgets."""
        if controller is None:
            controller = self
        widget_tree = gtk.glade.XML(
            pkg_resources.resource_filename(__name__,
            gladefile), toplevel)
        self.top_widget = widget_tree.get_widget(toplevel)
        widgets = dict([(widget.get_name(), widget) for widget in
            widget_tree.get_widget_prefix('')])
        for widget_name, widget in widgets.iteritems():
            setattr(self, widget_name, widget)
        for name in dir(controller):
            match = re.match('on_([a-zA-Z0-9_]+)_handle_([a-zA-Z0-9_]+)', name)
            callback = getattr(controller, name)
            if match:
                widget, signal = match.groups()
                signal = signal.replace('_', '-')
                if widget in widgets:
                    widget = widgets[widget]
                    if (signal == 'selection-changed' and
                        isinstance(widget, gtk.TreeView)):
                        widget = widget.get_selection()
                        signal = 'changed'
                    widget.connect(signal, callback)
                else:
                    raise RuntimeWarning(
                      _('Widget %s not found when trying to register '
                        'callback %s') % (widget, name))
dataset/ETHPy150Open thesamet/webilder/src/webilder/uitricks.py/UITricks.__init__/original