test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
VispaPlugin.py
Go to the documentation of this file.
1 import logging
2 
3 from PyQt4.QtCore import QObject
4 
5 from Vispa.Main.Filetype import Filetype
6 
7 class VispaPlugin(QObject):
8  """Interface for all VispaPlugins"""
9 
10  def __init__(self, application = None):
11  QObject.__init__(self, application)
12  self._application = application
13 
15  self._filetypes = []
16 
17  def application(self):
18  """ Returns application object.
19  """
20  return self._application
21 
22  def registerFiletype(self, ext, description):
23  """ Registers Filetype object for given extension with description.
24 
25  Description will be shown in open and save dialogs.
26  """
27  self._filetypes.append(Filetype(ext,description))
28 
29  def filetypes(self):
30  """ Returns local list of Filetype objects.
31  """
32  return self._filetypes
33 
34  def registerFiletypesFromTabController(self, TabControllerClass):
35  """Adds supported file types from TabControllerClass.
36 
37  Evaluates the static function staticSupportedFileTypes() of class TabControllerClass."""
38  for (ext, description) in TabControllerClass.staticSupportedFileTypes():
39  self.registerFiletype(ext, description)
40 
41  def openFile(self, filename):
42  """This function has to be implemented by each plugin which can open files.
43 
44  On success it should return True
45  """
46  logging.warning('VispaPlugin: openFile() method not implemented by '+ self.__class__.__name__ +'.')
47  self.application().statusBar().showMessage('Opening of desired file type not implemented.', 10000)
48  return False
49 
50  def addNewFileAction(self, label, slot=None):
51  """Creates a new file action with label and optionally with a callable slot set and appends it to local new file actions list. """
52  self._createNewFileActions.append(self._application.createAction(label, slot,image='filenew'))
53 
54  def getNewFileActions(self):
55  """ Returns local list of new file actions.
56  """
57  return self._createNewFileActions
58 
59  def shutdown(self):
60  """ Cleanup actions for the plugins
61  """
62  pass