| Home | Trees | Indices | Help |
|
|---|
|
|
1 """GNUmed configuration related widgets.
2 """
3 #================================================================
4 __version__ = '$Revision: 1.4 $'
5 __author__ = 'karsten.hilbert@gmx.net'
6 __license__ = 'GPL v2 or later (details at http://www.gnu.org)'
7
8 # stdlib
9 import logging, sys
10
11
12 # 3rd party
13 import wx
14
15
16 # GNUmed
17 if __name__ == '__main__':
18 sys.path.insert(0, '../../')
19 from Gnumed.pycommon import gmCfg
20 from Gnumed.pycommon import gmNetworkTools
21 from Gnumed.pycommon import gmTools
22 from Gnumed.pycommon import gmDispatcher
23 from Gnumed.pycommon import gmCfg2
24 from Gnumed.pycommon import gmWorkerThread
25 from Gnumed.pycommon import gmConnectionPool
26 from Gnumed.business import gmPraxis
27 from Gnumed.wxpython import gmGuiHelpers
28 from Gnumed.wxpython import gmListWidgets
29
30
31 _log = logging.getLogger('gm.ui')
32 _log.info(__version__)
33
34 #==============================================================================
36
37 dbcfg = gmCfg.cCfgSQL()
38 url = dbcfg.get2 (
39 option = 'horstspace.update.url',
40 workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace,
41 bias = 'workplace',
42 default = 'http://www.gnumed.de/downloads/gnumed-versions.txt'
43 )
44 consider_latest_branch = bool(dbcfg.get2 (
45 option = 'horstspace.update.consider_latest_branch',
46 workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace,
47 bias = 'workplace',
48 default = True
49 ))
50
51 _cfg = gmCfg2.gmCfgData()
52 update_found, msg = gmNetworkTools.check_for_update (
53 url = url,
54 current_branch = _cfg.get(option = 'client_branch'),
55 current_version = _cfg.get(option = 'client_version'),
56 consider_latest_branch = consider_latest_branch
57 )
58
59 return update_found, msg
60
61 #------------------------------------------------------------------------------
63
64 update_found, msg = status
65 if update_found is False:
66 _cfg = gmCfg2.gmCfgData()
67 gmDispatcher.send(signal = 'statustext', msg = _('Your client (%s) is up to date.') % _cfg.get(option = 'client_version'))
68 return
69
70 gmGuiHelpers.gm_show_info (
71 msg,
72 _('Checking for client updates')
73 )
74
75 #------------------------------------------------------------------------------
77 gmConnectionPool.gmConnectionPool().discard_pooled_connection_of_thread()
78 wx.CallAfter(_signal_update_status, status)
79
80 #------------------------------------------------------------------------------
82
83 if do_async:
84 gmWorkerThread.execute_in_worker_thread (
85 payload_function = _get_update_status,
86 payload_kwargs = None,
87 completion_callback = _async_signal_update_status,
88 worker_name = 'UpdChk'
89 )
90 return
91
92 _signal_update_status(_get_update_status())
93
94 #================================================================
96
97 if parent is None:
98 parent = wx.GetApp().GetTopWindow()
99
100 #---------------
101 def refresh(lctrl):
102 opts = gmCfg.get_all_options(order_by = 'owner, workplace, option')
103
104 items = [ [
105 o['owner'],
106 o['workplace'],
107 o['option'],
108 o['value'],
109 o['type'],
110 gmTools.coalesce(o['description'], '')
111 ] for o in opts ]
112 lctrl.set_string_items(items)
113 lctrl.set_data(opts)
114 #---------------
115 def tooltip(item):
116 return (
117 '%s %s (#%s) %s\n'
118 '\n'
119 ' %s @ %s\n'
120 '\n'
121 ' %s: %s\n'
122 '%s'
123 ) % (
124 gmTools.u_box_horiz_single * 3,
125 item['option'],
126 item['pk_cfg_item'],
127 gmTools.u_box_horiz_single * 3,
128 item['owner'],
129 item['workplace'],
130 item['type'],
131 gmTools.wrap(
132 text = item['value'],
133 width = 40,
134 subsequent_indent = ' ' * 8
135 ),
136 gmTools.wrap (
137 text = gmTools.coalesce(item['description'], '', '\n%s'),
138 width = 40,
139 initial_indent = ' ',
140 subsequent_indent = ' '
141 )
142 )
143 #---------------
144 def delete(item):
145 delete_it = gmGuiHelpers.gm_show_question (
146 aTitle = _('Deleting option'),
147 aMessage = '%s\n\n%s %s (#%s) %s\n\n%s\n\n%s' % (
148 tooltip(item),
149 gmTools.u_box_horiz_single * 3,
150 item['option'],
151 item['pk_cfg_item'],
152 gmTools.u_box_horiz_single * 3,
153 _('Do you really want to delete this option ?'),
154 _('(GNUmed will re-create options as needed.)')
155 )
156 )
157 if not delete_it:
158 return False
159
160 from Gnumed.wxpython.gmAuthWidgets import get_dbowner_connection
161 conn = get_dbowner_connection(procedure = _('Deleting option'))
162 if conn is None:
163 gmDispatcher.send(signal = 'statustext', msg = _('Cannot connect as database owner. Unable to delete option.'))
164 return False
165
166 cfg = gmCfg.cCfgSQL()
167 cfg.delete(conn = conn, pk_option = item['pk_cfg_item'])
168 return True
169 #---------------
170 gmListWidgets.get_choices_from_list (
171 parent = parent,
172 msg = _('All configured options currently in the database.'),
173 caption = _('All configured options'),
174 columns = [ _('User'), _('Workplace'), _('Option'), _('Value'), _('Type'), _('Description') ],
175 refresh_callback = refresh,
176 delete_callback = delete,
177 ignore_OK_button = True,
178 list_tooltip_callback = tooltip
179 )
180
181 #================================================================
182 -def configure_string_from_list_option(parent=None, message=None, option=None, bias='user', default_value='', choices=None, columns=None, data=None, caption=None):
183
184 dbcfg = gmCfg.cCfgSQL()
185
186 current_value = dbcfg.get2 (
187 option = option,
188 workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace,
189 bias = bias,
190 default = default_value
191 )
192
193 if parent is None:
194 parent = wx.GetApp().GetTopWindow()
195
196 if caption is None:
197 caption = _('Configuration')
198
199 selections = None
200 if current_value is not None:
201 try:
202 selections = [choices.index(current_value)]
203 except ValueError:
204 pass
205
206 choice = gmListWidgets.get_choices_from_list (
207 parent = parent,
208 msg = message,
209 caption = caption,
210 choices = choices,
211 columns = columns,
212 data = data,
213 selections = selections,
214 single_selection = True,
215 can_return_empty = False
216 )
217
218 # aborted
219 if choice is None:
220 return
221
222 # same value selected again
223 if choice == current_value:
224 return
225
226 dbcfg = gmCfg.cCfgSQL()
227 dbcfg.set (
228 workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace,
229 option = option,
230 value = choice
231 )
232
233 return
234
235 #================================================================
236 -def configure_list_from_list_option(parent=None, message=None, option=None, bias='user', default_value=None, choices=None, columns=None, data=None, caption=None, picks=None):
237
238 if default_value is None:
239 default_value = []
240
241 dbcfg = gmCfg.cCfgSQL()
242
243 current_value = dbcfg.get2 (
244 option = option,
245 workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace,
246 bias = bias,
247 default = default_value
248 )
249
250 if parent is None:
251 parent = wx.GetApp().GetTopWindow()
252
253 if caption is None:
254 caption = _('Configuration')
255
256 # setup item picker
257 picker = gmListWidgets.cItemPickerDlg(parent, -1, msg = message)
258 picker.set_columns(columns)
259 picker.set_choices(choices)
260 picker.set_picks(picks)
261 result = picker.ShowModal()
262 if result == wx.ID_CANCEL:
263 picker.DestroyLater()
264 return
265
266 picks = picker.get_picks()
267 picker.DestroyLater()
268
269 dbcfg.set (
270 workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace,
271 option = option,
272 value = picks
273 )
274
275 return
276
277 #================================================================
278 -def configure_string_option(parent=None, message=None, option=None, bias='user', default_value='', validator=None):
279
280 dbcfg = gmCfg.cCfgSQL()
281
282 current_value = dbcfg.get2 (
283 option = option,
284 workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace,
285 bias = bias,
286 default = default_value
287 )
288
289 if current_value is not None:
290 current_value = '%s' % current_value
291
292 if parent is None:
293 parent = wx.GetApp().GetTopWindow()
294
295 if validator is None:
296 validator = lambda in_val: (True, in_val)
297
298 while True:
299 dlg = wx.TextEntryDialog (
300 parent,
301 message,
302 caption = _('Configuration'),
303 value = gmTools.coalesce(current_value, ''),
304 style = wx.OK | wx.CANCEL | wx.CENTRE
305 )
306 result = dlg.ShowModal()
307 if result == wx.ID_CANCEL:
308 dlg.DestroyLater()
309 return None
310
311 user_val = dlg.GetValue().strip()
312 dlg.DestroyLater()
313
314 if user_val == current_value:
315 return user_val
316
317 validated, user_val = validator(user_val)
318 if validated:
319 break
320 gmDispatcher.send (
321 signal = 'statustext',
322 msg = _('Value [%s] not valid for option <%s>.') % (user_val, option),
323 beep = True
324 )
325
326 dbcfg = gmCfg.cCfgSQL()
327 dbcfg.set (
328 workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace,
329 option = option,
330 value = user_val
331 )
332
333 return user_val
334
335 #================================================================
337
338 if parent is None:
339 parent = wx.GetApp().GetTopWindow()
340
341 tooltips = [
342 _('Set "%s" to <True>.') % option,
343 _('Set "%s" to <False>.') % option,
344 _('Abort the dialog and do not change the current setting.')
345 ]
346 if button_tooltips is not None:
347 for idx in range(len(button_tooltips)):
348 tooltips[idx] = button_tooltips[idx]
349
350 dlg = gmGuiHelpers.c3ButtonQuestionDlg (
351 parent,
352 -1,
353 caption = _('Configuration'),
354 question = question,
355 button_defs = [
356 {'label': _('Yes'), 'tooltip': tooltips[0]},
357 {'label': _('No'), 'tooltip': tooltips[1]},
358 {'label': _('Cancel'), 'tooltip': tooltips[2], 'default': True}
359 ]
360 )
361
362 decision = dlg.ShowModal()
363 dbcfg = gmCfg.cCfgSQL()
364 if decision == wx.ID_YES:
365 dbcfg.set (
366 workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace,
367 option = option,
368 value = True
369 )
370 elif decision == wx.ID_NO:
371 dbcfg.set (
372 workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace,
373 option = option,
374 value = False
375 )
376
377 return
378
379 #================================================================
380 if __name__ == '__main__':
381
382 from Gnumed.pycommon import gmI18N
383 gmI18N.activate_locale()
384 gmI18N.install_domain()
385
386 if len(sys.argv) < 2:
387 sys.exit()
388
389 if sys.argv[1] != 'test':
390 sys.exit()
391
392 check_for_updates()
393
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Sat Feb 29 02:55:27 2020 | http://epydoc.sourceforge.net |