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

Source Code for Module Gnumed.wxpython.gmDeviceWidgets

  1  """GNUmed measurement widgets. 
  2  """ 
  3  #================================================================ 
  4  __version__ = "$Revision: 1.17 $" 
  5  __author__ = "Sebastian Hilbert <Sebastian.Hilbert@gmx.net>" 
  6  __license__ = "GPL" 
  7   
  8   
  9  import sys, logging, datetime as pyDT, decimal, StringIO 
 10  from lxml import etree 
 11   
 12  import wx       #, wx.grid 
 13   
 14   
 15  if __name__ == '__main__': 
 16          sys.path.insert(0, '../../') 
 17   
 18  from Gnumed.business import gmPerson, gmDevices, gmDocuments, gmPersonSearch 
 19  from Gnumed.pycommon import gmDispatcher, gmMatchProvider 
 20  from Gnumed.wxpython import gmRegetMixin, gmGuiHelpers, gmPatSearchWidgets 
 21  from Gnumed.wxGladeWidgets import wxgCardiacDevicePluginPnl 
 22   
 23  _log = logging.getLogger('gm.ui') 
 24  _log.info(__version__) 
 25  #================================================================ 
26 -class cCardiacDevicePluginPnl(wxgCardiacDevicePluginPnl.wxgCardiacDevicePluginPnl, gmRegetMixin.cRegetOnPaintMixin):
27 """Panel holding a number of widgets to manage implanted cardiac devices. Used as notebook page."""
28 - def __init__(self, *args, **kwargs):
29 wxgCardiacDevicePluginPnl.wxgCardiacDevicePluginPnl.__init__(self, *args, **kwargs) 30 gmRegetMixin.cRegetOnPaintMixin.__init__(self) 31 32 # check if report types exist in db, if not create them 33 self.__checkup_doc_type = u'cardiac device checkup report' 34 dtype = gmDocuments.create_document_type(self.__checkup_doc_type) 35 # cannot reuse self.__checkup_doc_type here or else it wouldn't get translated 36 dtype.set_translation(_('cardiac device checkup report')) 37 38 self.__init_ui() 39 self.__register_interests()
40 #-------------------------------------------------------- 41 # event handling 42 #--------------------------------------------------------
43 - def __register_interests(self):
44 gmDispatcher.connect(signal = u'pre_patient_selection', receiver = self._on_pre_patient_selection) 45 gmDispatcher.connect(signal = u'post_patient_selection', receiver = self._schedule_data_reget)
46 #--------------------------------------------------------
48 wx.CallAfter(self.__on_pre_patient_selection)
49 #--------------------------------------------------------
51 #self.data_grid.patient = None 52 pass
53 #--------------------------------------------------------
54 - def repopulate_ui(self):
55 _log.info('repopulate ui') 56 self._populate_with_data()
57 #-------------------------------------------------------- 58 #def _on_select_button_pressed(self, evt): 59 # if self._RBTN_my_unsigned.GetValue() is True: 60 # self.data_grid.select_cells(unsigned_only = True, accountables_only = True, keep_preselections = False) 61 # elif self._RBTN_all_unsigned.GetValue() is True: 62 # self.data_grid.select_cells(unsigned_only = True, accountables_only = False, keep_preselections = False) 63 #-------------------------------------------------------- 64 #def __on_sign_current_selection(self, evt): 65 # self.data_grid.sign_current_selection() 66 #-------------------------------------------------------- 67 #def __on_delete_current_selection(self, evt): 68 # self.data_grid.delete_current_selection() 69 #-------------------------------------------------------- 70 # internal API 71 #--------------------------------------------------------
72 - def __init_ui(self):
73 pass
74 #self.__action_button_popup = wx.Menu(title = _('Act on selected results')) 75 76 #menu_id = wx.NewId() 77 #self.__action_button_popup.AppendItem(wx.MenuItem(self.__action_button_popup, menu_id, _('Review and &sign'))) 78 #wx.EVT_MENU(self.__action_button_popup, menu_id, self.__on_sign_current_selection) 79 80 #menu_id = wx.NewId() 81 #self.__action_button_popup.AppendItem(wx.MenuItem(self.__action_button_popup, menu_id, _('Export to &file'))) 82 ##wx.EVT_MENU(self.__action_button_popup, menu_id, self.data_grid.current_selection_to_file) 83 #self.__action_button_popup.Enable(id = menu_id, enable = False) 84 85 #menu_id = wx.NewId() 86 #self.__action_button_popup.AppendItem(wx.MenuItem(self.__action_button_popup, menu_id, _('Export to &clipboard'))) 87 ##wx.EVT_MENU(self.__action_button_popup, menu_id, self.data_grid.current_selection_to_clipboard) 88 #self.__action_button_popup.Enable(id = menu_id, enable = False) 89 90 #menu_id = wx.NewId() 91 #self.__action_button_popup.AppendItem(wx.MenuItem(self.__action_button_popup, menu_id, _('&Delete'))) 92 #wx.EVT_MENU(self.__action_button_popup, menu_id, self.__on_delete_current_selection) 93 #-------------------------------------------------------- 94 # reget mixin API 95 #--------------------------------------------------------
96 - def _populate_with_data(self):
97 98 pat = gmPerson.gmCurrentPatient() 99 if not pat.connected: 100 return True 101 102 # get documents of type self.__checkup_doc_type 103 pat = gmPerson.gmCurrentPatient() 104 doc_folder = pat.get_document_folder() 105 checkups = doc_folder.get_documents(doc_type = self.__checkup_doc_type) 106 _log.info(checkups) 107 108 text = _('There are no device checkup reports in the database.') 109 if len(checkups) != 0: 110 # since get_documents() is sorted I simply get the first one as the most recent one 111 # for now assume that the xml file provide the cardiac device context. 112 # that pretty much means logical connection of leads and generator is provided in the xml 113 xml_fname = checkups[-1].parts[0].export_to_file() 114 tree = etree.parse(xml_fname) 115 DevicesDisplayed = gmDevices.device_status_as_text(tree) 116 text = u''.join(DevicesDisplayed) 117 118 self._TCTRL_current_status.SetValue(text) 119 120 return True
121 #================================================================ 122 # main 123 #---------------------------------------------------------------- 124 if __name__ == '__main__': 125 126 from Gnumed.pycommon import gmLog2, gmDateTime, gmI18N 127 128 gmI18N.activate_locale() 129 gmI18N.install_domain() 130 gmDateTime.init() 131 132 #------------------------------------------------------------
133 - def test_grid():
134 pat = gmPersonSearch.ask_for_patient() 135 app = wx.PyWidgetTester(size = (500, 300)) 136 lab_grid = cMeasurementsGrid(parent = app.frame, id = -1) 137 lab_grid.patient = pat 138 app.frame.Show() 139 app.MainLoop()
140 #------------------------------------------------------------
141 - def test_test_ea_pnl():
142 pat = gmPersonSearch.ask_for_patient() 143 gmPatSearchWidgets.set_active_patient(patient=pat) 144 app = wx.PyWidgetTester(size = (500, 300)) 145 ea = cMeasurementEditAreaPnl(parent = app.frame, id = -1) 146 app.frame.Show() 147 app.MainLoop()
148 #------------------------------------------------------------ 149 if (len(sys.argv) > 1) and (sys.argv[1] == 'test'): 150 #test_grid() 151 test_test_ea_pnl() 152 153 #================================================================ 154 # 155