Package Gnumed :: Package wxpython :: Module gmCfgWidgets
[frames] | no frames]

Source Code for Module Gnumed.wxpython.gmCfgWidgets

  1  """GNUmed configuration related widgets. 
  2  """ 
  3  #================================================================ 
  4  # $Source: /cvsroot/gnumed/gnumed/gnumed/client/wxpython/gmCfgWidgets.py,v $ 
  5  # $Id: gmCfgWidgets.py,v 1.4 2009/12/30 18:47:01 ncq Exp $ 
  6  __version__ = '$Revision: 1.4 $' 
  7  __author__ = 'karsten.hilbert@gmx.net' 
  8  __license__ = 'GPL (details at http://www.gnu.org)' 
  9   
 10  # stdlib 
 11  import logging, sys 
 12   
 13   
 14  # 3rd party 
 15  import wx 
 16   
 17   
 18  # GNUmed 
 19  if __name__ == '__main__': 
 20          sys.path.insert(0, '../../') 
 21  from Gnumed.pycommon import gmCfg, gmDispatcher, gmTools, gmCfg2 
 22  from Gnumed.business import gmSurgery 
 23  from Gnumed.wxpython import gmGuiHelpers, gmListWidgets 
 24   
 25   
 26  _log = logging.getLogger('gm.ui') 
 27  _log.info(__version__) 
 28   
 29  #============================================================================== 
30 -def check_for_updates():
31 32 dbcfg = gmCfg.cCfgSQL() 33 34 url = dbcfg.get2 ( 35 option = u'horstspace.update.url', 36 workplace = gmSurgery.gmCurrentPractice().active_workplace, 37 bias = 'workplace', 38 default = u'http://www.gnumed.de/downloads/gnumed-versions.txt' 39 ) 40 41 consider_latest_branch = bool(dbcfg.get2 ( 42 option = u'horstspace.update.consider_latest_branch', 43 workplace = gmSurgery.gmCurrentPractice().active_workplace, 44 bias = 'workplace', 45 default = True 46 )) 47 48 _cfg = gmCfg2.gmCfgData() 49 50 found, msg = gmTools.check_for_update ( 51 url = url, 52 current_branch = _cfg.get(option = 'client_branch'), 53 current_version = _cfg.get(option = 'client_version'), 54 consider_latest_branch = consider_latest_branch 55 ) 56 57 if found is False: 58 gmDispatcher.send(signal = 'statustext', msg = _('Your client (%s) is up to date.') % _cfg.get(option = 'client_version')) 59 return 60 61 gmGuiHelpers.gm_show_info ( 62 msg, 63 _('Checking for client updates') 64 )
65 #================================================================ 66 #================================================================
67 -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):
68 69 dbcfg = gmCfg.cCfgSQL() 70 71 current_value = dbcfg.get2 ( 72 option = option, 73 workplace = gmSurgery.gmCurrentPractice().active_workplace, 74 bias = bias, 75 default = default_value 76 ) 77 78 if parent is None: 79 parent = wx.GetApp().GetTopWindow() 80 81 if caption is None: 82 caption = _('Configuration') 83 84 selections = None 85 if current_value is not None: 86 try: 87 selections = [choices.index(current_value)] 88 except ValueError: 89 pass 90 91 choice = gmListWidgets.get_choices_from_list ( 92 parent = parent, 93 msg = message, 94 caption = caption, 95 choices = choices, 96 columns = columns, 97 data = data, 98 selections = selections, 99 single_selection = True, 100 can_return_empty = False 101 ) 102 103 # aborted 104 if choice is None: 105 return 106 107 # same value selected again 108 if choice == current_value: 109 return 110 111 dbcfg = gmCfg.cCfgSQL() 112 dbcfg.set ( 113 workplace = gmSurgery.gmCurrentPractice().active_workplace, 114 option = option, 115 value = choice 116 ) 117 118 return
119 #================================================================
120 -def configure_string_option(parent=None, message=None, option=None, bias=u'user', default_value=u'', validator=None):
121 122 dbcfg = gmCfg.cCfgSQL() 123 124 current_value = dbcfg.get2 ( 125 option = option, 126 workplace = gmSurgery.gmCurrentPractice().active_workplace, 127 bias = bias, 128 default = default_value 129 ) 130 131 if parent is None: 132 parent = wx.GetApp().GetTopWindow() 133 134 while True: 135 dlg = wx.TextEntryDialog ( 136 parent = parent, 137 message = message, 138 caption = _('Configuration'), 139 defaultValue = u'%s' % current_value, 140 style = wx.OK | wx.CANCEL | wx.CENTRE 141 ) 142 result = dlg.ShowModal() 143 if result == wx.ID_CANCEL: 144 dlg.Destroy() 145 return 146 147 user_val = dlg.GetValue().strip() 148 dlg.Destroy() 149 150 if user_val == current_value: 151 return 152 153 validated, user_val = validator(user_val) 154 if validated: 155 break 156 157 gmDispatcher.send ( 158 signal = u'statustext', 159 msg = _('Value [%s] not valid for option <%s>.') % (user_val, option), 160 beep = True 161 ) 162 163 dbcfg = gmCfg.cCfgSQL() 164 dbcfg.set ( 165 workplace = gmSurgery.gmCurrentPractice().active_workplace, 166 option = option, 167 value = user_val 168 ) 169 170 return
171 #================================================================
172 -def configure_boolean_option(parent=None, question=None, option=None, button_tooltips=None):
173 174 if parent is None: 175 parent = wx.GetApp().GetTopWindow() 176 177 tooltips = [ 178 _('Set "%s" to <True>.') % option, 179 _('Set "%s" to <False>.') % option, 180 _('Abort the dialog and do not change the current setting.') 181 ] 182 if button_tooltips is not None: 183 for idx in range(len(button_tooltips)): 184 tooltips[idx] = button_tooltips[idx] 185 186 dlg = gmGuiHelpers.c3ButtonQuestionDlg ( 187 parent, 188 -1, 189 caption = _('Configuration'), 190 question = question, 191 button_defs = [ 192 {'label': _('Yes'), 'tooltip': tooltips[0]}, 193 {'label': _('No'), 'tooltip': tooltips[1]}, 194 {'label': _('Cancel'), 'tooltip': tooltips[2], 'default': True} 195 ] 196 ) 197 198 decision = dlg.ShowModal() 199 dbcfg = gmCfg.cCfgSQL() 200 if decision == wx.ID_YES: 201 dbcfg.set ( 202 workplace = gmSurgery.gmCurrentPractice().active_workplace, 203 option = option, 204 value = True 205 ) 206 elif decision == wx.ID_NO: 207 dbcfg.set ( 208 workplace = gmSurgery.gmCurrentPractice().active_workplace, 209 option = option, 210 value = False 211 ) 212 213 return
214 #================================================================ 215 if __name__ == '__main__': 216 217 from Gnumed.pycommon import gmI18N 218 gmI18N.activate_locale() 219 gmI18N.install_domain() 220 221 if (len(sys.argv) > 1): 222 if sys.argv[1] == 'test': 223 check_for_updates() 224 225 #================================================================ 226 # $Log: gmCfgWidgets.py,v $ 227 # Revision 1.4 2009/12/30 18:47:01 ncq 228 # - fix strange case of missing gmCfg2 import 229 # 230 # Revision 1.3 2009/12/21 15:03:34 ncq 231 # - check_for_updates should be here 232 # 233 # Revision 1.2 2009/10/20 10:25:43 ncq 234 # - support pre-selections in configure-string-from-list 235 # 236 # Revision 1.1 2008/01/16 19:25:18 ncq 237 # - new file, factored out from gmGuiHelpers 238 # 239 # 240