Gnumed.wxpython.gui.gmExamplePlugin

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

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

      1  # -*- coding: utf-8 -*-
      2  """ This is a template plugin.
      3
      4  This is in line with the blog series on developing a plugin
      5  for GNUmed Read all posts to follow along a step by step
      6  guide The first thirteen parts are a chronical on a plugin I
      7  developed:
      8
      9  Part 1:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-1.html
     10  Part 2:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-2.html
     11  Part 3:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-3.html
     12  Part 4:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-4.html
     13  Part 5:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-5.html
     14  Part 6:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-6.html
     15  Part 7:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-7.html
     16  Part 8:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-8.html
     17  Part 9:  http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-9.html
     18  Part 10: http://gnumed.blogspot.com/2009/04/gnumed-plugin-development-part-10.html
     19  Part 11: http://gnumed.blogspot.com/2009/05/gnumed-plugin-development-part-11.html
     20  Part 12: http://gnumed.blogspot.com/2009/07/gnumed-plugin-development-part-12.html
     21  Part 13: http://gnumed.blogspot.com/2009/07/gnumed-plugin-development-part-13.html
     22
     23  The second series is  more general and coves second plugin as a starting point
     24  Part 1:  http://gnumed.blogspot.com/2010/04/gnumed-plugin-developement-part-1.html
     25
     26  The third series covers an hands on introduction on how to share your code
     27  and how to test your plugin
     28  Part 1:  http://gnumed.blogspot.com/2010/04/gnumed-plugin-development-how-to-share.html
     29  Part 2:  http://gnumed.blogspot.com/2010/07/gnumed-plugin-development-easy-testing.html
     30
     31  For development information such as database schema, function and classes documentation
     32  and more see http://wiki.gnumed.de
     33  """
     34
     35  """
     36  This file is used together with
     37  ../../wxg/wxgExamplePluginPnl.wxg            - this is the UI layout as done with wxglade
     38  ../../wxGladeWidgets/wxgExamplePluginPnl.py  - this is the generated python code of the above
     39  ../gmExamplePluginWidgets.py                 - holds the widgets of the user interface, it
     40                                                 imports and manipulates the above generated code
     41  """
     42
     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  #================================================================
     69  #The name of the class must match the filename of the plugin
     70 -class gmExamplePlugin(gmPlugin.cNotebookPlugin):
     71          #name of the plugin as it will appear as tab in GNUmed
     72          tab_name = _("Template Plugin")
     73
     74 -        def name (self):
     75                  return gmExamplePlugin.tab_name
     76          #--------------------------------------------------------
     77 -        def GetWidget (self, parent):
     78                  #Sets up the GUI by instanciating the file containing the widget that make up the layout in the plugin
     79                  self._widget = gmExamplePluginWidgets.cExamplePluginPnl(parent, -1)
     80                  return self._widget
     81          #--------------------------------------------------------
     82 -        def MenuInfo (self):
     83                  #This will set the name of the Plugin in the GNUmed menu
     84                  return ('emr', _('Show &ExamplePlugin'))
     85          #--------------------------------------------------------
     86 -        def can_receive_focus(self):
     87                  # need patient
     88                  """ uncomment the next two lines if a patient
     89                  needs to be active before the plugin """
     90                  #if not self._verify_patient_avail():
     91                  #       return None
     92                  return 1
     93          #--------------------------------------------------------
     94 -        def _on_raise_by_signal(self, **kwds):
     95                  if not gmPlugin.cNotebookPlugin._on_raise_by_signal(self, **kwds):
     96                          return False
     97                  try:
     98                          # add here any code you for the plugin executed after
     99                          # raising the pugin
    100                          pass
    101                  except KeyError:
    102                          pass
    103                  return True
    104  #================================================================
    105  # MAIN
    106  #----------------------------------------------------------------
    107  if __name__ == '__main__':
    108
    109          # GNUmed
    110          from Gnumed.business import gmPersonSearch
    111          from Gnumed.wxpython import gmPatSearchWidgets
    112
    113          _log.info("starting template plugin...")
    114
    115          # obtain patient
    116          patient = gmPersonSearch.ask_for_patient()
    117          if patient is None:
    118                  print "None patient. Exiting gracefully..."
    119                  sys.exit(0)
    120          gmPatSearchWidgets.set_active_patient(patient=patient)
    121
    122          # display the plugin standalone
    123          application = wx.wx.PyWidgetTester(size = (800,600))
    124          widgets = gmExamplePluginWidgets.cExamplePluginPnl(application.frame, -1)
    125
    126          application.frame.Show(True)
    127          application.MainLoop()
    128
    129          # clean up
    130          if patient is not None:
    131                  try:
    132                          patient.cleanup()
    133                  except Exception:
    134                          print "error cleaning up patient"
    135
    136          _log.info("closing example plugin...")
    137