36 from CustomGrid import CustomGrid |
36 from CustomGrid import CustomGrid |
37 from CustomTable import CustomTable |
37 from CustomTable import CustomTable |
38 from LocationCellEditor import LocationCellEditor |
38 from LocationCellEditor import LocationCellEditor |
39 from util.BitmapLibrary import GetBitmap |
39 from util.BitmapLibrary import GetBitmap |
40 from PLCControler import _VariableInfos |
40 from PLCControler import _VariableInfos |
41 |
41 from util.TranslationCatalogs import NoTranslate |
42 #------------------------------------------------------------------------------- |
42 |
|
43 |
|
44 # ------------------------------------------------------------------------------- |
43 # Helpers |
45 # Helpers |
44 #------------------------------------------------------------------------------- |
46 # ------------------------------------------------------------------------------- |
45 |
47 |
46 [TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, |
48 |
47 POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES |
49 [ |
|
50 TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, |
|
51 POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES |
48 ] = range(10) |
52 ] = range(10) |
49 |
53 |
|
54 |
50 def GetVariableTableColnames(location): |
55 def GetVariableTableColnames(location): |
51 _ = lambda x : x |
56 _ = NoTranslate |
52 if location: |
57 cols = ["#", |
53 return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Option"), _("Documentation")] |
58 _("Name"), |
54 return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Option"), _("Documentation")] |
59 _("Class"), |
|
60 _("Type"), |
|
61 _("Location"), |
|
62 _("Initial Value"), |
|
63 _("Option"), |
|
64 _("Documentation")] |
|
65 if not location: |
|
66 del cols[4] # remove 'Location' column |
|
67 return cols |
|
68 |
55 |
69 |
56 def GetOptions(constant=True, retain=True, non_retain=True): |
70 def GetOptions(constant=True, retain=True, non_retain=True): |
57 _ = lambda x : x |
71 _ = NoTranslate |
58 options = [""] |
72 options = [""] |
59 if constant: |
73 if constant: |
60 options.append(_("Constant")) |
74 options.append(_("Constant")) |
61 if retain: |
75 if retain: |
62 options.append(_("Retain")) |
76 options.append(_("Retain")) |
63 if non_retain: |
77 if non_retain: |
64 options.append(_("Non-Retain")) |
78 options.append(_("Non-Retain")) |
65 return options |
79 return options |
|
80 |
|
81 |
66 OPTIONS_DICT = dict([(_(option), option) for option in GetOptions()]) |
82 OPTIONS_DICT = dict([(_(option), option) for option in GetOptions()]) |
67 |
83 |
|
84 |
68 def GetFilterChoiceTransfer(): |
85 def GetFilterChoiceTransfer(): |
69 _ = lambda x : x |
86 _ = NoTranslate |
70 return {_("All"): _("All"), _("Interface"): _("Interface"), |
87 return {_("All"): _("All"), _("Interface"): _("Interface"), |
71 _(" Input"): _("Input"), _(" Output"): _("Output"), _(" InOut"): _("InOut"), |
88 _(" Input"): _("Input"), _(" Output"): _("Output"), _(" InOut"): _("InOut"), |
72 _(" External"): _("External"), _("Variables"): _("Variables"), _(" Local"): _("Local"), |
89 _(" External"): _("External"), _("Variables"): _("Variables"), _(" Local"): _("Local"), |
73 _(" Temp"): _("Temp"), _("Global"): _("Global")}#, _("Access") : _("Access")} |
90 _(" Temp"): _("Temp"), _("Global"): _("Global")} # , _("Access") : _("Access")} |
|
91 |
|
92 |
74 VARIABLE_CHOICES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().iterkeys()]) |
93 VARIABLE_CHOICES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().iterkeys()]) |
75 VARIABLE_CLASSES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().itervalues()]) |
94 VARIABLE_CLASSES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().itervalues()]) |
76 |
95 |
77 CheckOptionForClass = {"Local": lambda x: x, |
96 CheckOptionForClass = { |
78 "Temp": lambda x: "", |
97 "Local": lambda x: x, |
79 "Input": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""), |
98 "Temp": lambda x: "", |
80 "InOut": lambda x: "", |
99 "Input": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""), |
81 "Output": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""), |
100 "InOut": lambda x: "", |
82 "Global": lambda x: {"Constant": "Constant", "Retain": "Retain"}.get(x, ""), |
101 "Output": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""), |
83 "External": lambda x: {"Constant": "Constant"}.get(x, "") |
102 "Global": lambda x: {"Constant": "Constant", "Retain": "Retain"}.get(x, ""), |
84 } |
103 "External": lambda x: {"Constant": "Constant"}.get(x, "") |
|
104 } |
85 |
105 |
86 LOCATION_MODEL = re.compile("((?:%[IQM](?:\*|(?:[XBWLD]?[0-9]+(?:\.[0-9]+)*)))?)$") |
106 LOCATION_MODEL = re.compile("((?:%[IQM](?:\*|(?:[XBWLD]?[0-9]+(?:\.[0-9]+)*)))?)$") |
87 VARIABLE_NAME_SUFFIX_MODEL = re.compile("([0-9]*)$") |
107 VARIABLE_NAME_SUFFIX_MODEL = re.compile("([0-9]*)$") |
88 |
108 |
89 #------------------------------------------------------------------------------- |
109 |
|
110 # ------------------------------------------------------------------------------- |
90 # Variables Panel Table |
111 # Variables Panel Table |
91 #------------------------------------------------------------------------------- |
112 # ------------------------------------------------------------------------------- |
|
113 |
92 |
114 |
93 class VariableTable(CustomTable): |
115 class VariableTable(CustomTable): |
94 |
116 |
95 """ |
117 """ |
96 A custom wx.grid.Grid Table using user supplied data |
118 A custom wx.grid.Grid Table using user supplied data |
169 colname = self.GetColLabelValue(col, False) |
191 colname = self.GetColLabelValue(col, False) |
170 if self.Parent.Debug: |
192 if self.Parent.Debug: |
171 grid.SetReadOnly(row, col, True) |
193 grid.SetReadOnly(row, col, True) |
172 else: |
194 else: |
173 if colname == "Option": |
195 if colname == "Option": |
174 options = GetOptions(constant = var_class in ["Local", "External", "Global"], |
196 options = GetOptions(constant=var_class in ["Local", "External", "Global"], |
175 retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"], |
197 retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"], |
176 non_retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"]) |
198 non_retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"]) |
177 if len(options) > 1: |
199 if len(options) > 1: |
178 editor = wx.grid.GridCellChoiceEditor() |
200 editor = wx.grid.GridCellChoiceEditor() |
179 editor.SetParameters(",".join(map(_, options))) |
201 editor.SetParameters(",".join(map(_, options))) |
180 else: |
202 else: |
181 grid.SetReadOnly(row, col, True) |
203 grid.SetReadOnly(row, col, True) |
272 |
296 |
273 if values[2] is not None: |
297 if values[2] is not None: |
274 base_location_type = self.ParentWindow.Controler.GetBaseType(values[2]) |
298 base_location_type = self.ParentWindow.Controler.GetBaseType(values[2]) |
275 if values[2] != variable_type and base_type != base_location_type: |
299 if values[2] != variable_type and base_type != base_location_type: |
276 message = _("Incompatible data types between \"{a1}\" and \"{a2}\"").\ |
300 message = _("Incompatible data types between \"{a1}\" and \"{a2}\"").\ |
277 format(a1 = values[2], a2 = variable_type) |
301 format(a1=values[2], a2=variable_type) |
278 |
302 |
279 if message is None: |
303 if message is None: |
280 if not location.startswith("%"): |
304 if not location.startswith("%"): |
281 if location[0].isdigit() and base_type != "BOOL": |
305 if location[0].isdigit() and base_type != "BOOL": |
282 message = _("Incompatible size of data between \"%s\" and \"BOOL\"")%location |
306 message = _("Incompatible size of data between \"%s\" and \"BOOL\"") % location |
283 elif location[0] not in LOCATIONDATATYPES: |
307 elif location[0] not in LOCATIONDATATYPES: |
284 message = _("Unrecognized data size \"%s\"")%location[0] |
308 message = _("Unrecognized data size \"%s\"") % location[0] |
285 elif base_type not in LOCATIONDATATYPES[location[0]]: |
309 elif base_type not in LOCATIONDATATYPES[location[0]]: |
286 message = _("Incompatible size of data between \"{a1}\" and \"{a2}\"").\ |
310 message = _("Incompatible size of data between \"{a1}\" and \"{a2}\"").\ |
287 format(a1 = location, a2 = variable_type) |
311 format(a1=location, a2=variable_type) |
288 else: |
312 else: |
289 dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow.ParentWindow, |
313 dialog = wx.SingleChoiceDialog( |
290 _("Select a variable class:"), _("Variable class"), |
314 self.ParentWindow.ParentWindow.ParentWindow, |
291 [_("Input"), _("Output"), _("Memory")], |
315 _("Select a variable class:"), |
292 wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) |
316 _("Variable class"), |
|
317 [_("Input"), _("Output"), _("Memory")], |
|
318 wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL) |
293 if dialog.ShowModal() == wx.ID_OK: |
319 if dialog.ShowModal() == wx.ID_OK: |
294 selected = dialog.GetSelection() |
320 selected = dialog.GetSelection() |
295 else: |
321 else: |
296 selected = None |
322 selected = None |
297 dialog.Destroy() |
323 dialog.Destroy() |
330 dlg.SetValue(var_name) |
356 dlg.SetValue(var_name) |
331 var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None |
357 var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None |
332 dlg.Destroy() |
358 dlg.Destroy() |
333 if var_name is None: |
359 if var_name is None: |
334 return |
360 return |
335 elif var_name.upper() in [name.upper() |
361 elif var_name.upper() in [ |
336 for name in self.ParentWindow.Controler.\ |
362 name.upper() for name in |
337 GetProjectPouNames(self.ParentWindow.Debug)]: |
363 self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]: |
338 message = _("\"%s\" pou already exists!")%var_name |
364 message = _("\"%s\" pou already exists!") % var_name |
339 elif not var_name.upper() in [name.upper() |
365 elif not var_name.upper() in [ |
340 for name in self.ParentWindow.Controler.\ |
366 name.upper() |
341 GetEditedElementVariables(tagname, self.ParentWindow.Debug)]: |
367 for name in self.ParentWindow.Controler. |
|
368 GetEditedElementVariables(tagname, self.ParentWindow.Debug)]: |
342 var_infos = self.ParentWindow.DefaultValue.copy() |
369 var_infos = self.ParentWindow.DefaultValue.copy() |
343 var_infos.Name = var_name |
370 var_infos.Name = var_name |
344 var_infos.Type = values[2] |
371 var_infos.Type = values[2] |
345 var_infos.Documentation = values[4] |
372 var_infos.Documentation = values[4] |
346 if values[1] == "location": |
373 if values[1] == "location": |
347 location = values[0] |
374 location = values[0] |
348 if not location.startswith("%"): |
375 if not location.startswith("%"): |
349 dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow.ParentWindow, |
376 dialog = wx.SingleChoiceDialog( |
350 _("Select a variable class:"), _("Variable class"), |
377 self.ParentWindow.ParentWindow.ParentWindow, |
351 [_("Input"), _("Output"), _("Memory")], |
378 _("Select a variable class:"), |
352 wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) |
379 _("Variable class"), |
|
380 [_("Input"), _("Output"), _("Memory")], |
|
381 wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL) |
353 if dialog.ShowModal() == wx.ID_OK: |
382 if dialog.ShowModal() == wx.ID_OK: |
354 selected = dialog.GetSelection() |
383 selected = dialog.GetSelection() |
355 else: |
384 else: |
356 selected = None |
385 selected = None |
357 dialog.Destroy() |
386 dialog.Destroy() |
366 if element_type == "functionBlock": |
395 if element_type == "functionBlock": |
367 configs = self.ParentWindow.Controler.GetProjectConfigNames( |
396 configs = self.ParentWindow.Controler.GetProjectConfigNames( |
368 self.ParentWindow.Debug) |
397 self.ParentWindow.Debug) |
369 if len(configs) == 0: |
398 if len(configs) == 0: |
370 return |
399 return |
371 if not var_name.upper() in [name.upper() |
400 if not var_name.upper() in [ |
372 for name in self.ParentWindow.Controler.\ |
401 name.upper() for name in |
373 GetConfigurationVariableNames(configs[0])]: |
402 self.ParentWindow.Controler.GetConfigurationVariableNames(configs[0])]: |
374 self.ParentWindow.Controler.AddConfigurationGlobalVar( |
403 self.ParentWindow.Controler.AddConfigurationGlobalVar( |
375 configs[0], values[2], var_name, location, "") |
404 configs[0], values[2], var_name, location, "") |
376 var_infos.Class = "External" |
405 var_infos.Class = "External" |
377 else: |
406 else: |
378 if element_type == "program": |
407 if element_type == "program": |
379 var_infos.Class = "Local" |
408 var_infos.Class = "Local" |
380 else: |
409 else: |
381 var_infos.Class = "Global" |
410 var_infos.Class = "Global" |
382 var_infos.Location = location |
411 var_infos.Location = location |
383 elif values[1] == "NamedConstant": |
412 elif values[1] == "NamedConstant": |
384 if element_type in ["functionBlock","program"]: |
413 if element_type in ["functionBlock", "program"]: |
385 var_infos.Class = "Local" |
414 var_infos.Class = "Local" |
386 var_infos.InitialValue = values[0] |
415 var_infos.InitialValue = values[0] |
387 else : |
416 else: |
388 return |
417 return |
389 else: |
418 else: |
390 var_infos.Class = "External" |
419 var_infos.Class = "External" |
391 var_infos.Number = len(self.ParentWindow.Values) |
420 var_infos.Number = len(self.ParentWindow.Values) |
392 self.ParentWindow.Values.append(var_infos) |
421 self.ParentWindow.Values.append(var_infos) |
393 self.ParentWindow.SaveValues() |
422 self.ParentWindow.SaveValues() |
394 self.ParentWindow.RefreshValues() |
423 self.ParentWindow.RefreshValues() |
395 else: |
424 else: |
396 message = _("\"%s\" element for this pou already exists!")%var_name |
425 message = _("\"%s\" element for this pou already exists!") % var_name |
397 |
426 |
398 if message is not None: |
427 if message is not None: |
399 wx.CallAfter(self.ShowMessage, message) |
428 wx.CallAfter(self.ShowMessage, message) |
400 |
429 |
401 def ShowMessage(self, message): |
430 def ShowMessage(self, message): |
402 message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR) |
431 message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK | wx.ICON_ERROR) |
403 message.ShowModal() |
432 message.ShowModal() |
404 message.Destroy() |
433 message.Destroy() |
405 |
434 |
406 #------------------------------------------------------------------------------- |
435 |
|
436 # ------------------------------------------------------------------------------- |
407 # Variable Panel |
437 # Variable Panel |
408 #------------------------------------------------------------------------------- |
438 # ------------------------------------------------------------------------------- |
|
439 |
409 |
440 |
410 class VariablePanel(wx.Panel): |
441 class VariablePanel(wx.Panel): |
411 |
442 |
412 def __init__(self, parent, window, controler, element_type, debug=False): |
443 def __init__(self, parent, window, controler, element_type, debug=False): |
413 wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL) |
444 wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL) |
417 self.MainSizer.AddGrowableRow(1) |
448 self.MainSizer.AddGrowableRow(1) |
418 |
449 |
419 controls_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=5) |
450 controls_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=5) |
420 controls_sizer.AddGrowableCol(5) |
451 controls_sizer.AddGrowableCol(5) |
421 controls_sizer.AddGrowableRow(0) |
452 controls_sizer.AddGrowableRow(0) |
422 self.MainSizer.AddSizer(controls_sizer, border=5, flag=wx.GROW|wx.ALL) |
453 self.MainSizer.AddSizer(controls_sizer, border=5, flag=wx.GROW | wx.ALL) |
423 |
454 |
424 self.ReturnTypeLabel = wx.StaticText(self, label=_('Return Type:')) |
455 self.ReturnTypeLabel = wx.StaticText(self, label=_('Return Type:')) |
425 controls_sizer.AddWindow(self.ReturnTypeLabel, flag=wx.ALIGN_CENTER_VERTICAL) |
456 controls_sizer.AddWindow(self.ReturnTypeLabel, flag=wx.ALIGN_CENTER_VERTICAL) |
426 |
457 |
427 self.ReturnType = wx.ComboBox(self, |
458 self.ReturnType = wx.ComboBox(self, |
428 size=wx.Size(145, -1), style=wx.CB_READONLY) |
459 size=wx.Size(145, -1), style=wx.CB_READONLY) |
429 self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, self.ReturnType) |
460 self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, self.ReturnType) |
430 controls_sizer.AddWindow(self.ReturnType) |
461 controls_sizer.AddWindow(self.ReturnType) |
431 |
462 |
432 self.DescriptionLabel = wx.StaticText(self, label=_('Description:')) |
463 self.DescriptionLabel = wx.StaticText(self, label=_('Description:')) |
433 controls_sizer.AddWindow(self.DescriptionLabel, flag=wx.ALIGN_CENTER_VERTICAL) |
464 controls_sizer.AddWindow(self.DescriptionLabel, flag=wx.ALIGN_CENTER_VERTICAL) |
434 |
465 |
435 self.Description = wx.TextCtrl(self, |
466 self.Description = wx.TextCtrl(self, |
436 size=wx.Size(250, -1), style=wx.TE_PROCESS_ENTER) |
467 size=wx.Size(250, -1), style=wx.TE_PROCESS_ENTER) |
437 self.Bind(wx.EVT_TEXT_ENTER, self.OnDescriptionChanged, self.Description) |
468 self.Bind(wx.EVT_TEXT_ENTER, self.OnDescriptionChanged, self.Description) |
438 self.Description.Bind(wx.EVT_KILL_FOCUS, self.OnDescriptionChanged) |
469 self.Description.Bind(wx.EVT_KILL_FOCUS, self.OnDescriptionChanged) |
439 controls_sizer.AddWindow(self.Description) |
470 controls_sizer.AddWindow(self.Description) |
440 |
471 |
441 class_filter_label = wx.StaticText(self, label=_('Class Filter:')) |
472 class_filter_label = wx.StaticText(self, label=_('Class Filter:')) |
442 controls_sizer.AddWindow(class_filter_label, flag=wx.ALIGN_CENTER_VERTICAL) |
473 controls_sizer.AddWindow(class_filter_label, flag=wx.ALIGN_CENTER_VERTICAL) |
443 |
474 |
444 self.ClassFilter = wx.ComboBox(self, |
475 self.ClassFilter = wx.ComboBox(self, |
445 size=wx.Size(145, -1), style=wx.CB_READONLY) |
476 size=wx.Size(145, -1), style=wx.CB_READONLY) |
446 self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, self.ClassFilter) |
477 self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, self.ClassFilter) |
447 controls_sizer.AddWindow(self.ClassFilter) |
478 controls_sizer.AddWindow(self.ClassFilter) |
448 |
479 |
449 for name, bitmap, help in [ |
480 for name, bitmap, help in [ |
450 ("AddButton", "add_element", _("Add variable")), |
481 ("AddButton", "add_element", _("Add variable")), |
451 ("DeleteButton", "remove_element", _("Remove variable")), |
482 ("DeleteButton", "remove_element", _("Remove variable")), |
452 ("UpButton", "up", _("Move variable up")), |
483 ("UpButton", "up", _("Move variable up")), |
453 ("DownButton", "down", _("Move variable down"))]: |
484 ("DownButton", "down", _("Move variable down"))]: |
454 button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), |
485 button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), |
455 size=wx.Size(28, 28), style=wx.NO_BORDER) |
486 size=wx.Size(28, 28), style=wx.NO_BORDER) |
456 button.SetToolTipString(help) |
487 button.SetToolTipString(help) |
457 setattr(self, name, button) |
488 setattr(self, name, button) |
458 controls_sizer.AddWindow(button) |
489 controls_sizer.AddWindow(button) |
459 |
490 |
460 self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL | wx.HSCROLL) |
491 self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL | wx.HSCROLL) |
461 self.VariablesGrid.SetDropTarget(VariableDropTarget(self)) |
492 self.VariablesGrid.SetDropTarget(VariableDropTarget(self)) |
462 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, |
493 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, |
463 self.OnVariablesGridCellChange) |
494 self.OnVariablesGridCellChange) |
464 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, |
495 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, |
465 self.OnVariablesGridCellLeftClick) |
496 self.OnVariablesGridCellLeftClick) |
466 self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, |
497 self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, |
467 self.OnVariablesGridEditorShown) |
498 self.OnVariablesGridEditorShown) |
468 self.MainSizer.AddWindow(self.VariablesGrid, flag=wx.GROW) |
499 self.MainSizer.AddWindow(self.VariablesGrid, flag=wx.GROW) |
469 |
500 |
470 self.SetSizer(self.MainSizer) |
501 self.SetSizer(self.MainSizer) |
471 |
502 |
472 self.ParentWindow = window |
503 self.ParentWindow = window |
474 self.ElementType = element_type |
505 self.ElementType = element_type |
475 self.Debug = debug |
506 self.Debug = debug |
476 |
507 |
477 self.RefreshHighlightsTimer = wx.Timer(self, -1) |
508 self.RefreshHighlightsTimer = wx.Timer(self, -1) |
478 self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, |
509 self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, |
479 self.RefreshHighlightsTimer) |
510 self.RefreshHighlightsTimer) |
480 |
511 |
481 self.Filter = "All" |
512 self.Filter = "All" |
482 self.FilterChoices = [] |
513 self.FilterChoices = [] |
483 self.FilterChoiceTransfer = GetFilterChoiceTransfer() |
514 self.FilterChoiceTransfer = GetFilterChoiceTransfer() |
484 |
515 |
485 self.DefaultValue = _VariableInfos("", "", "", "", "", True, "", DefaultType, ([], []), 0) |
516 self.DefaultValue = _VariableInfos("", "", "", "", "", True, "", DefaultType, ([], []), 0) |
486 |
517 |
487 if element_type in ["config", "resource"]: |
518 if element_type in ["config", "resource"]: |
488 self.DefaultTypes = {"All" : "Global"} |
519 self.DefaultTypes = {"All": "Global"} |
489 else: |
520 else: |
490 self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"} |
521 self.DefaultTypes = {"All": "Local", "Interface": "Input", "Variables": "Local"} |
491 |
522 |
492 if element_type in ["config", "resource"] \ |
523 if element_type in ["config", "resource"] \ |
493 or element_type in ["program", "transition", "action"]: |
524 or element_type in ["program", "transition", "action"]: |
494 # this is an element that can have located variables |
525 # this is an element that can have located variables |
495 self.Table = VariableTable(self, [], GetVariableTableColnames(True)) |
526 self.Table = VariableTable(self, [], GetVariableTableColnames(True)) |
496 |
527 |
497 if element_type in ["config", "resource"]: |
528 if element_type in ["config", "resource"]: |
498 self.FilterChoices = ["All", "Global"]#,"Access"] |
529 self.FilterChoices = ["All", "Global"] # ,"Access"] |
499 else: |
530 else: |
500 self.FilterChoices = ["All", |
531 self.FilterChoices = ["All", |
501 "Interface", " Input", " Output", " InOut", " External", |
532 "Interface", " Input", " Output", " InOut", " External", |
502 "Variables", " Local", " Temp"]#,"Access"] |
533 "Variables", " Local", " Temp"] # ,"Access"] |
503 |
534 |
504 # these condense the ColAlignements list |
535 # these condense the ColAlignements list |
505 l = wx.ALIGN_LEFT |
536 left = wx.ALIGN_LEFT |
506 c = wx.ALIGN_CENTER |
537 center = wx.ALIGN_CENTER |
507 |
538 |
508 # Num Name Class Type Loc Init Option Doc |
539 # Num Name Class Type Loc Init Option Doc |
509 self.ColSizes = [40, 80, 100, 80, 110, 120, 100, 160] |
540 self.ColSettings = { |
510 self.ColAlignements = [c, l, l, l, l, l, l, l] |
541 "size": [40, 80, 100, 80, 110, 120, 100, 160], |
511 self.ColFixedSizeFlag=[True,False, True, False, True, True, True, False] |
542 "alignement": [center, left, left, left, left, left, left, left], |
|
543 "fixed_size": [True, False, True, False, True, True, True, False], |
|
544 } |
512 |
545 |
513 else: |
546 else: |
514 # this is an element that cannot have located variables |
547 # this is an element that cannot have located variables |
515 self.Table = VariableTable(self, [], GetVariableTableColnames(False)) |
548 self.Table = VariableTable(self, [], GetVariableTableColnames(False)) |
516 |
549 |
517 if element_type == "function": |
550 if element_type == "function": |
518 self.FilterChoices = ["All", |
551 self.FilterChoices = ["All", |
519 "Interface", " Input", " Output", " InOut", |
552 "Interface", " Input", " Output", " InOut", |
520 "Variables", " Local"] |
553 "Variables", " Local"] |
521 else: |
554 else: |
522 self.FilterChoices = ["All", |
555 self.FilterChoices = ["All", |
523 "Interface", " Input", " Output", " InOut", " External", |
556 "Interface", " Input", " Output", " InOut", " External", |
524 "Variables", " Local", " Temp"] |
557 "Variables", " Local", " Temp"] |
525 |
558 |
526 # these condense the ColAlignements list |
559 # these condense the alignements list |
527 l = wx.ALIGN_LEFT |
560 left = wx.ALIGN_LEFT |
528 c = wx.ALIGN_CENTER |
561 center = wx.ALIGN_CENTER |
529 |
562 |
530 # Num Name Class Type Init Option Doc |
563 # Num Name Class Type Init Option Doc |
531 self.ColSizes = [40, 80, 100, 80, 120, 100, 160] |
564 self.ColSettings = { |
532 self.ColAlignements = [c, l, l, l, l, l, l] |
565 "size": [40, 80, 100, 80, 120, 100, 160], |
533 self.ColFixedSizeFlag=[True,False, True, False, True, True, False] |
566 "alignement": [center, left, left, left, left, left, left], |
534 |
567 "fixed_size": [True, False, True, False, True, True, False], |
535 self.PanelWidthMin = sum(self.ColSizes) |
568 } |
536 |
569 |
|
570 self.PanelWidthMin = sum(self.ColSettings["size"]) |
|
571 |
537 self.ElementType = element_type |
572 self.ElementType = element_type |
538 self.BodyType = None |
573 self.BodyType = None |
539 |
574 |
540 for choice in self.FilterChoices: |
575 for choice in self.FilterChoices: |
541 self.ClassFilter.Append(_(choice)) |
576 self.ClassFilter.Append(_(choice)) |
641 setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons) |
676 setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons) |
642 |
677 |
643 panel_width = window.Parent.ScreenRect.Width - 35 |
678 panel_width = window.Parent.ScreenRect.Width - 35 |
644 if panel_width > self.PanelWidthMin: |
679 if panel_width > self.PanelWidthMin: |
645 stretch_cols_width = panel_width |
680 stretch_cols_width = panel_width |
646 stretch_cols_sum = 0 |
681 stretch_cols_sum = 0 |
647 for col in range(len(self.ColFixedSizeFlag)): |
682 for col in range(len(self.ColSettings["fixed_size"])): |
648 if self.ColFixedSizeFlag[col]: |
683 if self.ColSettings["fixed_size"][col]: |
649 stretch_cols_width -= self.ColSizes[col] |
684 stretch_cols_width -= self.ColSettings["size"][col] |
650 else: |
685 else: |
651 stretch_cols_sum += self.ColSizes[col] |
686 stretch_cols_sum += self.ColSettings["size"][col] |
652 |
687 |
653 self.VariablesGrid.SetRowLabelSize(0) |
688 self.VariablesGrid.SetRowLabelSize(0) |
654 for col in range(self.Table.GetNumberCols()): |
689 for col in range(self.Table.GetNumberCols()): |
655 attr = wx.grid.GridCellAttr() |
690 attr = wx.grid.GridCellAttr() |
656 attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
691 attr.SetAlignment(self.ColSettings["alignement"][col], wx.ALIGN_CENTRE) |
657 self.VariablesGrid.SetColAttr(col, attr) |
692 self.VariablesGrid.SetColAttr(col, attr) |
658 self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col]) |
693 self.VariablesGrid.SetColMinimalWidth(col, self.ColSettings["size"][col]) |
659 if (panel_width > self.PanelWidthMin) and not self.ColFixedSizeFlag[col]: |
694 if (panel_width > self.PanelWidthMin) and not self.ColSettings["fixed_size"][col]: |
660 self.VariablesGrid.SetColSize(col, int((float(self.ColSizes[col])/stretch_cols_sum)*stretch_cols_width)) |
695 self.VariablesGrid.SetColSize(col, int((float(self.ColSettings["size"][col])/stretch_cols_sum)*stretch_cols_width)) |
661 else: |
696 else: |
662 self.VariablesGrid.SetColSize(col, self.ColSizes[col]) |
697 self.VariablesGrid.SetColSize(col, self.ColSettings["size"][col]) |
663 |
698 |
664 def __del__(self): |
699 def __del__(self): |
665 self.RefreshHighlightsTimer.Stop() |
700 self.RefreshHighlightsTimer.Stop() |
666 |
701 |
667 def SetTagName(self, tagname): |
702 def SetTagName(self, tagname): |
745 self.VariablesGrid.RefreshButtons() |
780 self.VariablesGrid.RefreshButtons() |
746 event.Skip() |
781 event.Skip() |
747 |
782 |
748 def RefreshTypeList(self): |
783 def RefreshTypeList(self): |
749 if self.Filter == "All": |
784 if self.Filter == "All": |
750 self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All","Interface","Variables"]] |
785 self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All", "Interface", "Variables"]] |
751 elif self.Filter == "Interface": |
786 elif self.Filter == "Interface": |
752 self.ClassList = ["Input","Output","InOut","External"] |
787 self.ClassList = ["Input", "Output", "InOut", "External"] |
753 elif self.Filter == "Variables": |
788 elif self.Filter == "Variables": |
754 self.ClassList = ["Local","Temp"] |
789 self.ClassList = ["Local", "Temp"] |
755 else: |
790 else: |
756 self.ClassList = [self.Filter] |
791 self.ClassList = [self.Filter] |
757 |
792 |
758 def ShowErrorMessage(self, message): |
793 def ShowErrorMessage(self, message): |
759 dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
794 dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR) |
760 dialog.ShowModal() |
795 dialog.ShowModal() |
761 dialog.Destroy() |
796 dialog.Destroy() |
762 |
797 |
763 def OnVariablesGridCellChange(self, event): |
798 def OnVariablesGridCellChange(self, event): |
764 row, col = event.GetRow(), event.GetCol() |
799 row, col = event.GetRow(), event.GetCol() |
765 colname = self.Table.GetColLabelValue(col, False) |
800 colname = self.Table.GetColLabelValue(col, False) |
766 value = self.Table.GetValue(row, col) |
801 value = self.Table.GetValue(row, col) |
767 message = None |
802 message = None |
803 self.Table.GetColLabelValue(col, False) == 'Type' and not self.Controler.IsLocatableType(value): |
838 self.Table.GetColLabelValue(col, False) == 'Type' and not self.Controler.IsLocatableType(value): |
804 self.Values[row].Location = '' |
839 self.Values[row].Location = '' |
805 self.RefreshValues() |
840 self.RefreshValues() |
806 self.SaveValues() |
841 self.SaveValues() |
807 |
842 |
808 def BuildStdIECTypesMenu(self,type_menu): |
843 def BuildStdIECTypesMenu(self, type_menu): |
809 # build a submenu containing standard IEC types |
844 # build a submenu containing standard IEC types |
810 base_menu = wx.Menu(title='') |
845 base_menu = wx.Menu(title='') |
811 for base_type in self.Controler.GetBaseTypes(): |
846 for base_type in self.Controler.GetBaseTypes(): |
812 new_id = wx.NewId() |
847 new_id = wx.NewId() |
813 base_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type) |
848 base_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type) |
814 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id) |
849 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id) |
815 |
850 |
816 type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu) |
851 type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu) |
817 |
852 |
818 def BuildUserTypesMenu(self,type_menu): |
853 def BuildUserTypesMenu(self, type_menu): |
819 # build a submenu containing user-defined types |
854 # build a submenu containing user-defined types |
820 datatype_menu = wx.Menu(title='') |
855 datatype_menu = wx.Menu(title='') |
821 datatypes = self.Controler.GetDataTypes(basetypes = False, confnodetypes = False) |
856 datatypes = self.Controler.GetDataTypes(basetypes=False, confnodetypes=False) |
822 for datatype in datatypes: |
857 for datatype in datatypes: |
823 new_id = wx.NewId() |
858 new_id = wx.NewId() |
824 datatype_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) |
859 datatype_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) |
825 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id) |
860 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id) |
826 |
861 |