etherlab/ConfigEditor.py
author laurent
Sun, 11 Mar 2012 21:57:00 +0100
changeset 2040 d676082c1d2f
parent 2038 6f78c4ac22f9
child 2041 ce3727171207
permissions -rw-r--r--
Adding Ethercat network scan command for testing (print result, network configuration not modified)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
     1
import wx
2026
65ecbfe9a6f9 Adding support for drag'n dropping located variables from topology panel to configurations and resources variable panel for declaring global located variables
laurent
parents: 2023
diff changeset
     2
import wx.grid
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
     3
import wx.gizmos
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
     4
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
     5
from controls import CustomGrid, CustomTable, EditorPanel
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
     6
2040
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
     7
SCAN_COMMAND = """
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
     8
import commands
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
     9
result = commands.getoutput("ethercat slaves")
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    10
slaves = []
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    11
for slave_line in result.splitlines():
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    12
    chunks = slave_line.split()
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    13
    idx, pos, state, flag = chunks[:4]
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    14
    name = " ".join(chunks[4:])
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    15
    alias, position = pos.split(":")
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    16
    slave = {"idx": int(idx),
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    17
             "alias": int(alias),
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    18
             "position": int(position),
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    19
             "name": name}
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    20
    details = commands.getoutput("ethercat slaves -p %d -v" % slave["idx"])
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    21
    for details_line in details.splitlines():
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    22
        details_line = details_line.strip()
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    23
        for header, param in [("Vendor Id:", "vendor_id"),
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    24
                              ("Product code:", "product_code"),
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    25
                              ("Revision number:", "revision_number")]:
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    26
            if details_line.startswith(header):
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    27
                slave[param] = int(details_line.split()[-1], 16)
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    28
                break
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    29
    slaves.append(slave)
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    30
returnVal = slaves
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    31
"""
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
    32
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    33
[ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE] = range(3)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    34
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    35
def AppendMenu(parent, help, id, kind, text):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    36
    if wx.VERSION >= (2, 6, 0):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    37
        parent.Append(help=help, id=id, kind=kind, text=text)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    38
    else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    39
        parent.Append(helpString=help, id=id, kind=kind, item=text)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    40
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    41
[ID_SLAVETYPECHOICEDIALOG, ID_SLAVETYPECHOICEDIALOGSTATICTEXT1,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    42
 ID_SLAVETYPECHOICEDIALOGSLAVETYPESLIBRARY
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    43
] = [wx.NewId() for _init_ctrls in range(3)]
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    44
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    45
class SlaveTypeChoiceDialog(wx.Dialog):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    46
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    47
    if wx.VERSION < (2, 6, 0):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    48
        def Bind(self, event, function, id = None):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    49
            if id is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    50
                event(self, id, function)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    51
            else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    52
                event(self, function)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    53
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    54
    def _init_coll_flexGridSizer1_Items(self, parent):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    55
        parent.AddWindow(self.staticText1, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    56
        parent.AddWindow(self.SlaveTypesLibrary, 0, border=20, flag=wx.GROW|wx.LEFT|wx.RIGHT)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    57
        parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    58
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    59
    def _init_coll_flexGridSizer1_Growables(self, parent):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    60
        parent.AddGrowableCol(0)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    61
        parent.AddGrowableRow(1)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    62
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    63
    def _init_sizers(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    64
        self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    65
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    66
        self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    67
        self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    68
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    69
        self.SetSizer(self.flexGridSizer1)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    70
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    71
    def _init_ctrls(self, prnt):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    72
        wx.Dialog.__init__(self, id=ID_SLAVETYPECHOICEDIALOG,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    73
              name='SlaveTypeChoiceDialog', parent=prnt,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    74
              size=wx.Size(600, 400), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    75
              title=_('Browse slave types library'))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    76
        self.SetClientSize(wx.Size(600, 400))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    77
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    78
        self.staticText1 = wx.StaticText(id=ID_SLAVETYPECHOICEDIALOGSTATICTEXT1,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    79
              label=_('Choose a slave type:'), name='staticText1', parent=self,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    80
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    81
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    82
        self.SlaveTypesLibrary = wx.TreeCtrl(id=ID_SLAVETYPECHOICEDIALOGSLAVETYPESLIBRARY,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    83
              name='TypeTree', parent=self, pos=wx.Point(0, 0),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    84
              size=wx.Size(0, 0), style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER|wx.TR_HIDE_ROOT|wx.TR_LINES_AT_ROOT)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    85
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    86
        self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    87
        if wx.VERSION >= (2, 5, 0):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    88
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    89
        else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    90
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    91
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    92
        self._init_sizers()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    93
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    94
    def __init__(self, parent, controler, default=None):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    95
        self._init_ctrls(parent)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    96
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    97
        slaves_types = controler.GetSlaveTypesLibrary()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    98
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    99
        root = self.SlaveTypesLibrary.AddRoot("")
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   100
        self.GenerateSlaveTypesLibraryTreeBranch(root, slaves_types, default)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   101
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   102
    def GenerateSlaveTypesLibraryTreeBranch(self, root, children, default):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   103
        for infos in children:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   104
            item = self.SlaveTypesLibrary.AppendItem(root, infos["name"])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   105
            if infos["type"] == ETHERCAT_DEVICE:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   106
                self.SlaveTypesLibrary.SetPyData(item, infos["infos"])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   107
                if infos["infos"] == default:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   108
                    self.SlaveTypesLibrary.SelectItem(item)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   109
                    self.SlaveTypesLibrary.EnsureVisible(item)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   110
            else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   111
                self.GenerateSlaveTypesLibraryTreeBranch(item, infos["children"], default)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   112
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   113
    def GetType(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   114
        selected = self.SlaveTypesLibrary.GetSelection()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   115
        return self.SlaveTypesLibrary.GetPyData(selected)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   116
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   117
    def OnOK(self, event):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   118
        selected = self.SlaveTypesLibrary.GetSelection()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   119
        if not selected.IsOk() or self.SlaveTypesLibrary.GetPyData(selected) is None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   120
            message = wx.MessageDialog(self, _("No valid slave type selected!"), _("Error"), wx.OK|wx.ICON_ERROR)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   121
            message.ShowModal()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   122
            message.Destroy()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   123
        else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   124
            self.EndModal(wx.ID_OK)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   125
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   126
def GetSyncManagersTableColnames():
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   127
    _ = lambda x : x
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   128
    return ["#", _("Name"), _("Start Address"), _("Default Size"), _("Control Byte"), _("Enable")]
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   129
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   130
class SyncManagersTable(CustomTable):
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   131
    
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   132
    def GetValue(self, row, col):
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   133
        if row < self.GetNumberRows():
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   134
            if col == 0:
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   135
                return row
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   136
            return self.data[row].get(self.GetColLabelValue(col, False), "")
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   137
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   138
def GetVariablesTableColnames():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   139
    _ = lambda x : x
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   140
    return ["#", _("Name"), _("Index"), _("SubIndex"), _("Type"), _("PDO index"), _("PDO name"), _("PDO type")]
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   141
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   142
[ID_SLAVEINFOSPANEL, ID_SLAVEINFOSPANELVENDORLABEL, 
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   143
 ID_SLAVEINFOSPANELVENDOR, ID_SLAVEINFOSPANELPRODUCTCODELABEL, 
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   144
 ID_SLAVEINFOSPANELPRODUCTCODE, ID_SLAVEINFOSPANELREVISIONNUMBERLABEL, 
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   145
 ID_SLAVEINFOSPANELREVISIONNUMBER, ID_SLAVEINFOSPANELPHYSICSLABEL, 
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   146
 ID_SLAVEINFOSPANELPHYSICS, ID_SLAVEINFOSPANELSYNCMANAGERSLABEL, 
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   147
 ID_SLAVEINFOSPANELSYNCMANAGERSGRID, ID_SLAVEINFOSPANELVARIABLESLABEL, 
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   148
 ID_SLAVEINFOSPANELVARIABLESGRID, 
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   149
] = [wx.NewId() for _init_ctrls in range(13)]
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   150
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   151
class SlaveInfosPanel(wx.Panel):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   152
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   153
    if wx.VERSION < (2, 6, 0):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   154
        def Bind(self, event, function, id = None):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   155
            if id is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   156
                event(self, id, function)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   157
            else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   158
                event(self, function)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   159
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   160
    def _init_coll_MainSizer_Items(self, parent):
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   161
        parent.AddSizer(self.SlaveInfosDetailsSizer, 0, border=5, flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.GROW)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   162
        parent.AddWindow(self.SyncManagersLabel, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.GROW)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   163
        parent.AddWindow(self.SyncManagersGrid, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.GROW)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   164
        parent.AddWindow(self.VariablesLabel, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.GROW)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   165
        parent.AddWindow(self.VariablesGrid, 0, border=5, flag=wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.GROW)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   166
        
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   167
    def _init_coll_MainSizer_Growables(self, parent):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   168
        parent.AddGrowableCol(0)
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   169
        parent.AddGrowableRow(2, 1)
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   170
        parent.AddGrowableRow(4, 2)
2023
f9f884cf3033 Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents: 2022
diff changeset
   171
        
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   172
    def _init_coll_SlaveInfosDetailsSizer_Items(self, parent):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   173
        parent.AddWindow(self.VendorLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.GROW)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   174
        parent.AddWindow(self.Vendor, 0, border=0, flag=wx.GROW)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   175
        parent.AddWindow(self.ProductCodeLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.GROW)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   176
        parent.AddWindow(self.ProductCode, 0, border=0, flag=wx.GROW)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   177
        parent.AddWindow(self.RevisionNumberLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.GROW)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   178
        parent.AddWindow(self.RevisionNumber, 0, border=0, flag=wx.GROW)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   179
        parent.AddWindow(self.PhysicsLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.GROW)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   180
        parent.AddWindow(self.Physics, 0, border=0, flag=wx.GROW)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   181
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   182
    def _init_coll_SlaveInfosDetailsSizer_Growables(self, parent):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   183
        parent.AddGrowableCol(1)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   184
        parent.AddGrowableCol(3)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   185
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   186
    def _init_sizers(self):
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   187
        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=5, vgap=5)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   188
        self.SlaveInfosDetailsSizer = wx.FlexGridSizer(cols=4, hgap=5, rows=2, vgap=5)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   189
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   190
        self._init_coll_MainSizer_Growables(self.MainSizer)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   191
        self._init_coll_MainSizer_Items(self.MainSizer)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   192
        self._init_coll_SlaveInfosDetailsSizer_Growables(self.SlaveInfosDetailsSizer)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   193
        self._init_coll_SlaveInfosDetailsSizer_Items(self.SlaveInfosDetailsSizer)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   194
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   195
        self.SetSizer(self.MainSizer)
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   196
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   197
    def _init_ctrls(self, prnt):
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   198
        wx.Panel.__init__(self, id=ID_SLAVEINFOSPANEL, name='SlavePanel', parent=prnt,
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   199
              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   200
        
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   201
        self.VendorLabel = wx.StaticText(id=ID_SLAVEINFOSPANELVENDORLABEL,
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   202
              label=_('Vendor:'), name='VendorLabel', parent=self,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   203
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   204
        
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   205
        self.Vendor = wx.TextCtrl(id=ID_SLAVEINFOSPANELVENDOR, value='',
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   206
              name='Vendor', parent=self, pos=wx.Point(0, 0),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   207
              size=wx.Size(0, 24), style=wx.TE_READONLY)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   208
        
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   209
        self.ProductCodeLabel = wx.StaticText(id=ID_SLAVEINFOSPANELPRODUCTCODELABEL,
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   210
              label=_('Product code:'), name='ProductCodeLabel', parent=self,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   211
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   212
        
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   213
        self.ProductCode = wx.TextCtrl(id=ID_SLAVEINFOSPANELPRODUCTCODE, value='',
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   214
              name='ProductCode', parent=self, pos=wx.Point(0, 0),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   215
              size=wx.Size(0, 24), style=wx.TE_READONLY)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   216
        
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   217
        self.RevisionNumberLabel = wx.StaticText(id=ID_SLAVEINFOSPANELREVISIONNUMBERLABEL,
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   218
              label=_('Revision number:'), name='RevisionNumberLabel', parent=self,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   219
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   220
        
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   221
        self.RevisionNumber = wx.TextCtrl(id=ID_SLAVEINFOSPANELREVISIONNUMBER, value='',
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   222
              name='RevisionNumber', parent=self, pos=wx.Point(0, 0),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   223
              size=wx.Size(0, 24), style=wx.TE_READONLY)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   224
        
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   225
        self.PhysicsLabel = wx.StaticText(id=ID_SLAVEINFOSPANELPHYSICSLABEL,
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   226
              label=_('Physics:'), name='PhysicsLabel', parent=self,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   227
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   228
        
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   229
        self.Physics = wx.TextCtrl(id=ID_SLAVEINFOSPANELPHYSICS, value='',
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   230
              name='Physics', parent=self, pos=wx.Point(0, 0),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   231
              size=wx.Size(0, 24), style=wx.TE_READONLY)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   232
        
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   233
        self.SyncManagersLabel =  wx.StaticText(id=ID_SLAVEINFOSPANELSYNCMANAGERSLABEL,
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   234
              label=_('Sync managers:'), name='SyncManagersLabel', parent=self,
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   235
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   236
        
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   237
        self.SyncManagersGrid = CustomGrid(id=ID_SLAVEINFOSPANELSYNCMANAGERSGRID,
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   238
              name='SyncManagersGrid', parent=self, pos=wx.Point(0, 0), 
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   239
              size=wx.Size(0, 0), style=wx.VSCROLL)
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   240
        
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   241
        self.VariablesLabel =  wx.StaticText(id=ID_SLAVEINFOSPANELVARIABLESLABEL,
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   242
              label=_('Variable entries:'), name='VariablesLabel', parent=self,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   243
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   244
        
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   245
        self.VariablesGrid = wx.gizmos.TreeListCtrl(id=ID_SLAVEINFOSPANELVARIABLESGRID,
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   246
              name='VariablesGrid', parent=self, pos=wx.Point(0, 0), 
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   247
              size=wx.Size(0, 0), style=wx.TR_DEFAULT_STYLE |
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   248
                                        wx.TR_ROW_LINES |
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   249
                                        wx.TR_COLUMN_LINES |
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   250
                                        wx.TR_HIDE_ROOT |
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   251
                                        wx.TR_FULL_ROW_HIGHLIGHT)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   252
        self.VariablesGrid.GetMainWindow().Bind(wx.EVT_LEFT_DOWN, self.OnVariablesGridLeftClick)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   253
                
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   254
        self._init_sizers()
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   255
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   256
    def __init__(self, parent, controler):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   257
        self._init_ctrls(parent)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   258
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   259
        self.Controler = controler
2037
d54036f70390 Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents: 2034
diff changeset
   260
        self.Slave = None
d54036f70390 Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents: 2034
diff changeset
   261
        self.Type = None
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   262
        
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   263
        self.SyncManagersTable = SyncManagersTable(self, [], GetSyncManagersTableColnames())
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   264
        self.SyncManagersGrid.SetTable(self.SyncManagersTable)
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   265
        self.SyncManagersGridColAlignements = [wx.ALIGN_RIGHT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, 
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   266
                                               wx.ALIGN_RIGHT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT]
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   267
        self.SyncManagersGridColSizes = [40, 150, 100, 100, 100, 100]
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   268
        self.SyncManagersGrid.SetRowLabelSize(0)
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   269
        for col in range(self.SyncManagersTable.GetNumberCols()):
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   270
            attr = wx.grid.GridCellAttr()
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   271
            attr.SetAlignment(self.SyncManagersGridColAlignements[col], wx.ALIGN_CENTRE)
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   272
            self.SyncManagersGrid.SetColAttr(col, attr)
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   273
            self.SyncManagersGrid.SetColMinimalWidth(col, self.SyncManagersGridColSizes[col])
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   274
            self.SyncManagersGrid.AutoSizeColumn(col, False)
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   275
            
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   276
        for colname, colsize, colalign in zip(GetVariablesTableColnames(),
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   277
                                              [40, 150, 100, 100, 150, 100, 150, 100],
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   278
                                              [wx.ALIGN_RIGHT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, 
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   279
                                               wx.ALIGN_RIGHT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, 
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   280
                                               wx.ALIGN_LEFT, wx.ALIGN_LEFT]):
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   281
            self.VariablesGrid.AddColumn(colname, colsize, colalign)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   282
        self.VariablesGrid.SetMainColumn(1)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   283
        
2037
d54036f70390 Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents: 2034
diff changeset
   284
    def SetSlaveInfos(self, slave_pos, slave_infos):
d54036f70390 Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents: 2034
diff changeset
   285
        self.Slave = slave_pos
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   286
        if slave_infos is not None:
2037
d54036f70390 Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents: 2034
diff changeset
   287
            self.Type = slave_infos["device_type"]
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   288
            self.Vendor.SetValue(slave_infos["vendor"])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   289
            self.ProductCode.SetValue(slave_infos["product_code"])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   290
            self.RevisionNumber.SetValue(slave_infos["revision_number"])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   291
            self.Physics.SetValue(slave_infos["physics"])
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   292
            self.SyncManagersTable.SetData(slave_infos["sync_managers"])
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   293
            self.SyncManagersTable.ResetView(self.SyncManagersGrid)
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   294
            self.RefreshVariablesGrid(slave_infos["entries"])
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   295
        else:
2037
d54036f70390 Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents: 2034
diff changeset
   296
            self.Type = None
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   297
            self.Vendor.SetValue("")
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   298
            self.ProductCode.SetValue("")
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   299
            self.RevisionNumber.SetValue("")
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   300
            self.Physics.SetValue("")
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   301
            self.SyncManagersTable.SetData([])
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   302
            self.SyncManagersTable.ResetView(self.SyncManagersGrid)
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   303
            self.RefreshVariablesGrid([])
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   304
            
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   305
    def RefreshVariablesGrid(self, entries):
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   306
        root = self.VariablesGrid.GetRootItem()
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   307
        if not root.IsOk():
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   308
            root = self.VariablesGrid.AddRoot("Slave entries")
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   309
        self.GenerateVariablesGridBranch(root, entries, GetVariablesTableColnames())
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   310
        self.VariablesGrid.Expand(root)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   311
        
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   312
    def GenerateVariablesGridBranch(self, root, entries, colnames, idx=0):
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   313
        if wx.VERSION >= (2, 6, 0):
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   314
            item, root_cookie = self.VariablesGrid.GetFirstChild(root)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   315
        else:
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   316
            item, root_cookie = self.VariablesGrid.GetFirstChild(root, 0)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   317
        
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   318
        for entry in entries:
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   319
            idx += 1
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   320
            if not item.IsOk():
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   321
                item = self.VariablesGrid.AppendItem(root, "")
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   322
            for col, colname in enumerate(colnames):
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   323
                if col == 0:
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   324
                    self.VariablesGrid.SetItemText(item, str(idx), 0)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   325
                else:
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   326
                    self.VariablesGrid.SetItemText(item, entry.get(colname, ""), col)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   327
            if entry["PDOMapping"] == "":
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   328
                self.VariablesGrid.SetItemBackgroundColour(item, wx.LIGHT_GREY)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   329
            self.VariablesGrid.SetItemPyData(item, entry)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   330
            idx = self.GenerateVariablesGridBranch(item, entry["children"], colnames, idx)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   331
            if wx.Platform != '__WXMSW__':
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   332
                item, root_cookie = self.VariablesGrid.GetNextChild(root, root_cookie)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   333
            item, root_cookie = self.VariablesGrid.GetNextChild(root, root_cookie)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   334
        
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   335
        to_delete = []
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   336
        while item.IsOk():
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   337
            to_delete.append(item)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   338
            item, root_cookie = self.VariablesGrid.GetNextChild(root, root_cookie)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   339
        for item in to_delete:
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   340
            self.VariablesGrid.Delete(item)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   341
        
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   342
        return idx
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   343
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   344
    def OnVariablesGridLeftClick(self, event):
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   345
        item, flags, col = self.VariablesGrid.HitTest(event.GetPosition())
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   346
        if item.IsOk():
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   347
            entry = self.VariablesGrid.GetItemPyData(item)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   348
            data_type = entry.get("Type", "")
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   349
            pdo_mapping = entry.get("PDOMapping", "")
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   350
            
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   351
            if (col == -1 and pdo_mapping != "" and
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   352
                self.Controler.GetSizeOfType(data_type) is not None):
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   353
                
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   354
                entry_index = self.Controler.ExtractHexDecValue(entry.get("Index", "0"))
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   355
                entry_subindex = self.Controler.ExtractHexDecValue(entry.get("SubIndex", "0"))
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   356
                var_name = "%s_%4.4x_%2.2x" % (self.Type, entry_index, entry_subindex)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   357
                if pdo_mapping == "R":
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   358
                    dir = "%I"
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   359
                else:
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   360
                    dir = "%Q"
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   361
                location = "%s%s" % (dir, self.Controler.GetSizeOfType(data_type)) + \
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   362
                           ".".join(map(lambda x:str(x), self.Controler.GetCurrentLocation() + self.Slave + (entry_index, entry_subindex)))
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   363
                
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   364
                data = wx.TextDataObject(str((location, "location", data_type, var_name, "")))
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   365
                dragSource = wx.DropSource(self.VariablesGrid)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   366
                dragSource.SetData(data)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   367
                dragSource.DoDragDrop()
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   368
            
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   369
        event.Skip()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   370
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   371
[ID_SLAVEPANEL, ID_SLAVEPANELTYPELABEL,
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   372
 ID_SLAVEPANELTYPE, ID_SLAVEPANELTYPEBROWSE, 
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   373
 ID_SLAVEPANELALIASLABEL, ID_SLAVEPANELALIAS, 
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   374
 ID_SLAVEPANELPOSLABEL, ID_SLAVEPANELPOS, 
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   375
 ID_SLAVEPANELSLAVEINFOSSTATICBOX, 
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   376
] = [wx.NewId() for _init_ctrls in range(9)]
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   377
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   378
class SlavePanel(wx.Panel):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   379
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   380
    if wx.VERSION < (2, 6, 0):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   381
        def Bind(self, event, function, id = None):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   382
            if id is not None:
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   383
                event(self, id, function)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   384
            else:
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   385
                event(self, function)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   386
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   387
    def _init_coll_MainSizer_Items(self, parent):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   388
        parent.AddSizer(self.PositionSizer, 0, border=5, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   389
        parent.AddSizer(self.SlaveInfosBoxSizer, 0, border=5, flag=wx.GROW|wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   390
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   391
    def _init_coll_MainSizer_Growables(self, parent):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   392
        parent.AddGrowableCol(0)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   393
        parent.AddGrowableRow(1)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   394
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   395
    def _init_coll_PositionSizer_Items(self, parent):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   396
        parent.AddWindow(self.TypeLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   397
        parent.AddSizer(self.TypeSizer, 0, border=0, flag=wx.GROW)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   398
        parent.AddWindow(self.AliasLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   399
        parent.AddWindow(self.Alias, 0, border=0, flag=wx.GROW)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   400
        parent.AddWindow(self.PosLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   401
        parent.AddWindow(self.Pos, 0, border=0, flag=wx.GROW)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   402
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   403
    def _init_coll_PositionSizer_Growables(self, parent):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   404
        parent.AddGrowableCol(1)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   405
        parent.AddGrowableCol(3)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   406
        parent.AddGrowableCol(5)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   407
        parent.AddGrowableRow(0)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   408
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   409
    def _init_coll_TypeSizer_Items(self, parent):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   410
        parent.AddWindow(self.Type, 1, border=0, flag=0)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   411
        parent.AddWindow(self.TypeBrowse, 0, border=0, flag=0)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   412
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   413
    def _init_coll_SlaveInfosBoxSizer_Items(self, parent):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   414
        parent.AddWindow(self.SlaveInfosPanel, 1, border=0, flag=wx.GROW)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   415
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   416
    def _init_sizers(self):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   417
        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   418
        self.PositionSizer = wx.FlexGridSizer(cols=6, hgap=5, rows=1, vgap=0)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   419
        self.TypeSizer = wx.BoxSizer(wx.HORIZONTAL)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   420
        self.SlaveInfosBoxSizer = wx.StaticBoxSizer(self.SlaveInfosStaticBox, wx.VERTICAL)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   421
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   422
        self._init_coll_MainSizer_Growables(self.MainSizer)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   423
        self._init_coll_MainSizer_Items(self.MainSizer)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   424
        self._init_coll_PositionSizer_Growables(self.PositionSizer)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   425
        self._init_coll_PositionSizer_Items(self.PositionSizer)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   426
        self._init_coll_TypeSizer_Items(self.TypeSizer)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   427
        self._init_coll_SlaveInfosBoxSizer_Items(self.SlaveInfosBoxSizer)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   428
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   429
        self.SetSizer(self.MainSizer)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   430
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   431
    def _init_ctrls(self, prnt):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   432
        wx.Panel.__init__(self, id=ID_SLAVEPANEL, name='SlavePanel', parent=prnt,
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   433
              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   434
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   435
        self.TypeLabel = wx.StaticText(id=ID_SLAVEPANELTYPELABEL,
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   436
              label=_('Type:'), name='TypeLabel', parent=self,
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   437
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   438
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   439
        self.Type = wx.TextCtrl(id=ID_SLAVEPANELTYPE, value='',
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   440
              name='Type', parent=self, pos=wx.Point(0, 0),
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   441
              size=wx.Size(0, 24), style=wx.TE_READONLY)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   442
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   443
        self.TypeBrowse = wx.Button(id=ID_SLAVEPANELTYPEBROWSE, label='...',
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   444
              name='TypeBrowse', parent=self, pos=wx.Point(0, 0),
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   445
              size=wx.Size(30, 24), style=0)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   446
        self.Bind(wx.EVT_BUTTON, self.OnTypeBrowseClick, id=ID_SLAVEPANELTYPEBROWSE)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   447
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   448
        self.AliasLabel = wx.StaticText(id=ID_SLAVEPANELALIASLABEL,
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   449
              label=_('Alias:'), name='AliasLabel', parent=self,
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   450
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   451
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   452
        self.Alias = wx.SpinCtrl(id=ID_SLAVEPANELALIAS,
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   453
              name='Alias', parent=self, pos=wx.Point(0, 0),
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   454
              size=wx.Size(0, 24), style=wx.SP_ARROW_KEYS, min=0, max=0xffff)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   455
        self.Bind(wx.EVT_SPINCTRL, self.OnAliasChanged, id=ID_SLAVEPANELALIAS)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   456
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   457
        self.PosLabel = wx.StaticText(id=ID_SLAVEPANELPOSLABEL,
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   458
              label=_('Position:'), name='PositionLabel', parent=self,
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   459
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   460
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   461
        self.Pos = wx.SpinCtrl(id=ID_SLAVEPANELPOS,
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   462
              name='Pos', parent=self, pos=wx.Point(0, 0),
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   463
              size=wx.Size(0, 24), style=wx.SP_ARROW_KEYS, min=0, max=0xffff)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   464
        self.Bind(wx.EVT_SPINCTRL, self.OnPositionChanged, id=ID_SLAVEPANELPOS)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   465
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   466
        self.SlaveInfosStaticBox = wx.StaticBox(id=ID_SLAVEPANELSLAVEINFOSSTATICBOX,
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   467
              label=_('Slave infos:'), name='SlaveInfosStaticBox', parent=self,
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   468
              pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   469
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   470
        self.SlaveInfosPanel = SlaveInfosPanel(self, self.Controler)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   471
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   472
        self._init_sizers()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   473
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   474
    def __init__(self, parent, controler, window, slave):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   475
        self.Controler = controler
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   476
        self.ParentWindow = window
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   477
        self.Slave = slave
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   478
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   479
        self._init_ctrls(parent)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   480
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   481
        self.RefreshView()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   482
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   483
    def GetSlaveTitle(self):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   484
        type_infos = self.Controler.GetSlaveType(self.Slave)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   485
        return "%s (%d:%d)" % (type_infos["device_type"], self.Slave[0], self.Slave[1])
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   486
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   487
    def GetSlave(self):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   488
        return self.Slave
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   489
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   490
    def SetSlave(self, slave):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   491
        if self.Slave != slave:
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   492
            self.Slave = slave
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   493
            self.RefreshView()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   494
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   495
    def RefreshView(self):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   496
        self.Alias.SetValue(self.Slave[0])
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   497
        self.Pos.SetValue(self.Slave[1])
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   498
        slave_infos = self.Controler.GetSlaveInfos(self.Slave)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   499
        if slave_infos is not None:
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   500
            self.Type.SetValue(slave_infos["device_type"])
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   501
        else:
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   502
            type_infos = self.Controler.GetSlaveType(self.Slave)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   503
            self.Type.SetValue(type_infos["device_type"])
2037
d54036f70390 Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents: 2034
diff changeset
   504
        self.SlaveInfosPanel.SetSlaveInfos(self.Slave, slave_infos)
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   505
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   506
    def OnAliasChanged(self, event):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   507
        alias = self.Alias.GetValue()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   508
        if alias != self.Slave[0]:
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   509
            result = self.Controler.SetSlavePos(self.Slave[:2], alias = alias)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   510
            if result is not None:
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   511
                message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   512
                message.ShowModal()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   513
                message.Destroy()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   514
            else:
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   515
                wx.CallAfter(self.ParentWindow.RefreshView, (alias, self.Slave[1]))
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   516
                wx.CallAfter(self.ParentWindow.RefreshParentWindow)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   517
        event.Skip()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   518
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   519
    def OnPositionChanged(self, event):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   520
        position = self.Pos.GetValue()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   521
        if position != self.Slave[1]:
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   522
            result = self.Controler.SetSlavePos(self.Slave, position = position)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   523
            if result is not None:
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   524
                message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   525
                message.ShowModal()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   526
                message.Destroy()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   527
            else:
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   528
                wx.CallAfter(self.ParentWindow.RefreshView, (self.Slave[0], position))
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   529
                wx.CallAfter(self.ParentWindow.RefreshParentWindow)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   530
        event.Skip()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   531
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   532
    def OnTypeBrowseClick(self, event):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   533
        dialog = SlaveTypeChoiceDialog(self, self.Controler, self.Controler.GetSlaveType(self.Slave))
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   534
        if dialog.ShowModal() == wx.ID_OK:
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   535
            result = self.Controler.SetSlaveType(self.Slave, dialog.GetType())
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   536
            if result is not None:
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   537
                message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   538
                message.ShowModal()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   539
                message.Destroy()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   540
            else:
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   541
                wx.CallAfter(self.RefreshView)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   542
                wx.CallAfter(self.ParentWindow.RefreshSlaveNodesTitles)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   543
                wx.CallAfter(self.ParentWindow.RefreshParentWindow)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   544
        dialog.Destroy()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   545
        event.Skip()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   546
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   547
[ID_CONFIGEDITOR, ID_CONFIGEDITORSLAVENODES,
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   548
] = [wx.NewId() for _init_ctrls in range(2)]
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   549
2040
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
   550
[ID_CONFIGEDITORPLUGINMENUSCANNETWORK, ID_CONFIGEDITORPLUGINMENUADDSLAVE, 
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
   551
 ID_CONFIGEDITORPLUGINMENUDELETESLAVE,
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
   552
] = [wx.NewId() for _init_coll_PluginMenu_Items in range(3)]
2030
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   553
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   554
class ConfigEditor(EditorPanel):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   555
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   556
    ID = ID_CONFIGEDITOR
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   557
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   558
    def _init_coll_MainSizer_Items(self, parent):
2030
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   559
        parent.AddWindow(self.SlaveNodes, 0, border=5, flag=wx.GROW|wx.ALL)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   560
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   561
    def _init_coll_MainSizer_Growables(self, parent):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   562
        parent.AddGrowableCol(0)
2030
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   563
        parent.AddGrowableRow(0)
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   564
    
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   565
    def _init_sizers(self):
2030
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   566
        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=0)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   567
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   568
        self._init_coll_MainSizer_Items(self.MainSizer)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   569
        self._init_coll_MainSizer_Growables(self.MainSizer)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   570
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   571
        self.Editor.SetSizer(self.MainSizer)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   572
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   573
    def _init_Editor(self, prnt):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   574
        self.Editor = wx.Panel(id=-1, parent=prnt, pos=wx.Point(0, 0), 
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   575
                size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   576
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   577
        self.SlaveNodes = wx.Notebook(id=ID_CONFIGEDITORSLAVENODES,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   578
              name='SlaveNodes', parent=self.Editor, pos=wx.Point(0, 0),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   579
              size=wx.Size(0, 0), style=wx.NB_LEFT)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   580
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   581
        self._init_sizers()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   582
    
2030
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   583
    def _init_MenuItems(self):
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   584
        self.MenuItems = [
2040
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
   585
            (wx.ITEM_NORMAL, (_("Scan network"), ID_CONFIGEDITORPLUGINMENUSCANNETWORK, '', self.OnScanNetworkMenu)),
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
   586
            (wx.ITEM_SEPARATOR, None),
2030
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   587
            (wx.ITEM_NORMAL, (_("Add slave"), ID_CONFIGEDITORPLUGINMENUADDSLAVE, '', self.OnAddSlaveMenu)),
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   588
            (wx.ITEM_NORMAL, (_("Delete slave"), ID_CONFIGEDITORPLUGINMENUDELETESLAVE, '', self.OnDeleteSlaveMenu)),
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   589
        ]
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   590
    
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   591
    def __init__(self, parent, controler, window):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   592
        EditorPanel.__init__(self, parent, "", window, controler)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   593
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   594
        img = wx.Bitmap(self.Controler.GetIconPath("Cfile.png"), wx.BITMAP_TYPE_PNG).ConvertToImage()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   595
        self.SetIcon(wx.BitmapFromImage(img.Rescale(16, 16)))
2026
65ecbfe9a6f9 Adding support for drag'n dropping located variables from topology panel to configurations and resources variable panel for declaring global located variables
laurent
parents: 2023
diff changeset
   596
    
65ecbfe9a6f9 Adding support for drag'n dropping located variables from topology panel to configurations and resources variable panel for declaring global located variables
laurent
parents: 2023
diff changeset
   597
    def __del__(self):
2030
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   598
        self.Controler.OnCloseEditor(self)
2026
65ecbfe9a6f9 Adding support for drag'n dropping located variables from topology panel to configurations and resources variable panel for declaring global located variables
laurent
parents: 2023
diff changeset
   599
    
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   600
    def GetTitle(self):
2023
f9f884cf3033 Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents: 2022
diff changeset
   601
        fullname = self.Controler.PlugFullName()
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   602
        if not self.Controler.ConfigIsSaved():
2023
f9f884cf3033 Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents: 2022
diff changeset
   603
            return "~%s~" % fullname
f9f884cf3033 Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents: 2022
diff changeset
   604
        return fullname
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   605
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   606
    def GetBufferState(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   607
        return self.Controler.GetBufferState()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   608
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   609
    def Undo(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   610
        self.Controler.LoadPrevious()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   611
        self.RefreshView()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   612
            
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   613
    def Redo(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   614
        self.Controler.LoadNext()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   615
        self.RefreshView()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   616
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   617
    def RefreshView(self, slave_pos=None):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   618
        slaves = self.Controler.GetSlaves()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   619
        for i, slave in enumerate(slaves):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   620
            if i < self.SlaveNodes.GetPageCount():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   621
                panel = self.SlaveNodes.GetPage(i)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   622
                panel.SetSlave(slave)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   623
            else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   624
                panel = SlavePanel(self.SlaveNodes, self.Controler, self, slave)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   625
                self.SlaveNodes.AddPage(panel, "")
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   626
        while self.SlaveNodes.GetPageCount() > len(slaves):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   627
            self.SlaveNodes.RemovePage(len(slaves))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   628
        self.RefreshSlaveNodesTitles()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   629
        if slave_pos is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   630
            self.SelectSlave(slave_pos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   631
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   632
    def RefreshParentWindow(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   633
        self.ParentWindow.RefreshTitle()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   634
        self.ParentWindow.RefreshFileMenu()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   635
        self.ParentWindow.RefreshEditMenu()
2030
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   636
        self.ParentWindow.RefreshPluginMenu()
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   637
        self.ParentWindow.RefreshPageTitles()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   638
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   639
    def RefreshSlaveNodesTitles(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   640
        for idx in xrange(self.SlaveNodes.GetPageCount()):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   641
            panel = self.SlaveNodes.GetPage(idx)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   642
            self.SlaveNodes.SetPageText(idx, panel.GetSlaveTitle())
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   643
            
2030
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   644
    def RefreshPluginMenu(self, plugin_menu):
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   645
        plugin_menu.Enable(ID_CONFIGEDITORPLUGINMENUDELETESLAVE, 
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   646
                           self.SlaveNodes.GetPageCount() > 0)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   647
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   648
    def SelectSlave(self, slave):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   649
        for idx in xrange(self.SlaveNodes.GetPageCount()):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   650
            panel = self.SlaveNodes.GetPage(idx)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   651
            if panel.GetSlave() == slave:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   652
                self.SlaveNodes.SetSelection(idx)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   653
                return
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   654
    
2040
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
   655
    def OnScanNetworkMenu(self, event):
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
   656
        error, returnVal = self.Controler.RemoteExec(SCAN_COMMAND, returnVal = None)
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
   657
        if error != 0:
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
   658
            dialog = wx.MessageDialog(self, returnVal, "Error", wx.OK|wx.ICON_ERROR)
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
   659
            dialog.ShowModal()
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
   660
            dialog.Destroy()
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
   661
        elif returnVal is not None:
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
   662
            print returnVal
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
   663
            wx.CallAfter(self.RefreshView)
d676082c1d2f Adding Ethercat network scan command for testing (print result, network configuration not modified)
laurent
parents: 2038
diff changeset
   664
2030
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   665
    def OnAddSlaveMenu(self, event):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   666
        slave = self.Controler.AddSlave()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   667
        self.RefreshParentWindow()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   668
        wx.CallAfter(self.RefreshView, slave)
2030
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   669
        
7147f20c23e3 Moving Add and Remove button to Plugin menu items
laurent
parents: 2029
diff changeset
   670
    def OnDeleteSlaveMenu(self, event):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   671
        selected = self.SlaveNodes.GetSelection()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   672
        if selected != -1:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   673
            panel = self.SlaveNodes.GetPage(selected)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   674
            if self.Controler.RemoveSlave(panel.GetSlave()[:2]):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   675
                self.RefreshParentWindow()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   676
                wx.CallAfter(self.RefreshView)
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   677
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   678
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   679
[ID_DS402NODEEDITOR,
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   680
] = [wx.NewId() for _init_ctrls in range(1)]
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   681
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   682
class DS402NodeEditor(EditorPanel):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   683
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   684
    ID = ID_DS402NODEEDITOR
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   685
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   686
    def _init_Editor(self, prnt):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   687
        self.Editor = SlaveInfosPanel(prnt, self.Controler)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   688
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   689
    def __init__(self, parent, controler, window):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   690
        EditorPanel.__init__(self, parent, "", window, controler)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   691
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   692
        img = wx.Bitmap(self.Controler.GetIconPath("Cfile.png"), wx.BITMAP_TYPE_PNG).ConvertToImage()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   693
        self.SetIcon(wx.BitmapFromImage(img.Rescale(16, 16)))
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   694
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   695
    def __del__(self):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   696
        self.Controler.OnCloseEditor(self)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   697
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   698
    def GetTitle(self):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   699
        return self.Controler.PlugFullName()
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   700
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   701
    def GetBufferState(self):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   702
        return False, False
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   703
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   704
    def RefreshView(self):
2037
d54036f70390 Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents: 2034
diff changeset
   705
        self.Editor.SetSlaveInfos(self.Controler.GetSlavePos(), self.Controler.GetSlaveInfos())
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
   706