Robot Framework Integrated Development Environment (RIDE)
editordialogs.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 wx
17 
18 from wx import Colour
19 from .. import utils
20 from ..namespace.suggesters import ResourceSuggester, LibrariesSuggester, HistorySuggester
21 from ..validators import (ScalarVariableNameValidator, ListVariableNameValidator, TimeoutValidator, ArgumentsValidator,
22  TestCaseNameValidator, UserKeywordNameValidator, DictionaryVariableNameValidator)
23 from ..widgets import HelpLabel, RIDEDialog, ButtonWithHandler
24 from .dialoghelps import get_help
25 from .fieldeditors import (ValueEditor, ListValueEditor, MultiLineEditor, ContentAssistEditor, VariableNameEditor,
26  ArgumentEditor, FileNameEditor)
27 from .formatters import ListToStringFormatter
28 
29 
30 def EditorDialog(obj):
31  return globals()[obj.label.replace(' ', '') + 'Dialog']
32 
33 
34 class _Dialog(RIDEDialog):
35 
38  _title = property(lambda self: utils.name_from_class(self, drop='Dialog'))
39 
40  def __init__(self, controller, item=None, plugin=None):
41  # TODO: Get rid of item, everything should be in controller
42  RIDEDialog.__init__(self, self._title_title)
43  # set Left to Right direction (while we don't have localization)
44  self.SetLayoutDirection(wx.Layout_LeftToRight)
45  self.SetExtraStyle(wx.WS_EX_VALIDATE_RECURSIVELY)
46  self._controller_controller = controller
47  self.pluginplugin = plugin
48  self._sizer_sizer = wx.BoxSizer(wx.VERTICAL)
49  self._editors_editors = self._get_editors(item)
50  for editor in self._editors_editors:
51  self._sizer_sizer.Add(editor, editor.expand_factor, wx.EXPAND)
52  self._add_comment_editor_add_comment_editor(item)
53  self._create_help_create_help()
54  self._create_line_create_line()
55  self._create_buttons_create_buttons()
56  self.SetSizer(self._sizer_sizer)
57  self._sizer_sizer.Fit(self)
58  self._editors_editors[0].set_focus()
59 
60  def _add_comment_editor(self, item):
61  comment = ListToStringFormatter(item.comment).value if item else ''
62  self._comment_editor_comment_editor = ValueEditor(self, comment, 'Comment')
63  self._sizer_sizer.Add(self._comment_editor_comment_editor)
64 
65  def _create_line(self):
66  line = wx.StaticLine(self, size=(20,-1), style=wx.LI_HORIZONTAL)
67  if wx.VERSION < (4, 1, 0):
68  self._sizer_sizer.Add(line, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5)
69  else:
70  self._sizer_sizer.Add(line, 0, wx.GROW | wx.RIGHT | wx.TOP, 5)
71 
72  def _create_help(self):
73  self._sizer_sizer.Add(HelpLabel(self, label=get_help(self._title_title)),
74  flag=wx.ALL, border=2)
75 
76  def _create_buttons(self, **kwargs):
77  buttons = self.CreateStdDialogButtonSizer(wx.OK|wx.CANCEL)
78  self.SetBackgroundColour(Colour(self.color_background))
79  self.SetForegroundColour(Colour(self.color_foreground))
80  for item in self.GetChildren():
81  if isinstance(item, (wx.Button, wx.BitmapButton, ButtonWithHandler)):
82  item.SetBackgroundColour(Colour(self.color_secondary_background))
83  item.SetOwnBackgroundColour(Colour(self.color_secondary_background))
84  item.SetForegroundColour(Colour(self.color_secondary_foreground))
85  item.SetOwnForegroundColour(Colour(self.color_secondary_foreground))
86  self._sizer_sizer.Add(buttons, 0, wx.ALIGN_CENTER|wx.ALL, 5)
87 
88  def get_value(self):
89  return [ e.get_value() for e in self._editors_editors ]
90 
91  def get_comment(self):
92  return self._comment_editor_comment_editor.get_value()
93 
94  def setFocusToOK(self):
95  self.FindWindowById(wx.ID_OK).SetFocus()
96 
97  def _execute(self):
98  pass
99 
100 
101 class ScalarVariableDialog(_Dialog):
102 
103  def _get_editors(self, var):
104  name = var.name if var and var.name else '${}'
105  value = var.value[0] if var else ''
106  validator = ScalarVariableNameValidator(self._controller_controller, name)
107  return [VariableNameEditor(self, name, 'Name', validator),
108  ValueEditor(self, value, 'Value')]
109 
110  def _execute(self):
111  pass
112 
113 
114 class ListVariableDialog(_Dialog):
115 
116  def _get_editors(self, var):
117  name = var.name if var and var.name else '@{}'
118  value = var.value if var and var.value else ''
119  validator = ListVariableNameValidator(self._controller_controller, name)
120  return [VariableNameEditor(self, name, 'Name', validator),
121  ListValueEditor(self, value, 'Value',
122  settings=self.pluginplugin.global_settings)]
123 
124  def _execute(self):
125  pass
126 
127 
128 class DictionaryVariableDialog(_Dialog):
129 
130  def _get_editors(self, var):
131  name = var.name if var and var.name else '&{}'
132  value = var.value if var and var.value else ''
133  validator = DictionaryVariableNameValidator(self._controller_controller, name)
134  return [VariableNameEditor(self, name, 'Name', validator),
135  ListValueEditor(self, value, 'Value',
136  settings=self.pluginplugin.global_settings)]
137 
138  def _execute(self):
139  pass
140 
141 
142 class LibraryDialog(_Dialog):
143 
144 
147  _history_suggester = HistorySuggester()
148 
149  def _get_editors(self, item):
150  name = item and item.name or ''
151  args = item and utils.join_value(item.args) or ''
152  alias = item.alias if item else ''
153  self._suggester_suggester = LibrariesSuggester(self._controller_controller, self._history_suggester_history_suggester)
154  return [FileNameEditor(self, name, 'Name', self._controller_controller, suggestion_source=self._suggester_suggester),
155  ValueEditor(self, args, 'Args'),
156  ValueEditor(self, alias, 'Alias')]
157 
158  def get_value(self):
159  values = _Dialog.get_value(self)
160  self._history_suggester_history_suggester.store(values[0])
161  return values
162 
163  def _execute(self):
164  pass
165 
166 
167 class VariablesDialog(LibraryDialog):
168 
169 
172  _history_suggester = HistorySuggester()
173 
174  def _get_editors(self, item):
175  path = item and item.name or ''
176  args = item and utils.join_value(item.args) or ''
177  return [FileNameEditor(self, path, 'Path', self._controller_controller, suggestion_source=self._history_suggester_history_suggester_history_suggester),
178  ValueEditor(self, args, 'Args')]
179 
180  def _execute(self):
181  pass
182 
183 
184 class ResourceDialog(_Dialog):
185 
186  def _get_editors(self, item):
187  name = item and item.name or ''
188  return [FileNameEditor(self, name, 'Path', self._controller_controller,
189  suggestion_source=ResourceSuggester(self._controller_controller))]
190 
191  def _execute(self):
192  pass
193 
194 
195 class DocumentationDialog(_Dialog):
196 
197  def _get_editors(self, doc):
198  return [MultiLineEditor(self, doc)]
199 
200  def _add_comment_editor(self, item):
201  pass
202 
203  def get_value(self):
204  return _Dialog.get_value(self)
205 
206  def get_comment(self):
207  return ''
208 
209  def _execute(self):
210  pass
211 
212 
213 class _SettingDialog(_Dialog):
214 
217  _validator = None
218 
219  def _get_editors(self, item):
220  editor = ValueEditor(self, item.value)
221  if self._validator_validator:
222  editor.set_validator(self._validator_validator())
223  return [editor]
224 
225  def _execute(self):
226  pass
227 
228 
229 class ForceTagsDialog(_SettingDialog):
230  def _execute(self):
231  pass
232 
233 
234 class DefaultTagsDialog(_SettingDialog):
235  def _execute(self):
236  pass
237 
238 
239 class TagsDialog(_SettingDialog):
240  def _execute(self):
241  pass
242 
243 
244 class _FixtureDialog(_SettingDialog):
245 
246  def _get_editors(self, item):
247  return [ContentAssistEditor(self, item.value)]
248 
249  def _execute(self):
250  pass
251 
252 
253 class SuiteSetupDialog(_FixtureDialog):
254  tooltip = "Suite Setup is run before any tests"
255 
256  def _execute(self):
257  pass
258 
259 
260 class SuiteTeardownDialog(_FixtureDialog):
261  def _execute(self):
262  pass
263 
264 
265 class TestSetupDialog(_FixtureDialog):
266  def _execute(self):
267  pass
268 
269 
270 class TestTeardownDialog(_FixtureDialog):
271  def _execute(self):
272  pass
273 
274 
275 class SetupDialog(_FixtureDialog):
276  def _execute(self):
277  pass
278 
279 
280 class TeardownDialog(_FixtureDialog):
281  def _execute(self):
282  pass
283 
284 
285 class TemplateDialog(_FixtureDialog):
286  def _execute(self):
287  pass
288 
289 
290 class TestTemplateDialog(_FixtureDialog):
291  def _execute(self):
292  pass
293 
294 
295 class ArgumentsDialog(_SettingDialog):
296  def _get_editors(self, item):
297  return [ArgumentEditor(self, item.value, 'Arguments', ArgumentsValidator())]
298 
299  def _execute(self):
300  pass
301 
302 
303 class ReturnValueDialog(_SettingDialog):
304  def _execute(self):
305  pass
306 
307 
308 class TestTimeoutDialog(_SettingDialog):
309 
312  _validator = TimeoutValidator
313 
314  def _execute(self):
315  pass
316 
317 
318 class TimeoutDialog(TestTimeoutDialog):
319  def _execute(self):
320  pass
321 
322 
323 class MetadataDialog(_Dialog):
324 
325  def _get_editors(self, item):
326  name, value = item and (item.name, item.value) or ('', '')
327  return [ValueEditor(self, name, 'Name'),
328  ValueEditor(self, value, 'Value')]
329 
330  def _execute(self):
331  pass
332 
333 
334 class TestCaseNameDialog(_Dialog):
335 
338  _title = 'New Test Case'
339 
340  def _add_comment_editor(self, item):
341  pass
342 
343  def _get_editors(self, test):
344  value = test.name if test else ''
345  return [ValueEditor(self, value, 'Name',
346  TestCaseNameValidator(self._controller))]
347 
348  def get_name(self):
349  return _Dialog.get_value(self)[0]
350 
351  def _execute(self):
352  pass
353 
354 
355 class CopyUserKeywordDialog(_Dialog):
356 
359  _title = 'Copy User Keyword'
360 
361  def _add_comment_editor(self, item):
362  pass
363 
364  def _get_editors(self, uk):
365  value = uk.name if uk else ''
366  return [ValueEditor(self, value, 'Name',
367  UserKeywordNameValidator(self._controller))]
368 
369  def get_name(self):
370  return _Dialog.get_value(self)[0]
371 
372  def _execute(self):
373  pass
374 
375 
376 class UserKeywordNameDialog(_Dialog):
377  def _execute(self):
378  pass
379 
380 
383  _title = 'New User Keyword'
384 
385  def _add_comment_editor(self, item):
386  pass
387 
388  def _get_editors(self, uk):
389  value = uk.name if uk else ''
390  args_value = ' | '.join(uk.args.value) if uk else ''
391  return [ValueEditor(self, value, 'Name',
392  UserKeywordNameValidator(self._controller)),
393  ArgumentEditor(self, args_value, 'Arguments', ArgumentsValidator())]
394 
395  def get_name(self):
396  return _Dialog.get_value(self)[0]
397 
398  def get_args(self):
399  return _Dialog.get_value(self)[1]
def __init__(self, controller, item=None, plugin=None)