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
7 import sys
8 import 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.pycommon import gmNetworkTools
19
20 from Gnumed.business import gmPraxis
21
22 from Gnumed.wxpython import gmGuiHelpers
23 from Gnumed.wxpython import gmListWidgets
24 from Gnumed.wxpython import gmEditArea
25 from Gnumed.wxpython import gmAddressWidgets
26
27
28
29 _log = logging.getLogger('gm.ui')
30
31
32 try:
33 _('dummy-no-need-to-translate-but-make-epydoc-happy')
34 except NameError:
35 _ = lambda x:x
36
37
39
40
41 def calculate_tooltip(adr):
42 return '\n'.join(adr.format())
43
44 addresses = person.get_addresses()
45 if len(addresses) == 0:
46 return None
47
48 msg = _(
49 'There is no [%s] address registered with this patient.\n\n'
50 'Please select the address you would like to use instead:'
51 ) % missing
52 choices = [
53 [
54 a['l10n_address_type'],
55 '%s %s%s, %s %s, %s' % (
56 a['street'],
57 a['number'],
58 gmTools.coalesce(a['subunit'], '', '/%s'),
59 a['postcode'],
60 a['urb'],
61 a['l10n_country']
62 )
63 ]
64 for a in addresses ]
65
66 return gmListWidgets.get_choices_from_list (
67 msg = msg,
68 caption = _('Selecting address by type'),
69 columns = [_('Type'), _('Address')],
70 choices = choices,
71 data = addresses,
72 single_selection = True,
73 list_tooltip_callback = calculate_tooltip
74 )
75
76
78 """A list for managing a person's addresses.
79
80 Does NOT act on/listen to the current patient.
81 """
99
100
101
102 - def refresh(self, *args, **kwargs):
103 if self.__identity is None:
104 self._LCTRL_items.set_string_items()
105 return
106
107 adrs = self.__identity.get_addresses()
108 self._LCTRL_items.set_string_items (
109 items = [ [
110 a['l10n_address_type'],
111 a['street'],
112 gmTools.coalesce(a['notes_street'], ''),
113 a['number'],
114 gmTools.coalesce(a['subunit'], ''),
115 a['postcode'],
116 a['urb'],
117 gmTools.coalesce(a['suburb'], ''),
118 a['l10n_region'],
119 a['l10n_country'],
120 gmTools.coalesce(a['notes_subunit'], '')
121 ] for a in adrs
122 ]
123 )
124 self._LCTRL_items.set_column_widths()
125 self._LCTRL_items.set_data(data = adrs)
126
127
128
130 self.__static_tooltip_part = _('List of addresses related to this person.')
131 self._LCTRL_items.item_tooltip_callback = self._calculate_tooltip
132 self._LCTRL_items.set_columns(columns = [
133 _('Type'),
134 _('Street'),
135 _('Street info'),
136 _('Number'),
137 _('Subunit'),
138 _('Postal code'),
139 _('Community'),
140 _('Suburb'),
141 _('Region'),
142 _('Country'),
143 _('Comment')
144 ])
145
146 self.left_extra_button = (
147 _('Map'),
148 _('Show selected address on map'),
149 self._show_address_on_map
150 )
151 self.middle_extra_button = (
152 _('Distance'),
153 _('Show distance from your praxis'),
154 self._show_distance_on_map
155 )
156
157
166
179
181 go_ahead = gmGuiHelpers.gm_show_question (
182 _( 'Are you sure you want to remove this\n'
183 "address from the patient's addresses ?\n"
184 '\n'
185 'The address itself will not be deleted\n'
186 'but it will no longer be associated with\n'
187 'this patient.'
188 ),
189 _('Removing address')
190 )
191 if not go_ahead:
192 return False
193 self.__identity.unlink_address(address = address)
194 return True
195
200
201
207
208
215
216
217
218
220 return self.__identity
221
225
226 identity = property(_get_identity, _set_identity)
227
228
229 from Gnumed.wxGladeWidgets import wxgPersonContactsManagerPnl
230
263
264
265 if __name__ == "__main__":
266
267 if len(sys.argv) < 2:
268 sys.exit()
269
270 if sys.argv[1] != 'test':
271 sys.exit()
272
273 from Gnumed.pycommon import gmI18N, gmPG2
274
275 gmI18N.activate_locale()
276 gmI18N.install_domain(domain='gnumed')
277 gmPG2.get_connection()
278
279
281 app = wx.PyWidgetTester(size = (600, 400))
282 widget = cPersonAddressesManagerPnl(app.frame, -1)
283 widget.identity = activate_patient()
284 app.frame.Show(True)
285 app.MainLoop()
286
293
294
295
296
297
298