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