Gnumed.wxpython.gmPersonContactWidgets

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

# Source Code for Module Gnumed.wxpython.gmPersonContactWidgets

      1  """Widgets dealing with address/contact information."""
      2  #============================================================
      3  __author__ = "R.Terry, SJ Tan, I Haywood, Carlos Moro <cfmoro1976@yahoo.es>"
      4  __license__ = 'GPL v2 or later (details at http://www.gnu.org)'
      5
      6  # standard library
      7  import sys, logging
      8
      9
     10  import wx
     11
     12
     13  # GNUmed specific
     14  if __name__ == '__main__':
     15          sys.path.insert(0, '../../')
     16  from Gnumed.pycommon import gmTools
     17  from Gnumed.wxpython import gmGuiHelpers
     18  from Gnumed.wxpython import gmListWidgets
     19  from Gnumed.wxpython import gmEditArea
     20  from Gnumed.wxpython import gmAddressWidgets
     21
     22
     23  # constant defs
     24  _log = logging.getLogger('gm.ui')
     25
     26
     27  try:
     28          _('dummy-no-need-to-translate-but-make-epydoc-happy')
     29  except NameError:
     30          _ = lambda x:x
     31
     32  #============================================================
     33 -def select_address(missing=None, person=None):
     34
     35          #--------------------------
     36          def calculate_tooltip(adr):
     37                  return u'\n'.join(adr.format())
     38          #--------------------------
     39          addresses = person.get_addresses()
     40          if len(addresses) == 0:
     41                  return None
     42
     43          msg = _(
     44                  'There is no [%s] address registered with this patient.\n\n'
     45                  'Please select the address you would like to use instead:'
     46          ) % missing
     47          choices = [
     48                  [
     49                          a['l10n_address_type'],
     50                          u'%s %s%s, %s %s, %s' % (
     51                                  a['street'],
     52                                  a['number'],
     53                                  gmTools.coalesce(a['subunit'], u'', u'/%s'),
     54                                  a['postcode'],
     55                                  a['urb'],
     56                                  a['l10n_country']
     57                          )
     58                  ]
     59          for a in addresses ]
     60
     61          return gmListWidgets.get_choices_from_list (
     62                  msg = msg,
     63                  caption = _('Selecting address by type'),
     64                  columns = [_('Type'), _('Address')],
     65                  choices = choices,
     66                  data = addresses,
     67                  single_selection = True,
     68                  list_tooltip_callback = calculate_tooltip
     69          )
     70  #============================================================
     71 -class cPersonAddressesManagerPnl(gmListWidgets.cGenericListManagerPnl):
     72          """A list for managing a person's addresses.
     73
     74          Does NOT act on/listen to the current patient.
     75          """
     76 -        def __init__(self, *args, **kwargs):
     77
     78                  try:
     79                          self.__identity = kwargs['identity']
     80                          del kwargs['identity']
     81                  except KeyError:
     82                          self.__identity = None
     83
     84                  gmListWidgets.cGenericListManagerPnl.__init__(self, *args, **kwargs)
     85
     86                  self.new_callback = self._add_address
     87                  self.edit_callback = self._edit_address
     88                  self.delete_callback = self._del_address
     89                  self.refresh_callback = self.refresh
     90
     91                  self.__init_ui()
     92                  self.refresh()
     93          #--------------------------------------------------------
     94          # external API
     95          #--------------------------------------------------------
     96 -        def refresh(self, *args, **kwargs):
     97                  if self.__identity is None:
     98                          self._LCTRL_items.set_string_items()
     99                          return
    100
    101                  adrs = self.__identity.get_addresses()
    102                  self._LCTRL_items.set_string_items (
    103                          items = [ [
    104                                          a['l10n_address_type'],
    105                                          a['street'],
    106                                          gmTools.coalesce(a['notes_street'], u''),
    107                                          a['number'],
    108                                          gmTools.coalesce(a['subunit'], u''),
    109                                          a['postcode'],
    110                                          a['urb'],
    111                                          gmTools.coalesce(a['suburb'], u''),
    112                                          a['l10n_state'],
    113                                          a['l10n_country'],
    114                                          gmTools.coalesce(a['notes_subunit'], u'')
    115                                  ] for a in adrs
    116                          ]
    117                  )
    118                  self._LCTRL_items.set_column_widths()
    119                  self._LCTRL_items.set_data(data = adrs)
    120          #--------------------------------------------------------
    121          # internal helpers
    122          #--------------------------------------------------------
    123 -        def __init_ui(self):
    124                  self.__static_tooltip_part = _('List of addresses related to this person.')
    125                  self._LCTRL_items.item_tooltip_callback = self._calculate_tooltip
    126                  self._LCTRL_items.set_columns(columns = [
    127                          _('Type'),
    128                          _('Street'),
    129                          _('Street info'),
    130                          _('Number'),
    131                          _('Subunit'),
    132                          _('Postal code'),
    133                          _('Community'),
    134                          _('Suburb'),
    135                          _('Region'),
    136                          _('Country'),
    137                          _('Comment')
    138                  ])
    139          #--------------------------------------------------------
    140 -        def _add_address(self):
    141                  ea = gmAddressWidgets.cAddressEAPnl(self, -1)
    142                  ea.address_holder = self.__identity
    143                  dlg = gmEditArea.cGenericEditAreaDlg2(self, -1, edit_area = ea)
    144                  dlg.SetTitle(_('Adding new address'))
    145                  if dlg.ShowModal() == wx.ID_OK:
    146                          return True
    147                  return False
    148          #--------------------------------------------------------
    149 -        def _edit_address(self, address):
    150                  ea = gmAddressWidgets.cAddressEAPnl(self, -1, address = address)
    151                  ea.address_holder = self.__identity
    152                  dlg = gmEditArea.cGenericEditAreaDlg2(self, -1, edit_area = ea)
    153                  dlg.SetTitle(_('Editing address'))
    154                  if dlg.ShowModal() == wx.ID_OK:
    155                          # did we add an entirely new address ?
    156                          # if so then unlink the old one as implied by "edit"
    157                          if ea.address['pk_address'] != address['pk_address']:
    158                                  self.__identity.unlink_address(address = address)
    159                          return True
    160                  return False
    161          #--------------------------------------------------------
    162 -        def _del_address(self, address):
    163                  go_ahead = gmGuiHelpers.gm_show_question (
    164                          _(      'Are you sure you want to remove this\n'
    165                                  "address from the patient's addresses ?\n"
    166                                  '\n'
    167                                  'The address itself will not be deleted\n'
    168                                  'but it will no longer be associated with\n'
    169                                  'this patient.'
    170                          ),
    171                          _('Removing address')
    172                  )
    173                  if not go_ahead:
    174                          return False
    175                  self.__identity.unlink_address(address = address)
    176                  return True
    177          #--------------------------------------------------------
    178 -        def _calculate_tooltip(self, address):
    179                  tt = u'\n'.join(address.format())
    180                  tt += u'\n'
    181                  tt += u'%s\n' % (gmTools.u_box_horiz_single * 40)
    182                  tt += self.__static_tooltip_part
    183                  return tt
    184          #--------------------------------------------------------
    185          # properties
    186          #--------------------------------------------------------
    187 -        def _get_identity(self):
    188                  return self.__identity
    189
    190 -        def _set_identity(self, identity):
    191                  self.__identity = identity
    192                  self.refresh()
    193
    194          identity = property(_get_identity, _set_identity)
    195
    196  #------------------------------------------------------------
    197  from Gnumed.wxGladeWidgets import wxgPersonContactsManagerPnl
    198
    199 -class cPersonContactsManagerPnl(wxgPersonContactsManagerPnl.wxgPersonContactsManagerPnl):
    200          """A panel for editing contact data for a person.
    201
    202          - provides access to:
    203            - addresses
    204            - communication paths
    205
    206          Does NOT act on/listen to the current patient.
    207          """
    208 -        def __init__(self, *args, **kwargs):
    209
    210                  wxgPersonContactsManagerPnl.wxgPersonContactsManagerPnl.__init__(self, *args, **kwargs)
    211
    212                  self.__identity = None
    213                  self.refresh()
    214          #--------------------------------------------------------
    215          # external API
    216          #--------------------------------------------------------
    217 -        def refresh(self):
    218                  self._PNL_addresses.identity = self.__identity
    219                  self._PNL_comms.channel_owner = self.__identity
    220          #--------------------------------------------------------
    221          # properties
    222          #--------------------------------------------------------
    223 -        def _get_identity(self):
    224                  return self.__identity
    225
    226 -        def _set_identity(self, identity):
    227                  self.__identity = identity
    228                  self.refresh()
    229
    230          identity = property(_get_identity, _set_identity)
    231
    232  #============================================================
    233  if __name__ == "__main__":
    234
    235          if len(sys.argv) < 2:
    236                  sys.exit()
    237
    238          if sys.argv[1] != 'test':
    239                  sys.exit()
    240
    241          from Gnumed.pycommon import gmI18N, gmPG2
    242
    243          gmI18N.activate_locale()
    244          gmI18N.install_domain(domain='gnumed')
    245          gmPG2.get_connection()
    246
    247          #--------------------------------------------------------
    248 -        def test_person_adrs_pnl():
    249                  app = wx.PyWidgetTester(size = (600, 400))
    250                  widget = cPersonAddressesManagerPnl(app.frame, -1)
    251                  widget.identity = activate_patient()
    252                  app.frame.Show(True)
    253                  app.MainLoop()
    254          #--------------------------------------------------------
    255 -        def test_pat_contacts_pnl():
    256                  app = wx.PyWidgetTester(size = (600, 400))
    257                  widget = cPersonContactsManagerPnl(app.frame, -1)
    258                  widget.identity = activate_patient()
    259                  app.frame.Show(True)
    260                  app.MainLoop()
    261          #--------------------------------------------------------
    262          #test_pat_contacts_pnl()
    263          #test_person_adrs_pnl()
    264
    265  #============================================================
    266