DataTypeEditor.py
changeset 566 6014ef82a98a
parent 556 69214983dd03
child 576 3f2024f30553
equal deleted inserted replaced
565:94c11207aa6f 566:6014ef82a98a
    24 
    24 
    25 import wx
    25 import wx
    26 import wx.grid
    26 import wx.grid
    27 import wx.gizmos
    27 import wx.gizmos
    28 from plcopen.structures import IEC_KEYWORDS, TestIdentifier
    28 from plcopen.structures import IEC_KEYWORDS, TestIdentifier
       
    29 from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD
    29 
    30 
    30 import re
    31 import re
    31 
    32 
    32 DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$")
    33 DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$")
    33 
    34 
   259 
   260 
   260     def _init_coll_DirectlyPanelSizer_Items(self, parent):
   261     def _init_coll_DirectlyPanelSizer_Items(self, parent):
   261         parent.AddWindow(self.staticText2, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
   262         parent.AddWindow(self.staticText2, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
   262         parent.AddWindow(self.DirectlyBaseType, 1, border=5, flag=wx.GROW|wx.ALL)
   263         parent.AddWindow(self.DirectlyBaseType, 1, border=5, flag=wx.GROW|wx.ALL)
   263         parent.AddWindow(self.staticText3, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
   264         parent.AddWindow(self.staticText3, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
   264         parent.AddWindow(self.DirectlyInitialValue, 1, border=5, flag=wx.GROW|wx.ALL)
   265         parent.AddWindow(self.DirectlyInitialValue, 1, border=5, flag=wx.ALL)
   265 
   266 
   266     def _init_coll_SubrangePanelSizer_Items(self, parent):
   267     def _init_coll_SubrangePanelSizer_Items(self, parent):
   267         parent.AddWindow(self.staticText4, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
   268         parent.AddWindow(self.staticText4, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
   268         parent.AddWindow(self.SubrangeBaseType, 1, border=5, flag=wx.GROW|wx.ALL)
   269         parent.AddWindow(self.SubrangeBaseType, 1, border=5, flag=wx.GROW|wx.ALL)
   269         parent.AddWindow(self.staticText5, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
   270         parent.AddWindow(self.staticText5, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
   297         parent.AddWindow(self.staticText9, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
   298         parent.AddWindow(self.staticText9, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
   298         parent.AddWindow(self.ArrayBaseType, 1, border=5, flag=wx.GROW|wx.ALL)
   299         parent.AddWindow(self.ArrayBaseType, 1, border=5, flag=wx.GROW|wx.ALL)
   299     
   300     
   300     def _init_coll_ArrayPanelRightSizer_Items(self, parent):
   301     def _init_coll_ArrayPanelRightSizer_Items(self, parent):
   301         parent.AddWindow(self.staticText10, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
   302         parent.AddWindow(self.staticText10, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
   302         parent.AddWindow(self.ArrayInitialValue, 1, border=5, flag=wx.GROW|wx.ALL)    
   303         parent.AddWindow(self.ArrayInitialValue, 1, border=5, flag=wx.ALL)    
   303 
   304 
   304     def _init_coll_StructurePanelSizer_Items(self, parent):
   305     def _init_coll_StructurePanelSizer_Items(self, parent):
   305         parent.AddWindow(self.staticText11, 0, border=5, flag=wx.ALL)
   306         parent.AddWindow(self.staticText11, 0, border=5, flag=wx.ALL)
   306         parent.AddWindow(self.StructureElementsGrid, 0, border=0, flag=wx.GROW)
   307         parent.AddWindow(self.StructureElementsGrid, 0, border=0, flag=wx.GROW)
   307         parent.AddSizer(self.StructurePanelButtonSizer, 0, border=0, flag=wx.ALIGN_RIGHT)
   308         parent.AddSizer(self.StructurePanelButtonSizer, 0, border=0, flag=wx.ALIGN_RIGHT)
   580         self.SubrangePanel.Hide()
   581         self.SubrangePanel.Hide()
   581         self.EnumeratedPanel.Hide()
   582         self.EnumeratedPanel.Hide()
   582         self.ArrayPanel.Hide()
   583         self.ArrayPanel.Hide()
   583         self.StructurePanel.Hide()
   584         self.StructurePanel.Hide()
   584         self.CurrentPanel = "Directly"
   585         self.CurrentPanel = "Directly"
   585         self.Errors = []
   586         self.Highlights = []
   586         self.Initializing = False
   587         self.Initializing = False
   587         
   588         
   588         self.ParentWindow = window
   589         self.ParentWindow = window
   589         self.Controler = controler
   590         self.Controler = controler
   590         self.TagName = tagname
   591         self.TagName = tagname
       
   592         
       
   593         self.RefreshHighlightsTimer = wx.Timer(self, -1)
       
   594         self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
       
   595         
       
   596     def __del__(self):
       
   597         self.RefreshHighlightsTimer.Stop()
   591     
   598     
   592     def SetTagName(self, tagname):
   599     def SetTagName(self, tagname):
   593         self.TagName = tagname
   600         self.TagName = tagname
   594         
   601         
   595     def GetTagName(self):
   602     def GetTagName(self):
   919         self.ParentWindow.RefreshTitle()
   926         self.ParentWindow.RefreshTitle()
   920         self.ParentWindow.RefreshFileMenu()
   927         self.ParentWindow.RefreshFileMenu()
   921         self.ParentWindow.RefreshEditMenu()
   928         self.ParentWindow.RefreshEditMenu()
   922 
   929 
   923 #-------------------------------------------------------------------------------
   930 #-------------------------------------------------------------------------------
   924 #                        Errors showing functions
   931 #                        Highlights showing functions
   925 #-------------------------------------------------------------------------------
   932 #-------------------------------------------------------------------------------
   926 
   933 
   927     def ClearErrors(self):
   934     def OnRefreshHighlightsTimer(self, event):
   928         self.Errors = []
       
   929         self.RefreshView()
   935         self.RefreshView()
   930 
   936         event.Skip()
   931     def AddShownError(self, infos, start, end):
   937 
   932         self.Errors.append((infos, start, end))
   938     def ClearHighlights(self, highlight_type=None):
       
   939         if highlight_type is None:
       
   940             self.Highlights = []
       
   941         else:
       
   942             self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type]
       
   943         self.RefreshView()
       
   944 
       
   945     def AddHighlight(self, infos, start, end ,highlight_type):
       
   946         self.Highlights.append((infos, start, end, highlight_type))
       
   947         self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
   933 
   948 
   934     def ShowErrors(self):
   949     def ShowErrors(self):
   935         type_infos = self.Controler.GetDataTypeInfos(self.TagName)
   950         type_infos = self.Controler.GetDataTypeInfos(self.TagName)
   936         for infos, start, end in self.Errors:
   951         for infos, start, end, highlight_type in self.Highlights:
   937             if infos[0] == "base":
   952             if infos[0] == "base":
   938                 if type_infos["type"] == "Directly":
   953                 if type_infos["type"] == "Directly":
   939                     self.DirectlyBaseType.SetBackgroundColour(wx.Colour(255, 255, 0))
   954                     self.DirectlyBaseType.SetBackgroundColour(highlight_type[0])
   940                     self.DirectlyBaseType.SetForegroundColour(wx.RED)
   955                     self.DirectlyBaseType.SetForegroundColour(highlight_type[1])
   941                 elif type_infos["type"] == "Subrange":
   956                 elif type_infos["type"] == "Subrange":
   942                     self.SubrangeBaseType.SetBackgroundColour(wx.Colour(255, 255, 0))
   957                     self.SubrangeBaseType.SetBackgroundColour(highlight_type[0])
   943                     self.SubrangeBaseType.SetForegroundColour(wx.RED)
   958                     self.SubrangeBaseType.SetForegroundColour(highlight_type[1])
   944                 elif type_infos["type"] == "Array":
   959                 elif type_infos["type"] == "Array":
   945                     self.ArrayBaseType.SetBackgroundColour(wx.Colour(255, 255, 0))
   960                     self.ArrayBaseType.SetBackgroundColour(highlight_type[0])
   946                     self.ArrayBaseType.SetForegroundColour(wx.RED)
   961                     self.ArrayBaseType.SetForegroundColour(highlight_type[1])
   947             elif infos[0] == "lower":
   962             elif infos[0] == "lower":
   948                 self.SubrangeMinimum.SetBackgroundColour(wx.Colour(255, 255, 0))
   963                 self.SubrangeMinimum.SetBackgroundColour(highlight_type[0])
   949                 self.SubrangeMaximum.SetForegroundColour(wx.RED)
   964                 self.SubrangeMaximum.SetForegroundColour(highlight_type[1])
   950             elif infos[0] == "upper":
   965             elif infos[0] == "upper":
   951                 self.SubrangeMinimum.SetBackgroundColour(wx.Colour(255, 255, 0))
   966                 self.SubrangeMinimum.SetBackgroundColour(highlight_type[0])
   952                 self.SubrangeMaximum.SetForegroundColour(wx.RED)
   967                 self.SubrangeMaximum.SetForegroundColour(highlight_type[1])
   953             elif infos[0] == "value":
   968             elif infos[0] == "value":
   954                 listctrl = self.EnumeratedValues.GetListCtrl()
   969                 listctrl = self.EnumeratedValues.GetListCtrl()
   955                 listctrl.SetItemBackgroundColour(infos[1], wx.Colour(255, 255, 0))
   970                 listctrl.SetItemBackgroundColour(infos[1], highlight_type[0])
   956                 listctrl.SetItemTextColour(infos[1], wx.RED)
   971                 listctrl.SetItemTextColour(infos[1], highlight_type[1])
   957                 listctrl.Select(listctrl.FocusedItem, False)
   972                 listctrl.Select(listctrl.FocusedItem, False)
   958             elif infos[0] == "range":
   973             elif infos[0] == "range":
   959                 listctrl = self.EnumeratedValues.GetListCtrl()
   974                 listctrl = self.EnumeratedValues.GetListCtrl()
   960                 listctrl.SetItemBackgroundColour(infos[1], wx.Colour(255, 255, 0))
   975                 listctrl.SetItemBackgroundColour(infos[1], highlight_type[0])
   961                 listctrl.SetItemTextColour(infos[1], wx.RED)
   976                 listctrl.SetItemTextColour(infos[1], highlight_type[1])
   962                 listctrl.SetStringSelection("")
   977                 listctrl.SetStringSelection("")
   963             elif infos[0] == "initial":
   978             elif infos[0] == "initial":
   964                 if type_infos["type"] == "Directly":
   979                 if type_infos["type"] == "Directly":
   965                     text = self.DirectlyInitialValue.GetValue()
   980                     self.DirectlyInitialValue.SetStyle(start[1], end[1] + 1, wx.TextAttr(highlight_type[1], highlight_type[0]))
   966                     self.DirectlyInitialValue.SetValue(text[:start[1]])
       
   967                     self.DirectlyInitialValue.SetDefaultStyle(wx.TextAttr(wx.RED, wx.Colour(255, 255, 0)))
       
   968                     self.DirectlyInitialValue.AppendText(text[start[1]:end[1] + 1])
       
   969                     self.DirectlyInitialValue.SetDefaultStyle(wx.TextAttr(wx.BLACK, wx.WHITE))
       
   970                     self.DirectlyInitialValue.AppendText(text[end[1] + 1:])
       
   971                 elif type_infos["type"] == "Subrange":
   981                 elif type_infos["type"] == "Subrange":
   972                     self.SubrangeInitialValue.SetBackgroundColour(wx.Colour(255, 255, 0))
   982                     self.SubrangeInitialValue.SetBackgroundColour(highlight_type[0])
   973                     self.SubrangeInitialValue.SetForegroundColour(wx.RED)
   983                     self.SubrangeInitialValue.SetForegroundColour(highlight_type[1])
   974                 elif type_infos["type"] == "Enumerated":
   984                 elif type_infos["type"] == "Enumerated":
   975                     self.EnumeratedInitialValue.SetBackgroundColour(wx.Colour(255, 255, 0))
   985                     self.EnumeratedInitialValue.SetBackgroundColour(highlight_type[0])
   976                     self.EnumeratedInitialValue.SetForegroundColour(wx.RED)
   986                     self.EnumeratedInitialValue.SetForegroundColour(highlight_type[1])
   977                 elif type_infos["type"] == "Array":
   987                 elif type_infos["type"] == "Array":
   978                     text = self.ArrayInitialValue.GetValue()
   988                     self.ArrayInitialValue.SetStyle(start[1], end[1] + 1, wx.TextAttr(highlight_type[1], highlight_type[0]))
   979                     self.ArrayInitialValue.SetValue(text[:start[1]])
   989 
   980                     self.ArrayInitialValue.SetDefaultStyle(wx.TextAttr(wx.RED, wx.Colour(255, 255, 0)))
       
   981                     self.ArrayInitialValue.AppendText(text[start[1]:end[1] + 1])
       
   982                     self.ArrayInitialValue.SetDefaultStyle(wx.TextAttr(wx.BLACK, wx.WHITE))
       
   983                     self.ArrayInitialValue.AppendText(text[end[1] + 1:])