objdictgen/subindextable.py
author greg
Mon, 02 Jun 2008 08:52:06 +0200
changeset 467 40efa79d27dd
parent 453 c74a73474cce
child 485 24b506ea314b
permissions -rw-r--r--
kerneltest updated for the new api
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     1
#!/usr/bin/env python
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     3
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     4
#This file is part of CanFestival, a library implementing CanOpen Stack. 
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     5
#
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     6
#Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     7
#
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     8
#See COPYING file for copyrights details.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     9
#
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    10
#This library is free software; you can redistribute it and/or
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    11
#modify it under the terms of the GNU Lesser General Public
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    12
#License as published by the Free Software Foundation; either
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    13
#version 2.1 of the License, or (at your option) any later version.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    14
#
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    15
#This library is distributed in the hope that it will be useful,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    16
#but WITHOUT ANY WARRANTY; without even the implied warranty of
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    17
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    18
#Lesser General Public License for more details.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    19
#
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    20
#You should have received a copy of the GNU Lesser General Public
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    21
#License along with this library; if not, write to the Free Software
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    22
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    23
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    24
import wx
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    25
import wx.grid
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    26
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    27
from types import *
281
685d9a26e4f9 Obsolete example files in objdictgen/examples replaced by some new equivalents
lbessard
parents: 277
diff changeset
    28
from commondialogs import *
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    29
206
6787754b251b Bugs corrected on objdictedit and networkdict
greg
parents: 205
diff changeset
    30
from node import OD_Subindex, OD_MultipleSubindexes, OD_IdenticalSubindexes, OD_IdenticalIndexes
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    31
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    32
ColSizes = [75, 250, 150, 125, 100, 60, 250]
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    33
ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_RIGHT, wx.ALIGN_CENTER, wx.ALIGN_CENTER, wx.ALIGN_LEFT]
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    34
AccessList = "Read Only,Write Only,Read/Write"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    35
RAccessList = "Read Only,Read/Write"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    36
BoolList = "True,False"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    37
OptionList = "Yes,No"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    38
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    39
DictionaryOrganisation = [
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    40
    {"minIndex" : 0x0001, "maxIndex" : 0x0FFF, "name" : "Data Type Definitions"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    41
    {"minIndex" : 0x1000, "maxIndex" : 0x1029, "name" : "Communication Parameters"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    42
    {"minIndex" : 0x1200, "maxIndex" : 0x12FF, "name" : "SDO Parameters"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    43
    {"minIndex" : 0x1400, "maxIndex" : 0x15FF, "name" : "Receive PDO Parameters"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    44
    {"minIndex" : 0x1600, "maxIndex" : 0x17FF, "name" : "Receive PDO Mapping"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    45
    {"minIndex" : 0x1800, "maxIndex" : 0x19FF, "name" : "Transmit PDO Parameters"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    46
    {"minIndex" : 0x1A00, "maxIndex" : 0x1BFF, "name" : "Transmit PDO Mapping"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    47
    {"minIndex" : 0x1C00, "maxIndex" : 0x1FFF, "name" : "Other Communication Parameters"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    48
    {"minIndex" : 0x2000, "maxIndex" : 0x5FFF, "name" : "Manufacturer Specific"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    49
    {"minIndex" : 0x6000, "maxIndex" : 0x9FFF, "name" : "Standardized Device Profile"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    50
    {"minIndex" : 0xA000, "maxIndex" : 0xBFFF, "name" : "Standardized Interface Profile"}]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    51
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 237
diff changeset
    52
SizeConversion = {1 : "X", 8 : "B", 16 : "W", 24 : "D", 32 : "D", 40 : "L", 48 : "L", 56 : "L", 64 : "L"}
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 237
diff changeset
    53
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    54
class SubindexTable(wx.grid.PyGridTableBase):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    55
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    56
    """
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    57
    A custom wxGrid Table using user supplied data
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    58
    """
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    59
    def __init__(self, parent, data, editors, colnames):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    60
        # The base class must be initialized *first*
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    61
        wx.grid.PyGridTableBase.__init__(self)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    62
        self.data = data
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    63
        self.editors = editors
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    64
        self.CurrentIndex = 0
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    65
        self.colnames = colnames
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    66
        self.Parent = parent
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    67
        self.Editable = True
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    68
        # XXX
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    69
        # we need to store the row length and collength to
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    70
        # see if the table has changed size
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    71
        self._rows = self.GetNumberRows()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    72
        self._cols = self.GetNumberCols()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    73
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    74
    def Disable(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    75
        self.Editable = False
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    76
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    77
    def Enable(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    78
        self.Editable = True
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    79
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    80
    def GetNumberCols(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    81
        return len(self.colnames)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    82
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    83
    def GetNumberRows(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    84
        return len(self.data)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    85
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    86
    def GetColLabelValue(self, col):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    87
        if col < len(self.colnames):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    88
            return self.colnames[col]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    89
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    90
    def GetRowLabelValues(self, row):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    91
        return row
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    92
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    93
    def GetValue(self, row, col):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    94
        if row < self.GetNumberRows():
266
8678a3cf7fe7 Code corrections
lbessard
parents: 254
diff changeset
    95
            return str(self.data[row].get(self.GetColLabelValue(col), ""))
8678a3cf7fe7 Code corrections
lbessard
parents: 254
diff changeset
    96
            
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    97
    def GetEditor(self, row, col):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    98
        if row < self.GetNumberRows():
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    99
            return self.editors[row].get(self.GetColLabelValue(col), "")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   100
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   101
    def GetValueByName(self, row, colname):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   102
        return self.data[row].get(colname)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   103
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   104
    def SetValue(self, row, col, value):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   105
        if col < len(self.colnames):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   106
            self.data[row][self.GetColLabelValue(col)] = value
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   107
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   108
    def ResetView(self, grid):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   109
        """
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   110
        (wx.grid.Grid) -> Reset the grid view.   Call this to
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   111
        update the grid if rows and columns have been added or deleted
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   112
        """
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   113
        grid.BeginBatch()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   114
        for current, new, delmsg, addmsg in [
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   115
            (self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED),
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   116
            (self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED),
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   117
        ]:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   118
            if new < current:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   119
                msg = wx.grid.GridTableMessage(self,delmsg,new,current-new)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   120
                grid.ProcessTableMessage(msg)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   121
            elif new > current:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   122
                msg = wx.grid.GridTableMessage(self,addmsg,new-current)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   123
                grid.ProcessTableMessage(msg)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   124
                self.UpdateValues(grid)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   125
        grid.EndBatch()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   126
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   127
        self._rows = self.GetNumberRows()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   128
        self._cols = self.GetNumberCols()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   129
        # update the column rendering scheme
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   130
        self._updateColAttrs(grid)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   131
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   132
        # update the scrollbars and the displayed part of the grid
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   133
        grid.AdjustScrollbars()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   134
        grid.ForceRefresh()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   135
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   136
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   137
    def UpdateValues(self, grid):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   138
        """Update all displayed values"""
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   139
        # This sends an event to the grid table to update all of the values
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   140
        msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   141
        grid.ProcessTableMessage(msg)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   142
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   143
    def _updateColAttrs(self, grid):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   144
        """
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   145
        wx.grid.Grid -> update the column attributes to add the
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   146
        appropriate renderer given the column name.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   147
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   148
        Otherwise default to the default renderer.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   149
        """
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   150
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   151
        for col in range(self.GetNumberCols()):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   152
            attr = wx.grid.GridCellAttr()
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   153
            attr.SetAlignment(ColAlignements[col], wx.ALIGN_CENTRE)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   154
            grid.SetColAttr(col, attr)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   155
            grid.SetColSize(col, ColSizes[col])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   156
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   157
        typelist = None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   158
        maplist = None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   159
        for row in range(self.GetNumberRows()):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   160
            editors = self.editors[row]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   161
            for col in range(self.GetNumberCols()):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   162
                editor = None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   163
                renderer = None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   164
                
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   165
                colname = self.GetColLabelValue(col)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   166
                editortype = editors[colname]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   167
                if editortype and self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   168
                    grid.SetReadOnly(row, col, False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   169
                    if editortype == "string":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   170
                        editor = wx.grid.GridCellTextEditor()
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   171
                        renderer = wx.grid.GridCellStringRenderer()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   172
                        if colname == "value" and "length" in editors:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   173
                            editor.SetParameters(editors["length"]) 
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   174
                    elif editortype == "number":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   175
                        editor = wx.grid.GridCellNumberEditor()
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   176
                        renderer = wx.grid.GridCellNumberRenderer()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   177
                        if colname == "value" and "min" in editors and "max" in editors:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   178
                            editor.SetParameters("%s,%s"%(editors["min"],editors["max"]))
453
c74a73474cce Problem with Real types unsupported fixed
lbessard
parents: 340
diff changeset
   179
                    elif editortype == "float":
c74a73474cce Problem with Real types unsupported fixed
lbessard
parents: 340
diff changeset
   180
                        editor = wx.grid.GridCellTextEditor()
c74a73474cce Problem with Real types unsupported fixed
lbessard
parents: 340
diff changeset
   181
                        renderer = wx.grid.GridCellStringRenderer()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   182
                    elif editortype == "bool":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   183
                        editor = wx.grid.GridCellChoiceEditor()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   184
                        editor.SetParameters(BoolList)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   185
                    elif editortype == "access":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   186
                        editor = wx.grid.GridCellChoiceEditor()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   187
                        editor.SetParameters(AccessList)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   188
                    elif editortype == "raccess":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   189
                        editor = wx.grid.GridCellChoiceEditor()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   190
                        editor.SetParameters(RAccessList)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   191
                    elif editortype == "option":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   192
                        editor = wx.grid.GridCellChoiceEditor()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   193
                        editor.SetParameters(OptionList)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   194
                    elif editortype == "type":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   195
                        editor = wx.grid.GridCellChoiceEditor()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   196
                        if typelist == None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   197
                            typelist = self.Parent.Manager.GetCurrentTypeList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   198
                        editor.SetParameters(typelist)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   199
                    elif editortype == "map":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   200
                        editor = wx.grid.GridCellChoiceEditor()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   201
                        if maplist == None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   202
                            maplist = self.Parent.Manager.GetCurrentMapList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   203
                        editor.SetParameters(maplist)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   204
                    elif editortype == "time":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   205
                        editor = wx.grid.GridCellTextEditor()
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   206
                        renderer = wx.grid.GridCellStringRenderer()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   207
                    elif editortype == "domain":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   208
                        editor = wx.grid.GridCellTextEditor()
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   209
                        renderer = wx.grid.GridCellStringRenderer()
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   210
                    elif editortype == "dcf":
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   211
                        editor = wx.grid.GridCellTextEditor()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   212
                        renderer = wx.grid.GridCellStringRenderer()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   213
                else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   214
                    grid.SetReadOnly(row, col, True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   215
                    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   216
                grid.SetCellEditor(row, col, editor)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   217
                grid.SetCellRenderer(row, col, renderer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   218
                
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   219
                grid.SetCellBackgroundColour(row, col, wx.WHITE)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   220
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   221
    def SetData(self, data):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   222
        self.data = data
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   223
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   224
    def SetEditors(self, editors):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   225
        self.editors = editors
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   226
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   227
    def GetCurrentIndex(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   228
        return self.CurrentIndex
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   229
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   230
    def SetCurrentIndex(self, index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   231
        self.CurrentIndex = index
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   232
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   233
    def AppendRow(self, row_content):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   234
        self.data.append(row_content)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   235
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   236
    def Empty(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   237
        self.data = []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   238
        self.editors = []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   239
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   240
[ID_EDITINGPANEL, ID_EDITINGPANELADDBUTTON, ID_EDITINGPANELINDEXCHOICE, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   241
 ID_EDITINGPANELINDEXLIST, ID_EDITINGPANELINDEXLISTPANEL, ID_EDITINGPANELPARTLIST, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   242
 ID_EDITINGPANELSECONDSPLITTER, ID_EDITINGPANELSUBINDEXGRID,
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   243
 ID_EDITINGPANELSUBINDEXGRIDPANEL, ID_EDITINGPANELCALLBACKCHECK,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   244
] = [wx.NewId() for _init_ctrls in range(10)]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   245
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   246
[ID_EDITINGPANELINDEXLISTMENUITEMS0, ID_EDITINGPANELINDEXLISTMENUITEMS1, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   247
 ID_EDITINGPANELINDEXLISTMENUITEMS2, 
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   248
] = [wx.NewId() for _init_coll_IndexListMenu_Items in range(3)]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   249
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   250
[ID_EDITINGPANELMENU1ITEMS0, ID_EDITINGPANELMENU1ITEMS1, 
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   251
 ID_EDITINGPANELMENU1ITEMS3, ID_EDITINGPANELMENU1ITEMS4, 
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   252
] = [wx.NewId() for _init_coll_SubindexGridMenu_Items in range(4)]
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   253
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   254
class EditingPanel(wx.SplitterWindow):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   255
    def _init_coll_AddToListSizer_Items(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   256
        parent.AddWindow(self.AddButton, 0, border=0, flag=0)
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   257
        parent.AddWindow(self.IndexChoice, 0, border=0, flag=wx.GROW)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   258
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   259
    def _init_coll_SubindexGridSizer_Items(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   260
        parent.AddWindow(self.CallbackCheck, 0, border=0, flag=0)
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   261
        parent.AddWindow(self.SubindexGrid, 0, border=0, flag=wx.GROW)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   262
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   263
    def _init_coll_IndexListSizer_Items(self, parent):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   264
        parent.AddWindow(self.IndexList, 0, border=0, flag=wx.GROW)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   265
        parent.AddSizer(self.AddToListSizer, 0, border=0, flag=wx.GROW)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   266
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   267
    def _init_coll_AddToListSizer_Growables(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   268
        parent.AddGrowableCol(1)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   269
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   270
    def _init_coll_SubindexGridSizer_Growables(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   271
        parent.AddGrowableCol(0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   272
        parent.AddGrowableRow(1)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   273
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   274
    def _init_coll_IndexListSizer_Growables(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   275
        parent.AddGrowableCol(0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   276
        parent.AddGrowableRow(0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   277
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   278
    def _init_coll_SubindexGridMenu_Items(self, parent):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   279
        parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS0,
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   280
              kind=wx.ITEM_NORMAL, text='Add subindexes')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   281
        parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS1,
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   282
              kind=wx.ITEM_NORMAL, text='Delete subindexes')
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   283
        parent.AppendSeparator()
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   284
        parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS3,
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   285
              kind=wx.ITEM_NORMAL, text='Default value')
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   286
        if not self.Editable:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   287
            parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS4,
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   288
                  kind=wx.ITEM_NORMAL, text='Add to DCF')
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   289
        self.Bind(wx.EVT_MENU, self.OnAddSubindexMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   290
              id=ID_EDITINGPANELMENU1ITEMS0)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   291
        self.Bind(wx.EVT_MENU, self.OnDeleteSubindexMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   292
              id=ID_EDITINGPANELMENU1ITEMS1)
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   293
        self.Bind(wx.EVT_MENU, self.OnDefaultValueSubindexMenu,
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   294
              id=ID_EDITINGPANELMENU1ITEMS3)
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   295
        if not self.Editable:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   296
            self.Bind(wx.EVT_MENU, self.OnAddToDCFSubindexMenu,
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   297
                  id=ID_EDITINGPANELMENU1ITEMS4)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   298
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   299
    def _init_coll_IndexListMenu_Items(self, parent):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   300
        parent.Append(help='', id=ID_EDITINGPANELINDEXLISTMENUITEMS0,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   301
              kind=wx.ITEM_NORMAL, text='Rename')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   302
        parent.Append(help='', id=ID_EDITINGPANELINDEXLISTMENUITEMS2,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   303
              kind=wx.ITEM_NORMAL, text='Modify')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   304
        parent.Append(help='', id=ID_EDITINGPANELINDEXLISTMENUITEMS1,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   305
              kind=wx.ITEM_NORMAL, text='Delete')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   306
        self.Bind(wx.EVT_MENU, self.OnRenameIndexMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   307
              id=ID_EDITINGPANELINDEXLISTMENUITEMS0)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   308
        self.Bind(wx.EVT_MENU, self.OnDeleteIndexMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   309
              id=ID_EDITINGPANELINDEXLISTMENUITEMS1)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   310
        self.Bind(wx.EVT_MENU, self.OnModifyIndexMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   311
              id=ID_EDITINGPANELINDEXLISTMENUITEMS2)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   312
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   313
    def _init_utils(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   314
        self.IndexListMenu = wx.Menu(title='')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   315
        self.SubindexGridMenu = wx.Menu(title='')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   316
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   317
        self._init_coll_IndexListMenu_Items(self.IndexListMenu)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   318
        self._init_coll_SubindexGridMenu_Items(self.SubindexGridMenu)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   319
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   320
    def _init_sizers(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   321
        self.IndexListSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   322
        self.SubindexGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   323
        self.AddToListSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   324
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   325
        self._init_coll_IndexListSizer_Growables(self.IndexListSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   326
        self._init_coll_IndexListSizer_Items(self.IndexListSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   327
        self._init_coll_SubindexGridSizer_Growables(self.SubindexGridSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   328
        self._init_coll_SubindexGridSizer_Items(self.SubindexGridSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   329
        self._init_coll_AddToListSizer_Growables(self.AddToListSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   330
        self._init_coll_AddToListSizer_Items(self.AddToListSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   331
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   332
        self.SubindexGridPanel.SetSizer(self.SubindexGridSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   333
        self.IndexListPanel.SetSizer(self.IndexListSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   334
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   335
    def _init_ctrls(self, prnt):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   336
        wx.SplitterWindow.__init__(self, id=ID_EDITINGPANEL,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   337
              name='MainSplitter', parent=prnt, point=wx.Point(0, 0),
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   338
              size=wx.Size(-1, -1), style=wx.SP_3D)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   339
        self._init_utils()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   340
        self.SetNeedUpdating(True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   341
        self.SetMinimumPaneSize(1)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   342
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   343
        self.PartList = wx.ListBox(choices=[], id=ID_EDITINGPANELPARTLIST,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   344
              name='PartList', parent=self, pos=wx.Point(0, 0),
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   345
              size=wx.Size(-1, -1), style=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   346
        self.PartList.Bind(wx.EVT_LISTBOX, self.OnPartListBoxClick,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   347
              id=ID_EDITINGPANELPARTLIST)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   348
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   349
        self.SecondSplitter = wx.SplitterWindow(id=ID_EDITINGPANELSECONDSPLITTER,
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   350
              name='SecondSplitter', parent=self, point=wx.Point(0, 0), 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   351
              size=wx.Size(-1, -1), style=wx.SP_3D)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   352
        self.SecondSplitter.SetMinimumPaneSize(1)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   353
        self.SplitHorizontally(self.PartList, self.SecondSplitter,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   354
              110)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   355
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   356
        self.SubindexGridPanel = wx.Panel(id=ID_EDITINGPANELSUBINDEXGRIDPANEL,
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   357
              name='SubindexGridPanel', parent=self.SecondSplitter, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   358
              pos=wx.Point(0, 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   359
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   360
        self.IndexListPanel = wx.Panel(id=ID_EDITINGPANELINDEXLISTPANEL,
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   361
              name='IndexListPanel', parent=self.SecondSplitter, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   362
              pos=wx.Point(0, 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   363
        self.SecondSplitter.SplitVertically(self.IndexListPanel,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   364
              self.SubindexGridPanel, 280)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   365
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   366
        self.SubindexGrid = wx.grid.Grid(id=ID_EDITINGPANELSUBINDEXGRID,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   367
              name='SubindexGrid', parent=self.SubindexGridPanel, pos=wx.Point(0,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   368
              0), size=wx.Size(-1, -1), style=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   369
        self.SubindexGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   370
              'Sans'))
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   371
        self.SubindexGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   372
              False, 'Sans'))
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   373
        self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   374
              self.OnSubindexGridCellChange)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   375
        self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   376
              self.OnSubindexGridRightClick)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   377
        self.SubindexGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   378
              self.OnSubindexGridSelectCell)
324
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   379
        self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, 
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   380
              self.OnSubindexGridCellLeftClick)
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   381
        self.SubindexGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, 
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   382
              self.OnSubindexGridEditorShown)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   383
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   384
        self.CallbackCheck = wx.CheckBox(id=ID_EDITINGPANELCALLBACKCHECK,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   385
              label='Have Callbacks', name='CallbackCheck',
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   386
              parent=self.SubindexGridPanel, pos=wx.Point(0, 0), size=wx.Size(152,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   387
              24), style=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   388
        self.CallbackCheck.Bind(wx.EVT_CHECKBOX, self.OnCallbackCheck,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   389
              id=ID_EDITINGPANELCALLBACKCHECK)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   390
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   391
        self.IndexList = wx.ListBox(choices=[], id=ID_EDITINGPANELINDEXLIST,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   392
              name='IndexList', parent=self.IndexListPanel, pos=wx.Point(0, 0),
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   393
              size=wx.Size(-1, -1), style=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   394
        self.IndexList.Bind(wx.EVT_LISTBOX, self.OnIndexListClick,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   395
              id=ID_EDITINGPANELINDEXLIST)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   396
        self.IndexList.Bind(wx.EVT_RIGHT_UP, self.OnIndexListRightUp)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   397
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   398
        self.AddButton = wx.Button(id=ID_EDITINGPANELADDBUTTON, label='Add',
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   399
              name='AddButton', parent=self.IndexListPanel, pos=wx.Point(0, 0),
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   400
              size=wx.Size(50, 30), style=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   401
        self.AddButton.Bind(wx.EVT_BUTTON, self.OnAddButtonClick,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   402
              id=ID_EDITINGPANELADDBUTTON)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   403
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   404
        self.IndexChoice = wx.Choice(choices=[], id=ID_EDITINGPANELINDEXCHOICE,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   405
              name='IndexChoice', parent=self.IndexListPanel, pos=wx.Point(50,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   406
              0), size=wx.Size(-1, 30), style=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   407
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   408
        self._init_sizers()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   409
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   410
    def __init__(self, parent, window, manager, editable = True):
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   411
        self.Editable = editable
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   412
        self._init_ctrls(parent)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   413
        self.ParentWindow = window
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   414
        self.Manager = manager
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   415
        self.ListIndex = []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   416
        self.ChoiceIndex = []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   417
        self.FirstCall = False
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   418
        self.Index = None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   419
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   420
        for values in DictionaryOrganisation:
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   421
            text = "   0x%04X-0x%04X      %s"%(values["minIndex"], values["maxIndex"], values["name"])
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   422
            self.PartList.Append(text)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   423
        self.Table = SubindexTable(self, [], [], ["subindex", "name", "type", "value", "access", "save", "comment"])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   424
        self.SubindexGrid.SetTable(self.Table)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   425
        self.SubindexGrid.SetRowLabelSize(0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   426
        self.CallbackCheck.Disable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   427
        self.Table.ResetView(self.SubindexGrid)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   428
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   429
        if not self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   430
            self.AddButton.Disable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   431
            self.IndexChoice.Disable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   432
            self.CallbackCheck.Disable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   433
            self.Table.Disable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   434
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   435
    def GetIndex(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   436
        return self.Index
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   437
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   438
    def SetIndex(self, index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   439
        self.Index = index
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   440
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   441
    def GetSelection(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   442
        selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   443
        if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   444
            index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   445
            subIndex = self.SubindexGrid.GetGridCursorRow()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   446
            return index, subIndex
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   447
        return None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   448
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 237
diff changeset
   449
    def OnSubindexGridCellLeftClick(self, event):
324
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   450
        if not self.ParentWindow.ModeSolo:
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   451
            col = event.GetCol()
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   452
            if not self.Editable and col == 0:
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   453
                selected = self.IndexList.GetSelection()
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   454
                if selected != wx.NOT_FOUND:
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   455
                    index = self.ListIndex[selected]
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   456
                    subindex = event.GetRow()
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   457
                    entry_infos = self.Manager.GetEntryInfos(index)
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   458
                    if not entry_infos["struct"] & OD_MultipleSubindexes or subindex != 0:
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   459
                        subentry_infos = self.Manager.GetSubentryInfos(index, subindex)
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   460
                        typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"])
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   461
                        if subentry_infos["pdo"] and typeinfos:
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   462
                            bus_id = '.'.join(map(str, self.ParentWindow.GetBusId()))
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   463
                            node_id = self.ParentWindow.GetCurrentNodeId()
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   464
                            size = typeinfos["size"]
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   465
                            data = wx.TextDataObject(str(("%s%s.%d.%d.%d"%(SizeConversion[size], bus_id, node_id, index, subindex), "location")))
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   466
                            dragSource = wx.DropSource(self.SubindexGrid)
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   467
                            dragSource.SetData(data)
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   468
                            dragSource.DoDragDrop()
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 237
diff changeset
   469
        event.Skip()
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 237
diff changeset
   470
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   471
    def OnAddButtonClick(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   472
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   473
            self.SubindexGrid.SetGridCursor(0, 0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   474
            selected = self.IndexChoice.GetStringSelection()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   475
            if selected != "":
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   476
                if selected == "User Type":
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   477
                    self.ParentWindow.AddUserType()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   478
                elif selected == "SDO Server":
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   479
                    self.Manager.AddSDOServerToCurrent()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   480
                elif selected == "SDO Client":
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   481
                    self.Manager.AddSDOClientToCurrent()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   482
                elif selected == "PDO Receive":
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   483
                    self.Manager.AddPDOReceiveToCurrent()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   484
                elif selected == "PDO Transmit":
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   485
                    self.Manager.AddPDOTransmitToCurrent()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   486
                elif selected == "Map Variable":
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   487
                    self.ParentWindow.AddMapVariable()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   488
                elif selected in [menu for menu, indexes in self.Manager.GetCurrentSpecificMenu()]:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   489
                    self.Manager.AddSpecificEntryToCurrent(selected)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   490
                else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   491
                    index = self.ChoiceIndex[self.IndexChoice.GetSelection()]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   492
                    self.Manager.ManageEntriesOfCurrent([index], [])
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   493
                self.ParentWindow.RefreshBufferState()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   494
                self.RefreshIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   495
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   496
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   497
    def OnPartListBoxClick(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   498
        self.SubindexGrid.SetGridCursor(0, 0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   499
        self.RefreshIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   500
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   501
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   502
    def OnIndexListClick(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   503
        self.SubindexGrid.SetGridCursor(0, 0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   504
        self.RefreshTable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   505
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   506
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   507
    def OnSubindexGridSelectCell(self, event):
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   508
        wx.CallAfter(self.ParentWindow.RefreshStatusBar)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   509
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   510
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   511
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   512
#                             Refresh Functions
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   513
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   514
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   515
    def RefreshIndexList(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   516
        selected = self.IndexList.GetSelection()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   517
        choice = self.IndexChoice.GetStringSelection()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   518
        choiceindex = self.IndexChoice.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   519
        if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   520
            selectedindex = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   521
        self.IndexList.Clear()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   522
        self.IndexChoice.Clear()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   523
        i = self.PartList.GetSelection()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   524
        if i < len(DictionaryOrganisation):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   525
            values = DictionaryOrganisation[i]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   526
            self.ListIndex = []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   527
            for name, index in self.Manager.GetCurrentValidIndexes(values["minIndex"], values["maxIndex"]):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   528
                self.IndexList.Append("0x%04X   %s"%(index, name))
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   529
                self.ListIndex.append(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   530
            if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   531
                self.ChoiceIndex = []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   532
                if i == 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   533
                    self.IndexChoice.Append("User Type")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   534
                    self.IndexChoice.SetStringSelection("User Type")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   535
                elif i == 2:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   536
                    self.IndexChoice.Append("SDO Server")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   537
                    self.IndexChoice.Append("SDO Client")
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   538
                    if choiceindex != wx.NOT_FOUND and choice == self.IndexChoice.GetString(choiceindex):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   539
                         self.IndexChoice.SetStringSelection(choice)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   540
                elif i in (3, 4):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   541
                    self.IndexChoice.Append("PDO Receive")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   542
                    self.IndexChoice.SetStringSelection("PDO Receive")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   543
                elif i in (5, 6):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   544
                    self.IndexChoice.Append("PDO Transmit")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   545
                    self.IndexChoice.SetStringSelection("PDO Transmit")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   546
                elif i == 8:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   547
                    self.IndexChoice.Append("Map Variable")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   548
                    self.IndexChoice.SetStringSelection("Map Variable")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   549
                else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   550
                    for name, index in self.Manager.GetCurrentValidChoices(values["minIndex"], values["maxIndex"]):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   551
                        if index:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   552
                            self.IndexChoice.Append("0x%04X   %s"%(index, name))
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   553
                        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   554
                            self.IndexChoice.Append(name)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   555
                        self.ChoiceIndex.append(index)
312
70f96abd8ecd Bug on RefreshList in subindextable.py fixed
lbessard
parents: 310
diff changeset
   556
                if choiceindex != wx.NOT_FOUND and choiceindex < self.IndexChoice.GetCount() and choice == self.IndexChoice.GetString(choiceindex):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   557
                    self.IndexChoice.SetStringSelection(choice)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   558
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   559
            self.IndexChoice.Enable(self.IndexChoice.GetCount() != 0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   560
            self.AddButton.Enable(self.IndexChoice.GetCount() != 0)
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   561
        if selected == wx.NOT_FOUND or selected >= len(self.ListIndex) or selectedindex != self.ListIndex[selected]:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   562
            self.Table.Empty()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   563
            self.CallbackCheck.SetValue(False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   564
            self.CallbackCheck.Disable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   565
            self.Table.ResetView(self.SubindexGrid)
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   566
            self.ParentWindow.RefreshStatusBar()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   567
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   568
            self.IndexList.SetSelection(selected)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   569
            self.RefreshTable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   570
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   571
    def RefreshTable(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   572
        selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   573
        if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   574
            index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   575
            if index > 0x260 and self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   576
                self.CallbackCheck.Enable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   577
                self.CallbackCheck.SetValue(self.Manager.HasCurrentEntryCallbacks(index))
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   578
            result = self.Manager.GetCurrentEntryValues(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   579
            if result != None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   580
                self.Table.SetCurrentIndex(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   581
                data, editors = result
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   582
                self.Table.SetData(data)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   583
                self.Table.SetEditors(editors)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   584
                self.Table.ResetView(self.SubindexGrid)
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   585
        self.ParentWindow.RefreshStatusBar()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   586
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   587
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   588
#                        Editing Table value function
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   589
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   590
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   591
    def OnSubindexGridEditorShown(self, event):
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   592
        row, col = event.GetRow(), event.GetCol() 
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   593
        if self.Table.GetEditor(row, col) == "dcf":
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   594
            wx.CallAfter(self.ShowDCFEntryDialog, row, col)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   595
            event.Veto()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   596
        else:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   597
            event.Skip()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   598
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   599
    def ShowDCFEntryDialog(self, row, col):
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   600
        if self.Editable:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   601
            selected = self.IndexList.GetSelection()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   602
            if selected != wx.NOT_FOUND:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   603
                index = self.ListIndex[selected]
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   604
                if self.Manager.IsCurrentEntry(index):
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   605
                    dialog = DCFEntryValuesDialog(self)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   606
                    dialog.SetValues(self.Table.GetValue(row, col).decode("hex_codec"))
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   607
                    if dialog.ShowModal() == wx.ID_OK:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   608
                        value = dialog.GetValues()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   609
                        self.Manager.SetCurrentEntry(index, row, value, "value", "dcf")
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   610
                        self.ParentWindow.RefreshBufferState()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   611
                        wx.CallAfter(self.RefreshTable)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   612
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   613
    def OnSubindexGridCellChange(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   614
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   615
            index = self.Table.GetCurrentIndex()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   616
            subIndex = event.GetRow()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   617
            col = event.GetCol()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   618
            name = self.Table.GetColLabelValue(col)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   619
            value = self.Table.GetValue(subIndex, col)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   620
            editor = self.Table.GetEditor(subIndex, col)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   621
            self.Manager.SetCurrentEntry(index, subIndex, value, name, editor)
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   622
            self.ParentWindow.RefreshBufferState()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   623
            wx.CallAfter(self.RefreshTable)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   624
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   625
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   626
    def OnCallbackCheck(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   627
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   628
            index = self.Table.GetCurrentIndex()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   629
            self.Manager.SetCurrentEntryCallbacks(index, self.CallbackCheck.GetValue())
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   630
            self.ParentWindow.RefreshBufferState()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   631
            wx.CallAfter(self.RefreshTable)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   632
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   633
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   634
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   635
#                          Contextual Menu functions
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   636
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   637
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   638
    def OnIndexListRightUp(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   639
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   640
            if not self.FirstCall:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   641
                self.FirstCall = True
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   642
                selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   643
                if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   644
                    index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   645
                    if index < 0x260:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   646
                        self.IndexListMenu.FindItemByPosition(0).Enable(False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   647
                        self.IndexListMenu.FindItemByPosition(1).Enable(True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   648
                        self.PopupMenu(self.IndexListMenu)
273
58b39f97e352 Some bugs fixed
lbessard
parents: 271
diff changeset
   649
                    elif 0x1000 <= index <= 0x1FFF:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   650
                        self.IndexListMenu.FindItemByPosition(0).Enable(False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   651
                        self.IndexListMenu.FindItemByPosition(1).Enable(False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   652
                        self.PopupMenu(self.IndexListMenu)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   653
                    elif 0x2000 <= index <= 0x5FFF:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   654
                        self.IndexListMenu.FindItemByPosition(0).Enable(True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   655
                        self.IndexListMenu.FindItemByPosition(1).Enable(False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   656
                        self.PopupMenu(self.IndexListMenu)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   657
                    elif index >= 0x6000:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   658
                        self.IndexListMenu.FindItemByPosition(0).Enable(False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   659
                        self.IndexListMenu.FindItemByPosition(1).Enable(False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   660
                        self.PopupMenu(self.IndexListMenu)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   661
            else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   662
                self.FirstCall = False
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   663
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   664
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   665
    def OnSubindexGridRightClick(self, event):
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   666
        self.SubindexGrid.SetGridCursor(event.GetRow(), event.GetCol())
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   667
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   668
            selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   669
            if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   670
                index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   671
                if self.Manager.IsCurrentEntry(index):
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   672
                    showpopup = False
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   673
                    infos = self.Manager.GetEntryInfos(index)
310
1975e546178b Bugs on EDS import fixed
lbessard
parents: 299
diff changeset
   674
                    if 0x2000 <= index <= 0x5FFF and infos["struct"] & OD_MultipleSubindexes or infos["struct"] & OD_IdenticalSubindexes:
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   675
                        showpopup = True
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   676
                        self.SubindexGridMenu.FindItemByPosition(0).Enable(True)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   677
                        self.SubindexGridMenu.FindItemByPosition(1).Enable(True)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   678
                    else:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   679
                        self.SubindexGridMenu.FindItemByPosition(0).Enable(False)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   680
                        self.SubindexGridMenu.FindItemByPosition(1).Enable(False)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   681
                    if self.Table.GetColLabelValue(event.GetCol()) == "value":
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   682
                        showpopup = True
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   683
                        self.SubindexGridMenu.FindItemByPosition(3).Enable(True)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   684
                    else:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   685
                        self.SubindexGridMenu.FindItemByPosition(3).Enable(False)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   686
                    if showpopup:
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 237
diff changeset
   687
                        self.PopupMenu(self.SubindexGridMenu)
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   688
        elif self.Table.GetColLabelValue(event.GetCol()) == "value":
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   689
            selected = self.IndexList.GetSelection()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   690
            if selected != wx.NOT_FOUND:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   691
                index = self.ListIndex[selected]
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   692
                if self.Manager.IsCurrentEntry(index):
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   693
                    infos = self.Manager.GetEntryInfos(index)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   694
                    if not infos["struct"] & OD_MultipleSubindexes or event.GetRow() > 0:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   695
                        self.SubindexGridMenu.FindItemByPosition(0).Enable(False)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   696
                        self.SubindexGridMenu.FindItemByPosition(1).Enable(False)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   697
                        self.SubindexGridMenu.FindItemByPosition(3).Enable(False)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   698
                        self.SubindexGridMenu.FindItemByPosition(4).Enable(True)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   699
                        self.PopupMenu(self.SubindexGridMenu)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   700
        event.Skip()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   701
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   702
    def OnAddToDCFSubindexMenu(self, event):
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   703
        if not self.Editable:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   704
            selected = self.IndexList.GetSelection()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   705
            if selected != wx.NOT_FOUND:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   706
                index = self.ListIndex[selected]
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   707
                subindex = self.SubindexGrid.GetGridCursorRow()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   708
                entry_infos = self.Manager.GetEntryInfos(index)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   709
                if not entry_infos["struct"] & OD_MultipleSubindexes or subindex != 0:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   710
                    subentry_infos = self.Manager.GetSubentryInfos(index, subindex)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   711
                    typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"])
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   712
                    if typeinfos:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   713
                        node_id = self.ParentWindow.GetCurrentNodeId()
336
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   714
                        value = self.Table.GetValueByName(subindex, "value")
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   715
                        if value == "True":
340
60e1eb89455e Bug on new DCF entry boolean value fixed
lbessard
parents: 336
diff changeset
   716
                            value = 1
60e1eb89455e Bug on new DCF entry boolean value fixed
lbessard
parents: 336
diff changeset
   717
                        elif value == "False":
336
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   718
                            value = 0
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   719
                        elif value.isdigit():
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   720
                            value = int(value)
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   721
                        elif value.startswith("0x"):
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   722
                            value = int(value, 16)
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   723
                        else:
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   724
                            value = int(value.encode("hex_codec"), 16)
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   725
                        self.Manager.AddToMasterDCF(node_id, index, subindex, max(1, typeinfos["size"] / 8), value)    
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   726
                        self.ParentWindow.OpenMasterDCFDialog(node_id)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   727
336
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   728
    def OpenDCFDialog(self, node_id):
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   729
        self.PartList.SetSelection(7)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   730
        self.RefreshIndexList()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   731
        self.IndexList.SetSelection(self.ListIndex.index(0x1F22))
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   732
        self.RefreshTable()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   733
        self.SubindexGrid.SetGridCursor(node_id, 3)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   734
        self.ShowDCFEntryDialog(node_id, 3)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   735
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   736
    def OnRenameIndexMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   737
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   738
            selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   739
            if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   740
                index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   741
                if self.Manager.IsCurrentEntry(index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   742
                    infos = self.Manager.GetEntryInfos(index)
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   743
                    dialog = wx.TextEntryDialog(self, "Give a new name for index 0x%04X"%index,
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   744
                                 "Rename an index", infos["name"], wx.OK|wx.CANCEL)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   745
                    if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   746
                        self.Manager.SetCurrentEntryName(index, dialog.GetValue())
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   747
                        self.ParentWindow.RefreshBufferState()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   748
                        self.RefreshIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   749
                    dialog.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   750
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   751
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   752
    def OnModifyIndexMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   753
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   754
            selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   755
            if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   756
                index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   757
                if self.Manager.IsCurrentEntry(index) and index < 0x260:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   758
                    values, valuetype = self.Manager.GetCustomisedTypeValues(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   759
                    dialog = UserTypeDialog(self)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   760
                    dialog.SetTypeList(self.Manager.GetCustomisableTypes(), values[1])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   761
                    if valuetype == 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   762
                        dialog.SetValues(min = values[2], max = values[3])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   763
                    elif valuetype == 1:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   764
                        dialog.SetValues(length = values[2])
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   765
                    if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   766
                        type, min, max, length = dialog.GetValues()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   767
                        self.Manager.SetCurrentUserType(index, type, min, max, length)
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   768
                        self.ParentWindow.RefreshBufferState()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   769
                        self.RefreshIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   770
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   771
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   772
    def OnDeleteIndexMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   773
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   774
            selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   775
            if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   776
                index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   777
                if self.Manager.IsCurrentEntry(index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   778
                    self.Manager.ManageEntriesOfCurrent([],[index])
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   779
                    self.ParentWindow.RefreshBufferState()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   780
                    self.RefreshIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   781
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   782
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   783
    def OnAddSubindexMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   784
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   785
            selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   786
            if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   787
                index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   788
                if self.Manager.IsCurrentEntry(index):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   789
                    dialog = wx.TextEntryDialog(self, "Number of subindexes to add:",
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   790
                                 "Add subindexes", "1", wx.OK|wx.CANCEL)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   791
                    if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   792
                        try:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   793
                            number = int(dialog.GetValue())
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   794
                            self.Manager.AddSubentriesToCurrent(index, number)
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   795
                            self.ParentWindow.RefreshBufferState()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   796
                            self.RefreshIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   797
                        except:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   798
                            message = wx.MessageDialog(self, "An integer is required!", "ERROR", wx.OK|wx.ICON_ERROR)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   799
                            message.ShowModal()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   800
                            message.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   801
                    dialog.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   802
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   803
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   804
    def OnDeleteSubindexMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   805
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   806
            selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   807
            if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   808
                index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   809
                if self.Manager.IsCurrentEntry(index):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   810
                    dialog = wx.TextEntryDialog(self, "Number of subindexes to delete:",
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   811
                                 "Delete subindexes", "1", wx.OK|wx.CANCEL)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   812
                    if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   813
                        try:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   814
                            number = int(dialog.GetValue())
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   815
                            self.Manager.RemoveSubentriesFromCurrent(index, number)
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   816
                            self.ParentWindow.RefreshBufferState()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   817
                            self.RefreshIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   818
                        except:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   819
                            message = wx.MessageDialog(self, "An integer is required!", "ERROR", wx.OK|wx.ICON_ERROR)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   820
                            message.ShowModal()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   821
                            message.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   822
                    dialog.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   823
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   824
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   825
    def OnDefaultValueSubindexMenu(self, event):
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   826
        if self.Editable:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   827
            selected = self.IndexList.GetSelection()
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   828
            if selected != wx.NOT_FOUND:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   829
                index = self.ListIndex[selected]
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   830
                if self.Manager.IsCurrentEntry(index):
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   831
                    row = self.SubindexGrid.GetGridCursorRow()
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   832
                    self.Manager.SetCurrentEntryToDefault(index, row)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   833
                    self.ParentWindow.RefreshBufferState()
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   834
                    self.RefreshIndexList()
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   835
        event.Skip()