def __init__(self, ui): Dialog.__init__(self, ui, _('Custom Tools'), buttons=gtk.BUTTONS_CLOSE) # T: Dialog title self.set_help(':Help:Custom Tools') self.manager = CustomToolManager() self.add_help_text(_( 'You can configure custom tools that will appear\n' 'in the tool menu and in the tool bar or context menus.' ) ) # T: help text in "Custom Tools" dialog hbox = gtk.HBox(spacing=5) self.vbox.add(hbox) self.listview = CustomToolList(self.manager) hbox.add(self.listview) vbox = gtk.VBox(spacing=5) hbox.pack_start(vbox, False) for stock, handler, data in ( (gtk.STOCK_ADD, self.__class__.on_add, None), (gtk.STOCK_EDIT, self.__class__.on_edit, None), (gtk.STOCK_DELETE, self.__class__.on_delete, None), (gtk.STOCK_GO_UP, self.__class__.on_move, -1), (gtk.STOCK_GO_DOWN, self.__class__.on_move, 1), ): button = IconButton(stock) # TODO tooltips for icon button if data: button.connect_object('clicked', handler, self, data) else: button.connect_object('clicked', handler, self) vbox.pack_start(button, False)
class CustomToolManagerDialog(Dialog): def __init__(self, ui): Dialog.__init__(self, ui, _('Custom Tools'), buttons=gtk.BUTTONS_CLOSE) # T: Dialog title self.set_help(':Help:Custom Tools') self.manager = CustomToolManager() self.add_help_text(_( 'You can configure custom tools that will appear\n' 'in the tool menu and in the tool bar or context menus.' ) ) # T: help text in "Custom Tools" dialog hbox = gtk.HBox(spacing=5) self.vbox.add(hbox) self.listview = CustomToolList(self.manager) hbox.add(self.listview) vbox = gtk.VBox(spacing=5) hbox.pack_start(vbox, False) for stock, handler, data in ( (gtk.STOCK_ADD, self.__class__.on_add, None), (gtk.STOCK_EDIT, self.__class__.on_edit, None), (gtk.STOCK_DELETE, self.__class__.on_delete, None), (gtk.STOCK_GO_UP, self.__class__.on_move, -1), (gtk.STOCK_GO_DOWN, self.__class__.on_move, 1), ): button = IconButton(stock) # TODO tooltips for icon button if data: button.connect_object('clicked', handler, self, data) else: button.connect_object('clicked', handler, self) vbox.pack_start(button, False) def on_add(self): properties = EditCustomToolDialog(self).run() if properties: self.manager.create(**properties) self.listview.refresh() def on_edit(self): name = self.listview.get_selected() if name: tool = self.manager.get_tool(name) properties = EditCustomToolDialog(self, tool=tool).run() if properties: tool.update(**properties) tool.write() self.listview.refresh() def on_delete(self): name = self.listview.get_selected() if name: self.manager.delete(name) self.listview.refresh() def on_move(self, step): name = self.listview.get_selected() if name: i = self.manager.index(name) self.manager.reorder(name, i + step) self.listview.refresh() self.listview.select(i+step)