class Tool(object): def __init__( self, name, help_link="", icon=None, enabled=True, checkable=False, popup_menu=False, ): super(Tool, self).__init__() self.__icon = icon self.__name = name self.__parent = None self.__enabled = enabled self.__checkable = checkable self.__help_link = help_link self.__is_popup_menu = popup_menu self.__action = QAction(self.getIcon(), self.getName(), None) self.__action.setIconText(self.getName()) self.__action.setEnabled(self.isEnabled()) self.__action.setCheckable(checkable) self.__action.triggered.connect(self.trigger) HelpCenter.addHelpToAction(self.__action, self.getHelpLink()) def getIcon(self): return self.__icon def getName(self): return self.__name def trigger(self): raise NotImplementedError() def setParent(self, parent): self.__parent = parent self.__action.setParent(parent) def parent(self): return self.__parent def isEnabled(self): return self.__enabled def getHelpLink(self): return self.__help_link def getAction(self): return self.__action def setVisible(self, visible): self.__action.setVisible(visible) def setEnabled(self, enabled): self.__action.setEnabled(enabled) def isPopupMenu(self): return self.__is_popup_menu
def fill_layout(self): """Fill grid layout""" import qwt for fname in get_tests(qwt): self.add_test(fname) toolbar = QToolBar(self) all_act = QAction(self.get_std_icon("DialogYesButton"), "", self) all_act.setIconText("Run all tests") all_act.triggered.connect(lambda checked: run_all_tests(wait=False)) folder_act = QAction(self.get_std_icon("DirOpenIcon"), "", self) folder_act.setIconText("Open tests folder") open_test_folder = lambda checked: os.startfile(TEST_PATH) folder_act.triggered.connect(open_test_folder) about_act = QAction(self.get_std_icon("FileDialogInfoView"), "", self) about_act.setIconText("About") about_act.triggered.connect(self.about) for action in (all_act, folder_act, None, about_act): if action is None: toolbar.addSeparator() else: toolbar.addAction(action) toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.addToolBar(toolbar)