Gnumed.wxpython.gmPlugin_Patient

Package Gnumed :: Package wxpython :: Module gmPlugin_Patient |
[frames] | no frames]

# Source Code for Module Gnumed.wxpython.gmPlugin_Patient

      1  """gmPlugin_Patient - base classes for GNUMed's patient plugin architecture.
      2
      3  @copyright: author
      4  @license: GPL v2 or later (details at http://www.gnu.org)
      5  """
      6  ############################################################################
      7  # $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/client/wxpython/gmPlugin_Patient.py,v $
      8  # $Id: gmPlugin_Patient.py,v 1.12 2009-07-17 09:26:53 ncq Exp $
      9  __version__ = "$Revision: 1.12 $"
     10  __author__ = "H.Herb, I.Haywood, K.Hilbert"
     11
     12  import os, sys, re, cPickle, zlib
     13
     14  import wx
     15
     16  from Gnumed.pycommon import gmExceptions, gmGuiBroker, gmCfg
     17  from Gnumed.wxpython import gmShadow
     18
     19  gmPerson = None
     20  _log = gmLog.gmDefLog
     21  _log.Log(gmLog.lInfo, __version__)
     22
     23  #------------------------------------------------------------------
     24 -class BasePlugin:
     25          """Base class for all plugins providing wxPython widgets.
     26
     27          Plugins must have a class descending of this class in
     28          their file, which MUST HAVE THE SAME NAME AS THE FILE.
     29
     30          The file must be in a directory which is loaded by
     31          LoadPluginSet (gui/ for the moment, others may be
     32          added for different plugin types)
     33          """
     34          # NOTE: I anticipate that all plugins will in fact be derived
     35          # from this class. Without the brokers a plugin is useless (IH)
     36 -        def __init__(self, set='', guibroker=None, callbackbroker=None, params=None):
     37                  self.gb = guibroker
     38                  self.cb = callbackbroker
     39                  if self.gb is None:
     40                          self.gb = gmGuiBroker.GuiBroker()
     41                  self.set = set
     42          #-----------------------------------------------------
     43 -        def GetIcon (self):
     44                  """Return icon representing page on the toolbar.
     45
     46                  This is the default behaviour. GetIconData should return
     47                  pickled, compressed and escaped string with the icon data.
     48
     49                  If you want to change the behaviour (because you want to load
     50                  plugin icons from overseas via a satellite link or something
     51                  you need to override this function in your plugin (class).
     52
     53                  Using this standard code also allows us to only import cPickle
     54                  and zlib here and not in each and every plugin module which
     55                  should speed up plugin load time :-)
     56                  """
     57                  # FIXME: load from config which plugin we want
     58                  # which_icon is a cookie stored on the backend by a config manager,
     59                  # it tells the plugin which icon to return data for,
     60                  which_icon = None
     61                  icon_data = self.GetIconData(which_icon)
     62                  if icon_data is None:
     63                          return None
     64                  else:
     65                          return wx.BitmapFromXPMData(cPickle.loads(zlib.decompress(icon_data)))
     66          #-----------------------------------------------------
     67 -        def GetIconData(self, anIconID = None):
     68                  # FIXME: in overriding methods need to be very careful about the
     69                  # type of the icon ID since if we read it back from the database we
     70                  # may not know what type it was
     71                  return None
     72          #-----------------------------------------------------
     73 -        def GetWidget (self, parent):
     74                  """
     75                  Return the widget to display. Usually called from
     76                  register(). The instance returned is the
     77                  active object for event handling purposes.
     78                  """
     79                  raise AttributeError('no such patient plugin - GetWidget')
     80          #-----------------------------------------------------
     81 -        def MenuInfo (self):
     82                  """Return tuple of (menuname, menuitem).
     83
     84                  menuname can be
     85                          "tools",
     86                          "view",
     87                          "help",
     88                          "file"
     89
     90                  If you return "None" no entry will be placed
     91                  in any menu.
     92                  """
     93                  raise AttributeError('no such patient plugin - MenuInfo')
     94          #-----------------------------------------------------
     95 -        def Raise (self):
     96                  """Raises this plugin to the top level if not visible.
     97                  """
     98                  raise AttributeError('no such patient plugin - Raise')
     99          #-----------------------------------------------------
    100 -        def ReceiveFocus(self):
    101                  """Called whenever this module receives focus and is thus shown onscreen.
    102                  """
    103                  pass
    104          #-----------------------------------------------------
    105 -        def register(self):
    106                  # register ANY type of plugin, regardless of where plugged in
    107                  # we may be able to do away with this once we don't do
    108                  # several types of plugins anymore, as we should
    109                  self.gb['modules.%s' % self.set][self.__class__.__name__] = self                # split/renamed 'horstspace.notebook.%s'
    110                  _log.Log(gmLog.lInfo, "plugin: [%s] (class: [%s]) set: [%s]" % (self.name(), self.__class__.__name__, self.set))
    111          #-----------------------------------------------------
    112 -        def unregister(self):
    113                  del self.gb['modules.%s' % self.set][self.__class__.__name__]                   # split/renamed 'horstspace.notebook.%s'
    114                  _log.Log(gmLog.lInfo, "plugin: [%s] (class: [%s]) set: [%s]" % (self.name(), self.__class__.__name__, self.set))
    115          #-----------------------------------------------------
    116 -        def name(self):
    117                  return 'plugin %s' % self.__class__.__name__
    118  #------------------------------------------------------------------
    119 -class wxPatientPlugin (BasePlugin):
    120          """
    121          A 'small page', sits inside the patient view, with the side visible
    122          """
    123 -        def register (self):
    124                  BasePlugin.register (self)
    125                  self.mwm = self.gb['clinical.manager']
    126
    127                  # FIXME: do proper config check for shadowing
    128                  # FIXME: do we always want shadows and set it to 0 width via themes ?
    129                  shadow = gmShadow.Shadow (self.mwm, -1)
    130                  widget = self.GetWidget (shadow)
    131                  shadow.SetContents (widget)
    132                  self.mwm.RegisterLeftSide (self.__class__.__name__, shadow)
    133
    134                  icon = self.GetIcon ()
    135                  if icon is not None:
    136                          tb2 = self.gb['toolbar.%s' % 'gmClinicalWindowManager']
    137                          #tb2.AddSeparator()
    138                          self.tool_id = wx.NewId ()
    139                          tool1 = tb2.AddTool(
    140                                  self.tool_id,
    141                                  icon,
    142                                  shortHelpString = self.name()
    143                          )
    144                          wx.EVT_TOOL (tb2, self.tool_id, self.OnTool)
    145                  menuname = self.name ()
    146                  menu = self.gb['clinical.submenu']
    147                  self.menu_id = wx.NewId ()
    148                  menu.Append (self.menu_id, menuname)
    149                  #wx.EVT_MENU (..., self.menu_id, self.OnTool)
    150          #-----------------------------------------------------
    151 -        def OnTool (self, event):
    152                  self.ReceiveFocus()
    153                  self.mwm.Display (self.__class__.__name__)
    154                  # redundant as cannot access toolbar unless mwm raised
    155                  #self.gb['modules.gui']['Patient'].Raise ()             # split/renamed 'horstspace.notebook.%s'
    156          #-----------------------------------------------------
    157 -        def Raise (self):
    158                  self.gb['modules.gui']['Patient'].Raise()               # split/renamed 'horstspace.notebook.%s'
    159                  self.mwm.Display (self.__class__.__name__)
    160          #-----------------------------------------------------
    161 -        def unregister (self):
    162                  BasePlugin.unregister (self)
    163                  self.mwm.Unregister (self.__class__.__name__)
    164                  menu = self.gb['main.submenu']
    165                  menu.Delete (menu_id)
    166                  if self.GetIcon () is not None:
    167                          tb2 = self.gb['toolbar.%s' % 'gmClinicalWindowManager']
    168                          tb2.DeleteTool (self.tool_id)
    169                  del self.gb['modules.patient'][self.__class__.__name__]
    170
    171  #==================================================================
    172  # Main
    173  #------------------------------------------------------------------
    174  if __name__ == '__main__':
    175          print "please write a unit test"
    176
    177  #==================================================================
    178