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, logging
8
9
10 import wx
11
12
13
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
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
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
72 """A list for managing a person's addresses.
73
74 Does NOT act on/listen to the current patient.
75 """
93
94
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
122
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
148
161
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
184
185
186
188 return self.__identity
189
193
194 identity = property(_get_identity, _set_identity)
195
196
197 from Gnumed.wxGladeWidgets import wxgPersonContactsManagerPnl
198
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
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
261
262
263
264
265
266