1 from __future__
import absolute_import
9 from PyQt4.QtGui import QDialog,QListWidget,QVBoxLayout,QHBoxLayout,QToolButton,QPushButton,QSplitter,QFileDialog,QMessageBox
14 from .ToolDataAccessor
import standardToolsDir,ConfigToolBase
18 logging.debug(__name__ +
': __init__')
19 QDialog.__init__(self,parent)
25 self.setWindowFlags(Qt.Window)
26 self.setWindowTitle(
"Apply tool...")
30 logging.debug(__name__ +
': fill')
31 self.setLayout(QVBoxLayout())
41 self.layout().addLayout(bottom)
42 changedir=QPushButton(
"&Change tools directory...")
43 bottom.addWidget(changedir)
44 self.connect(changedir, SIGNAL(
'clicked()'), self.
changedir)
45 help=QPushButton(
"&Help")
46 bottom.addWidget(help)
47 self.connect(help, SIGNAL(
'clicked()'), self.
help)
49 cancel = QPushButton(
'&Cancel')
50 bottom.addWidget(cancel)
51 self.connect(cancel, SIGNAL(
'clicked()'), self.reject)
52 self.
ok=QPushButton(
"&Apply")
53 bottom.addWidget(self.
ok)
54 self.ok.setDefault(
True)
55 self.connect(self.
ok, SIGNAL(
'clicked()'), self.
apply)
58 self._toolList.clear()
60 toolsFiles = [os.path.join(self.
_toolsDir,f)
for f
in os.listdir(self.
_toolsDir)
if f.endswith(
".py")
and not f.startswith(
"_")]
62 for toolsFile
in toolsFiles:
63 pythonModule = os.path.splitext(os.path.basename(toolsFile))[0]
64 module=imp.load_source(pythonModule, toolsFile)
65 for name
in dir(module):
66 tool=getattr(module,name)
67 if inspect.isclass(tool)
and issubclass(tool,ConfigToolBase)
and not self._toolDataAccessor.label(tool)
in self._toolsDict.keys()
and not tool==ConfigToolBase:
68 self.
_toolsDict[self._toolDataAccessor.label(tool)]=tool
72 if len(self._toolsDict.keys())==0
and self.
_toolsDir==standardToolsDir:
73 logging.error(__name__ +
": Could not find any PAT tools. These will be available for the ConfigEditor in a future release.")
74 QCoreApplication.instance().errorMessage(
"Could not find any PAT tools. These will be available for the ConfigEditor in a future release.")
76 for item
in self._toolsDict.keys():
77 self._toolList.addItem(item)
78 self._toolList.sortItems()
81 if event.modifiers() == Qt.ControlModifier
and event.key() == Qt.Key_W:
83 QDialog.keyPressEvent(self, event)
91 self._properties.updateContent()
94 self._properties.setDataAccessor(accessor)
102 if not self.ok.hasFocus():
103 self._properties.clearFocus()
106 parameterErrors=self._toolDataAccessor.parameterErrors(self.
_selectedTool)
107 if len(parameterErrors)>0:
108 message=
"\n".
join([error
for error
in parameterErrors])
109 QCoreApplication.instance().errorMessage(message)
114 self._selectedTool.apply(self._toolDataAccessor.configDataAccessor().
process())
115 if not self._toolDataAccessor.configDataAccessor().
process().checkRecording():
117 logging.error(__name__ +
": Could not apply tool "+self._toolDataAccessor.label(self.
_selectedTool)+
" (problem with enable recording flag) Please restart the ConfigEditor.")
118 QCoreApplication.instance().errorMessage(
"Could not apply tool "+self._toolDataAccessor.label(self.
_selectedTool)+
" (problem with enable recording flag) Please restart the ConfigEditor.")
119 except Exception
as e:
122 QCoreApplication.instance().errorMessage(
"Cannot apply tool "+self._toolDataAccessor.label(self.
_selectedTool)+
" (see log file for details):\n"+str(e))
125 logging.error(__name__ +
": Could not apply tool: No tool selected.")
126 QCoreApplication.instance().errorMessage(
"Cannot apply tool: No tool selected.")
128 self._toolDataAccessor.configDataAccessor().setProcess(self.
_processCopy)
133 filename = QFileDialog.getExistingDirectory(
134 self,
'Select a directory',self.
_toolsDir,QFileDialog.ShowDirsOnly)
135 if not filename.isEmpty():
140 QMessageBox.about(self,
'Info',
"This dialog let's you choose and configure a tool.\n 1. Select a tool on the left\n 2. Set the parameters on the right. If you hold the mouse over a parameter name a tooltip with a description of the parameter will show up.\n 3. Apply the tool. In case the tool has wrong parameters set an error message will be displayed.")
static std::string join(char **cmd)