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

Source Code for Module Gnumed.wxpython.gmEditArea

   1  #==================================================================== 
   2  # GNUmed Richard style Edit Area 
   3  #==================================================================== 
   4  __license__ = 'GPL' 
   5  __version__ = "$Revision: 1.135 $" 
   6  __author__ = "R.Terry, K.Hilbert" 
   7   
   8  #====================================================================== 
   9  import logging, datetime as pydt 
  10   
  11   
  12  import wx 
  13   
  14   
  15  from Gnumed.pycommon import gmDispatcher, gmExceptions 
  16  from Gnumed.wxGladeWidgets import wxgGenericEditAreaDlg, wxgGenericEditAreaDlg2 
  17   
  18   
  19  _log = logging.getLogger('gm.ui') 
  20  _log.info(__version__) 
  21  #==================================================================== 
  22  edit_area_modes = ['new', 'edit', 'new_from_existing'] 
  23   
24 -class cGenericEditAreaMixin(object):
25 """Mixin for edit area panels providing generic functionality. 26 27 #==================================================================== 28 # Class definition: 29 30 from Gnumed.wxGladeWidgets import wxgXxxEAPnl 31 32 class cXxxEAPnl(wxgXxxEAPnl.wxgXxxEAPnl, gmEditArea.cGenericEditAreaMixin): 33 34 def __init__(self, *args, **kwargs): 35 36 try: 37 data = kwargs['xxx'] 38 del kwargs['xxx'] 39 except KeyError: 40 data = None 41 42 wxgXxxEAPnl.wxgXxxEAPnl.__init__(self, *args, **kwargs) 43 gmEditArea.cGenericEditAreaMixin.__init__(self) 44 45 # Code using this mixin should set mode and data 46 # after instantiating the class: 47 self.mode = 'new' 48 self.data = data 49 if data is not None: 50 self.mode = 'edit' 51 52 #self.__init_ui() 53 #---------------------------------------------------------------- 54 # def __init_ui(self): 55 # # adjust phrasewheels etc 56 #---------------------------------------------------------------- 57 # generic Edit Area mixin API 58 #---------------------------------------------------------------- 59 def _valid_for_save(self): 60 # remove when implemented: 61 return False 62 63 validity = True 64 65 if self._TCTRL_xxx.GetValue().strip() == u'': 66 validity = False 67 self.display_tctrl_as_valid(tctrl = self._TCTRL_xxx, valid = False) 68 else: 69 self.display_tctrl_as_valid(tctrl = self._TCTRL_xxx, valid = True) 70 71 if self._PRW_xxx.GetData() is None: 72 validity = False 73 self._PRW_xxx.display_as_valid(False) 74 else: 75 self._PRW_xxx.display_as_valid(True) 76 77 return validity 78 #---------------------------------------------------------------- 79 def _save_as_new(self): 80 # save the data as a new instance 81 data = gmXXXX.create_xxxx() 82 83 data[''] = self._ 84 data[''] = self._ 85 86 data.save() 87 88 # must be done very late or else the property access 89 # will refresh the display such that later field 90 # access will return empty values 91 self.data = data 92 return False 93 return True 94 #---------------------------------------------------------------- 95 def _save_as_update(self): 96 # update self.data and save the changes 97 self.data[''] = self._TCTRL_xxx.GetValue().strip() 98 self.data[''] = self._PRW_xxx.GetData() 99 self.data[''] = self._CHBOX_xxx.GetValue() 100 self.data.save() 101 return True 102 #---------------------------------------------------------------- 103 def _refresh_as_new(self): 104 pass 105 #---------------------------------------------------------------- 106 def _refresh_as_new_from_existing(self): 107 self._refresh_as_new() 108 #---------------------------------------------------------------- 109 def _refresh_from_existing(self): 110 pass 111 #---------------------------------------------------------------- 112 """
113 - def __init__(self):
114 self.__mode = 'new' 115 self.__data = None 116 self.successful_save_msg = None 117 self._refresh_as_new() 118 self.__tctrl_validity_colors = { 119 True: wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW), 120 False: 'pink' 121 }
122 #----------------------------------------------------------------
123 - def _get_mode(self):
124 return self.__mode
125
126 - def _set_mode(self, mode=None):
127 if mode not in edit_area_modes: 128 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes)) 129 if mode == 'edit': 130 if self.__data is None: 131 raise ValueError('[%s] <mode> "edit" needs data value' % self.__class__.__name__) 132 133 prev_mode = self.__mode 134 self.__mode = mode 135 if mode != prev_mode: 136 self.refresh()
137 138 mode = property(_get_mode, _set_mode) 139 #----------------------------------------------------------------
140 - def _get_data(self):
141 return self.__data
142
143 - def _set_data(self, data=None):
144 if data is None: 145 if self.__mode == 'edit': 146 raise ValueError('[%s] <mode> "edit" needs data value' % self.__class__.__name__) 147 self.__data = data 148 self.refresh()
149 150 data = property(_get_data, _set_data) 151 #----------------------------------------------------------------
152 - def save(self):
153 """Invoked from the generic edit area dialog. 154 155 Invokes 156 _valid_for_save, 157 _save_as_new, 158 _save_as_update 159 on the implementing edit area as needed. 160 161 _save_as_* must set self.__data and return True/False 162 """ 163 if not self._valid_for_save(): 164 return False 165 166 if self.__mode in ['new', 'new_from_existing']: 167 if self._save_as_new(): 168 self.mode = 'edit' 169 return True 170 return False 171 172 elif self.__mode == 'edit': 173 return self._save_as_update() 174 175 else: 176 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
177 #----------------------------------------------------------------
178 - def refresh(self):
179 """Invoked from the generic edit area dialog. 180 181 Invokes 182 _refresh_as_new() 183 _refresh_from_existing() 184 _refresh_as_new_from_existing() 185 on the implementing edit area as needed. 186 187 Then calls _valid_for_save(). 188 """ 189 if self.__mode == 'new': 190 result = self._refresh_as_new() 191 self._valid_for_save() 192 return result 193 elif self.__mode == 'edit': 194 result = self._refresh_from_existing() 195 return result 196 elif self.__mode == 'new_from_existing': 197 result = self._refresh_as_new_from_existing() 198 self._valid_for_save() 199 return result 200 else: 201 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
202 #----------------------------------------------------------------
203 - def display_tctrl_as_valid(self, tctrl=None, valid=None):
204 tctrl.SetBackgroundColour(self.__tctrl_validity_colors[valid]) 205 tctrl.Refresh()
206 #----------------------------------------------------------------
207 - def display_ctrl_as_valid(self, ctrl=None, valid=None):
208 ctrl.SetBackgroundColour(self.__tctrl_validity_colors[valid]) 209 ctrl.Refresh()
210 #====================================================================
211 -class cGenericEditAreaDlg2(wxgGenericEditAreaDlg2.wxgGenericEditAreaDlg2):
212 """Dialog for parenting edit area panels with save/clear/next/cancel""" 213 214 _lucky_day = 1 215 _lucky_month = 4 216 _today = pydt.date.today() 217
218 - def __init__(self, *args, **kwargs):
219 220 new_ea = kwargs['edit_area'] 221 del kwargs['edit_area'] 222 223 if not isinstance(new_ea, cGenericEditAreaMixin): 224 raise TypeError('[%s]: edit area instance must be child of cGenericEditAreaMixin') 225 226 try: 227 single_entry = kwargs['single_entry'] 228 del kwargs['single_entry'] 229 except KeyError: 230 single_entry = False 231 232 wxgGenericEditAreaDlg2.wxgGenericEditAreaDlg2.__init__(self, *args, **kwargs) 233 234 self.left_extra_button = None 235 236 if cGenericEditAreaDlg2._today.day != cGenericEditAreaDlg2._lucky_day: 237 self._BTN_lucky.Enable(False) 238 self._BTN_lucky.Hide() 239 else: 240 if cGenericEditAreaDlg2._today.month != cGenericEditAreaDlg2._lucky_month: 241 self._BTN_lucky.Enable(False) 242 self._BTN_lucky.Hide() 243 244 # replace dummy panel 245 old_ea = self._PNL_ea 246 ea_pnl_szr = old_ea.GetContainingSizer() 247 ea_pnl_parent = old_ea.GetParent() 248 ea_pnl_szr.Remove(old_ea) 249 old_ea.Destroy() 250 del old_ea 251 new_ea.Reparent(ea_pnl_parent) 252 self._PNL_ea = new_ea 253 ea_pnl_szr.Add(self._PNL_ea, 1, wx.EXPAND, 0) 254 255 # adjust buttons 256 if single_entry: 257 self._BTN_forward.Enable(False) 258 self._BTN_forward.Hide() 259 260 self._adjust_clear_revert_buttons() 261 262 # redraw layout 263 self.Layout() 264 main_szr = self.GetSizer() 265 main_szr.Fit(self) 266 self.Refresh() 267 268 self._PNL_ea.refresh()
269 #--------------------------------------------------------
271 if self._PNL_ea.data is None: 272 self._BTN_clear.Enable(True) 273 self._BTN_clear.Show() 274 self._BTN_revert.Enable(False) 275 self._BTN_revert.Hide() 276 else: 277 self._BTN_clear.Enable(False) 278 self._BTN_clear.Hide() 279 self._BTN_revert.Enable(True) 280 self._BTN_revert.Show()
281 #--------------------------------------------------------
282 - def _on_save_button_pressed(self, evt):
283 if self._PNL_ea.save(): 284 if self.IsModal(): 285 self.EndModal(wx.ID_OK) 286 else: 287 self.Close()
288 #--------------------------------------------------------
289 - def _on_revert_button_pressed(self, evt):
290 self._PNL_ea.refresh()
291 #--------------------------------------------------------
292 - def _on_clear_button_pressed(self, evt):
293 self._PNL_ea.refresh()
294 #--------------------------------------------------------
295 - def _on_forward_button_pressed(self, evt):
296 if self._PNL_ea.save(): 297 if self._PNL_ea.successful_save_msg is not None: 298 gmDispatcher.send(signal = 'statustext', msg = self._PNL_ea.successful_save_msg) 299 self._PNL_ea.mode = 'new_from_existing' 300 301 self._adjust_clear_revert_buttons() 302 303 self.Layout() 304 main_szr = self.GetSizer() 305 main_szr.Fit(self) 306 self.Refresh() 307 308 self._PNL_ea.refresh()
309 #--------------------------------------------------------
310 - def _on_lucky_button_pressed(self, evt):
311 gmGuiHelpers.gm_show_info ( 312 _( 'Today is your lucky day !\n' 313 '\n' 314 'You have won one year of GNUmed\n' 315 'updates for free !\n' 316 ), 317 _('GNUmed Lottery') 318 )
319 #--------------------------------------------------------
320 - def _on_left_extra_button_pressed(self, event):
321 if not self.__left_extra_button_callback(self._PNL_ea.data): 322 return 323 324 if self.IsModal(): 325 self.EndModal(wx.ID_OK) 326 else: 327 self.Close()
328 #------------------------------------------------------------ 329 # properties 330 #------------------------------------------------------------
331 - def _set_left_extra_button(self, definition):
332 if definition is None: 333 self._BTN_extra_left.Enable(False) 334 self._BTN_extra_left.Hide() 335 self.__left_extra_button_callback = None 336 return 337 338 (label, tooltip, callback) = definition 339 if not callable(callback): 340 raise ValueError('<left extra button> callback is not a callable: %s' % callback) 341 self.__left_extra_button_callback = callback 342 self._BTN_extra_left.SetLabel(label) 343 self._BTN_extra_left.SetToolTipString(tooltip) 344 self._BTN_extra_left.Enable(True) 345 self._BTN_extra_left.Show()
346 347 left_extra_button = property(lambda x:x, _set_left_extra_button)
348 #==================================================================== 349 # DEPRECATED:
350 -class cGenericEditAreaDlg(wxgGenericEditAreaDlg.wxgGenericEditAreaDlg):
351 """Dialog for parenting edit area with save/clear/cancel""" 352
353 - def __init__(self, *args, **kwargs):
354 355 ea = kwargs['edit_area'] 356 del kwargs['edit_area'] 357 358 wxgGenericEditAreaDlg.wxgGenericEditAreaDlg.__init__(self, *args, **kwargs) 359 360 szr = self._PNL_ea.GetContainingSizer() 361 szr.Remove(self._PNL_ea) 362 ea.Reparent(self) 363 szr.Add(ea, 1, wx.ALL|wx.EXPAND, 4) 364 self._PNL_ea = ea 365 366 self.Layout() 367 szr = self.GetSizer() 368 szr.Fit(self) 369 self.Refresh() 370 371 self._PNL_ea.refresh()
372 #--------------------------------------------------------
373 - def _on_save_button_pressed(self, evt):
374 """The edit area save() method must return True/False.""" 375 if self._PNL_ea.save(): 376 if self.IsModal(): 377 self.EndModal(wx.ID_OK) 378 else: 379 self.Close()
380 #--------------------------------------------------------
381 - def _on_clear_button_pressed(self, evt):
382 self._PNL_ea.refresh()
383 #==================================================================== 384 #==================================================================== 385 #==================================================================== 386 #import time 387 388 #from Gnumed.business import gmPerson, gmDemographicRecord 389 from Gnumed.pycommon import gmGuiBroker 390 #from Gnumed.wxpython import gmDateTimeInput, gmPhraseWheel, gmGuiHelpers 391 392 _gb = gmGuiBroker.GuiBroker() 393 394 gmSECTION_SUMMARY = 1 395 gmSECTION_DEMOGRAPHICS = 2 396 gmSECTION_CLINICALNOTES = 3 397 gmSECTION_FAMILYHISTORY = 4 398 gmSECTION_PASTHISTORY = 5 399 gmSECTION_SCRIPT = 8 400 gmSECTION_REQUESTS = 9 401 gmSECTION_REFERRALS = 11 402 gmSECTION_RECALLS = 12 403 404 richards_blue = wx.Colour(0,0,131) 405 richards_aqua = wx.Colour(0,194,197) 406 richards_dark_gray = wx.Color(131,129,131) 407 richards_light_gray = wx.Color(255,255,255) 408 richards_coloured_gray = wx.Color(131,129,131) 409 410 411 CONTROLS_WITHOUT_LABELS =['wxTextCtrl', 'cEditAreaField', 'wx.SpinCtrl', 'gmPhraseWheel', 'wx.ComboBox'] 412
413 -def _decorate_editarea_field(widget):
414 widget.SetForegroundColour(wx.Color(255, 0, 0)) 415 widget.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
416 #====================================================================
417 -class cEditAreaPopup(wx.Dialog):
418 - def __init__ ( 419 self, 420 parent, 421 id, 422 title = 'edit area popup', 423 pos=wx.DefaultPosition, 424 size=wx.DefaultSize, 425 style=wx.SIMPLE_BORDER, 426 name='', 427 edit_area = None 428 ):
429 if not isinstance(edit_area, cEditArea2): 430 raise gmExceptions.ConstructorError, '<edit_area> must be of type cEditArea2 but is <%s>' % type(edit_area) 431 wx.Dialog.__init__(self, parent, id, title, pos, size, style, name) 432 self.__wxID_BTN_SAVE = wx.NewId() 433 self.__wxID_BTN_RESET = wx.NewId() 434 self.__editarea = edit_area 435 self.__do_layout() 436 self.__register_events()
437 #-------------------------------------------------------- 438 # public API 439 #--------------------------------------------------------
440 - def get_summary(self):
441 return self.__editarea.get_summary()
442 #--------------------------------------------------------
443 - def __do_layout(self):
444 self.__editarea.Reparent(self) 445 446 self.__btn_SAVE = wx.Button(self, self.__wxID_BTN_SAVE, _("Save")) 447 self.__btn_SAVE.SetToolTipString(_('save entry into medical record')) 448 self.__btn_RESET = wx.Button(self, self.__wxID_BTN_RESET, _("Reset")) 449 self.__btn_RESET.SetToolTipString(_('reset entry')) 450 self.__btn_CANCEL = wx.Button(self, wx.ID_CANCEL, _("Cancel")) 451 self.__btn_CANCEL.SetToolTipString(_('discard entry and cancel')) 452 453 szr_buttons = wx.BoxSizer(wx.HORIZONTAL) 454 szr_buttons.Add(self.__btn_SAVE, 1, wx.EXPAND | wx.ALL, 1) 455 szr_buttons.Add(self.__btn_RESET, 1, wx.EXPAND | wx.ALL, 1) 456 szr_buttons.Add(self.__btn_CANCEL, 1, wx.EXPAND | wx.ALL, 1) 457 458 szr_main = wx.BoxSizer(wx.VERTICAL) 459 szr_main.Add(self.__editarea, 1, wx.EXPAND) 460 szr_main.Add(szr_buttons, 0, wx.EXPAND) 461 462 self.SetSizerAndFit(szr_main)
463 #-------------------------------------------------------- 464 # event handling 465 #--------------------------------------------------------
466 - def __register_events(self):
467 # connect standard buttons 468 wx.EVT_BUTTON(self.__btn_SAVE, self.__wxID_BTN_SAVE, self._on_SAVE_btn_pressed) 469 wx.EVT_BUTTON(self.__btn_RESET, self.__wxID_BTN_RESET, self._on_RESET_btn_pressed) 470 wx.EVT_BUTTON(self.__btn_CANCEL, wx.ID_CANCEL, self._on_CANCEL_btn_pressed) 471 472 wx.EVT_CLOSE(self, self._on_CANCEL_btn_pressed) 473 474 # client internal signals 475 # gmDispatcher.connect(signal = gmSignals.pre_patient_selection(), receiver = self._on_pre_patient_selection) 476 # gmDispatcher.connect(signal = gmSignals.application_closing(), receiver = self._on_application_closing) 477 # gmDispatcher.connect(signal = gmSignals.post_patient_selection(), receiver = self.on_post_patient_selection) 478 479 return 1
480 #--------------------------------------------------------
481 - def _on_SAVE_btn_pressed(self, evt):
482 if self.__editarea.save_data(): 483 self.__editarea.Close() 484 self.EndModal(wx.ID_OK) 485 return 486 short_err = self.__editarea.get_short_error() 487 long_err = self.__editarea.get_long_error() 488 if (short_err is None) and (long_err is None): 489 long_err = _( 490 'Unspecified error saving data in edit area.\n\n' 491 'Programmer forgot to specify proper error\n' 492 'message in [%s].' 493 ) % self.__editarea.__class__.__name__ 494 if short_err is not None: 495 gmDispatcher.send(signal = 'statustext', msg = short_err) 496 if long_err is not None: 497 gmGuiHelpers.gm_show_error(long_err, _('saving clinical data'))
498 #--------------------------------------------------------
499 - def _on_CANCEL_btn_pressed(self, evt):
500 self.__editarea.Close() 501 self.EndModal(wx.ID_CANCEL)
502 #--------------------------------------------------------
503 - def _on_RESET_btn_pressed(self, evt):
504 self.__editarea.reset_ui()
505 #====================================================================
506 -class cEditArea2(wx.Panel):
507 - def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL):
508 # init main background panel 509 wx.Panel.__init__ ( 510 self, 511 parent, 512 id, 513 pos = pos, 514 size = size, 515 style = style | wx.TAB_TRAVERSAL 516 ) 517 self.SetBackgroundColour(wx.Color(222,222,222)) 518 519 self.data = None # a placeholder for opaque data 520 self.fields = {} 521 self.prompts = {} 522 self._short_error = None 523 self._long_error = None 524 self._summary = None 525 self._patient = gmPerson.gmCurrentPatient() 526 self.__wxID_BTN_OK = wx.NewId() 527 self.__wxID_BTN_CLEAR = wx.NewId() 528 self.__do_layout() 529 self.__register_events() 530 self.Show()
531 #-------------------------------------------------------- 532 # external API 533 #--------------------------------------------------------
534 - def save_data(self):
535 """This needs to be overridden by child classes.""" 536 self._long_error = _( 537 'Cannot save data from edit area.\n\n' 538 'Programmer forgot to override method:\n' 539 ' <%s.save_data>' 540 ) % self.__class__.__name__ 541 return False
542 #--------------------------------------------------------
543 - def reset_ui(self):
544 msg = _( 545 'Cannot reset fields in edit area.\n\n' 546 'Programmer forgot to override method:\n' 547 ' <%s.reset_ui>' 548 ) % self.__class__.__name__ 549 gmGuiHelpers.gm_show_error(msg)
550 #--------------------------------------------------------
551 - def get_short_error(self):
552 tmp = self._short_error 553 self._short_error = None 554 return tmp
555 #--------------------------------------------------------
556 - def get_long_error(self):
557 tmp = self._long_error 558 self._long_error = None 559 return tmp
560 #--------------------------------------------------------
561 - def get_summary(self):
562 return _('<No embed string for [%s]>') % self.__class__.__name__
563 #-------------------------------------------------------- 564 # event handling 565 #--------------------------------------------------------
566 - def __register_events(self):
567 # client internal signals 568 if self._patient.connected: 569 gmDispatcher.connect(signal = 'pre_patient_selection', receiver = self._on_pre_patient_selection) 570 gmDispatcher.connect(signal = 'post_patient_selection', receiver = self.on_post_patient_selection) 571 gmDispatcher.connect(signal = 'application_closing', receiver = self._on_application_closing) 572 573 # wxPython events 574 wx.EVT_CLOSE(self, self._on_close) 575 576 return 1
577 #--------------------------------------------------------
578 - def __deregister_events(self):
579 gmDispatcher.disconnect(signal = u'pre_patient_selection', receiver = self._on_pre_patient_selection) 580 gmDispatcher.disconnect(signal = u'post_patient_selection', receiver = self.on_post_patient_selection) 581 gmDispatcher.disconnect(signal = u'application_closing', receiver = self._on_application_closing)
582 #-------------------------------------------------------- 583 # handlers 584 #--------------------------------------------------------
585 - def _on_close(self, event):
586 self.__deregister_events() 587 event.Skip()
588 #--------------------------------------------------------
589 - def _on_OK_btn_pressed(self, event):
590 """Only active if _make_standard_buttons was called in child class.""" 591 # FIXME: this try: except: block seems to large 592 try: 593 event.Skip() 594 if self.data is None: 595 self._save_new_entry() 596 self.reset_ui() 597 else: 598 self._save_modified_entry() 599 self.reset_ui() 600 except gmExceptions.InvalidInputError, err: 601 # nasty evil popup dialogue box 602 # but for invalid input we want to interrupt user 603 gmGuiHelpers.gm_show_error (err, _("Invalid Input")) 604 except: 605 _log.exception( "save data problem in [%s]" % self.__class__.__name__)
606 #--------------------------------------------------------
607 - def _on_clear_btn_pressed(self, event):
608 """Only active if _make_standard_buttons was called in child class.""" 609 # FIXME: check for unsaved data 610 self.reset_ui() 611 event.Skip()
612 #--------------------------------------------------------
613 - def _on_application_closing(self, **kwds):
614 self.__deregister_events() 615 # remember wxCallAfter 616 if not self._patient.connected: 617 return True 618 # FIXME: should do this: 619 # if self.user_wants_save(): 620 # if self.save_data(): 621 # return True 622 return True 623 _log.error('[%s] lossage' % self.__class__.__name__) 624 return False
625 #--------------------------------------------------------
626 - def _on_pre_patient_selection(self, **kwds):
627 """Just before new patient becomes active.""" 628 # remember wxCallAfter 629 if not self._patient.connected: 630 return True 631 # FIXME: should do this: 632 # if self.user_wants_save(): 633 # if self.save_data(): 634 # return True 635 return True 636 _log.error('[%s] lossage' % self.__class__.__name__) 637 return False
638 #--------------------------------------------------------
639 - def on_post_patient_selection( self, **kwds):
640 """Just after new patient became active.""" 641 # remember to use wxCallAfter() 642 self.reset_ui()
643 #---------------------------------------------------------------- 644 # internal helpers 645 #----------------------------------------------------------------
646 - def __do_layout(self):
647 648 # define prompts and fields 649 self._define_prompts() 650 self._define_fields(parent = self) 651 if len(self.fields) != len(self.prompts): 652 _log.error('[%s]: #fields != #prompts' % self.__class__.__name__) 653 return None 654 655 # and generate edit area from it 656 szr_main_fgrid = wx.FlexGridSizer(rows = len(self.prompts), cols=2) 657 color = richards_aqua 658 lines = self.prompts.keys() 659 lines.sort() 660 for line in lines: 661 # 1) prompt 662 label, color, weight = self.prompts[line] 663 # FIXME: style for centering in vertical direction ? 664 prompt = wx.StaticText ( 665 parent = self, 666 id = -1, 667 label = label, 668 style = wx.ALIGN_CENTRE 669 ) 670 # FIXME: resolution dependant 671 prompt.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, '')) 672 prompt.SetForegroundColour(color) 673 prompt.SetBackgroundColour(richards_light_gray) 674 szr_main_fgrid.Add(prompt, flag=wx.EXPAND | wx.ALIGN_RIGHT) 675 676 # 2) widget(s) for line 677 szr_line = wx.BoxSizer(wx.HORIZONTAL) 678 positions = self.fields[line].keys() 679 positions.sort() 680 for pos in positions: 681 field, weight = self.fields[line][pos] 682 # field.SetBackgroundColour(wx.Color(222,222,222)) 683 szr_line.Add(field, weight, wx.EXPAND) 684 szr_main_fgrid.Add(szr_line, flag=wx.GROW | wx.ALIGN_LEFT) 685 686 # grid can grow column 1 only, not column 0 687 szr_main_fgrid.AddGrowableCol(1) 688 689 # # use sizer for border around everything plus a little gap 690 # # FIXME: fold into szr_main_panels ? 691 # self.szr_central_container = wx.BoxSizer(wxHORIZONTAL) 692 # self.szr_central_container.Add(self.szr_main_panels, 1, wx.EXPAND | wxALL, 5) 693 694 # and do the layouting 695 self.SetSizerAndFit(szr_main_fgrid)
696 # self.FitInside() 697 #---------------------------------------------------------------- 698 # intra-class API 699 #----------------------------------------------------------------
700 - def _define_prompts(self):
701 """Child classes override this to define their prompts using _add_prompt()""" 702 _log.error('missing override in [%s]' % self.__class__.__name__)
703 #----------------------------------------------------------------
704 - def _add_prompt(self, line, label='missing label', color=richards_blue, weight=0):
705 """Add a new prompt line. 706 707 To be used from _define_fields in child classes. 708 709 - label, the label text 710 - color 711 - weight, the weight given in sizing the various rows. 0 means the row 712 always has minimum size 713 """ 714 self.prompts[line] = (label, color, weight)
715 #----------------------------------------------------------------
716 - def _define_fields(self, parent):
717 """Defines the fields. 718 719 - override in child classes 720 - mostly uses _add_field() 721 """ 722 _log.error('missing override in [%s]' % self.__class__.__name__)
723 #----------------------------------------------------------------
724 - def _add_field(self, line=None, pos=None, widget=None, weight=0):
725 if None in (line, pos, widget): 726 _log.error('argument error in [%s]: line=%s, pos=%s, widget=%s' % (self.__class__.__name__, line, pos, widget)) 727 if not self.fields.has_key(line): 728 self.fields[line] = {} 729 self.fields[line][pos] = (widget, weight)
730 #----------------------------------------------------------------
731 - def _make_standard_buttons(self, parent):
732 """Generates OK/CLEAR buttons for edit area.""" 733 self.btn_OK = wx.Button(parent, self.__wxID_BTN_OK, _("OK")) 734 self.btn_OK.SetToolTipString(_('save entry into medical record')) 735 self.btn_Clear = wx.Button(parent, self.__wxID_BTN_CLEAR, _("Clear")) 736 self.btn_Clear.SetToolTipString(_('initialize input fields for new entry')) 737 738 szr_buttons = wx.BoxSizer(wx.HORIZONTAL) 739 szr_buttons.Add(self.btn_OK, 1, wx.EXPAND | wx.ALL, 1) 740 szr_buttons.Add((5, 0), 0) 741 szr_buttons.Add(self.btn_Clear, 1, wx.EXPAND | wx.ALL, 1) 742 743 # connect standard buttons 744 wx.EVT_BUTTON(self.btn_OK, self.__wxID_BTN_OK, self._on_OK_btn_pressed) 745 wx.EVT_BUTTON(self.btn_Clear, self.__wxID_BTN_CLEAR, self._on_clear_btn_pressed) 746 747 return szr_buttons
748 #==================================================================== 749 #==================================================================== 750 #text control class to be later replaced by the gmPhraseWheel 751 #--------------------------------------------------------------------
752 -class cEditAreaField(wx.TextCtrl):
753 - def __init__ (self, parent, id = -1, pos = wx.DefaultPosition, size=wx.DefaultSize):
754 wx.TextCtrl.__init__(self,parent,id,"",pos, size ,wx.SIMPLE_BORDER) 755 _decorate_editarea_field(self)
756 #====================================================================
757 -class cEditArea(wx.Panel):
758 - def __init__(self, parent, id, pos, size, style):
759 760 print "class [%s] is deprecated, use cEditArea2 instead" % self.__class__.__name__ 761 762 # init main background panel 763 wx.Panel.__init__(self, parent, id, pos=pos, size=size, style=wx.NO_BORDER | wx.TAB_TRAVERSAL) 764 self.SetBackgroundColour(wx.Color(222,222,222)) 765 766 self.data = None 767 self.fields = {} 768 self.prompts = {} 769 770 ID_BTN_OK = wx.NewId() 771 ID_BTN_CLEAR = wx.NewId() 772 773 self.__do_layout() 774 775 # self.input_fields = {} 776 777 # self._postInit() 778 # self.old_data = {} 779 780 self._patient = gmPerson.gmCurrentPatient() 781 self.__register_events() 782 self.Show(True)
783 #---------------------------------------------------------------- 784 # internal helpers 785 #----------------------------------------------------------------
786 - def __do_layout(self):
787 # define prompts and fields 788 self._define_prompts() 789 self.fields_pnl = wx.Panel(self, -1, style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL) 790 self._define_fields(parent = self.fields_pnl) 791 # and generate edit area from it 792 szr_prompts = self.__generate_prompts() 793 szr_fields = self.__generate_fields() 794 795 # stack prompts and fields horizontally 796 self.szr_main_panels = wx.BoxSizer(wx.HORIZONTAL) 797 self.szr_main_panels.Add(szr_prompts, 11, wx.EXPAND) 798 self.szr_main_panels.Add(5, 0, 0, wx.EXPAND) 799 self.szr_main_panels.Add(szr_fields, 90, wx.EXPAND) 800 801 # use sizer for border around everything plus a little gap 802 # FIXME: fold into szr_main_panels ? 803 self.szr_central_container = wx.BoxSizer(wx.HORIZONTAL) 804 self.szr_central_container.Add(self.szr_main_panels, 1, wx.EXPAND | wx.ALL, 5) 805 806 # and do the layouting 807 self.SetAutoLayout(True) 808 self.SetSizer(self.szr_central_container) 809 self.szr_central_container.Fit(self)
810 #----------------------------------------------------------------
811 - def __generate_prompts(self):
812 if len(self.fields) != len(self.prompts): 813 _log.error('[%s]: #fields != #prompts' % self.__class__.__name__) 814 return None 815 # prompts live on a panel 816 prompt_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER) 817 prompt_pnl.SetBackgroundColour(richards_light_gray) 818 # make them 819 color = richards_aqua 820 lines = self.prompts.keys() 821 lines.sort() 822 self.prompt_widget = {} 823 for line in lines: 824 label, color, weight = self.prompts[line] 825 self.prompt_widget[line] = self.__make_prompt(prompt_pnl, "%s " % label, color) 826 # make shadow below prompts in gray 827 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0) 828 shadow_below_prompts.SetBackgroundColour(richards_dark_gray) 829 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL) 830 szr_shadow_below_prompts.Add(5, 0, 0, wx.EXPAND) 831 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND) 832 833 # stack prompt panel and shadow vertically 834 vszr_prompts = wx.BoxSizer(wx.VERTICAL) 835 vszr_prompts.Add(prompt_pnl, 97, wx.EXPAND) 836 vszr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND) 837 838 # make shadow to the right of the prompts 839 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0) 840 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray) 841 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL) 842 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND) 843 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts, 1, wx.EXPAND) 844 845 # stack vertical prompt sizer and shadow horizontally 846 hszr_prompts = wx.BoxSizer(wx.HORIZONTAL) 847 hszr_prompts.Add(vszr_prompts, 10, wx.EXPAND) 848 hszr_prompts.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND) 849 850 return hszr_prompts
851 #----------------------------------------------------------------
852 - def __generate_fields(self):
853 self.fields_pnl.SetBackgroundColour(wx.Color(222,222,222)) 854 # rows, cols, hgap, vgap 855 vszr = wx.BoxSizer(wx.VERTICAL) 856 lines = self.fields.keys() 857 lines.sort() 858 self.field_line_szr = {} 859 for line in lines: 860 self.field_line_szr[line] = wx.BoxSizer(wx.HORIZONTAL) 861 positions = self.fields[line].keys() 862 positions.sort() 863 for pos in positions: 864 field, weight = self.fields[line][pos] 865 self.field_line_szr[line].Add(field, weight, wx.EXPAND) 866 try: 867 vszr.Add(self.field_line_szr[line], self.prompts[line][2], flag = wx.EXPAND) # use same lineweight as prompts 868 except KeyError: 869 _log.error("Error with line=%s, self.field_line_szr has key:%s; self.prompts has key: %s" % (line, self.field_line_szr.has_key(line), self.prompts.has_key(line) ) ) 870 # put them on the panel 871 self.fields_pnl.SetSizer(vszr) 872 vszr.Fit(self.fields_pnl) 873 874 # make shadow below edit fields in gray 875 shadow_below_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0) 876 shadow_below_edit_fields.SetBackgroundColour(richards_coloured_gray) 877 szr_shadow_below_edit_fields = wx.BoxSizer(wx.HORIZONTAL) 878 szr_shadow_below_edit_fields.Add(5, 0, 0, wx.EXPAND) 879 szr_shadow_below_edit_fields.Add(shadow_below_edit_fields, 12, wx.EXPAND) 880 881 # stack edit fields and shadow vertically 882 vszr_edit_fields = wx.BoxSizer(wx.VERTICAL) 883 vszr_edit_fields.Add(self.fields_pnl, 92, wx.EXPAND) 884 vszr_edit_fields.Add(szr_shadow_below_edit_fields, 5, wx.EXPAND) 885 886 # make shadow to the right of the edit area 887 shadow_rightof_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0) 888 shadow_rightof_edit_fields.SetBackgroundColour(richards_coloured_gray) 889 szr_shadow_rightof_edit_fields = wx.BoxSizer(wx.VERTICAL) 890 szr_shadow_rightof_edit_fields.Add(0, 5, 0, wx.EXPAND) 891 szr_shadow_rightof_edit_fields.Add(shadow_rightof_edit_fields, 1, wx.EXPAND) 892 893 # stack vertical edit fields sizer and shadow horizontally 894 hszr_edit_fields = wx.BoxSizer(wx.HORIZONTAL) 895 hszr_edit_fields.Add(vszr_edit_fields, 89, wx.EXPAND) 896 hszr_edit_fields.Add(szr_shadow_rightof_edit_fields, 1, wx.EXPAND) 897 898 return hszr_edit_fields
899 #---------------------------------------------------------------
900 - def __make_prompt(self, parent, aLabel, aColor):
901 # FIXME: style for centering in vertical direction ? 902 prompt = wx.StaticText( 903 parent, 904 -1, 905 aLabel, 906 style = wx.ALIGN_RIGHT 907 ) 908 prompt.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, '')) 909 prompt.SetForegroundColour(aColor) 910 return prompt
911 #---------------------------------------------------------------- 912 # intra-class API 913 #----------------------------------------------------------------
914 - def _add_prompt(self, line, label='missing label', color=richards_blue, weight=0):
915 """Add a new prompt line. 916 917 To be used from _define_fields in child classes. 918 919 - label, the label text 920 - color 921 - weight, the weight given in sizing the various rows. 0 means the rwo 922 always has minimum size 923 """ 924 self.prompts[line] = (label, color, weight)
925 #----------------------------------------------------------------
926 - def _add_field(self, line=None, pos=None, widget=None, weight=0):
927 if None in (line, pos, widget): 928 _log.error('argument error in [%s]: line=%s, pos=%s, widget=%s' % (self.__class__.__name__, line, pos, widget)) 929 if not self.fields.has_key(line): 930 self.fields[line] = {} 931 self.fields[line][pos] = (widget, weight)
932 #----------------------------------------------------------------
933 - def _define_fields(self, parent):
934 """Defines the fields. 935 936 - override in child classes 937 - mostly uses _add_field() 938 """ 939 _log.error('missing override in [%s]' % self.__class__.__name__)
940 #----------------------------------------------------------------
941 - def _define_prompts(self):
942 _log.error('missing override in [%s]' % self.__class__.__name__)
943 #----------------------------------------------------------------
944 - def _make_standard_buttons(self, parent):
945 """Generates OK/CLEAR buttons for edit area.""" 946 self.btn_OK = wx.Button(parent, ID_BTN_OK, _("OK")) 947 self.btn_OK.SetToolTipString(_('save entry into medical record')) 948 self.btn_Clear = wx.Button(parent, ID_BTN_CLEAR, _("Clear")) 949 self.btn_Clear.SetToolTipString(_('initialize input fields for new entry')) 950 951 szr_buttons = wx.BoxSizer(wx.HORIZONTAL) 952 szr_buttons.Add(self.btn_OK, 1, wx.EXPAND | wx.ALL, 1) 953 szr_buttons.Add(5, 0, 0) 954 szr_buttons.Add(self.btn_Clear, 1, wx.EXPAND | wx.ALL, 1) 955 956 return szr_buttons
957 #--------------------------------------------------------
958 - def _pre_save_data(self):
959 pass
960 #--------------------------------------------------------
961 - def _save_data(self):
962 _log.error('[%s] programmer forgot to define _save_data()' % self.__class__.__name__) 963 _log.info('child classes of cEditArea *must* override this function') 964 return False
965 #-------------------------------------------------------- 966 # event handling 967 #--------------------------------------------------------
968 - def __register_events(self):
969 # connect standard buttons 970 wx.EVT_BUTTON(self.btn_OK, ID_BTN_OK, self._on_OK_btn_pressed) 971 wx.EVT_BUTTON(self.btn_Clear, ID_BTN_CLEAR, self._on_clear_btn_pressed) 972 973 wx.EVT_SIZE (self.fields_pnl, self._on_resize_fields) 974 975 # client internal signals 976 gmDispatcher.connect(signal = u'pre_patient_selection', receiver = self._on_pre_patient_selection) 977 gmDispatcher.connect(signal = u'application_closing', receiver = self._on_application_closing) 978 gmDispatcher.connect(signal = u'post_patient_selection', receiver = self.on_post_patient_selection) 979 980 return 1
981 #-------------------------------------------------------- 982 # handlers 983 #--------------------------------------------------------
984 - def _on_OK_btn_pressed(self, event):
985 # FIXME: this try: except: block seems to large 986 try: 987 event.Skip() 988 if self.data is None: 989 self._save_new_entry() 990 self.set_data() 991 else: 992 self._save_modified_entry() 993 self.set_data() 994 except gmExceptions.InvalidInputError, err: 995 # nasty evil popup dialogue box 996 # but for invalid input we want to interrupt user 997 gmGuiHelpers.gm_show_error (err, _("Invalid Input")) 998 except: 999 _log.exception( "save data problem in [%s]" % self.__class__.__name__)
1000 #--------------------------------------------------------
1001 - def _on_clear_btn_pressed(self, event):
1002 # FIXME: check for unsaved data 1003 self.set_data() 1004 event.Skip()
1005 #--------------------------------------------------------
1006 - def on_post_patient_selection( self, **kwds):
1007 # remember to use wxCallAfter() 1008 self.set_data()
1009 #--------------------------------------------------------
1010 - def _on_application_closing(self, **kwds):
1011 # remember wxCallAfter 1012 if not self._patient.connected: 1013 return True 1014 if self._save_data(): 1015 return True 1016 _log.error('[%s] lossage' % self.__class__.__name__) 1017 return False
1018 #--------------------------------------------------------
1019 - def _on_pre_patient_selection(self, **kwds):
1020 # remember wxCallAfter 1021 if not self._patient.connected: 1022 return True 1023 if self._save_data(): 1024 return True 1025 _log.error('[%s] lossage' % self.__class__.__name__) 1026 return False
1027 #--------------------------------------------------------
1028 - def _on_resize_fields (self, event):
1029 self.fields_pnl.Layout() 1030 # resize the prompts accordingly 1031 for i in self.field_line_szr.keys(): 1032 # query the BoxSizer to find where the field line is 1033 pos = self.field_line_szr[i].GetPosition() 1034 # and set the prompt lable to the same Y position 1035 self.prompt_widget[i].SetPosition((0, pos.y))
1036 #====================================================================
1037 -class gmEditArea(cEditArea):
1038 - def __init__(self, parent, id, aType = None):
1039 1040 print "class [%s] is deprecated, use cEditArea2 instead" % self.__class__.__name__ 1041 1042 # sanity checks 1043 if aType not in _known_edit_area_types: 1044 _log.error('unknown edit area type: [%s]' % aType) 1045 raise gmExceptions.ConstructorError, 'unknown edit area type: [%s]' % aType 1046 self._type = aType 1047 1048 # init main background panel 1049 cEditArea.__init__(self, parent, id) 1050 1051 self.input_fields = {} 1052 1053 self._postInit() 1054 self.old_data = {} 1055 1056 self._patient = gmPerson.gmCurrentPatient() 1057 self.Show(True)
1058 #---------------------------------------------------------------- 1059 # internal helpers 1060 #---------------------------------------------------------------- 1061 #---------------------------------------------------------------- 1062 # to be obsoleted 1063 #----------------------------------------------------------------
1064 - def __make_prompts(self, prompt_labels):
1065 # prompts live on a panel 1066 prompt_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER) 1067 prompt_pnl.SetBackgroundColour(richards_light_gray) 1068 # make them 1069 gszr = wx.FlexGridSizer (len(prompt_labels)+1, 1, 2, 2) 1070 color = richards_aqua 1071 for prompt in prompt_labels: 1072 label = self.__make_prompt(prompt_pnl, "%s " % prompt, color) 1073 gszr.Add(label, 0, wx.EXPAND | wx.ALIGN_RIGHT) 1074 color = richards_blue 1075 gszr.RemoveGrowableRow (line-1) 1076 # put sizer on panel 1077 prompt_pnl.SetSizer(gszr) 1078 gszr.Fit(prompt_pnl) 1079 prompt_pnl.SetAutoLayout(True) 1080 1081 # make shadow below prompts in gray 1082 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0) 1083 shadow_below_prompts.SetBackgroundColour(richards_dark_gray) 1084 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL) 1085 szr_shadow_below_prompts.Add(5, 0, 0, wx.EXPAND) 1086 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND) 1087 1088 # stack prompt panel and shadow vertically 1089 vszr_prompts = wx.BoxSizer(wx.VERTICAL) 1090 vszr_prompts.Add(prompt_pnl, 97, wx.EXPAND) 1091 vszr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND) 1092 1093 # make shadow to the right of the prompts 1094 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0) 1095 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray) 1096 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL) 1097 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND) 1098 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts,1,wx.EXPAND) 1099 1100 # stack vertical prompt sizer and shadow horizontally 1101 hszr_prompts = wx.BoxSizer(wx.HORIZONTAL) 1102 hszr_prompts.Add(vszr_prompts, 10, wx.EXPAND) 1103 hszr_prompts.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND) 1104 1105 return hszr_prompts
1106 #----------------------------------------------------------------
1107 - def _make_edit_lines(self, parent):
1108 _log.error('programmer forgot to define edit area lines for [%s]' % self._type) 1109 _log.info('child classes of gmEditArea *must* override this function') 1110 return []
1111 #----------------------------------------------------------------
1112 - def __make_editing_area(self):
1113 # make edit fields 1114 fields_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL) 1115 fields_pnl.SetBackgroundColour(wx.Color(222,222,222)) 1116 # rows, cols, hgap, vgap 1117 gszr = wx.GridSizer(len(_prompt_defs[self._type]), 1, 2, 2) 1118 1119 # get lines 1120 lines = self._make_edit_lines(parent = fields_pnl) 1121 1122 self.lines = lines 1123 if len(lines) != len(_prompt_defs[self._type]): 1124 _log.error('#(edit lines) not equal #(prompts) for [%s], something is fishy' % self._type) 1125 for line in lines: 1126 gszr.Add(line, 0, wx.EXPAND | wx.ALIGN_LEFT) 1127 # put them on the panel 1128 fields_pnl.SetSizer(gszr) 1129 gszr.Fit(fields_pnl) 1130 fields_pnl.SetAutoLayout(True) 1131 1132 # make shadow below edit fields in gray 1133 shadow_below_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0) 1134 shadow_below_edit_fields.SetBackgroundColour(richards_coloured_gray) 1135 szr_shadow_below_edit_fields = wx.BoxSizer(wx.HORIZONTAL) 1136 szr_shadow_below_edit_fields.Add(5, 0, 0, wx.EXPAND) 1137 szr_shadow_below_edit_fields.Add(shadow_below_edit_fields, 12, wx.EXPAND) 1138 1139 # stack edit fields and shadow vertically 1140 vszr_edit_fields = wx.BoxSizer(wx.VERTICAL) 1141 vszr_edit_fields.Add(fields_pnl, 92, wx.EXPAND) 1142 vszr_edit_fields.Add(szr_shadow_below_edit_fields, 5, wx.EXPAND) 1143 1144 # make shadow to the right of the edit area 1145 shadow_rightof_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0) 1146 shadow_rightof_edit_fields.SetBackgroundColour(richards_coloured_gray) 1147 szr_shadow_rightof_edit_fields = wx.BoxSizer(wx.VERTICAL) 1148 szr_shadow_rightof_edit_fields.Add(0, 5, 0, wx.EXPAND) 1149 szr_shadow_rightof_edit_fields.Add(shadow_rightof_edit_fields, 1, wx.EXPAND) 1150 1151 # stack vertical edit fields sizer and shadow horizontally 1152 hszr_edit_fields = wx.BoxSizer(wx.HORIZONTAL) 1153 hszr_edit_fields.Add(vszr_edit_fields, 89, wx.EXPAND) 1154 hszr_edit_fields.Add(szr_shadow_rightof_edit_fields, 1, wx.EXPAND) 1155 1156 return hszr_edit_fields
1157
1158 - def set_old_data( self, map):
1159 self.old_data = map
1160
1161 - def _default_init_fields(self):
1162 #self.dirty = 0 #this flag is for patient_activating event to save any unsaved entries 1163 self.setInputFieldValues( self._get_init_values()) 1164 self.data = None
1165
1166 - def _get_init_values(self):
1167 map = {} 1168 for k in self.input_fields.keys(): 1169 map[k] = '' 1170 return map
1171 1172 #--------------------------------------------------------
1173 - def _init_fields(self):
1174 self._default_init_fields()
1175 1176 # _log.Log(gmLog.lErr, 'programmer forgot to define _init_fields() for [%s]' % self._type) 1177 # _log.Log(gmLog.lInfo, 'child classes of gmEditArea *must* override this function') 1178 # raise AttributeError 1179 #-------------------------------------------------------------------------------------------------------------
1180 - def _updateUI(self):
1181 _log.warning("you may want to override _updateUI for [%s]" % self.__class__.__name__)
1182 1183
1184 - def _postInit(self):
1185 """override for further control setup""" 1186 pass
1187 1188
1189 - def _makeLineSizer(self, widget, weight, spacerWeight):
1190 szr = wx.BoxSizer(wx.HORIZONTAL) 1191 szr.Add( widget, weight, wx.EXPAND) 1192 szr.Add( 0,0, spacerWeight, wx.EXPAND) 1193 return szr
1194
1195 - def _makeCheckBox(self, parent, title):
1196 1197 cb = wx.CheckBox( parent, -1, _(title)) 1198 cb.SetForegroundColour( richards_blue) 1199 return cb
1200 1201 1202
1203 - def _makeExtraColumns(self , parent, lines, weightMap = {} ):
1204 """this is a utlity method to add extra columns""" 1205 #add an extra column if the class has attribute "extraColumns" 1206 if self.__class__.__dict__.has_key("extraColumns"): 1207 for x in self.__class__.extraColumns: 1208 lines = self._addColumn(parent, lines, x, weightMap) 1209 return lines
1210 1211 1212
1213 - def _addColumn(self, parent, lines, extra, weightMap = {}, existingWeight = 5 , extraWeight = 2):
1214 """ 1215 # add ia extra column in the edit area. 1216 # preconditions: 1217 # parent is fields_pnl (weak); 1218 # self.input_fields exists (required); 1219 # ; extra is a list of tuples of format - 1220 # ( key for input_fields, widget label , widget class to instantiate ) 1221 """ 1222 1223 newlines = [] 1224 i = 0 1225 for x in lines: 1226 # adjust weight if line has specific weightings. 1227 if weightMap.has_key( x): 1228 (existingWeight, extraWeight) = weightMap[x] 1229 1230 szr = wx.BoxSizer(wx.HORIZONTAL) 1231 szr.Add( x, existingWeight, wx.EXPAND) 1232 if i < len(extra) and extra[i] <> None: 1233 1234 (inputKey, widgetLabel, aclass) = extra[i] 1235 if aclass.__name__ in CONTROLS_WITHOUT_LABELS: 1236 szr.Add( self._make_prompt(parent, widgetLabel, richards_blue) ) 1237 widgetLabel = "" 1238 1239 1240 w = aclass( parent, -1, widgetLabel) 1241 if not aclass.__name__ in CONTROLS_WITHOUT_LABELS: 1242 w.SetForegroundColour(richards_blue) 1243 1244 szr.Add(w, extraWeight , wx.EXPAND) 1245 1246 # make sure the widget is locatable via input_fields 1247 self.input_fields[inputKey] = w 1248 1249 newlines.append(szr) 1250 i += 1 1251 return newlines
1252
1253 - def setInputFieldValues(self, map, id = None ):
1254 #self.monitoring_dirty = 0 1255 for k,v in map.items(): 1256 field = self.input_fields.get(k, None) 1257 if field == None: 1258 continue 1259 try: 1260 field.SetValue( str(v) ) 1261 except: 1262 try: 1263 if type(v) == type(''): 1264 v = 0 1265 1266 field.SetValue( v) 1267 except: 1268 pass 1269 self.setDataId(id) 1270 #self.monitoring_dirty = 1 1271 self.set_old_data(self.getInputFieldValues())
1272
1273 - def getDataId(self):
1274 return self.data
1275
1276 - def setDataId(self, id):
1277 self.data = id
1278
1279 - def _getInputFieldValues(self):
1280 values = {} 1281 for k,v in self.input_fields.items(): 1282 values[k] = v.GetValue() 1283 return values
1284
1285 - def getInputFieldValues(self, fields = None):
1286 if fields == None: 1287 fields = self.input_fields.keys() 1288 values = {} 1289 for f in fields: 1290 try: 1291 values[f] = self.input_fields[f].GetValue() 1292 except: 1293 pass 1294 return values
1295 #====================================================================
1296 -class gmFamilyHxEditArea(gmEditArea):
1297 - def __init__(self, parent, id):
1298 try: 1299 gmEditArea.__init__(self, parent, id, aType = 'family history') 1300 except gmExceptions.ConstructorError: 1301 _log.exceptions('cannot instantiate family Hx edit area') 1302 raise
1303 #----------------------------------------------------------------
1304 - def _make_edit_lines(self, parent):
1305 _log.debug("making family Hx lines") 1306 lines = [] 1307 self.input_fields = {} 1308 # line 1 1309 # FIXME: put patient search widget here, too ... 1310 # add button "make active patient" 1311 self.input_fields['name'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize) 1312 self.input_fields['DOB'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize) 1313 lbl_dob = self._make_prompt(parent, _(" Date of Birth "), richards_blue) 1314 szr = wx.BoxSizer(wx.HORIZONTAL) 1315 szr.Add(self.input_fields['name'], 4, wx.EXPAND) 1316 szr.Add(lbl_dob, 2, wx.EXPAND) 1317 szr.Add(self.input_fields['DOB'], 4, wx.EXPAND) 1318 lines.append(szr) 1319 # line 2 1320 # FIXME: keep relationship attachments permamently ! (may need to make new patient ...) 1321 # FIXME: learning phrasewheel attached to list loaded from backend 1322 self.input_fields['relationship'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize) 1323 szr = wx.BoxSizer(wx.HORIZONTAL) 1324 szr.Add(self.input_fields['relationship'], 4, wx.EXPAND) 1325 lines.append(szr) 1326 # line 3 1327 self.input_fields['condition'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize) 1328 self.cb_condition_confidential = wx.CheckBox(parent, -1, _("confidental"), wx.DefaultPosition, wx.DefaultSize, wx.NO_BORDER) 1329 szr = wx.BoxSizer(wx.HORIZONTAL) 1330 szr.Add(self.input_fields['condition'], 6, wx.EXPAND) 1331 szr.Add(self.cb_condition_confidential, 0, wx.EXPAND) 1332 lines.append(szr) 1333 # line 4 1334 self.input_fields['comment'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize) 1335 lines.append(self.input_fields['comment']) 1336 # line 5 1337 lbl_onset = self._make_prompt(parent, _(" age onset "), richards_blue) 1338 self.input_fields['age onset'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize) 1339 # FIXME: combo box ... 1340 lbl_caused_death = self._make_prompt(parent, _(" caused death "), richards_blue) 1341 self.input_fields['caused death'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize) 1342 lbl_aod = self._make_prompt(parent, _(" age died "), richards_blue) 1343 self.input_fields['AOD'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize) 1344 szr = wx.BoxSizer(wx.HORIZONTAL) 1345 szr.Add(lbl_onset, 0, wx.EXPAND) 1346 szr.Add(self.input_fields['age onset'], 1,wx.EXPAND) 1347 szr.Add(lbl_caused_death, 0, wx.EXPAND) 1348 szr.Add(self.input_fields['caused death'], 2,wx.EXPAND) 1349 szr.Add(lbl_aod, 0, wx.EXPAND) 1350 szr.Add(self.input_fields['AOD'], 1, wx.EXPAND) 1351 szr.Add(2, 2, 8) 1352 lines.append(szr) 1353 # line 6 1354 self.input_fields['progress notes'] = cEditAreaField(parent, -1, wx.DefaultPosition, wx.DefaultSize) 1355 lines.append(self.input_fields['progress notes']) 1356 # line 8 1357 self.Btn_next_condition = wx.Button(parent, -1, _("Next Condition")) 1358 szr = wx.BoxSizer(wx.HORIZONTAL) 1359 szr.AddSpacer(10, 0, 0) 1360 szr.Add(self.Btn_next_condition, 0, wx.EXPAND | wx.ALL, 1) 1361 szr.Add(2, 1, 5) 1362 szr.Add(self._make_standard_buttons(parent), 0, wx.EXPAND) 1363 lines.append(szr) 1364 1365 return lines
1366
1367 - def _save_data(self):
1368 return 1
1369 1370 #====================================================================
1371 -class gmPastHistoryEditArea(gmEditArea):
1372
1373 - def __init__(self, parent, id):
1374 gmEditArea.__init__(self, parent, id, aType = 'past history')
1375
1376 - def _define_prompts(self):
1377 self._add_prompt(line = 1, label = _("When Noted")) 1378 self._add_prompt(line = 2, label = _("Laterality")) 1379 self._add_prompt(line = 3, label = _("Condition")) 1380 self._add_prompt(line = 4, label = _("Notes")) 1381 self._add_prompt(line = 6, label = _("Status")) 1382 self._add_prompt(line = 7, label = _("Progress Note")) 1383 self._add_prompt(line = 8, label = '')
1384 #--------------------------------------------------------
1385 - def _define_fields(self, parent):
1386 # line 1 1387 self.fld_date_noted = gmDateTimeInput.gmDateInput( 1388 parent = parent, 1389 id = -1, 1390 style = wx.SIMPLE_BORDER 1391 ) 1392 self._add_field( 1393 line = 1, 1394 pos = 1, 1395 widget = self.fld_date_noted, 1396 weight = 2 1397 ) 1398 self._add_field( 1399 line = 1, 1400 pos = 2, 1401 widget = cPrompt_edit_area(parent,-1, _("Age")), 1402 weight = 0) 1403 1404 self.fld_age_noted = cEditAreaField(parent) 1405 self._add_field( 1406 line = 1, 1407 pos = 3, 1408 widget = self.fld_age_noted, 1409 weight = 2 1410 ) 1411 1412 # line 2 1413 self.fld_laterality_none= wx.RadioButton(parent, -1, _("N/A")) 1414 self.fld_laterality_left= wx.RadioButton(parent, -1, _("L")) 1415 self.fld_laterality_right= wx.RadioButton(parent, -1, _("R")) 1416 self.fld_laterality_both= wx.RadioButton(parent, -1, _("both")) 1417 self._add_field( 1418 line = 2, 1419 pos = 1, 1420 widget = self.fld_laterality_none, 1421 weight = 0 1422 ) 1423 self._add_field( 1424 line = 2, 1425 pos = 2, 1426 widget = self.fld_laterality_left, 1427 weight = 0 1428 ) 1429 self._add_field( 1430 line = 2, 1431 pos = 3, 1432 widget = self.fld_laterality_right, 1433 weight = 1 1434 ) 1435 self._add_field( 1436 line = 2, 1437 pos = 4, 1438 widget = self.fld_laterality_both, 1439 weight = 1 1440 ) 1441 # line 3 1442 self.fld_condition= cEditAreaField(parent) 1443 self._add_field( 1444 line = 3, 1445 pos = 1, 1446 widget = self.fld_condition, 1447 weight = 6 1448 ) 1449 # line 4 1450 self.fld_notes= cEditAreaField(parent) 1451 self._add_field( 1452 line = 4, 1453 pos = 1, 1454 widget = self.fld_notes, 1455 weight = 6 1456 ) 1457 # line 5 1458 self.fld_significant= wx.CheckBox( 1459 parent, 1460 -1, 1461 _("significant"), 1462 style = wx.NO_BORDER 1463 ) 1464 self.fld_active= wx.CheckBox( 1465 parent, 1466 -1, 1467 _("active"), 1468 style = wx.NO_BORDER 1469 ) 1470 1471 self._add_field( 1472 line = 5, 1473 pos = 1, 1474 widget = self.fld_significant, 1475 weight = 0 1476 ) 1477 self._add_field( 1478 line = 5, 1479 pos = 2, 1480 widget = self.fld_active, 1481 weight = 0 1482 ) 1483 #line 6 1484 self.fld_progress= cEditAreaField(parent) 1485 self._add_field( 1486 line = 6, 1487 pos = 1, 1488 widget = self.fld_progress, 1489 weight = 6 1490 ) 1491 1492 #line 7 1493 self._add_field( 1494 line = 7, 1495 pos = 4, 1496 widget = self._make_standard_buttons(parent), 1497 weight = 2 1498 )
1499 #--------------------------------------------------------
1500 - def _postInit(self):
1501 return 1502 #handling of auto age or year filling. 1503 wx.EVT_KILL_FOCUS( self.fld_age_noted, self._ageKillFocus) 1504 wx.EVT_KILL_FOCUS( self.fld_date_noted, self._yearKillFocus)
1505 #--------------------------------------------------------
1506 - def _ageKillFocus( self, event):
1507 # skip first, else later failure later in block causes widget to be unfocusable 1508 event.Skip() 1509 try : 1510 year = self._getBirthYear() + int(self.fld_age_noted.GetValue().strip() ) 1511 self.fld_date_noted.SetValue( str (year) ) 1512 except: 1513 pass
1514
1515 - def _getBirthYear(self):
1516 try: 1517 birthyear = int(str(self._patient['dob']).split('-')[0]) 1518 except: 1519 # birthyear = time.localtime()[0] 1520 birthyear = 1 1521 1522 return birthyear
1523
1524 - def _yearKillFocus( self, event):
1525 event.Skip() 1526 try: 1527 age = int(self.fld_date_noted.GetValue().strip() ) - self._getBirthYear() 1528 self.fld_age_noted.SetValue( str (age) ) 1529 except: 1530 pass 1531 1532 __init_values = { 1533 "condition": "", 1534 "notes1": "", 1535 "notes2": "", 1536 "age": "", 1537 #"year": str(time.localtime()[0]), 1538 "progress": "", 1539 "active": 1, 1540 "operation": 0, 1541 "confidential": 0, 1542 "significant": 1, 1543 "both": 0, 1544 "left": 0, 1545 "right": 0, 1546 "none" : 1 1547 } 1548
1549 - def _getDefaultAge(self):
1550 try: 1551 #return time.localtime()[0] - self._patient.getBirthYear() 1552 return 1 1553 except: 1554 return 0
1555
1556 - def _get_init_values(self):
1557 values = gmPastHistoryEditArea.__init_values 1558 values["age"] = str( self._getDefaultAge()) 1559 return values
1560
1561 - def _save_data(self):
1562 clinical = self._patient.get_emr().get_past_history() 1563 if self.getDataId() is None: 1564 id = clinical.create_history( self.get_fields_formatting_values() ) 1565 self.setDataId(id) 1566 return 1567 1568 clinical.update_history( self.get_fields_formatting_values(), self.getDataId() )
1569 1570 #====================================================================
1571 -class gmReferralEditArea(gmEditArea):
1572
1573 - def __init__(self, parent, id):
1574 try: 1575 gmEditArea.__init__(self, parent, id, aType = 'referral') 1576 except gmExceptions.ConstructorError: 1577 _log.exception('cannot instantiate referral edit area') 1578 self.data = None # we don't use this in this widget 1579 self.recipient = None
1580
1581 - def _define_prompts(self):
1582 self._add_prompt (line = 1, label = _ ("Specialty")) 1583 self._add_prompt (line = 2, label = _ ("Name")) 1584 self._add_prompt (line = 3, label = _ ("Address")) 1585 self._add_prompt (line = 4, label = _ ("Options")) 1586 self._add_prompt (line = 5, label = _("Text"), weight =6) 1587 self._add_prompt (line = 6, label = "")
1588
1589 - def _define_fields (self, parent):
1590 self.fld_specialty = gmPhraseWheel.cPhraseWheel ( 1591 parent = parent, 1592 id = -1, 1593 style = wx.SIMPLE_BORDER 1594 ) 1595 #_decorate_editarea_field (self.fld_specialty) 1596 self._add_field ( 1597 line = 1, 1598 pos = 1, 1599 widget = self.fld_specialty, 1600 weight = 1 1601 ) 1602 self.fld_name = gmPhraseWheel.cPhraseWheel ( 1603 parent = parent, 1604 id = -1, 1605 style = wx.SIMPLE_BORDER 1606 ) 1607 #_decorate_editarea_field (self.fld_name) 1608 self._add_field ( 1609 line = 2, 1610 pos = 1, 1611 widget = self.fld_name, 1612 weight = 1 1613 ) 1614 self.fld_address = wx.ComboBox (parent, -1, style = wx.CB_READONLY) 1615 #_decorate_editarea_field (self.fld_address) 1616 self._add_field ( 1617 line = 3, 1618 pos = 1, 1619 widget = self.fld_address, 1620 weight = 1 1621 ) 1622 # FIXME: replace with set_callback_on_* 1623 # self.fld_specialty.setDependent (self.fld_name, "occupation") 1624 self.fld_name.add_callback_on_selection(self.setAddresses) 1625 # flags line 1626 self.fld_med = wx.CheckBox (parent, -1, _("Meds"), style=wx.NO_BORDER) 1627 self._add_field ( 1628 line = 4, 1629 pos = 1, 1630 widget = self.fld_med, 1631 weight = 1 1632 ) 1633 self.fld_past = wx.CheckBox (parent, -1, _("Past Hx"), style=wx.NO_BORDER) 1634 self._add_field ( 1635 line = 4, 1636 pos = 4, 1637 widget = self.fld_past, 1638 weight = 1 1639 ) 1640 self.fld_text = wx.TextCtrl (parent, -1, style= wx.TE_MULTILINE) 1641 self._add_field ( 1642 line = 5, 1643 pos = 1, 1644 widget = self.fld_text, 1645 weight = 1) 1646 # final line 1647 self._add_field( 1648 line = 6, 1649 pos = 1, 1650 widget = self._make_standard_buttons(parent), 1651 weight = 1 1652 ) 1653 return 1
1654
1655 - def set_data (self):
1656 """ 1657 Doesn't accept any value as this doesn't make sense for this edit area 1658 """ 1659 self.fld_specialty.SetValue ('') 1660 self.fld_name.SetValue ('') 1661 self.fld_address.Clear () 1662 self.fld_address.SetValue ('') 1663 self.fld_med.SetValue (0) 1664 self.fld_past.SetValue (0) 1665 self.fld_text.SetValue ('') 1666 self.recipient = None
1667
1668 - def setAddresses (self, id):
1669 """ 1670 Set the available addresses for the selected identity 1671 """ 1672 if id is None: 1673 self.recipient = None 1674 self.fld_address.Clear () 1675 self.fld_address.SetValue ('') 1676 else: 1677 self.recipient = gmDemographicRecord.cDemographicRecord_SQL (id) 1678 self.fld_address.Clear () 1679 self.addr = self.recipient.getAddresses ('work') 1680 for i in self.addr: 1681 self.fld_address.Append (_("%(number)s %(street)s, %(urb)s %(postcode)s") % i, ('post', i)) 1682 fax = self.recipient.getCommChannel (gmDemographicRecord.FAX) 1683 email = self.recipient.getCommChannel (gmDemographicRecord.EMAIL) 1684 if fax: 1685 self.fld_address.Append ("%s: %s" % (_("FAX"), fax), ('fax', fax)) 1686 if email: 1687 self.fld_address.Append ("%s: %s" % (_("E-MAIL"), email), ('email', email))
1688
1689 - def _save_new_entry(self):
1690 """ 1691 We are always saving a "new entry" here because data_ID is always None 1692 """ 1693 if not self.recipient: 1694 raise gmExceptions.InvalidInputError(_('must have a recipient')) 1695 if self.fld_address.GetSelection() == -1: 1696 raise gmExceptions.InvalidInputError(_('must select address')) 1697 channel, addr = self.fld_address.GetClientData (self.fld_address.GetSelection()) 1698 text = self.fld_text.GetValue() 1699 flags = {} 1700 flags['meds'] = self.fld_med.GetValue() 1701 flags['pasthx'] = self.fld_past.GetValue() 1702 if not gmReferral.create_referral (self._patient, self.recipient, channel, addr, text, flags): 1703 raise gmExceptions.InvalidInputError('error sending form')
1704 1705 #==================================================================== 1706 #==================================================================== 1707 # unconverted edit areas below 1708 #====================================================================
1709 -class gmPrescriptionEditArea(gmEditArea):
1710 - def __init__(self, parent, id):
1711 try: 1712 gmEditArea.__init__(self, parent, id, aType = 'prescription') 1713 except gmExceptions.ConstructorError: 1714 _log.exceptions('cannot instantiate prescription edit area') 1715 raise
1716 1717 1718 #----------------------------------------------------------------
1719 - def _make_edit_lines(self, parent):
1720 _log.debug("making prescription lines") 1721 lines = [] 1722 self.txt_problem = cEditAreaField(parent) 1723 self.txt_class = cEditAreaField(parent) 1724 self.txt_generic = cEditAreaField(parent) 1725 self.txt_brand = cEditAreaField(parent) 1726 self.txt_strength= cEditAreaField(parent) 1727 self.txt_directions= cEditAreaField(parent) 1728 self.txt_for = cEditAreaField(parent) 1729 self.txt_progress = cEditAreaField(parent) 1730 1731 lines.append(self.txt_problem) 1732 lines.append(self.txt_class) 1733 lines.append(self.txt_generic) 1734 lines.append(self.txt_brand) 1735 lines.append(self.txt_strength) 1736 lines.append(self.txt_directions) 1737 lines.append(self.txt_for) 1738 lines.append(self.txt_progress) 1739 lines.append(self._make_standard_buttons(parent)) 1740 self.input_fields = { 1741 "problem": self.txt_problem, 1742 "class" : self.txt_class, 1743 "generic" : self.txt_generic, 1744 "brand" : self.txt_brand, 1745 "strength": self.txt_strength, 1746 "directions": self.txt_directions, 1747 "for" : self.txt_for, 1748 "progress": self.txt_progress 1749 1750 } 1751 1752 return self._makeExtraColumns( parent, lines)
1753 1754 1755 # This makes gmPrescriptionEditArea more adaptable to different nationalities special requirements. 1756 # ( well, it could be.) 1757 # to change at runtime, do 1758 1759 # gmPrescriptionEditArea.extraColumns = [ one or more columnListInfo ] 1760 1761 # each columnListInfo element describes one column, 1762 # where columnListInfo is a list of 1763 # tuples of [ inputMap name, widget label, widget class to instantiate from] 1764 1765 #gmPrescriptionEditArea.extraColumns = [ basicPrescriptionExtra ] 1766 #gmPrescriptionEditArea.extraColumns = [ auPrescriptionExtra ] 1767 1768
1769 - def _save_data(self):
1770 return 1
1771 1772 #==================================================================== 1773 # old style stuff below 1774 #==================================================================== 1775 #Class which shows a blue bold label left justified 1776 #--------------------------------------------------------------------
1777 -class cPrompt_edit_area(wx.StaticText):
1778 - def __init__(self, parent, id, prompt, aColor = richards_blue):
1779 wx.StaticText.__init__(self, parent, id, prompt, wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_LEFT) 1780 self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, '')) 1781 self.SetForegroundColour(aColor)
1782 #==================================================================== 1783 # create the editorprompts class which expects a dictionary of labels 1784 # passed to it with prompts relevant to the editing area. 1785 # remove the if else from this once the edit area labelling is fixed 1786 #--------------------------------------------------------------------
1787 -class gmPnlEditAreaPrompts(wx.Panel):
1788 - def __init__(self, parent, id, prompt_labels):
1789 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER) 1790 self.SetBackgroundColour(richards_light_gray) 1791 gszr = wx.GridSizer (len(prompt_labels)+1, 1, 2, 2) 1792 color = richards_aqua 1793 for prompt_key in prompt_labels.keys(): 1794 label = cPrompt_edit_area(self, -1, " %s" % prompt_labels[prompt_key], aColor = color) 1795 gszr.Add(label, 0, wx.EXPAND | wx.ALIGN_RIGHT) 1796 color = richards_blue 1797 self.SetSizer(gszr) 1798 gszr.Fit(self) 1799 self.SetAutoLayout(True)
1800 #==================================================================== 1801 #Class central to gnumed data input 1802 #allows data entry of multiple different types.e.g scripts, 1803 #referrals, measurements, recalls etc 1804 #@TODO : just about everything 1805 #section = calling section eg allergies, script 1806 #----------------------------------------------------------
1807 -class EditTextBoxes(wx.Panel):
1808 - def __init__(self, parent, id, editareaprompts, section):
1809 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize,style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL) 1810 self.SetBackgroundColour(wx.Color(222,222,222)) 1811 self.parent = parent 1812 # rows, cols, hgap, vgap 1813 self.gszr = wx.GridSizer(len(editareaprompts), 1, 2, 2) 1814 1815 if section == gmSECTION_SUMMARY: 1816 pass 1817 elif section == gmSECTION_DEMOGRAPHICS: 1818 pass 1819 elif section == gmSECTION_CLINICALNOTES: 1820 pass 1821 elif section == gmSECTION_FAMILYHISTORY: 1822 pass 1823 elif section == gmSECTION_PASTHISTORY: 1824 pass 1825 # line 1 1826 1827 self.txt_condition = cEditAreaField(self,PHX_CONDITION,wx.DefaultPosition,wx.DefaultSize) 1828 self.rb_sideleft = wxRadioButton(self,PHX_LEFT, _(" (L) "), wx.DefaultPosition,wx.DefaultSize) 1829 self.rb_sideright = wxRadioButton(self, PHX_RIGHT, _("(R)"), wx.DefaultPosition,wx.DefaultSize,wx.SUNKEN_BORDER) 1830 self.rb_sideboth = wxRadioButton(self, PHX_BOTH, _("Both"), wx.DefaultPosition,wx.DefaultSize) 1831 rbsizer = wx.BoxSizer(wx.HORIZONTAL) 1832 rbsizer.Add(self.rb_sideleft,1,wx.EXPAND) 1833 rbsizer.Add(self.rb_sideright,1,wx.EXPAND) 1834 rbsizer.Add(self.rb_sideboth,1,wx.EXPAND) 1835 szr1 = wx.BoxSizer(wx.HORIZONTAL) 1836 szr1.Add(self.txt_condition, 4, wx.EXPAND) 1837 szr1.Add(rbsizer, 3, wx.EXPAND) 1838 # self.sizer_line1.Add(self.rb_sideleft,1,wx.EXPAND|wxALL,2) 1839 # self.sizer_line1.Add(self.rb_sideright,1,wx.EXPAND|wxALL,2) 1840 # self.sizer_line1.Add(self.rb_sideboth,1,wx.EXPAND|wxALL,2) 1841 # line 2 1842 self.txt_notes1 = cEditAreaField(self,PHX_NOTES,wx.DefaultPosition,wx.DefaultSize) 1843 # line 3 1844 self.txt_notes2= cEditAreaField(self,PHX_NOTES2,wx.DefaultPosition,wx.DefaultSize) 1845 # line 4 1846 self.txt_agenoted = cEditAreaField(self, PHX_AGE, wx.DefaultPosition, wx.DefaultSize) 1847 szr4 = wx.BoxSizer(wx.HORIZONTAL) 1848 szr4.Add(self.txt_agenoted, 1, wx.EXPAND) 1849 szr4.Add(5, 0, 5) 1850 # line 5 1851 self.txt_yearnoted = cEditAreaField(self,PHX_YEAR,wx.DefaultPosition,wx.DefaultSize) 1852 szr5 = wx.BoxSizer(wx.HORIZONTAL) 1853 szr5.Add(self.txt_yearnoted, 1, wx.EXPAND) 1854 szr5.Add(5, 0, 5) 1855 # line 6 1856 self.parent.cb_active = wx.CheckBox(self, PHX_ACTIVE, _("Active"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 1857 self.parent.cb_operation = wx.CheckBox(self, PHX_OPERATION, _("Operation"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 1858 self.parent.cb_confidential = wx.CheckBox(self, PHX_CONFIDENTIAL , _("Confidential"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 1859 self.parent.cb_significant = wx.CheckBox(self, PHX_SIGNIFICANT, _("Significant"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 1860 szr6 = wx.BoxSizer(wx.HORIZONTAL) 1861 szr6.Add(self.parent.cb_active, 1, wx.EXPAND) 1862 szr6.Add(self.parent.cb_operation, 1, wx.EXPAND) 1863 szr6.Add(self.parent.cb_confidential, 1, wx.EXPAND) 1864 szr6.Add(self.parent.cb_significant, 1, wx.EXPAND) 1865 # line 7 1866 self.txt_progressnotes = cEditAreaField(self,PHX_PROGRESSNOTES ,wx.DefaultPosition,wx.DefaultSize) 1867 # line 8 1868 szr8 = wx.BoxSizer(wx.HORIZONTAL) 1869 szr8.Add(5, 0, 6) 1870 szr8.Add(self._make_standard_buttons(), 0, wx.EXPAND) 1871 1872 self.gszr.Add(szr1,0,wx.EXPAND) 1873 self.gszr.Add(self.txt_notes1,0,wx.EXPAND) 1874 self.gszr.Add(self.txt_notes2,0,wx.EXPAND) 1875 self.gszr.Add(szr4,0,wx.EXPAND) 1876 self.gszr.Add(szr5,0,wx.EXPAND) 1877 self.gszr.Add(szr6,0,wx.EXPAND) 1878 self.gszr.Add(self.txt_progressnotes,0,wx.EXPAND) 1879 self.gszr.Add(szr8,0,wx.EXPAND) 1880 #self.anylist = wx.ListCtrl(self, -1, wx.DefaultPosition,wx.DefaultSize,wx.LC_REPORT|wx.LC_LIST|wx.SUNKEN_BORDER) 1881 1882 elif section == gmSECTION_SCRIPT: 1883 pass 1884 elif section == gmSECTION_REQUESTS: 1885 pass 1886 elif section == gmSECTION_RECALLS: 1887 pass 1888 else: 1889 pass 1890 1891 self.SetSizer(self.gszr) 1892 self.gszr.Fit(self) 1893 1894 self.SetAutoLayout(True) 1895 self.Show(True)
1896 #----------------------------------------------------------------
1897 - def _make_standard_buttons(self):
1898 self.btn_OK = wx.Button(self, -1, _("Ok")) 1899 self.btn_Clear = wx.Button(self, -1, _("Clear")) 1900 szr_buttons = wx.BoxSizer(wx.HORIZONTAL) 1901 szr_buttons.Add(self.btn_OK, 1, wx.EXPAND, wx.ALL, 1) 1902 szr_buttons.Add(5, 0, 0) 1903 szr_buttons.Add(self.btn_Clear, 1, wx.EXPAND, wx.ALL, 1) 1904 return szr_buttons
1905 #====================================================================
1906 -class EditArea(wx.Panel):
1907 - def __init__(self, parent, id, line_labels, section):
1908 _log.warning('***** old style EditArea instantiated, please convert *****') 1909 1910 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, style = wx.NO_BORDER) 1911 self.SetBackgroundColour(wx.Color(222,222,222)) 1912 1913 # make prompts 1914 prompts = gmPnlEditAreaPrompts(self, -1, line_labels) 1915 # and shadow below prompts in ... 1916 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0) 1917 # ... gray 1918 shadow_below_prompts.SetBackgroundColour(richards_dark_gray) 1919 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL) 1920 szr_shadow_below_prompts.Add(5,0,0,wx.EXPAND) 1921 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND) 1922 # stack prompts and shadow vertically 1923 szr_prompts = wx.BoxSizer(wx.VERTICAL) 1924 szr_prompts.Add(prompts, 97, wx.EXPAND) 1925 szr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND) 1926 1927 # make edit fields 1928 edit_fields = EditTextBoxes(self, -1, line_labels, section) 1929 # make shadow below edit area ... 1930 shadow_below_editarea = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0) 1931 # ... gray 1932 shadow_below_editarea.SetBackgroundColour(richards_coloured_gray) 1933 szr_shadow_below_editarea = wx.BoxSizer(wx.HORIZONTAL) 1934 szr_shadow_below_editarea.Add(5,0,0,wx.EXPAND) 1935 szr_shadow_below_editarea.Add(shadow_below_editarea, 12, wx.EXPAND) 1936 # stack edit fields and shadow vertically 1937 szr_editarea = wx.BoxSizer(wx.VERTICAL) 1938 szr_editarea.Add(edit_fields, 92, wx.EXPAND) 1939 szr_editarea.Add(szr_shadow_below_editarea, 5, wx.EXPAND) 1940 1941 # make shadows to the right of ... 1942 # ... the prompts ... 1943 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0) 1944 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray) 1945 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL) 1946 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND) 1947 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts,1,wx.EXPAND) 1948 # ... and the edit area 1949 shadow_rightof_editarea = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0) 1950 shadow_rightof_editarea.SetBackgroundColour(richards_coloured_gray) 1951 szr_shadow_rightof_editarea = wx.BoxSizer(wx.VERTICAL) 1952 szr_shadow_rightof_editarea.Add(0, 5, 0, wx.EXPAND) 1953 szr_shadow_rightof_editarea.Add(shadow_rightof_editarea, 1, wx.EXPAND) 1954 1955 # stack prompts, shadows and fields horizontally 1956 self.szr_main_panels = wx.BoxSizer(wx.HORIZONTAL) 1957 self.szr_main_panels.Add(szr_prompts, 10, wx.EXPAND) 1958 self.szr_main_panels.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND) 1959 self.szr_main_panels.Add(5, 0, 0, wx.EXPAND) 1960 self.szr_main_panels.Add(szr_editarea, 89, wx.EXPAND) 1961 self.szr_main_panels.Add(szr_shadow_rightof_editarea, 1, wx.EXPAND) 1962 1963 # use sizer for border around everything plus a little gap 1964 # FIXME: fold into szr_main_panels ? 1965 self.szr_central_container = wx.BoxSizer(wx.HORIZONTAL) 1966 self.szr_central_container.Add(self.szr_main_panels, 1, wx.EXPAND | wx.ALL, 5) 1967 self.SetSizer(self.szr_central_container) 1968 self.szr_central_container.Fit(self) 1969 self.SetAutoLayout(True) 1970 self.Show(True)
1971 1972 1973 #==================================================================== 1974 # old stuff still needed for conversion 1975 #-------------------------------------------------------------------- 1976 #==================================================================== 1977 1978 #==================================================================== 1979 1980 # elif section == gmSECTION_SCRIPT: 1981 # gmLog.gmDefLog.Log (gmLog.lData, "in script section now") 1982 # self.text1_prescription_reason = cEditAreaField(self,-1,wx.DefaultPosition,wx.DefaultSize) 1983 # self.text2_drug_class = cEditAreaField(self,-1,wx.DefaultPosition,wx.DefaultSize) 1984 # self.text3_generic_drug = cEditAreaField(self,-1,wx.DefaultPosition,wx.DefaultSize) 1985 # self.text4_brand_drug = cEditAreaField(self,-1,wx.DefaultPosition,wx.DefaultSize) 1986 # self.text5_strength = cEditAreaField(self,-1,wx.DefaultPosition,wx.DefaultSize) 1987 # self.text6_directions = cEditAreaField(self,-1,wx.DefaultPosition,wx.DefaultSize) 1988 # self.text7_for_duration = cEditAreaField(self,-1,wx.DefaultPosition,wx.DefaultSize) 1989 # self.text8_prescription_progress_notes = cEditAreaField(self,-1,wx.DefaultPosition,wx.DefaultSize) 1990 # self.text9_quantity = cEditAreaField(self,-1,wx.DefaultPosition,wx.DefaultSize) 1991 # lbl_veterans = cPrompt_edit_area(self,-1," Veteran ") 1992 # lbl_reg24 = cPrompt_edit_area(self,-1," Reg 24 ") 1993 # lbl_quantity = cPrompt_edit_area(self,-1," Quantity ") 1994 # lbl_repeats = cPrompt_edit_area(self,-1," Repeats ") 1995 # lbl_usualmed = cPrompt_edit_area(self,-1," Usual ") 1996 # self.cb_veteran = wx.CheckBox(self, -1, " Yes ", wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 1997 # self.cb_reg24 = wx.CheckBox(self, -1, " Yes ", wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 1998 # self.cb_usualmed = wx.CheckBox(self, -1, " Yes ", wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 1999 # self.sizer_auth_PI = wx.BoxSizer(wxHORIZONTAL) 2000 # self.btn_authority = wx.Button(self,-1,">Authority") #create authority script 2001 # self.btn_briefPI = wx.Button(self,-1,"Brief PI") #show brief drug product information 2002 # self.sizer_auth_PI.Add(self.btn_authority,1,wx.EXPAND|wxALL,2) #put authority button and PI button 2003 # self.sizer_auth_PI.Add(self.btn_briefPI,1,wx.EXPAND|wxALL,2) #on same sizer 2004 # self.text10_repeats = cEditAreaField(self,-1,wx.DefaultPosition,wx.DefaultSize) 2005 # self.sizer_line3.Add(self.text3_generic_drug,5,wx.EXPAND) 2006 # self.sizer_line3.Add(lbl_veterans,1,wx.EXPAND) 2007 # self.sizer_line3.Add(self.cb_veteran,1,wx.EXPAND) 2008 # self.sizer_line4.Add(self.text4_brand_drug,5,wx.EXPAND) 2009 # self.sizer_line4.Add(lbl_reg24,1,wx.EXPAND) 2010 # self.sizer_line4.Add(self.cb_reg24,1,wx.EXPAND) 2011 # self.sizer_line5.Add(self.text5_strength,5,wx.EXPAND) 2012 # self.sizer_line5.Add(lbl_quantity,1,wx.EXPAND) 2013 # self.sizer_line5.Add(self.text9_quantity,1,wx.EXPAND) 2014 # self.sizer_line6.Add(self.text6_directions,5,wx.EXPAND) 2015 # self.sizer_line6.Add(lbl_repeats,1,wx.EXPAND) 2016 # self.sizer_line6.Add(self.text10_repeats,1,wx.EXPAND) 2017 # self.sizer_line7.Add(self.text7_for_duration,5,wx.EXPAND) 2018 # self.sizer_line7.Add(lbl_usualmed,1,wx.EXPAND) 2019 # self.sizer_line7.Add(self.cb_usualmed,1,wx.EXPAND) 2020 # self.sizer_line8.Add(5,0,0) 2021 # self.sizer_line8.Add(self.sizer_auth_PI,2,wx.EXPAND) 2022 # self.sizer_line8.Add(5,0,2) 2023 # self.sizer_line8.Add(self.btn_OK,1,wx.EXPAND|wxALL,2) 2024 # self.sizer_line8.Add(self.btn_Clear,1,wx.EXPAND|wxALL,2) 2025 # self.gszr.Add(self.text1_prescription_reason,1,wx.EXPAND) #prescribe for 2026 # self.gszr.Add(self.text2_drug_class,1,wx.EXPAND) #prescribe by class 2027 # self.gszr.Add(self.sizer_line3,1,wx.EXPAND) #prescribe by generic, lbl_veterans, cb_veteran 2028 # self.gszr.Add(self.sizer_line4,1,wx.EXPAND) #prescribe by brand, lbl_reg24, cb_reg24 2029 # self.gszr.Add(self.sizer_line5,1,wx.EXPAND) #drug strength, lbl_quantity, text_quantity 2030 # self.gszr.Add(self.sizer_line6,1,wx.EXPAND) #txt_directions, lbl_repeats, text_repeats 2031 # self.gszr.Add(self.sizer_line7,1,wx.EXPAND) #text_for,lbl_usual,chk_usual 2032 # self.gszr.Add(self.text8_prescription_progress_notes,1,wx.EXPAND) #text_progressNotes 2033 # self.gszr.Add(self.sizer_line8,1,wx.EXPAND) 2034 2035 2036 # elif section == gmSECTION_REQUESTS: 2037 # #----------------------------------------------------------------------------- 2038 #editing area for general requests e.g pathology, radiology, physiotherapy etc 2039 #create textboxes, radiobuttons etc 2040 #----------------------------------------------------------------------------- 2041 # self.txt_request_type = cEditAreaField(self,ID_REQUEST_TYPE,wx.DefaultPosition,wx.DefaultSize) 2042 # self.txt_request_company = cEditAreaField(self,ID_REQUEST_COMPANY,wx.DefaultPosition,wx.DefaultSize) 2043 # self.txt_request_street = cEditAreaField(self,ID_REQUEST_STREET,wx.DefaultPosition,wx.DefaultSize) 2044 # self.txt_request_suburb = cEditAreaField(self,ID_REQUEST_SUBURB,wx.DefaultPosition,wx.DefaultSize) 2045 # self.txt_request_phone= cEditAreaField(self,ID_REQUEST_PHONE,wx.DefaultPosition,wx.DefaultSize) 2046 # self.txt_request_requests = cEditAreaField(self,ID_REQUEST_REQUESTS,wx.DefaultPosition,wx.DefaultSize) 2047 # self.txt_request_notes = cEditAreaField(self,ID_REQUEST_FORMNOTES,wx.DefaultPosition,wx.DefaultSize) 2048 # self.txt_request_medications = cEditAreaField(self,ID_REQUEST_MEDICATIONS,wx.DefaultPosition,wx.DefaultSize) 2049 # self.txt_request_copyto = cEditAreaField(self,ID_REQUEST_COPYTO,wx.DefaultPosition,wx.DefaultSize) 2050 # self.txt_request_progressnotes = cEditAreaField(self,ID_PROGRESSNOTES,wx.DefaultPosition,wx.DefaultSize) 2051 # self.lbl_companyphone = cPrompt_edit_area(self,-1," Phone ") 2052 # self.cb_includeallmedications = wx.CheckBox(self, -1, " Include all medications ", wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 2053 # self.rb_request_bill_bb = wxRadioButton(self, ID_REQUEST_BILL_BB, "Bulk Bill ", wx.DefaultPosition,wx.DefaultSize) 2054 # self.rb_request_bill_private = wxRadioButton(self, ID_REQUEST_BILL_PRIVATE, "Private", wx.DefaultPosition,wx.DefaultSize,wx.SUNKEN_BORDER) 2055 # self.rb_request_bill_rebate = wxRadioButton(self, ID_REQUEST_BILL_REBATE, "Rebate", wx.DefaultPosition,wx.DefaultSize) 2056 # self.rb_request_bill_wcover = wxRadioButton(self, ID_REQUEST_BILL_wcover, "w/cover", wx.DefaultPosition,wx.DefaultSize) 2057 #-------------------------------------------------------------- 2058 #add controls to sizers where multiple controls per editor line 2059 #-------------------------------------------------------------- 2060 # self.sizer_request_optionbuttons = wx.BoxSizer(wxHORIZONTAL) 2061 # self.sizer_request_optionbuttons.Add(self.rb_request_bill_bb,1,wx.EXPAND) 2062 # self.sizer_request_optionbuttons.Add(self.rb_request_bill_private ,1,wx.EXPAND) 2063 # self.sizer_request_optionbuttons.Add(self.rb_request_bill_rebate ,1,wx.EXPAND) 2064 # self.sizer_request_optionbuttons.Add(self.rb_request_bill_wcover ,1,wx.EXPAND) 2065 # self.sizer_line4.Add(self.txt_request_suburb,4,wx.EXPAND) 2066 # self.sizer_line4.Add(self.lbl_companyphone,1,wx.EXPAND) 2067 # self.sizer_line4.Add(self.txt_request_phone,2,wx.EXPAND) 2068 # self.sizer_line7.Add(self.txt_request_medications, 4,wx.EXPAND) 2069 # self.sizer_line7.Add(self.cb_includeallmedications,3,wx.EXPAND) 2070 # self.sizer_line10.AddSizer(self.sizer_request_optionbuttons,3,wx.EXPAND) 2071 # self.sizer_line10.AddSizer(self.szr_buttons,1,wx.EXPAND) 2072 #self.sizer_line10.Add(self.btn_OK,1,wx.EXPAND|wxALL,1) 2073 #self.sizer_line10.Add(self.btn_Clear,1,wx.EXPAND|wxALL,1) 2074 #------------------------------------------------------------------ 2075 #add either controls or sizers with controls to vertical grid sizer 2076 #------------------------------------------------------------------ 2077 # self.gszr.Add(self.txt_request_type,0,wx.EXPAND) #e.g Pathology 2078 # self.gszr.Add(self.txt_request_company,0,wx.EXPAND) #e.g Douglas Hanly Moir 2079 # self.gszr.Add(self.txt_request_street,0,wx.EXPAND) #e.g 120 Big Street 2080 # self.gszr.AddSizer(self.sizer_line4,0,wx.EXPAND) #e.g RYDE NSW Phone 02 1800 222 365 2081 # self.gszr.Add(self.txt_request_requests,0,wx.EXPAND) #e.g FBC;ESR;UEC;LFTS 2082 # self.gszr.Add(self.txt_request_notes,0,wx.EXPAND) #e.g generally tired;weight loss; 2083 # self.gszr.AddSizer(self.sizer_line7,0,wx.EXPAND) #e.g Lipitor;losec;zyprexa 2084 # self.gszr.Add(self.txt_request_copyto,0,wx.EXPAND) #e.g Dr I'm All Heart, 120 Big Street Smallville 2085 # self.gszr.Add(self.txt_request_progressnotes,0,wx.EXPAND) #emphasised to patient must return for results 2086 # self.sizer_line8.Add(5,0,6) 2087 # self.sizer_line8.Add(self.btn_OK,1,wx.EXPAND|wxALL,2) 2088 # self.sizer_line8.Add(self.btn_Clear,1,wx.EXPAND|wxALL,2) 2089 # self.gszr.Add(self.sizer_line10,0,wx.EXPAND) #options:b/bill private, rebate,w/cover btnok,btnclear 2090 2091 2092 # elif section == gmSECTION_MEASUREMENTS: 2093 # self.combo_measurement_type = wx.ComboBox(self, ID_MEASUREMENT_TYPE, "", wx.DefaultPosition,wx.DefaultSize, ['Blood pressure','INR','Height','Weight','Whatever other measurement you want to put in here'], wx.CB_DROPDOWN) 2094 # self.combo_measurement_type.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL, wx.BOLD,False,'')) 2095 # self.combo_measurement_type.SetForegroundColour(wx.Color(255,0,0)) 2096 # self.txt_measurement_value = cEditAreaField(self,ID_MEASUREMENT_VALUE,wx.DefaultPosition,wx.DefaultSize) 2097 # self.txt_txt_measurement_date = cEditAreaField(self,ID_MEASUREMENT_DATE,wx.DefaultPosition,wx.DefaultSize) 2098 # self.txt_txt_measurement_comment = cEditAreaField(self,ID_MEASUREMENT_COMMENT,wx.DefaultPosition,wx.DefaultSize) 2099 # self.txt_txt_measurement_progressnote = cEditAreaField(self,ID_PROGRESSNOTES,wx.DefaultPosition,wx.DefaultSize) 2100 # self.sizer_graphnextbtn = wx.BoxSizer(wxHORIZONTAL) 2101 # self.btn_nextvalue = wx.Button(self,ID_MEASUREMENT_NEXTVALUE," Next Value ") #clear fields except type 2102 # self.btn_graph = wx.Button(self,ID_MEASUREMENT_GRAPH," Graph ") #graph all values of this type 2103 # self.sizer_graphnextbtn.Add(self.btn_nextvalue,1,wx.EXPAND|wxALL,2) #put next and graph button 2104 # self.sizer_graphnextbtn.Add(self.btn_graph,1,wx.EXPAND|wxALL,2) #on same sizer 2105 # self.gszr.Add(self.combo_measurement_type,0,wx.EXPAND) #e.g Blood pressure 2106 # self.gszr.Add(self.txt_measurement_value,0,wx.EXPAND) #e.g 120.70 2107 # self.gszr.Add(self.txt_txt_measurement_date,0,wx.EXPAND) #e.g 10/12/2001 2108 # self.gszr.Add(self.txt_txt_measurement_comment,0,wx.EXPAND) #e.g sitting, right arm 2109 # self.gszr.Add(self.txt_txt_measurement_progressnote,0,wx.EXPAND) #e.g given home BP montitor, see 1 week 2110 # self.sizer_line8.Add(5,0,0) 2111 # self.sizer_line8.Add(self.sizer_graphnextbtn,2,wx.EXPAND) 2112 # self.sizer_line8.Add(5,0,2) 2113 # self.sizer_line8.Add(self.btn_OK,1,wx.EXPAND|wxALL,2) 2114 # self.sizer_line8.Add(self.btn_Clear,1,wx.EXPAND|wxALL,2) 2115 # self.gszr.AddSizer(self.sizer_line8,0,wx.EXPAND) 2116 2117 2118 # elif section == gmSECTION_REFERRALS: 2119 # self.btnpreview = wx.Button(self,-1,"Preview") 2120 # self.sizer_btnpreviewok = wx.BoxSizer(wxHORIZONTAL) 2121 #-------------------------------------------------------- 2122 #editing area for referral letters, insurance letters etc 2123 #create textboxes, checkboxes etc 2124 #-------------------------------------------------------- 2125 # self.txt_referralcategory = cEditAreaField(self,ID_REFERRAL_CATEGORY,wx.DefaultPosition,wx.DefaultSize) 2126 # self.txt_referralname = cEditAreaField(self,ID_REFERRAL_NAME,wx.DefaultPosition,wx.DefaultSize) 2127 # self.txt_referralorganisation = cEditAreaField(self,ID_REFERRAL_ORGANISATION,wx.DefaultPosition,wx.DefaultSize) 2128 # self.txt_referralstreet1 = cEditAreaField(self,ID_REFERRAL_STREET1,wx.DefaultPosition,wx.DefaultSize) 2129 # self.txt_referralstreet2 = cEditAreaField(self,ID_REFERRAL_STREET2,wx.DefaultPosition,wx.DefaultSize) 2130 # self.txt_referralstreet3 = cEditAreaField(self,ID_REFERRAL_STREET3,wx.DefaultPosition,wx.DefaultSize) 2131 # self.txt_referralsuburb = cEditAreaField(self,ID_REFERRAL_SUBURB,wx.DefaultPosition,wx.DefaultSize) 2132 # self.txt_referralpostcode = cEditAreaField(self,ID_REFERRAL_POSTCODE,wx.DefaultPosition,wx.DefaultSize) 2133 # self.txt_referralfor = cEditAreaField(self,ID_REFERRAL_FOR,wx.DefaultPosition,wx.DefaultSize) 2134 # self.txt_referralwphone= cEditAreaField(self,ID_REFERRAL_WPHONE,wx.DefaultPosition,wx.DefaultSize) 2135 # self.txt_referralwfax= cEditAreaField(self,ID_REFERRAL_WFAX,wx.DefaultPosition,wx.DefaultSize) 2136 # self.txt_referralwemail= cEditAreaField(self,ID_REFERRAL_WEMAIL,wx.DefaultPosition,wx.DefaultSize) 2137 #self.txt_referralrequests = cEditAreaField(self,ID_REFERRAL_REQUESTS,wx.DefaultPosition,wx.DefaultSize) 2138 #self.txt_referralnotes = cEditAreaField(self,ID_REFERRAL_FORMNOTES,wx.DefaultPosition,wx.DefaultSize) 2139 #self.txt_referralmedications = cEditAreaField(self,ID_REFERRAL_MEDICATIONS,wx.DefaultPosition,wx.DefaultSize) 2140 # self.txt_referralcopyto = cEditAreaField(self,ID_REFERRAL_COPYTO,wx.DefaultPosition,wx.DefaultSize) 2141 # self.txt_referralprogressnotes = cEditAreaField(self,ID_PROGRESSNOTES,wx.DefaultPosition,wx.DefaultSize) 2142 # self.lbl_referralwphone = cPrompt_edit_area(self,-1," W Phone ") 2143 # self.lbl_referralwfax = cPrompt_edit_area(self,-1," W Fax ") 2144 # self.lbl_referralwemail = cPrompt_edit_area(self,-1," W Email ") 2145 # self.lbl_referralpostcode = cPrompt_edit_area(self,-1," Postcode ") 2146 # self.chkbox_referral_usefirstname = wx.CheckBox(self, -1, " Use Firstname ", wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 2147 # self.chkbox_referral_headoffice = wx.CheckBox(self, -1, " Head Office ", wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 2148 # self.chkbox_referral_medications = wx.CheckBox(self, -1, " Medications ", wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 2149 # self.chkbox_referral_socialhistory = wx.CheckBox(self, -1, " Social History ", wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 2150 # self.chkbox_referral_familyhistory = wx.CheckBox(self, -1, " Family History ", wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 2151 # self.chkbox_referral_pastproblems = wx.CheckBox(self, -1, " Past Problems ", wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 2152 # self.chkbox_referral_activeproblems = wx.CheckBox(self, -1, " Active Problems ", wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 2153 # self.chkbox_referral_habits = wx.CheckBox(self, -1, " Habits ", wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 2154 #self.chkbox_referral_Includeall = wx.CheckBox(self, -1, " Include all of the above ", wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER) 2155 #-------------------------------------------------------------- 2156 #add controls to sizers where multiple controls per editor line 2157 #-------------------------------------------------------------- 2158 # self.sizer_line2.Add(self.txt_referralname,2,wx.EXPAND) 2159 # self.sizer_line2.Add(self.chkbox_referral_usefirstname,2,wx.EXPAND) 2160 # self.sizer_line3.Add(self.txt_referralorganisation,2,wx.EXPAND) 2161 # self.sizer_line3.Add(self.chkbox_referral_headoffice,2, wx.EXPAND) 2162 # self.sizer_line4.Add(self.txt_referralstreet1,2,wx.EXPAND) 2163 # self.sizer_line4.Add(self.lbl_referralwphone,1,wx.EXPAND) 2164 # self.sizer_line4.Add(self.txt_referralwphone,1,wx.EXPAND) 2165 # self.sizer_line5.Add(self.txt_referralstreet2,2,wx.EXPAND) 2166 # self.sizer_line5.Add(self.lbl_referralwfax,1,wx.EXPAND) 2167 # self.sizer_line5.Add(self.txt_referralwfax,1,wx.EXPAND) 2168 # self.sizer_line6.Add(self.txt_referralstreet3,2,wx.EXPAND) 2169 # self.sizer_line6.Add(self.lbl_referralwemail,1,wx.EXPAND) 2170 # self.sizer_line6.Add(self.txt_referralwemail,1,wx.EXPAND) 2171 # self.sizer_line7.Add(self.txt_referralsuburb,2,wx.EXPAND) 2172 # self.sizer_line7.Add(self.lbl_referralpostcode,1,wx.EXPAND) 2173 # self.sizer_line7.Add(self.txt_referralpostcode,1,wx.EXPAND) 2174 # self.sizer_line10.Add(self.chkbox_referral_medications,1,wx.EXPAND) 2175 # self.sizer_line10.Add(self.chkbox_referral_socialhistory,1,wx.EXPAND) 2176 # self.sizer_line10.Add(self.chkbox_referral_familyhistory,1,wx.EXPAND) 2177 # self.sizer_line11.Add(self.chkbox_referral_pastproblems ,1,wx.EXPAND) 2178 # self.sizer_line11.Add(self.chkbox_referral_activeproblems ,1,wx.EXPAND) 2179 # self.sizer_line11.Add(self.chkbox_referral_habits ,1,wx.EXPAND) 2180 # self.sizer_btnpreviewok.Add(self.btnpreview,0,wx.EXPAND) 2181 # self.szr_buttons.Add(self.btn_Clear,0, wx.EXPAND) 2182 #------------------------------------------------------------------ 2183 #add either controls or sizers with controls to vertical grid sizer 2184 #------------------------------------------------------------------ 2185 # self.gszr.Add(self.txt_referralcategory,0,wx.EXPAND) #e.g Othopaedic surgeon 2186 # self.gszr.Add(self.sizer_line2,0,wx.EXPAND) #e.g Dr B Breaker 2187 # self.gszr.Add(self.sizer_line3,0,wx.EXPAND) #e.g General Orthopaedic servies 2188 # self.gszr.Add(self.sizer_line4,0,wx.EXPAND) #e.g street1 2189 # self.gszr.Add(self.sizer_line5,0,wx.EXPAND) #e.g street2 2190 # self.gszr.Add(self.sizer_line6,0,wx.EXPAND) #e.g street3 2191 # self.gszr.Add(self.sizer_line7,0,wx.EXPAND) #e.g suburb and postcode 2192 # self.gszr.Add(self.txt_referralfor,0,wx.EXPAND) #e.g Referral for an opinion 2193 # self.gszr.Add(self.txt_referralcopyto,0,wx.EXPAND) #e.g Dr I'm All Heart, 120 Big Street Smallville 2194 # self.gszr.Add(self.txt_referralprogressnotes,0,wx.EXPAND) #emphasised to patient must return for results 2195 # self.gszr.AddSizer(self.sizer_line10,0,wx.EXPAND) #e.g check boxes to include medications etc 2196 # self.gszr.Add(self.sizer_line11,0,wx.EXPAND) #e.g check boxes to include active problems etc 2197 #self.spacer = wxWindow(self,-1,wx.DefaultPosition,wx.DefaultSize) 2198 #self.spacer.SetBackgroundColour(wx.Color(255,255,255)) 2199 # self.sizer_line12.Add(5,0,6) 2200 #self.sizer_line12.Add(self.spacer,6,wx.EXPAND) 2201 # self.sizer_line12.Add(self.btnpreview,1,wx.EXPAND|wxALL,2) 2202 # self.sizer_line12.Add(self.btn_Clear,1,wx.EXPAND|wxALL,2) 2203 # self.gszr.Add(self.sizer_line12,0,wx.EXPAND) #btnpreview and btn clear 2204 2205 2206 # elif section == gmSECTION_RECALLS: 2207 #FIXME remove present options in this combo box #FIXME defaults need to be loaded from database 2208 # self.combo_tosee = wx.ComboBox(self, ID_RECALLS_TOSEE, "", wx.DefaultPosition,wx.DefaultSize, ['Doctor1','Doctor2','Nurse1','Dietition'], wx.CB_READONLY ) #wx.CB_DROPDOWN) 2209 # self.combo_tosee.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL, wx.BOLD,False,'')) 2210 # self.combo_tosee.SetForegroundColour(wx.Color(255,0,0)) 2211 #FIXME defaults need to be loaded from database 2212 # self.combo_recall_method = wx.ComboBox(self, ID_RECALLS_CONTACTMETHOD, "", wx.DefaultPosition,wx.DefaultSize, ['Letter','Telephone','Email','Carrier pigeon'], wx.CB_READONLY ) 2213 # self.combo_recall_method.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL, wx.BOLD,False,'')) 2214 # self.combo_recall_method.SetForegroundColour(wx.Color(255,0,0)) 2215 #FIXME defaults need to be loaded from database 2216 # self.combo_apptlength = wx.ComboBox(self, ID_RECALLS_APPNTLENGTH, "", wx.DefaultPosition,wx.DefaultSize, ['brief','standard','long','prolonged'], wx.CB_READONLY ) 2217 # self.combo_apptlength.SetFont(wx.Font(12,wx.SWISS,wx.NORMAL, wx.BOLD,False,'')) 2218 # self.combo_apptlength.SetForegroundColour(wx.Color(255,0,0)) 2219 # self.txt_recall_for = cEditAreaField(self,ID_RECALLS_TXT_FOR, wx.DefaultPosition,wx.DefaultSize) 2220 # self.txt_recall_due = cEditAreaField(self,ID_RECALLS_TXT_DATEDUE, wx.DefaultPosition,wx.DefaultSize) 2221 # self.txt_recall_addtext = cEditAreaField(self,ID_RECALLS_TXT_ADDTEXT,wx.DefaultPosition,wx.DefaultSize) 2222 # self.txt_recall_include = cEditAreaField(self,ID_RECALLS_TXT_INCLUDEFORMS,wx.DefaultPosition,wx.DefaultSize) 2223 # self.txt_recall_progressnotes = cEditAreaField(self,ID_PROGRESSNOTES,wx.DefaultPosition,wx.DefaultSize) 2224 # self.lbl_recall_consultlength = cPrompt_edit_area(self,-1," Appointment length ") 2225 #sizer_lkine1 has the method of recall and the appointment length 2226 # self.sizer_line1.Add(self.combo_recall_method,1,wx.EXPAND) 2227 # self.sizer_line1.Add(self.lbl_recall_consultlength,1,wx.EXPAND) 2228 # self.sizer_line1.Add(self.combo_apptlength,1,wx.EXPAND) 2229 #Now add the controls to the grid sizer 2230 # self.gszr.Add(self.combo_tosee,1,wx.EXPAND) #list of personel for patient to see 2231 # self.gszr.Add(self.txt_recall_for,1,wx.EXPAND) #the actual recall may be free text or word wheel 2232 # self.gszr.Add(self.txt_recall_due,1,wx.EXPAND) #date of future recall 2233 # self.gszr.Add(self.txt_recall_addtext,1,wx.EXPAND) #added explanation e.g 'come fasting' 2234 # self.gszr.Add(self.txt_recall_include,1,wx.EXPAND) #any forms to be sent out first eg FBC 2235 # self.gszr.AddSizer(self.sizer_line1,1,wx.EXPAND) #the contact method, appointment length 2236 # self.gszr.Add(self.txt_recall_progressnotes,1,wx.EXPAND) #add any progress notes for consultation 2237 # self.sizer_line8.Add(5,0,6) 2238 # self.sizer_line8.Add(self.btn_OK,1,wx.EXPAND|wxALL,2) 2239 # self.sizer_line8.Add(self.btn_Clear,1,wx.EXPAND|wxALL,2) 2240 # self.gszr.Add(self.sizer_line8,1,wx.EXPAND) 2241 # else: 2242 # pass 2243 2244 #==================================================================== 2245 # main 2246 #-------------------------------------------------------------------- 2247 if __name__ == "__main__": 2248 2249 #================================================================
2250 - class cTestEditArea(cEditArea):
2251 - def __init__(self, parent):
2252 cEditArea.__init__(self, parent, -1)
2253 - def _define_prompts(self):
2254 self._add_prompt(line=1, label='line 1') 2255 self._add_prompt(line=2, label='buttons')
2256 - def _define_fields(self, parent):
2257 # line 1 2258 self.fld_substance = cEditAreaField(parent) 2259 self._add_field( 2260 line = 1, 2261 pos = 1, 2262 widget = self.fld_substance, 2263 weight = 1 2264 ) 2265 # line 2 2266 self._add_field( 2267 line = 2, 2268 pos = 1, 2269 widget = self._make_standard_buttons(parent), 2270 weight = 1 2271 )
2272 #================================================================ 2273 app = wxPyWidgetTester(size = (400, 200)) 2274 app.SetWidget(cTestEditArea) 2275 app.MainLoop() 2276 # app = wxPyWidgetTester(size = (400, 200)) 2277 # app.SetWidget(gmFamilyHxEditArea, -1) 2278 # app.MainLoop() 2279 # app = wxPyWidgetTester(size = (400, 200)) 2280 # app.SetWidget(gmPastHistoryEditArea, -1) 2281 # app.MainLoop() 2282 #==================================================================== 2283