Robot Framework Integrated Development Environment (RIDE)
configmanagerui.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 from wx import Colour
18 from wx.lib.mixins.listctrl import TextEditMixin
19 
20 from ..editor.listeditor import AutoWidthColumnList, ListEditorBase
21 from ..widgets import RIDEDialog, HelpLabel, ButtonWithHandler
22 
23 
26 _CONFIG_HELP = """The specified command string will be split from whitespaces into a command
27 and its arguments. If either the command or any of the arguments require
28 internal spaces, they must be written as '<SPACE>'.\n
29 The command will be executed in the system directly without opening a shell.
30 This means that shell commands and extensions are not available. For example,
31 in Windows batch files to execute must contain the '.bat' extension and 'dir'
32 command does not work.\n
33 Examples:
34  robot.bat --include smoke C:\\my_tests
35  svn update /home/robot
36  C:\\Program<SPACE>Files\\App\\prg.exe argument<SPACE>with<SPACE>space,
37 Run configurations are stored in the RIDE settings file.
38 """
39 
40 
41 class ConfigManagerDialog(RIDEDialog):
42 
43  def __init__(self, configs, plugin):
44  RIDEDialog.__init__(self, title='Manage Run Configurations')
45  # set Left to Right direction (while we don't have localization)
46 
47  self.SetBackgroundColour(Colour(self.color_background))
48  self.SetOwnBackgroundColour(Colour(self.color_background))
49  self.SetForegroundColour(Colour(self.color_foreground))
50  self.SetOwnForegroundColour(Colour(self.color_foreground))
51 
52  self.SetLayoutDirection(wx.Layout_LeftToRight)
53  self.pluginplugin = plugin
54  self._create_ui_create_ui(configs)
55 
56  def _create_ui(self, configs):
57  self.SetSizer(wx.BoxSizer(wx.VERTICAL))
58  self._editor_editor = self._create_editor_create_editor(configs)
59  self._create_help_create_help()
60  self._create_line_create_line()
61  self._create_buttons_create_buttons()
62  self.SetSize((750, 400))
63 
64  def _create_editor(self, configs):
65  editor = _ConfigListEditor(self, configs)
66  self.Sizer.Add(editor, flag=wx.GROW, proportion=1)
67  return editor
68 
69  def _create_help(self):
70  help = HelpLabel(self, label=_CONFIG_HELP)
71  help.Wrap(700)
72  self.Sizer.Add(help, border=5, flag=wx.TOP)
73 
74  def _create_line(self):
75  line = wx.StaticLine(self, size=(20, -1), style=wx.LI_HORIZONTAL)
76  if wx.VERSION < (4, 1, 0):
77  self.Sizer.Add(line, border=5, flag=wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP)
78  else:
79  self.Sizer.Add(line, border=5, flag=wx.GROW | wx.RIGHT | wx.TOP)
80 
81  def _create_buttons(self):
82  buttons = self.CreateStdDialogButtonSizer(wx.OK|wx.CANCEL)
83  self.SetBackgroundColour(Colour(self.color_background))
84  self.SetForegroundColour(Colour(self.color_foreground))
85  for item in self.GetChildren():
86  if isinstance(item, (wx.Button, wx.BitmapButton, ButtonWithHandler)):
87  item.SetBackgroundColour(Colour(self.color_secondary_background))
88  item.SetOwnBackgroundColour(Colour(self.color_secondary_background))
89  item.SetForegroundColour(Colour(self.color_secondary_foreground))
90  item.SetOwnForegroundColour(Colour(self.color_secondary_foreground))
91  self.Sizer.Add(buttons, flag=wx.ALIGN_CENTER | wx.ALL, border=5)
92 
93  def get_data(self):
94  return self._editor_editor.get_data()
95 
96 
98 
101  _buttons = ['New', 'Remove']
102 
105  _columns = ['Name', 'Command', 'Documentation']
106 
107  def __init__(self, parent, configs):
108  self._editor_open_editor_open = False
109  ListEditorBase.__init__(self, parent, self._columns_columns, configs)
110 
111  def _create_list(self, columns, data):
112  return _TextEditListCtrl(self, columns, color_foreground=self.color_secondary_foregroundcolor_secondary_foreground,
113  color_background=self.color_secondary_backgroundcolor_secondary_background, data=data)
114 
115  def get_column_values(self, config):
116  return config.name, config.command, config.doc
117 
118  def get_data(self):
119  return self._list_list.get_data()
120 
121  def OnEdit(self, event):
122  self._list_list.open_editor(self._selection_selection)
123 
124  def OnNew(self, event):
125  self._list_list.new_item()
126 
127  def OnRemove(self, event):
128  self.OnDeleteOnDeleteOnDelete(event)
129 
130  def new_config(self, data):
131  self._controller_controller.add(*data)
132 
133  def edit_config(self, index, data):
134  self._controller_controller.edit(index, *data)
135 
136  def OnDelete(self, event):
137  if not self._editor_open_editor_open:
138  ListEditorBase.OnDelete(self, event)
139 
140  def editor_open(self):
141  self._editor_open_editor_open = True
142 
143  def editor_closed(self):
144  self._editor_open_editor_open = False
145 
146 
148  last_index = property(lambda self: self.ItemCount - 1)
149 
150  def __init__(self, parent, columns, color_foreground, color_background, data):
151  AutoWidthColumnList.__init__(self, parent, columns, color_foreground=color_foreground,
152  color_background=color_background, data=data)
153  TextEditMixin.__init__(self)
154 
155  self.SetBackgroundColour(Colour(color_background))
156  self.SetForegroundColour(Colour(color_foreground))
157 
158  self._set_command_column_width_set_command_column_width()
159  self.col_locscol_locs = self._calculate_col_locs_calculate_col_locs()
160  self._new_item_creation_new_item_creation = False
161 
163  self.SetColumnWidth(1, 250)
164 
165 
173  locations = [0]
174  loc = 0
175  for n in range(self.GetColumnCount()):
176  loc = loc + self.GetColumnWidth(n)
177  locations.append(loc)
178  return locations
179 
180  def open_editor(self, row):
181  self.OpenEditorOpenEditor(0, row)
182 
183  def OpenEditor(self, col, row):
184  self._parent_parent.editor_open()
185  TextEditMixin.OpenEditor(self, col, row)
186 
187  def new_item(self):
188  self._new_item_creation_new_item_creation = True
189  self.InsertItem(self.ItemCount, '')
190  self.Select(self.ItemCount-1, True)
191  self.open_editoropen_editor(self.last_indexlast_index)
192 
193  def get_data(self):
194  return [ self._get_row_get_row(row) for row in range(self.ItemCount) ]
195 
196  def _get_row(self, row):
197  return [ self.GetItem(row, col).GetText() for col in range(3)]
198 
199  def CloseEditor(self, event=None):
200  TextEditMixin.CloseEditor(self, event)
201  # It seems that this is called twice per editing action and in the
202  # first time the value may be empty.
203  # End new item creation only when there really is a value
204  lastrow = self._get_row_get_row(self.last_indexlast_index)
205  if self._new_item_creation_new_item_creation:
206  if any(lastrow):
207  self._new_item_creation_new_item_creation = False
208  self.Parent.new_config(lastrow)
209  else:
210  self.Parent.edit_config(self.curRow, self._get_row_get_row(self.curRow))
211  self.Select(self.curRow)
212  self._parent_parent.editor_closed()
def __init__(self, parent, columns, color_foreground, color_background, data)
def _calculate_col_locs(self)
Calculates and returns initial locations of colums.