Gnumed.wxpython.gui.gmExamplePlugin

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

# Source Code for Module Gnumed.wxpython.gui.gmExamplePlugin

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