Home | Trees | Indices | Help |
|
---|
|
1 """GNUmed generic contact related widgets.""" 2 #================================================================ 3 __author__ = 'karsten.hilbert@gmx.net' 4 __license__ = 'GPL v2 or later (details at http://www.gnu.org)' 5 6 # stdlib 7 import logging, sys 8 9 10 # 3rd party 11 import wx 12 13 14 # GNUmed 15 if __name__ == '__main__': 16 sys.path.insert(0, '../../') 17 18 from Gnumed.pycommon import gmPG2 19 from Gnumed.pycommon import gmTools 20 from Gnumed.pycommon import gmMatchProvider 21 from Gnumed.pycommon import gmDispatcher 22 from Gnumed.business import gmDemographicRecord 23 from Gnumed.wxpython import gmListWidgets 24 from Gnumed.wxpython import gmPhraseWheel 25 from Gnumed.wxpython import gmEditArea 26 from Gnumed.wxpython import gmGuiHelpers 27 28 29 _log = logging.getLogger('gm.ui') 30 #============================================================ 31 # communication channels related widgets 32 #============================================================34 35 if parent is None: 36 parent = wx.GetApp().GetTopWindow() 37 38 #------------------------------------------------------------ 39 def delete(channel=None): 40 return gmDemographicRecord.delete_comm_channel_type(pk_channel_type = channel['pk'])41 #------------------------------------------------------------ 42 def refresh(lctrl): 43 wx.BeginBusyCursor() 44 channel_types = gmDemographicRecord.get_comm_channel_types() 45 lctrl.set_string_items([ (ct['l10n_description'], ct['description'], ct['pk']) for ct in channel_types ]) 46 lctrl.set_data(channel_types) 47 wx.EndBusyCursor() 48 #------------------------------------------------------------ 49 msg = _('\nThis lists the communication channel types known to GNUmed.\n') 50 51 gmListWidgets.get_choices_from_list ( 52 parent = parent, 53 msg = msg, 54 caption = _('Managing communication types ...'), 55 columns = [_('Channel'), _('System type'), '#'], 56 single_selection = True, 57 #new_callback = edit, 58 #edit_callback = edit, 59 delete_callback = delete, 60 refresh_callback = refresh 61 ) 62 63 #------------------------------------------------------------6597 98 #================================================================ 99 from Gnumed.wxGladeWidgets import wxgCommChannelEditAreaPnl 10067 68 query = u""" 69 SELECT 70 data, 71 field_label, 72 list_label 73 FROM ( 74 SELECT DISTINCT ON (field_label) 75 pk 76 AS data, 77 _(description) 78 AS field_label, 79 (_(description) || ' (' || description || ')') 80 AS list_label 81 FROM dem.enum_comm_types 82 WHERE 83 _(description) %(fragment_condition)s 84 OR 85 description %(fragment_condition)s 86 ) AS ur 87 ORDER BY 88 ur.list_label 89 """ 90 mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) 91 mp.setThresholds(1, 2, 4) 92 mp.word_separators = u'[ \t]+' 93 gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) 94 self.matcher = mp 95 self.SetToolTipString(_('Select the type of communications channel.')) 96 self.selection_only = True101 -class cCommChannelEditAreaPnl(wxgCommChannelEditAreaPnl.wxgCommChannelEditAreaPnl, gmEditArea.cGenericEditAreaMixin):102 """An edit area for editing/creating a comms channel. 103 104 Does NOT act on/listen to the current patient. 105 """198 #------------------------------------------------------------107 try: 108 data = kwargs['comm_channel'] 109 del kwargs['comm_channel'] 110 except KeyError: 111 data = None 112 113 self.channel_owner = None 114 115 wxgCommChannelEditAreaPnl.wxgCommChannelEditAreaPnl.__init__(self, *args, **kwargs) 116 gmEditArea.cGenericEditAreaMixin.__init__(self) 117 118 self.mode = 'new' 119 self.data = data 120 if data is not None: 121 self.mode = 'edit' 122 123 self.__init_ui()124 #---------------------------------------------------------------- 127 #---------------------------------------------------------------- 128 # generic Edit Area mixin API 129 #----------------------------------------------------------------131 validity = True 132 133 if self._TCTRL_url.GetValue().strip() == u'': 134 validity = False 135 self.display_tctrl_as_valid(tctrl = self._TCTRL_url, valid = False) 136 self._TCTRL_url.SetFocus() 137 else: 138 self.display_tctrl_as_valid(tctrl = self._TCTRL_url, valid = True) 139 140 # do not check GetData() because comm 141 # types are created as needed 142 #if self._PRW_type.GetData() is None: 143 if self._PRW_type.GetValue().strip() == u'': 144 validity = False 145 self._PRW_type.display_as_valid(False) 146 self._PRW_type.SetFocus() 147 else: 148 self._PRW_type.display_as_valid(True) 149 150 return validity151 #----------------------------------------------------------------153 try: 154 data = self.channel_owner.link_comm_channel ( 155 comm_medium = self._PRW_type.GetValue().strip(), 156 pk_channel_type = self._PRW_type.GetData(), 157 url = self._TCTRL_url.GetValue().strip(), 158 is_confidential = self._CHBOX_confidential.GetValue(), 159 ) 160 except gmPG2.dbapi.IntegrityError: 161 _log.exception('error saving comm channel') 162 gmDispatcher.send(signal = u'statustext', msg = _('Cannot save communications channel.'), beep = True) 163 return False 164 165 self.data = data 166 return True167 #----------------------------------------------------------------169 comm_type = self._PRW_type.GetValue().strip() 170 if comm_type != u'': 171 self.data['comm_type'] = comm_type 172 url = self._TCTRL_url.GetValue().strip() 173 if url != u'': 174 self.data['url'] = url 175 self.data['is_confidential'] = self._CHBOX_confidential.GetValue() 176 177 self.data.save() 178 return True179 #----------------------------------------------------------------181 self._PRW_type.SetText(u'') 182 self._TCTRL_url.SetValue(u'') 183 #self._PRW_address.SetText(value = u'', data = None) 184 self._CHBOX_confidential.SetValue(False) 185 186 self._PRW_type.SetFocus()187 #---------------------------------------------------------------- 190 #----------------------------------------------------------------200 """A list for managing a person's comm channels."""283 284 #================================================================ 285 # main 286 #---------------------------------------------------------------- 287 if __name__ == '__main__': 288 289 if len(sys.argv) < 2: 290 sys.exit() 291 292 if sys.argv[1] != 'test': 293 sys.exit() 294 295 from Gnumed.pycommon import gmI18N 296 gmI18N.activate_locale() 297 gmI18N.install_domain() 298 from Gnumed.business import gmPersonSearch 299 300 #--------------------------------------------------------202 203 try: 204 self.__channel_owner = kwargs['identity'] 205 del kwargs['identity'] 206 except KeyError: 207 self.__channel_owner = None 208 209 gmListWidgets.cGenericListManagerPnl.__init__(self, *args, **kwargs) 210 211 self.new_callback = self._add_comm 212 self.edit_callback = self._edit_comm 213 self.delete_callback = self._del_comm 214 self.refresh_callback = self.refresh 215 216 self.__init_ui() 217 self.refresh()218 #-------------------------------------------------------- 219 # external API 220 #--------------------------------------------------------222 if self.__channel_owner is None: 223 self._LCTRL_items.set_string_items() 224 return 225 226 comms = self.__channel_owner.get_comm_channels() 227 self._LCTRL_items.set_string_items ( 228 items = [ [ gmTools.bool2str(c['is_confidential'], u'X', u''), c['l10n_comm_type'], c['url'] ] for c in comms ] 229 ) 230 self._LCTRL_items.set_column_widths() 231 self._LCTRL_items.set_data(data = comms)232 #-------------------------------------------------------- 233 # internal helpers 234 #--------------------------------------------------------236 self._LCTRL_items.SetToolTipString(_('List of known communication channels.')) 237 self._LCTRL_items.set_columns(columns = [ 238 _('confidential'), 239 _('Type'), 240 _('Value') 241 ])242 #--------------------------------------------------------244 ea = cCommChannelEditAreaPnl(self, -1) 245 ea.channel_owner = self.__channel_owner 246 dlg = gmEditArea.cGenericEditAreaDlg2(self, -1, edit_area = ea) 247 dlg.SetTitle(_('Adding new communications channel')) 248 if dlg.ShowModal() == wx.ID_OK: 249 return True 250 return False251 #--------------------------------------------------------253 ea = cCommChannelEditAreaPnl(self, -1, comm_channel = comm_channel) 254 ea.channel_owner = self.__channel_owner 255 dlg = gmEditArea.cGenericEditAreaDlg2(self, -1, edit_area = ea, single_entry = True) 256 dlg.SetTitle(_('Editing communications channel')) 257 if dlg.ShowModal() == wx.ID_OK: 258 return True 259 return False260 #--------------------------------------------------------262 go_ahead = gmGuiHelpers.gm_show_question ( 263 _( 'Are you sure this communication channel\n' 264 'can no longer be used ?' 265 ), 266 _('Removing communication channel') 267 ) 268 if not go_ahead: 269 return False 270 self.__channel_owner.unlink_comm_channel(comm_channel = comm) 271 return True272 #-------------------------------------------------------- 273 # properties 274 #-------------------------------------------------------- 277 281 282 channel_owner = property(__get_channel_owner, __set_channel_owner)302 pat = gmPersonSearch.ask_for_patient() 303 app = wx.PyWidgetTester(size = (600, 400)) 304 widget = cCommChannelsManagerPnl(app.frame, -1) 305 widget.identity = pat 306 app.frame.Show(True) 307 app.MainLoop()308 #-------------------------------------------------------- 309 test_person_comms_pnl() 310 311 #================================================================ 312
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Dec 5 04:00:07 2011 | http://epydoc.sourceforge.net |