controls/VariablePanel.py
changeset 2450 5024c19ca8f0
parent 2439 f0a040f1de1b
child 2554 45d4f9a84c60
equal deleted inserted replaced
2449:b0560adec4b7 2450:5024c19ca8f0
    24 
    24 
    25 
    25 
    26 from __future__ import absolute_import
    26 from __future__ import absolute_import
    27 from __future__ import division
    27 from __future__ import division
    28 import re
    28 import re
    29 from types import TupleType, StringType, UnicodeType
       
    30 from builtins import str as text
    29 from builtins import str as text
    31 
    30 
    32 import wx
    31 import wx
    33 import wx.grid
    32 import wx.grid
    34 import wx.lib.buttons
    33 import wx.lib.buttons
       
    34 from six import string_types
    35 from six.moves import xrange
    35 from six.moves import xrange
    36 
    36 
    37 from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS, DefaultType
    37 from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS, DefaultType
    38 from plcopen.VariableInfoCollector import _VariableInfos
    38 from plcopen.VariableInfoCollector import _VariableInfos
    39 from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD, ERROR_HIGHLIGHT
    39 from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD, ERROR_HIGHLIGHT
   138                 return self.data[row].Number
   138                 return self.data[row].Number
   139             colname = self.GetColLabelValue(col, False)
   139             colname = self.GetColLabelValue(col, False)
   140             if colname == "Initial Value":
   140             if colname == "Initial Value":
   141                 colname = "InitialValue"
   141                 colname = "InitialValue"
   142             value = getattr(self.data[row], colname, "")
   142             value = getattr(self.data[row], colname, "")
   143             if colname == "Type" and isinstance(value, TupleType):
   143             if colname == "Type" and isinstance(value, tuple):
   144                 if value[0] == "array":
   144                 if value[0] == "array":
   145                     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])
   146             if not isinstance(value, (StringType, UnicodeType)):
   146             if not isinstance(value, string_types):
   147                 value = str(value)
   147                 value = str(value)
   148             if colname in ["Class", "Option"]:
   148             if colname in ["Class", "Option"]:
   149                 return _(value)
   149                 return _(value)
   150             return value
   150             return value
   151 
   151 
   278         try:
   278         try:
   279             values = eval(data)
   279             values = eval(data)
   280         except Exception:
   280         except Exception:
   281             message = _("Invalid value \"%s\" for variable grid element") % data
   281             message = _("Invalid value \"%s\" for variable grid element") % data
   282             values = None
   282             values = None
   283         if not isinstance(values, TupleType):
   283         if not isinstance(values, tuple):
   284             message = _("Invalid value \"%s\" for variable grid element") % data
   284             message = _("Invalid value \"%s\" for variable grid element") % data
   285             values = None
   285             values = None
   286         if values is not None:
   286         if values is not None:
   287             if col != wx.NOT_FOUND and row != wx.NOT_FOUND:
   287             if col != wx.NOT_FOUND and row != wx.NOT_FOUND:
   288                 colname = self.ParentWindow.Table.GetColLabelValue(col, False)
   288                 colname = self.ParentWindow.Table.GetColLabelValue(col, False)
   698 
   698 
   699     def GetTagName(self):
   699     def GetTagName(self):
   700         return self.TagName
   700         return self.TagName
   701 
   701 
   702     def IsFunctionBlockType(self, name):
   702     def IsFunctionBlockType(self, name):
   703         if isinstance(name, TupleType) or \
   703         if isinstance(name, tuple) or \
   704            self.ElementType != "function" and self.BodyType in ["ST", "IL"]:
   704            self.ElementType != "function" and self.BodyType in ["ST", "IL"]:
   705             return False
   705             return False
   706         else:
   706         else:
   707             return self.Controler.GetBlockType(name, debug=self.Debug) is not None
   707             return self.Controler.GetBlockType(name, debug=self.Debug) is not None
   708 
   708 
   986     def OnRefreshHighlightsTimer(self, event):
   986     def OnRefreshHighlightsTimer(self, event):
   987         self.Table.ResetView(self.VariablesGrid)
   987         self.Table.ResetView(self.VariablesGrid)
   988         event.Skip()
   988         event.Skip()
   989 
   989 
   990     def AddVariableHighlight(self, infos, highlight_type):
   990     def AddVariableHighlight(self, infos, highlight_type):
   991         if isinstance(infos[0], TupleType):
   991         if isinstance(infos[0], tuple):
   992             for i in xrange(*infos[0]):
   992             for i in xrange(*infos[0]):
   993                 self.Table.AddHighlight((i,) + infos[1:], highlight_type)
   993                 self.Table.AddHighlight((i,) + infos[1:], highlight_type)
   994             cell_visible = infos[0][0]
   994             cell_visible = infos[0][0]
   995         else:
   995         else:
   996             self.Table.AddHighlight(infos, highlight_type)
   996             self.Table.AddHighlight(infos, highlight_type)
   998         colnames = [colname.lower() for colname in self.Table.colnames]
   998         colnames = [colname.lower() for colname in self.Table.colnames]
   999         self.VariablesGrid.MakeCellVisible(cell_visible, colnames.index(infos[1]))
   999         self.VariablesGrid.MakeCellVisible(cell_visible, colnames.index(infos[1]))
  1000         self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
  1000         self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
  1001 
  1001 
  1002     def RemoveVariableHighlight(self, infos, highlight_type):
  1002     def RemoveVariableHighlight(self, infos, highlight_type):
  1003         if isinstance(infos[0], TupleType):
  1003         if isinstance(infos[0], tuple):
  1004             for i in xrange(*infos[0]):
  1004             for i in xrange(*infos[0]):
  1005                 self.Table.RemoveHighlight((i,) + infos[1:], highlight_type)
  1005                 self.Table.RemoveHighlight((i,) + infos[1:], highlight_type)
  1006         else:
  1006         else:
  1007             self.Table.RemoveHighlight(infos, highlight_type)
  1007             self.Table.RemoveHighlight(infos, highlight_type)
  1008         self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
  1008         self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)