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
8 import sys, logging
9
10
11 import wx
12
13
14
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
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
35
36
37 def calculate_tooltip(adr):
38 return u'\n'.join(adr.format())
39
40 addresses = person.get_addresses()
41 if len(addresses) == 0:
42 return None
43
44 msg = _(
45 'There is no [%s] address registered with this patient.\n\n'
46 'Please select the address you would like to use instead:'
47 ) % missing
48 choices = [
49 [
50 a['l10n_address_type'],
51 u'%s %s%s, %s %s, %s' % (
52 a['street'],
53 a['number'],
54 gmTools.coalesce(a['subunit'], u'', u'/%s'),
55 a['postcode'],
56 a['urb'],
57 a['l10n_country']
58 )
59 ]
60 for a in addresses ]
61
62 return gmListWidgets.get_choices_from_list (
63 msg = msg,
64 caption = _('Selecting address by type'),
65 columns = [_('Type'), _('Address')],
66 choices = choices,
67 data = addresses,
68 single_selection = True,
69 list_tooltip_callback = calculate_tooltip
70 )
71
73 """A list for managing a person's addresses.
74
75 Does NOT act on/listen to the current patient.
76 """
94
95
96
97 - def refresh(self, *args, **kwargs):
98 if self.__identity is None:
99 self._LCTRL_items.set_string_items()
100 return
101
102 adrs = self.__identity.get_addresses()
103 self._LCTRL_items.set_string_items (
104 items = [ [
105 a['l10n_address_type'],
106 a['street'],
107 gmTools.coalesce(a['notes_street'], u''),
108 a['number'],
109 gmTools.coalesce(a['subunit'], u''),
110 a['postcode'],
111 a['urb'],
112 gmTools.coalesce(a['suburb'], u''),
113 a['l10n_state'],
114 a['l10n_country'],
115 gmTools.coalesce(a['notes_subunit'], u'')
116 ] for a in adrs
117 ]
118 )
119 self._LCTRL_items.set_column_widths()
120 self._LCTRL_items.set_data(data = adrs)
121
122
123
125 self.__static_tooltip_part = _('List of addresses related to this person.')
126 self._LCTRL_items.item_tooltip_callback = self._calculate_tooltip
127 self._LCTRL_items.set_columns(columns = [
128 _('Type'),
129 _('Street'),
130 _('Street info'),
131 _('Number'),
132 _('Subunit'),
133 _('Postal code'),
134 _('Community'),
135 _('Suburb'),
136 _('Region'),
137 _('Country'),
138 _('Comment')
139 ])
140
149
162
164 go_ahead = gmGuiHelpers.gm_show_question (
165 _( 'Are you sure you want to remove this\n'
166 "address from the patient's addresses ?\n"
167 '\n'
168 'The address itself will not be deleted\n'
169 'but it will no longer be associated with\n'
170 'this patient.'
171 ),
172 _('Removing address')
173 )
174 if not go_ahead:
175 return False
176 self.__identity.unlink_address(address = address)
177 return True
178
185
186
187
189 return self.__identity
190
194
195 identity = property(_get_identity, _set_identity)
196
197
198 from Gnumed.wxGladeWidgets import wxgPersonContactsManagerPnl
199
232
233
234 if __name__ == "__main__":
235
236 if len(sys.argv) < 2:
237 sys.exit()
238
239 if sys.argv[1] != 'test':
240 sys.exit()
241
242 from Gnumed.pycommon import gmI18N, gmPG2
243
244 gmI18N.activate_locale()
245 gmI18N.install_domain(domain='gnumed')
246 gmPG2.get_connection()
247
248
250 app = wx.PyWidgetTester(size = (600, 400))
251 widget = cPersonAddressesManagerPnl(app.frame, -1)
252 widget.identity = activate_patient()
253 app.frame.Show(True)
254 app.MainLoop()
255
262
263
264
265
266
267