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
8
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
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
35
36 - def __init__(self, set='', guibroker=None, callbackbroker=None, params=None):
42
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
58
59
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
72
80
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 gmExceptions.PureVirtualFunction()
94
99
101 """Called whenever this module receives focus and is thus shown onscreen.
102 """
103 pass
104
106
107
108
109 self.gb['modules.%s' % self.set][self.__class__.__name__] = self
110 _log.Log(gmLog.lInfo, "plugin: [%s] (class: [%s]) set: [%s]" % (self.name(), self.__class__.__name__, self.set))
111
113 del self.gb['modules.%s' % self.set][self.__class__.__name__]
114 _log.Log(gmLog.lInfo, "plugin: [%s] (class: [%s]) set: [%s]" % (self.name(), self.__class__.__name__, self.set))
115
117 return 'plugin %s' % self.__class__.__name__
118
120 """
121 A 'small page', sits inside the patient view, with the side visible
122 """
124 BasePlugin.register (self)
125 self.mwm = self.gb['clinical.manager']
126
127
128
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
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
150
154
155
156
158 self.gb['modules.gui']['Patient'].Raise()
159 self.mwm.Display (self.__class__.__name__)
160
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
173
174 if __name__ == '__main__':
175 print "please write a unit test"
176
177
178