| Home | Trees | Indices | Help |
|
|---|
|
|
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 #============================================================
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 """
78
79 try:
80 self.__identity = kwargs['identity']
81 del kwargs['identity']
82 except KeyError:
83 self.__identity = None
84
85 gmListWidgets.cGenericListManagerPnl.__init__(self, *args, **kwargs)
86
87 self.new_callback = self._add_address
88 self.edit_callback = self._edit_address
89 self.delete_callback = self._del_address
90 self.refresh_callback = self.refresh
91
92 self.__init_ui()
93 self.refresh()
94 #--------------------------------------------------------
95 # external API
96 #--------------------------------------------------------
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 # internal helpers
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 #--------------------------------------------------------
142 ea = gmAddressWidgets.cAddressEditAreaPnl(self, -1)
143 ea.address_holder = self.__identity
144 dlg = gmEditArea.cGenericEditAreaDlg(self, -1, edit_area = ea)
145 dlg.SetTitle(_('Adding new address'))
146 if dlg.ShowModal() == wx.ID_OK:
147 return True
148 return False
149 #--------------------------------------------------------
151 ea = gmAddressWidgets.cAddressEditAreaPnl(self, -1, address = address)
152 ea.address_holder = self.__identity
153 dlg = gmEditArea.cGenericEditAreaDlg(self, -1, edit_area = ea)
154 dlg.SetTitle(_('Editing address'))
155 if dlg.ShowModal() == wx.ID_OK:
156 # did we add an entirely new address ?
157 # if so then unlink the old one as implied by "edit"
158 if ea.address['pk_address'] != address['pk_address']:
159 self.__identity.unlink_address(address = address)
160 return True
161 return False
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 #--------------------------------------------------------
180 tt = u'\n'.join(address.format())
181 tt += u'\n'
182 tt += u'%s\n' % (gmTools.u_box_horiz_single * 40)
183 tt += self.__static_tooltip_part
184 return tt
185 #--------------------------------------------------------
186 # properties
187 #--------------------------------------------------------
190
194
195 identity = property(_get_identity, _set_identity)
196
197 #------------------------------------------------------------
198 from Gnumed.wxGladeWidgets import wxgPersonContactsManagerPnl
199
201 """A panel for editing contact data for a person.
202
203 - provides access to:
204 - addresses
205 - communication paths
206
207 Does NOT act on/listen to the current patient.
208 """
210
211 wxgPersonContactsManagerPnl.wxgPersonContactsManagerPnl.__init__(self, *args, **kwargs)
212
213 self.__identity = None
214 self.refresh()
215 #--------------------------------------------------------
216 # external API
217 #--------------------------------------------------------
219 self._PNL_addresses.identity = self.__identity
220 self._PNL_comms.channel_owner = self.__identity
221 #--------------------------------------------------------
222 # properties
223 #--------------------------------------------------------
226
230
231 identity = property(_get_identity, _set_identity)
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 #--------------------------------------------------------
257 app = wx.PyWidgetTester(size = (600, 400))
258 widget = cPersonContactsManagerPnl(app.frame, -1)
259 widget.identity = activate_patient()
260 app.frame.Show(True)
261 app.MainLoop()
262 #--------------------------------------------------------
263 #test_pat_contacts_pnl()
264 #test_person_adrs_pnl()
265
266 #============================================================
267
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Mon Jun 25 03:58:27 2012 | http://epydoc.sourceforge.net |