etherlab/ConfigEditor.py
changeset 2459 21164625b393
parent 2450 5024c19ca8f0
child 2643 b98d9e08231f
equal deleted inserted replaced
2458:2a70d5240300 2459:21164625b393
     8 #                          Higen Motor : Donggu Kang
     8 #                          Higen Motor : Donggu Kang
     9 #
     9 #
    10 # See COPYING file for copyrights details.
    10 # See COPYING file for copyrights details.
    11 
    11 
    12 from __future__ import absolute_import
    12 from __future__ import absolute_import
       
    13 from __future__ import division
    13 import os
    14 import os
    14 import re
    15 import re
    15 from types import TupleType
       
    16 
    16 
    17 import wx
    17 import wx
    18 import wx.grid
    18 import wx.grid
    19 import wx.gizmos
    19 import wx.gizmos
    20 import wx.lib.buttons
    20 import wx.lib.buttons
    69 
    69 
    70 VARIABLE_INDEX_FILTER_FORMAT = _("Variable Index: #x%4.4X")
    70 VARIABLE_INDEX_FILTER_FORMAT = _("Variable Index: #x%4.4X")
    71 
    71 
    72 ETHERCAT_INDEX_MODEL = re.compile("#x([0-9a-fA-F]{0,4})$")
    72 ETHERCAT_INDEX_MODEL = re.compile("#x([0-9a-fA-F]{0,4})$")
    73 ETHERCAT_SUBINDEX_MODEL = re.compile("#x([0-9a-fA-F]{0,2})$")
    73 ETHERCAT_SUBINDEX_MODEL = re.compile("#x([0-9a-fA-F]{0,2})$")
    74 LOCATION_MODEL = re.compile("(?:%[IQM](?:[XBWLD]?([0-9]+(?:\.[0-9]+)*)))$")
    74 LOCATION_MODEL = re.compile(r"(?:%[IQM](?:[XBWLD]?([0-9]+(?:\.[0-9]+)*)))$")
    75 
    75 
    76 
    76 
    77 class NodeVariablesSizer(wx.FlexGridSizer):
    77 class NodeVariablesSizer(wx.FlexGridSizer):
    78 
    78 
    79     def __init__(self, parent, controler, position_column=False):
    79     def __init__(self, parent, controler, position_column=False):
   322     def OnResize(self, event):
   322     def OnResize(self, event):
   323         self.EtherCATManagementEditor.GetBestSize()
   323         self.EtherCATManagementEditor.GetBestSize()
   324         xstart, ystart = self.EtherCATManagementEditor.GetViewStart()
   324         xstart, ystart = self.EtherCATManagementEditor.GetViewStart()
   325         window_size = self.EtherCATManagementEditor.GetClientSize()
   325         window_size = self.EtherCATManagementEditor.GetClientSize()
   326         maxx, maxy = self.EtherCATManagementEditor.GetMinSize()
   326         maxx, maxy = self.EtherCATManagementEditor.GetMinSize()
   327         posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
   327         posx = max(0, min(xstart, (maxx - window_size[0]) // SCROLLBAR_UNIT))
   328         posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
   328         posy = max(0, min(ystart, (maxy - window_size[1]) // SCROLLBAR_UNIT))
   329         self.EtherCATManagementEditor.Scroll(posx, posy)
   329         self.EtherCATManagementEditor.Scroll(posx, posy)
   330         self.EtherCATManagementEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
   330         self.EtherCATManagementEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
   331                                                     maxx / SCROLLBAR_UNIT,
   331                                                     maxx // SCROLLBAR_UNIT,
   332                                                     maxy / SCROLLBAR_UNIT,
   332                                                     maxy // SCROLLBAR_UNIT,
   333                                                     posx, posy)
   333                                                     posx, posy)
   334         event.Skip()
   334         event.Skip()
   335     # -------------------------------------------------------------------------------------------------------
   335     # -------------------------------------------------------------------------------------------------------
   336 
   336 
   337 
   337 
   415         try:
   415         try:
   416             values = eval(data)
   416             values = eval(data)
   417         except Exception:
   417         except Exception:
   418             message = _("Invalid value \"%s\" for process variable") % data
   418             message = _("Invalid value \"%s\" for process variable") % data
   419             values = None
   419             values = None
   420         if not isinstance(values, TupleType):
   420         if not isinstance(values, tuple):
   421             message = _("Invalid value \"%s\" for process variable") % data
   421             message = _("Invalid value \"%s\" for process variable") % data
   422             values = None
   422             values = None
   423         if values is not None and col != wx.NOT_FOUND and row != wx.NOT_FOUND and 2 <= col <= 3:
   423         if values is not None and col != wx.NOT_FOUND and row != wx.NOT_FOUND and 2 <= col <= 3:
   424             location = None
   424             location = None
   425             if values[1] == "location":
   425             if values[1] == "location":
   477         try:
   477         try:
   478             values = eval(data)
   478             values = eval(data)
   479         except Exception:
   479         except Exception:
   480             message = _("Invalid value \"%s\" for startup command") % data
   480             message = _("Invalid value \"%s\" for startup command") % data
   481             values = None
   481             values = None
   482         if not isinstance(values, TupleType):
   482         if not isinstance(values, tuple):
   483             message = _("Invalid value \"%s\" for startup command") % data
   483             message = _("Invalid value \"%s\" for startup command") % data
   484             values = None
   484             values = None
   485         if values is not None:
   485         if values is not None:
   486             location = None
   486             location = None
   487             if values[1] == "location":
   487             if values[1] == "location":
  1054     def OnResize(self, event):
  1054     def OnResize(self, event):
  1055         self.EthercatMasterEditor.GetBestSize()
  1055         self.EthercatMasterEditor.GetBestSize()
  1056         xstart, ystart = self.EthercatMasterEditor.GetViewStart()
  1056         xstart, ystart = self.EthercatMasterEditor.GetViewStart()
  1057         window_size = self.EthercatMasterEditor.GetClientSize()
  1057         window_size = self.EthercatMasterEditor.GetClientSize()
  1058         maxx, maxy = self.EthercatMasterEditorSizer.GetMinSize()
  1058         maxx, maxy = self.EthercatMasterEditorSizer.GetMinSize()
  1059         posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
  1059         posx = max(0, min(xstart, (maxx - window_size[0]) // SCROLLBAR_UNIT))
  1060         posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
  1060         posy = max(0, min(ystart, (maxy - window_size[1]) // SCROLLBAR_UNIT))
  1061         self.EthercatMasterEditor.Scroll(posx, posy)
  1061         self.EthercatMasterEditor.Scroll(posx, posy)
  1062         self.EthercatMasterEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
  1062         self.EthercatMasterEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
  1063                                                 maxx / SCROLLBAR_UNIT,
  1063                                                 maxx // SCROLLBAR_UNIT,
  1064                                                 maxy / SCROLLBAR_UNIT,
  1064                                                 maxy // SCROLLBAR_UNIT,
  1065                                                 posx, posy)
  1065                                                 posx, posy)
  1066         event.Skip()
  1066         event.Skip()
  1067 
  1067 
  1068     # def OnButtonClick(self, event):
  1068     # def OnButtonClick(self, event):
  1069     #    self.MasterState = self.Controler.getMasterState()
  1069     #    self.MasterState = self.Controler.getMasterState()
  1419     def OnResize(self, event):
  1419     def OnResize(self, event):
  1420         self.ModuleLibraryEditor.GetBestSize()
  1420         self.ModuleLibraryEditor.GetBestSize()
  1421         xstart, ystart = self.ModuleLibraryEditor.GetViewStart()
  1421         xstart, ystart = self.ModuleLibraryEditor.GetViewStart()
  1422         window_size = self.ModuleLibraryEditor.GetClientSize()
  1422         window_size = self.ModuleLibraryEditor.GetClientSize()
  1423         maxx, maxy = self.ModuleLibraryEditor.GetMinSize()
  1423         maxx, maxy = self.ModuleLibraryEditor.GetMinSize()
  1424         posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
  1424         posx = max(0, min(xstart, (maxx - window_size[0]) // SCROLLBAR_UNIT))
  1425         posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
  1425         posy = max(0, min(ystart, (maxy - window_size[1]) // SCROLLBAR_UNIT))
  1426         self.ModuleLibraryEditor.Scroll(posx, posy)
  1426         self.ModuleLibraryEditor.Scroll(posx, posy)
  1427         self.ModuleLibraryEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
  1427         self.ModuleLibraryEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
  1428                                                maxx / SCROLLBAR_UNIT,
  1428                                                maxx // SCROLLBAR_UNIT,
  1429                                                maxy / SCROLLBAR_UNIT,
  1429                                                maxy // SCROLLBAR_UNIT,
  1430                                                posx, posy)
  1430                                                posx, posy)
  1431         event.Skip()
  1431         event.Skip()