Robot Framework Integrated Development Environment (RIDE)
preferences_dialogs.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import textwrap
17 
18 import wx
19 from wx import Colour
20 
21 from ..context import IS_LINUX
22 from ..widgets import HelpLabel, Label, TextField
23 
24 
25 
26 class PreferencesPanel(wx.Panel):
27  location = ("Preferences",)
28  title = "Preferences"
29 
30  def __init__(self, parent=None, *args, **kwargs):
31  self.tree_itemtree_item = None
32  wx.Panel.__init__(self, parent, *args, **kwargs)
33  """
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))
38  """
39 
40  def GetTitle(self):
41  return getattr(self, "title", self.locationlocation[-1])
42 
43 
44  def Separator(self, parent, title):
45  container = wx.Panel(parent, wx.ID_ANY)
46  label = wx.StaticText(container, wx.ID_ANY, label=title)
47  """
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))
52  """
53  sep = wx.StaticLine(container, wx.ID_ANY)
54  """
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))
59  """
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)
64  return container
65 
66 
67 
68 class PreferencesComboBox(wx.ComboBox):
69  def __init__(self, parent, id, settings, key, choices):
70  self.settingssettings = settings
71  self.keykey = key
72  super(PreferencesComboBox, self).__init__(parent, id, self._get_value_get_value(),
73  size=self._get_size_get_size(choices),
74  choices=choices, style=wx.CB_READONLY)
75  """
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))
80  """
81  self.Bind(wx.EVT_COMBOBOX, self.OnSelectOnSelect)
82 
83  def _get_value(self):
84  return self.settingssettings[self.keykey]
85 
86 
93  def _get_size(self, choices=[]):
94  if IS_LINUX and choices:
95  return wx.Size(max(max(len(str(s)) for s in choices) * 9, 144), 20)
96  return wx.DefaultSize
97 
98  def OnSelect(self, event):
99  self._set_value_set_value(str(event.GetEventObject().GetValue()))
100  self.settingssettings.save()
101 
102  def _set_value(self, value):
103  self.settingssettings[self.keykey] = value
104 
105 
106 
108 
109  def _get_value(self):
110  return str(self.settingssettings[self.keykey])
111 
112  def _set_value(self, value):
113  self.settingssettings[self.keykey] = int(value)
114 
115 
116 
117 class PreferencesSpinControl(wx.SpinCtrl):
118 
119  def __init__(self, parent, id, settings, key, choices):
120  self.settingssettings = settings
121  self.keykey = key
122  super(PreferencesSpinControl, self).__init__(parent, id,
123  size=self._get_size_get_size(choices[-1]))
124  self.SetRange(*choices)
125  self.SetValue(self._get_value_get_value())
126  """
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))
131  """
132  self.Bind(wx.EVT_SPINCTRL, self.OnChangeOnChange)
133  self.Bind(wx.EVT_TEXT, self.OnChangeOnChange)
134 
135  def _get_value(self):
136  return self.settingssettings[self.keykey]
137 
138 
145  def _get_size(self, max_value):
146  if IS_LINUX and max_value:
147  return wx.Size(max(len(str(max_value)) * 9, 144), 20)
148  return wx.DefaultSize
149 
150  def OnChange(self, event):
151  self._set_value_set_value(event.GetEventObject().GetValue())
152  self.settingssettings.save()
153 
154  def _set_value(self, value):
155  self.settingssettings[self.keykey] = value
156 
157 
158 
159 class PreferencesColorPicker(wx.ColourPickerCtrl):
160  def __init__(self, parent, id, settings, key):
161  self.settingssettings = settings
162  self.keykey = key
163  # print(f"DEBUG: Preferences ColourPicker value type {type(settings[key])}")
164  value = Colour(settings[key])
165  super(PreferencesColorPicker, self).__init__(parent, id, colour=value)
166  """
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))
171  """
172  self.Bind(wx.EVT_COLOURPICKER_CHANGED, self.OnPickColorOnPickColor)
173 
174 
175  def OnPickColor(self, event):
176  color = event.GetColour()
177  rgb = color.GetAsString(flags=wx.C2S_HTML_SYNTAX)
178  self.settingssettings[self.keykey] = rgb
179  self.settingssettings.save()
180 
181  def SetColour(self, colour):
182  super(PreferencesColorPicker, self).SetColour(colour)
183  self.settingssettings[self.keykey] = colour
184  self.settingssettings.save()
185 
186 
188 
191  _editor_class = None
192 
193  def __init__(self, settings, setting_name, label, choices, help=''):
194  self._settings_settings = settings
195  self._setting_name_setting_name = setting_name
196  self._label_label = label
197  self._choices_choices = choices
198  self._help_help = help
199 
200  def chooser(self, parent):
201  return self._editor_class_editor_class(parent, wx.NewId(), self._settings_settings,
202  key=self._setting_name_setting_name, choices=self._choices_choices)
203 
204  def label(self, parent):
205  return wx.StaticText(parent, wx.NewId(), self._label_label)
206 
207  def help(self, parent):
208  return HelpLabel(parent, '\n'.join(textwrap.wrap(self._help_help, 60)))
209 
210 
212 
215  _editor_class = PreferencesComboBox
216 
217 
219 
222  _editor_class = IntegerPreferenceComboBox
223 
224 
226 
229  _editor_class = PreferencesSpinControl
230 
231 
232 def boolean_editor(parent, settings, name, label, help=''):
233  editor = _create_checkbox_editor(parent, settings, name, help)
234  """
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))
239  """
240  label = Label(parent, label=label)
241  return label, editor
242 
243 
244 def _create_checkbox_editor(parent, settings, name, help):
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)
250  return editor
251 
252 
253 def comma_separated_value_editor(parent, settings, name, label, help=''):
254  initial_value = ', '.join(settings.get(name, ""))
255  editor = TextField(parent, initial_value)
256  """
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))
261  """
262  editor.SetToolTip(help)
263 
264  def set_value(evt):
265  new_value = [token.strip() for token in editor.GetValue().split(',')
266  if token.strip()]
267  settings.set(name, new_value)
268  evt.Skip()
269  editor.Bind(wx.EVT_KILL_FOCUS, lambda evt: set_value(evt))
270 
271  return Label(parent, label=label), editor
A combobox tied to a setting that has integer values.
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 __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 __init__(self, parent, id, settings, key, choices)
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)