15 from functools
import lru_cache
16 from os.path
import abspath, dirname, join
20 from ..ui.preferences_dialogs
import (boolean_editor, PreferencesPanel, IntegerChoiceEditor, SpinChoiceEditor,
21 StringChoiceEditor, PreferencesColorPicker)
22 from .managesettingsdialog
import SaveLoadSettings
24 from ..context
import IS_WINDOWS
26 ID_APPLY_TO_PANEL = wx.NewId()
28 ID_SAVELOADSETTINGS = wx.NewId()
37 f = wx.FontEnumerator()
38 f.EnumerateFacenames()
39 names = f.GetFacenames(fixedWidthOnly=fixed)
40 names = [n
for n
in names
if not n.startswith(
'@')]
48 super(GeneralPreferences, self).
__init__(*args, **kwargs)
60 main_sizer = wx.FlexGridSizer(rows=6, cols=1, vgap=10, hgap=10)
61 buttons_sizer = wx.BoxSizer(orient=wx.HORIZONTAL)
62 reset = wx.Button(self, ID_RESET,
'Reset colors to default')
63 saveloadsettings = wx.Button(self, ID_SAVELOADSETTINGS,
'Save or Load settings')
64 self.
cb_apply_to_panelscb_apply_to_panels = wx.CheckBox(self, ID_APPLY_TO_PANEL, label=
"Apply to Project and File Explorer panels")
68 background_color = Colour(
"light gray")
69 foreground_color = Colour(
"black")
74 main_sizer.Add(font_editor)
75 main_sizer.Add(colors_sizer)
77 buttons_sizer.Add(reset)
78 buttons_sizer.AddSpacer(10)
79 buttons_sizer.Add(saveloadsettings)
80 main_sizer.Add(buttons_sizer)
81 self.SetSizerAndFit(main_sizer)
82 self.Bind(wx.EVT_BUTTON, self.
OnResetOnReset)
92 if event.GetId() != ID_RESET:
97 picker.SetColour(defaults[picker.key])
101 if event.GetId() != ID_SAVELOADSETTINGS:
105 save_settings_dialog.CenterOnParent()
106 value = save_settings_dialog.ShowModal()
112 wx.FindWindowByName(
"RIDE - Preferences").Close(force=
True)
116 from ..context
import SETTINGS_DIRECTORY
117 self.
_default_path_default_path = os.path.join(SETTINGS_DIRECTORY,
'settings.cfg')
118 settings = [s.strip()
for s
in open(self.
_default_path_default_path,
'r').readlines()]
120 start_index = settings.index(name) + 1
122 for line
in settings[start_index:]:
123 if line.startswith(
'['):
127 key, value = [s.strip().strip(
'\'')
for s
in line.split(
"=")]
129 if len(value) > 0
and value[0] ==
'(' and value[-1] ==
')':
130 from ast
import literal_eval
as make_tuple
131 value = make_tuple(value)
132 defaults[key] = value
136 picker.SetColour(defaults[picker.key])
140 settings = [s.strip()
for s
in open(self.
_get_path_get_path(),
'r').readlines()]
141 name = (
'[[%s]]' if plugin
else '[%s]') % self.name
142 start_index = settings.index(name) + 1
144 for line
in settings[start_index:]:
145 if line.startswith(
'['):
149 key, value = [s.strip().strip(
'\'')
for s
in line.split(
"=")]
151 if len(value) > 0
and value[0] ==
'(' and value[-1] ==
')':
152 from ast
import literal_eval
as make_tuple
153 value = make_tuple(value)
154 defaults[key] = value
158 return join(dirname(
abspath(__file__)),
'settings.cfg')
162 self.
_settings_settings,
'font size',
'Font Size',
163 [str(i)
for i
in range(8, 16)])
164 sizer = wx.FlexGridSizer(rows=3, cols=2, vgap=10, hgap=30)
165 l_size = f.label(self)
167 background_color = Colour(
"light gray")
168 foreground_color = Colour(
"black")
169 l_size.SetBackgroundColour(background_color)
170 l_size.SetOwnBackgroundColour(background_color)
171 l_size.SetForegroundColour(foreground_color)
172 l_size.SetOwnForegroundColour(foreground_color)
173 sizer.AddMany([l_size, f.chooser(self)])
175 if 'zoom factor' in self.
_settings_settings:
177 self.
_settings_settings,
'zoom factor',
'Zoom Factor', (-10, 20))
178 l_zoom = z.label(self)
180 l_zoom.SetForegroundColour(foreground_color)
181 l_zoom.SetBackgroundColour(background_color)
182 l_zoom.SetOwnBackgroundColour(background_color)
183 l_zoom.SetOwnForegroundColour(foreground_color)
184 sizer.AddMany([l_zoom, z.chooser(self)])
185 if 'fixed font' in self.
_settings_settings:
188 l_ff.SetForegroundColour(foreground_color)
189 l_ff.SetBackgroundColour(background_color)
190 l_ff.SetOwnBackgroundColour(background_color)
191 l_ff.SetOwnForegroundColour(foreground_color)
192 sizer.AddMany([l_ff, editor])
193 fixed_font = self.
_settings_settings[
'fixed font']
194 if 'font face' in self.
_settings_settings:
196 l_font = s.label(self)
198 l_font.SetForegroundColour(foreground_color)
199 l_font.SetBackgroundColour(background_color)
200 l_font.SetOwnBackgroundColour(background_color)
201 l_font.SetOwnForegroundColour(foreground_color)
202 sizer.AddMany([l_font, s.chooser(self)])
207 raise NotImplementedError(
'Implement me')
211 location = (
"General",)
212 title =
"General Settings"
216 super(DefaultPreferences, self).
__init__(settings[self.
namename], *args, **kwargs)
221 container = wx.GridBagSizer()
225 (
'foreground',
'Foreground'),
226 (
'background',
'Background'),
227 (
'secondary foreground',
'Secondary Foreground'),
228 (
'secondary background',
'Secondary Background'),
229 (
'foreground text',
'Text Foreground'),
230 (
'background help',
'Help Background')
233 background_color = Colour(
"light gray")
234 foreground_color = Colour(
"black")
235 for settings_key, label_text
in settings:
239 label = wx.StaticText(self, wx.ID_ANY, label_text)
241 label.SetForegroundColour(foreground_color)
242 label.SetBackgroundColour(background_color)
243 label.SetOwnBackgroundColour(background_color)
244 label.SetOwnForegroundColour(foreground_color)
246 self, wx.ID_ANY, self.
_settings_settings, settings_key)
247 container.Add(button, (row, column),
248 flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=4)
251 container.Add(label, (row, column),
252 flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=8)
259 picker.SetColour(defaults[picker.key])
261 wx.FindWindowByName(
"RIDE - Preferences").Close(force=
True)
def create_colors_sizer(self)
def __init__(self, settings, *args, **kwargs)
def _reload_settings(self)
def _read_defaults(self, plugin=False)
def _create_font_editor(self)
def create_colors_sizer(self)
def OnSaveLoadSettings(self, event)
def __init__(self, settings, *args, **kwargs)
def OnCheckBox(self, event)
A colored button that opens a color picker dialog.
Base class for all preference panels used by PreferencesDialog.
def abspath(path, case_normalize=False)
Replacement for os.path.abspath with some enhancements and bug fixes.
def read_fonts(fixed=False)
Returns list with fixed width fonts.
def boolean_editor(parent, settings, name, label, help='')