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