| 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 (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, gmDispatcher, gmTools, gmCfg2
20 from Gnumed.business import gmSurgery
21 from Gnumed.wxpython import gmGuiHelpers, gmListWidgets
22
23
24 _log = logging.getLogger('gm.ui')
25 _log.info(__version__)
26
27 #==============================================================================
29
30 dbcfg = gmCfg.cCfgSQL()
31
32 url = dbcfg.get2 (
33 option = u'horstspace.update.url',
34 workplace = gmSurgery.gmCurrentPractice().active_workplace,
35 bias = 'workplace',
36 default = u'http://www.gnumed.de/downloads/gnumed-versions.txt'
37 )
38
39 consider_latest_branch = bool(dbcfg.get2 (
40 option = u'horstspace.update.consider_latest_branch',
41 workplace = gmSurgery.gmCurrentPractice().active_workplace,
42 bias = 'workplace',
43 default = True
44 ))
45
46 _cfg = gmCfg2.gmCfgData()
47
48 found, msg = gmTools.check_for_update (
49 url = url,
50 current_branch = _cfg.get(option = 'client_branch'),
51 current_version = _cfg.get(option = 'client_version'),
52 consider_latest_branch = consider_latest_branch
53 )
54
55 if found is False:
56 gmDispatcher.send(signal = 'statustext', msg = _('Your client (%s) is up to date.') % _cfg.get(option = 'client_version'))
57 return
58
59 gmGuiHelpers.gm_show_info (
60 msg,
61 _('Checking for client updates')
62 )
63 #================================================================
65
66 if parent is None:
67 parent = wx.GetApp().GetTopWindow()
68
69 #---------------
70 def refresh(lctrl):
71 opts = gmCfg.get_all_options(order_by = u'owner, workplace, option')
72
73 items = [ [
74 o['owner'],
75 o['workplace'],
76 o['option'],
77 o['value'],
78 o['type'],
79 gmTools.coalesce(o['description'], u'')
80 ] for o in opts ]
81 lctrl.set_string_items(items)
82
83 #---------------
84 gmListWidgets.get_choices_from_list (
85 parent = parent,
86 msg = _('This list shows all configuration settings from the database.'),
87 caption = _('Showing configuration'),
88 columns = [ _('User'), _('Workplace'), _('Option'), _('Value'), _('Type'), _('Description') ],
89 refresh_callback = refresh,
90 ignore_OK_button = True
91 )
92 #================================================================
93 -def configure_string_from_list_option(parent=None, message=None, option=None, bias='user', default_value=u'', choices=None, columns=None, data=None, caption=None):
94
95 dbcfg = gmCfg.cCfgSQL()
96
97 current_value = dbcfg.get2 (
98 option = option,
99 workplace = gmSurgery.gmCurrentPractice().active_workplace,
100 bias = bias,
101 default = default_value
102 )
103
104 if parent is None:
105 parent = wx.GetApp().GetTopWindow()
106
107 if caption is None:
108 caption = _('Configuration')
109
110 selections = None
111 if current_value is not None:
112 try:
113 selections = [choices.index(current_value)]
114 except ValueError:
115 pass
116
117 choice = gmListWidgets.get_choices_from_list (
118 parent = parent,
119 msg = message,
120 caption = caption,
121 choices = choices,
122 columns = columns,
123 data = data,
124 selections = selections,
125 single_selection = True,
126 can_return_empty = False
127 )
128
129 # aborted
130 if choice is None:
131 return
132
133 # same value selected again
134 if choice == current_value:
135 return
136
137 dbcfg = gmCfg.cCfgSQL()
138 dbcfg.set (
139 workplace = gmSurgery.gmCurrentPractice().active_workplace,
140 option = option,
141 value = choice
142 )
143
144 return
145 #================================================================
146 -def configure_string_option(parent=None, message=None, option=None, bias=u'user', default_value=u'', validator=None):
147
148 dbcfg = gmCfg.cCfgSQL()
149
150 current_value = dbcfg.get2 (
151 option = option,
152 workplace = gmSurgery.gmCurrentPractice().active_workplace,
153 bias = bias,
154 default = default_value
155 )
156
157 if current_value is not None:
158 current_value = u'%s' % current_value
159
160 if parent is None:
161 parent = wx.GetApp().GetTopWindow()
162
163 while True:
164 dlg = wx.TextEntryDialog (
165 parent = parent,
166 message = message,
167 caption = _('Configuration'),
168 defaultValue = gmTools.coalesce(current_value, u''),
169 style = wx.OK | wx.CANCEL | wx.CENTRE
170 )
171 result = dlg.ShowModal()
172 if result == wx.ID_CANCEL:
173 dlg.Destroy()
174 return None
175
176 user_val = dlg.GetValue().strip()
177 dlg.Destroy()
178
179 if user_val == current_value:
180 return user_val
181
182 validated, user_val = validator(user_val)
183 if validated:
184 break
185
186 gmDispatcher.send (
187 signal = u'statustext',
188 msg = _('Value [%s] not valid for option <%s>.') % (user_val, option),
189 beep = True
190 )
191
192 dbcfg = gmCfg.cCfgSQL()
193 dbcfg.set (
194 workplace = gmSurgery.gmCurrentPractice().active_workplace,
195 option = option,
196 value = user_val
197 )
198
199 return user_val
200 #================================================================
202
203 if parent is None:
204 parent = wx.GetApp().GetTopWindow()
205
206 tooltips = [
207 _('Set "%s" to <True>.') % option,
208 _('Set "%s" to <False>.') % option,
209 _('Abort the dialog and do not change the current setting.')
210 ]
211 if button_tooltips is not None:
212 for idx in range(len(button_tooltips)):
213 tooltips[idx] = button_tooltips[idx]
214
215 dlg = gmGuiHelpers.c3ButtonQuestionDlg (
216 parent,
217 -1,
218 caption = _('Configuration'),
219 question = question,
220 button_defs = [
221 {'label': _('Yes'), 'tooltip': tooltips[0]},
222 {'label': _('No'), 'tooltip': tooltips[1]},
223 {'label': _('Cancel'), 'tooltip': tooltips[2], 'default': True}
224 ]
225 )
226
227 decision = dlg.ShowModal()
228 dbcfg = gmCfg.cCfgSQL()
229 if decision == wx.ID_YES:
230 dbcfg.set (
231 workplace = gmSurgery.gmCurrentPractice().active_workplace,
232 option = option,
233 value = True
234 )
235 elif decision == wx.ID_NO:
236 dbcfg.set (
237 workplace = gmSurgery.gmCurrentPractice().active_workplace,
238 option = option,
239 value = False
240 )
241
242 return
243 #================================================================
244 if __name__ == '__main__':
245
246 from Gnumed.pycommon import gmI18N
247 gmI18N.activate_locale()
248 gmI18N.install_domain()
249
250 if (len(sys.argv) > 1):
251 if sys.argv[1] == 'test':
252 check_for_updates()
253
254 #================================================================
255
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Mon Nov 29 04:05:19 2010 | http://epydoc.sourceforge.net |