etherlab/ConfigEditor.py
author Laurent Bessard
Tue, 05 Mar 2013 00:59:34 +0100
changeset 2098 392791b5cc04
parent 2097 58d07e039896
child 2099 ea5384ab152c
permissions -rw-r--r--
Improved Ethercat Network Configurator panels
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
     1
import os
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
     2
import re
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
     3
from types import TupleType
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
     4
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
     5
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
     6
import wx.grid
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
     7
import wx.gizmos
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
     8
import wx.lib.buttons
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
     9
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    10
from plcopen.structures import IEC_KEYWORDS, TestIdentifier
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
    11
from controls import CustomGrid, CustomTable, FolderTree
2071
37d603e91a43 Fix import after integration of plcopeneditor into Beremiz
Laurent Bessard
parents: 2067
diff changeset
    12
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor, SCROLLBAR_UNIT
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
    13
from util.BitmapLibrary import GetBitmap
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    14
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    15
[ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE] = range(3)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    16
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    17
def AppendMenu(parent, help, id, kind, text):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    18
    if wx.VERSION >= (2, 6, 0):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    19
        parent.Append(help=help, id=id, kind=kind, text=text)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    20
    else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    21
        parent.Append(helpString=help, id=id, kind=kind, item=text)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    22
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    23
def GetVariablesTableColnames(position=False):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    24
    _ = lambda x : x
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    25
    colname = ["#"]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    26
    if position:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    27
        colname.append(_("Position"))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    28
    return colname + [_("Name"), _("Index"), _("SubIndex"), _("Type"), _("Access")]
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
    29
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
    30
ACCESS_TYPES = {
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
    31
    'ro': 'R',
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
    32
    'wo': 'W',
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
    33
    'rw': 'R/W'}
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
    34
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
    35
def GetAccessValue(access, pdo_mapping):
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    36
    value = ACCESS_TYPES.get(access, "")
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
    37
    if pdo_mapping != "":
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
    38
        value += "/P"
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
    39
    return value
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2030
diff changeset
    40
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    41
VARIABLES_FILTERS = [
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    42
    (_("All"), (0x0000, 0xffff)),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    43
    (_("Communication Parameters"), (0x1000, 0x1fff)),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    44
    (_("Manufacturer Specific"), (0x2000, 0x5fff)),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    45
    (_("Standardized Device Profile"), (0x6000, 0x9fff))]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    46
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    47
ETHERCAT_INDEX_MODEL = re.compile("#x([0-9a-fA-F]{0,4})$")
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    48
ETHERCAT_SUBINDEX_MODEL = re.compile("#x([0-9a-fA-F]{0,2})$")
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    49
LOCATION_MODEL = re.compile("(?:%[IQM](?:[XBWLD]?([0-9]+(?:\.[0-9]+)*)))$")
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    50
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    51
class NodeVariablesSizer(wx.FlexGridSizer):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    52
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    53
    def __init__(self, parent, controler, position_column=False):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    54
        wx.FlexGridSizer.__init__(self, cols=1, hgap=0, rows=2, vgap=5)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    55
        self.AddGrowableCol(0)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    56
        self.AddGrowableRow(1)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    57
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    58
        self.Controler = controler
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    59
        self.PositionColumn = position_column
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    60
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    61
        self.VariablesFilter = wx.ComboBox(parent)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    62
        self.VariablesFilter.Bind(wx.EVT_COMBOBOX, self.OnVariablesFilterChanged)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    63
        self.AddWindow(self.VariablesFilter, flag=wx.GROW)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    64
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    65
        self.VariablesGrid = wx.gizmos.TreeListCtrl(parent, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    66
                style=wx.TR_DEFAULT_STYLE |
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    67
                      wx.TR_ROW_LINES |
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    68
                      wx.TR_COLUMN_LINES |
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    69
                      wx.TR_HIDE_ROOT |
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    70
                      wx.TR_FULL_ROW_HIGHLIGHT)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    71
        self.VariablesGrid.GetMainWindow().Bind(wx.EVT_LEFT_DOWN,
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
    72
            self.OnVariablesGridLeftClick)
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    73
        self.AddWindow(self.VariablesGrid, flag=wx.GROW)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    74
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    75
        self.Filters = []
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    76
        for desc, value in VARIABLES_FILTERS:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    77
            self.VariablesFilter.Append(desc)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    78
            self.Filters.append(value)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    79
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    80
        self.VariablesFilter.SetSelection(0)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    81
        self.CurrentFilter = self.Filters[0]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    82
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    83
        if position_column:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    84
            for colname, colsize, colalign in zip(GetVariablesTableColnames(position_column),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    85
                                                  [40, 80, 350, 80, 100, 80, 80],
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    86
                                                  [wx.ALIGN_RIGHT, wx.ALIGN_RIGHT, wx.ALIGN_LEFT, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    87
                                                   wx.ALIGN_RIGHT, wx.ALIGN_RIGHT, wx.ALIGN_LEFT, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    88
                                                   wx.ALIGN_LEFT]):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    89
                self.VariablesGrid.AddColumn(_(colname), colsize, colalign)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    90
            self.VariablesGrid.SetMainColumn(2)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    91
        else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    92
            for colname, colsize, colalign in zip(GetVariablesTableColnames(),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    93
                                                  [40, 350, 80, 100, 80, 80],
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    94
                                                  [wx.ALIGN_RIGHT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    95
                                                   wx.ALIGN_RIGHT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    96
                self.VariablesGrid.AddColumn(_(colname), colsize, colalign)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    97
            self.VariablesGrid.SetMainColumn(1)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    98
    
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2040
diff changeset
    99
    def RefreshView(self):
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   100
        entries = self.Controler.GetSlaveVariables(self.CurrentFilter)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   101
        self.RefreshVariablesGrid(entries)
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2040
diff changeset
   102
    
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   103
    def RefreshVariablesGrid(self, entries):
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   104
        root = self.VariablesGrid.GetRootItem()
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   105
        if not root.IsOk():
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   106
            root = self.VariablesGrid.AddRoot(_("Slave entries"))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   107
        self.GenerateVariablesGridBranch(root, entries, GetVariablesTableColnames(self.PositionColumn))
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   108
        self.VariablesGrid.Expand(root)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   109
        
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   110
    def GenerateVariablesGridBranch(self, root, entries, colnames, idx=0):
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   111
        item, root_cookie = self.VariablesGrid.GetFirstChild(root)
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   112
        
2056
0a23fe9594e0 Fix bug with VariablesList on Windows
laurent
parents: 2055
diff changeset
   113
        no_more_items = not item.IsOk()
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   114
        for entry in entries:
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   115
            idx += 1
2056
0a23fe9594e0 Fix bug with VariablesList on Windows
laurent
parents: 2055
diff changeset
   116
            if no_more_items:
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   117
                item = self.VariablesGrid.AppendItem(root, "")
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   118
            for col, colname in enumerate(colnames):
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   119
                if col == 0:
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   120
                    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
   121
                else:
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   122
                    value = entry.get(colname, "")
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   123
                    if colname == "Access":
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   124
                        value = GetAccessValue(value, entry.get("PDOMapping", ""))
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   125
                    self.VariablesGrid.SetItemText(item, value, col)
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   126
            if entry["PDOMapping"] == "":
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   127
                self.VariablesGrid.SetItemBackgroundColour(item, wx.LIGHT_GREY)
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   128
            else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   129
                self.VariablesGrid.SetItemBackgroundColour(item, wx.WHITE)
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   130
            self.VariablesGrid.SetItemPyData(item, entry)
2056
0a23fe9594e0 Fix bug with VariablesList on Windows
laurent
parents: 2055
diff changeset
   131
            idx = self.GenerateVariablesGridBranch(item, entry["children"], colnames, idx)
0a23fe9594e0 Fix bug with VariablesList on Windows
laurent
parents: 2055
diff changeset
   132
            if not no_more_items:
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2040
diff changeset
   133
                item, root_cookie = self.VariablesGrid.GetNextChild(root, root_cookie)
2056
0a23fe9594e0 Fix bug with VariablesList on Windows
laurent
parents: 2055
diff changeset
   134
                no_more_items = not item.IsOk()
0a23fe9594e0 Fix bug with VariablesList on Windows
laurent
parents: 2055
diff changeset
   135
        
0a23fe9594e0 Fix bug with VariablesList on Windows
laurent
parents: 2055
diff changeset
   136
        if not no_more_items:
0a23fe9594e0 Fix bug with VariablesList on Windows
laurent
parents: 2055
diff changeset
   137
            to_delete = []
0a23fe9594e0 Fix bug with VariablesList on Windows
laurent
parents: 2055
diff changeset
   138
            while item.IsOk():
0a23fe9594e0 Fix bug with VariablesList on Windows
laurent
parents: 2055
diff changeset
   139
                to_delete.append(item)
0a23fe9594e0 Fix bug with VariablesList on Windows
laurent
parents: 2055
diff changeset
   140
                item, root_cookie = self.VariablesGrid.GetNextChild(root, root_cookie)
0a23fe9594e0 Fix bug with VariablesList on Windows
laurent
parents: 2055
diff changeset
   141
            for item in to_delete:
0a23fe9594e0 Fix bug with VariablesList on Windows
laurent
parents: 2055
diff changeset
   142
                self.VariablesGrid.Delete(item)
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   143
        
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   144
        return idx
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   145
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   146
    def OnVariablesFilterChanged(self, event):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   147
        filter = self.VariablesFilter.GetSelection()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   148
        if filter != -1:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   149
            self.CurrentFilter = self.Filters[filter]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   150
            self.RefreshView()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   151
        else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   152
            try:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   153
                value = self.VariablesFilter.GetValue()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   154
                result = ETHERCAT_INDEX_MODEL.match(value)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   155
                if result is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   156
                    value = result.group(1)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   157
                index = int(value)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   158
                self.CurrentFilter = (index, index)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   159
                self.RefreshView()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   160
            except:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   161
                pass
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   162
        event.Skip()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   163
    
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   164
    def OnVariablesGridLeftClick(self, event):
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   165
        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
   166
        if item.IsOk():
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   167
            entry = self.VariablesGrid.GetItemPyData(item)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   168
            data_type = entry.get("Type", "")
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   169
            data_size = self.Controler.GetSizeOfType(data_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
   170
            
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   171
            if col == -1 and data_size is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   172
                pdo_mapping = entry.get("PDOMapping", "")
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   173
                access = entry.get("Access", "")
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   174
                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
   175
                entry_subindex = self.Controler.ExtractHexDecValue(entry.get("SubIndex", "0"))
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   176
                if self.PositionColumn:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   177
                    slave_pos = self.Controler.ExtractHexDecValue(entry.get("Position", "0"))
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   178
                else:
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   179
                    slave_pos = self.Controler.GetSlavePos()
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   180
                
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   181
                if pdo_mapping != "":
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   182
                    var_name = "%s_%4.4x_%2.2x" % (self.Controler.CTNName(), entry_index, entry_subindex)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   183
                    if pdo_mapping == "R":
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   184
                        dir = "%I"
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   185
                    else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   186
                        dir = "%Q"
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   187
                    location = "%s%s" % (dir, data_size) + \
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   188
                               ".".join(map(lambda x:str(x), self.Controler.GetCurrentLocation() + 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   189
                                                             (slave_pos, entry_index, entry_subindex)))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   190
                    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   191
                    data = wx.TextDataObject(str((location, "location", data_type, var_name, "", access)))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   192
                    dragSource = wx.DropSource(self.VariablesGrid)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   193
                    dragSource.SetData(data)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   194
                    dragSource.DoDragDrop()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   195
                    return
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   196
                
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   197
                elif self.ColumnPosition:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   198
                    location = self.Controler.GetCurrentLocation() +\
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   199
                               (slave_pos, entry_index, entry_subindex)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   200
                    data = wx.TextDataObject(str((location, "variable", access)))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   201
                    dragSource = wx.DropSource(self.VariablesGrid)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   202
                    dragSource.SetData(data)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   203
                    dragSource.DoDragDrop()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   204
                    return
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   205
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   206
        event.Skip()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   207
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   208
class NodeEditor(ConfTreeNodeEditor):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   209
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   210
    CONFNODEEDITOR_TABS = [
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   211
        (_("Ethercat node"), "_create_EthercatNodeEditor")]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   212
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   213
    def _create_EthercatNodeEditor(self, prnt):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   214
        self.EthercatNodeEditor = wx.Panel(prnt, style=wx.TAB_TRAVERSAL)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   215
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   216
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   217
        main_sizer.AddGrowableCol(0)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   218
        main_sizer.AddGrowableRow(1)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   219
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   220
        variables_label = wx.StaticText(self.EthercatNodeEditor,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   221
              label=_('Variable entries:'))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   222
        main_sizer.AddWindow(variables_label, border=10, flag=wx.TOP|wx.LEFT|wx.RIGHT)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   223
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   224
        self.NodeVariables = NodeVariablesSizer(self.EthercatNodeEditor, self.Controler)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   225
        main_sizer.AddSizer(self.NodeVariables, border=10, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   226
            flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   227
                
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   228
        self.EthercatNodeEditor.SetSizer(main_sizer)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   229
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   230
        return self.EthercatNodeEditor
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   231
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   232
    def __init__(self, parent, controler, window):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   233
        ConfTreeNodeEditor.__init__(self, parent, controler, window)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   234
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   235
    def GetBufferState(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   236
        return False, False
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   237
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   238
    def RefreshView(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   239
        ConfTreeNodeEditor.RefreshView(self)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   240
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   241
        self.NodeVariables.RefreshView()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   242
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   243
CIA402NodeEditor = NodeEditor
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   244
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   245
def GetProcessVariablesTableColnames():
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   246
    _ = lambda x : x
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   247
    return ["#", _("Name"), 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   248
            _("Read from (nodeid, index, subindex)"), 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   249
            _("Write to (nodeid, index, subindex)"),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   250
            _("Description")]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   251
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   252
class ProcessVariablesTable(CustomTable):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   253
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   254
    def GetValue(self, row, col):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   255
        if row < self.GetNumberRows():
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   256
            if col == 0:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   257
                return row + 1
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   258
            colname = self.GetColLabelValue(col, False)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   259
            if colname.startswith("Read from"):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   260
                value = self.data[row].get("ReadFrom", "")
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   261
                if value == "":
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   262
                    return value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   263
                return "%d, #x%0.4x, #x%0.2x" % value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   264
            elif colname.startswith("Write to"):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   265
                value = self.data[row].get("WriteTo", "")
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   266
                if value == "":
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   267
                    return value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   268
                return "%d, #x%0.4x, #x%0.2x" % value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   269
            return self.data[row].get(colname, "")
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   270
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   271
    def SetValue(self, row, col, value):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   272
        if col < len(self.colnames):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   273
            colname = self.GetColLabelValue(col, False)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   274
            if colname.startswith("Read from"):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   275
                self.data[row]["ReadFrom"] = value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   276
            elif colname.startswith("Write to"):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   277
                self.data[row]["WriteTo"] = value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   278
            else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   279
                self.data[row][colname] = value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   280
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   281
    def _updateColAttrs(self, grid):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   282
        """
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   283
        wx.grid.Grid -> update the column attributes to add the
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   284
        appropriate renderer given the column name.
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   285
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   286
        Otherwise default to the default renderer.
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   287
        """
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   288
        for row in range(self.GetNumberRows()):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   289
            for col in range(self.GetNumberCols()):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   290
                editor = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   291
                renderer = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   292
                colname = self.GetColLabelValue(col, False)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   293
                if colname in ["Name", "Description"]:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   294
                    editor = wx.grid.GridCellTextEditor()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   295
                    renderer = wx.grid.GridCellStringRenderer()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   296
                    grid.SetReadOnly(row, col, False)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   297
                else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   298
                    grid.SetReadOnly(row, col, True)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   299
                
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   300
                grid.SetCellEditor(row, col, editor)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   301
                grid.SetCellRenderer(row, col, renderer)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   302
                
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   303
            self.ResizeRow(grid, row)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   304
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   305
class ProcessVariableDropTarget(wx.TextDropTarget):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   306
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   307
    def __init__(self, parent):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   308
        wx.TextDropTarget.__init__(self)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   309
        self.ParentWindow = parent
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   310
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   311
    def OnDropText(self, x, y, data):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   312
        self.ParentWindow.Select()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   313
        x, y = self.ParentWindow.ProcessVariablesGrid.CalcUnscrolledPosition(x, y)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   314
        col = self.ParentWindow.ProcessVariablesGrid.XToCol(x)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   315
        row = self.ParentWindow.ProcessVariablesGrid.YToRow(y - self.ParentWindow.ProcessVariablesGrid.GetColLabelSize())
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   316
        message = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   317
        try:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   318
            values = eval(data)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   319
        except:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   320
            message = _("Invalid value \"%s\" for process variable")%data
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   321
            values = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   322
        if not isinstance(values, TupleType):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   323
            message = _("Invalid value \"%s\" for process variable")%data
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   324
            values = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   325
        if values is not None and 2 <= col <= 3:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   326
            location = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   327
            if values[1] == "location":
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   328
                result = LOCATION_MODEL.match(values[0])
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   329
                if result is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   330
                    location = map(int, result.group(1).split('.'))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   331
                master_location = self.ParentWindow.GetMasterLocation()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   332
                if (master_location == tuple(location[:len(master_location)]) and 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   333
                    len(location) - len(master_location) == 3):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   334
                    if col == 2:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   335
                        self.ParentWindow.ProcessVariablesTable.SetValueByName(
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   336
                            row, "ReadFrom", tuple(location[len(master_location):]))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   337
                    else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   338
                        self.ParentWindow.ProcessVariablesTable.SetValueByName(
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   339
                            row, "WriteTo", tuple(location[len(master_location):]))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   340
                    self.ParentWindow.SaveProcessVariables()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   341
                    self.ParentWindow.RefreshProcessVariables()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   342
                else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   343
                    message = _("Invalid value \"%s\" for process variable")%data
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   344
                    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   345
        if message is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   346
            wx.CallAfter(self.ShowMessage, message)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   347
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   348
    def ShowMessage(self, message):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   349
        message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   350
        message.ShowModal()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   351
        message.Destroy()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   352
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   353
def GetStartupCommandsTableColnames():
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   354
    _ = lambda x : x
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   355
    return [_("Position"), _("Index"), _("Subindex"), _("Value"), _("Description")]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   356
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   357
class StartupCommandDropTarget(wx.TextDropTarget):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   358
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   359
    def __init__(self, parent):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   360
        wx.TextDropTarget.__init__(self)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   361
        self.ParentWindow = parent
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   362
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   363
    def OnDropText(self, x, y, data):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   364
        self.ParentWindow.Select()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   365
        message = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   366
        try:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   367
            values = eval(data)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   368
        except:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   369
            message = _("Invalid value \"%s\" for startup command")%data
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   370
            values = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   371
        if not isinstance(values, TupleType):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   372
            message = _("Invalid value \"%s\" for startup command")%data
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   373
            values = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   374
        if values is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   375
            location = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   376
            if values[1] == "location":
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   377
                result = LOCATION_MODEL.match(values[0])
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   378
                if result is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   379
                    location = map(int, result.group(1).split('.'))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   380
                    access = values[5]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   381
            elif values[1] == "variable":
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   382
                location = values[0]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   383
                access = values[2]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   384
            if location is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   385
                master_location = self.ParentWindow.GetMasterLocation()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   386
                if (master_location == tuple(location[:len(master_location)]) and 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   387
                    len(location) - len(master_location) == 3):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   388
                    if access in ["wo", "rw"]:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   389
                        self.ParentWindow.AddStartupCommand(*location[len(master_location):])
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   390
                    else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   391
                        message = _("Entry can't be write through SDO")
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   392
                else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   393
                    message = _("Invalid value \"%s\" for startup command")%data
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   394
                    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   395
        if message is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   396
            wx.CallAfter(self.ShowMessage, message)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   397
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   398
    def ShowMessage(self, message):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   399
        message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   400
        message.ShowModal()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   401
        message.Destroy()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   402
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   403
class StartupCommandsTable(CustomTable):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   404
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   405
    """
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   406
    A custom wx.grid.Grid Table using user supplied data
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   407
    """
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   408
    def __init__(self, parent, data, colnames):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   409
        # The base class must be initialized *first*
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   410
        CustomTable.__init__(self, parent, data, colnames)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   411
        self.old_value = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   412
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   413
    def GetValue(self, row, col):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   414
        if row < self.GetNumberRows():
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   415
            colname = self.GetColLabelValue(col, False)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   416
            value = self.data[row].get(colname, "")
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   417
            if colname == "Index":
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   418
                return "#x%0.4x" % value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   419
            elif colname == "Subindex":
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   420
                return "#x%0.2x" % value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   421
            return value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   422
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   423
    def SetValue(self, row, col, value):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   424
        if col < len(self.colnames):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   425
            colname = self.GetColLabelValue(col, False)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   426
            if colname in ["Index", "Subindex"]:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   427
                if colname == "Index":
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   428
                    result = ETHERCAT_INDEX_MODEL.match(value)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   429
                else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   430
                    result = ETHERCAT_SUBINDEX_MODEL.match(value)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   431
                if result is None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   432
                    return
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   433
                value = int(result.group(1), 16)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   434
            elif colname == "Value":
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   435
                value = int(value)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   436
            elif colname == "Position":
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   437
                self.old_value = self.data[row][colname]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   438
                value = int(value)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   439
            self.data[row][colname] = value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   440
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   441
    def GetOldValue(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   442
        return self.old_value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   443
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   444
    def _updateColAttrs(self, grid):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   445
        """
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   446
        wx.grid.Grid -> update the column attributes to add the
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   447
        appropriate renderer given the column name.
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   448
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   449
        Otherwise default to the default renderer.
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   450
        """
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   451
        for row in range(self.GetNumberRows()):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   452
            for col in range(self.GetNumberCols()):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   453
                editor = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   454
                renderer = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   455
                colname = self.GetColLabelValue(col, False)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   456
                if colname in ["Position", "Value"]:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   457
                    editor = wx.grid.GridCellNumberEditor()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   458
                    renderer = wx.grid.GridCellNumberRenderer()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   459
                else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   460
                    editor = wx.grid.GridCellTextEditor()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   461
                    renderer = wx.grid.GridCellStringRenderer()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   462
                
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   463
                grid.SetCellEditor(row, col, editor)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   464
                grid.SetCellRenderer(row, col, renderer)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   465
                grid.SetReadOnly(row, col, False)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   466
                
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   467
            self.ResizeRow(grid, row)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   468
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   469
    def GetCommandIndex(self, position, command_idx):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   470
        for row, command in enumerate(self.data):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   471
            if command["Position"] == position and command["command_idx"] == command_idx:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   472
                return row
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   473
        return None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   474
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   475
class MasterNodesVariablesSizer(NodeVariablesSizer):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   476
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   477
    def __init__(self, parent, controler):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   478
        NodeVariablesSizer.__init__(self, parent, controler, True)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   479
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   480
        self.CurrentNodesFilter = {}
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   481
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   482
    def SetCurrentNodesFilter(self, nodes_filter):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   483
        self.CurrentNodesFilter = nodes_filter
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   484
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   485
    def RefreshView(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   486
        if self.CurrentNodesFilter is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   487
            args = self.CurrentNodesFilter.copy()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   488
            args["limits"] = self.CurrentFilter
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   489
            entries = self.Controler.GetNodesVariables(**args)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   490
            self.RefreshVariablesGrid(entries)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   491
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   492
class MasterEditor(ConfTreeNodeEditor):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   493
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   494
    CONFNODEEDITOR_TABS = [
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   495
        (_("Network"), "_create_EthercatMasterEditor")]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   496
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   497
    def _create_EthercatMasterEditor(self, prnt):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   498
        self.EthercatMasterEditor = wx.ScrolledWindow(prnt, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   499
            style=wx.TAB_TRAVERSAL|wx.HSCROLL|wx.VSCROLL)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   500
        self.EthercatMasterEditor.Bind(wx.EVT_SIZE, self.OnResize)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   501
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   502
        main_sizer = wx.BoxSizer(wx.VERTICAL)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   503
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   504
        self.NodesFilter = wx.ComboBox(self.EthercatMasterEditor,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   505
            style=wx.TE_PROCESS_ENTER)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   506
        self.Bind(wx.EVT_COMBOBOX, self.OnNodesFilterChanged, self.NodesFilter)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   507
        self.Bind(wx.EVT_TEXT_ENTER, self.OnNodesFilterChanged, self.NodesFilter)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   508
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   509
        process_variables_header = wx.BoxSizer(wx.HORIZONTAL)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   510
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   511
        process_variables_label = wx.StaticText(self.EthercatMasterEditor,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   512
              label=_("Process variables mapped between nodes:"))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   513
        process_variables_header.AddWindow(process_variables_label, 1,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   514
              flag=wx.ALIGN_CENTER_VERTICAL)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   515
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   516
        for name, bitmap, help in [
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   517
                ("AddVariableButton", "add_element", _("Add process variable")),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   518
                ("DeleteVariableButton", "remove_element", _("Remove process variable")),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   519
                ("UpVariableButton", "up", _("Move process variable up")),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   520
                ("DownVariableButton", "down", _("Move process variable down"))]:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   521
            button = wx.lib.buttons.GenBitmapButton(self.EthercatMasterEditor, bitmap=GetBitmap(bitmap), 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   522
                  size=wx.Size(28, 28), style=wx.NO_BORDER)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   523
            button.SetToolTipString(help)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   524
            setattr(self, name, button)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   525
            process_variables_header.AddWindow(button, border=5, flag=wx.LEFT)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   526
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   527
        self.ProcessVariablesGrid = CustomGrid(self.EthercatMasterEditor, style=wx.VSCROLL)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   528
        self.ProcessVariablesGrid.SetMinSize(wx.Size(0, 150))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   529
        self.ProcessVariablesGrid.SetDropTarget(ProcessVariableDropTarget(self))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   530
        self.ProcessVariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   531
              self.OnProcessVariablesGridCellChange)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   532
        self.ProcessVariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   533
              self.OnProcessVariablesGridCellLeftClick)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   534
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   535
        startup_commands_header = wx.BoxSizer(wx.HORIZONTAL)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   536
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   537
        startup_commands_label = wx.StaticText(self.EthercatMasterEditor,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   538
              label=_("Startup service variables assignments:"))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   539
        startup_commands_header.AddWindow(startup_commands_label, 1,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   540
              flag=wx.ALIGN_CENTER_VERTICAL)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   541
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   542
        for name, bitmap, help in [
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   543
                ("AddCommandButton", "add_element", _("Add startup service variable")),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   544
                ("DeleteCommandButton", "remove_element", _("Remove startup service variable"))]:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   545
            button = wx.lib.buttons.GenBitmapButton(self.EthercatMasterEditor, bitmap=GetBitmap(bitmap), 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   546
                  size=wx.Size(28, 28), style=wx.NO_BORDER)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   547
            button.SetToolTipString(help)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   548
            setattr(self, name, button)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   549
            startup_commands_header.AddWindow(button, border=5, flag=wx.LEFT)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   550
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   551
        self.StartupCommandsGrid = CustomGrid(self.EthercatMasterEditor, style=wx.VSCROLL)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   552
        self.StartupCommandsGrid.SetDropTarget(StartupCommandDropTarget(self))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   553
        self.StartupCommandsGrid.SetMinSize(wx.Size(0, 150))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   554
        self.StartupCommandsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   555
              self.OnStartupCommandsGridCellChange)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   556
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   557
        second_staticbox = wx.StaticBox(self.EthercatMasterEditor, label=_("Nodes variables filter:"))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   558
        second_staticbox_sizer = wx.StaticBoxSizer(second_staticbox, wx.VERTICAL)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   559
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   560
        self.NodesVariables = MasterNodesVariablesSizer(self.EthercatMasterEditor, self.Controler)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   561
        second_staticbox_sizer.AddSizer(self.NodesVariables, 1, border=5, flag=wx.GROW|wx.ALL)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   562
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   563
        main_staticbox = wx.StaticBox(self.EthercatMasterEditor, label=_("Node filter:"))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   564
        staticbox_sizer = wx.StaticBoxSizer(main_staticbox, wx.VERTICAL)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   565
        main_sizer.AddSizer(staticbox_sizer, border=10, flag=wx.GROW|wx.ALL)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   566
        main_staticbox_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=5, vgap=0)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   567
        main_staticbox_sizer.AddGrowableCol(0)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   568
        main_staticbox_sizer.AddGrowableRow(1)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   569
        main_staticbox_sizer.AddGrowableRow(3)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   570
        staticbox_sizer.AddSizer(main_staticbox_sizer, 1, flag=wx.GROW)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   571
        main_staticbox_sizer.AddWindow(self.NodesFilter, border=5, flag=wx.GROW|wx.ALL)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   572
        main_staticbox_sizer.AddSizer(process_variables_header, border=5, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   573
              flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   574
        main_staticbox_sizer.AddWindow(self.ProcessVariablesGrid, 1, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   575
              border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   576
        main_staticbox_sizer.AddSizer(startup_commands_header, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   577
              border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   578
        main_staticbox_sizer.AddWindow(self.StartupCommandsGrid, 1, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   579
              border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   580
        main_staticbox_sizer.AddSizer(second_staticbox_sizer, 1, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   581
            border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   582
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   583
        self.EthercatMasterEditor.SetSizer(main_sizer)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   584
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   585
        return self.EthercatMasterEditor
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   586
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   587
    def __init__(self, parent, controler, window):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   588
        ConfTreeNodeEditor.__init__(self, parent, controler, window)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   589
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   590
        self.ProcessVariablesDefaultValue = {"Name": "", "ReadFrom": "", "WriteTo": "", "Description": ""}
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   591
        self.ProcessVariablesTable = ProcessVariablesTable(self, [], GetProcessVariablesTableColnames())
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   592
        self.ProcessVariablesColSizes = [40, 100, 150, 150, 200]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   593
        self.ProcessVariablesColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   594
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   595
        self.ProcessVariablesGrid.SetTable(self.ProcessVariablesTable)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   596
        self.ProcessVariablesGrid.SetButtons({"Add": self.AddVariableButton,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   597
                                              "Delete": self.DeleteVariableButton,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   598
                                              "Up": self.UpVariableButton,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   599
                                              "Down": self.DownVariableButton})
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   600
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   601
        def _AddVariablesElement(new_row):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   602
            self.ProcessVariablesTable.InsertRow(new_row, self.ProcessVariablesDefaultValue.copy())
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   603
            self.SaveProcessVariables()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   604
            self.ProcessVariablesTable.ResetView(self.ProcessVariablesGrid)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   605
            return new_row
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   606
        setattr(self.ProcessVariablesGrid, "_AddRow", _AddVariablesElement)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   607
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   608
        def _DeleteVariablesElement(row):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   609
            self.ProcessVariablesTable.RemoveRow(row)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   610
            self.SaveProcessVariables()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   611
            self.ProcessVariablesTable.ResetView(self.ProcessVariablesGrid)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   612
        setattr(self.ProcessVariablesGrid, "_DeleteRow", _DeleteVariablesElement)
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   613
            
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   614
        def _MoveVariablesElement(row, move):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   615
            new_row = self.ProcessVariablesTable.MoveRow(row, move)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   616
            if new_row != row:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   617
                self.SaveProcessVariables()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   618
                self.ProcessVariablesTable.ResetView(self.ProcessVariablesGrid)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   619
            return new_row
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   620
        setattr(self.ProcessVariablesGrid, "_MoveRow", _MoveVariablesElement)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   621
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   622
        self.ProcessVariablesGrid.SetRowLabelSize(0)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   623
        for col in range(self.ProcessVariablesTable.GetNumberCols()):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   624
            attr = wx.grid.GridCellAttr()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   625
            attr.SetAlignment(self.ProcessVariablesColAlignements[col], wx.ALIGN_CENTRE)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   626
            self.ProcessVariablesGrid.SetColAttr(col, attr)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   627
            self.ProcessVariablesGrid.SetColMinimalWidth(col, self.ProcessVariablesColSizes[col])
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   628
            self.ProcessVariablesGrid.AutoSizeColumn(col, False)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   629
        self.ProcessVariablesGrid.RefreshButtons()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   630
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   631
        self.StartupCommandsDefaultValue = {"Position": 0, "Index": 0, "Subindex": 0, "Value": 0, "Description": ""}
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   632
        self.StartupCommandsTable = StartupCommandsTable(self, [], GetStartupCommandsTableColnames())
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   633
        self.StartupCommandsColSizes = [100, 100, 50, 100, 200]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   634
        self.StartupCommandsColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT, wx.ALIGN_LEFT]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   635
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   636
        self.StartupCommandsGrid.SetTable(self.StartupCommandsTable)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   637
        self.StartupCommandsGrid.SetButtons({"Add": self.AddCommandButton,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   638
                                             "Delete": self.DeleteCommandButton})
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   639
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   640
        def _AddCommandsElement(new_row):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   641
            command = self.StartupCommandsDefaultValue.copy()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   642
            command_idx = self.Controler.AppendStartupCommand(command)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   643
            self.RefreshStartupCommands()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   644
            self.RefreshBuffer()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   645
            return self.StartupCommandsTable.GetCommandIndex(command["Position"], command_idx)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   646
        setattr(self.StartupCommandsGrid, "_AddRow", _AddCommandsElement)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   647
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   648
        def _DeleteCommandsElement(row):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   649
            command = self.StartupCommandsTable.GetRow(row)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   650
            self.Controler.RemoveStartupCommand(command["Position"], command["command_idx"])
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   651
            self.RefreshStartupCommands()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   652
            self.RefreshBuffer()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   653
        setattr(self.StartupCommandsGrid, "_DeleteRow", _DeleteCommandsElement)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   654
            
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   655
        self.StartupCommandsGrid.SetRowLabelSize(0)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   656
        for col in range(self.StartupCommandsTable.GetNumberCols()):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   657
            attr = wx.grid.GridCellAttr()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   658
            attr.SetAlignment(self.StartupCommandsColAlignements[col], wx.ALIGN_CENTRE)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   659
            self.StartupCommandsGrid.SetColAttr(col, attr)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   660
            self.StartupCommandsGrid.SetColMinimalWidth(col, self.StartupCommandsColSizes[col])
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   661
            self.StartupCommandsGrid.AutoSizeColumn(col, False)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   662
        self.StartupCommandsGrid.RefreshButtons()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   663
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   664
    def RefreshBuffer(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   665
        self.ParentWindow.RefreshTitle()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   666
        self.ParentWindow.RefreshFileMenu()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   667
        self.ParentWindow.RefreshEditMenu()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   668
        self.ParentWindow.RefreshPageTitles()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   669
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   670
    def RefreshView(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   671
        ConfTreeNodeEditor.RefreshView(self)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   672
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   673
        self.RefreshNodesFilter()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   674
        self.RefreshProcessVariables()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   675
        self.RefreshStartupCommands()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   676
        self.NodesVariables.RefreshView()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   677
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   678
    def RefreshNodesFilter(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   679
        value = self.NodesFilter.GetValue()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   680
        self.NodesFilter.Clear()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   681
        self.NodesFilter.Append(_("All"))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   682
        self.NodesFilterValues = [{}]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   683
        for vendor_id, vendor_name in self.Controler.GetLibraryVendors():
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   684
            self.NodesFilter.Append(_("%s's nodes") % vendor_name)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   685
            self.NodesFilterValues.append({"vendor": vendor_id})
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   686
        self.NodesFilter.Append(_("CIA402 nodes"))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   687
        self.NodesFilterValues.append({"slave_profile": 402})
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   688
        if value in self.NodesFilter.GetStrings():
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   689
            self.NodesFilter.SetStringSelection(value)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   690
        else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   691
            try:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   692
                int(value)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   693
                self.NodesFilter.SetValue(value)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   694
            except:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   695
                self.NodesFilter.SetSelection(0)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   696
        self.RefreshCurrentNodesFilter()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   697
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   698
    def RefreshCurrentNodesFilter(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   699
        filter = self.NodesFilter.GetSelection()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   700
        if filter != -1:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   701
            self.CurrentNodesFilter = self.NodesFilterValues[filter]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   702
        else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   703
            try:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   704
                self.CurrentNodesFilter = {"slave_pos": int(self.NodesFilter.GetValue())}
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   705
            except:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   706
                self.CurrentNodesFilter = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   707
        self.NodesVariables.SetCurrentNodesFilter(self.CurrentNodesFilter)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   708
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   709
    def RefreshProcessVariables(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   710
        self.ProcessVariablesTable.SetData(
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   711
            self.Controler.GetProcessVariables())
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   712
        self.ProcessVariablesTable.ResetView(self.ProcessVariablesGrid)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   713
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   714
    def SaveProcessVariables(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   715
        self.Controler.SetProcessVariables(
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   716
            self.ProcessVariablesTable.GetData())
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   717
        self.RefreshBuffer()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   718
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   719
    def RefreshStartupCommands(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   720
        if self.CurrentNodesFilter is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   721
            self.StartupCommandsTable.SetData(
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   722
                self.Controler.GetStartupCommands(**self.CurrentNodesFilter))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   723
            self.StartupCommandsTable.ResetView(self.StartupCommandsGrid)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   724
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   725
    def SelectStartupCommand(self, position, command_idx):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   726
        self.StartupCommandsGrid.SetSelectedRow(
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   727
            self.StartupCommandsTable.GetCommandIndex(position, command_idx))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   728
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   729
    def GetMasterLocation(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   730
        return self.Controler.GetCurrentLocation()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   731
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   732
    def AddStartupCommand(self, position, index, subindex):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   733
        command = self.StartupCommandsDefaultValue.copy()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   734
        command["Position"] = position
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   735
        command["Index"] = index
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   736
        command["Subindex"] = subindex
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   737
        command_idx = self.Controler.AppendStartupCommand(command)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   738
        self.RefreshStartupCommands()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   739
        self.RefreshBuffer()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   740
        self.StartupCommandsGrid.SetSelectedRow(
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   741
            self.StartupCommandsTable.GetCommandIndex(position, command_idx))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   742
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   743
    def OnNodesFilterChanged(self, event):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   744
        self.RefreshCurrentNodesFilter()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   745
        if self.CurrentNodesFilter is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   746
            self.RefreshStartupCommands()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   747
            self.NodesVariables.RefreshView()
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   748
        event.Skip()
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   749
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   750
    def OnProcessVariablesGridCellChange(self, event):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   751
        row, col = event.GetRow(), event.GetCol()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   752
        colname = self.ProcessVariablesTable.GetColLabelValue(col, False)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   753
        value = self.ProcessVariablesTable.GetValue(row, col)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   754
        message = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   755
        if colname == "Name":
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   756
            if not TestIdentifier(value):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   757
                message = _("\"%s\" is not a valid identifier!") % value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   758
            elif value.upper() in IEC_KEYWORDS:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   759
                message = _("\"%s\" is a keyword. It can't be used!") % value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   760
            elif value.upper() in [var["Name"].upper() for idx, var in enumerate(self.ProcessVariablesTable.GetData()) if idx != row]:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   761
                message = _("An variable named \"%s\" already exists!") % value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   762
        if message is None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   763
            self.SaveProcessVariables()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   764
            wx.CallAfter(self.ProcessVariablesTable.ResetView, self.ProcessVariablesGrid)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   765
            event.Skip()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   766
        else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   767
            dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   768
            dialog.ShowModal()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   769
            dialog.Destroy()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   770
            event.Veto()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   771
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   772
    def OnProcessVariablesGridCellLeftClick(self, event):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   773
        event.Skip()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   774
    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   775
    def OnStartupCommandsGridCellChange(self, event):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   776
        row, col = event.GetRow(), event.GetCol()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   777
        colname = self.StartupCommandsTable.GetColLabelValue(col, False)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   778
        value = self.StartupCommandsTable.GetValue(row, col)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   779
        message = None
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   780
        if colname == "Position":
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   781
            if value not in self.Controler.GetSlaves():
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   782
                message = _("No slave defined at position %d!") % value
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   783
            if message is None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   784
                self.Controler.RemoveStartupCommand(
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   785
                    self.StartupCommandsTable.GetOldValue(),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   786
                    self.StartupCommandsTable.GetValueByName(row, "command_idx"))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   787
                command = self.StartupCommandsTable.GetRow(row)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   788
                command_idx = self.Controler.AppendStartupCommand(command)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   789
                wx.CallAfter(self.RefreshStartupCommands)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   790
                wx.CallAfter(self.SelectStartupCommand, command["Position"], command_idx)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   791
        else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   792
            self.Controler.SetStartupCommandInfos(self.StartupCommandsTable.GetRow(row))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   793
        if message is None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   794
            self.RefreshBuffer()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   795
            event.Skip()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   796
        else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   797
            dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   798
            dialog.ShowModal()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   799
            dialog.Destroy()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   800
            event.Veto()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   801
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   802
    def OnResize(self, event):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   803
        self.EthercatMasterEditor.GetBestSize()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   804
        xstart, ystart = self.EthercatMasterEditor.GetViewStart()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   805
        window_size = self.EthercatMasterEditor.GetClientSize()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   806
        maxx, maxy = self.EthercatMasterEditor.GetMinSize()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   807
        posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   808
        posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   809
        self.EthercatMasterEditor.Scroll(posx, posy)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   810
        self.EthercatMasterEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   811
                maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   812
        event.Skip()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   813
    
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   814
def GetModulesTableColnames():
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   815
    _ = lambda x : x
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   816
    return [_("Name"), _("PDO alignment (bits)")]
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   817
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   818
class LibraryEditorSizer(wx.FlexGridSizer):
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   819
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   820
    def __init__(self, parent, module_library, buttons):
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   821
        wx.FlexGridSizer.__init__(self, cols=1, hgap=0, rows=4, vgap=5)
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   822
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   823
        self.ModuleLibrary = module_library
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   824
    
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   825
        self.AddGrowableCol(0)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   826
        self.AddGrowableRow(1)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   827
        self.AddGrowableRow(3)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   828
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   829
        ESI_files_label = wx.StaticText(parent, 
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   830
            label=_("ESI Files:"))
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   831
        self.AddWindow(ESI_files_label, border=10, 
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   832
            flag=wx.TOP|wx.LEFT|wx.RIGHT)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   833
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   834
        folder_tree_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=0)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   835
        folder_tree_sizer.AddGrowableCol(0)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   836
        folder_tree_sizer.AddGrowableRow(0)
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   837
        self.AddSizer(folder_tree_sizer, border=10, 
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   838
            flag=wx.GROW|wx.LEFT|wx.RIGHT)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   839
        
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   840
        self.ESIFiles = FolderTree(parent, self.GetPath(), editable=False)
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   841
        self.ESIFiles.SetFilter(".xml")
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   842
        folder_tree_sizer.AddWindow(self.ESIFiles, flag=wx.GROW)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   843
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   844
        buttons_sizer = wx.BoxSizer(wx.VERTICAL)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   845
        folder_tree_sizer.AddSizer(buttons_sizer, 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   846
            flag=wx.ALIGN_CENTER_VERTICAL)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   847
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   848
        for idx, (name, bitmap, help, callback) in enumerate(buttons):
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   849
            button = wx.lib.buttons.GenBitmapButton(parent, 
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   850
                  bitmap=GetBitmap(bitmap), 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   851
                  size=wx.Size(28, 28), style=wx.NO_BORDER)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   852
            button.SetToolTipString(help)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   853
            setattr(self, name, button)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   854
            if idx > 0:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   855
                flag = wx.TOP
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   856
            else:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   857
                flag = 0
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   858
            if callback is None:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   859
                callback = getattr(self, "On" + name, None)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   860
            if callback is not None:
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   861
                parent.Bind(wx.EVT_BUTTON, callback, button)
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   862
            buttons_sizer.AddWindow(button, border=10, flag=flag)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   863
        
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   864
        modules_label = wx.StaticText(parent, 
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   865
            label=_("Modules library:"))
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   866
        self.AddSizer(modules_label, border=10, 
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   867
            flag=wx.LEFT|wx.RIGHT)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   868
        
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   869
        self.ModulesGrid = wx.gizmos.TreeListCtrl(parent,
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   870
              style=wx.TR_DEFAULT_STYLE |
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   871
                    wx.TR_ROW_LINES |
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   872
                    wx.TR_COLUMN_LINES |
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   873
                    wx.TR_HIDE_ROOT |
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   874
                    wx.TR_FULL_ROW_HIGHLIGHT)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   875
        self.ModulesGrid.GetMainWindow().Bind(wx.EVT_LEFT_DCLICK,
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   876
            self.OnModulesGridLeftDClick)
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   877
        self.AddWindow(self.ModulesGrid, border=10, 
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   878
            flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   879
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   880
        for colname, colsize, colalign in zip(GetModulesTableColnames(),
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   881
                                              [400, 150],
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   882
                                              [wx.ALIGN_LEFT, wx.ALIGN_RIGHT]):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   883
            self.ModulesGrid.AddColumn(_(colname), colsize, colalign)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   884
        self.ModulesGrid.SetMainColumn(0)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   885
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   886
    def GetPath(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   887
        return self.ModuleLibrary.GetPath()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   888
    
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   889
    def SetControlMinSize(self, size):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   890
        self.ESIFiles.SetMinSize(size)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   891
        self.ModulesGrid.SetMinSize(size)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   892
        
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   893
    def GetSelectedFilePath(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   894
        return self.ESIFiles.GetPath()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   895
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   896
    def RefreshView(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   897
        self.ESIFiles.RefreshTree()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   898
        self.RefreshModulesGrid()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   899
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   900
    def RefreshModulesGrid(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   901
        root = self.ModulesGrid.GetRootItem()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   902
        if not root.IsOk():
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   903
            root = self.ModulesGrid.AddRoot("Modules")
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   904
        self.GenerateModulesGridBranch(root, 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   905
            self.ModuleLibrary.GetModulesLibrary(), 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   906
            GetVariablesTableColnames())
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   907
        self.ModulesGrid.Expand(root)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   908
            
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   909
    def GenerateModulesGridBranch(self, root, modules, colnames):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   910
        item, root_cookie = self.ModulesGrid.GetFirstChild(root)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   911
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   912
        no_more_items = not item.IsOk()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   913
        for module in modules:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   914
            if no_more_items:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   915
                item = self.ModulesGrid.AppendItem(root, "")
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   916
            self.ModulesGrid.SetItemText(item, module["name"], 0)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   917
            if module["infos"] is not None:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   918
                self.ModulesGrid.SetItemText(item, str(module["infos"]["alignment"]), 1)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   919
            else:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   920
                self.ModulesGrid.SetItemBackgroundColour(item, wx.LIGHT_GREY)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   921
            self.ModulesGrid.SetItemPyData(item, module["infos"])
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   922
            self.GenerateModulesGridBranch(item, module["children"], colnames)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   923
            if not no_more_items:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   924
                item, root_cookie = self.ModulesGrid.GetNextChild(root, root_cookie)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   925
                no_more_items = not item.IsOk()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   926
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   927
        if not no_more_items:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   928
            to_delete = []
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   929
            while item.IsOk():
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   930
                to_delete.append(item)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   931
                item, root_cookie = self.ModulesGrid.GetNextChild(root, root_cookie)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   932
            for item in to_delete:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   933
                self.ModulesGrid.Delete(item)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   934
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   935
    def OnImportButton(self, event):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   936
        dialog = wx.FileDialog(self,
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   937
             _("Choose an XML file"), 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   938
             os.getcwd(), "",  
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   939
             _("XML files (*.xml)|*.xml|All files|*.*"), wx.OPEN)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   940
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   941
        if dialog.ShowModal() == wx.ID_OK:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   942
            filepath = dialog.GetPath()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   943
            if self.ModuleLibrary.ImportModuleLibrary(filepath):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   944
                wx.CallAfter(self.RefreshView)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   945
            else:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   946
                message = wx.MessageDialog(self, 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   947
                    _("No such XML file: %s\n") % filepath, 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   948
                    _("Error"), wx.OK|wx.ICON_ERROR)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   949
                message.ShowModal()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   950
                message.Destroy()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   951
        dialog.Destroy()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   952
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   953
        event.Skip()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   954
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   955
    def OnDeleteButton(self, event):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   956
        filepath = self.GetSelectedFilePath()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   957
        if os.path.isfile(filepath):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   958
            folder, filename = os.path.split(filepath)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   959
            
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   960
            dialog = wx.MessageDialog(self, 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   961
                  _("Do you really want to delete the file '%s'?") % filename, 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   962
                  _("Delete File"), wx.YES_NO|wx.ICON_QUESTION)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   963
            remove = dialog.ShowModal() == wx.ID_YES
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   964
            dialog.Destroy()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   965
            
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   966
            if remove:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   967
                os.remove(filepath)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   968
                self.ModuleLibrary.LoadModules()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   969
                wx.CallAfter(self.RefreshView)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   970
        event.Skip()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   971
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   972
    def OnModulesGridLeftDClick(self, event):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   973
        item, flags, col = self.ModulesGrid.HitTest(event.GetPosition())
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   974
        if item.IsOk():
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   975
            entry_infos = self.ModulesGrid.GetItemPyData(item)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   976
            if entry_infos is not None and col == 1:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   977
                dialog = wx.TextEntryDialog(self, 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   978
                    _("Set PDO alignment (bits):"),
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   979
                    _("%s PDO alignment") % self.ModulesGrid.GetItemText(item), 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   980
                    str(entry_infos["alignment"]))
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   981
                
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   982
                if dialog.ShowModal() == wx.ID_OK:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   983
                    try:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   984
                        self.ModuleLibrary.SetAlignment(
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   985
                            entry_infos["vendor"],
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   986
                            entry_infos["product_code"],
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   987
                            entry_infos["revision_number"],
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   988
                            int(dialog.GetValue()))
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   989
                        wx.CallAfter(self.RefreshModulesGrid)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   990
                    except ValueError:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   991
                        message = wx.MessageDialog(self, 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   992
                            _("Module PDO alignment must be an integer!"), 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   993
                            _("Error"), wx.OK|wx.ICON_ERROR)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   994
                        message.ShowModal()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   995
                        message.Destroy()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   996
                    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   997
                dialog.Destroy()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   998
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
   999
        event.Skip()
2058
b3bc00dae385 Replacing Panel by ScrolledWindow for displaying node information for more clarity when window is small
Laurent Bessard
parents: 2056
diff changeset
  1000
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1001
class DatabaseManagementDialog(wx.Dialog):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1002
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1003
    def __init__(self, parent, database):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1004
        wx.Dialog.__init__(self, parent,
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1005
              size=wx.Size(700, 500), title=_('ESI Files Database management'),
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1006
              style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1007
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1008
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1009
        main_sizer.AddGrowableCol(0)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1010
        main_sizer.AddGrowableRow(0)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1011
        
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1012
        self.DatabaseSizer = LibraryEditorSizer(self, database,
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1013
            [("ImportButton", "ImportESI", _("Import file to ESI files database"), None),
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1014
             ("DeleteButton", "remove_element", _("Remove file from database"), None)])
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1015
        self.DatabaseSizer.SetControlMinSize(wx.Size(0, 0))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1016
        main_sizer.AddSizer(self.DatabaseSizer, border=10,
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1017
            flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1018
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1019
        button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1020
        button_sizer.GetAffirmativeButton().SetLabel(_("Add file to project"))
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1021
        button_sizer.GetCancelButton().SetLabel(_("Close"))
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1022
        main_sizer.AddSizer(button_sizer, border=10, 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1023
              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1024
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1025
        self.SetSizer(main_sizer)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1026
        
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1027
        self.DatabaseSizer.RefreshView()
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1028
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1029
    def GetValue(self):
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1030
        return self.DatabaseSizer.GetSelectedFilePath()
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1031
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1032
class LibraryEditor(ConfTreeNodeEditor):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1033
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1034
    CONFNODEEDITOR_TABS = [
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1035
        (_("Modules Library"), "_create_ModuleLibraryEditor")]
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1036
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1037
    def _create_ModuleLibraryEditor(self, prnt):
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1038
        self.ModuleLibraryEditor = wx.ScrolledWindow(prnt,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1039
            style=wx.TAB_TRAVERSAL|wx.HSCROLL|wx.VSCROLL)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1040
        self.ModuleLibraryEditor.Bind(wx.EVT_SIZE, self.OnResize)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1041
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1042
        self.ModuleLibrarySizer = LibraryEditorSizer(self.ModuleLibraryEditor,
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1043
            self.Controler.GetModulesLibraryInstance(),
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1044
            [("ImportButton", "ImportESI", _("Import ESI file"), None),
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1045
             ("AddButton", "ImportDatabase", _("Add file from ESI files database"), self.OnAddButton),
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1046
             ("DeleteButton", "remove_element", _("Remove file from library"), None)])
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1047
        self.ModuleLibrarySizer.SetControlMinSize(wx.Size(0, 200))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1048
        self.ModuleLibraryEditor.SetSizer(self.ModuleLibrarySizer)
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1049
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1050
        return self.ModuleLibraryEditor
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1051
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1052
    def __init__(self, parent, controler, window):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1053
        ConfTreeNodeEditor.__init__(self, parent, controler, window)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1054
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1055
        self.RefreshView()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1056
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1057
    def RefreshView(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1058
        ConfTreeNodeEditor.RefreshView(self)
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1059
        self.ModuleLibrarySizer.RefreshView()
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1060
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1061
    def OnAddButton(self, event):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1062
        dialog = DatabaseManagementDialog(self, 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1063
            self.Controler.GetModulesDatabaseInstance())
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1064
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1065
        if dialog.ShowModal() == wx.ID_OK:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1066
            module_library = self.Controler.GetModulesLibraryInstance()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1067
            module_library.ImportModuleLibrary(dialog.GetValue())
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1068
            
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1069
        dialog.Destroy()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1070
        
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1071
        wx.CallAfter(self.ModuleLibrarySizer.RefreshView)
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1072
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1073
        event.Skip()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2095
diff changeset
  1074
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1075
    def OnResize(self, event):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1076
        self.ModuleLibraryEditor.GetBestSize()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1077
        xstart, ystart = self.ModuleLibraryEditor.GetViewStart()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1078
        window_size = self.ModuleLibraryEditor.GetClientSize()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1079
        maxx, maxy = self.ModuleLibraryEditor.GetMinSize()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1080
        posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1081
        posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1082
        self.ModuleLibraryEditor.Scroll(posx, posy)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1083
        self.ModuleLibraryEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1084
                maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1085
        event.Skip()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1086
        
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
  1087