18 from FWCore.GuiBrowsers.DOTExport
import DotExport
19 import_dotexport_error=
None
25 event_content_error=
None
30 from ToolDataAccessor
import ToolDataAccessor,ConfigToolBase,standardConfigDir
31 from ToolDialog
import ToolDialog
32 import_tools_error=
None
40 logging.debug(__name__ +
": __init__")
41 BrowserTabController.__init__(self, plugin)
52 openEditorAction = self.
plugin().application().createAction(
'&Open in custom editor', self.
openEditor,
"F6")
53 self._configMenu.addAction(openEditorAction)
54 chooseEditorAction = self.
plugin().application().createAction(
'&Choose custom editor...', self.
chooseEditor,
"Ctrl+T")
55 self._configMenu.addAction(chooseEditorAction)
56 self._configMenu.addSeparator()
65 self._configMenu.addSeparator()
72 """ Returns supported file type: py.
74 return [(
'py',
'Config file')]
75 staticSupportedFileTypes = staticmethod(staticSupportedFileTypes)
81 BrowserTabController.updateViewMenu(self)
86 logging.debug(__name__ +
": onCenterViewDoubleClicked()")
91 """ Fill the center view from an item in the TreeView and update it """
96 statusMessage = self.
plugin().application().startWorking(
"Updating center view")
101 if self.
_thread !=
None and self._thread.isRunning():
103 while self._thread.isRunning():
104 if not Application.NO_PROCESS_EVENTS:
105 QCoreApplication.instance().processEvents()
116 while self._thread.isRunning():
117 if not Application.NO_PROCESS_EVENTS:
118 QCoreApplication.instance().processEvents()
119 self.
tab().
centerView().setConnections(self._thread.returnValue())
135 if self.
tab().propertyView().dataObject() != select
and propertyView:
136 self.
tab().propertyView().setDataObject(select)
138 if import_tools_error==
None and self.
tab().editorSplitter():
140 self.
plugin().application().stopWorking(statusMessage)
143 """ Shows plugin menus when user selects tab.
145 logging.debug(__name__ +
": activated()")
146 BrowserTabController.activated(self)
149 self._editorAction.setVisible(
not self.
tab().editorSplitter())
150 if self.
tab().editorSplitter():
152 self.
tab().mainWindow().application().showZoomToolBar()
156 logging.debug(__name__ +
": openEditor")
157 selected_object = self.
tab().propertyView().dataObject()
158 filename = self.
dataAccessor().fullFilename(selected_object)
159 if self.
_editorName !=
"" and selected_object !=
None and os.path.exists(filename):
160 if os.path.expandvars(
"$CMSSW_RELEASE_BASE")
in filename:
161 QMessageBox.information(self.
tab(),
"Opening readonly file...",
"This file is from $CMSSW_RELEASE_BASE and readonly")
163 command +=
" " + filename
168 """ Choose editor using FileDialog """
169 logging.debug(__name__ +
": chooseEditor")
170 if _editorName ==
"":
171 _editorName = str(QFileDialog.getSaveFileName(self.
tab(),
"Choose editor", self.
_editorName,
"Editor (*)",
None , QFileDialog.DontConfirmOverwrite
or QFileDialog.DontResolveSymlinks))
172 if not os.path.exists(_editorName):
173 _editorName = os.path.basename(_editorName)
174 if _editorName !=
None and _editorName !=
"":
179 """ Dump python configuration to file """
180 logging.debug(__name__ +
": dumpPython")
183 logging.error(self.__class__.__name__ +
": dumpPython() - "+
"Cannot dump this config because it does not contain a 'process'.\nNote that only 'cfg' files contain a 'process'.")
184 self.
plugin().application().errorMessage(
"Cannot dump this config because it does not contain a 'process'.\nNote that only 'cfg' files contain a 'process'.")
188 defaultname = os.path.splitext(self.
_filename)[0] +
"_dump" + os.path.splitext(self.
_filename)[1]
189 fileName = str(QFileDialog.getSaveFileName(self.
tab(),
"Save python config...", defaultname,
"Python config (*.py)", filter))
193 if os.path.splitext(fileName)[1].
upper().strip(
".") == ext:
194 name = os.path.splitext(fileName)[0]
195 ext = os.path.splitext(fileName)[1].
upper().strip(
".")
196 text_file =
open(name +
"." + ext.lower(),
"w")
197 text_file.write(dump)
201 """ Show config history """
202 logging.debug(__name__ +
": history")
205 logging.error(self.__class__.__name__ +
": history() - "+
"Cannot show config history because it does not contain a 'process'.\nNote that only 'cfg' files contain a 'process'.")
206 self.
plugin().application().errorMessage(
"Cannot show config history because it does not contain 'process'.\nNote that only 'cfg' files contain a 'process'.")
208 dialog=
TextDialog(self.
tab(),
"Configuration history", history,
True,
"This window lists the parameter changes and tools applied in this configuration file before it was loaded into ConfigEditor.")
212 """ Open event content dialog """
213 logging.debug(__name__ +
": eventContent")
214 if event_content_error!=
None:
215 logging.error(__name__ +
": Could not import EventContentDialog: "+event_content_error[1])
216 self.
plugin().application().errorMessage(
"Could not import EventContentDialog (see logfile for details):\n"+event_content_error[0])
218 dialog=
EventContentDialog(self.
tab(),
"This dialog let's you check if the input needed by your configuration file is in a dataformat or edm root file. You can compare either to a dataformat definition from a txt file (e.g. RECO_3_3_0) or any edm root file by selecting an input file.\n\nBranches that are used as input by your configuration but not present in the dataformat or file are marked in red.\nBranches that are newly created by your configuration are marked in green.")
223 """ read options from ini """
224 ini = self.
plugin().application().ini()
225 if ini.has_option(
"config",
"editor"):
226 self.
_editorName = str(ini.get(
"config",
"editor"))
229 if ini.has_option(
"config",
"CurrentView"):
230 proposed_view = ini.get(
"config",
"CurrentView")
232 proposed_view = self.
plugin().viewClassId(ConnectionStructureView)
234 if ini.has_option(
"config",
"box content script")
and isinstance(self.
centerView(),ConfigEditorBoxView):
235 self.
centerView().setBoxContentScript(str(ini.get(
"config",
"box content script")))
236 self._boxContentDialog.setScript(str(ini.get(
"config",
"box content script")))
239 BrowserTabController.scriptChanged(self, script)
243 """ write options to ini """
244 ini = self.
plugin().application().ini()
245 if not ini.has_section(
"config"):
246 ini.add_section(
"config")
250 if isinstance(self.
centerView(),ConfigEditorBoxView):
251 ini.set(
"config",
"box content script", self.
centerView().boxContentScript())
252 self.
plugin().application().writeIni()
255 if import_dotexport_error!=
None:
256 logging.error(__name__ +
": Could not import DOTExport: "+import_dotexport_error[1])
257 self.
plugin().application().errorMessage(
"Could not import DOTExport (see logfile for details):\n"+import_dotexport_error[0])
261 presets = {
'seqconnect':
False,
'tagconnect':
True,
'seq':
False,
'services':
False,
'es':
False,
'endpath':
True,
'source':
True,
'legend':
False}
263 presets = {
'seqconnect':
True,
'tagconnect':
False,
'seq':
True,
'services':
False,
'es':
False,
'endpath':
True,
'source':
True,
'legend':
False}
264 for opt, val
in presets.items():
265 dot.setOption(opt, val)
267 for ft
in dot.file_types:
270 types += ft.upper() +
" File (*." + ft.lower() +
")"
271 filter = QString(
"PDF File (*.pdf)")
273 defaultname = os.path.splitext(self.
_filename)[0] +
"_export"
274 fileName = str(QFileDialog.getSaveFileName(self.
tab(),
"Export dot graphic...", defaultname, types, filter))
277 ext = str(filter).
split(
" ")[0].lower()
278 if os.path.splitext(fileName)[1].lower().strip(
".")
in dot.file_types:
279 name = os.path.splitext(fileName)[0]
280 ext = os.path.splitext(fileName)[1].lower().strip(
".")
286 logging.error(self.__class__.__name__ +
": exportDot() - "+
"'dot' executable not found which is needed for conversion to '*." + ext +
"'. Created '*.dot' file instead.")
287 self.
plugin().application().errorMessage(
"'dot' executable not found which is needed for conversion to '*." + ext +
"'. Created '*.dot' file instead.")
289 logging.error(self.__class__.__name__ +
": exportDot() - "+
"Could not export dot graphic (see logfile for details): " + str(e))
293 """ Reads in the file in a separate thread.
301 if self.
plugin().application().commandLineOptions().saveimage:
303 self.
saveImage(self.
plugin().application().commandLineOptions().saveimage)
304 print "Saved image to", self.
plugin().application().commandLineOptions().saveimage,
"."
310 logging.debug(__name__ +
': save')
314 logging.error(self.__class__.__name__ +
": save() - "+
"Cannot use name of original configuration file: "+str(filename))
315 self.
plugin().application().errorMessage(
"Cannot use name of original configuration file.")
316 elif BrowserTabController.save(self, filename):
322 return BrowserTabController.save(self, filename)
323 return self.
tab().mainWindow().application().saveFileAsDialog()
326 """ Write replace config file.
328 logging.debug(__name__ +
': writeFile')
330 text_file =
open(filename,
"w")
337 def open(self, filename=None, update=True):
338 if BrowserTabController.open(self, filename, update):
345 logging.debug(__name__ +
": startEditMode")
346 if import_tools_error!=
None:
347 logging.error(__name__ +
": Could not import tools for ConfigEditor: "+import_tools_error[1])
348 self.
plugin().application().errorMessage(
"Could not import tools for ConfigEditor (see logfile for details):\n"+import_tools_error[0])
350 if self.
tab().editorSplitter():
353 logging.error(__name__ +
": Config does not contain a process and cannot be edited using ConfigEditor.")
354 self.
plugin().application().errorMessage(
"Config does not contain a process and cannot be edited using ConfigEditor.")
359 self.
tab().createEditor()
372 self._toolDataAccessor.setConfigDataAccessor(self.
dataAccessor())
377 self.connect(self.
tab().editorTableView(), SIGNAL(
'selected'), self.
codeSelected)
378 self.connect(self.
tab().propertyView(), SIGNAL(
'valueChanged'), self.
valueChanged)
385 if self.
tab().originalButton().isChecked():
387 self.
tab().minimizeButton().setChecked(
True)
388 self.
tab().originalButton().setChecked(
False)
389 self.
tab().maximizeButton().setChecked(
False)
390 self.
tab().verticalSplitter().setSizes([100, 1, 0])
393 self.
tab().minimizeButton().setChecked(
False)
394 self.
tab().originalButton().setChecked(
True)
395 self.
tab().maximizeButton().setChecked(
False)
399 if self.
tab().originalButton().isChecked():
401 self.
tab().minimizeButton().setChecked(
False)
402 self.
tab().originalButton().setChecked(
False)
403 self.
tab().maximizeButton().setChecked(
True)
404 self.
tab().verticalSplitter().setSizes([0, 1, 100])
407 logging.debug(__name__ +
": _updateCode")
408 self.
tab().propertyView().setEnabled(
False)
412 self.
tab().editorTableView().restoreSelection()
414 self.
tab().propertyView().setEnabled(
True)
417 logging.debug(__name__ +
": importConfig")
418 statusMessage = self.
plugin().application().startWorking(
"Import python configuration in Editor")
420 good=self.
open(filename,
False)
423 self.
plugin().application().errorMessage(
"Could not open configuration file (see log file for details).")
424 self.
plugin().application().stopWorking(statusMessage,
"failed")
427 logging.error(__name__ +
": Could not open configuration file.")
428 self.
plugin().application().errorMessage(
"Could not open configuration file.")
429 self.
plugin().application().stopWorking(statusMessage,
"failed")
432 logging.error(__name__ +
": Config does not contain a process and cannot be edited using ConfigEditor.")
433 self.
plugin().application().errorMessage(
"Config does not contain a process and cannot be edited using ConfigEditor.")
434 self.
plugin().application().stopWorking(statusMessage,
"failed")
440 self.
tab().propertyView().setDataObject(
None)
442 self._applyPatToolAction.setVisible(
True)
443 self.
plugin().application().stopWorking(statusMessage)
453 logging.debug(__name__ +
": importButtonClicked")
454 filename = QFileDialog.getOpenFileName(
455 self.
tab(),
'Select a configuration file',standardConfigDir,
"Python configuration (*.py)")
456 if not filename.isEmpty():
460 logging.debug(__name__ +
": applyButtonClicked")
464 if not self._toolDialog.exec_():
470 self.
tab().editorTableView().
select(self.
tab().editorTableView().dataObjects()[-2])
474 logging.debug(__name__ +
": removeButtonClicked")
476 self._toolDataAccessor.label(object)
in [
"Import",
"ApplyTool"]:
479 self.
plugin().application().errorMessage(
"Could not apply tool. See log file for details.")
483 self.
tab().editorTableView().
select(self.
tab().editorTableView().dataObjects()[-1])
488 BrowserTabController.onSelected(self, select)
491 self.
tab().propertyView().setDataObject(
None)
492 BrowserTabController.refresh(self)
495 if import_tools_error==
None and isinstance(object,ConfigToolBase):
499 BrowserTabController.updateContent(self, filtered, propertyView)
503 BrowserTabController.select(self, object)
506 if import_tools_error==
None and isinstance(object,ConfigToolBase):
512 if self.
tab().propertyView().dataObject() != select:
513 statusMessage = self.
plugin().application().startWorking(
"Updating property view")
515 self.
tab().propertyView().setDataObject(select)
517 self.
plugin().application().stopWorking(statusMessage)
521 if isinstance(self.
tab().propertyView().dataObject(),ConfigToolBase):
522 if self._toolDataAccessor.label(self.
tab().propertyView().dataObject())==
"Import":
523 filename=self.
toolDataAccessor().propertyValue(self.
tab().propertyView().dataObject(),
"filename")
def onCenterViewDoubleClicked
def staticSupportedFileTypes
def updateConfigHighlight
def currentCenterViewClassId