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