/usr/share/pyshared/wxglade/config.py is in python-wxglade 0.6.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | from ConfigParser import *
import common, sys, os, os.path
if common.use_gui:
import wx
import misc
try:
wx.FIXED_MINSIZE
except NameError:
import configUI
configUI.wxFIXED_MINSIZE = 0
from configUI import *
class wxGladePreferences(wxGladePreferencesUI):
def __init__(self, preferences):
wxGladePreferencesUI.__init__(self, None, -1, "")
wx.EVT_BUTTON(self, self.choose_widget_path.GetId(),
self.on_widget_path)
self.preferences = preferences
self.set_values()
def set_values(self):
try:
self.use_menu_icons.SetValue(self.preferences.use_menu_icons)
self.frame_tool_win.SetValue(self.preferences.frame_tool_win)
self.open_save_path.SetValue(self.preferences.open_save_path)
self.codegen_path.SetValue(self.preferences.codegen_path)
self.use_dialog_units.SetValue(
self.preferences.use_dialog_units)
self.number_history.SetValue(self.preferences.number_history)
self.show_progress.SetValue(self.preferences.show_progress)
self.wxg_backup.SetValue(self.preferences.wxg_backup)
self.codegen_backup.SetValue(self.preferences.codegen_backup)
#MARCELLO
self.default_border.SetValue(self.preferences.default_border)
self.default_border_size.SetValue(
self.preferences.default_border_size)
if self.preferences.backup_suffix == '.bak':
self.backup_suffix.SetSelection(1)
self.buttons_per_row.SetValue(self.preferences.buttons_per_row)
self.remember_geometry.SetValue(
self.preferences.remember_geometry)
self.local_widget_path.SetValue(
self.preferences.local_widget_path)
# ALB 2004-08-11
self.show_sizer_handle.SetValue(
self.preferences.show_sizer_handle)
self.allow_duplicate_names.SetValue(
self.preferences.allow_duplicate_names)
# ALB 2004-10-15
self.autosave.SetValue(self.preferences.autosave)
self.autosave_delay.SetValue(self.preferences.autosave_delay)
# ALB 2004-10-27
self.use_kde_dialogs.SetValue(self.preferences.use_kde_dialogs)
self.write_timestamp.SetValue(self.preferences.write_timestamp)
self.write_generated_from.SetValue(
self.preferences.write_generated_from)
self._fix_spin_ctrls()
except Exception, e:
wx.MessageBox(_('Error reading config file:\n%s') % e, 'Error',
wx.OK|wx.CENTRE|wx.ICON_ERROR)
def _fix_spin_ctrls(self):
"""\
Workaround to a wxGTK 2.8.4.2 bug in wx.SpinCtrl.GetValue
"""
done = {}
for name in ('buttons_per_row', 'autosave_delay', 'number_history',
'default_border_size'):
def fix(n):
done[n] = False
def update(e):
done[n] = True
e.Skip()
def get_val():
if not done[n]:
return getattr(self.preferences, n)
else:
return wx.SpinCtrl.GetValue(getattr(self, n))
return update, get_val
spin = getattr(self, name)
if spin.GetValue() != getattr(self.preferences, name):
update, get_val = fix(name)
spin.GetValue = get_val
spin.Bind(wx.EVT_SPINCTRL, update)
def set_preferences(self):
prefs = self.preferences
prefs['use_menu_icons'] = self.use_menu_icons.GetValue()
prefs['frame_tool_win'] = self.frame_tool_win.GetValue()
prefs['open_save_path'] = self.open_save_path.GetValue()
prefs['codegen_path'] = self.codegen_path.GetValue()
prefs['use_dialog_units'] = self.use_dialog_units.GetValue()
prefs['number_history'] = self.number_history.GetValue()
prefs['show_progress'] = self.show_progress.GetValue()
prefs['wxg_backup'] = self.wxg_backup.GetValue()
prefs['codegen_backup'] = self.codegen_backup.GetValue()
#MARCELLO
prefs['default_border'] = self.default_border.GetValue()
prefs['default_border_size'] = self.default_border_size.GetValue()
if self.backup_suffix.GetSelection():
prefs['backup_suffix'] = '.bak'
else: prefs['backup_suffix'] = '~'
prefs['buttons_per_row'] = self.buttons_per_row.GetValue()
prefs['remember_geometry'] = self.remember_geometry.GetValue()
prefs['local_widget_path'] = self.local_widget_path.GetValue()
# ALB 2004-08-11
prefs['show_sizer_handle'] = self.show_sizer_handle.GetValue()
prefs['allow_duplicate_names'] = self.allow_duplicate_names.\
GetValue()
# ALB 2004-10-15
prefs['autosave'] = self.autosave.GetValue()
prefs['autosave_delay'] = self.autosave_delay.GetValue()
# ALB 2004-10-27
prefs['use_kde_dialogs'] = self.use_kde_dialogs.GetValue()
prefs['write_timestamp'] = self.write_timestamp.GetValue()
prefs['write_generated_from'] = self.write_generated_from.GetValue()
def on_widget_path(self, event):
# create a file choice dialog
pth = misc.DirSelector(_("Choose a directory:"), os.getcwd(),
style=wx.DD_DEFAULT_STYLE |
wx.DD_NEW_DIR_BUTTON)
if pth:
self.local_widget_path.SetValue(pth)
# end of class wxGladePreferences
def _get_home(default=common.wxglade_path):
h = os.path.expanduser('~')
if h not in ('~', '%USERPROFILE%'):
return h
if os.name == 'nt' and h == '%USERPROFILE%':
return os.environ.get('USERPROFILE', default)
return default
def _get_appdatapath(default=common.wxglade_path):
if os.name == 'nt':
result = os.environ.get('APPDATA')
if result:
return result
return _get_home(default)
class Preferences(ConfigParser):
_has_home = os.path.expanduser('~') != '~'
_defaults = {
'use_menu_icons': common.use_gui and wx.Platform != '__WXGTK__',
'frame_tool_win': True,
'open_save_path': _get_home(),
'codegen_path': _get_home(),
'use_dialog_units': False,
'number_history': 4,
'show_progress': True,
'wxg_backup': True,
'codegen_backup': True,
'backup_suffix': sys.platform == 'win32' and '.bak' or '~',
'buttons_per_row': 5,
'remember_geometry': False,
'local_widget_path': (_get_appdatapath('') and \
os.path.join(_get_appdatapath(),
'.wxglade', 'widgets')
or ''),
'default_border' : False,
'default_border_size' : 3,
'show_sizer_handle': True,
'allow_duplicate_names': False,
'autosave': True,
'autosave_delay': 120, # in seconds
'use_kde_dialogs': False,
'write_timestamp': True,
'write_generated_from': False,
}
def __init__(self, defaults=None):
self.def_vals = defaults
if self.def_vals is None:
self.def_vals = Preferences._defaults
self.changed = False
ConfigParser.__init__(self)
#self.default_border_size = 3
def __getattr__(self, attr):
val = self.def_vals.get(attr, "")
# UGLY!!!
cast = type(val)
if cast is bool: cast = self._cast_to_bool
# ...but I haven't found a better way: the problem is that
# bool('0') == True, while int('0') == False, and we want the
# latter behaviour
try:
return cast(self.get('wxglade', attr))
except (NoOptionError, ValueError):
return val
def __iter__(self):
def do_iter():
for key in self.def_vals:
yield key, self[key]
return do_iter()
def _cast_to_bool(self, val):
try:
return int(val)
except ValueError:
val = val.lower().strip()
if val in ('true', 'on'): return 1
elif val in ('false', 'off'): return 0
else: raise
def __getitem__(self, attr):
return self.__getattr__(attr)
def __setitem__(self, attr, val):
self.set('wxglade', attr, str(val))
self.changed = True
def set_geometry(self, name, geometry):
if geometry is not None:
section = 'geometry_%s' % name
if not self.has_section(section):
self.add_section(section)
self.set(section, 'x', geometry[0])
self.set(section, 'y', geometry[1])
self.set(section, 'w', geometry[2])
self.set(section, 'h', geometry[3])
def get_geometry(self, name):
section = 'geometry_%s' % name
if self.has_section(section):
x = self.get(section, 'x')
y = self.get(section, 'y')
w = self.get(section, 'w')
h = self.get(section, 'h')
return (x, y, w, h)
else:
return None
# end of class Preferences
preferences = None
if sys.platform == 'win32': _rc_name = 'wxglade.ini'
else: _rc_name = 'wxgladerc'
_use_file_history = False
if common.use_gui:
import misc
if misc.check_wx_version(2, 3, 3): _use_file_history = True
def init_preferences():
global preferences
if preferences is None:
preferences = Preferences()
h = _get_appdatapath('')
search_path = [os.path.join(common.wxglade_path, _rc_name)]
if h:
search_path.append(os.path.join(h, '.wxglade', _rc_name))
if 'WXGLADE_CONFIG_PATH' in os.environ:
search_path.append(
os.path.expandvars('$WXGLADE_CONFIG_PATH/%s' % _rc_name))
preferences.read(search_path)
if not preferences.has_section('wxglade'):
preferences.add_section('wxglade')
def edit_preferences():
dialog = wxGladePreferences(preferences)
if dialog.ShowModal() == wx.ID_OK:
wx.MessageBox(_('Changes will take effect after wxGlade is restarted'),
_('Preferences saved'),
wx.OK|wx.CENTRE|wx.ICON_INFORMATION)
dialog.set_preferences()
dialog.Destroy()
def save_preferences():
# let the exception be raised
if 'WXGLADE_CONFIG_PATH' in os.environ:
path = os.path.expandvars('$WXGLADE_CONFIG_PATH')
else:
path = _get_appdatapath()
if path != common.wxglade_path:
path = os.path.join(path, '.wxglade')
if not os.path.isdir(path):
os.mkdir(path)
# always save the file history
if _use_file_history:
fh = common.palette.file_history
if misc.check_wx_version(2, 5):
count = fh.GetCount()
else:
count = fh.GetNoHistoryFiles()
encoding = 'utf-8'
filenames = [common._encode_to_xml(fh.GetHistoryFile(i), encoding)
for i in range(min(preferences.number_history, count))]
outfile = open(os.path.join(path, 'file_history.txt'), 'w')
print >> outfile, "# -*- coding: %s -*-" % encoding
for filename in filenames:
print >> outfile, filename
outfile.close()
if preferences.changed:
outfile = open(os.path.join(path, _rc_name), 'w')
# let the exception be raised to signal abnormal behaviour
preferences.write(outfile)
outfile.close()
def load_history():
"""\
Loads the file history and returns a list of paths
"""
if 'WXGLADE_CONFIG_PATH' in os.environ:
path = os.path.expandvars('$WXGLADE_CONFIG_PATH')
else:
path = _get_appdatapath()
if path != common.wxglade_path:
path = os.path.join(path, '.wxglade')
try:
history = open(os.path.join(path, 'file_history.txt'))
l = history.readlines()
if l and l[0].startswith('# -*- coding:'):
try:
encoding = 'utf-8'
#l = [common._encode_from_xml(e, encoding) for e in l[1:]]
l = [e.decode(encoding) for e in l[1:]]
except Exception, e:
print _("ERR:"), e
l = l[1:]
history.close()
if common.use_gui:
l = [misc.wxstr(e, 'utf-8') for e in l]
return l
except IOError:
# don't consider this an error
return []
|