CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ConfigEditorPlugin.py
Go to the documentation of this file.
1 import os.path
2 import logging
3 
4 from PyQt4.QtCore import QCoreApplication
5 
6 from Vispa.Plugins.Browser.BrowserPlugin import BrowserPlugin
7 from Vispa.Plugins.Browser.BrowserTab import BrowserTab
8 from Vispa.Main.Exceptions import NoCurrentTabControllerException
9 from Vispa.Main.Exceptions import PluginIgnoredException
10 
11 try:
12  from Vispa.Plugins.ConfigEditor.ConfigDataAccessor import ConfigDataAccessor
13 except Exception,e:
14  raise PluginIgnoredException("cannot import CMSSW: " + str(e))
15 
16 from Vispa.Plugins.ConfigEditor.ConfigEditorTab import ConfigEditorTab
17 from Vispa.Plugins.ConfigEditor.ConfigEditorTabController import ConfigEditorTabController
18 from Vispa.Plugins.ConfigEditor.ConfigEditorBoxView import ConnectionStructureView
19 from Vispa.Plugins.ConfigEditor.ConfigEditorBoxView import SequenceStructureView
20 from Vispa.Views.AbstractView import NoneView
21 
22 class ConfigEditorPlugin(BrowserPlugin):
23  """ The ConfigEditorPlugin opens config files in a ConfigEditorTab.
24  """
25 
26  def __init__(self, application=None, name=None):
27  logging.debug(__name__ + ": __init__")
28  BrowserPlugin.__init__(self, application)
29  self.registerFiletypesFromTabController(ConfigEditorTabController)
30  self.addNewFileAction("New configuration file", self.newFile)
31  self.application().commandLineParser().add_option("-s", "--saveimage", dest="saveimage", help="save center view to image FILE", metavar="FILE")
32 
33  def startUp(self):
34  BrowserPlugin.startUp(self)
35  self.addCenterView(NoneView)
36  self.addCenterView(ConnectionStructureView,True)
37  self.addCenterView(SequenceStructureView)
38 
39  def newTab(self):
40  """ Create ConfigEditorTab and add to MainWindow.
41  """
42  tab = ConfigEditorTab(self.application().mainWindow())
43  controller = ConfigEditorTabController(self)
44  controller.setDataAccessor(ConfigDataAccessor())
45  tab.setController(controller)
46  controller.boxContentDialog().addButton("&Type", "object.type")
47  controller.boxContentDialog().addButton("&Classname", "object.classname")
48  controller.boxContentDialog().addButton("&Filename", "object.filename")
49  controller.boxContentDialog().addButton("&Package", "object.package")
50  self.application().mainWindow().addTab(tab)
51  return tab
52 
53  def newFile(self,new=True):
54  """ Create ConfigEditorTab and add to MainWindow.
55  """
56  if self._startUp:
57  self.startUp()
58  if new:
59  controller=self.newTab().controller()
60  else:
61  try:
62  if isinstance(self.application().currentTabController(),ConfigEditorTabController):
63  controller=self.application().currentTabController()
64  except NoCurrentTabControllerException:
65  controller=None
66  if not controller:
67  logging.error(__name__ + ": No configuration file was opened for editing.")
68  self.application().errorMessage("No configuration file was opened for editing.")
69  return None
70  controller.startEditMode()