22 # along with this program; if not, write to the Free Software |
22 # along with this program; if not, write to the Free Software |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
24 |
25 |
25 |
26 from __future__ import absolute_import |
26 from __future__ import absolute_import |
|
27 from __future__ import division |
27 import re |
28 import re |
28 from types import TupleType, StringType, UnicodeType |
29 from builtins import str as text |
29 |
30 |
30 import wx |
31 import wx |
31 import wx.grid |
32 import wx.grid |
32 import wx.lib.buttons |
33 import wx.lib.buttons |
|
34 from six import string_types |
|
35 from six.moves import xrange |
33 |
36 |
34 from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS, DefaultType |
37 from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS, DefaultType |
35 from plcopen.VariableInfoCollector import _VariableInfos |
38 from plcopen.VariableInfoCollector import _VariableInfos |
36 from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD, ERROR_HIGHLIGHT |
39 from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD, ERROR_HIGHLIGHT |
37 from dialogs.ArrayTypeDialog import ArrayTypeDialog |
40 from dialogs.ArrayTypeDialog import ArrayTypeDialog |
96 "Output": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""), |
99 "Output": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""), |
97 "Global": lambda x: {"Constant": "Constant", "Retain": "Retain"}.get(x, ""), |
100 "Global": lambda x: {"Constant": "Constant", "Retain": "Retain"}.get(x, ""), |
98 "External": lambda x: {"Constant": "Constant"}.get(x, "") |
101 "External": lambda x: {"Constant": "Constant"}.get(x, "") |
99 } |
102 } |
100 |
103 |
101 LOCATION_MODEL = re.compile("((?:%[IQM](?:\*|(?:[XBWLD]?[0-9]+(?:\.[0-9]+)*)))?)$") |
104 LOCATION_MODEL = re.compile(r"((?:%[IQM](?:\*|(?:[XBWLD]?[0-9]+(?:\.[0-9]+)*)))?)$") |
102 LOCATION_MODEL_SET = re.compile("((?:%[IQM](?:[XBWLD]?[0-9]+(?:\.[0-9]+)*))?)$") |
105 LOCATION_MODEL_SET = re.compile(r"((?:%[IQM](?:[XBWLD]?[0-9]+(?:\.[0-9]+)*))?)$") |
103 |
106 |
104 |
107 |
105 # ------------------------------------------------------------------------------- |
108 # ------------------------------------------------------------------------------- |
106 # Variables Panel Table |
109 # Variables Panel Table |
107 # ------------------------------------------------------------------------------- |
110 # ------------------------------------------------------------------------------- |
135 return self.data[row].Number |
138 return self.data[row].Number |
136 colname = self.GetColLabelValue(col, False) |
139 colname = self.GetColLabelValue(col, False) |
137 if colname == "Initial Value": |
140 if colname == "Initial Value": |
138 colname = "InitialValue" |
141 colname = "InitialValue" |
139 value = getattr(self.data[row], colname, "") |
142 value = getattr(self.data[row], colname, "") |
140 if colname == "Type" and isinstance(value, TupleType): |
143 if colname == "Type" and isinstance(value, tuple): |
141 if value[0] == "array": |
144 if value[0] == "array": |
142 return "ARRAY [%s] OF %s" % (",".join(map("..".join, value[2])), value[1]) |
145 return "ARRAY [%s] OF %s" % (",".join(map("..".join, value[2])), value[1]) |
143 if not isinstance(value, (StringType, UnicodeType)): |
146 if not isinstance(value, string_types): |
144 value = str(value) |
147 value = str(value) |
145 if colname in ["Class", "Option"]: |
148 if colname in ["Class", "Option"]: |
146 return _(value) |
149 return _(value) |
147 return value |
150 return value |
148 |
151 |
275 try: |
278 try: |
276 values = eval(data) |
279 values = eval(data) |
277 except Exception: |
280 except Exception: |
278 message = _("Invalid value \"%s\" for variable grid element") % data |
281 message = _("Invalid value \"%s\" for variable grid element") % data |
279 values = None |
282 values = None |
280 if not isinstance(values, TupleType): |
283 if not isinstance(values, tuple): |
281 message = _("Invalid value \"%s\" for variable grid element") % data |
284 message = _("Invalid value \"%s\" for variable grid element") % data |
282 values = None |
285 values = None |
283 if values is not None: |
286 if values is not None: |
284 if col != wx.NOT_FOUND and row != wx.NOT_FOUND: |
287 if col != wx.NOT_FOUND and row != wx.NOT_FOUND: |
285 colname = self.ParentWindow.Table.GetColLabelValue(col, False) |
288 colname = self.ParentWindow.Table.GetColLabelValue(col, False) |
601 self.TagName, old_name, old_name+'%d') |
604 self.TagName, old_name, old_name+'%d') |
602 |
605 |
603 # increment location address |
606 # increment location address |
604 if row_content.Location != "" and LOCATION_MODEL_SET.match(row_content.Location): |
607 if row_content.Location != "" and LOCATION_MODEL_SET.match(row_content.Location): |
605 old_location = row_content.Location |
608 old_location = row_content.Location |
606 model = re.compile("%[IQM][XBWLD]?(.*\.|)") |
609 model = re.compile(r"%[IQM][XBWLD]?(.*\.|)") |
607 prefix = model.match(old_location).group(0) |
610 prefix = model.match(old_location).group(0) |
608 addr = int(re.split(model, old_location)[-1]) + 1 |
611 addr = int(re.split(model, old_location)[-1]) + 1 |
609 row_content.Location = prefix + unicode(addr) |
612 row_content.Location = prefix + text(addr) |
610 |
613 |
611 if not row_content.Class: |
614 if not row_content.Class: |
612 row_content.Class = self.DefaultTypes.get(self.Filter, self.Filter) |
615 row_content.Class = self.DefaultTypes.get(self.Filter, self.Filter) |
613 |
616 |
614 if self.Filter == "All" and len(self.Values) > 0: |
617 if self.Filter == "All" and len(self.Values) > 0: |
680 attr = wx.grid.GridCellAttr() |
683 attr = wx.grid.GridCellAttr() |
681 attr.SetAlignment(self.ColSettings["alignement"][col], wx.ALIGN_CENTRE) |
684 attr.SetAlignment(self.ColSettings["alignement"][col], wx.ALIGN_CENTRE) |
682 self.VariablesGrid.SetColAttr(col, attr) |
685 self.VariablesGrid.SetColAttr(col, attr) |
683 self.VariablesGrid.SetColMinimalWidth(col, self.ColSettings["size"][col]) |
686 self.VariablesGrid.SetColMinimalWidth(col, self.ColSettings["size"][col]) |
684 if (panel_width > self.PanelWidthMin) and not self.ColSettings["fixed_size"][col]: |
687 if (panel_width > self.PanelWidthMin) and not self.ColSettings["fixed_size"][col]: |
685 self.VariablesGrid.SetColSize(col, int((float(self.ColSettings["size"][col])/stretch_cols_sum)*stretch_cols_width)) |
688 self.VariablesGrid.SetColSize(col, int((self.ColSettings["size"][col]/stretch_cols_sum)*stretch_cols_width)) |
686 else: |
689 else: |
687 self.VariablesGrid.SetColSize(col, self.ColSettings["size"][col]) |
690 self.VariablesGrid.SetColSize(col, self.ColSettings["size"][col]) |
688 |
691 |
689 def __del__(self): |
692 def __del__(self): |
690 self.RefreshHighlightsTimer.Stop() |
693 self.RefreshHighlightsTimer.Stop() |
695 |
698 |
696 def GetTagName(self): |
699 def GetTagName(self): |
697 return self.TagName |
700 return self.TagName |
698 |
701 |
699 def IsFunctionBlockType(self, name): |
702 def IsFunctionBlockType(self, name): |
700 if isinstance(name, TupleType) or \ |
703 if isinstance(name, tuple) or \ |
701 self.ElementType != "function" and self.BodyType in ["ST", "IL"]: |
704 self.ElementType != "function" and self.BodyType in ["ST", "IL"]: |
702 return False |
705 return False |
703 else: |
706 else: |
704 return self.Controler.GetBlockType(name, debug=self.Debug) is not None |
707 return self.Controler.GetBlockType(name, debug=self.Debug) is not None |
705 |
708 |
983 def OnRefreshHighlightsTimer(self, event): |
986 def OnRefreshHighlightsTimer(self, event): |
984 self.Table.ResetView(self.VariablesGrid) |
987 self.Table.ResetView(self.VariablesGrid) |
985 event.Skip() |
988 event.Skip() |
986 |
989 |
987 def AddVariableHighlight(self, infos, highlight_type): |
990 def AddVariableHighlight(self, infos, highlight_type): |
988 if isinstance(infos[0], TupleType): |
991 if isinstance(infos[0], tuple): |
989 for i in xrange(*infos[0]): |
992 for i in xrange(*infos[0]): |
990 self.Table.AddHighlight((i,) + infos[1:], highlight_type) |
993 self.Table.AddHighlight((i,) + infos[1:], highlight_type) |
991 cell_visible = infos[0][0] |
994 cell_visible = infos[0][0] |
992 else: |
995 else: |
993 self.Table.AddHighlight(infos, highlight_type) |
996 self.Table.AddHighlight(infos, highlight_type) |
995 colnames = [colname.lower() for colname in self.Table.colnames] |
998 colnames = [colname.lower() for colname in self.Table.colnames] |
996 self.VariablesGrid.MakeCellVisible(cell_visible, colnames.index(infos[1])) |
999 self.VariablesGrid.MakeCellVisible(cell_visible, colnames.index(infos[1])) |
997 self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
1000 self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
998 |
1001 |
999 def RemoveVariableHighlight(self, infos, highlight_type): |
1002 def RemoveVariableHighlight(self, infos, highlight_type): |
1000 if isinstance(infos[0], TupleType): |
1003 if isinstance(infos[0], tuple): |
1001 for i in xrange(*infos[0]): |
1004 for i in xrange(*infos[0]): |
1002 self.Table.RemoveHighlight((i,) + infos[1:], highlight_type) |
1005 self.Table.RemoveHighlight((i,) + infos[1:], highlight_type) |
1003 else: |
1006 else: |
1004 self.Table.RemoveHighlight(infos, highlight_type) |
1007 self.Table.RemoveHighlight(infos, highlight_type) |
1005 self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
1008 self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |