| Home | Trees | Indices | Help |
|
|---|
|
|
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
8 import 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.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 # constant defs
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 #============================================================
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 """
83
84 try:
85 self.__identity = kwargs['identity']
86 del kwargs['identity']
87 except KeyError:
88 self.__identity = None
89
90 gmListWidgets.cGenericListManagerPnl.__init__(self, *args, **kwargs)
91
92 self.refresh_callback = self.refresh
93 self.new_callback = self._add_address
94 self.edit_callback = self._edit_address
95 self.delete_callback = self._del_address
96
97 self.__init_ui()
98 self.refresh()
99 #--------------------------------------------------------
100 # external API
101 #--------------------------------------------------------
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 # internal helpers
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 #--------------------------------------------------------
159 ea = gmAddressWidgets.cAddressEAPnl(self, -1)
160 ea.address_holder = self.__identity
161 dlg = gmEditArea.cGenericEditAreaDlg2(self, -1, edit_area = ea)
162 dlg.SetTitle(_('Adding new address'))
163 if dlg.ShowModal() == wx.ID_OK:
164 return True
165 return False
166 #--------------------------------------------------------
168 ea = gmAddressWidgets.cAddressEAPnl(self, -1, address = address)
169 ea.address_holder = self.__identity
170 dlg = gmEditArea.cGenericEditAreaDlg2(self, -1, edit_area = ea)
171 dlg.SetTitle(_('Editing address'))
172 if dlg.ShowModal() == wx.ID_OK:
173 # did we add an entirely new address ?
174 # if so then unlink the old one as implied by "edit"
175 if ea.address['pk_address'] != address['pk_address']:
176 self.__identity.unlink_address(address = address)
177 return True
178 return False
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 #--------------------------------------------------------
197 if address is None:
198 return False
199 gmNetworkTools.open_url_in_browser(address.as_map_url, new = 2, autoraise = True)
200
201 #--------------------------------------------------------
203 if address is None:
204 return False
205 praxis_branch = gmPraxis.gmCurrentPraxisBranch()
206 gmNetworkTools.open_url_in_browser(praxis_branch.get_distance2address_url(address), new = 2, autoraise = True)
207
208 #--------------------------------------------------------
210 tt = '\n'.join(address.format())
211 tt += '\n'
212 tt += '%s\n' % (gmTools.u_box_horiz_single * 40)
213 tt += self.__static_tooltip_part
214 return tt
215
216 #--------------------------------------------------------
217 # properties
218 #--------------------------------------------------------
221
225
226 identity = property(_get_identity, _set_identity)
227
228 #------------------------------------------------------------
229 from Gnumed.wxGladeWidgets import wxgPersonContactsManagerPnl
230
232 """A panel for editing contact data for a person.
233
234 - provides access to:
235 - addresses
236 - communication paths
237
238 Does NOT act on/listen to the current patient.
239 """
241
242 wxgPersonContactsManagerPnl.wxgPersonContactsManagerPnl.__init__(self, *args, **kwargs)
243
244 self.__identity = None
245 self.refresh()
246 #--------------------------------------------------------
247 # external API
248 #--------------------------------------------------------
250 self._PNL_addresses.identity = self.__identity
251 self._PNL_comms.channel_owner = self.__identity
252 #--------------------------------------------------------
253 # properties
254 #--------------------------------------------------------
257
261
262 identity = property(_get_identity, _set_identity)
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 #--------------------------------------------------------
288 app = wx.PyWidgetTester(size = (600, 400))
289 widget = cPersonContactsManagerPnl(app.frame, -1)
290 widget.identity = activate_patient()
291 app.frame.Show(True)
292 app.MainLoop()
293 #--------------------------------------------------------
294 #test_pat_contacts_pnl()
295 #test_person_adrs_pnl()
296
297 #============================================================
298
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Thu May 10 01:55:20 2018 | http://epydoc.sourceforge.net |