21 from ..context
import IS_LINUX
22 from ..widgets
import HelpLabel, Label, TextField
27 location = (
"Preferences",)
30 def __init__(self, parent=None, *args, **kwargs):
32 wx.Panel.__init__(self, parent, *args, **kwargs)
34 self.SetBackgroundColour(Colour(200, 222, 40))
35 self.SetOwnBackgroundColour(Colour(200, 222, 40))
36 self.SetForegroundColour(Colour(7, 0, 70))
37 self.SetOwnForegroundColour(Colour(7, 0, 70))
41 return getattr(self,
"title", self.
locationlocation[-1])
45 container = wx.Panel(parent, wx.ID_ANY)
46 label = wx.StaticText(container, wx.ID_ANY, label=title)
48 label.SetBackgroundColour(Colour(200, 222, 40))
49 label.SetOwnBackgroundColour(Colour(200, 222, 40))
50 label.SetForegroundColour(Colour(7, 0, 70))
51 label.SetOwnForegroundColour(Colour(7, 0, 70))
53 sep = wx.StaticLine(container, wx.ID_ANY)
55 sep.SetBackgroundColour(Colour(200, 222, 40))
56 sep.SetOwnBackgroundColour(Colour(200, 222, 40))
57 sep.SetForegroundColour(Colour(7, 0, 70))
58 sep.SetOwnForegroundColour(Colour(7, 0, 70))
60 sizer = wx.BoxSizer(wx.VERTICAL)
61 sizer.Add(label, 0, wx.EXPAND|wx.TOP, 8)
62 sizer.Add(sep, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 2)
63 container.SetSizerAndFit(sizer)
69 def __init__(self, parent, id, settings, key, choices):
74 choices=choices, style=wx.CB_READONLY)
76 self.SetBackgroundColour(Colour(200, 222, 40))
77 self.SetOwnBackgroundColour(Colour(200, 222, 40))
78 self.SetForegroundColour(Colour(7, 0, 70))
79 self.SetOwnForegroundColour(Colour(7, 0, 70))
81 self.Bind(wx.EVT_COMBOBOX, self.
OnSelectOnSelect)
94 if IS_LINUX
and choices:
95 return wx.Size(max(max(len(str(s))
for s
in choices) * 9, 144), 20)
99 self.
_set_value_set_value(str(event.GetEventObject().GetValue()))
119 def __init__(self, parent, id, settings, key, choices):
122 super(PreferencesSpinControl, self).
__init__(parent, id,
123 size=self.
_get_size_get_size(choices[-1]))
124 self.SetRange(*choices)
127 self.SetBackgroundColour(Colour(200, 222, 40))
128 self.SetOwnBackgroundColour(Colour(200, 222, 40))
129 self.SetForegroundColour(Colour(7, 0, 70))
130 self.SetOwnForegroundColour(Colour(7, 0, 70))
132 self.Bind(wx.EVT_SPINCTRL, self.
OnChangeOnChange)
133 self.Bind(wx.EVT_TEXT, self.
OnChangeOnChange)
146 if IS_LINUX
and max_value:
147 return wx.Size(max(len(str(max_value)) * 9, 144), 20)
148 return wx.DefaultSize
151 self.
_set_value_set_value(event.GetEventObject().GetValue())
164 value = Colour(settings[key])
165 super(PreferencesColorPicker, self).
__init__(parent, id, colour=value)
167 self.SetBackgroundColour(Colour(200, 222, 40))
168 self.SetOwnBackgroundColour(Colour(200, 222, 40))
169 self.SetForegroundColour(Colour(7, 0, 70))
170 self.SetOwnForegroundColour(Colour(7, 0, 70))
172 self.Bind(wx.EVT_COLOURPICKER_CHANGED, self.
OnPickColorOnPickColor)
176 color = event.GetColour()
177 rgb = color.GetAsString(flags=wx.C2S_HTML_SYNTAX)
182 super(PreferencesColorPicker, self).
SetColour(colour)
193 def __init__(self, settings, setting_name, label, choices, help=''):
205 return wx.StaticText(parent, wx.NewId(), self.
_label_label)
208 return HelpLabel(parent,
'\n'.join(textwrap.wrap(self.
_help_help, 60)))
215 _editor_class = PreferencesComboBox
222 _editor_class = IntegerPreferenceComboBox
229 _editor_class = PreferencesSpinControl
235 editor.SetBackgroundColour(Colour(200, 222, 40))
236 editor.SetOwnBackgroundColour(Colour(200, 222, 40))
237 editor.SetForegroundColour(Colour(7, 0, 70))
238 editor.SetOwnForegroundColour(Colour(7, 0, 70))
240 label = Label(parent, label=label)
245 initial_value = settings.get(name,
"")
246 editor = wx.CheckBox(parent)
247 editor.SetValue(initial_value)
248 editor.Bind(wx.EVT_CHECKBOX,
lambda evt: settings.set(name, editor.GetValue()))
249 editor.SetToolTip(help)
254 initial_value =
', '.join(settings.get(name,
""))
255 editor = TextField(parent, initial_value)
257 editor.SetBackgroundColour(Colour(200, 222, 40))
258 editor.SetOwnBackgroundColour(Colour(200, 222, 40))
259 editor.SetForegroundColour(Colour(7, 0, 70))
260 editor.SetOwnForegroundColour(Colour(7, 0, 70))
262 editor.SetToolTip(help)
265 new_value = [token.strip()
for token
in editor.GetValue().split(
',')
267 settings.set(name, new_value)
269 editor.Bind(wx.EVT_KILL_FOCUS,
lambda evt: set_value(evt))
271 return Label(parent, label=label), editor
A combobox tied to a setting that has integer values.
def _set_value(self, value)
A colored button that opens a color picker dialog.
def OnPickColor(self, event)
Set the color for the given key to the color of the widget.
def SetColour(self, colour)
def __init__(self, parent, id, settings, key)
A combobox tied to a specific setting.
def OnSelect(self, event)
def _set_value(self, value)
def __init__(self, parent, id, settings, key, choices)
def _get_size(self, choices=[])
In Linux with GTK3 wxPython 4, there was not enough spacing.
Base class for all preference panels used by PreferencesDialog.
def __init__(self, parent=None, *args, **kwargs)
def Separator(self, parent, title)
Creates a simple horizontal separator with title.
A spin control tied to a specific setting.
def _get_size(self, max_value)
In Linux with GTK3 wxPython 4, there was not enough spacing.
def _set_value(self, value)
def __init__(self, parent, id, settings, key, choices)
def OnChange(self, event)
def chooser(self, parent)
def __init__(self, settings, setting_name, label, choices, help='')
def comma_separated_value_editor(parent, settings, name, label, help='')
def boolean_editor(parent, settings, name, label, help='')
def _create_checkbox_editor(parent, settings, name, help)