16 from os.path
import abspath, dirname, join
20 from wx.lib.masked
import NumCtrl
23 from ..ui.preferences_dialogs
import (PreferencesPanel, SpinChoiceEditor, IntegerChoiceEditor, boolean_editor,
24 StringChoiceEditor, PreferencesColorPicker)
25 from ..widgets
import Label
26 from .managesettingsdialog
import SaveLoadSettings
27 from ..context
import IS_WINDOWS
30 from pygments.lexers
import robotframework
as robotframeworklexer
32 robotframeworklexer =
None
34 ID_SAVELOADSETTINGS = wx.NewId()
39 from functools
import lru_cache
44 f = wx.FontEnumerator()
45 f.EnumerateFacenames()
46 names = f.GetFacenames(fixedWidthOnly=fixed)
47 names = [n
for n
in names
if not n.startswith(
'@')]
55 super(EditorPreferences, self).
__init__(*args, **kwargs)
66 main_sizer = wx.FlexGridSizer(rows=6, cols=1, vgap=10, hgap=10)
67 buttons_sizer = wx.BoxSizer(orient=wx.HORIZONTAL)
68 reset = wx.Button(self, wx.ID_ANY,
'Reset colors to default')
69 saveloadsettings = wx.Button(self, ID_SAVELOADSETTINGS,
'Save or Load settings')
70 main_sizer.Add(font_editor)
71 main_sizer.Add(colors_sizer)
72 buttons_sizer.Add(reset)
73 buttons_sizer.AddSpacer(10)
74 buttons_sizer.Add(saveloadsettings)
75 main_sizer.Add(buttons_sizer)
76 self.SetSizer(main_sizer)
77 self.Bind(wx.EVT_BUTTON, self.
OnResetOnReset)
81 raise NotImplementedError(
'Implement me')
86 picker.SetColour(defaults[picker.key])
89 settings = [s.strip()
for s
in open(self.
_get_path_get_path(),
'r').readlines()]
90 name = (
'[[%s]]' if plugin
else '[%s]') % self.name
91 start_index = settings.index(name) + 1
93 for line
in settings[start_index:]:
94 if line.startswith(
'['):
98 key, value = [s.strip().strip(
'\'')
for s
in line.split(
"=")]
103 return join(dirname(
abspath(__file__)),
'settings.cfg')
107 self.
_settings_settings,
'font size',
'Font Size',
108 [str(i)
for i
in range(8, 16)])
109 sizer = wx.FlexGridSizer(rows=3, cols=2, vgap=10, hgap=30)
110 l_size = f.label(self)
112 background_color = Colour(
"light gray")
113 foreground_color = Colour(
"black")
114 l_size.SetBackgroundColour(background_color)
115 l_size.SetOwnBackgroundColour(background_color)
116 l_size.SetForegroundColour(foreground_color)
117 l_size.SetOwnForegroundColour(foreground_color)
118 sizer.AddMany([l_size, f.chooser(self)])
120 if 'zoom factor' in self.
_settings_settings:
122 self.
_settings_settings,
'zoom factor',
'Zoom Factor', (-10, 20))
123 l_zoom = z.label(self)
125 l_zoom.SetForegroundColour(foreground_color)
126 l_zoom.SetBackgroundColour(background_color)
127 l_zoom.SetOwnBackgroundColour(background_color)
128 l_zoom.SetOwnForegroundColour(foreground_color)
129 sizer.AddMany([l_zoom, z.chooser(self)])
130 if 'fixed font' in self.
_settings_settings:
133 l_ff.SetForegroundColour(foreground_color)
134 l_ff.SetBackgroundColour(background_color)
135 l_ff.SetOwnBackgroundColour(background_color)
136 l_ff.SetOwnForegroundColour(foreground_color)
137 sizer.AddMany([l_ff, editor])
138 fixed_font = self.
_settings_settings[
'fixed font']
139 if 'font face' in self.
_settings_settings:
141 l_font = s.label(self)
143 l_font.SetForegroundColour(foreground_color)
144 l_font.SetBackgroundColour(background_color)
145 l_font.SetOwnBackgroundColour(background_color)
146 l_font.SetOwnForegroundColour(foreground_color)
147 sizer.AddMany([l_font, s.chooser(self)])
151 raise NotImplementedError(
'Implement me')
155 location = (
"Text Editor",)
156 title =
"Text Editor Settings"
160 super(TextEditorPreferences, self).
__init__(
161 settings[self.
namename], *args, **kwargs)
164 container = wx.GridBagSizer()
167 if robotframeworklexer:
169 (
'argument',
'Argument foreground'),
170 (
'comment',
'Comment foreground'),
171 (
'error',
'Error foreground'),
172 (
'gherkin',
'Gherkin keyword foreground'),
173 (
'heading',
'Heading foreground'),
174 (
'import',
'Import foreground'),
175 (
'variable',
'Variable foreground'),
176 (
'tc_kw_name',
'Keyword definition foreground'),
177 (
'separator',
'Separator'),
178 (
'setting',
'Setting foreground'),
179 (
'syntax',
'Syntax characters'),
180 (
'background',
'Text background'),
184 (
'setting',
'Text foreground'),
185 (
'background',
'Text background'),
188 background_color = Colour(
"light gray")
189 foreground_color = Colour(
"black")
190 for settings_key, label_text
in settings:
194 label = wx.StaticText(self, wx.ID_ANY, label_text)
196 label.SetForegroundColour(foreground_color)
197 label.SetBackgroundColour(background_color)
198 label.SetOwnBackgroundColour(background_color)
199 label.SetOwnForegroundColour(foreground_color)
201 self, wx.ID_ANY, self.
_settings_settings, settings_key)
202 container.Add(button, (row, column),
203 flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=4)
206 container.Add(label, (row, column),
207 flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=8)
212 if event.GetId() != ID_SAVELOADSETTINGS:
216 save_settings_dialog.CenterOnParent()
217 value = save_settings_dialog.ShowModal()
220 picker.SetColour(self.
_settings_settings[picker.key])
225 picker.SetColour(defaults[picker.key])
229 location = (
"Grid Editor",)
230 title =
"Grid Editor Settings"
234 super(GridEditorPreferences, self).
__init__(
235 settings[self.
namename], *args, **kwargs)
240 sizer = wx.FlexGridSizer(rows=6, cols=2, vgap=10, hgap=10)
241 l_col_size = self.
_label_for_label_for(
'Default column size')
243 background_color = Colour(
"light gray")
244 foreground_color = Colour(
"black")
245 l_col_size.SetForegroundColour(foreground_color)
246 l_col_size.SetBackgroundColour(background_color)
247 l_col_size.SetOwnBackgroundColour(background_color)
248 l_col_size.SetOwnForegroundColour(foreground_color)
249 sizer.Add(l_col_size)
250 sizer.Add(self.
_number_editor_number_editor(settings,
'col size'))
251 l_auto_size, editor =
boolean_editor(self, settings,
'auto size cols',
'Auto size columns')
253 l_auto_size.SetForegroundColour(foreground_color)
254 l_auto_size.SetBackgroundColour(background_color)
255 l_auto_size.SetOwnBackgroundColour(background_color)
256 l_auto_size.SetOwnForegroundColour(foreground_color)
257 sizer.AddMany([l_auto_size, editor])
258 l_max_size = self.
_label_for_label_for(
'Max column size\n(applies when auto size is on)')
260 l_max_size.SetForegroundColour(foreground_color)
261 l_max_size.SetBackgroundColour(background_color)
262 l_max_size.SetOwnBackgroundColour(background_color)
263 l_max_size.SetOwnForegroundColour(foreground_color)
264 sizer.Add(l_max_size)
265 sizer.Add(self.
_number_editor_number_editor(settings,
'max col size'))
266 l_word_wrap, editor =
boolean_editor(self, settings,
'word wrap',
'Word wrap and auto size rows')
268 l_word_wrap.SetForegroundColour(foreground_color)
269 l_word_wrap.SetBackgroundColour(background_color)
270 l_word_wrap.SetOwnBackgroundColour(background_color)
271 l_word_wrap.SetOwnForegroundColour(foreground_color)
272 sizer.AddMany([l_word_wrap, editor])
276 label = (
'%s: ' % name).capitalize()
277 return Label(self, label=label)
280 initial_value = settings[name]
281 editor = NumCtrl(self, value=initial_value, integerWidth=3, allowNone=
True)
283 editor.SetBackgroundColour(Colour(200, 222, 40))
284 editor.SetOwnBackgroundColour(Colour(200, 222, 40))
285 editor.SetForegroundColour(Colour(7, 0, 70))
286 editor.SetOwnForegroundColour(Colour(7, 0, 70))
288 editor.Bind(wx.EVT_TEXT,
lambda evt: self.
_set_value_set_value(editor, name))
294 value = editor.GetValue()
295 if value
is not None:
299 colors_sizer = wx.GridBagSizer()
307 (
'text user keyword',
'User Keyword Foreground'),
308 (
'text library keyword',
'Library Keyword Foreground'),
309 (
'text variable',
'Variable Foreground'),
310 (
'text unknown variable',
'Unknown Variable Foreground'),
311 (
'text commented',
'Comments Foreground'),
312 (
'text string',
'Default Foreground'),
313 (
'text empty',
'Empty Foreground'),
315 lbl = wx.StaticText(self, wx.ID_ANY, label)
317 background_color = Colour(
"light gray")
318 foreground_color = Colour(
"black")
319 lbl.SetForegroundColour(foreground_color)
320 lbl.SetBackgroundColour(background_color)
321 lbl.SetOwnBackgroundColour(background_color)
322 lbl.SetOwnForegroundColour(foreground_color)
324 self, wx.ID_ANY, self.
_settings_settings, key)
326 colors_sizer.Add(btn, (row, 2),
327 flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=4)
328 colors_sizer.Add(lbl, (row, 3),
329 flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=4)
335 background_color = Colour(
"light gray")
336 foreground_color = Colour(
"black")
338 (
'background assign',
'Variable Background'),
339 (
'background keyword',
'Keyword Background'),
340 (
'background mandatory',
'Mandatory Field Background'),
341 (
'background optional',
'Optional Field Background'),
342 (
'background must be empty',
'Mandatory Empty Field Background'),
343 (
'background unknown',
'Unknown Background'),
344 (
'background error',
'Error Background'),
345 (
'background highlight',
'Highlight Background')
347 lbl = wx.StaticText(self, wx.ID_ANY, label)
349 lbl.SetForegroundColour(foreground_color)
350 lbl.SetBackgroundColour(background_color)
351 lbl.SetOwnBackgroundColour(background_color)
352 lbl.SetOwnForegroundColour(foreground_color)
354 self, wx.ID_ANY, self.
_settings_settings, key)
356 colors_sizer.Add(btn, (row, 0),
357 flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=4)
358 colors_sizer.Add(lbl, (row, 1),
359 flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=4)
363 if event.GetId() != ID_SAVELOADSETTINGS:
367 save_settings_dialog.CenterOnParent()
368 value = save_settings_dialog.ShowModal()
371 picker.SetColour(self.
_settings_settings[picker.key])
375 location = (
"Test Runner",)
376 title =
"Test Runner Settings"
380 super(TestRunnerPreferences, self).
__init__(
381 settings[
'Plugins'][self.
namename], *args, **kwargs)
385 self.
_settings_settings.get(
'confirm run',
True)
386 self.
_settings_settings.get(
'use colors',
False)
388 sizer = wx.FlexGridSizer(rows=6, cols=2, vgap=10, hgap=10)
389 from sys
import platform
390 if platform.endswith(
'win32'):
391 add_colors =
"-C ansi"
394 l_usecolor, usecolor =
boolean_editor(self, settings,
'use colors',
395 f
"Shows console colors set by {add_colors} ")
397 'Asks for confirmation to run all tests if none selected ')
399 background_color = Colour(
"light gray")
400 foreground_color = Colour(
"black")
401 l_confirm.SetForegroundColour(foreground_color)
402 l_confirm.SetBackgroundColour(background_color)
403 l_confirm.SetOwnBackgroundColour(background_color)
404 l_confirm.SetOwnForegroundColour(foreground_color)
405 l_usecolor.SetForegroundColour(foreground_color)
406 l_usecolor.SetBackgroundColour(background_color)
407 l_usecolor.SetOwnBackgroundColour(background_color)
408 l_usecolor.SetOwnForegroundColour(foreground_color)
409 sizer.AddMany([l_usecolor, usecolor])
410 sizer.AddMany([l_confirm, editor])
414 container = wx.GridBagSizer()
418 background_color = Colour(
"light gray")
419 foreground_color = Colour(
"black")
420 for settings_key, label_text
in (
421 (
'foreground',
'Text foreground'),
422 (
'background',
'Text background'),
423 (
'error',
'Error foreground'),
424 (
'fail color',
'Fail foreground'),
425 (
'pass color',
'Pass foreground'),
426 (
'skip color',
'Skip foreground'),
431 label = wx.StaticText(self, wx.ID_ANY, label_text)
433 label.SetForegroundColour(foreground_color)
434 label.SetBackgroundColour(background_color)
435 label.SetOwnBackgroundColour(background_color)
436 label.SetOwnForegroundColour(foreground_color)
438 self, wx.ID_ANY, self.
_settings_settings, settings_key)
439 container.Add(button, (row, column),
440 flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=4)
443 container.Add(label, (row, column),
444 flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=8)
449 if event.GetId() != ID_SAVELOADSETTINGS:
453 save_settings_dialog.CenterOnParent()
454 value = save_settings_dialog.ShowModal()
457 picker.SetColour(self.
_settings_settings[picker.key])
462 picker.SetColour(defaults[picker.key])
def create_colors_sizer(self)
def __init__(self, settings, *args, **kwargs)
def _read_defaults(self, plugin=False)
def OnSaveLoadSettings(self, event)
def _create_font_editor(self)
def create_colors_sizer(self)
def _create_foreground_pickers(self, colors_sizer)
def _create_background_pickers(self, colors_sizer)
def __init__(self, settings, *args, **kwargs)
def OnSaveLoadSettings(self, event)
def _create_grid_config_editor(self)
def _number_editor(self, settings, name)
def _set_value(self, editor, name)
def _label_for(self, name)
def __init__(self, settings, *args, **kwargs)
def create_colors_sizer(self)
def OnSaveLoadSettings(self, event)
def _create_test_runner_config_editor(self)
def create_colors_sizer(self)
def __init__(self, settings, *args, **kwargs)
def OnSaveLoadSettings(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 ReadFonts(fixed=False)
Returns list with fixed width fonts.
def boolean_editor(parent, settings, name, label, help='')