CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BrowserPlugin.py
Go to the documentation of this file.
1 import os.path
2 import logging
3 
4 from PyQt4.QtCore import QVariant
5 
6 from Vispa.Main.VispaPlugin import VispaPlugin
7 from Vispa.Views.AbstractView import AbstractView
8 from Vispa.Main.Exceptions import NoCurrentTabControllerException
9 
11  """ The BrowserPlugin supplies the view menu and supports center views.
12  """
13 
14  def __init__(self, application=None):
15  logging.debug(__name__ + ": __init__")
16  VispaPlugin.__init__(self, application)
20  self._startUp=True
21 
22  def startUp(self):
23  self._startUp=False
24  self._fillMenu()
25 
27  return self._defaultCenterViewId
28 
30  return self._disabledCenterViewIds
31 
32  def setDisabledCenterViewIds(self,ids):
33  self._disabledCenterViewIds=ids
34 
36  return self._availableCenterViews
37 
38  def _fillMenu(self):
39  """ Fill specific menu.
40  """
41  self._viewMenu = self.application().createPluginMenu('&View')
42  self._expandAllAction = self.application().createAction('&Expand all', self._expandAll,"Ctrl+E")
43  self._viewMenu.addAction(self._expandAllAction)
44  self._expandToDepthAction = self.application().createAction('Expand to &depth...', self._expandToDepth, "Ctrl+Shift+E")
45  self._viewMenu.addAction(self._expandToDepthAction)
46  self._collapseAllAction = self.application().createAction('&Collapse all', self._collapseAll,"Ctrl+L")
47  self._viewMenu.addAction(self._collapseAllAction)
48  self._viewMenu.addSeparator()
49  self._filterAction = self.application().createAction('&Apply filter...', self.filterDialog, "Ctrl+P")
50  self._viewMenu.addAction(self._filterAction)
51  self._boxContentAction = self.application().createAction('Show &object details...', self._showBoxContentDialog, "Ctrl+B")
52  self._viewMenu.addAction(self._boxContentAction)
53  self._saveImageAction = self.application().createAction('&Save image...', self.saveImage, "Ctrl+I")
54  self._viewMenu.addAction(self._saveImageAction)
55  self._zoomAction = self.application().createAction('&Zoom...', self.zoomDialog, "Ctrl+Shift+Z")
56  self._viewMenu.addAction(self._zoomAction)
57  self._viewMenu.addSeparator()
58 
59  def viewMenu(self):
60  return self._viewMenu
61 
62  def _expandAll(self):
63  """ Calls expandAll() function of tree view.
64  """
65  try:
66  self.application().currentTabController().tab().treeView().expandAll()
67  except NoCurrentTabControllerException:
68  logging.warning(self.__class__.__name__ + ": _expandAll() - No tab controller found.")
69 
70  def _expandToDepth(self):
71  """ Calls expandToDepthDialog() function of current tab controller.
72  """
73  try:
74  self.application().currentTabController().tab().treeView().expandToDepthDialog()
75  except NoCurrentTabControllerException:
76  logging.warning(self.__class__.__name__ + ": _expandToDepth() - No tab controller found.")
77 
78  def _collapseAll(self):
79  """ Calls collapseAll() function of tree view.
80  """
81  try:
82  self.application().currentTabController().tab().treeView().collapseAll()
83  except NoCurrentTabControllerException:
84  logging.warning(self.__class__.__name__ + ": _collapseAll() - No tab controller found.")
85 
86  def filterDialog(self):
87  """ Calls filterDialog() function of current tab controller.
88  """
89  try:
90  self.application().currentTabController().filterDialog()
91  except NoCurrentTabControllerException:
92  logging.warning(self.__class__.__name__ + ": filterDialog() - No tab controller found.")
93 
95  """ Calls showBoxContentDialog() function of current tab controller.
96  """
97  try:
98  self.application().currentTabController().showBoxContentDialog()
99  except NoCurrentTabControllerException:
100  logging.warning(self.__class__.__name__ + ": showBoxContentDialog() - No tab controller found.")
101 
102  def zoomDialog(self):
103  """ Calls zoomDialog() function of current tab controller.
104  """
105  try:
106  self.application().currentTabController().zoomDialog()
107  except NoCurrentTabControllerException:
108  logging.warning(self.__class__.__name__ + ": zoomDialog() - No tab controller found.")
109 
110  def saveImage(self):
111  """ Calls saveImage() function of current tab controller.
112  """
113  try:
114  self.application().currentTabController().saveImage()
115  except NoCurrentTabControllerException:
116  logging.warning(self.__class__.__name__ + ": saveImage() - No tab controller found.")
117 
118  def viewClassId(self, viewClass):
119  if not viewClass:# or not isinstance(viewClass, AbstractView):
120  return None
121  return str(viewClass) + str(viewClass.LABEL)
122 
123  def addCenterView(self, viewClass, default=False, enabled=True):
124  """ add a View for the Center View
125 
126  selection: name is the menu entry, function the function to be
127  added as action if the menu is selecteds
128  """
129  logging.debug(__name__ + ": addCenterView")
130  if not issubclass(viewClass, AbstractView):
131  logging.error(self.__class__.__name__ + ": addCenterView() - Cannot add non views as view. Aborting...")
132  return
133  if viewClass in self._availableCenterViews:
134  logging.warning(self.__class__.__name__ + ": Already have a View of type "+ viewClass.__name__ +". Aborting...")
135  return
136  viewClassId=self.viewClassId(viewClass)
137  action = self.application().createAction(viewClass.LABEL, self.switchCenterViewSlot, "Ctrl+"+ str(len(self._availableCenterViews)))
138  action.setCheckable(True)
139  action.setEnabled(enabled)
140  if not enabled:
141  self._disabledCenterViewIds = [viewClassId]
142  action.setData(QVariant(viewClassId))
143  if default:
144  self._defaultCenterViewId = self.viewClassId(viewClass)
145  self._availableCenterViews.append(viewClass)
146  self._viewMenu.addAction(action)
147 
149  """ Slot for center view menu entries.
150 
151  It switches the tab's current center view to the selected view.
152  """
153  requestedViewClassId = self.sender().data().toString()
154  try:
155  self.application().currentTabController().switchCenterView(requestedViewClassId)
156  except NoCurrentTabControllerException:
157  logging.warning(self.__class__.__name__ + ": switchCenterViewSlot() - No tab controller found.")
158 
159  def openFile(self, filename=None):
160  """ Open the requested file in a new tab.
161 
162  This method is called when the user wants to open a file with an extension this plugin.
163  previously registered.
164 
165  This methods overwrites openFile from VispaPlugin.
166  """
167  logging.debug(__name__ + ": openFile " + filename)
168  if self._startUp:
169  self.startUp()
170  if filename == None:
171  return False
172  base = os.path.basename(filename)
173  ext = os.path.splitext(base)[1].lower().strip(".")
174  if ext in [ft.extension() for ft in self.filetypes()]:
175  tab = self.newTab()
176  return tab.controller().open(filename)
177  return False
178 
179  def newTab(self):
180  raise NotImplementedError
181 
182  def boxContentAction(self):
183  return self._boxContentAction
184 
185  def saveImageAction(self):
186  return self._saveImageAction
187 
188  def zoomAction(self):
189  return self._zoomAction
190 
191  def expandAllAction(self):
192  return self._expandAllAction
193 
195  return self._expandToDepthAction
196 
197  def collapseAllAction(self):
198  return self._collapseAllAction
std::string toString(const char *format,...)
Definition: xdaq_compat.cc:4