def execToolConfig(self): ''' Show the dialog box for executing a "tool config" A tool config is has a pointer to an existing tool (a "tool hook") but can provide an alternative configuration. ''' assert self.has_selected_item() # First we need to get the hooked node that we want to run node = self.selected_item().node hooked_tool_name = node.find('tool_hook').text hooked_tool_node = get_tool_node_by_name(self.project, hooked_tool_name) if hooked_tool_node is None: MessageBox.error( mainwindow=self.view, text='Invalid tool hook', detailed_text=( 'This tool config points to a tool named "%s" ' 'but there is no tool with that name in this project.' % hooked_tool_name)) return # Open up a GUI element and populate with variable's tool_lib_node = get_tool_library_node(self.project) params = {'tool_path': get_path_to_tool_modules(self.project)} window = ExecuteToolGui(parent_widget=self.manager.base_widget, tool_node=hooked_tool_node, tool_config=node, tool_library_node=tool_lib_node, params=params) window.setModal(True) window.show()
def dataActionMenuFunction(self, action): QObject.disconnect(self.menu, SIGNAL("triggered(QAction*)"), self.dataActionMenuFunction) if action != self.actRefresh: actiontext = str(action.text()) tool_node = self.dynactions[actiontext] filename = self.model.fileName(self.currentIndex) filepath = self.model.filePath(self.currentIndex) parentfilepath = self.model.filePath(self.currentIndex.parent()) params = self.getOptionalParams() window = ExecuteToolGui(parent_widget=self.treeview, tool_node=tool_node, tool_config=None, tool_library_node=self.tool_library_node, params=params) window.show() return
class XmlController_DataTools(XmlController): def __init__(self, manager): XmlController.__init__(self, manager) # Show dialog to execute/config tools self.actExecToolFile = self.create_action('execute', "Execute Tool...", self.execToolFile) self.actExecToolConfig = self.create_action('execute', "Execute Tool...", self.execToolConfig) # Adding tools, groups, sets and configurations self.actAddToolFile = self.create_action('add', "Add Tool", self.addToolFile) self.actAddToolGroup = self.create_action('add', "Create Tool Group", self.addNewToolGroup) self.actAddNewToolSet = self.create_action('add', "Create Tool Set", self.addNewToolSet) self.actNewConfig = self.create_action('add', "Add New Tool Configuration", self.newConfig) self.actAddParam = self.create_action('add', "Add New Param", self.addParam) self.actEditParam = self.create_action('rename', "Edit Param", self.editParam) self.actOpenDocumentation = self.create_action('calendar_view_day', "Open Documentation", self.openDocumentation) self.actChangeClassModule = self.create_action( 'rename', "Change Module Class Name", self.changeClassModule) self.actChangePathToTools = self.create_action('rename', "Change Path to Tools", self.changePathToTools) # moving tools up and down self.actMoveNodeUp = self.create_action('arrow_up', "Move Up", self.moveNodeUp) self.actMoveNodeDown = self.create_action('arrow_down', "Move Down", self.moveNodeDown) self.actExecBatch = self.create_action('execute', "Execute Tool Set", self.execBatch) self.actExportXMLToFile = self.create_action( 'export', "Export XML Node To File", self.exportXMLToFile) self.actImportXMLFromFile = self.create_action( 'import', "Import XML Node From File", self.importXMLFromFile) def addParam(self): assert self.has_selected_item() item = self.selected_item() node = item.node window = addParamGui(self.manager.base_widget, None) window.setModal(True) window.show() if window.exec_() == window.Accepted: name = str(window.nameEdit.text()) typ = str(window.typeComboBox.currentText()) default = str(window.defaultEdit.text()) required = str(window.requiredComboBox.currentText()) attributes = { 'name': name, 'param_type': typ, 'required': required } node = Element('param', attributes) node.text = default if self.model.insertRow(0, self.selected_index(), node) == False: MessageBox.error( mainwindow=self.view, text='Parameter Name Exists', detailed_text=( 'The parameter name to add is "%s" ' 'but there is already a parameter with that name.' % name)) return self.view.expand(self.selected_index()) def editParam(self): assert self.has_selected_item() item = self.selected_item() node = item.node window = addParamGui(self.manager.base_widget, node) window.setModal(True) window.show() if window.exec_() == window.Accepted: name = str(window.nameEdit.text()) typ = str(window.typeComboBox.currentText()) default = str(window.defaultEdit.text()) required = str(window.requiredComboBox.currentText()) self.model.make_item_local(item) node.set('name', name) node.set('param_type', typ) node.set('required', required) node.text = default def changeClassModule(self): ''' Opens a dialog box for changing the class module. ''' assert self.has_selected_item() item = self.selected_item() node = item.node dialog = RenameDialog(node.text, [], self.view) if dialog.exec_() == dialog.Accepted: node.text = dialog.accepted_name self.model.make_item_local(item) def changePathToTools(self): ''' Opens a dialog box for changing the path to tools. ''' assert self.has_selected_item() item = self.selected_item() node = item.node dialog = RenameDialog(node.text, [], self.view) if dialog.exec_() == dialog.Accepted: node.text = dialog.accepted_name self.model.make_item_local(item) def addToolFile(self): ''' NO DOCUMENTATION ''' assert self.has_selected_item() tool_node = Element('tool', {'name': 'unnamed_tool'}) SubElement(tool_node, "class_module").text = 'unnamed_module' SubElement(tool_node, "params") self.model.insertRow(0, self.selected_index(), tool_node) self.view.expand(self.selected_index()) def addNewToolSet(self): ''' NO DOCUMENTATION ''' assert self.has_selected_item() # First add the dummy toolset shell toolset_node = Element('tool_set', {'name': 'unnamed_tool_set'}) self.model.insertRow(0, self.selected_index(), toolset_node) def addNewToolGroup(self): ''' NO DOCUMENTATION ''' assert self.has_selected_item() # First add the dummy toolset shell node = Element('tool_group', { 'name': 'unnamed_tool_group', 'setexpanded': 'True' }) self.model.insertRow(0, self.selected_index(), node) def newConfig(self): ''' NO DOCUMENTATION ''' assert self.has_selected_item() index = self.selected_index() tool_library_node = get_tool_library_node(self.project) callback = \ lambda node: self.model.insertRow(0, index, node) window = ConfigureToolGui(tool_library_node, callback, self.view) window.setModal(True) window.show() def moveNodeUp(self): ''' NO DOCUMENTATION ''' # TODO connect directly to lambda assert self.has_selected_item() new_index = self.model.move_up(self.selected_index(), view=self.view) self.view.setCurrentIndex(new_index) def moveNodeDown(self): ''' NO DOCUMENTATION ''' # TODO connect directly to lambda assert self.has_selected_item() new_index = self.model.move_down(self.selected_index(), view=self.view) self.view.setCurrentIndex(new_index) def openDocumentation(self): ''' NO DOCUMENTATION ''' print 'NOTE openDocumentation for tools is disabled for now.' return # assert self.has_selected_item() # filePath = self.selected_item().node.text # fileInfo = QFileInfo(filePath) # baseInfo = QFileInfo(self.toolboxbase.xml_file) # baseDir = baseInfo.absolutePath() # newFile = QFileInfo(QString(baseDir).append("/").append(QString(fileInfo.filePath()))) # fileName = newFile.absoluteFilePath().trimmed() # x = util.documentationbase.DocumentationTab(self.mainwindow, # QString(fileName)) def execToolFile(self): ''' Show a dialog box that lets the user configure and execute a tool. ''' assert self.has_selected_item() tool_lib_node = get_tool_library_node(self.project) params = {'tool_path': get_path_to_tool_modules(self.project)} tool_node = self.selected_item().node try: module_name = tool_node.find('class_module').text import_path = params['tool_path'] + '.' + module_name importString = "from %s import opusRun" % (import_path) exec(importString) except Exception, e: print e MessageBox.error( mainwindow=self.view, text='Invalid module name', detailed_text= ('This tool points to a module named "%s" ' 'but there is no module with that name, or module returned import error.' % import_path)) return window = ExecuteToolGui(parent_widget=self.manager.base_widget, tool_node=tool_node, tool_config=None, tool_library_node=tool_lib_node, params=params) window.setModal(True) window.show()