objdictgen/subindextable.py
author mwildbolz
Mon, 01 Oct 2012 17:19:00 +0200
changeset 753 072787c24bec
parent 747 4725d8f909ff
child 748 18ed0f3b030a
permissions -rw-r--r--
Doxyfile adapted to show all basic source files, search engine included
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]
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    34
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    35
def GetAccessList(write=True):
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    36
    _ = lambda x : x
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    37
    if write:
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    38
        return [_("Read Only"), _("Write Only"), _("Read/Write")]
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    39
    return [_("Read Only"), _("Read/Write")]
584
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 580
diff changeset
    40
AccessList = ",".join(map(_, GetAccessList()))
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 580
diff changeset
    41
RAccessList = ",".join(map(_, GetAccessList(False)))
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    42
ACCESS_LIST_DICT = dict([(_(access), access) for access in GetAccessList()])
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    43
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    44
def GetBoolList():
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    45
    _ = lambda x : x
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    46
    return [_("True"), _("False")]
584
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 580
diff changeset
    47
BoolList = ",".join(map(_, GetBoolList()))
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    48
BOOL_LIST_DICT = dict([(_(bool), bool) for bool in GetBoolList()])
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    49
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    50
def GetOptionList():
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    51
    _ = lambda x : x
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    52
    return [_("Yes"), _("No")]
584
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 580
diff changeset
    53
OptionList = ",".join(map(_, GetOptionList()))
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    54
OPTION_LIST_DICT = dict([(_(option), option) for option in GetOptionList()])
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    55
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    56
[USER_TYPE, SDO_SERVER, SDO_CLIENT, 
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    57
 PDO_TRANSMIT, PDO_RECEIVE, MAP_VARIABLE] = range(6)
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    58
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    59
INDEXCHOICE_OPTIONS = {
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    60
    USER_TYPE: (_("User Type"), 0, "AddUserType"), 
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    61
    SDO_SERVER: (_("SDO Server"), 1, "AddSDOServerToCurrent"),
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    62
    SDO_CLIENT: (_("SDO Client"), 1, "AddSDOClientToCurrent"),
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    63
    PDO_RECEIVE: (_("PDO Receive"), 1, "AddPDOReceiveToCurrent"),
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    64
    PDO_TRANSMIT: (_("PDO Transmit"), 1, "AddPDOTransmitToCurrent"),
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    65
    MAP_VARIABLE: (_("Map Variable"), 0, "AddMapVariable")
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    66
}
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    67
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    68
INDEXCHOICE_OPTIONS_DICT = dict([(translation, option) for option, (translation, object, function) in INDEXCHOICE_OPTIONS.iteritems()])
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    69
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    70
INDEXCHOICE_SECTIONS = {
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    71
    0 : [USER_TYPE],
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    72
    2 : [SDO_SERVER, SDO_CLIENT],
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    73
    3 : [PDO_RECEIVE],
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    74
    4 : [PDO_RECEIVE],
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    75
    5 : [PDO_TRANSMIT],
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    76
    6 : [PDO_TRANSMIT],
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    77
    8 : [MAP_VARIABLE],
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    78
}
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    79
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    80
def GetSubindexTableColnames():
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    81
    _ = lambda x : x
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
    82
    return [_("subindex"), _("name"), _("type"), _("value"), _("access"), _("save"), _("comment")]
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    83
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    84
DictionaryOrganisation = [
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    85
    {"minIndex" : 0x0001, "maxIndex" : 0x0FFF, "name" : "Data Type Definitions"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    86
    {"minIndex" : 0x1000, "maxIndex" : 0x1029, "name" : "Communication Parameters"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    87
    {"minIndex" : 0x1200, "maxIndex" : 0x12FF, "name" : "SDO Parameters"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    88
    {"minIndex" : 0x1400, "maxIndex" : 0x15FF, "name" : "Receive PDO Parameters"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    89
    {"minIndex" : 0x1600, "maxIndex" : 0x17FF, "name" : "Receive PDO Mapping"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    90
    {"minIndex" : 0x1800, "maxIndex" : 0x19FF, "name" : "Transmit PDO Parameters"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    91
    {"minIndex" : 0x1A00, "maxIndex" : 0x1BFF, "name" : "Transmit PDO Mapping"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    92
    {"minIndex" : 0x1C00, "maxIndex" : 0x1FFF, "name" : "Other Communication Parameters"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    93
    {"minIndex" : 0x2000, "maxIndex" : 0x5FFF, "name" : "Manufacturer Specific"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    94
    {"minIndex" : 0x6000, "maxIndex" : 0x9FFF, "name" : "Standardized Device Profile"},
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    95
    {"minIndex" : 0xA000, "maxIndex" : 0xBFFF, "name" : "Standardized Interface Profile"}]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    96
747
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
    97
IECTypeConversion = {
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
    98
    "BOOLEAN": "BOOL",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
    99
    "INTEGER8": "SINT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   100
    "INTEGER16": "INT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   101
    "INTEGER32": "DINT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   102
    "UNSIGNED8": "USINT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   103
    "UNSIGNED16": "UINT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   104
    "UNSIGNED32": "UDINT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   105
    "REAL32": "REAL",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   106
    "VISIBLE_STRING": "STRING",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   107
    "OCTET_STRING": "STRING",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   108
    "UNICODE_STRING": "WSTRING",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   109
    "DOMAIN": "STRING",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   110
    "INTEGER24": "DINT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   111
    "REAL64": "LREAL",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   112
    "INTEGER40": "LINT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   113
    "INTEGER48": "LINT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   114
    "INTEGER56": "LINT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   115
    "INTEGER64": "LINT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   116
    "UNSIGNED24": "UDINT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   117
    "UNSIGNED40": "ULINT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   118
    "UNSIGNED48": "ULINT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   119
    "UNSIGNED56": "ULINT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   120
    "UNSIGNED64": "ULINT",
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   121
}
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 237
diff changeset
   122
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
   123
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   124
class SubindexTable(wx.grid.PyGridTableBase):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   125
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   126
    """
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   127
    A custom wxGrid Table using user supplied data
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   128
    """
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   129
    def __init__(self, parent, data, editors, colnames):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   130
        # The base class must be initialized *first*
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   131
        wx.grid.PyGridTableBase.__init__(self)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   132
        self.data = data
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   133
        self.editors = editors
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   134
        self.CurrentIndex = 0
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   135
        self.colnames = colnames
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   136
        self.Parent = parent
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   137
        self.Editable = True
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   138
        # XXX
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   139
        # we need to store the row length and collength to
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   140
        # see if the table has changed size
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   141
        self._rows = self.GetNumberRows()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   142
        self._cols = self.GetNumberCols()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   143
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   144
    def Disable(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   145
        self.Editable = False
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   146
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   147
    def Enable(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   148
        self.Editable = True
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   149
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   150
    def GetNumberCols(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   151
        return len(self.colnames)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   152
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   153
    def GetNumberRows(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   154
        return len(self.data)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   155
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   156
    def GetColLabelValue(self, col, translate=True):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   157
        if col < len(self.colnames):
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   158
            if translate:
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   159
                return _(self.colnames[col])
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   160
            return self.colnames[col]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   161
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   162
    def GetRowLabelValues(self, row, translate=True):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   163
        return row
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   164
584
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 580
diff changeset
   165
    def GetValue(self, row, col, translate=True):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   166
        if row < self.GetNumberRows():
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   167
            colname = self.GetColLabelValue(col, False)
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   168
            value = unicode(self.data[row].get(colname, ""))
584
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 580
diff changeset
   169
            if translate and (colname == "access" or 
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 580
diff changeset
   170
                              self.editors[row][colname] in ["bool", "option"] or
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 580
diff changeset
   171
                              self.editors[row][colname] == "map" and value == "None"):
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   172
                value = _(value)
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   173
            return value
266
8678a3cf7fe7 Code corrections
lbessard
parents: 254
diff changeset
   174
            
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   175
    def GetEditor(self, row, col):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   176
        if row < self.GetNumberRows():
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   177
            return self.editors[row].get(self.GetColLabelValue(col, False), "")
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   178
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   179
    def GetValueByName(self, row, colname):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   180
        return self.data[row].get(colname)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   181
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   182
    def SetValue(self, row, col, value):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   183
        if col < len(self.colnames):
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   184
            colname = self.GetColLabelValue(col, False)
584
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 580
diff changeset
   185
            if colname == "access":
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   186
                value = ACCESS_LIST_DICT[value]
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   187
            elif self.editors[row][colname] == "bool":
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   188
                value = BOOL_LIST_DICT[value]
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   189
            elif self.editors[row][colname] == "option":
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   190
                value = OPTION_LIST_DICT[value]
584
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 580
diff changeset
   191
            elif self.editors[row][colname] == "map" and value == _("None"):
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 580
diff changeset
   192
                value = "None"
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   193
            self.data[row][colname] = value
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   194
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   195
    def ResetView(self, grid):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   196
        """
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   197
        (wx.grid.Grid) -> Reset the grid view.   Call this to
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   198
        update the grid if rows and columns have been added or deleted
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   199
        """
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   200
        grid.BeginBatch()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   201
        for current, new, delmsg, addmsg in [
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   202
            (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
   203
            (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
   204
        ]:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   205
            if new < current:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   206
                msg = wx.grid.GridTableMessage(self,delmsg,new,current-new)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   207
                grid.ProcessTableMessage(msg)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   208
            elif new > current:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   209
                msg = wx.grid.GridTableMessage(self,addmsg,new-current)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   210
                grid.ProcessTableMessage(msg)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   211
                self.UpdateValues(grid)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   212
        grid.EndBatch()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   213
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   214
        self._rows = self.GetNumberRows()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   215
        self._cols = self.GetNumberCols()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   216
        # update the column rendering scheme
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   217
        self._updateColAttrs(grid)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   218
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   219
        # update the scrollbars and the displayed part of the grid
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   220
        grid.AdjustScrollbars()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   221
        grid.ForceRefresh()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   222
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   223
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   224
    def UpdateValues(self, grid):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   225
        """Update all displayed values"""
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   226
        # 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
   227
        msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   228
        grid.ProcessTableMessage(msg)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   229
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   230
    def _updateColAttrs(self, grid):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   231
        """
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   232
        wx.grid.Grid -> update the column attributes to add the
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   233
        appropriate renderer given the column name.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   234
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   235
        Otherwise default to the default renderer.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   236
        """
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   237
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   238
        for col in range(self.GetNumberCols()):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   239
            attr = wx.grid.GridCellAttr()
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   240
            attr.SetAlignment(ColAlignements[col], wx.ALIGN_CENTRE)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   241
            grid.SetColAttr(col, attr)
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   242
            grid.SetColMinimalWidth(col, ColSizes[col])
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   243
            grid.AutoSizeColumn(col, False)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   244
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   245
        typelist = None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   246
        maplist = None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   247
        for row in range(self.GetNumberRows()):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   248
            editors = self.editors[row]
585
d62424ba12bf Replacing wx.Choice controls by wx.ComboBox controls
laurent
parents: 584
diff changeset
   249
            grid.SetRowMinimalHeight(row, 28)
d62424ba12bf Replacing wx.Choice controls by wx.ComboBox controls
laurent
parents: 584
diff changeset
   250
            grid.AutoSizeRow(row, False)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   251
            for col in range(self.GetNumberCols()):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   252
                editor = None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   253
                renderer = None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   254
                
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   255
                colname = self.GetColLabelValue(col, False)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   256
                editortype = editors[colname]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   257
                if editortype and self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   258
                    grid.SetReadOnly(row, col, False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   259
                    if editortype == "string":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   260
                        editor = wx.grid.GridCellTextEditor()
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   261
                        renderer = wx.grid.GridCellStringRenderer()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   262
                        if colname == "value" and "length" in editors:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   263
                            editor.SetParameters(editors["length"]) 
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   264
                    elif editortype == "number":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   265
                        editor = wx.grid.GridCellNumberEditor()
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   266
                        renderer = wx.grid.GridCellNumberRenderer()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   267
                        if colname == "value" and "min" in editors and "max" in editors:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   268
                            editor.SetParameters("%s,%s"%(editors["min"],editors["max"]))
453
c74a73474cce Problem with Real types unsupported fixed
lbessard
parents: 340
diff changeset
   269
                    elif editortype == "float":
c74a73474cce Problem with Real types unsupported fixed
lbessard
parents: 340
diff changeset
   270
                        editor = wx.grid.GridCellTextEditor()
c74a73474cce Problem with Real types unsupported fixed
lbessard
parents: 340
diff changeset
   271
                        renderer = wx.grid.GridCellStringRenderer()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   272
                    elif editortype == "bool":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   273
                        editor = wx.grid.GridCellChoiceEditor()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   274
                        editor.SetParameters(BoolList)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   275
                    elif editortype == "access":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   276
                        editor = wx.grid.GridCellChoiceEditor()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   277
                        editor.SetParameters(AccessList)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   278
                    elif editortype == "raccess":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   279
                        editor = wx.grid.GridCellChoiceEditor()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   280
                        editor.SetParameters(RAccessList)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   281
                    elif editortype == "option":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   282
                        editor = wx.grid.GridCellChoiceEditor()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   283
                        editor.SetParameters(OptionList)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   284
                    elif editortype == "type":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   285
                        editor = wx.grid.GridCellChoiceEditor()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   286
                        if typelist == None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   287
                            typelist = self.Parent.Manager.GetCurrentTypeList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   288
                        editor.SetParameters(typelist)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   289
                    elif editortype == "map":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   290
                        editor = wx.grid.GridCellChoiceEditor()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   291
                        if maplist == None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   292
                            maplist = self.Parent.Manager.GetCurrentMapList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   293
                        editor.SetParameters(maplist)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   294
                    elif editortype == "time":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   295
                        editor = wx.grid.GridCellTextEditor()
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   296
                        renderer = wx.grid.GridCellStringRenderer()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   297
                    elif editortype == "domain":
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   298
                        editor = wx.grid.GridCellTextEditor()
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   299
                        renderer = wx.grid.GridCellStringRenderer()
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   300
                    elif editortype == "dcf":
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   301
                        editor = wx.grid.GridCellTextEditor()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   302
                        renderer = wx.grid.GridCellStringRenderer()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   303
                else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   304
                    grid.SetReadOnly(row, col, True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   305
                    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   306
                grid.SetCellEditor(row, col, editor)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   307
                grid.SetCellRenderer(row, col, renderer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   308
                
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   309
                grid.SetCellBackgroundColour(row, col, wx.WHITE)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   310
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   311
    def SetData(self, data):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   312
        self.data = data
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   313
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   314
    def SetEditors(self, editors):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   315
        self.editors = editors
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   316
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   317
    def GetCurrentIndex(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   318
        return self.CurrentIndex
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   319
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   320
    def SetCurrentIndex(self, index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   321
        self.CurrentIndex = index
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   322
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   323
    def AppendRow(self, row_content):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   324
        self.data.append(row_content)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   325
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   326
    def Empty(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   327
        self.data = []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   328
        self.editors = []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   329
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   330
[ID_EDITINGPANEL, ID_EDITINGPANELADDBUTTON, ID_EDITINGPANELINDEXCHOICE, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   331
 ID_EDITINGPANELINDEXLIST, ID_EDITINGPANELINDEXLISTPANEL, ID_EDITINGPANELPARTLIST, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   332
 ID_EDITINGPANELSECONDSPLITTER, ID_EDITINGPANELSUBINDEXGRID,
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   333
 ID_EDITINGPANELSUBINDEXGRIDPANEL, ID_EDITINGPANELCALLBACKCHECK,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   334
] = [wx.NewId() for _init_ctrls in range(10)]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   335
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   336
[ID_EDITINGPANELINDEXLISTMENUITEMS0, ID_EDITINGPANELINDEXLISTMENUITEMS1, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   337
 ID_EDITINGPANELINDEXLISTMENUITEMS2, 
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   338
] = [wx.NewId() for _init_coll_IndexListMenu_Items in range(3)]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   339
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   340
[ID_EDITINGPANELMENU1ITEMS0, ID_EDITINGPANELMENU1ITEMS1, 
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   341
 ID_EDITINGPANELMENU1ITEMS3, ID_EDITINGPANELMENU1ITEMS4, 
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   342
] = [wx.NewId() for _init_coll_SubindexGridMenu_Items in range(4)]
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   343
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   344
class EditingPanel(wx.SplitterWindow):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   345
    def _init_coll_AddToListSizer_Items(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   346
        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
   347
        parent.AddWindow(self.IndexChoice, 0, border=0, flag=wx.GROW)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   348
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   349
    def _init_coll_SubindexGridSizer_Items(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   350
        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
   351
        parent.AddWindow(self.SubindexGrid, 0, border=0, flag=wx.GROW)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   352
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   353
    def _init_coll_IndexListSizer_Items(self, parent):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   354
        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
   355
        parent.AddSizer(self.AddToListSizer, 0, border=0, flag=wx.GROW)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   356
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   357
    def _init_coll_AddToListSizer_Growables(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   358
        parent.AddGrowableCol(1)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   359
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   360
    def _init_coll_SubindexGridSizer_Growables(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   361
        parent.AddGrowableCol(0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   362
        parent.AddGrowableRow(1)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   363
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   364
    def _init_coll_IndexListSizer_Growables(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   365
        parent.AddGrowableCol(0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   366
        parent.AddGrowableRow(0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   367
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   368
    def _init_coll_SubindexGridMenu_Items(self, parent):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   369
        parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS0,
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   370
              kind=wx.ITEM_NORMAL, text=_('Add subindexes'))
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   371
        parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS1,
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   372
              kind=wx.ITEM_NORMAL, text=_('Delete subindexes'))
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   373
        parent.AppendSeparator()
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   374
        parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS3,
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   375
              kind=wx.ITEM_NORMAL, text=_('Default value'))
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   376
        if not self.Editable:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   377
            parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS4,
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   378
                  kind=wx.ITEM_NORMAL, text=_('Add to DCF'))
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   379
        self.Bind(wx.EVT_MENU, self.OnAddSubindexMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   380
              id=ID_EDITINGPANELMENU1ITEMS0)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   381
        self.Bind(wx.EVT_MENU, self.OnDeleteSubindexMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   382
              id=ID_EDITINGPANELMENU1ITEMS1)
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   383
        self.Bind(wx.EVT_MENU, self.OnDefaultValueSubindexMenu,
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   384
              id=ID_EDITINGPANELMENU1ITEMS3)
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   385
        if not self.Editable:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   386
            self.Bind(wx.EVT_MENU, self.OnAddToDCFSubindexMenu,
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   387
                  id=ID_EDITINGPANELMENU1ITEMS4)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   388
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   389
    def _init_coll_IndexListMenu_Items(self, parent):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   390
        parent.Append(help='', id=ID_EDITINGPANELINDEXLISTMENUITEMS0,
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   391
              kind=wx.ITEM_NORMAL, text=_('Rename'))
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   392
        parent.Append(help='', id=ID_EDITINGPANELINDEXLISTMENUITEMS2,
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   393
              kind=wx.ITEM_NORMAL, text=_('Modify'))
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   394
        parent.Append(help='', id=ID_EDITINGPANELINDEXLISTMENUITEMS1,
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   395
              kind=wx.ITEM_NORMAL, text=_('Delete'))
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   396
        self.Bind(wx.EVT_MENU, self.OnRenameIndexMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   397
              id=ID_EDITINGPANELINDEXLISTMENUITEMS0)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   398
        self.Bind(wx.EVT_MENU, self.OnDeleteIndexMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   399
              id=ID_EDITINGPANELINDEXLISTMENUITEMS1)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   400
        self.Bind(wx.EVT_MENU, self.OnModifyIndexMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   401
              id=ID_EDITINGPANELINDEXLISTMENUITEMS2)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   402
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   403
    def _init_utils(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   404
        self.IndexListMenu = wx.Menu(title='')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   405
        self.SubindexGridMenu = wx.Menu(title='')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   406
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   407
        self._init_coll_IndexListMenu_Items(self.IndexListMenu)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   408
        self._init_coll_SubindexGridMenu_Items(self.SubindexGridMenu)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   409
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   410
    def _init_sizers(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   411
        self.IndexListSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   412
        self.SubindexGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   413
        self.AddToListSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   414
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   415
        self._init_coll_IndexListSizer_Growables(self.IndexListSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   416
        self._init_coll_IndexListSizer_Items(self.IndexListSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   417
        self._init_coll_SubindexGridSizer_Growables(self.SubindexGridSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   418
        self._init_coll_SubindexGridSizer_Items(self.SubindexGridSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   419
        self._init_coll_AddToListSizer_Growables(self.AddToListSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   420
        self._init_coll_AddToListSizer_Items(self.AddToListSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   421
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   422
        self.SubindexGridPanel.SetSizer(self.SubindexGridSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   423
        self.IndexListPanel.SetSizer(self.IndexListSizer)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   424
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   425
    def _init_ctrls(self, prnt):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   426
        wx.SplitterWindow.__init__(self, id=ID_EDITINGPANEL,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   427
              name='MainSplitter', parent=prnt, point=wx.Point(0, 0),
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   428
              size=wx.Size(-1, -1), style=wx.SP_3D)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   429
        self._init_utils()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   430
        self.SetNeedUpdating(True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   431
        self.SetMinimumPaneSize(1)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   432
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   433
        self.PartList = wx.ListBox(choices=[], id=ID_EDITINGPANELPARTLIST,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   434
              name='PartList', parent=self, pos=wx.Point(0, 0),
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   435
              size=wx.Size(-1, -1), style=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   436
        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
   437
              id=ID_EDITINGPANELPARTLIST)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   438
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   439
        self.SecondSplitter = wx.SplitterWindow(id=ID_EDITINGPANELSECONDSPLITTER,
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   440
              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
   441
              size=wx.Size(-1, -1), style=wx.SP_3D)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   442
        self.SecondSplitter.SetMinimumPaneSize(1)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   443
        self.SplitHorizontally(self.PartList, self.SecondSplitter,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   444
              110)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   445
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   446
        self.SubindexGridPanel = wx.Panel(id=ID_EDITINGPANELSUBINDEXGRIDPANEL,
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   447
              name='SubindexGridPanel', parent=self.SecondSplitter, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   448
              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
   449
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   450
        self.IndexListPanel = wx.Panel(id=ID_EDITINGPANELINDEXLISTPANEL,
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   451
              name='IndexListPanel', parent=self.SecondSplitter, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   452
              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
   453
        self.SecondSplitter.SplitVertically(self.IndexListPanel,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   454
              self.SubindexGridPanel, 280)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   455
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   456
        self.SubindexGrid = wx.grid.Grid(id=ID_EDITINGPANELSUBINDEXGRID,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   457
              name='SubindexGrid', parent=self.SubindexGridPanel, pos=wx.Point(0,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   458
              0), size=wx.Size(-1, -1), style=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   459
        self.SubindexGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   460
              'Sans'))
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   461
        self.SubindexGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   462
              False, 'Sans'))
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   463
        self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   464
              self.OnSubindexGridCellChange)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   465
        self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   466
              self.OnSubindexGridRightClick)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   467
        self.SubindexGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   468
              self.OnSubindexGridSelectCell)
324
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   469
        self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, 
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   470
              self.OnSubindexGridCellLeftClick)
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   471
        self.SubindexGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, 
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   472
              self.OnSubindexGridEditorShown)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   473
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   474
        self.CallbackCheck = wx.CheckBox(id=ID_EDITINGPANELCALLBACKCHECK,
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   475
              label=_('Have Callbacks'), name='CallbackCheck',
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   476
              parent=self.SubindexGridPanel, pos=wx.Point(0, 0), size=wx.Size(152,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   477
              24), style=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   478
        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
   479
              id=ID_EDITINGPANELCALLBACKCHECK)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   480
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   481
        self.IndexList = wx.ListBox(choices=[], id=ID_EDITINGPANELINDEXLIST,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   482
              name='IndexList', parent=self.IndexListPanel, pos=wx.Point(0, 0),
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   483
              size=wx.Size(-1, -1), style=0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   484
        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
   485
              id=ID_EDITINGPANELINDEXLIST)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   486
        self.IndexList.Bind(wx.EVT_RIGHT_UP, self.OnIndexListRightUp)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   487
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   488
        self.AddButton = wx.Button(id=ID_EDITINGPANELADDBUTTON, label=_('Add'),
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   489
              name='AddButton', parent=self.IndexListPanel, pos=wx.Point(0, 0),
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   490
              size=wx.DefaultSize, style=0)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   491
        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
   492
              id=ID_EDITINGPANELADDBUTTON)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   493
585
d62424ba12bf Replacing wx.Choice controls by wx.ComboBox controls
laurent
parents: 584
diff changeset
   494
        self.IndexChoice = wx.ComboBox(choices=[], id=ID_EDITINGPANELINDEXCHOICE,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   495
              name='IndexChoice', parent=self.IndexListPanel, pos=wx.Point(50,
585
d62424ba12bf Replacing wx.Choice controls by wx.ComboBox controls
laurent
parents: 584
diff changeset
   496
              0), size=wx.Size(-1, 30), style=wx.CB_READONLY)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   497
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   498
        self._init_sizers()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   499
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   500
    def __init__(self, parent, window, manager, editable = True):
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   501
        self.Editable = editable
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   502
        self._init_ctrls(parent)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   503
        self.ParentWindow = window
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   504
        self.Manager = manager
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   505
        self.ListIndex = []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   506
        self.ChoiceIndex = []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   507
        self.FirstCall = False
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   508
        self.Index = None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   509
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   510
        for values in DictionaryOrganisation:
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   511
            text = "   0x%04X-0x%04X      %s"%(values["minIndex"], values["maxIndex"], values["name"])
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   512
            self.PartList.Append(text)
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   513
        self.Table = SubindexTable(self, [], [], GetSubindexTableColnames())
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   514
        self.SubindexGrid.SetTable(self.Table)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   515
        self.SubindexGrid.SetRowLabelSize(0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   516
        self.CallbackCheck.Disable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   517
        self.Table.ResetView(self.SubindexGrid)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   518
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   519
        if not self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   520
            self.AddButton.Disable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   521
            self.IndexChoice.Disable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   522
            self.CallbackCheck.Disable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   523
            self.Table.Disable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   524
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   525
    def GetIndex(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   526
        return self.Index
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   527
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   528
    def SetIndex(self, index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   529
        self.Index = index
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   530
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   531
    def GetSelection(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   532
        selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   533
        if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   534
            index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   535
            subIndex = self.SubindexGrid.GetGridCursorRow()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   536
            return index, subIndex
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   537
        return None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   538
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 237
diff changeset
   539
    def OnSubindexGridCellLeftClick(self, event):
324
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   540
        if not self.ParentWindow.ModeSolo:
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   541
            col = event.GetCol()
485
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   542
            if self.Editable and col == 0:
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   543
                selected = self.IndexList.GetSelection()
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   544
                if selected != wx.NOT_FOUND:
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   545
                    index = self.ListIndex[selected]
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   546
                    subindex = event.GetRow()
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   547
                    entry_infos = self.Manager.GetEntryInfos(index)
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   548
                    if not entry_infos["struct"] & OD_MultipleSubindexes or subindex != 0:
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   549
                        subentry_infos = self.Manager.GetSubentryInfos(index, subindex)
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   550
                        typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"])
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   551
                        if typeinfos:
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   552
                            bus_id = '.'.join(map(str, self.ParentWindow.GetBusId()))
741
b1a73ddc514b Adding informations in data send when drag'n dropping locations
Laurent Bessard
parents: 622
diff changeset
   553
                            var_name = "master_%04x_%02x" % (index, subindex)
485
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   554
                            size = typeinfos["size"]
747
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   555
                            data = wx.TextDataObject(str(
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   556
                                ("%s%s.%d.%d"%(SizeConversion[size], bus_id, index, subindex), 
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   557
                                 "location", 
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   558
                                 IECTypeConversion.get(typeinfos["name"]), 
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   559
                                 var_name, "")))
485
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   560
                            dragSource = wx.DropSource(self.SubindexGrid)
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   561
                            dragSource.SetData(data)
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   562
                            dragSource.DoDragDrop()
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   563
            elif col == 0:
324
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   564
                selected = self.IndexList.GetSelection()
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   565
                if selected != wx.NOT_FOUND:
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   566
                    index = self.ListIndex[selected]
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   567
                    subindex = event.GetRow()
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   568
                    entry_infos = self.Manager.GetEntryInfos(index)
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   569
                    if not entry_infos["struct"] & OD_MultipleSubindexes or subindex != 0:
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   570
                        subentry_infos = self.Manager.GetSubentryInfos(index, subindex)
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   571
                        typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"])
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   572
                        if subentry_infos["pdo"] and typeinfos:
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   573
                            bus_id = '.'.join(map(str, self.ParentWindow.GetBusId()))
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   574
                            node_id = self.ParentWindow.GetCurrentNodeId()
741
b1a73ddc514b Adding informations in data send when drag'n dropping locations
Laurent Bessard
parents: 622
diff changeset
   575
                            var_name = "%s_%04x_%02x" % (self.Manager.GetSlaveName(node_id), index, subindex)
324
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   576
                            size = typeinfos["size"]
747
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   577
                            data = wx.TextDataObject(str(
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   578
                                ("%s%s.%d.%d.%d"%(SizeConversion[size], bus_id, node_id, index, subindex), 
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   579
                                 "location", 
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   580
                                 IECTypeConversion.get(typeinfos["name"]), 
4725d8f909ff Adding support for translating CANOpen type to corresponding IEC type for location drag'n drop
Laurent Bessard
parents: 741
diff changeset
   581
                                 var_name, "")))
324
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   582
                            dragSource = wx.DropSource(self.SubindexGrid)
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   583
                            dragSource.SetData(data)
c6865f99747a Bug with Drag and Drop on SubindexGrid fixed
lbessard
parents: 312
diff changeset
   584
                            dragSource.DoDragDrop()
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 237
diff changeset
   585
        event.Skip()
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 237
diff changeset
   586
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   587
    def OnAddButtonClick(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   588
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   589
            self.SubindexGrid.SetGridCursor(0, 0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   590
            selected = self.IndexChoice.GetStringSelection()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   591
            if selected != "":
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   592
                choice = INDEXCHOICE_OPTIONS_DICT.get(selected, None)
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   593
                if choice is not None:
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   594
                    if INDEXCHOICE_OPTIONS[choice][1] == 0:
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   595
                        getattr(self.ParentWindow, INDEXCHOICE_OPTIONS[choice][2])()
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   596
                    elif INDEXCHOICE_OPTIONS[choice][1] == 1:
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   597
                        getattr(self.Manager, INDEXCHOICE_OPTIONS[choice][2])()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   598
                elif selected in [menu for menu, indexes in self.Manager.GetCurrentSpecificMenu()]:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   599
                    self.Manager.AddSpecificEntryToCurrent(selected)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   600
                else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   601
                    index = self.ChoiceIndex[self.IndexChoice.GetSelection()]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   602
                    self.Manager.ManageEntriesOfCurrent([index], [])
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   603
                self.ParentWindow.RefreshBufferState()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   604
                self.RefreshIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   605
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   606
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   607
    def OnPartListBoxClick(self, event):
491
2ad3dedf6c6a Segmentation Fault on closing fixed
lbessard
parents: 485
diff changeset
   608
        if not self.ParentWindow.IsClosing():
2ad3dedf6c6a Segmentation Fault on closing fixed
lbessard
parents: 485
diff changeset
   609
            self.SubindexGrid.SetGridCursor(0, 0)
2ad3dedf6c6a Segmentation Fault on closing fixed
lbessard
parents: 485
diff changeset
   610
            self.RefreshIndexList()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   611
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   612
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   613
    def OnIndexListClick(self, event):
491
2ad3dedf6c6a Segmentation Fault on closing fixed
lbessard
parents: 485
diff changeset
   614
        if not self.ParentWindow.IsClosing():
2ad3dedf6c6a Segmentation Fault on closing fixed
lbessard
parents: 485
diff changeset
   615
            self.SubindexGrid.SetGridCursor(0, 0)
2ad3dedf6c6a Segmentation Fault on closing fixed
lbessard
parents: 485
diff changeset
   616
            self.RefreshTable()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   617
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   618
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   619
    def OnSubindexGridSelectCell(self, event):
491
2ad3dedf6c6a Segmentation Fault on closing fixed
lbessard
parents: 485
diff changeset
   620
        if not self.ParentWindow.IsClosing():
2ad3dedf6c6a Segmentation Fault on closing fixed
lbessard
parents: 485
diff changeset
   621
            wx.CallAfter(self.ParentWindow.RefreshStatusBar)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   622
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   623
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   624
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   625
#                             Refresh Functions
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   626
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   627
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   628
    def RefreshIndexList(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   629
        selected = self.IndexList.GetSelection()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   630
        choice = self.IndexChoice.GetStringSelection()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   631
        choiceindex = self.IndexChoice.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   632
        if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   633
            selectedindex = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   634
        self.IndexList.Clear()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   635
        self.IndexChoice.Clear()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   636
        i = self.PartList.GetSelection()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   637
        if i < len(DictionaryOrganisation):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   638
            values = DictionaryOrganisation[i]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   639
            self.ListIndex = []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   640
            for name, index in self.Manager.GetCurrentValidIndexes(values["minIndex"], values["maxIndex"]):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   641
                self.IndexList.Append("0x%04X   %s"%(index, name))
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   642
                self.ListIndex.append(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   643
            if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   644
                self.ChoiceIndex = []
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   645
                choices = INDEXCHOICE_SECTIONS.get(i, None)
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   646
                if choices is not None:
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   647
                    for c in choices:
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   648
                        self.IndexChoice.Append(INDEXCHOICE_OPTIONS[c][0])
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   649
                    if len(choices) > 1:
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   650
                        if choiceindex != wx.NOT_FOUND and choice == self.IndexChoice.GetString(choiceindex):
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   651
                            self.IndexChoice.SetStringSelection(choice)
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   652
                    else:
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   653
                        self.IndexChoice.SetSelection(0)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   654
                else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   655
                    for name, index in self.Manager.GetCurrentValidChoices(values["minIndex"], values["maxIndex"]):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   656
                        if index:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   657
                            self.IndexChoice.Append("0x%04X   %s"%(index, name))
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   658
                        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   659
                            self.IndexChoice.Append(name)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   660
                        self.ChoiceIndex.append(index)
312
70f96abd8ecd Bug on RefreshList in subindextable.py fixed
lbessard
parents: 310
diff changeset
   661
                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
   662
                    self.IndexChoice.SetStringSelection(choice)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   663
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   664
            self.IndexChoice.Enable(self.IndexChoice.GetCount() != 0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   665
            self.AddButton.Enable(self.IndexChoice.GetCount() != 0)
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   666
        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
   667
            self.Table.Empty()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   668
            self.CallbackCheck.SetValue(False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   669
            self.CallbackCheck.Disable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   670
            self.Table.ResetView(self.SubindexGrid)
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   671
            self.ParentWindow.RefreshStatusBar()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   672
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   673
            self.IndexList.SetSelection(selected)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   674
            self.RefreshTable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   675
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   676
    def RefreshTable(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   677
        selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   678
        if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   679
            index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   680
            if index > 0x260 and self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   681
                self.CallbackCheck.Enable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   682
                self.CallbackCheck.SetValue(self.Manager.HasCurrentEntryCallbacks(index))
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   683
            result = self.Manager.GetCurrentEntryValues(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   684
            if result != None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   685
                self.Table.SetCurrentIndex(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   686
                data, editors = result
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   687
                self.Table.SetData(data)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   688
                self.Table.SetEditors(editors)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   689
                self.Table.ResetView(self.SubindexGrid)
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   690
        self.ParentWindow.RefreshStatusBar()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   691
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   692
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   693
#                        Editing Table value function
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   694
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   695
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   696
    def OnSubindexGridEditorShown(self, event):
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   697
        row, col = event.GetRow(), event.GetCol() 
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   698
        if self.Table.GetEditor(row, col) == "dcf":
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   699
            wx.CallAfter(self.ShowDCFEntryDialog, row, col)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   700
            event.Veto()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   701
        else:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   702
            event.Skip()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   703
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   704
    def ShowDCFEntryDialog(self, row, col):
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   705
        if self.Editable:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   706
            selected = self.IndexList.GetSelection()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   707
            if selected != wx.NOT_FOUND:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   708
                index = self.ListIndex[selected]
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   709
                if self.Manager.IsCurrentEntry(index):
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   710
                    dialog = DCFEntryValuesDialog(self)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   711
                    dialog.SetValues(self.Table.GetValue(row, col).decode("hex_codec"))
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   712
                    if dialog.ShowModal() == wx.ID_OK:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   713
                        value = dialog.GetValues()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   714
                        self.Manager.SetCurrentEntry(index, row, value, "value", "dcf")
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   715
                        self.ParentWindow.RefreshBufferState()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   716
                        wx.CallAfter(self.RefreshTable)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   717
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   718
    def OnSubindexGridCellChange(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   719
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   720
            index = self.Table.GetCurrentIndex()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   721
            subIndex = event.GetRow()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   722
            col = event.GetCol()
584
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 580
diff changeset
   723
            name = self.Table.GetColLabelValue(col, False)
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 580
diff changeset
   724
            value = self.Table.GetValue(subIndex, col, False)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   725
            editor = self.Table.GetEditor(subIndex, col)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   726
            self.Manager.SetCurrentEntry(index, subIndex, value, name, editor)
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   727
            self.ParentWindow.RefreshBufferState()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   728
            wx.CallAfter(self.RefreshTable)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   729
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   730
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   731
    def OnCallbackCheck(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   732
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   733
            index = self.Table.GetCurrentIndex()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   734
            self.Manager.SetCurrentEntryCallbacks(index, self.CallbackCheck.GetValue())
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   735
            self.ParentWindow.RefreshBufferState()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   736
            wx.CallAfter(self.RefreshTable)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   737
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   738
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   739
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   740
#                          Contextual Menu functions
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   741
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   742
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   743
    def OnIndexListRightUp(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   744
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   745
            if not self.FirstCall:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   746
                self.FirstCall = True
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   747
                selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   748
                if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   749
                    index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   750
                    if index < 0x260:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   751
                        self.IndexListMenu.FindItemByPosition(0).Enable(False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   752
                        self.IndexListMenu.FindItemByPosition(1).Enable(True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   753
                        self.PopupMenu(self.IndexListMenu)
273
58b39f97e352 Some bugs fixed
lbessard
parents: 271
diff changeset
   754
                    elif 0x1000 <= index <= 0x1FFF:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   755
                        self.IndexListMenu.FindItemByPosition(0).Enable(False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   756
                        self.IndexListMenu.FindItemByPosition(1).Enable(False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   757
                        self.PopupMenu(self.IndexListMenu)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   758
                    elif 0x2000 <= index <= 0x5FFF:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   759
                        self.IndexListMenu.FindItemByPosition(0).Enable(True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   760
                        self.IndexListMenu.FindItemByPosition(1).Enable(False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   761
                        self.PopupMenu(self.IndexListMenu)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   762
                    elif index >= 0x6000:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   763
                        self.IndexListMenu.FindItemByPosition(0).Enable(False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   764
                        self.IndexListMenu.FindItemByPosition(1).Enable(False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   765
                        self.PopupMenu(self.IndexListMenu)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   766
            else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   767
                self.FirstCall = False
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   768
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   769
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   770
    def OnSubindexGridRightClick(self, event):
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   771
        self.SubindexGrid.SetGridCursor(event.GetRow(), event.GetCol())
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   772
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   773
            selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   774
            if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   775
                index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   776
                if self.Manager.IsCurrentEntry(index):
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   777
                    showpopup = False
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   778
                    infos = self.Manager.GetEntryInfos(index)
310
1975e546178b Bugs on EDS import fixed
lbessard
parents: 299
diff changeset
   779
                    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
   780
                        showpopup = True
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   781
                        self.SubindexGridMenu.FindItemByPosition(0).Enable(True)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   782
                        self.SubindexGridMenu.FindItemByPosition(1).Enable(True)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   783
                    else:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   784
                        self.SubindexGridMenu.FindItemByPosition(0).Enable(False)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   785
                        self.SubindexGridMenu.FindItemByPosition(1).Enable(False)
622
f0935accb93b Bug in Subindex grid right click with i18n fixed
laurent
parents: 608
diff changeset
   786
                    if self.Table.GetColLabelValue(event.GetCol(), False) == "value":
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   787
                        showpopup = True
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   788
                        self.SubindexGridMenu.FindItemByPosition(3).Enable(True)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   789
                    else:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   790
                        self.SubindexGridMenu.FindItemByPosition(3).Enable(False)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   791
                    if showpopup:
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 237
diff changeset
   792
                        self.PopupMenu(self.SubindexGridMenu)
622
f0935accb93b Bug in Subindex grid right click with i18n fixed
laurent
parents: 608
diff changeset
   793
        elif self.Table.GetColLabelValue(event.GetCol(), False) == "value":
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   794
            selected = self.IndexList.GetSelection()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   795
            if selected != wx.NOT_FOUND:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   796
                index = self.ListIndex[selected]
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   797
                if self.Manager.IsCurrentEntry(index):
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   798
                    infos = self.Manager.GetEntryInfos(index)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   799
                    if not infos["struct"] & OD_MultipleSubindexes or event.GetRow() > 0:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   800
                        self.SubindexGridMenu.FindItemByPosition(0).Enable(False)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   801
                        self.SubindexGridMenu.FindItemByPosition(1).Enable(False)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   802
                        self.SubindexGridMenu.FindItemByPosition(3).Enable(False)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   803
                        self.SubindexGridMenu.FindItemByPosition(4).Enable(True)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   804
                        self.PopupMenu(self.SubindexGridMenu)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   805
        event.Skip()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   806
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   807
    def OnAddToDCFSubindexMenu(self, event):
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   808
        if not self.Editable:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   809
            selected = self.IndexList.GetSelection()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   810
            if selected != wx.NOT_FOUND:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   811
                index = self.ListIndex[selected]
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   812
                subindex = self.SubindexGrid.GetGridCursorRow()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   813
                entry_infos = self.Manager.GetEntryInfos(index)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   814
                if not entry_infos["struct"] & OD_MultipleSubindexes or subindex != 0:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   815
                    subentry_infos = self.Manager.GetSubentryInfos(index, subindex)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   816
                    typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"])
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   817
                    if typeinfos:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   818
                        node_id = self.ParentWindow.GetCurrentNodeId()
336
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   819
                        value = self.Table.GetValueByName(subindex, "value")
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   820
                        if value == "True":
340
60e1eb89455e Bug on new DCF entry boolean value fixed
lbessard
parents: 336
diff changeset
   821
                            value = 1
60e1eb89455e Bug on new DCF entry boolean value fixed
lbessard
parents: 336
diff changeset
   822
                        elif value == "False":
336
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   823
                            value = 0
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   824
                        elif value.isdigit():
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   825
                            value = int(value)
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   826
                        elif value.startswith("0x"):
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   827
                            value = int(value, 16)
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   828
                        else:
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   829
                            value = int(value.encode("hex_codec"), 16)
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   830
                        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
   831
                        self.ParentWindow.OpenMasterDCFDialog(node_id)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   832
336
42ab55532da8 Bug on DCF edition fixed
lbessard
parents: 327
diff changeset
   833
    def OpenDCFDialog(self, node_id):
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   834
        self.PartList.SetSelection(7)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   835
        self.RefreshIndexList()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   836
        self.IndexList.SetSelection(self.ListIndex.index(0x1F22))
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   837
        self.RefreshTable()
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   838
        self.SubindexGrid.SetGridCursor(node_id, 3)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 324
diff changeset
   839
        self.ShowDCFEntryDialog(node_id, 3)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   840
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   841
    def OnRenameIndexMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   842
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   843
            selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   844
            if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   845
                index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   846
                if self.Manager.IsCurrentEntry(index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   847
                    infos = self.Manager.GetEntryInfos(index)
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   848
                    dialog = wx.TextEntryDialog(self, _("Give a new name for index 0x%04X")%index,
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   849
                                 _("Rename an index"), infos["name"], wx.OK|wx.CANCEL)
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   850
                    if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   851
                        self.Manager.SetCurrentEntryName(index, dialog.GetValue())
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   852
                        self.ParentWindow.RefreshBufferState()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   853
                        self.RefreshIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   854
                    dialog.Destroy()
608
daa1e1c3fba4 Removing superfluous event.Skip()
laurent
parents: 585
diff changeset
   855
        
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   856
    def OnModifyIndexMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   857
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   858
            selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   859
            if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   860
                index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   861
                if self.Manager.IsCurrentEntry(index) and index < 0x260:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   862
                    values, valuetype = self.Manager.GetCustomisedTypeValues(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   863
                    dialog = UserTypeDialog(self)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   864
                    dialog.SetTypeList(self.Manager.GetCustomisableTypes(), values[1])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   865
                    if valuetype == 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   866
                        dialog.SetValues(min = values[2], max = values[3])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   867
                    elif valuetype == 1:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   868
                        dialog.SetValues(length = values[2])
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   869
                    if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   870
                        type, min, max, length = dialog.GetValues()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   871
                        self.Manager.SetCurrentUserType(index, type, min, max, length)
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   872
                        self.ParentWindow.RefreshBufferState()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   873
                        self.RefreshIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   874
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   875
    def OnDeleteIndexMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   876
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   877
            selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   878
            if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   879
                index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   880
                if self.Manager.IsCurrentEntry(index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   881
                    self.Manager.ManageEntriesOfCurrent([],[index])
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   882
                    self.ParentWindow.RefreshBufferState()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   883
                    self.RefreshIndexList()
608
daa1e1c3fba4 Removing superfluous event.Skip()
laurent
parents: 585
diff changeset
   884
        
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   885
    def OnAddSubindexMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   886
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   887
            selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   888
            if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   889
                index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   890
                if self.Manager.IsCurrentEntry(index):
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   891
                    dialog = wx.TextEntryDialog(self, _("Number of subindexes to add:"),
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   892
                                 _("Add subindexes"), "1", wx.OK|wx.CANCEL)
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   893
                    if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   894
                        try:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   895
                            number = int(dialog.GetValue())
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   896
                            self.Manager.AddSubentriesToCurrent(index, number)
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   897
                            self.ParentWindow.RefreshBufferState()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   898
                            self.RefreshIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   899
                        except:
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   900
                            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
   901
                            message.ShowModal()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   902
                            message.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   903
                    dialog.Destroy()
608
daa1e1c3fba4 Removing superfluous event.Skip()
laurent
parents: 585
diff changeset
   904
        
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   905
    def OnDeleteSubindexMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   906
        if self.Editable:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   907
            selected = self.IndexList.GetSelection()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   908
            if selected != wx.NOT_FOUND:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   909
                index = self.ListIndex[selected]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   910
                if self.Manager.IsCurrentEntry(index):
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   911
                    dialog = wx.TextEntryDialog(self, _("Number of subindexes to delete:"),
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   912
                                 _("Delete subindexes"), "1", wx.OK|wx.CANCEL)
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   913
                    if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   914
                        try:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   915
                            number = int(dialog.GetValue())
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   916
                            self.Manager.RemoveSubentriesFromCurrent(index, number)
271
2f286d3fc7f6 Adding support for using Networkedit with Beremiz
lbessard
parents: 269
diff changeset
   917
                            self.ParentWindow.RefreshBufferState()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   918
                            self.RefreshIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   919
                        except:
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 491
diff changeset
   920
                            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
   921
                            message.ShowModal()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   922
                            message.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   923
                    dialog.Destroy()
608
daa1e1c3fba4 Removing superfluous event.Skip()
laurent
parents: 585
diff changeset
   924
        
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   925
    def OnDefaultValueSubindexMenu(self, event):
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   926
        if self.Editable:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   927
            selected = self.IndexList.GetSelection()
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   928
            if selected != wx.NOT_FOUND:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   929
                index = self.ListIndex[selected]
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   930
                if self.Manager.IsCurrentEntry(index):
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   931
                    row = self.SubindexGrid.GetGridCursorRow()
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   932
                    self.Manager.SetCurrentEntryToDefault(index, row)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   933
                    self.ParentWindow.RefreshBufferState()
506f9700b9fb Allowing user to type formulas
lbessard
parents: 281
diff changeset
   934
                    self.RefreshIndexList()
608
daa1e1c3fba4 Removing superfluous event.Skip()
laurent
parents: 585
diff changeset
   935