def __init__(self, element_factory): Toolbox.__init__(self) self.factory = element_factory self.group = ToolGroup('Elements') for element in element_factory.get_list(): self.add_element(element) self.factory.connect('element-added', self._on_factory_element_added) self.add(self.group)
class ElementView(Toolbox): def __init__(self, element_factory): Toolbox.__init__(self) self.factory = element_factory self.group = ToolGroup('Elements') for element in element_factory.get_list(): self.add_element(element) self.factory.connect('element-added', self._on_factory_element_added) self.add(self.group) def add_element(self, element): name = element.name clsname = element.__module__.split('.')[-1] caption = element.caption icon = os.path.join(basedir, 'Elements', clsname, 'icon.png') button = self.group.add_icon_button(name, icon, caption) button.connect('button-press-event', self._on_button_press_event) def _on_factory_element_added(self, factory, element_class): self.add_element(element_class) def _on_button_press_event(self, button, event): self.emit('element-button-press-event', button, event)
def __init__(self): gtk.Window.__init__(self) toolbox = Toolbox() toolbox.connect('button-clicked', self._on_button_clicked) # Add first group without icons. group = ToolGroup('My ToolGroup') group.add_button('button1', 'Button 1') group.add_button('button2', 'Button 2') toolbox.add(group) # Add another group with icons. group = ToolGroup('My ToolGroup') icon1 = os.path.join(icon_dir, 'label.png') icon2 = os.path.join(icon_dir, 'table.png') group.add_icon_button('button3', icon1, 'Button 3') group.add_icon_button('button4', icon2, 'Button 4') toolbox.add(group) self.add(toolbox) self.show_all()