etherlab/ConfigEditor.py
changeset 2152 e6946c298a42
parent 2151 015dab6a915f
child 2165 02a2b5dee5e3
equal deleted inserted replaced
2151:015dab6a915f 2152:e6946c298a42
    10 from plcopen.structures import IEC_KEYWORDS, TestIdentifier
    10 from plcopen.structures import IEC_KEYWORDS, TestIdentifier
    11 from controls import CustomGrid, CustomTable, FolderTree
    11 from controls import CustomGrid, CustomTable, FolderTree
    12 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor, SCROLLBAR_UNIT
    12 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor, SCROLLBAR_UNIT
    13 from util.BitmapLibrary import GetBitmap
    13 from util.BitmapLibrary import GetBitmap
    14 from controls.CustomStyledTextCtrl import NAVIGATION_KEYS
    14 from controls.CustomStyledTextCtrl import NAVIGATION_KEYS
       
    15 
       
    16 # -----------------------------------------------------------------------
       
    17 from EtherCATManagementEditor import EtherCATManagementTreebook, MasterStatePanelClass
       
    18 # -----------------------------------------------------------------------
    15 
    19 
    16 [ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE] = range(3)
    20 [ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE] = range(3)
    17 
    21 
    18 def AppendMenu(parent, help, id, kind, text):
    22 def AppendMenu(parent, help, id, kind, text):
    19     if wx.VERSION >= (2, 6, 0):
    23     if wx.VERSION >= (2, 6, 0):
   238         event.Skip()
   242         event.Skip()
   239 
   243 
   240 class NodeEditor(ConfTreeNodeEditor):
   244 class NodeEditor(ConfTreeNodeEditor):
   241     
   245     
   242     CONFNODEEDITOR_TABS = [
   246     CONFNODEEDITOR_TABS = [
   243         (_("Ethercat node"), "_create_EthercatNodeEditor")]
   247         (_("Ethercat node"), "_create_EthercatNodeEditor"),
       
   248         # Add Notebook Tab for EtherCAT Management Treebook
       
   249         (_("EtherCAT Management"), "_create_EtherCATManagementEditor")
       
   250         ]
   244     
   251     
   245     def _create_EthercatNodeEditor(self, prnt):
   252     def _create_EthercatNodeEditor(self, prnt):
   246         self.EthercatNodeEditor = wx.Panel(prnt, style=wx.TAB_TRAVERSAL)
   253         self.EthercatNodeEditor = wx.Panel(prnt, style=wx.TAB_TRAVERSAL)
   247         
   254         
   248         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
   255         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
   262         return self.EthercatNodeEditor
   269         return self.EthercatNodeEditor
   263     
   270     
   264     def __init__(self, parent, controler, window):
   271     def __init__(self, parent, controler, window):
   265         ConfTreeNodeEditor.__init__(self, parent, controler, window)
   272         ConfTreeNodeEditor.__init__(self, parent, controler, window)
   266         
   273         
       
   274         # add Contoler for use EthercatSlave.py Method
       
   275         self.Controler = controler
       
   276         
   267     def GetBufferState(self):
   277     def GetBufferState(self):
   268         return False, False
   278         return False, False
   269         
   279         
   270     def RefreshView(self):
   280     def RefreshView(self):
   271         ConfTreeNodeEditor.RefreshView(self)
   281         ConfTreeNodeEditor.RefreshView(self)
   272     
   282     
   273         self.NodeVariables.RefreshView()
   283         self.NodeVariables.RefreshView()
   274 
   284 
       
   285     # -------------------For EtherCAT Management ----------------------------------------------    
       
   286     def _create_EtherCATManagementEditor(self, prnt):
       
   287         self.EtherCATManagementEditor = wx.ScrolledWindow(prnt,
       
   288             style=wx.TAB_TRAVERSAL|wx.HSCROLL|wx.VSCROLL)
       
   289         self.EtherCATManagementEditor.Bind(wx.EVT_SIZE, self.OnResize)
       
   290 
       
   291         self.EtherCATManagermentEditor_Main_Sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
       
   292         self.EtherCATManagermentEditor_Main_Sizer.AddGrowableCol(0)
       
   293         self.EtherCATManagermentEditor_Main_Sizer.AddGrowableRow(0)
       
   294         
       
   295         self.EtherCATManagementTreebook = EtherCATManagementTreebook(self.EtherCATManagementEditor, self.Controler, self)
       
   296           
       
   297         self.EtherCATManagermentEditor_Main_Sizer.AddSizer(self.EtherCATManagementTreebook, border=10, flag=wx.GROW)
       
   298 
       
   299         self.EtherCATManagementEditor.SetSizer(self.EtherCATManagermentEditor_Main_Sizer)
       
   300         return self.EtherCATManagementEditor
       
   301     
       
   302     def OnResize(self, event):
       
   303         self.EtherCATManagementEditor.GetBestSize()
       
   304         xstart, ystart = self.EtherCATManagementEditor.GetViewStart()
       
   305         window_size = self.EtherCATManagementEditor.GetClientSize()
       
   306         maxx, maxy = self.EtherCATManagementEditor.GetMinSize()
       
   307         posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
       
   308         posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
       
   309         self.EtherCATManagementEditor.Scroll(posx, posy)
       
   310         self.EtherCATManagementEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
       
   311                 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
       
   312         event.Skip()
       
   313     # -------------------------------------------------------------------------------------------------------
       
   314 
   275 CIA402NodeEditor = NodeEditor
   315 CIA402NodeEditor = NodeEditor
       
   316 
   276 
   317 
   277 def GetProcessVariablesTableColnames():
   318 def GetProcessVariablesTableColnames():
   278     _ = lambda x : x
   319     _ = lambda x : x
   279     return ["#", _("Name"), 
   320     return ["#", _("Name"), 
   280             _("Read from (nodeid, index, subindex)"), 
   321             _("Read from (nodeid, index, subindex)"), 
   535 NODE_POSITION_FILTER_FORMAT = _("Node Position: %d")
   576 NODE_POSITION_FILTER_FORMAT = _("Node Position: %d")
   536 
   577 
   537 class MasterEditor(ConfTreeNodeEditor):
   578 class MasterEditor(ConfTreeNodeEditor):
   538     
   579     
   539     CONFNODEEDITOR_TABS = [
   580     CONFNODEEDITOR_TABS = [
   540         (_("Network"), "_create_EthercatMasterEditor")]
   581         (_("Network"), "_create_EthercatMasterEditor"),
       
   582         (_("Master State"), "_create_MasterStateEditor")
       
   583         ]
       
   584     
       
   585     def _create_MasterStateEditor(self, prnt):
       
   586         self.MasterStateEditor = wx.ScrolledWindow(prnt, style=wx.TAB_TRAVERSAL|wx.HSCROLL|wx.VSCROLL)
       
   587         self.MasterStateEditor.Bind(wx.EVT_SIZE, self.OnResize)
       
   588         
       
   589         self.MasterStateEditor_Panel_Main_Sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
       
   590         self.MasterStateEditor_Panel_Main_Sizer.AddGrowableCol(0)
       
   591         self.MasterStateEditor_Panel_Main_Sizer.AddGrowableRow(0)
       
   592         
       
   593         self.MasterStateEditor_Panel = MasterStatePanelClass(self.MasterStateEditor, self.Controler)
       
   594         
       
   595         self.MasterStateEditor_Panel_Main_Sizer.AddSizer(self.MasterStateEditor_Panel, border=10, flag=wx.GROW)
       
   596          
       
   597         self.MasterStateEditor.SetSizer(self.MasterStateEditor_Panel_Main_Sizer)
       
   598         return self.MasterStateEditor
       
   599     
       
   600     def OnResize(self, event):
       
   601         self.MasterStateEditor.GetBestSize()
       
   602         xstart, ystart = self.MasterStateEditor.GetViewStart()
       
   603         window_size = self.MasterStateEditor.GetClientSize()
       
   604         maxx, maxy = self.MasterStateEditor.GetMinSize()
       
   605         posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
       
   606         posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
       
   607         self.MasterStateEditor.Scroll(posx, posy)
       
   608         self.MasterStateEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
       
   609                 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
       
   610         event.Skip()
   541     
   611     
   542     def _create_EthercatMasterEditor(self, prnt):
   612     def _create_EthercatMasterEditor(self, prnt):
   543         self.EthercatMasterEditor = wx.ScrolledWindow(prnt, 
   613         self.EthercatMasterEditor = wx.ScrolledWindow(prnt, 
   544             style=wx.TAB_TRAVERSAL|wx.HSCROLL|wx.VSCROLL)
   614             style=wx.TAB_TRAVERSAL|wx.HSCROLL|wx.VSCROLL)
   545         self.EthercatMasterEditor.Bind(wx.EVT_SIZE, self.OnResize)
   615         self.EthercatMasterEditor.Bind(wx.EVT_SIZE, self.OnResize)
   636         
   706         
   637         return self.EthercatMasterEditor
   707         return self.EthercatMasterEditor
   638 
   708 
   639     def __init__(self, parent, controler, window):
   709     def __init__(self, parent, controler, window):
   640         ConfTreeNodeEditor.__init__(self, parent, controler, window)
   710         ConfTreeNodeEditor.__init__(self, parent, controler, window)
       
   711         
       
   712         # ------------------------------------------------------------------
       
   713         self.Controler = controler
       
   714         # ------------------------------------------------------------------
   641         
   715         
   642         self.ProcessVariables = []
   716         self.ProcessVariables = []
   643         self.CellShown = None
   717         self.CellShown = None
   644         self.NodesFilterFirstCharacter = True
   718         self.NodesFilterFirstCharacter = True
   645         
   719         
   966         posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
  1040         posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
   967         self.EthercatMasterEditor.Scroll(posx, posy)
  1041         self.EthercatMasterEditor.Scroll(posx, posy)
   968         self.EthercatMasterEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
  1042         self.EthercatMasterEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
   969                 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
  1043                 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
   970         event.Skip()
  1044         event.Skip()
       
  1045         
       
  1046     #def OnButtonClick(self, event):
       
  1047     #    self.MasterState = self.Controler.getMasterState()
       
  1048     #    if self.MasterState:
       
  1049     #        self.Phase.SetValue(self.MasterState["phase"])
       
  1050     #        self.Active.SetValue(self.MasterState["active"])
       
  1051     #        self.SlaveCount.SetValue(self.MasterState["slave"])
       
  1052     #        self.MacAddress.SetValue(self.MasterState["MAC"])
       
  1053     #        self.LinkState.SetValue(self.MasterState["link"])
       
  1054     #        self.TxFrames.SetValue(self.MasterState["TXframe"])
       
  1055     #        self.RxFrames.SetValue(self.MasterState["RXframe"])
       
  1056     #        self.TxByte.SetValue(self.MasterState["TXbyte"])
       
  1057     #        self.TxError.SetValue(self.MasterState["TXerror"])
       
  1058     #        self.LostFrames.SetValue(self.MasterState["lost"])
       
  1059             
       
  1060     #        self.TxFrameRate1.SetValue(self.MasterState["TXframerate1"])
       
  1061     #        self.TxFrameRate2.SetValue(self.MasterState["TXframerate2"])
       
  1062     #        self.TxFrameRate3.SetValue(self.MasterState["TXframerate3"])
       
  1063     #        self.TxRate1.SetValue(self.MasterState["TXrate1"])
       
  1064     #        self.TxRate2.SetValue(self.MasterState["TXrate2"])
       
  1065     #        self.TxRate3.SetValue(self.MasterState["TXrate3"])
       
  1066     #        self.LossRate1.SetValue(self.MasterState["loss1"])
       
  1067     #        self.LossRate2.SetValue(self.MasterState["loss2"])
       
  1068     #        self.LossRate3.SetValue(self.MasterState["loss3"])
       
  1069     #        self.FrameLoss1.SetValue(self.MasterState["frameloss1"])
       
  1070     #        self.FrameLoss2.SetValue(self.MasterState["frameloss2"])
       
  1071     #        self.FrameLoss3.SetValue(self.MasterState["frameloss3"])
   971     
  1072     
   972 class LibraryEditorSizer(wx.FlexGridSizer):
  1073 class LibraryEditorSizer(wx.FlexGridSizer):
   973     
  1074     
   974     def __init__(self, parent, module_library, buttons):
  1075     def __init__(self, parent, module_library, buttons):
   975         wx.FlexGridSizer.__init__(self, cols=1, hgap=0, rows=4, vgap=5)
  1076         wx.FlexGridSizer.__init__(self, cols=1, hgap=0, rows=4, vgap=5)
  1288         self.ModuleLibraryEditor.Scroll(posx, posy)
  1389         self.ModuleLibraryEditor.Scroll(posx, posy)
  1289         self.ModuleLibraryEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
  1390         self.ModuleLibraryEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
  1290                 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
  1391                 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
  1291         event.Skip()
  1392         event.Skip()
  1292         
  1393         
  1293