Package Gnumed :: Package wxpython :: Package gui :: Module gmExamplePlugin
[frames] | no frames]

Source Code for Module Gnumed.wxpython.gui.gmExamplePlugin

  1  """ 
  2  This is a template plugin  
  3  This is in line with the blog series on developing a plugin for GNUmed 
  4  Read all posts to follow along a step by step guide 
  5  The first thirteen parts are a chronical on a plugin I developed 
  6   
  7  Part 1:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-1.html 
  8  Part 2:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-2.html 
  9  Part 3:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-3.html 
 10  Part 4:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-4.html 
 11  Part 5:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-5.html 
 12  Part 6:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-6.html 
 13  Part 7:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-7.html 
 14  Part 8:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-8.html 
 15  Part 9:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-9.html 
 16  Part 10: http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-10.html 
 17  Part 11: http://gnumed.blogspot.com/2009/05/gnumed-plugin-development-part-11.html 
 18  Part 12: http://gnumed.blogspot.com/2009/07/gnumed-plugin-development-part-12.html 
 19  Part 13: http://gnumed.blogspot.com/2009/07/gnumed-plugin-development-part-13.html 
 20   
 21  The second series is  more general and coves second plugin as a starting point 
 22  Part 1:  http://gnumed.blogspot.com/2010/04/gnumed-plugin-developement-part-1.html 
 23   
 24  The third series covers an hands on introduction on how to share your code 
 25  Part 1:  http://gnumed.blogspot.com/2010/04/gnumed-plugin-development-how-to-share.html 
 26   
 27  For development information such as database schema, function and classes documentation 
 28  and more see http://wiki.gnumed.de 
 29  """ 
 30   
 31  """ 
 32  This file is used together with  
 33  ../../wxg/wxgExamplePluginPnl.wxg            - this is the UI layout as done with wxglade 
 34  ../../wxGladeWidgets/wxgExamplePluginPnl.py  - this is the generated python code of the above 
 35  ../gmExamplePluginWidgets.py                 - holds the widgets of the user interface, it  
 36                                                 imports and manipulates the above generated code  
 37  """ 
 38   
 39  __version__ = "$Revision: 0.2 $" 
 40  __author__ = "Sebastian Hilbert <Sebastian.Hilbert@gmx.net>" 
 41  __license__ = "GPL" 
 42   
 43  #================================================================ 
 44  import os.path, sys, logging 
 45  import wx 
 46   
 47  if __name__ == '__main__': 
 48          # stdlib 
 49          import sys 
 50          sys.path.insert(0, '../../../') 
 51   
 52          from Gnumed.pycommon import gmI18N 
 53          gmI18N.activate_locale() 
 54          gmI18N.install_domain() 
 55   
 56  """ import the widgets from the file referencing the widgets  
 57  for that particualr plugin (e.g. ExamplePlugin. 
 58  If you code your own plugin replace Example by something reflecting 
 59  what your plugin does.  
 60  """ 
 61   
 62  from Gnumed.wxpython import gmPlugin, gmExamplePluginWidgets 
 63   
 64  _log = logging.getLogger('gm.ui') 
 65  _log.info(__version__) 
 66  #================================================================ 
 67  #The name of the class must match the filename of the plugin 
68 -class gmExamplePlugin(gmPlugin.cNotebookPlugin):
69 #name of the plugin as it will appear as tab in GNUmed 70 tab_name = _("Template Plugin") 71
72 - def name (self):
74 #--------------------------------------------------------
75 - def GetWidget (self, parent):
76 #Sets up the GUI by instanciating the file containing the widget that make up the layout in the plugin 77 self._widget = gmExamplePluginWidgets.cExamplePluginPnl(parent, -1) 78 return self._widget
79 #--------------------------------------------------------
80 - def MenuInfo (self):
81 #This will set the name of the Plugin in the GNUmed menu 82 return ('emr', _('Show &ExamplePlugin'))
83 #--------------------------------------------------------
84 - def can_receive_focus(self):
85 # need patient 86 """ uncomment the next two lines if a patient 87 needs to be active before the plugin """ 88 #if not self._verify_patient_avail(): 89 # return None 90 return 1
91 #--------------------------------------------------------
92 - def _on_raise_by_signal(self, **kwds):
93 if not gmPlugin.cNotebookPlugin._on_raise_by_signal(self, **kwds): 94 return False 95 try: 96 # add here any code you for the plugin executed after 97 # raising the pugin 98 pass 99 except KeyError: 100 pass 101 return True
102 #================================================================ 103 # MAIN 104 #---------------------------------------------------------------- 105 if __name__ == '__main__': 106 107 # GNUmed 108 from Gnumed.business import gmPerson 109 from Gnumed.wxpython import gmPatSearchWidgets 110 111 _log.info("starting template plugin...") 112 113 try: 114 # obtain patient 115 patient = gmPerson.ask_for_patient() 116 if patient is None: 117 print "None patient. Exiting gracefully..." 118 sys.exit(0) 119 gmPatSearchWidgets.set_active_patient(patient=patient) 120 121 # display the plugin standalone 122 application = wx.wx.PyWidgetTester(size = (800,600)) 123 widgets = gmExamplePluginWidgets.cExamplePluginPnl(application.frame, -1) 124 125 application.frame.Show(True) 126 application.MainLoop() 127 128 # clean up 129 if patient is not None: 130 try: 131 patient.cleanup() 132 except: 133 print "error cleaning up patient" 134 except StandardError: 135 _log.exception("unhandled exception caught !") 136 # but re-raise them 137 raise 138 139 _log.info("closing example plugin...") 140