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