1 from __future__
import absolute_import
19 from FWCore.GuiBrowsers.DOTExport
import DotExport
20 import_dotexport_error=
None
21 except Exception
as e:
26 event_content_error=
None
27 except Exception
as e:
31 from .ToolDataAccessor
import ToolDataAccessor,ConfigToolBase,standardConfigDir
32 from .ToolDialog
import ToolDialog
33 import_tools_error=
None
34 except Exception
as e:
41 logging.debug(__name__ +
": __init__")
42 BrowserTabController.__init__(self, plugin)
53 openEditorAction = self.
plugin().application().createAction(
'&Open in custom editor', self.
openEditor,
"F6")
54 self._configMenu.addAction(openEditorAction)
55 chooseEditorAction = self.
plugin().application().createAction(
'&Choose custom editor...', self.
chooseEditor,
"Ctrl+T")
56 self._configMenu.addAction(chooseEditorAction)
57 self._configMenu.addSeparator()
66 self._configMenu.addSeparator()
73 """ Returns supported file type: py.
75 return [(
'py',
'Config file')]
76 staticSupportedFileTypes = staticmethod(staticSupportedFileTypes)
82 BrowserTabController.updateViewMenu(self)
87 logging.debug(__name__ +
": onCenterViewDoubleClicked()")
92 """ Fill the center view from an item in the TreeView and update it """
97 statusMessage = self.
plugin().application().startWorking(
"Updating center view")
102 if self.
_thread !=
None and self._thread.isRunning():
104 while self._thread.isRunning():
105 if not Application.NO_PROCESS_EVENTS:
106 QCoreApplication.instance().processEvents()
117 while self._thread.isRunning():
118 if not Application.NO_PROCESS_EVENTS:
119 QCoreApplication.instance().processEvents()
120 self.
tab().
centerView().setConnections(self._thread.returnValue())
136 if self.
tab().propertyView().dataObject() != select
and propertyView:
137 self.
tab().propertyView().setDataObject(select)
139 if import_tools_error==
None and self.
tab().editorSplitter():
141 self.
plugin().application().stopWorking(statusMessage)
144 """ Shows plugin menus when user selects tab.
146 logging.debug(__name__ +
": activated()")
147 BrowserTabController.activated(self)
150 self._editorAction.setVisible(
not self.
tab().editorSplitter())
151 if self.
tab().editorSplitter():
153 self.
tab().mainWindow().application().showZoomToolBar()
157 logging.debug(__name__ +
": openEditor")
158 selected_object = self.
tab().propertyView().dataObject()
159 filename = self.
dataAccessor().fullFilename(selected_object)
160 if self.
_editorName !=
"" and selected_object !=
None and os.path.exists(filename):
161 if os.path.expandvars(
"$CMSSW_RELEASE_BASE")
in filename:
162 QMessageBox.information(self.
tab(),
"Opening readonly file...",
"This file is from $CMSSW_RELEASE_BASE and readonly")
164 command +=
" " + filename
169 """ Choose editor using FileDialog """
170 logging.debug(__name__ +
": chooseEditor")
171 if _editorName ==
"":
172 _editorName = str(QFileDialog.getSaveFileName(self.
tab(),
"Choose editor", self.
_editorName,
"Editor (*)",
None , QFileDialog.DontConfirmOverwrite
or QFileDialog.DontResolveSymlinks))
173 if not os.path.exists(_editorName):
174 _editorName = os.path.basename(_editorName)
175 if _editorName !=
None and _editorName !=
"":
180 """ Dump python configuration to file """
181 logging.debug(__name__ +
": dumpPython")
184 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'.")
185 self.
plugin().application().errorMessage(
"Cannot dump this config because it does not contain a 'process'.\nNote that only 'cfg' files contain a 'process'.")
189 defaultname = os.path.splitext(self.
_filename)[0] +
"_dump" + os.path.splitext(self.
_filename)[1]
190 fileName = str(QFileDialog.getSaveFileName(self.
tab(),
"Save python config...", defaultname,
"Python config (*.py)", filter))
194 if os.path.splitext(fileName)[1].
upper().strip(
".") == ext:
195 name = os.path.splitext(fileName)[0]
196 ext = os.path.splitext(fileName)[1].
upper().strip(
".")
197 text_file =
open(name +
"." + ext.lower(),
"w")
198 text_file.write(dump)
202 """ Show config history """
203 logging.debug(__name__ +
": history")
206 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'.")
207 self.
plugin().application().errorMessage(
"Cannot show config history because it does not contain 'process'.\nNote that only 'cfg' files contain a 'process'.")
209 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.")
213 """ Open event content dialog """
214 logging.debug(__name__ +
": eventContent")
215 if event_content_error!=
None:
216 logging.error(__name__ +
": Could not import EventContentDialog: "+event_content_error[1])
217 self.
plugin().application().errorMessage(
"Could not import EventContentDialog (see logfile for details):\n"+event_content_error[0])
219 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.")
224 """ read options from ini """
225 ini = self.
plugin().application().ini()
226 if ini.has_option(
"config",
"editor"):
227 self.
_editorName = str(ini.get(
"config",
"editor"))
230 if ini.has_option(
"config",
"CurrentView"):
231 proposed_view = ini.get(
"config",
"CurrentView")
233 proposed_view = self.
plugin().viewClassId(ConnectionStructureView)
235 if ini.has_option(
"config",
"box content script")
and isinstance(self.
centerView(),ConfigEditorBoxView):
236 self.
centerView().setBoxContentScript(str(ini.get(
"config",
"box content script")))
237 self._boxContentDialog.setScript(str(ini.get(
"config",
"box content script")))
240 BrowserTabController.scriptChanged(self, script)
244 """ write options to ini """
245 ini = self.
plugin().application().ini()
246 if not ini.has_section(
"config"):
247 ini.add_section(
"config")
251 if isinstance(self.
centerView(),ConfigEditorBoxView):
252 ini.set(
"config",
"box content script", self.
centerView().boxContentScript())
253 self.
plugin().application().writeIni()
256 if import_dotexport_error!=
None:
257 logging.error(__name__ +
": Could not import DOTExport: "+import_dotexport_error[1])
258 self.
plugin().application().errorMessage(
"Could not import DOTExport (see logfile for details):\n"+import_dotexport_error[0])
262 presets = {
'seqconnect':
False,
'tagconnect':
True,
'seq':
False,
'services':
False,
'es':
False,
'endpath':
True,
'source':
True,
'legend':
False}
264 presets = {
'seqconnect':
True,
'tagconnect':
False,
'seq':
True,
'services':
False,
'es':
False,
'endpath':
True,
'source':
True,
'legend':
False}
265 for opt, val
in presets.items():
266 dot.setOption(opt, val)
268 for ft
in dot.file_types:
271 types += ft.upper() +
" File (*." + ft.lower() +
")"
272 filter = QString(
"PDF File (*.pdf)")
274 defaultname = os.path.splitext(self.
_filename)[0] +
"_export"
275 fileName = str(QFileDialog.getSaveFileName(self.
tab(),
"Export dot graphic...", defaultname, types, filter))
278 ext = str(filter).
split(
" ")[0].lower()
279 if os.path.splitext(fileName)[1].lower().strip(
".")
in dot.file_types:
280 name = os.path.splitext(fileName)[0]
281 ext = os.path.splitext(fileName)[1].lower().strip(
".")
287 logging.error(self.__class__.__name__ +
": exportDot() - "+
"'dot' executable not found which is needed for conversion to '*." + ext +
"'. Created '*.dot' file instead.")
288 self.
plugin().application().errorMessage(
"'dot' executable not found which is needed for conversion to '*." + ext +
"'. Created '*.dot' file instead.")
289 except Exception
as e:
290 logging.error(self.__class__.__name__ +
": exportDot() - "+
"Could not export dot graphic (see logfile for details): " + str(e))
294 """ Reads in the file in a separate thread.
302 if self.
plugin().application().commandLineOptions().saveimage:
304 self.
saveImage(self.
plugin().application().commandLineOptions().saveimage)
305 print "Saved image to", self.
plugin().application().commandLineOptions().saveimage,
"."
311 logging.debug(__name__ +
': save')
315 logging.error(self.__class__.__name__ +
": save() - "+
"Cannot use name of original configuration file: "+str(filename))
316 self.
plugin().application().errorMessage(
"Cannot use name of original configuration file.")
317 elif BrowserTabController.save(self, filename):
323 return BrowserTabController.save(self, filename)
324 return self.
tab().mainWindow().application().saveFileAsDialog()
327 """ Write replace config file.
329 logging.debug(__name__ +
': writeFile')
331 text_file =
open(filename,
"w")
338 def open(self, filename=None, update=True):
339 if BrowserTabController.open(self, filename, update):
346 logging.debug(__name__ +
": startEditMode")
347 if import_tools_error!=
None:
348 logging.error(__name__ +
": Could not import tools for ConfigEditor: "+import_tools_error[1])
349 self.
plugin().application().errorMessage(
"Could not import tools for ConfigEditor (see logfile for details):\n"+import_tools_error[0])
351 if self.
tab().editorSplitter():
354 logging.error(__name__ +
": Config does not contain a process and cannot be edited using ConfigEditor.")
355 self.
plugin().application().errorMessage(
"Config does not contain a process and cannot be edited using ConfigEditor.")
360 self.
tab().createEditor()
373 self._toolDataAccessor.setConfigDataAccessor(self.
dataAccessor())
378 self.connect(self.
tab().editorTableView(), SIGNAL(
'selected'), self.
codeSelected)
379 self.connect(self.
tab().propertyView(), SIGNAL(
'valueChanged'), self.
valueChanged)
386 if self.
tab().originalButton().isChecked():
388 self.
tab().minimizeButton().setChecked(
True)
389 self.
tab().originalButton().setChecked(
False)
390 self.
tab().maximizeButton().setChecked(
False)
391 self.
tab().verticalSplitter().setSizes([100, 1, 0])
394 self.
tab().minimizeButton().setChecked(
False)
395 self.
tab().originalButton().setChecked(
True)
396 self.
tab().maximizeButton().setChecked(
False)
400 if self.
tab().originalButton().isChecked():
402 self.
tab().minimizeButton().setChecked(
False)
403 self.
tab().originalButton().setChecked(
False)
404 self.
tab().maximizeButton().setChecked(
True)
405 self.
tab().verticalSplitter().setSizes([0, 1, 100])
408 logging.debug(__name__ +
": _updateCode")
409 self.
tab().propertyView().setEnabled(
False)
413 self.
tab().editorTableView().restoreSelection()
415 self.
tab().propertyView().setEnabled(
True)
418 logging.debug(__name__ +
": importConfig")
419 statusMessage = self.
plugin().application().startWorking(
"Import python configuration in Editor")
421 good=self.
open(filename,
False)
424 self.
plugin().application().errorMessage(
"Could not open configuration file (see log file for details).")
425 self.
plugin().application().stopWorking(statusMessage,
"failed")
428 logging.error(__name__ +
": Could not open configuration file.")
429 self.
plugin().application().errorMessage(
"Could not open configuration file.")
430 self.
plugin().application().stopWorking(statusMessage,
"failed")
433 logging.error(__name__ +
": Config does not contain a process and cannot be edited using ConfigEditor.")
434 self.
plugin().application().errorMessage(
"Config does not contain a process and cannot be edited using ConfigEditor.")
435 self.
plugin().application().stopWorking(statusMessage,
"failed")
441 self.
tab().propertyView().setDataObject(
None)
443 self._applyPatToolAction.setVisible(
True)
444 self.
plugin().application().stopWorking(statusMessage)
454 logging.debug(__name__ +
": importButtonClicked")
455 filename = QFileDialog.getOpenFileName(
456 self.
tab(),
'Select a configuration file',standardConfigDir,
"Python configuration (*.py)")
457 if not filename.isEmpty():
461 logging.debug(__name__ +
": applyButtonClicked")
465 if not self._toolDialog.exec_():
471 self.
tab().editorTableView().
select(self.
tab().editorTableView().dataObjects()[-2])
475 logging.debug(__name__ +
": removeButtonClicked")
477 self._toolDataAccessor.label(object)
in [
"Import",
"ApplyTool"]:
480 self.
plugin().application().errorMessage(
"Could not apply tool. See log file for details.")
484 self.
tab().editorTableView().
select(self.
tab().editorTableView().dataObjects()[-1])
489 BrowserTabController.onSelected(self, select)
492 self.
tab().propertyView().setDataObject(
None)
493 BrowserTabController.refresh(self)
496 if import_tools_error==
None and isinstance(object,ConfigToolBase):
500 BrowserTabController.updateContent(self, filtered, propertyView)
504 BrowserTabController.select(self, object)
507 if import_tools_error==
None and isinstance(object,ConfigToolBase):
513 if self.
tab().propertyView().dataObject() != select:
514 statusMessage = self.
plugin().application().startWorking(
"Updating property view")
516 self.
tab().propertyView().setDataObject(select)
518 self.
plugin().application().stopWorking(statusMessage)
522 if isinstance(self.
tab().propertyView().dataObject(),ConfigToolBase):
523 if self._toolDataAccessor.label(self.
tab().propertyView().dataObject())==
"Import":
524 filename=self.
toolDataAccessor().propertyValue(self.
tab().propertyView().dataObject(),
"filename")
def onCenterViewDoubleClicked
def staticSupportedFileTypes
def updateConfigHighlight
def currentCenterViewClassId