1
2
3
4 __license__ = 'GPL'
5 __version__ = "$Revision: 1.135 $"
6 __author__ = "R.Terry, K.Hilbert"
7
8
9 import sys
10 import logging
11 import datetime as pydt
12
13
14 import wx
15
16
17 if __name__ == '__main__':
18 sys.path.insert(0, '../../')
19 from Gnumed.pycommon import gmDispatcher
20
21
22 _log = logging.getLogger('gm.ui')
23 _log.info(__version__)
24
25 edit_area_modes = ['new', 'edit', 'new_from_existing']
26
28 """Mixin for edit area panels providing generic functionality.
29
30 **************** start of template ****************
31
32 #====================================================================
33 # Class definition:
34
35 from Gnumed.wxGladeWidgets import wxgXxxEAPnl
36
37 class cXxxEAPnl(wxgXxxEAPnl.wxgXxxEAPnl, gmEditArea.cGenericEditAreaMixin):
38
39 def __init__(self, *args, **kwargs):
40
41 try:
42 data = kwargs['xxx']
43 del kwargs['xxx']
44 except KeyError:
45 data = None
46
47 wxgXxxEAPnl.wxgXxxEAPnl.__init__(self, *args, **kwargs)
48 gmEditArea.cGenericEditAreaMixin.__init__(self)
49
50 # Code using this mixin should set mode and data
51 # after instantiating the class:
52 self.mode = 'new'
53 self.data = data
54 if data is not None:
55 self.mode = 'edit'
56
57 #self.__init_ui()
58 #----------------------------------------------------------------
59 # def __init_ui(self):
60 # # adjust phrasewheels etc
61 #----------------------------------------------------------------
62 # generic Edit Area mixin API
63 #----------------------------------------------------------------
64 def _valid_for_save(self):
65
66 # its best to validate bottom -> top such that the
67 # cursor ends up in the topmost failing field
68
69 # remove when implemented:
70 return False
71
72 validity = True
73
74 if self._TCTRL_xxx.GetValue().strip() == u'':
75 validity = False
76 self.display_tctrl_as_valid(tctrl = self._TCTRL_xxx, valid = False)
77 self._TCTRL_xxx.SetFocus()
78 else:
79 self.display_tctrl_as_valid(tctrl = self._TCTRL_xxx, valid = True)
80
81 if self._PRW_xxx.GetData() is None:
82 validity = False
83 self._PRW_xxx.display_as_valid(False)
84 self._PRW_xxx.SetFocus()
85 else:
86 self._PRW_xxx.display_as_valid(True)
87
88 return validity
89 #----------------------------------------------------------------
90 def _save_as_new(self):
91
92 # remove when implemented:
93 return False
94
95 # save the data as a new instance
96 data = gmXXXX.create_xxxx()
97
98 data[''] = self._
99 data[''] = self._
100
101 data.save()
102
103 # must be done very late or else the property access
104 # will refresh the display such that later field
105 # access will return empty values
106 self.data = data
107 return False
108 return True
109 #----------------------------------------------------------------
110 def _save_as_update(self):
111
112 # remove when implemented:
113 return False
114
115 # update self.data and save the changes
116 self.data[''] = self._TCTRL_xxx.GetValue().strip()
117 self.data[''] = self._PRW_xxx.GetData()
118 self.data[''] = self._CHBOX_xxx.GetValue()
119 self.data.save()
120 return True
121 #----------------------------------------------------------------
122 def _refresh_as_new(self):
123 pass
124 #----------------------------------------------------------------
125 def _refresh_as_new_from_existing(self):
126 self._refresh_as_new()
127 #----------------------------------------------------------------
128 def _refresh_from_existing(self):
129 pass
130 #----------------------------------------------------------------
131
132 **************** end of template ****************
133 """
135 self.__mode = 'new'
136 self.__data = None
137 self.successful_save_msg = None
138 self.__tctrl_validity_colors = {
139 True: wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW),
140 False: 'pink'
141 }
142 self._refresh_as_new()
143
146
148 if mode not in edit_area_modes:
149 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
150 if mode == 'edit':
151 if self.__data is None:
152 raise ValueError('[%s] <mode> "edit" needs data value' % self.__class__.__name__)
153
154 prev_mode = self.__mode
155 self.__mode = mode
156 if mode != prev_mode:
157 self.refresh()
158
159 mode = property(_get_mode, _set_mode)
160
163
165 if data is None:
166 if self.__mode == 'edit':
167 raise ValueError('[%s] <mode> "edit" needs data value' % self.__class__.__name__)
168 self.__data = data
169 self.refresh()
170
171 data = property(_get_data, _set_data)
172
174 """Invoked from the generic edit area dialog.
175
176 Invokes
177 _valid_for_save,
178 _save_as_new,
179 _save_as_update
180 on the implementing edit area as needed.
181
182 _save_as_* must set self.__data and return True/False
183 """
184 if not self._valid_for_save():
185 return False
186
187
188 gmDispatcher.send(signal = 'statustext', msg = u'')
189
190 if self.__mode in ['new', 'new_from_existing']:
191 if self._save_as_new():
192 self.mode = 'edit'
193 return True
194 return False
195
196 elif self.__mode == 'edit':
197 return self._save_as_update()
198
199 else:
200 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
201
203 """Invoked from the generic edit area dialog.
204
205 Invokes
206 _refresh_as_new()
207 _refresh_from_existing()
208 _refresh_as_new_from_existing()
209 on the implementing edit area as needed.
210
211 Then calls _valid_for_save().
212 """
213 if self.__mode == 'new':
214 result = self._refresh_as_new()
215 self._valid_for_save()
216 return result
217 elif self.__mode == 'edit':
218 result = self._refresh_from_existing()
219 return result
220 elif self.__mode == 'new_from_existing':
221 result = self._refresh_as_new_from_existing()
222 self._valid_for_save()
223 return result
224 else:
225 raise ValueError('[%s] <mode> must be in %s' % (self.__class__.__name__, edit_area_modes))
226
229
231 ctrl.SetBackgroundColour(self.__tctrl_validity_colors[valid])
232 ctrl.Refresh()
233
234 from Gnumed.wxGladeWidgets import wxgGenericEditAreaDlg2
235
237 """Dialog for parenting edit area panels with save/clear/next/cancel"""
238
239 _lucky_day = 1
240 _lucky_month = 4
241 _today = pydt.date.today()
242
244
245 new_ea = kwargs['edit_area']
246 del kwargs['edit_area']
247
248 if not isinstance(new_ea, cGenericEditAreaMixin):
249 raise TypeError('[%s]: edit area instance must be child of cGenericEditAreaMixin')
250
251 try:
252 single_entry = kwargs['single_entry']
253 del kwargs['single_entry']
254 except KeyError:
255 single_entry = False
256
257 wxgGenericEditAreaDlg2.wxgGenericEditAreaDlg2.__init__(self, *args, **kwargs)
258
259 self.left_extra_button = None
260
261 if cGenericEditAreaDlg2._today.day != cGenericEditAreaDlg2._lucky_day:
262 self._BTN_lucky.Enable(False)
263 self._BTN_lucky.Hide()
264 else:
265 if cGenericEditAreaDlg2._today.month != cGenericEditAreaDlg2._lucky_month:
266 self._BTN_lucky.Enable(False)
267 self._BTN_lucky.Hide()
268
269
270 dummy_ea_pnl = self._PNL_ea
271 ea_pnl_szr = dummy_ea_pnl.GetContainingSizer()
272 ea_pnl_parent = dummy_ea_pnl.GetParent()
273 ea_pnl_szr.Remove(dummy_ea_pnl)
274 dummy_ea_pnl.Destroy()
275 del dummy_ea_pnl
276 new_ea_min_size = new_ea.GetMinSize()
277 new_ea.Reparent(ea_pnl_parent)
278 self._PNL_ea = new_ea
279 ea_pnl_szr.Add(self._PNL_ea, 1, wx.EXPAND, 0)
280 ea_pnl_szr.SetMinSize(new_ea_min_size)
281 ea_pnl_szr.Fit(new_ea)
282
283
284 if single_entry:
285 self._BTN_forward.Enable(False)
286 self._BTN_forward.Hide()
287
288 self._adjust_clear_revert_buttons()
289
290
291 self._TCTRL_status.SetValue('')
292 gmDispatcher.connect(signal = u'statustext', receiver = self._on_set_statustext)
293
294
295
296 main_szr = self.GetSizer()
297 main_szr.Fit(self)
298 self.Layout()
299
300
301 self._PNL_ea.refresh()
302
303 - def _on_set_statustext(self, msg=None, loglevel=None, beep=True):
304 if msg is None:
305 self._TCTRL_status.SetValue('')
306 return
307 if msg.strip() == u'':
308 self._TCTRL_status.SetValue('')
309 return
310 self._TCTRL_status.SetValue(msg)
311 return
312
324
332
335
338
353
364
373
374
375
391
392 left_extra_button = property(lambda x:x, _set_left_extra_button)
393
394
395 from Gnumed.wxGladeWidgets import wxgGenericEditAreaDlg
396
398 """Dialog for parenting edit area with save/clear/cancel"""
399
401
402 ea = kwargs['edit_area']
403 del kwargs['edit_area']
404
405 wxgGenericEditAreaDlg.wxgGenericEditAreaDlg.__init__(self, *args, **kwargs)
406
407 szr = self._PNL_ea.GetContainingSizer()
408 szr.Remove(self._PNL_ea)
409 ea.Reparent(self)
410 szr.Add(ea, 1, wx.ALL|wx.EXPAND, 4)
411 self._PNL_ea = ea
412
413 self.Layout()
414 szr = self.GetSizer()
415 szr.Fit(self)
416 self.Refresh()
417
418 self._PNL_ea.refresh()
419
427
430
431
432
433
434
435
436 from Gnumed.pycommon import gmGuiBroker
437
438
439 _gb = gmGuiBroker.GuiBroker()
440
441 gmSECTION_SUMMARY = 1
442 gmSECTION_DEMOGRAPHICS = 2
443 gmSECTION_CLINICALNOTES = 3
444 gmSECTION_FAMILYHISTORY = 4
445 gmSECTION_PASTHISTORY = 5
446 gmSECTION_SCRIPT = 8
447 gmSECTION_REQUESTS = 9
448 gmSECTION_REFERRALS = 11
449 gmSECTION_RECALLS = 12
450
451 richards_blue = wx.Colour(0,0,131)
452 richards_aqua = wx.Colour(0,194,197)
453 richards_dark_gray = wx.Colour(131,129,131)
454 richards_light_gray = wx.Colour(255,255,255)
455 richards_coloured_gray = wx.Colour(131,129,131)
456
457
458 CONTROLS_WITHOUT_LABELS =['wxTextCtrl', 'cEditAreaField', 'wx.SpinCtrl', 'gmPhraseWheel', 'wx.ComboBox']
459
461 widget.SetForegroundColour(wx.Colour(255, 0, 0))
462 widget.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
463
476 if not isinstance(edit_area, cEditArea2):
477 raise TypeError('<edit_area> must be of type cEditArea2 but is <%s>' % type(edit_area))
478 wx.Dialog.__init__(self, parent, id, title, pos, size, style, name)
479 self.__wxID_BTN_SAVE = wx.NewId()
480 self.__wxID_BTN_RESET = wx.NewId()
481 self.__editarea = edit_area
482 self.__do_layout()
483 self.__register_events()
484
485
486
489
491 self.__editarea.Reparent(self)
492
493 self.__btn_SAVE = wx.Button(self, self.__wxID_BTN_SAVE, _("Save"))
494 self.__btn_SAVE.SetToolTipString(_('save entry into medical record'))
495 self.__btn_RESET = wx.Button(self, self.__wxID_BTN_RESET, _("Reset"))
496 self.__btn_RESET.SetToolTipString(_('reset entry'))
497 self.__btn_CANCEL = wx.Button(self, wx.ID_CANCEL, _("Cancel"))
498 self.__btn_CANCEL.SetToolTipString(_('discard entry and cancel'))
499
500 szr_buttons = wx.BoxSizer(wx.HORIZONTAL)
501 szr_buttons.Add(self.__btn_SAVE, 1, wx.EXPAND | wx.ALL, 1)
502 szr_buttons.Add(self.__btn_RESET, 1, wx.EXPAND | wx.ALL, 1)
503 szr_buttons.Add(self.__btn_CANCEL, 1, wx.EXPAND | wx.ALL, 1)
504
505 szr_main = wx.BoxSizer(wx.VERTICAL)
506 szr_main.Add(self.__editarea, 1, wx.EXPAND)
507 szr_main.Add(szr_buttons, 0, wx.EXPAND)
508
509 self.SetSizerAndFit(szr_main)
510
511
512
514
515 wx.EVT_BUTTON(self.__btn_SAVE, self.__wxID_BTN_SAVE, self._on_SAVE_btn_pressed)
516 wx.EVT_BUTTON(self.__btn_RESET, self.__wxID_BTN_RESET, self._on_RESET_btn_pressed)
517 wx.EVT_BUTTON(self.__btn_CANCEL, wx.ID_CANCEL, self._on_CANCEL_btn_pressed)
518
519 wx.EVT_CLOSE(self, self._on_CANCEL_btn_pressed)
520
521
522
523
524
525
526 return 1
527
529 if self.__editarea.save_data():
530 self.__editarea.Close()
531 self.EndModal(wx.ID_OK)
532 return
533 short_err = self.__editarea.get_short_error()
534 long_err = self.__editarea.get_long_error()
535 if (short_err is None) and (long_err is None):
536 long_err = _(
537 'Unspecified error saving data in edit area.\n\n'
538 'Programmer forgot to specify proper error\n'
539 'message in [%s].'
540 ) % self.__editarea.__class__.__name__
541 if short_err is not None:
542 gmDispatcher.send(signal = 'statustext', msg = short_err)
543 if long_err is not None:
544 gmGuiHelpers.gm_show_error(long_err, _('saving clinical data'))
545
547 self.__editarea.Close()
548 self.EndModal(wx.ID_CANCEL)
549
552
554 - def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL):
555
556 wx.Panel.__init__ (
557 self,
558 parent,
559 id,
560 pos = pos,
561 size = size,
562 style = style | wx.TAB_TRAVERSAL
563 )
564 self.SetBackgroundColour(wx.Colour(222,222,222))
565
566 self.data = None
567 self.fields = {}
568 self.prompts = {}
569 self._short_error = None
570 self._long_error = None
571 self._summary = None
572 self._patient = gmPerson.gmCurrentPatient()
573 self.__wxID_BTN_OK = wx.NewId()
574 self.__wxID_BTN_CLEAR = wx.NewId()
575 self.__do_layout()
576 self.__register_events()
577 self.Show()
578
579
580
582 """This needs to be overridden by child classes."""
583 self._long_error = _(
584 'Cannot save data from edit area.\n\n'
585 'Programmer forgot to override method:\n'
586 ' <%s.save_data>'
587 ) % self.__class__.__name__
588 return False
589
591 msg = _(
592 'Cannot reset fields in edit area.\n\n'
593 'Programmer forgot to override method:\n'
594 ' <%s.reset_ui>'
595 ) % self.__class__.__name__
596 gmGuiHelpers.gm_show_error(msg)
597
599 tmp = self._short_error
600 self._short_error = None
601 return tmp
602
604 tmp = self._long_error
605 self._long_error = None
606 return tmp
607
609 return _('<No embed string for [%s]>') % self.__class__.__name__
610
611
612
624
629
630
631
633 self.__deregister_events()
634 event.Skip()
635
637 """Only active if _make_standard_buttons was called in child class."""
638
639 try:
640 event.Skip()
641 if self.data is None:
642 self._save_new_entry()
643 self.reset_ui()
644 else:
645 self._save_modified_entry()
646 self.reset_ui()
647 except gmExceptions.InvalidInputError, err:
648
649
650 gmGuiHelpers.gm_show_error (err, _("Invalid Input"))
651 except:
652 _log.exception( "save data problem in [%s]" % self.__class__.__name__)
653
655 """Only active if _make_standard_buttons was called in child class."""
656
657 self.reset_ui()
658 event.Skip()
659
661 self.__deregister_events()
662
663 if not self._patient.connected:
664 return True
665
666
667
668
669 return True
670 _log.error('[%s] lossage' % self.__class__.__name__)
671 return False
672
674 """Just before new patient becomes active."""
675
676 if not self._patient.connected:
677 return True
678
679
680
681
682 return True
683 _log.error('[%s] lossage' % self.__class__.__name__)
684 return False
685
687 """Just after new patient became active."""
688
689 self.reset_ui()
690
691
692
694
695
696 self._define_prompts()
697 self._define_fields(parent = self)
698 if len(self.fields) != len(self.prompts):
699 _log.error('[%s]: #fields != #prompts' % self.__class__.__name__)
700 return None
701
702
703 szr_main_fgrid = wx.FlexGridSizer(rows = len(self.prompts), cols=2)
704 color = richards_aqua
705 lines = self.prompts.keys()
706 lines.sort()
707 for line in lines:
708
709 label, color, weight = self.prompts[line]
710
711 prompt = wx.StaticText (
712 parent = self,
713 id = -1,
714 label = label,
715 style = wx.ALIGN_CENTRE
716 )
717
718 prompt.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
719 prompt.SetForegroundColour(color)
720 prompt.SetBackgroundColour(richards_light_gray)
721 szr_main_fgrid.Add(prompt, flag=wx.EXPAND | wx.ALIGN_RIGHT)
722
723
724 szr_line = wx.BoxSizer(wx.HORIZONTAL)
725 positions = self.fields[line].keys()
726 positions.sort()
727 for pos in positions:
728 field, weight = self.fields[line][pos]
729
730 szr_line.Add(field, weight, wx.EXPAND)
731 szr_main_fgrid.Add(szr_line, flag=wx.GROW | wx.ALIGN_LEFT)
732
733
734 szr_main_fgrid.AddGrowableCol(1)
735
736
737
738
739
740
741
742 self.SetSizerAndFit(szr_main_fgrid)
743
744
745
746
748 """Child classes override this to define their prompts using _add_prompt()"""
749 _log.error('missing override in [%s]' % self.__class__.__name__)
750
752 """Add a new prompt line.
753
754 To be used from _define_fields in child classes.
755
756 - label, the label text
757 - color
758 - weight, the weight given in sizing the various rows. 0 means the row
759 always has minimum size
760 """
761 self.prompts[line] = (label, color, weight)
762
764 """Defines the fields.
765
766 - override in child classes
767 - mostly uses _add_field()
768 """
769 _log.error('missing override in [%s]' % self.__class__.__name__)
770
771 - def _add_field(self, line=None, pos=None, widget=None, weight=0):
772 if None in (line, pos, widget):
773 _log.error('argument error in [%s]: line=%s, pos=%s, widget=%s' % (self.__class__.__name__, line, pos, widget))
774 if not self.fields.has_key(line):
775 self.fields[line] = {}
776 self.fields[line][pos] = (widget, weight)
777
795
796
797
798
800 - def __init__ (self, parent, id = -1, pos = wx.DefaultPosition, size=wx.DefaultSize):
801 wx.TextCtrl.__init__(self,parent,id,"",pos, size ,wx.SIMPLE_BORDER)
802 _decorate_editarea_field(self)
803
805 - def __init__(self, parent, id, pos, size, style):
806
807 print "class [%s] is deprecated, use cEditArea2 instead" % self.__class__.__name__
808
809
810 wx.Panel.__init__(self, parent, id, pos=pos, size=size, style=wx.NO_BORDER | wx.TAB_TRAVERSAL)
811 self.SetBackgroundColour(wx.Colour(222,222,222))
812
813 self.data = None
814 self.fields = {}
815 self.prompts = {}
816
817 ID_BTN_OK = wx.NewId()
818 ID_BTN_CLEAR = wx.NewId()
819
820 self.__do_layout()
821
822
823
824
825
826
827 self._patient = gmPerson.gmCurrentPatient()
828 self.__register_events()
829 self.Show(True)
830
831
832
834
835 self._define_prompts()
836 self.fields_pnl = wx.Panel(self, -1, style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
837 self._define_fields(parent = self.fields_pnl)
838
839 szr_prompts = self.__generate_prompts()
840 szr_fields = self.__generate_fields()
841
842
843 self.szr_main_panels = wx.BoxSizer(wx.HORIZONTAL)
844 self.szr_main_panels.Add(szr_prompts, 11, wx.EXPAND)
845 self.szr_main_panels.Add(5, 0, 0, wx.EXPAND)
846 self.szr_main_panels.Add(szr_fields, 90, wx.EXPAND)
847
848
849
850 self.szr_central_container = wx.BoxSizer(wx.HORIZONTAL)
851 self.szr_central_container.Add(self.szr_main_panels, 1, wx.EXPAND | wx.ALL, 5)
852
853
854 self.SetAutoLayout(True)
855 self.SetSizer(self.szr_central_container)
856 self.szr_central_container.Fit(self)
857
859 if len(self.fields) != len(self.prompts):
860 _log.error('[%s]: #fields != #prompts' % self.__class__.__name__)
861 return None
862
863 prompt_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER)
864 prompt_pnl.SetBackgroundColour(richards_light_gray)
865
866 color = richards_aqua
867 lines = self.prompts.keys()
868 lines.sort()
869 self.prompt_widget = {}
870 for line in lines:
871 label, color, weight = self.prompts[line]
872 self.prompt_widget[line] = self.__make_prompt(prompt_pnl, "%s " % label, color)
873
874 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
875 shadow_below_prompts.SetBackgroundColour(richards_dark_gray)
876 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL)
877 szr_shadow_below_prompts.Add(5, 0, 0, wx.EXPAND)
878 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND)
879
880
881 vszr_prompts = wx.BoxSizer(wx.VERTICAL)
882 vszr_prompts.Add(prompt_pnl, 97, wx.EXPAND)
883 vszr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND)
884
885
886 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
887 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray)
888 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL)
889 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND)
890 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts, 1, wx.EXPAND)
891
892
893 hszr_prompts = wx.BoxSizer(wx.HORIZONTAL)
894 hszr_prompts.Add(vszr_prompts, 10, wx.EXPAND)
895 hszr_prompts.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND)
896
897 return hszr_prompts
898
900 self.fields_pnl.SetBackgroundColour(wx.Colour(222,222,222))
901
902 vszr = wx.BoxSizer(wx.VERTICAL)
903 lines = self.fields.keys()
904 lines.sort()
905 self.field_line_szr = {}
906 for line in lines:
907 self.field_line_szr[line] = wx.BoxSizer(wx.HORIZONTAL)
908 positions = self.fields[line].keys()
909 positions.sort()
910 for pos in positions:
911 field, weight = self.fields[line][pos]
912 self.field_line_szr[line].Add(field, weight, wx.EXPAND)
913 try:
914 vszr.Add(self.field_line_szr[line], self.prompts[line][2], flag = wx.EXPAND)
915 except KeyError:
916 _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) ) )
917
918 self.fields_pnl.SetSizer(vszr)
919 vszr.Fit(self.fields_pnl)
920
921
922 shadow_below_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
923 shadow_below_edit_fields.SetBackgroundColour(richards_coloured_gray)
924 szr_shadow_below_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
925 szr_shadow_below_edit_fields.Add(5, 0, 0, wx.EXPAND)
926 szr_shadow_below_edit_fields.Add(shadow_below_edit_fields, 12, wx.EXPAND)
927
928
929 vszr_edit_fields = wx.BoxSizer(wx.VERTICAL)
930 vszr_edit_fields.Add(self.fields_pnl, 92, wx.EXPAND)
931 vszr_edit_fields.Add(szr_shadow_below_edit_fields, 5, wx.EXPAND)
932
933
934 shadow_rightof_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
935 shadow_rightof_edit_fields.SetBackgroundColour(richards_coloured_gray)
936 szr_shadow_rightof_edit_fields = wx.BoxSizer(wx.VERTICAL)
937 szr_shadow_rightof_edit_fields.Add(0, 5, 0, wx.EXPAND)
938 szr_shadow_rightof_edit_fields.Add(shadow_rightof_edit_fields, 1, wx.EXPAND)
939
940
941 hszr_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
942 hszr_edit_fields.Add(vszr_edit_fields, 89, wx.EXPAND)
943 hszr_edit_fields.Add(szr_shadow_rightof_edit_fields, 1, wx.EXPAND)
944
945 return hszr_edit_fields
946
948
949 prompt = wx.StaticText(
950 parent,
951 -1,
952 aLabel,
953 style = wx.ALIGN_RIGHT
954 )
955 prompt.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
956 prompt.SetForegroundColour(aColor)
957 return prompt
958
959
960
962 """Add a new prompt line.
963
964 To be used from _define_fields in child classes.
965
966 - label, the label text
967 - color
968 - weight, the weight given in sizing the various rows. 0 means the rwo
969 always has minimum size
970 """
971 self.prompts[line] = (label, color, weight)
972
973 - def _add_field(self, line=None, pos=None, widget=None, weight=0):
974 if None in (line, pos, widget):
975 _log.error('argument error in [%s]: line=%s, pos=%s, widget=%s' % (self.__class__.__name__, line, pos, widget))
976 if not self.fields.has_key(line):
977 self.fields[line] = {}
978 self.fields[line][pos] = (widget, weight)
979
981 """Defines the fields.
982
983 - override in child classes
984 - mostly uses _add_field()
985 """
986 _log.error('missing override in [%s]' % self.__class__.__name__)
987
989 _log.error('missing override in [%s]' % self.__class__.__name__)
990
1004
1007
1009 _log.error('[%s] programmer forgot to define _save_data()' % self.__class__.__name__)
1010 _log.info('child classes of cEditArea *must* override this function')
1011 return False
1012
1013
1014
1016
1017 wx.EVT_BUTTON(self.btn_OK, ID_BTN_OK, self._on_OK_btn_pressed)
1018 wx.EVT_BUTTON(self.btn_Clear, ID_BTN_CLEAR, self._on_clear_btn_pressed)
1019
1020 wx.EVT_SIZE (self.fields_pnl, self._on_resize_fields)
1021
1022
1023 gmDispatcher.connect(signal = u'pre_patient_selection', receiver = self._on_pre_patient_selection)
1024 gmDispatcher.connect(signal = u'application_closing', receiver = self._on_application_closing)
1025 gmDispatcher.connect(signal = u'post_patient_selection', receiver = self.on_post_patient_selection)
1026
1027 return 1
1028
1029
1030
1047
1049
1050 self.set_data()
1051 event.Skip()
1052
1053 - def on_post_patient_selection( self, **kwds):
1054
1055 self.set_data()
1056
1058
1059 if not self._patient.connected:
1060 return True
1061 if self._save_data():
1062 return True
1063 _log.error('[%s] lossage' % self.__class__.__name__)
1064 return False
1065
1067
1068 if not self._patient.connected:
1069 return True
1070 if self._save_data():
1071 return True
1072 _log.error('[%s] lossage' % self.__class__.__name__)
1073 return False
1074
1076 self.fields_pnl.Layout()
1077
1078 for i in self.field_line_szr.keys():
1079
1080 pos = self.field_line_szr[i].GetPosition()
1081
1082 self.prompt_widget[i].SetPosition((0, pos.y))
1083
1085 - def __init__(self, parent, id, aType = None):
1086
1087 print "class [%s] is deprecated, use cEditArea2 instead" % self.__class__.__name__
1088
1089
1090 if aType not in _known_edit_area_types:
1091 _log.error('unknown edit area type: [%s]' % aType)
1092 raise gmExceptions.ConstructorError, 'unknown edit area type: [%s]' % aType
1093 self._type = aType
1094
1095
1096 cEditArea.__init__(self, parent, id)
1097
1098 self.input_fields = {}
1099
1100 self._postInit()
1101 self.old_data = {}
1102
1103 self._patient = gmPerson.gmCurrentPatient()
1104 self.Show(True)
1105
1106
1107
1108
1109
1110
1112
1113 prompt_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER)
1114 prompt_pnl.SetBackgroundColour(richards_light_gray)
1115
1116 gszr = wx.FlexGridSizer (len(prompt_labels)+1, 1, 2, 2)
1117 color = richards_aqua
1118 for prompt in prompt_labels:
1119 label = self.__make_prompt(prompt_pnl, "%s " % prompt, color)
1120 gszr.Add(label, 0, wx.EXPAND | wx.ALIGN_RIGHT)
1121 color = richards_blue
1122 gszr.RemoveGrowableRow (line-1)
1123
1124 prompt_pnl.SetSizer(gszr)
1125 gszr.Fit(prompt_pnl)
1126 prompt_pnl.SetAutoLayout(True)
1127
1128
1129 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1130 shadow_below_prompts.SetBackgroundColour(richards_dark_gray)
1131 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL)
1132 szr_shadow_below_prompts.Add(5, 0, 0, wx.EXPAND)
1133 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND)
1134
1135
1136 vszr_prompts = wx.BoxSizer(wx.VERTICAL)
1137 vszr_prompts.Add(prompt_pnl, 97, wx.EXPAND)
1138 vszr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND)
1139
1140
1141 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1142 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray)
1143 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL)
1144 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND)
1145 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts,1,wx.EXPAND)
1146
1147
1148 hszr_prompts = wx.BoxSizer(wx.HORIZONTAL)
1149 hszr_prompts.Add(vszr_prompts, 10, wx.EXPAND)
1150 hszr_prompts.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND)
1151
1152 return hszr_prompts
1153
1155 _log.error('programmer forgot to define edit area lines for [%s]' % self._type)
1156 _log.info('child classes of gmEditArea *must* override this function')
1157 return []
1158
1160
1161 fields_pnl = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
1162 fields_pnl.SetBackgroundColour(wx.Colour(222,222,222))
1163
1164 gszr = wx.GridSizer(len(_prompt_defs[self._type]), 1, 2, 2)
1165
1166
1167 lines = self._make_edit_lines(parent = fields_pnl)
1168
1169 self.lines = lines
1170 if len(lines) != len(_prompt_defs[self._type]):
1171 _log.error('#(edit lines) not equal #(prompts) for [%s], something is fishy' % self._type)
1172 for line in lines:
1173 gszr.Add(line, 0, wx.EXPAND | wx.ALIGN_LEFT)
1174
1175 fields_pnl.SetSizer(gszr)
1176 gszr.Fit(fields_pnl)
1177 fields_pnl.SetAutoLayout(True)
1178
1179
1180 shadow_below_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1181 shadow_below_edit_fields.SetBackgroundColour(richards_coloured_gray)
1182 szr_shadow_below_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
1183 szr_shadow_below_edit_fields.Add(5, 0, 0, wx.EXPAND)
1184 szr_shadow_below_edit_fields.Add(shadow_below_edit_fields, 12, wx.EXPAND)
1185
1186
1187 vszr_edit_fields = wx.BoxSizer(wx.VERTICAL)
1188 vszr_edit_fields.Add(fields_pnl, 92, wx.EXPAND)
1189 vszr_edit_fields.Add(szr_shadow_below_edit_fields, 5, wx.EXPAND)
1190
1191
1192 shadow_rightof_edit_fields = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1193 shadow_rightof_edit_fields.SetBackgroundColour(richards_coloured_gray)
1194 szr_shadow_rightof_edit_fields = wx.BoxSizer(wx.VERTICAL)
1195 szr_shadow_rightof_edit_fields.Add(0, 5, 0, wx.EXPAND)
1196 szr_shadow_rightof_edit_fields.Add(shadow_rightof_edit_fields, 1, wx.EXPAND)
1197
1198
1199 hszr_edit_fields = wx.BoxSizer(wx.HORIZONTAL)
1200 hszr_edit_fields.Add(vszr_edit_fields, 89, wx.EXPAND)
1201 hszr_edit_fields.Add(szr_shadow_rightof_edit_fields, 1, wx.EXPAND)
1202
1203 return hszr_edit_fields
1204
1207
1212
1214 map = {}
1215 for k in self.input_fields.keys():
1216 map[k] = ''
1217 return map
1218
1219
1221 self._default_init_fields()
1222
1223
1224
1225
1226
1228 _log.warning("you may want to override _updateUI for [%s]" % self.__class__.__name__)
1229
1230
1231 - def _postInit(self):
1232 """override for further control setup"""
1233 pass
1234
1235
1237 szr = wx.BoxSizer(wx.HORIZONTAL)
1238 szr.Add( widget, weight, wx.EXPAND)
1239 szr.Add( 0,0, spacerWeight, wx.EXPAND)
1240 return szr
1241
1243
1244 cb = wx.CheckBox( parent, -1, _(title))
1245 cb.SetForegroundColour( richards_blue)
1246 return cb
1247
1248
1249
1251 """this is a utlity method to add extra columns"""
1252
1253 if self.__class__.__dict__.has_key("extraColumns"):
1254 for x in self.__class__.extraColumns:
1255 lines = self._addColumn(parent, lines, x, weightMap)
1256 return lines
1257
1258
1259
1260 - def _addColumn(self, parent, lines, extra, weightMap = {}, existingWeight = 5 , extraWeight = 2):
1261 """
1262 # add ia extra column in the edit area.
1263 # preconditions:
1264 # parent is fields_pnl (weak);
1265 # self.input_fields exists (required);
1266 # ; extra is a list of tuples of format -
1267 # ( key for input_fields, widget label , widget class to instantiate )
1268 """
1269
1270 newlines = []
1271 i = 0
1272 for x in lines:
1273
1274 if weightMap.has_key( x):
1275 (existingWeight, extraWeight) = weightMap[x]
1276
1277 szr = wx.BoxSizer(wx.HORIZONTAL)
1278 szr.Add( x, existingWeight, wx.EXPAND)
1279 if i < len(extra) and extra[i] <> None:
1280
1281 (inputKey, widgetLabel, aclass) = extra[i]
1282 if aclass.__name__ in CONTROLS_WITHOUT_LABELS:
1283 szr.Add( self._make_prompt(parent, widgetLabel, richards_blue) )
1284 widgetLabel = ""
1285
1286
1287 w = aclass( parent, -1, widgetLabel)
1288 if not aclass.__name__ in CONTROLS_WITHOUT_LABELS:
1289 w.SetForegroundColour(richards_blue)
1290
1291 szr.Add(w, extraWeight , wx.EXPAND)
1292
1293
1294 self.input_fields[inputKey] = w
1295
1296 newlines.append(szr)
1297 i += 1
1298 return newlines
1299
1319
1322
1325
1331
1342
1343 -class gmPastHistoryEditArea(gmEditArea):
1344
1345 - def __init__(self, parent, id):
1346 gmEditArea.__init__(self, parent, id, aType = 'past history')
1347
1348 - def _define_prompts(self):
1349 self._add_prompt(line = 1, label = _("When Noted"))
1350 self._add_prompt(line = 2, label = _("Laterality"))
1351 self._add_prompt(line = 3, label = _("Condition"))
1352 self._add_prompt(line = 4, label = _("Notes"))
1353 self._add_prompt(line = 6, label = _("Status"))
1354 self._add_prompt(line = 7, label = _("Progress Note"))
1355 self._add_prompt(line = 8, label = '')
1356
1357 - def _define_fields(self, parent):
1358
1359 self.fld_date_noted = gmDateTimeInput.gmDateInput(
1360 parent = parent,
1361 id = -1,
1362 style = wx.SIMPLE_BORDER
1363 )
1364 self._add_field(
1365 line = 1,
1366 pos = 1,
1367 widget = self.fld_date_noted,
1368 weight = 2
1369 )
1370 self._add_field(
1371 line = 1,
1372 pos = 2,
1373 widget = cPrompt_edit_area(parent,-1, _("Age")),
1374 weight = 0)
1375
1376 self.fld_age_noted = cEditAreaField(parent)
1377 self._add_field(
1378 line = 1,
1379 pos = 3,
1380 widget = self.fld_age_noted,
1381 weight = 2
1382 )
1383
1384
1385 self.fld_laterality_none= wx.RadioButton(parent, -1, _("N/A"))
1386 self.fld_laterality_left= wx.RadioButton(parent, -1, _("L"))
1387 self.fld_laterality_right= wx.RadioButton(parent, -1, _("R"))
1388 self.fld_laterality_both= wx.RadioButton(parent, -1, _("both"))
1389 self._add_field(
1390 line = 2,
1391 pos = 1,
1392 widget = self.fld_laterality_none,
1393 weight = 0
1394 )
1395 self._add_field(
1396 line = 2,
1397 pos = 2,
1398 widget = self.fld_laterality_left,
1399 weight = 0
1400 )
1401 self._add_field(
1402 line = 2,
1403 pos = 3,
1404 widget = self.fld_laterality_right,
1405 weight = 1
1406 )
1407 self._add_field(
1408 line = 2,
1409 pos = 4,
1410 widget = self.fld_laterality_both,
1411 weight = 1
1412 )
1413
1414 self.fld_condition= cEditAreaField(parent)
1415 self._add_field(
1416 line = 3,
1417 pos = 1,
1418 widget = self.fld_condition,
1419 weight = 6
1420 )
1421
1422 self.fld_notes= cEditAreaField(parent)
1423 self._add_field(
1424 line = 4,
1425 pos = 1,
1426 widget = self.fld_notes,
1427 weight = 6
1428 )
1429
1430 self.fld_significant= wx.CheckBox(
1431 parent,
1432 -1,
1433 _("significant"),
1434 style = wx.NO_BORDER
1435 )
1436 self.fld_active= wx.CheckBox(
1437 parent,
1438 -1,
1439 _("active"),
1440 style = wx.NO_BORDER
1441 )
1442
1443 self._add_field(
1444 line = 5,
1445 pos = 1,
1446 widget = self.fld_significant,
1447 weight = 0
1448 )
1449 self._add_field(
1450 line = 5,
1451 pos = 2,
1452 widget = self.fld_active,
1453 weight = 0
1454 )
1455
1456 self.fld_progress= cEditAreaField(parent)
1457 self._add_field(
1458 line = 6,
1459 pos = 1,
1460 widget = self.fld_progress,
1461 weight = 6
1462 )
1463
1464
1465 self._add_field(
1466 line = 7,
1467 pos = 4,
1468 widget = self._make_standard_buttons(parent),
1469 weight = 2
1470 )
1471
1472 - def _postInit(self):
1473 return
1474
1475 wx.EVT_KILL_FOCUS( self.fld_age_noted, self._ageKillFocus)
1476 wx.EVT_KILL_FOCUS( self.fld_date_noted, self._yearKillFocus)
1477
1478 - def _ageKillFocus( self, event):
1479
1480 event.Skip()
1481 try :
1482 year = self._getBirthYear() + int(self.fld_age_noted.GetValue().strip() )
1483 self.fld_date_noted.SetValue( str (year) )
1484 except:
1485 pass
1486
1487 - def _getBirthYear(self):
1488 try:
1489 birthyear = int(str(self._patient['dob']).split('-')[0])
1490 except:
1491
1492 birthyear = 1
1493
1494 return birthyear
1495
1496 - def _yearKillFocus( self, event):
1497 event.Skip()
1498 try:
1499 age = int(self.fld_date_noted.GetValue().strip() ) - self._getBirthYear()
1500 self.fld_age_noted.SetValue( str (age) )
1501 except:
1502 pass
1503
1504 __init_values = {
1505 "condition": "",
1506 "notes1": "",
1507 "notes2": "",
1508 "age": "",
1509
1510 "progress": "",
1511 "active": 1,
1512 "operation": 0,
1513 "confidential": 0,
1514 "significant": 1,
1515 "both": 0,
1516 "left": 0,
1517 "right": 0,
1518 "none" : 1
1519 }
1520
1521 - def _getDefaultAge(self):
1522 try:
1523
1524 return 1
1525 except:
1526 return 0
1527
1528 - def _get_init_values(self):
1529 values = gmPastHistoryEditArea.__init_values
1530 values["age"] = str( self._getDefaultAge())
1531 return values
1532
1533 - def _save_data(self):
1534 clinical = self._patient.get_emr().get_past_history()
1535 if self.getDataId() is None:
1536 id = clinical.create_history( self.get_fields_formatting_values() )
1537 self.setDataId(id)
1538 return
1539
1540 clinical.update_history( self.get_fields_formatting_values(), self.getDataId() )
1541
1542
1552
1554 self._add_prompt (line = 1, label = _ ("Specialty"))
1555 self._add_prompt (line = 2, label = _ ("Name"))
1556 self._add_prompt (line = 3, label = _ ("Address"))
1557 self._add_prompt (line = 4, label = _ ("Options"))
1558 self._add_prompt (line = 5, label = _("Text"), weight =6)
1559 self._add_prompt (line = 6, label = "")
1560
1562 self.fld_specialty = gmPhraseWheel.cPhraseWheel (
1563 parent = parent,
1564 id = -1,
1565 style = wx.SIMPLE_BORDER
1566 )
1567
1568 self._add_field (
1569 line = 1,
1570 pos = 1,
1571 widget = self.fld_specialty,
1572 weight = 1
1573 )
1574 self.fld_name = gmPhraseWheel.cPhraseWheel (
1575 parent = parent,
1576 id = -1,
1577 style = wx.SIMPLE_BORDER
1578 )
1579
1580 self._add_field (
1581 line = 2,
1582 pos = 1,
1583 widget = self.fld_name,
1584 weight = 1
1585 )
1586 self.fld_address = wx.ComboBox (parent, -1, style = wx.CB_READONLY)
1587
1588 self._add_field (
1589 line = 3,
1590 pos = 1,
1591 widget = self.fld_address,
1592 weight = 1
1593 )
1594
1595
1596 self.fld_name.add_callback_on_selection(self.setAddresses)
1597
1598 self.fld_med = wx.CheckBox (parent, -1, _("Meds"), style=wx.NO_BORDER)
1599 self._add_field (
1600 line = 4,
1601 pos = 1,
1602 widget = self.fld_med,
1603 weight = 1
1604 )
1605 self.fld_past = wx.CheckBox (parent, -1, _("Past Hx"), style=wx.NO_BORDER)
1606 self._add_field (
1607 line = 4,
1608 pos = 4,
1609 widget = self.fld_past,
1610 weight = 1
1611 )
1612 self.fld_text = wx.TextCtrl (parent, -1, style= wx.TE_MULTILINE)
1613 self._add_field (
1614 line = 5,
1615 pos = 1,
1616 widget = self.fld_text,
1617 weight = 1)
1618
1619 self._add_field(
1620 line = 6,
1621 pos = 1,
1622 widget = self._make_standard_buttons(parent),
1623 weight = 1
1624 )
1625 return 1
1626
1628 """
1629 Doesn't accept any value as this doesn't make sense for this edit area
1630 """
1631 self.fld_specialty.SetValue ('')
1632 self.fld_name.SetValue ('')
1633 self.fld_address.Clear ()
1634 self.fld_address.SetValue ('')
1635 self.fld_med.SetValue (0)
1636 self.fld_past.SetValue (0)
1637 self.fld_text.SetValue ('')
1638 self.recipient = None
1639
1641 """
1642 Set the available addresses for the selected identity
1643 """
1644 if id is None:
1645 self.recipient = None
1646 self.fld_address.Clear ()
1647 self.fld_address.SetValue ('')
1648 else:
1649 self.recipient = gmDemographicRecord.cDemographicRecord_SQL (id)
1650 self.fld_address.Clear ()
1651 self.addr = self.recipient.getAddresses ('work')
1652 for i in self.addr:
1653 self.fld_address.Append (_("%(number)s %(street)s, %(urb)s %(postcode)s") % i, ('post', i))
1654 fax = self.recipient.getCommChannel (gmDemographicRecord.FAX)
1655 email = self.recipient.getCommChannel (gmDemographicRecord.EMAIL)
1656 if fax:
1657 self.fld_address.Append ("%s: %s" % (_("FAX"), fax), ('fax', fax))
1658 if email:
1659 self.fld_address.Append ("%s: %s" % (_("E-MAIL"), email), ('email', email))
1660
1661 - def _save_new_entry(self):
1662 """
1663 We are always saving a "new entry" here because data_ID is always None
1664 """
1665 if not self.recipient:
1666 raise gmExceptions.InvalidInputError(_('must have a recipient'))
1667 if self.fld_address.GetSelection() == -1:
1668 raise gmExceptions.InvalidInputError(_('must select address'))
1669 channel, addr = self.fld_address.GetClientData (self.fld_address.GetSelection())
1670 text = self.fld_text.GetValue()
1671 flags = {}
1672 flags['meds'] = self.fld_med.GetValue()
1673 flags['pasthx'] = self.fld_past.GetValue()
1674 if not gmReferral.create_referral (self._patient, self.recipient, channel, addr, text, flags):
1675 raise gmExceptions.InvalidInputError('error sending form')
1676
1677
1678
1679
1680
1688
1689
1690
1692 _log.debug("making prescription lines")
1693 lines = []
1694 self.txt_problem = cEditAreaField(parent)
1695 self.txt_class = cEditAreaField(parent)
1696 self.txt_generic = cEditAreaField(parent)
1697 self.txt_brand = cEditAreaField(parent)
1698 self.txt_strength= cEditAreaField(parent)
1699 self.txt_directions= cEditAreaField(parent)
1700 self.txt_for = cEditAreaField(parent)
1701 self.txt_progress = cEditAreaField(parent)
1702
1703 lines.append(self.txt_problem)
1704 lines.append(self.txt_class)
1705 lines.append(self.txt_generic)
1706 lines.append(self.txt_brand)
1707 lines.append(self.txt_strength)
1708 lines.append(self.txt_directions)
1709 lines.append(self.txt_for)
1710 lines.append(self.txt_progress)
1711 lines.append(self._make_standard_buttons(parent))
1712 self.input_fields = {
1713 "problem": self.txt_problem,
1714 "class" : self.txt_class,
1715 "generic" : self.txt_generic,
1716 "brand" : self.txt_brand,
1717 "strength": self.txt_strength,
1718 "directions": self.txt_directions,
1719 "for" : self.txt_for,
1720 "progress": self.txt_progress
1721
1722 }
1723
1724 return self._makeExtraColumns( parent, lines)
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1743
1744
1745
1746
1747
1748
1751 wx.StaticText.__init__(self, parent, id, prompt, wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_LEFT)
1752 self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False, ''))
1753 self.SetForegroundColour(aColor)
1754
1755
1756
1757
1758
1760 - def __init__(self, parent, id, prompt_labels):
1761 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, wx.SIMPLE_BORDER)
1762 self.SetBackgroundColour(richards_light_gray)
1763 gszr = wx.GridSizer (len(prompt_labels)+1, 1, 2, 2)
1764 color = richards_aqua
1765 for prompt_key in prompt_labels.keys():
1766 label = cPrompt_edit_area(self, -1, " %s" % prompt_labels[prompt_key], aColor = color)
1767 gszr.Add(label, 0, wx.EXPAND | wx.ALIGN_RIGHT)
1768 color = richards_blue
1769 self.SetSizer(gszr)
1770 gszr.Fit(self)
1771 self.SetAutoLayout(True)
1772
1773
1774
1775
1776
1777
1778
1779 -class EditTextBoxes(wx.Panel):
1780 - def __init__(self, parent, id, editareaprompts, section):
1781 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize,style = wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
1782 self.SetBackgroundColour(wx.Colour(222,222,222))
1783 self.parent = parent
1784
1785 self.gszr = wx.GridSizer(len(editareaprompts), 1, 2, 2)
1786
1787 if section == gmSECTION_SUMMARY:
1788 pass
1789 elif section == gmSECTION_DEMOGRAPHICS:
1790 pass
1791 elif section == gmSECTION_CLINICALNOTES:
1792 pass
1793 elif section == gmSECTION_FAMILYHISTORY:
1794 pass
1795 elif section == gmSECTION_PASTHISTORY:
1796 pass
1797
1798
1799 self.txt_condition = cEditAreaField(self,PHX_CONDITION,wx.DefaultPosition,wx.DefaultSize)
1800 self.rb_sideleft = wxRadioButton(self,PHX_LEFT, _(" (L) "), wx.DefaultPosition,wx.DefaultSize)
1801 self.rb_sideright = wxRadioButton(self, PHX_RIGHT, _("(R)"), wx.DefaultPosition,wx.DefaultSize,wx.SUNKEN_BORDER)
1802 self.rb_sideboth = wxRadioButton(self, PHX_BOTH, _("Both"), wx.DefaultPosition,wx.DefaultSize)
1803 rbsizer = wx.BoxSizer(wx.HORIZONTAL)
1804 rbsizer.Add(self.rb_sideleft,1,wx.EXPAND)
1805 rbsizer.Add(self.rb_sideright,1,wx.EXPAND)
1806 rbsizer.Add(self.rb_sideboth,1,wx.EXPAND)
1807 szr1 = wx.BoxSizer(wx.HORIZONTAL)
1808 szr1.Add(self.txt_condition, 4, wx.EXPAND)
1809 szr1.Add(rbsizer, 3, wx.EXPAND)
1810
1811
1812
1813
1814 self.txt_notes1 = cEditAreaField(self,PHX_NOTES,wx.DefaultPosition,wx.DefaultSize)
1815
1816 self.txt_notes2= cEditAreaField(self,PHX_NOTES2,wx.DefaultPosition,wx.DefaultSize)
1817
1818 self.txt_agenoted = cEditAreaField(self, PHX_AGE, wx.DefaultPosition, wx.DefaultSize)
1819 szr4 = wx.BoxSizer(wx.HORIZONTAL)
1820 szr4.Add(self.txt_agenoted, 1, wx.EXPAND)
1821 szr4.Add(5, 0, 5)
1822
1823 self.txt_yearnoted = cEditAreaField(self,PHX_YEAR,wx.DefaultPosition,wx.DefaultSize)
1824 szr5 = wx.BoxSizer(wx.HORIZONTAL)
1825 szr5.Add(self.txt_yearnoted, 1, wx.EXPAND)
1826 szr5.Add(5, 0, 5)
1827
1828 self.parent.cb_active = wx.CheckBox(self, PHX_ACTIVE, _("Active"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1829 self.parent.cb_operation = wx.CheckBox(self, PHX_OPERATION, _("Operation"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1830 self.parent.cb_confidential = wx.CheckBox(self, PHX_CONFIDENTIAL , _("Confidential"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1831 self.parent.cb_significant = wx.CheckBox(self, PHX_SIGNIFICANT, _("Significant"), wx.DefaultPosition,wx.DefaultSize, wx.NO_BORDER)
1832 szr6 = wx.BoxSizer(wx.HORIZONTAL)
1833 szr6.Add(self.parent.cb_active, 1, wx.EXPAND)
1834 szr6.Add(self.parent.cb_operation, 1, wx.EXPAND)
1835 szr6.Add(self.parent.cb_confidential, 1, wx.EXPAND)
1836 szr6.Add(self.parent.cb_significant, 1, wx.EXPAND)
1837
1838 self.txt_progressnotes = cEditAreaField(self,PHX_PROGRESSNOTES ,wx.DefaultPosition,wx.DefaultSize)
1839
1840 szr8 = wx.BoxSizer(wx.HORIZONTAL)
1841 szr8.Add(5, 0, 6)
1842 szr8.Add(self._make_standard_buttons(), 0, wx.EXPAND)
1843
1844 self.gszr.Add(szr1,0,wx.EXPAND)
1845 self.gszr.Add(self.txt_notes1,0,wx.EXPAND)
1846 self.gszr.Add(self.txt_notes2,0,wx.EXPAND)
1847 self.gszr.Add(szr4,0,wx.EXPAND)
1848 self.gszr.Add(szr5,0,wx.EXPAND)
1849 self.gszr.Add(szr6,0,wx.EXPAND)
1850 self.gszr.Add(self.txt_progressnotes,0,wx.EXPAND)
1851 self.gszr.Add(szr8,0,wx.EXPAND)
1852
1853
1854 elif section == gmSECTION_SCRIPT:
1855 pass
1856 elif section == gmSECTION_REQUESTS:
1857 pass
1858 elif section == gmSECTION_RECALLS:
1859 pass
1860 else:
1861 pass
1862
1863 self.SetSizer(self.gszr)
1864 self.gszr.Fit(self)
1865
1866 self.SetAutoLayout(True)
1867 self.Show(True)
1868
1870 self.btn_OK = wx.Button(self, -1, _("Ok"))
1871 self.btn_Clear = wx.Button(self, -1, _("Clear"))
1872 szr_buttons = wx.BoxSizer(wx.HORIZONTAL)
1873 szr_buttons.Add(self.btn_OK, 1, wx.EXPAND, wx.ALL, 1)
1874 szr_buttons.Add(5, 0, 0)
1875 szr_buttons.Add(self.btn_Clear, 1, wx.EXPAND, wx.ALL, 1)
1876 return szr_buttons
1877
1879 - def __init__(self, parent, id, line_labels, section):
1880 _log.warning('***** old style EditArea instantiated, please convert *****')
1881
1882 wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize, style = wx.NO_BORDER)
1883 self.SetBackgroundColour(wx.Colour(222,222,222))
1884
1885
1886 prompts = gmPnlEditAreaPrompts(self, -1, line_labels)
1887
1888 shadow_below_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1889
1890 shadow_below_prompts.SetBackgroundColour(richards_dark_gray)
1891 szr_shadow_below_prompts = wx.BoxSizer (wx.HORIZONTAL)
1892 szr_shadow_below_prompts.Add(5,0,0,wx.EXPAND)
1893 szr_shadow_below_prompts.Add(shadow_below_prompts, 10, wx.EXPAND)
1894
1895 szr_prompts = wx.BoxSizer(wx.VERTICAL)
1896 szr_prompts.Add(prompts, 97, wx.EXPAND)
1897 szr_prompts.Add(szr_shadow_below_prompts, 5, wx.EXPAND)
1898
1899
1900 edit_fields = EditTextBoxes(self, -1, line_labels, section)
1901
1902 shadow_below_editarea = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1903
1904 shadow_below_editarea.SetBackgroundColour(richards_coloured_gray)
1905 szr_shadow_below_editarea = wx.BoxSizer(wx.HORIZONTAL)
1906 szr_shadow_below_editarea.Add(5,0,0,wx.EXPAND)
1907 szr_shadow_below_editarea.Add(shadow_below_editarea, 12, wx.EXPAND)
1908
1909 szr_editarea = wx.BoxSizer(wx.VERTICAL)
1910 szr_editarea.Add(edit_fields, 92, wx.EXPAND)
1911 szr_editarea.Add(szr_shadow_below_editarea, 5, wx.EXPAND)
1912
1913
1914
1915 shadow_rightof_prompts = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1916 shadow_rightof_prompts.SetBackgroundColour(richards_dark_gray)
1917 szr_shadow_rightof_prompts = wx.BoxSizer(wx.VERTICAL)
1918 szr_shadow_rightof_prompts.Add(0,5,0,wx.EXPAND)
1919 szr_shadow_rightof_prompts.Add(shadow_rightof_prompts,1,wx.EXPAND)
1920
1921 shadow_rightof_editarea = wxWindow(self, -1, wx.DefaultPosition, wx.DefaultSize, 0)
1922 shadow_rightof_editarea.SetBackgroundColour(richards_coloured_gray)
1923 szr_shadow_rightof_editarea = wx.BoxSizer(wx.VERTICAL)
1924 szr_shadow_rightof_editarea.Add(0, 5, 0, wx.EXPAND)
1925 szr_shadow_rightof_editarea.Add(shadow_rightof_editarea, 1, wx.EXPAND)
1926
1927
1928 self.szr_main_panels = wx.BoxSizer(wx.HORIZONTAL)
1929 self.szr_main_panels.Add(szr_prompts, 10, wx.EXPAND)
1930 self.szr_main_panels.Add(szr_shadow_rightof_prompts, 1, wx.EXPAND)
1931 self.szr_main_panels.Add(5, 0, 0, wx.EXPAND)
1932 self.szr_main_panels.Add(szr_editarea, 89, wx.EXPAND)
1933 self.szr_main_panels.Add(szr_shadow_rightof_editarea, 1, wx.EXPAND)
1934
1935
1936
1937 self.szr_central_container = wx.BoxSizer(wx.HORIZONTAL)
1938 self.szr_central_container.Add(self.szr_main_panels, 1, wx.EXPAND | wx.ALL, 5)
1939 self.SetSizer(self.szr_central_container)
1940 self.szr_central_container.Fit(self)
1941 self.SetAutoLayout(True)
1942 self.Show(True)
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219 if __name__ == "__main__":
2220
2221
2226 self._add_prompt(line=1, label='line 1')
2227 self._add_prompt(line=2, label='buttons')
2229
2230 self.fld_substance = cEditAreaField(parent)
2231 self._add_field(
2232 line = 1,
2233 pos = 1,
2234 widget = self.fld_substance,
2235 weight = 1
2236 )
2237
2238 self._add_field(
2239 line = 2,
2240 pos = 1,
2241 widget = self._make_standard_buttons(parent),
2242 weight = 1
2243 )
2244
2245 app = wxPyWidgetTester(size = (400, 200))
2246 app.SetWidget(cTestEditArea)
2247 app.MainLoop()
2248
2249
2250
2251
2252
2253
2254
2255