30 from controls import CustomGrid, CustomTable, DurationCellEditor |
30 from controls import CustomGrid, CustomTable, DurationCellEditor |
31 from dialogs.DurationEditorDialog import IEC_TIME_MODEL |
31 from dialogs.DurationEditorDialog import IEC_TIME_MODEL |
32 from EditorPanel import EditorPanel |
32 from EditorPanel import EditorPanel |
33 from util.BitmapLibrary import GetBitmap |
33 from util.BitmapLibrary import GetBitmap |
34 from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS, DefaultType |
34 from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS, DefaultType |
35 #------------------------------------------------------------------------------- |
35 from util.TranslationCatalogs import NoTranslate |
|
36 |
|
37 |
|
38 # ------------------------------------------------------------------------------- |
36 # Configuration Editor class |
39 # Configuration Editor class |
37 #------------------------------------------------------------------------------- |
40 # ------------------------------------------------------------------------------- |
38 |
41 |
39 [ID_CONFIGURATIONEDITOR, |
42 |
|
43 [ |
|
44 ID_CONFIGURATIONEDITOR, |
40 ] = [wx.NewId() for _init_ctrls in range(1)] |
45 ] = [wx.NewId() for _init_ctrls in range(1)] |
|
46 |
41 |
47 |
42 class ConfigurationEditor(EditorPanel): |
48 class ConfigurationEditor(EditorPanel): |
43 |
49 |
44 ID = ID_CONFIGURATIONEDITOR |
50 ID = ID_CONFIGURATIONEDITOR |
45 VARIABLE_PANEL_TYPE = "config" |
51 VARIABLE_PANEL_TYPE = "config" |
57 |
63 |
58 def HasNoModel(self): |
64 def HasNoModel(self): |
59 return self.Controler.GetEditedElement(self.TagName) is None |
65 return self.Controler.GetEditedElement(self.TagName) is None |
60 |
66 |
61 |
67 |
62 #------------------------------------------------------------------------------- |
68 # ------------------------------------------------------------------------------- |
63 # Resource Editor class |
69 # Resource Editor class |
64 #------------------------------------------------------------------------------- |
70 # ------------------------------------------------------------------------------- |
65 |
71 |
66 def GetTasksTableColnames(): |
72 def GetTasksTableColnames(): |
67 _ = lambda x : x |
73 _ = NoTranslate |
68 return [_("Name"), _("Triggering"), _("Single"), _("Interval"), _("Priority")] |
74 return [_("Name"), _("Triggering"), _("Single"), _("Interval"), _("Priority")] |
69 |
75 |
|
76 |
70 def GetTaskTriggeringOptions(): |
77 def GetTaskTriggeringOptions(): |
71 _ = lambda x : x |
78 _ = NoTranslate |
72 return [_("Interrupt"), _("Cyclic")] |
79 return [_("Interrupt"), _("Cyclic")] |
|
80 |
|
81 |
73 TASKTRIGGERINGOPTIONS_DICT = dict([(_(option), option) for option in GetTaskTriggeringOptions()]) |
82 TASKTRIGGERINGOPTIONS_DICT = dict([(_(option), option) for option in GetTaskTriggeringOptions()]) |
74 |
83 |
75 SingleCellEditor = lambda *x : wx.grid.GridCellChoiceEditor() |
84 |
|
85 def SingleCellEditor(*x): |
|
86 return wx.grid.GridCellChoiceEditor() |
|
87 |
76 |
88 |
77 def CheckSingle(single, varlist): |
89 def CheckSingle(single, varlist): |
78 return single in varlist |
90 return single in varlist |
79 |
91 |
80 |
92 |
81 def GetInstancesTableColnames(): |
93 def GetInstancesTableColnames(): |
82 _ = lambda x : x |
94 _ = NoTranslate |
83 return [_("Name"), _("Type"), _("Task")] |
95 return [_("Name"), _("Type"), _("Task")] |
|
96 |
84 |
97 |
85 class ResourceTable(CustomTable): |
98 class ResourceTable(CustomTable): |
86 |
99 |
87 """ |
100 """ |
88 A custom wx.grid.Grid Table using user supplied data |
101 A custom wx.grid.Grid Table using user supplied data |
152 grid.SetReadOnly(row, col, True) |
165 grid.SetReadOnly(row, col, True) |
153 interval = self.GetValueByName(row, colname) |
166 interval = self.GetValueByName(row, colname) |
154 if interval != "" and IEC_TIME_MODEL.match(interval.upper()) is None: |
167 if interval != "" and IEC_TIME_MODEL.match(interval.upper()) is None: |
155 error = True |
168 error = True |
156 elif colname == "Single": |
169 elif colname == "Single": |
157 editor = SingleCellEditor(self,colname) |
170 editor = SingleCellEditor(self, colname) |
158 editor.SetParameters(self.Parent.VariableList) |
171 editor.SetParameters(self.Parent.VariableList) |
159 if self.GetValueByName(row, "Triggering") != "Interrupt": |
172 if self.GetValueByName(row, "Triggering") != "Interrupt": |
160 grid.SetReadOnly(row, col, True) |
173 grid.SetReadOnly(row, col, True) |
161 single = self.GetValueByName(row, colname) |
174 single = self.GetValueByName(row, colname) |
162 if single != "" and not CheckSingle(single,self.Parent.VariableList): |
175 if single != "" and not CheckSingle(single, self.Parent.VariableList): |
163 error = True |
176 error = True |
164 elif colname == "Triggering": |
177 elif colname == "Triggering": |
165 editor = wx.grid.GridCellChoiceEditor() |
178 editor = wx.grid.GridCellChoiceEditor() |
166 editor.SetParameters(",".join(map(_, GetTaskTriggeringOptions()))) |
179 editor.SetParameters(",".join(map(_, GetTaskTriggeringOptions()))) |
167 elif colname == "Type": |
180 elif colname == "Type": |
183 highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] |
196 highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] |
184 grid.SetCellBackgroundColour(row, col, highlight_colours[0]) |
197 grid.SetCellBackgroundColour(row, col, highlight_colours[0]) |
185 grid.SetCellTextColour(row, col, highlight_colours[1]) |
198 grid.SetCellTextColour(row, col, highlight_colours[1]) |
186 self.ResizeRow(grid, row) |
199 self.ResizeRow(grid, row) |
187 |
200 |
188 |
201 # ------------------------------------------------------------------------------- |
189 #------------------------------------------------------------------------------- |
202 # Highlights showing functions |
190 # Highlights showing functions |
203 # ------------------------------------------------------------------------------- |
191 #------------------------------------------------------------------------------- |
|
192 |
204 |
193 def AddHighlight(self, infos, highlight_type): |
205 def AddHighlight(self, infos, highlight_type): |
194 row_highlights = self.Highlights.setdefault(infos[0], {}) |
206 row_highlights = self.Highlights.setdefault(infos[0], {}) |
195 col_highlights = row_highlights.setdefault(infos[1], []) |
207 col_highlights = row_highlights.setdefault(infos[1], []) |
196 col_highlights.append(highlight_type) |
208 col_highlights.append(highlight_type) |
206 col_highlights.remove(highlight_type) |
218 col_highlights.remove(highlight_type) |
207 if len(col_highlights) == 0: |
219 if len(col_highlights) == 0: |
208 row_highlights.pop(col) |
220 row_highlights.pop(col) |
209 |
221 |
210 |
222 |
211 |
|
212 class ResourceEditor(EditorPanel): |
223 class ResourceEditor(EditorPanel): |
213 |
224 |
214 VARIABLE_PANEL_TYPE = "resource" |
225 VARIABLE_PANEL_TYPE = "resource" |
215 |
226 |
216 def _init_Editor(self, parent): |
227 def _init_Editor(self, parent): |
217 self.Editor = wx.Panel(parent, style=wx.SUNKEN_BORDER|wx.TAB_TRAVERSAL) |
228 self.Editor = wx.Panel(parent, style=wx.SUNKEN_BORDER | wx.TAB_TRAVERSAL) |
218 |
229 |
219 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
230 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
220 main_sizer.AddGrowableCol(0) |
231 main_sizer.AddGrowableCol(0) |
221 main_sizer.AddGrowableRow(0) |
232 main_sizer.AddGrowableRow(0) |
222 main_sizer.AddGrowableRow(1) |
233 main_sizer.AddGrowableRow(1) |
223 |
234 |
224 tasks_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
235 tasks_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
225 tasks_sizer.AddGrowableCol(0) |
236 tasks_sizer.AddGrowableCol(0) |
226 tasks_sizer.AddGrowableRow(1) |
237 tasks_sizer.AddGrowableRow(1) |
227 main_sizer.AddSizer(tasks_sizer, border=5, |
238 main_sizer.AddSizer(tasks_sizer, border=5, |
228 flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
239 flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT) |
229 |
240 |
230 tasks_buttons_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
241 tasks_buttons_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
231 tasks_buttons_sizer.AddGrowableCol(0) |
242 tasks_buttons_sizer.AddGrowableCol(0) |
232 tasks_buttons_sizer.AddGrowableRow(0) |
243 tasks_buttons_sizer.AddGrowableRow(0) |
233 tasks_sizer.AddSizer(tasks_buttons_sizer, flag=wx.GROW) |
244 tasks_sizer.AddSizer(tasks_buttons_sizer, flag=wx.GROW) |
239 ("AddTaskButton", "add_element", _("Add task")), |
250 ("AddTaskButton", "add_element", _("Add task")), |
240 ("DeleteTaskButton", "remove_element", _("Remove task")), |
251 ("DeleteTaskButton", "remove_element", _("Remove task")), |
241 ("UpTaskButton", "up", _("Move task up")), |
252 ("UpTaskButton", "up", _("Move task up")), |
242 ("DownTaskButton", "down", _("Move task down"))]: |
253 ("DownTaskButton", "down", _("Move task down"))]: |
243 button = wx.lib.buttons.GenBitmapButton(self.Editor, |
254 button = wx.lib.buttons.GenBitmapButton(self.Editor, |
244 bitmap=GetBitmap(bitmap), size=wx.Size(28, 28), style=wx.NO_BORDER) |
255 bitmap=GetBitmap(bitmap), |
|
256 size=wx.Size(28, 28), |
|
257 style=wx.NO_BORDER) |
245 button.SetToolTipString(help) |
258 button.SetToolTipString(help) |
246 setattr(self, name, button) |
259 setattr(self, name, button) |
247 tasks_buttons_sizer.AddWindow(button) |
260 tasks_buttons_sizer.AddWindow(button) |
248 |
261 |
249 self.TasksGrid = CustomGrid(self.Editor, style=wx.VSCROLL) |
262 self.TasksGrid = CustomGrid(self.Editor, style=wx.VSCROLL) |
252 |
265 |
253 instances_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
266 instances_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
254 instances_sizer.AddGrowableCol(0) |
267 instances_sizer.AddGrowableCol(0) |
255 instances_sizer.AddGrowableRow(1) |
268 instances_sizer.AddGrowableRow(1) |
256 main_sizer.AddSizer(instances_sizer, border=5, |
269 main_sizer.AddSizer(instances_sizer, border=5, |
257 flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
270 flag=wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
258 |
271 |
259 instances_buttons_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
272 instances_buttons_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
260 instances_buttons_sizer.AddGrowableCol(0) |
273 instances_buttons_sizer.AddGrowableCol(0) |
261 instances_buttons_sizer.AddGrowableRow(0) |
274 instances_buttons_sizer.AddGrowableRow(0) |
262 instances_sizer.AddSizer(instances_buttons_sizer, flag=wx.GROW) |
275 instances_sizer.AddSizer(instances_buttons_sizer, flag=wx.GROW) |
267 for name, bitmap, help in [ |
280 for name, bitmap, help in [ |
268 ("AddInstanceButton", "add_element", _("Add instance")), |
281 ("AddInstanceButton", "add_element", _("Add instance")), |
269 ("DeleteInstanceButton", "remove_element", _("Remove instance")), |
282 ("DeleteInstanceButton", "remove_element", _("Remove instance")), |
270 ("UpInstanceButton", "up", _("Move instance up")), |
283 ("UpInstanceButton", "up", _("Move instance up")), |
271 ("DownInstanceButton", "down", _("Move instance down"))]: |
284 ("DownInstanceButton", "down", _("Move instance down"))]: |
272 button = wx.lib.buttons.GenBitmapButton(self.Editor, |
285 button = wx.lib.buttons.GenBitmapButton( |
273 bitmap=GetBitmap(bitmap), size=wx.Size(28, 28), style=wx.NO_BORDER) |
286 self.Editor, bitmap=GetBitmap(bitmap), |
|
287 size=wx.Size(28, 28), style=wx.NO_BORDER) |
274 button.SetToolTipString(help) |
288 button.SetToolTipString(help) |
275 setattr(self, name, button) |
289 setattr(self, name, button) |
276 instances_buttons_sizer.AddWindow(button) |
290 instances_buttons_sizer.AddWindow(button) |
277 |
291 |
278 self.InstancesGrid = CustomGrid(self.Editor, style=wx.VSCROLL) |
292 self.InstancesGrid = CustomGrid(self.Editor, style=wx.VSCROLL) |
279 self.InstancesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, |
293 self.InstancesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnInstancesGridCellChange) |
280 self.OnInstancesGridCellChange) |
|
281 instances_sizer.AddWindow(self.InstancesGrid, flag=wx.GROW) |
294 instances_sizer.AddWindow(self.InstancesGrid, flag=wx.GROW) |
282 |
295 |
283 self.Editor.SetSizer(main_sizer) |
296 self.Editor.SetSizer(main_sizer) |
284 |
297 |
285 def __init__(self, parent, tagname, window, controler): |
298 def __init__(self, parent, tagname, window, controler): |
286 EditorPanel.__init__(self, parent, tagname, window, controler) |
299 EditorPanel.__init__(self, parent, tagname, window, controler) |
287 |
300 |
288 self.RefreshHighlightsTimer = wx.Timer(self, -1) |
301 self.RefreshHighlightsTimer = wx.Timer(self, -1) |
289 self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
302 self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
290 |
303 |
291 self.TasksDefaultValue = {"Name" : "", "Triggering" : "", "Single" : "", "Interval" : "", "Priority" : 0} |
304 self.TasksDefaultValue = {"Name": "", "Triggering": "", "Single": "", "Interval": "", "Priority": 0} |
292 self.TasksTable = ResourceTable(self, [], GetTasksTableColnames()) |
305 self.TasksTable = ResourceTable(self, [], GetTasksTableColnames()) |
293 self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT]) |
306 self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT]) |
294 self.TasksTable.SetColSizes([200, 100, 100, 150, 100]) |
307 self.TasksTable.SetColSizes([200, 100, 100, 150, 100]) |
295 self.TasksGrid.SetTable(self.TasksTable) |
308 self.TasksGrid.SetTable(self.TasksTable) |
296 self.TasksGrid.SetButtons({"Add": self.AddTaskButton, |
309 self.TasksGrid.SetButtons({"Add": self.AddTaskButton, |
321 |
334 |
322 self.TasksGrid.SetRowLabelSize(0) |
335 self.TasksGrid.SetRowLabelSize(0) |
323 self.TasksTable.ResetView(self.TasksGrid) |
336 self.TasksTable.ResetView(self.TasksGrid) |
324 self.TasksGrid.RefreshButtons() |
337 self.TasksGrid.RefreshButtons() |
325 |
338 |
326 self.InstancesDefaultValue = {"Name" : "", "Type" : "", "Task" : ""} |
339 self.InstancesDefaultValue = {"Name": "", "Type": "", "Task": ""} |
327 self.InstancesTable = ResourceTable(self, [], GetInstancesTableColnames()) |
340 self.InstancesTable = ResourceTable(self, [], GetInstancesTableColnames()) |
328 self.InstancesTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]) |
341 self.InstancesTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]) |
329 self.InstancesTable.SetColSizes([200, 150, 150]) |
342 self.InstancesTable.SetColSizes([200, 150, 150]) |
330 self.InstancesGrid.SetTable(self.InstancesTable) |
343 self.InstancesGrid.SetTable(self.InstancesTable) |
331 self.InstancesGrid.SetButtons({"Add": self.AddInstanceButton, |
344 self.InstancesGrid.SetButtons({"Add": self.AddInstanceButton, |
360 def _RefreshInstanceButtons(): |
373 def _RefreshInstanceButtons(): |
361 if self: |
374 if self: |
362 rows = self.InstancesTable.GetNumberRows() |
375 rows = self.InstancesTable.GetNumberRows() |
363 row = self.InstancesGrid.GetGridCursorRow() |
376 row = self.InstancesGrid.GetGridCursorRow() |
364 self.DeleteInstanceButton.Enable(rows > 0) |
377 self.DeleteInstanceButton.Enable(rows > 0) |
365 self.UpInstanceButton.Enable(row > 0 and |
378 self.UpInstanceButton.Enable( |
|
379 row > 0 and |
366 self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row - 1, "Task")) |
380 self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row - 1, "Task")) |
367 self.DownInstanceButton.Enable(0 <= row < rows - 1 and |
381 self.DownInstanceButton.Enable( |
|
382 0 <= row < rows - 1 and |
368 self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row + 1, "Task")) |
383 self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row + 1, "Task")) |
369 setattr(self.InstancesGrid, "RefreshButtons", _RefreshInstanceButtons) |
384 setattr(self.InstancesGrid, "RefreshButtons", _RefreshInstanceButtons) |
370 |
385 |
371 self.InstancesGrid.SetRowLabelSize(0) |
386 self.InstancesGrid.SetRowLabelSize(0) |
372 self.InstancesTable.ResetView(self.InstancesGrid) |
387 self.InstancesTable.ResetView(self.InstancesGrid) |
379 |
394 |
380 def RefreshTypeList(self): |
395 def RefreshTypeList(self): |
381 self.TypeList = "" |
396 self.TypeList = "" |
382 blocktypes = self.Controler.GetBlockResource() |
397 blocktypes = self.Controler.GetBlockResource() |
383 for blocktype in blocktypes: |
398 for blocktype in blocktypes: |
384 self.TypeList += ",%s"%blocktype |
399 self.TypeList += ",%s" % blocktype |
385 |
400 |
386 def RefreshTaskList(self): |
401 def RefreshTaskList(self): |
387 self.TaskList = "" |
402 self.TaskList = "" |
388 for row in xrange(self.TasksTable.GetNumberRows()): |
403 for row in xrange(self.TasksTable.GetNumberRows()): |
389 self.TaskList += ",%s"%self.TasksTable.GetValueByName(row, "Name") |
404 self.TaskList += ",%s" % self.TasksTable.GetValueByName(row, "Name") |
390 |
405 |
391 def RefreshVariableList(self): |
406 def RefreshVariableList(self): |
392 self.VariableList = "" |
407 self.VariableList = "" |
393 for variable in self.Controler.GetEditedResourceVariables(self.TagName): |
408 for variable in self.Controler.GetEditedResourceVariables(self.TagName): |
394 self.VariableList += ",%s"%variable |
409 self.VariableList += ",%s" % variable |
395 |
410 |
396 def RefreshModel(self): |
411 def RefreshModel(self): |
397 self.Controler.SetEditedResourceInfos(self.TagName, self.TasksTable.GetData(), self.InstancesTable.GetData()) |
412 self.Controler.SetEditedResourceInfos(self.TagName, self.TasksTable.GetData(), self.InstancesTable.GetData()) |
398 self.RefreshBuffer() |
413 self.RefreshBuffer() |
399 |
414 |
431 self.InstancesTable.ResetView(self.InstancesGrid) |
446 self.InstancesTable.ResetView(self.InstancesGrid) |
432 self.TasksGrid.RefreshButtons() |
447 self.TasksGrid.RefreshButtons() |
433 self.InstancesGrid.RefreshButtons() |
448 self.InstancesGrid.RefreshButtons() |
434 |
449 |
435 def ShowErrorMessage(self, message): |
450 def ShowErrorMessage(self, message): |
436 dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
451 dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR) |
437 dialog.ShowModal() |
452 dialog.ShowModal() |
438 dialog.Destroy() |
453 dialog.Destroy() |
439 |
454 |
440 def OnTasksGridCellChange(self, event): |
455 def OnTasksGridCellChange(self, event): |
441 row, col = event.GetRow(), event.GetCol() |
456 row, col = event.GetRow(), event.GetCol() |