etherlab/EtherCATManagementEditor.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Sat, 29 Sep 2018 17:00:01 +0300
changeset 2402 a1df3102327d
parent 2390 81116c5db60f
child 2405 af050469fc5c
permissions -rw-r--r--
ignore missing MotionLibrary

to fix pylint error 'E0401 # (import-error) Unable to import 'X'
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     1
#!/usr/bin/env python
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     2
# -*- coding: utf-8 -*-
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     3
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     4
# This file is part of Beremiz
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     5
#
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     6
# Copyright (C) 2013: Real-Time & Embedded Systems (RTES) Lab., University of Seoul
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     7
#
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     8
# See COPYING file for copyrights details.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     9
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    10
import os
2390
81116c5db60f clean etherlab: pylint, C0411 # (wrong-import-order) standard import "import x" comes before "import y"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2389
diff changeset
    11
import string
81116c5db60f clean etherlab: pylint, C0411 # (wrong-import-order) standard import "import x" comes before "import y"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2389
diff changeset
    12
from xml.dom import minidom
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    13
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    14
import wx
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    15
import wx.grid
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    16
import wx.gizmos
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    17
import wx.lib.buttons
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    18
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    19
# --------------------------------------------------------------------
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    20
from controls import CustomGrid, CustomTable
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    21
# --------------------------------------------------------------------
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    22
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    23
# ------------ for register management ---------------
2390
81116c5db60f clean etherlab: pylint, C0411 # (wrong-import-order) standard import "import x" comes before "import y"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2389
diff changeset
    24
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
    25
from util.TranslationCatalogs import NoTranslate
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    26
# -------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    27
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
    28
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    29
# ----------------------------- For Sync Manager Table -----------------------------------
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    30
def GetSyncManagersTableColnames():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    31
    """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    32
    Returns column names of SyncManager Table in Slave state panel.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    33
    """
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
    34
    _ = NoTranslate
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    35
    return ["#", _("Name"), _("Start Address"), _("Default Size"), _("Control Byte"), _("Enable")]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    36
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
    37
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    38
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    39
#                    Sync Managers Table
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    40
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    41
class SyncManagersTable(CustomTable):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    42
    def GetValue(self, row, col):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    43
        if row < self.GetNumberRows():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    44
            if col == 0:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    45
                return row
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    46
            return self.data[row].get(self.GetColLabelValue(col, False), "")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    47
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
    48
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    49
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    50
#                    EtherCAT Management Treebook
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    51
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    52
class EtherCATManagementTreebook(wx.Treebook):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    53
    def __init__(self, parent, controler, node_editor):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    54
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    55
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    56
        @param parent: Reference to the parent wx.ScrolledWindow object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    57
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    58
        @param node_editor: Reference to Beremiz frame
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    59
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    60
        wx.Treebook.__init__(self, parent, -1, size=wx.DefaultSize, style=wx.BK_DEFAULT)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    61
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    62
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    63
        self.NodeEditor = node_editor
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    64
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    65
        self.EtherCATManagementClassObject = {}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    66
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    67
        # fill EtherCAT Management Treebook
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    68
        panels = [
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    69
            ("Slave State",        SlaveStatePanelClass, []),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    70
            ("SDO Management",     SDOPanelClass, []),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    71
            ("PDO Monitoring",     PDOPanelClass, []),
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    72
            ("ESC Management",     EEPROMAccessPanel, [
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    73
                ("Smart View", SlaveSiiSmartView),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    74
                ("Hex View", HexView)]),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    75
            ("Register Access",     RegisterAccessPanel, [])
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    76
        ]
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    77
        for pname, pclass, subs in panels:
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    78
            self.AddPage(pclass(self, self.Controler), pname)
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    79
            for spname, spclass in subs:
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    80
                self.AddSubPage(spclass(self, self.Controler), spname)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    81
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    82
        self.Bind(wx.EVT_TREEBOOK_PAGE_CHANGED, self.OnPageChanged)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    83
        self.Bind(wx.EVT_TREEBOOK_PAGE_CHANGING, self.OnPageChanging)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    84
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    85
    def OnPageChanged(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    86
        old = event.GetOldSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    87
        new = event.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    88
        sel = event.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    89
        event.Skip()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    90
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    91
    def OnPageChanging(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    92
        old = event.GetOldSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    93
        new = event.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    94
        sel = event.GetSelection()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    95
        event.Skip()
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    96
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
    97
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    98
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    99
#                    For SlaveState Panel
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   100
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   101
class SlaveStatePanelClass(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   102
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   103
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   104
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   105
        @param parent: Reference to the parent EtherCATManagementTreebook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   106
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   107
        """
2366
d635680e4c2c cleanup etherlab: pep8, E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2365
diff changeset
   108
        wx.Panel.__init__(self, parent, -1, (0, 0), size=wx.DefaultSize, style=wx.SUNKEN_BORDER)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   109
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   110
        self.parent = parent
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   111
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   112
        # initialize SlaveStatePanel UI dictionaries
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   113
        self.StaticBoxDic = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   114
        self.StaticTextDic = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   115
        self.TextCtrlDic = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   116
        self.ButtonDic = {}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   117
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   118
        # iniitalize BoxSizer and FlexGridSizer
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   119
        self.SizerDic = {
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   120
            "SlaveState_main_sizer": wx.BoxSizer(wx.VERTICAL),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   121
            "SlaveState_inner_main_sizer": wx.FlexGridSizer(cols=1, hgap=50, rows=3, vgap=10),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   122
            "SlaveInfosDetailsInnerSizer": wx.FlexGridSizer(cols=4, hgap=10, rows=2, vgap=10),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   123
            "SyncManagerInnerSizer": wx.FlexGridSizer(cols=1, hgap=5, rows=1, vgap=5),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   124
            "SlaveState_sizer": wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   125
            "SlaveState_up_sizer": wx.FlexGridSizer(cols=4, hgap=10, rows=2, vgap=10),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   126
            "SlaveState_down_sizer": wx.FlexGridSizer(cols=2, hgap=10, rows=1, vgap=10)}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   127
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   128
        # initialize StaticBox and StaticBoxSizer
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   129
        for box_name, box_label in [
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   130
                ("SlaveInfosDetailsBox", "Slave Informations"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   131
                ("SyncManagerBox", "Sync Manager"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   132
                ("SlaveStateBox", "Slave State Transition && Monitoring")]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   133
            self.StaticBoxDic[box_name] = wx.StaticBox(self, label=_(box_label))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   134
            self.SizerDic[box_name] = wx.StaticBoxSizer(self.StaticBoxDic[box_name])
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   135
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   136
        for statictext_name, statictext_label, textctrl_name in [
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   137
                ("VendorLabel", "Vendor:", "vendor"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   138
                ("ProductcodeLabel", "Product code:", "product_code"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   139
                ("RevisionnumberLabel", "Slave Count:", "revision_number"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   140
                ("PhysicsLabel", "Physics:", "physics")]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   141
            self.StaticTextDic[statictext_name] = wx.StaticText(self, label=_(statictext_label))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   142
            self.TextCtrlDic[textctrl_name] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   143
            self.SizerDic["SlaveInfosDetailsInnerSizer"].AddMany([self.StaticTextDic[statictext_name],
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   144
                                                                  self.TextCtrlDic[textctrl_name]])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   145
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   146
        self.SizerDic["SlaveInfosDetailsBox"].AddSizer(self.SizerDic["SlaveInfosDetailsInnerSizer"])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   147
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   148
        self.SyncManagersGrid = CustomGrid(self, size=wx.Size(605, 155), style=wx.VSCROLL)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   149
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   150
        self.SizerDic["SyncManagerInnerSizer"].Add(self.SyncManagersGrid)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   151
        self.SizerDic["SyncManagerBox"].Add(self.SizerDic["SyncManagerInnerSizer"])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   152
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   153
        buttons = [
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   154
            ("InitButton",   0, "INIT", "State Transition to \"Init\" State",     self.OnButtonClick, []),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   155
            ("PreOPButton",  1, "PREOP", "State Transition to \"PreOP\" State",   self.OnButtonClick, [
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   156
                ("TargetStateLabel", "Target State:", "TargetState")]),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   157
            ("SafeOPButton", 2, "SAFEOP", "State Transition to \"SafeOP\" State", self.OnButtonClick, []),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   158
            ("OPButton",     3, "OP",  "State Transition to \"OP\" State",        self.OnButtonClick, [
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   159
                ("CurrentStateLabel", "Current State:", "CurrentState")])
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   160
        ]
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   161
        for button_name, button_id, button_label, button_tooltipstring, event_method, sub_item in buttons:
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   162
            self.ButtonDic[button_name] = wx.Button(self, id=button_id, label=_(button_label))
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   163
            self.ButtonDic[button_name].Bind(wx.EVT_BUTTON, event_method)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   164
            self.ButtonDic[button_name].SetToolTipString(button_tooltipstring)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   165
            self.SizerDic["SlaveState_up_sizer"].Add(self.ButtonDic[button_name])
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   166
            for statictext_name, statictext_label, textctrl_name in sub_item:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   167
                self.StaticTextDic[statictext_name] = wx.StaticText(self, label=_(statictext_label))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   168
                self.TextCtrlDic[textctrl_name] = wx.TextCtrl(self, size=wx.DefaultSize, style=wx.TE_READONLY)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   169
                self.SizerDic["SlaveState_up_sizer"].AddMany([self.StaticTextDic[statictext_name],
2380
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
   170
                                                              self.TextCtrlDic[textctrl_name]])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   171
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   172
        for button_name, button_label, button_tooltipstring, event_method in [
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   173
                ("StartTimerButton", "Start State Monitoring", "Slave State Update Restart", self.StartTimer),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   174
                ("StopTimerButton", "Stop State Monitoring", "Slave State Update Stop", self.CurrentStateThreadStop)]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   175
            self.ButtonDic[button_name] = wx.Button(self, label=_(button_label))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   176
            self.ButtonDic[button_name].Bind(wx.EVT_BUTTON, event_method)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   177
            self.ButtonDic[button_name].SetToolTipString(button_tooltipstring)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   178
            self.SizerDic["SlaveState_down_sizer"].Add(self.ButtonDic[button_name])
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   179
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   180
        self.SizerDic["SlaveState_sizer"].AddMany([self.SizerDic["SlaveState_up_sizer"],
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   181
                                                   self.SizerDic["SlaveState_down_sizer"]])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   182
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   183
        self.SizerDic["SlaveStateBox"].Add(self.SizerDic["SlaveState_sizer"])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   184
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   185
        self.SizerDic["SlaveState_inner_main_sizer"].AddMany([
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   186
            self.SizerDic["SlaveInfosDetailsBox"], self.SizerDic["SyncManagerBox"],
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   187
            self.SizerDic["SlaveStateBox"]])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   188
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   189
        self.SizerDic["SlaveState_main_sizer"].Add(self.SizerDic["SlaveState_inner_main_sizer"])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   190
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   191
        self.SetSizer(self.SizerDic["SlaveState_main_sizer"])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   192
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   193
        # register a timer for periodic exectuion of slave state update (period: 1000 ms)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   194
        self.Bind(wx.EVT_TIMER, self.GetCurrentState)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   195
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   196
        self.CreateSyncManagerTable()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   197
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   198
        self.Centre()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   199
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   200
    def CreateSyncManagerTable(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   201
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   202
        Create grid for "SyncManager"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   203
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   204
        # declare Table object
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   205
        self.SyncManagersTable = SyncManagersTable(self, [], GetSyncManagersTableColnames())
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   206
        self.SyncManagersGrid.SetTable(self.SyncManagersTable)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   207
        # set grid alignment attr. (CENTER)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   208
        self.SyncManagersGridColAlignements = [wx.ALIGN_CENTRE, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE,
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   209
                                               wx.ALIGN_CENTRE, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   210
        # set grid size
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   211
        self.SyncManagersGridColSizes = [40, 150, 100, 100, 100, 100]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   212
        self.SyncManagersGrid.SetRowLabelSize(0)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   213
        for col in range(self.SyncManagersTable.GetNumberCols()):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   214
            attr = wx.grid.GridCellAttr()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   215
            attr.SetAlignment(self.SyncManagersGridColAlignements[col], wx.ALIGN_CENTRE)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   216
            self.SyncManagersGrid.SetColAttr(col, attr)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   217
            self.SyncManagersGrid.SetColMinimalWidth(col, self.SyncManagersGridColSizes[col])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   218
            self.SyncManagersGrid.AutoSizeColumn(col, False)
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   219
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   220
        self.RefreshSlaveInfos()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   221
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   222
    def RefreshSlaveInfos(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   223
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   224
        Fill data in "Slave Information" and "SyncManager"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   225
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   226
        slave_infos = self.Controler.GetSlaveInfos()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   227
        sync_manager_section = ["vendor", "product_code", "revision_number", "physics"]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   228
        if slave_infos is not None:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   229
            # this method is same as "TextCtrl.SetValue"
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   230
            for textctrl_name in sync_manager_section:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   231
                self.TextCtrlDic[textctrl_name].SetValue(slave_infos[textctrl_name])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   232
            self.SyncManagersTable.SetData(slave_infos["sync_managers"])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   233
            self.SyncManagersTable.ResetView(self.SyncManagersGrid)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   234
        else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   235
            for textctrl_name in sync_manager_section:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   236
                self.TextCtrlDic[textctrl_name].SetValue("")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   237
            self.SyncManagersTable.SetData([])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   238
            self.SyncManagersTable.ResetView(self.SyncManagersGrid)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   239
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   240
    def OnButtonClick(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   241
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   242
        Event handler for slave state transition button click (Init, PreOP, SafeOP, OP button)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   243
        @param event : wx.EVT_BUTTON object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   244
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   245
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   246
        if check_connect_flag:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   247
            state_dic = ["INIT", "PREOP", "SAFEOP", "OP"]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   248
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   249
            # If target state is one of {INIT, PREOP, SAFEOP}, request slave state transition immediately.
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   250
            if event.GetId() < 3:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   251
                self.Controler.CommonMethod.RequestSlaveState(state_dic[event.GetId()])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   252
                self.TextCtrlDic["TargetState"].SetValue(state_dic[event.GetId()])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   253
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   254
            # If target state is OP, first check "PLC status".
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   255
            #  (1) If current PLC status is "Started", then request slave state transition
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   256
            #  (2) Otherwise, show error message and return
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   257
            else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   258
                status, count = self.Controler.GetCTRoot()._connector.GetPLCstatus()
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   259
                if status == "Started":
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   260
                    self.Controler.CommonMethod.RequestSlaveState("OP")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   261
                    self.TextCtrlDic["TargetState"].SetValue("OP")
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   262
                else:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   263
                    self.Controler.CommonMethod.CreateErrorDialog("PLC is Not Started")
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   264
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   265
    def GetCurrentState(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   266
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   267
        Timer event handler for periodic slave state monitoring (Default period: 1 sec = 1000 msec).
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   268
        @param event : wx.TIMER object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   269
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   270
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(True)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   271
        if check_connect_flag:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   272
            returnVal = self.Controler.CommonMethod.GetSlaveStateFromSlave()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   273
            line = returnVal.split("\n")
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   274
            try:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   275
                self.SetCurrentState(line[self.Controler.GetSlavePos()])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   276
            except Exception:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   277
                pass
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   278
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   279
    def SetCurrentState(self, line):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   280
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   281
        Show current slave state using the executiob result of "ethercat slaves" command.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   282
        @param line : result of "ethercat slaves" command
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   283
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   284
        state_array = ["INIT", "PREOP", "SAFEOP", "OP"]
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   285
        try:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   286
            # parse the execution result of  "ethercat slaves" command
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   287
            # Result example : 0  0:0  PREOP  +  EL9800 (V4.30) (PIC24, SPI, ET1100)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   288
            token = line.split("  ")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   289
            if token[2] in state_array:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   290
                self.TextCtrlDic["CurrentState"].SetValue(token[2])
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   291
        except Exception:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   292
            pass
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   293
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   294
    def StartTimer(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   295
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   296
        Event handler for "Start State Monitoring" button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   297
          - start slave state monitoring thread
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   298
        @param event : wx.EVT_BUTTON object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   299
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   300
        self.SlaveStateThread = wx.Timer(self)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   301
        # set timer period (1000 ms)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   302
        self.SlaveStateThread.Start(1000)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   303
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   304
    def CurrentStateThreadStop(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   305
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   306
        Event handler for "Stop State Monitoring" button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   307
          - stop slave state monitoring thread
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   308
        @param event : wx.EVT_BUTTON object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   309
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   310
        try:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   311
            self.SlaveStateThread.Stop()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   312
        except Exception:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   313
            pass
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   314
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
   315
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   316
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   317
#                    For SDO Management Panel
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   318
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   319
class SDOPanelClass(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   320
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   321
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   322
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   323
        @param parent: Reference to the parent EtherCATManagementTreebook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   324
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   325
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   326
        wx.Panel.__init__(self, parent, -1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   327
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   328
        self.DatatypeDescription, self.CommunicationObject, self.ManufacturerSpecific, \
2384
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2383
diff changeset
   329
            self.ProfileSpecific, self.Reserved, self.AllSDOData = range(6)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   330
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   331
        self.Controler = controler
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   332
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   333
        self.SDOManagementMainSizer = wx.BoxSizer(wx.VERTICAL)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   334
        self.SDOManagementInnerMainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   335
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   336
        self.SDOUpdate = wx.Button(self, label=_('update'))
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   337
        self.SDOUpdate.Bind(wx.EVT_BUTTON, self.SDOInfoUpdate)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   338
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   339
        self.CallSDONoteBook = SDONoteBook(self, controler=self.Controler)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   340
        self.SDOManagementInnerMainSizer.Add(self.SDOUpdate)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   341
        self.SDOManagementInnerMainSizer.Add(self.CallSDONoteBook, wx.ALL | wx.EXPAND)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   342
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   343
        self.SDOManagementMainSizer.Add(self.SDOManagementInnerMainSizer)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   344
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   345
        self.SetSizer(self.SDOManagementMainSizer)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   346
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   347
    def SDOInfoUpdate(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   348
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   349
        Evenet handler for SDO "update" button.
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   350
          - Load SDO data from current slave
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   351
        @param event : wx.EVT_BUTTON object
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   352
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   353
        self.Controler.CommonMethod.SaveSDOData = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   354
        self.Controler.CommonMethod.ClearSDODataSet()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   355
        self.SDOFlag = False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   356
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   357
        # Check whether beremiz connected or not.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   358
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   359
        if check_connect_flag:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   360
            self.SDOs = self.Controler.CommonMethod.GetSlaveSDOFromSlave()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   361
            # SDOFlag is "False", user click "Cancel" button
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   362
            self.SDOFlag = self.SDOParser()
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   363
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   364
            if self.SDOFlag:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   365
                self.CallSDONoteBook.CreateNoteBook()
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   366
                self.Refresh()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   367
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   368
    def SDOParser(self):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   369
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   370
        Parse SDO data set that obtain "SDOInfoUpdate" Method
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   371
        @return True or False
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   372
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   373
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   374
        slaveSDO_progress = wx.ProgressDialog("Slave SDO Monitoring", "Now Uploading...",
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   375
                                              maximum=len(self.SDOs.splitlines()),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   376
                                              parent=self,
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   377
                                              style=wx.PD_CAN_ABORT | wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME |
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   378
                                              wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME |
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   379
                                              wx.PD_AUTO_HIDE | wx.PD_SMOOTH)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   380
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   381
        # If keep_going flag is False, SDOParser method is stop and return "False".
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   382
        keep_going = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   383
        count = 0
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   384
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   385
        # SDO data example
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   386
        # SDO 0x1000, "Device type"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   387
        # 0x1000:00,r-r-r-,uint32,32 bit,"Device type",0x00020192, 131474
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   388
        for details_line in self.SDOs.splitlines():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   389
            count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   390
            line_token = details_line.split("\"")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   391
            # len(line_token[2]) case : SDO 0x1000, "Device type"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   392
            if len(line_token[2]) == 0:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   393
                title_name = line_token[1]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   394
            # else case : 0x1000:00,r-r-r-,uint32,32 bit,"Device type",0x00020192, 131474
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   395
            else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   396
                # line_token = ['0x1000:00,r-r-r-,uint32,32 bit,', 'Device type', ',0x00020192, 131474']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   397
                token_head, name, token_tail = line_token
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   398
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   399
                # token_head = ['0x1000:00', 'r-r-r-', 'uint32', '32 bit', '']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   400
                token_head = token_head.split(",")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   401
                ful_idx, access, type, size, empty = token_head
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   402
                # ful_idx.split(":") = ['0x1000', '00']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   403
                idx, sub_idx = ful_idx.split(":")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   404
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   405
                # token_tail = ['', '0x00020192', '131474']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   406
                token_tail = token_tail.split(",")
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   407
                try:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   408
                    empty, hex_val, dec_val = token_tail
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   409
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   410
                # SDO data is not return "dec value"
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   411
                # line example :
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   412
                # 0x1702:01,rwr-r-,uint32,32 bit," 1st mapping", ----
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   413
                except Exception:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   414
                    empty, hex_val = token_tail
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   415
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   416
                name_after_check = self.StringTest(name)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   417
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   418
                # convert hex type
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   419
                sub_idx = "0x" + sub_idx
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   420
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   421
                if type == "octet_string":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   422
                    hex_val = ' ---- '
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   423
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   424
                # SResult of SlaveSDO data parsing. (data type : dictionary)
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   425
                self.Data = {'idx': idx.strip(), 'subIdx': sub_idx.strip(), 'access': access.strip(),
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   426
                             'type': type.strip(), 'size': size.strip(),  'name': name_after_check.strip("\""),
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   427
                             'value': hex_val.strip(), "category": title_name.strip("\"")}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   428
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   429
                category_divide_value = [0x1000, 0x2000, 0x6000, 0xa000, 0xffff]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   430
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   431
                for count in range(len(category_divide_value)):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   432
                    if int(idx, 0) < category_divide_value[count]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   433
                        self.Controler.CommonMethod.SaveSDOData[count].append(self.Data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   434
                        break
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   435
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   436
                self.Controler.CommonMethod.SaveSDOData[self.AllSDOData].append(self.Data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   437
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   438
            if count >= len(self.SDOs.splitlines()) / 2:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   439
                (keep_going, skip) = slaveSDO_progress.Update(count, "Please waiting a moment!!")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   440
            else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   441
                (keep_going, skip) = slaveSDO_progress.Update(count)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   442
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   443
            # If user click "Cancel" loop suspend immediately
2374
aed3ca79a10a clean etherlab: pep8, E712 comparison to True should be 'if cond is True:' or 'if cond:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2373
diff changeset
   444
            if not keep_going:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   445
                break
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   446
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   447
        slaveSDO_progress.Destroy()
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   448
        return keep_going
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   449
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   450
    def StringTest(self, check_string):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   451
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   452
        Test value 'name' is alphanumeric
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   453
        @param check_string : input data for check
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   454
        @return result : output data after check
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   455
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   456
        # string.printable is print this result
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   457
        # '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   458
        # !"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   459
        allow_range = string.printable
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   460
        result = check_string
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   461
        for i in range(0, len(check_string)):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   462
            # string.isalnum() is check whether string is alphanumeric or not
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   463
            if check_string[len(check_string)-1-i:len(check_string)-i] in allow_range:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   464
                result = check_string[:len(check_string) - i]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   465
                break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   466
        return result
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   467
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   468
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   469
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   470
#                    For SDO Notebook (divide category)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   471
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   472
class SDONoteBook(wx.Notebook):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   473
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   474
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   475
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   476
        @param parent: Reference to the parent SDOPanelClass class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   477
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   478
        """
2366
d635680e4c2c cleanup etherlab: pep8, E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2365
diff changeset
   479
        wx.Notebook.__init__(self, parent, id=-1, size=(850, 500))
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   480
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   481
        self.parent = parent
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   482
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   483
        self.CreateNoteBook()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   484
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   485
        self.Bind(wx.EVT_CHOICEBOOK_PAGE_CHANGED, self.OnPageChanged)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   486
        self.Bind(wx.EVT_CHOICEBOOK_PAGE_CHANGING, self.OnPageChanging)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   487
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   488
    def CreateNoteBook(self):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   489
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   490
        Create each NoteBook page, divided SDO index
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   491
        According to EtherCAT Communication(03/2011), 158p
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   492
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   493
        self.Data = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   494
        count = 1
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   495
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   496
        page_texts = [("all", self.parent.AllSDOData),
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   497
                      ("0x0000 - 0x0ff", self.parent.DatatypeDescription),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   498
                      ("0x1000 - 0x1fff", self.parent.CommunicationObject),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   499
                      ("0x2000 - 0x5fff", self.parent.ManufacturerSpecific),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   500
                      ("0x6000 - 0x9fff", self.parent.ProfileSpecific),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   501
                      ("0xa000 - 0xffff", self.parent.Reserved)]
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   502
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   503
        page_tooltip_string = ["SDO Index 0x0000 - 0x0fff : Data Type Description",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   504
                               "SDO Index 0x1000 - 0x1fff : Communication object",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   505
                               "SDO Index 0x2000 - 0x5fff : Manufacturer specific",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   506
                               "SDO Index 0x6000 - 0x9fff : Profile specific",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   507
                               "SDO Index 0xa000 - 0xffff : Reserved",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   508
                               "All SDO Object"]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   509
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   510
        self.DeleteAllPages()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   511
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   512
        for txt, count in page_texts:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   513
            self.Data = self.Controler.CommonMethod.SaveSDOData[count]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   514
            self.Win = SlaveSDOTable(self, self.Data)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   515
            self.AddPage(self.Win, txt)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   516
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   517
    def OnPageChanged(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   518
        old = event.GetOldSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   519
        new = event.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   520
        sel = self.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   521
        event.Skip()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   522
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   523
    def OnPageChanging(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   524
        old = event.GetOldSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   525
        new = event.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   526
        sel = self.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   527
        event.Skip()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   528
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
   529
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   530
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   531
#                    For SDO Grid (fill index, subindex, etc...)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   532
# -------------------------------------------------------------------------------
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   533
class SlaveSDOTable(wx.grid.Grid):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   534
    def __init__(self, parent, data):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   535
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   536
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   537
        @param parent: Reference to the parent SDOPanelClass class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   538
        @param data: SDO data after parsing "SDOParser" method
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   539
        """
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   540
        wx.grid.Grid.__init__(self, parent, -1, size=(830, 490),
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
   541
                              style=wx.EXPAND | wx.ALIGN_CENTRE_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   542
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   543
        self.Controler = parent.Controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   544
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   545
        self.SDOFlag = True
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   546
        if data is None:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   547
            self.SDOs = []
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   548
        else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   549
            self.SDOs = data
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   550
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   551
        self.CreateGrid(len(self.SDOs), 8)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   552
        SDOCellSize = [(0, 65), (1, 65), (2, 50), (3, 55),
2380
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
   553
                       (4, 40), (5, 200), (6, 250), (7, 85)]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   554
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   555
        for (index, size) in SDOCellSize:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   556
            self.SetColSize(index, size)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   557
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   558
        self.SetRowLabelSize(0)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   559
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   560
        SDOTableLabel = [(0, "Index"), (1, "Subindex"), (2, "Access"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   561
                         (3, "Type"), (4, "Size"), (5, "Category"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   562
                         (6, "Name"), (7, "Value")]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   563
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   564
        for (index, label) in SDOTableLabel:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   565
            self.SetColLabelValue(index, label)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   566
            self.SetColLabelAlignment(index, wx.ALIGN_CENTRE)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   567
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   568
        attr = wx.grid.GridCellAttr()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   569
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   570
        # for SDO download
2389
f86eefc8d378 clean etherlab: pylint, W0404 # reimported module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2386
diff changeset
   571
        self.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.SDOModifyDialog)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   572
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   573
        for i in range(7):
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   574
            self.SetColAttr(i, attr)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   575
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   576
        self.SetColLabelAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   577
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   578
        self.SetTableValue()
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   579
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   580
    def SetTableValue(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   581
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   582
        Cell is filled by new parsing data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   583
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   584
        sdo_list = ['idx', 'subIdx', 'access', 'type', 'size', 'category', 'name', 'value']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   585
        for row_idx in range(len(self.SDOs)):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   586
            for col_idx in range(len(self.SDOs[row_idx])):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   587
                self.SetCellValue(row_idx, col_idx, self.SDOs[row_idx][sdo_list[col_idx]])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   588
                self.SetReadOnly(row_idx, col_idx, True)
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   589
                if col_idx < 5:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   590
                    self.SetCellAlignment(row_idx, col_idx, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   591
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   592
    def CheckSDODataAccess(self, row):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   593
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   594
        CheckSDODataAccess method is checking that access data has "w"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   595
        Access field consist 6 char, if mean
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   596
           rw      rw     rw
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   597
        (preop) (safeop) (op)
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   598
        Example Access field : rwrwrw, rwrw--
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   599
        @param row : Selected cell by user
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   600
        @return Write_flag : If data has "w", flag is true
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   601
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   602
        write_flag = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   603
        check = self.SDOs[row]['access']
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   604
        if check[1:2] == 'w':
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   605
            self.Controler.CommonMethod.Check_PREOP = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   606
            write_flag = True
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   607
        if check[3:4] == 'w':
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   608
            self.Controler.CommonMethod.Check_SAFEOP = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   609
            write_flag = True
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   610
        if check[5:] == 'w':
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   611
            self.Controler.CommonMethod.Check_OP = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   612
            write_flag = True
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   613
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   614
        return write_flag
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   615
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   616
    def DecideSDODownload(self, state):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   617
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   618
        compare current state and "access" field,
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   619
        result notify SDOModifyDialog method
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   620
        @param state : current slave state
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   621
        @return True or False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   622
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   623
        # Example of 'state' parameter : "0  0:0  PREOP  +  EL9800 (V4.30) (PIC24, SPI, ET1100)"
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   624
        state = state[self.Controler.GetSlavePos()].split("  ")[2]
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   625
        if state == "PREOP" and self.Controler.CommonMethod.Check_PREOP:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   626
            return True
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   627
        elif state == "SAFEOP" and self.Controler.CommonMethod.Check_SAFEOP:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   628
            return True
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   629
        elif state == "OP" and self.Controler.CommonMethod.Check_OP:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   630
            return True
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   631
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   632
        return False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   633
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   634
    def ClearStateFlag(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   635
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   636
        Initialize StateFlag
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   637
        StateFlag is notice SDOData access each slave state
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   638
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   639
        self.Controler.CommonMethod.Check_PREOP = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   640
        self.Controler.CommonMethod.Check_SAFEOP = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   641
        self.Controler.CommonMethod.Check_OP = False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   642
2382
e783c6beacf1 clean etherlab: pep8, E211 whitespace before '['
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   643
    def SDOModifyDialog(self, event):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   644
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   645
        Create dialog for SDO value modify
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   646
        if user enter data, perform command "ethercat download"
2389
f86eefc8d378 clean etherlab: pylint, W0404 # reimported module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2386
diff changeset
   647
        @param event : wx.grid.EVT_GRID_CELL_LEFT_DCLICK object
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   648
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   649
        self.ClearStateFlag()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   650
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   651
        # CheckSDODataAccess is checking that OD(Object Dictionary) has "w"
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   652
        if event.GetCol() == 7 and self.CheckSDODataAccess(event.GetRow()):
2382
e783c6beacf1 clean etherlab: pep8, E211 whitespace before '['
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   653
            dlg = wx.TextEntryDialog(
e783c6beacf1 clean etherlab: pep8, E211 whitespace before '['
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   654
                self,
e783c6beacf1 clean etherlab: pep8, E211 whitespace before '['
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   655
                _("Enter hex or dec value (if enter dec value, it automatically conversed hex value)"),
e783c6beacf1 clean etherlab: pep8, E211 whitespace before '['
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   656
                "SDOModifyDialog",
e783c6beacf1 clean etherlab: pep8, E211 whitespace before '['
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   657
                style=wx.OK | wx.CANCEL)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   658
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   659
            start_value = self.GetCellValue(event.GetRow(), event.GetCol())
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   660
            dlg.SetValue(start_value)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   661
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   662
            if dlg.ShowModal() == wx.ID_OK:
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   663
                try:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   664
                    int(dlg.GetValue(), 0)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   665
                    # check "Access" field
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   666
                    if self.DecideSDODownload(self.Controler.CommonMethod.SlaveState[self.Controler.GetSlavePos()]):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   667
                        # Request "SDODownload"
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   668
                        self.Controler.CommonMethod.SDODownload(
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   669
                            self.SDOs[event.GetRow()]['type'],
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   670
                            self.SDOs[event.GetRow()]['idx'],
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   671
                            self.SDOs[event.GetRow()]['subIdx'],
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   672
                            dlg.GetValue())
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   673
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   674
                        self.SetCellValue(event.GetRow(), event.GetCol(), hex(int(dlg.GetValue(), 0)))
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   675
                    else:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   676
                        self.Controler.CommonMethod.CreateErrorDialog('You cannot SDO download this state')
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   677
                # Error occured process of "int(variable)"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   678
                # User input is not hex, dec value
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   679
                except ValueError:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   680
                    self.Controler.CommonMethod.CreateErrorDialog('You can input only hex, dec value')
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   681
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   682
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   683
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   684
#                 For PDO Monitoring Panel
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   685
# PDO Class UI  : Panel -> Choicebook (RxPDO, TxPDO) ->
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   686
#                 Notebook (PDO Index) -> Grid (PDO entry)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   687
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   688
class PDOPanelClass(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   689
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   690
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   691
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   692
        @param parent: Reference to the parent EtherCATManagementTreebook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   693
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   694
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   695
        wx.Panel.__init__(self, parent, -1)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   696
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   697
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   698
        self.PDOMonitoringEditorMainSizer = wx.BoxSizer(wx.VERTICAL)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   699
        self.PDOMonitoringEditorInnerMainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   700
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   701
        self.CallPDOChoicebook = PDOChoicebook(self, controler=self.Controler)
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   702
        self.PDOMonitoringEditorInnerMainSizer.Add(self.CallPDOChoicebook, wx.ALL)
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   703
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   704
        self.PDOMonitoringEditorMainSizer.Add(self.PDOMonitoringEditorInnerMainSizer)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   705
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   706
        self.SetSizer(self.PDOMonitoringEditorMainSizer)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   707
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   708
    def PDOInfoUpdate(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   709
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   710
        Call RequestPDOInfo method and create Choicebook
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   711
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   712
        self.Controler.CommonMethod.RequestPDOInfo()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   713
        self.CallPDOChoicebook.Destroy()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   714
        self.CallPDOChoicebook = PDOChoicebook(self, controler=self.Controler)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   715
        self.Refresh()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   716
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   717
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   718
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   719
#                    For PDO Choicebook (divide Tx, Rx PDO)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   720
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   721
class PDOChoicebook(wx.Choicebook):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   722
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   723
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   724
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   725
        @param parent: Reference to the parent PDOPanelClass class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   726
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   727
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   728
        wx.Choicebook.__init__(self, parent, id=-1, size=(500, 500), style=wx.CHB_DEFAULT)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   729
        self.Controler = controler
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   730
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   731
        RxWin = PDONoteBook(self, controler=self.Controler, name="Rx")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   732
        TxWin = PDONoteBook(self, controler=self.Controler, name="Tx")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   733
        self.AddPage(RxWin, "RxPDO")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   734
        self.AddPage(TxWin, "TxPDO")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   735
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   736
        self.Bind(wx.EVT_CHOICEBOOK_PAGE_CHANGED, self.OnPageChanged)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   737
        self.Bind(wx.EVT_CHOICEBOOK_PAGE_CHANGING, self.OnPageChanging)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   738
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   739
    def OnPageChanged(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   740
        old = event.GetOldSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   741
        new = event.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   742
        sel = self.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   743
        event.Skip()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   744
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   745
    def OnPageChanging(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   746
        old = event.GetOldSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   747
        new = event.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   748
        sel = self.GetSelection()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   749
        event.Skip()
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   750
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   751
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   752
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   753
#                    For PDO Notebook (divide PDO index)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   754
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   755
class PDONoteBook(wx.Notebook):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   756
    def __init__(self, parent, name, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   757
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   758
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   759
        @param parent: Reference to the parent PDOChoicebook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   760
        @param name: identifier whether RxPDO or TxPDO
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   761
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   762
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   763
        wx.Notebook.__init__(self, parent, id=-1, size=(640, 400))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   764
        self.Controler = controler
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   765
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   766
        count = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   767
        page_texts = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   768
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   769
        self.Controler.CommonMethod.RequestPDOInfo()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   770
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   771
        if name == "Tx":
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   772
            # obtain pdo_info and pdo_entry
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   773
            # pdo_info include (PDO index, name, number of entry)
2373
73d35ba8f982 clean etherlab: pep8, E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2369
diff changeset
   774
            pdo_info = self.Controler.CommonMethod.GetTxPDOCategory()
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   775
            pdo_entry = self.Controler.CommonMethod.GetTxPDOInfo()
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   776
            for tmp in pdo_info:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   777
                title = str(hex(tmp['pdo_index']))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   778
                page_texts.append(title)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   779
        # RX PDO case
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   780
        else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   781
            pdo_info = self.Controler.CommonMethod.GetRxPDOCategory()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   782
            pdo_entry = self.Controler.CommonMethod.GetRxPDOInfo()
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   783
            for tmp in pdo_info:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   784
                title = str(hex(tmp['pdo_index']))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   785
                page_texts.append(title)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   786
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   787
        # Add page depending on the number of pdo_info
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   788
        for txt in page_texts:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   789
            win = PDOEntryTable(self, pdo_info, pdo_entry, count)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   790
            self.AddPage(win, txt)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   791
            count += 1
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   792
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   793
        self.Bind(wx.EVT_CHOICEBOOK_PAGE_CHANGED, self.OnPageChanged)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   794
        self.Bind(wx.EVT_CHOICEBOOK_PAGE_CHANGING, self.OnPageChanging)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   795
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   796
    def OnPageChanged(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   797
        old = event.GetOldSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   798
        new = event.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   799
        sel = self.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   800
        event.Skip()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   801
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   802
    def OnPageChanging(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   803
        old = event.GetOldSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   804
        new = event.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   805
        sel = self.GetSelection()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   806
        event.Skip()
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   807
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   808
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   809
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   810
#                    For PDO Grid (fill entry index, subindex etc...)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   811
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   812
class PDOEntryTable(wx.grid.Grid):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   813
    def __init__(self, parent, info, entry, count):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   814
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   815
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   816
        @param parent: Reference to the parent PDONoteBook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   817
        @param info : data structure including entry index, sub index, name, length, type
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   818
        @param entry : data structure including index, name, entry number
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   819
        @param count : page number
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   820
        """
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   821
        wx.grid.Grid.__init__(self, parent, -1, size=(500, 400), pos=wx.Point(0, 0),
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
   822
                              style=wx.EXPAND | wx.ALIGN_CENTRE_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   823
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   824
        self.Controler = parent.Controler
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   825
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   826
        self.PDOInfo = info
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   827
        self.PDOEntry = entry
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   828
        self.Count = count
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   829
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   830
        self.CreateGrid(self.PDOInfo[self.Count]['number_of_entry'], 5)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   831
        self.SetColLabelSize(25)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   832
        self.SetRowLabelSize(0)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   833
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   834
        PDOTableLabel = [(0, "Index"), (1, "Subindex"), (2, "Length"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   835
                         (3, "Type"), (4, "Name")]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   836
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   837
        for (index, label) in PDOTableLabel:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   838
            self.SetColLabelValue(index, label)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   839
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   840
        PDOCellSize = [(0, 45), (1, 65), (2, 55), (3, 40), (4, 300)]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   841
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   842
        for (index, size) in PDOCellSize:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   843
            self.SetColSize(index, size)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   844
            self.SetColLabelAlignment(index, wx.ALIGN_LEFT)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   845
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   846
        attr = wx.grid.GridCellAttr()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   847
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   848
        for i in range(5):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   849
            self.SetColAttr(i, attr)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   850
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   851
        self.SetTableValue()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   852
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   853
    def SetTableValue(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   854
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   855
        Cell is filled by new parsing data in XML
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   856
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   857
        list_index = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   858
        # number of entry
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   859
        for i in range(self.Count + 1):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   860
            list_index += self.PDOInfo[i]['number_of_entry']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   861
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   862
        start_value = list_index - self.PDOInfo[self.Count]['number_of_entry']
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   863
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   864
        pdo_list = ['entry_index', 'subindex', 'bitlen', 'type', 'name']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   865
        for row_idx in range(self.PDOInfo[self.Count]['number_of_entry']):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   866
            for col_idx in range(len(self.PDOEntry[row_idx])):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   867
                # entry index is converted hex value.
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   868
                if col_idx == 0:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   869
                    self.SetCellValue(row_idx, col_idx, hex(self.PDOEntry[start_value][pdo_list[col_idx]]))
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   870
                else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   871
                    self.SetCellValue(row_idx, col_idx, str(self.PDOEntry[start_value][pdo_list[col_idx]]))
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   872
                if col_idx != 4:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   873
                    self.SetCellAlignment(row_idx, col_idx, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   874
                else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   875
                    self.SetCellAlignment(row_idx, col_idx, wx.ALIGN_LEFT, wx.ALIGN_CENTRE)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   876
                self.SetReadOnly(row_idx, col_idx, True)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   877
                self.SetRowSize(row_idx, 25)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   878
            start_value += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   879
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   880
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   881
# -------------------------------------------------------------------------------
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   882
#                    For EEPROM Access Main Panel
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   883
#                 (This class explain EEPROM Access)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   884
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   885
class EEPROMAccessPanel(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   886
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   887
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   888
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   889
        @param parent: Reference to the parent EtherCATManagementTreebook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   890
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   891
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   892
        wx.Panel.__init__(self, parent, -1)
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   893
        sizer = wx.FlexGridSizer(cols=1, hgap=20, rows=3, vgap=20)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   894
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   895
        line = wx.StaticText(self, -1, "\n  EEPROM Access is composed to SmartView and HexView. \
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   896
                                              \n\n   - SmartView shows Config Data, Device Identity, Mailbox settings, etc. \
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   897
                                              \n\n   - HexView shows EEPROM's contents.")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   898
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   899
        sizer.Add(line)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   900
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   901
        self.SetSizer(sizer)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   902
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   903
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   904
# -------------------------------------------------------------------------------
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   905
#                    For Smart View Panel
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   906
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   907
class SlaveSiiSmartView(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   908
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   909
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   910
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   911
        @param parent: Reference to the parent EtherCATManagementTreebook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   912
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   913
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   914
        wx.Panel.__init__(self, parent, -1)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   915
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   916
        self.Controler = controler
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   917
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   918
        self.PDIType = {
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   919
            0: ['none', '00000000'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   920
            4: ['Digital I/O', '00000100'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   921
            5: ['SPI Slave', '00000101'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   922
            7: ['EtherCAT Bridge (port3)', '00000111'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   923
            8: ['uC async. 16bit', '00001000'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   924
            9: ['uC async. 8bit', '00001001'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   925
            10: ['uC sync. 16bit', '00001010'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   926
            11: ['uC sync. 8bit', '00001011'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   927
            16: ['32 Digtal Input and 0 Digital Output', '00010000'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   928
            17: ['24 Digtal Input and 8 Digital Output', '00010001'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   929
            18: ['16 Digtal Input and 16 Digital Output', '00010010'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   930
            19: ['8 Digtal Input and 24 Digital Output', '00010011'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   931
            20: ['0 Digtal Input and 32 Digital Output', '00010100'],
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   932
            128: ['On-chip bus', '11111111']
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   933
        }
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   934
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   935
        sizer = wx.FlexGridSizer(cols=1, hgap=5, rows=2, vgap=5)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   936
        button_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=5)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   937
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   938
        for button, mapping_method in [("Write EEPROM", self.WriteToEEPROM),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   939
                                       ("Read EEPROM", self.ReadFromEEPROM)]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   940
            btn = wx.Button(self, -1, button, size=(150, 40))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   941
            button_sizer.Add(btn, border=10, flag=wx.ALL)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   942
            btn.Bind(wx.EVT_BUTTON, mapping_method)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   943
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   944
        self.TreeListCtrl = SmartViewTreeListCtrl(self, self.Controler)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   945
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   946
        sizer.Add(button_sizer, border=10, flag=wx.ALL)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   947
        sizer.Add(self.TreeListCtrl, border=10, flag=wx.ALL)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   948
        self.SetSizer(sizer)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   949
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   950
        self.Create_SmartView()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   951
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   952
    def Create_SmartView(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   953
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   954
        SmartView shows information based on XML as initial value.
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   955
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   956
        self.Controler.CommonMethod.SmartViewInfosFromXML = self.Controler.CommonMethod.GetSmartViewInfos()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   957
        self.SetXMLData()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   958
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   959
    def WriteToEEPROM(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   960
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   961
        Open binary file (user select) and write the selected binary data to EEPROM
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   962
        @param event : wx.EVT_BUTTON object
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   963
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   964
        # Check whether beremiz connected or not, and whether status is "Started" or not.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   965
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   966
        if check_connect_flag:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   967
            status, count = self.Controler.GetCTRoot()._connector.GetPLCstatus()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   968
            if status is not "Started":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   969
                dialog = wx.FileDialog(self, _("Choose a binary file"), os.getcwd(), "",  _("bin files (*.bin)|*.bin"), wx.OPEN)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   970
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   971
                if dialog.ShowModal() == wx.ID_OK:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   972
                    filepath = dialog.GetPath()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   973
                    try:
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   974
                        binfile = open(filepath, "rb")
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   975
                        self.SiiBinary = binfile.read()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   976
                        dialog.Destroy()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   977
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   978
                        self.Controler.CommonMethod.SiiWrite(self.SiiBinary)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   979
                        # refresh data structure kept by master
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   980
                        self.Controler.CommonMethod.Rescan()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   981
                        # save binary data as inner global data of beremiz
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   982
                        # for fast loading when slave plugin node is reopened.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   983
                        self.Controler.CommonMethod.SiiData = self.SiiBinary
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   984
                        self.SetEEPROMData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   985
                    except Exception:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   986
                        self.Controler.CommonMethod.CreateErrorDialog('The file does not exist!')
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   987
                        dialog.Destroy()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   988
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   989
    def ReadFromEEPROM(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   990
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   991
        Refresh displayed data based on slave EEPROM and save binary file through dialog
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   992
        @param event : wx.EVT_BUTTON object
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   993
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   994
        # Check whether beremiz connected or not.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   995
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   996
        if check_connect_flag:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   997
            self.SiiBinary = self.Controler.CommonMethod.LoadData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   998
            self.SetEEPROMData()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   999
            dialog = wx.FileDialog(self, _("Save as..."), os.getcwd(),
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1000
                                   "slave0.bin",  _("bin files (*.bin)|*.bin|All files|*.*"),
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
  1001
                                   wx.SAVE | wx.OVERWRITE_PROMPT)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1002
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1003
            if dialog.ShowModal() == wx.ID_OK:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1004
                filepath = dialog.GetPath()
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1005
                binfile = open(filepath, "wb")
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1006
                binfile.write(self.SiiBinary)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1007
                binfile.close()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1008
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1009
            dialog.Destroy()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1010
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1011
    def SetXMLData(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1012
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1013
        Set data based on XML initially
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1014
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1015
        # Config Data: EEPROM Size, PDI Type, Device Emulation
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1016
        # Find PDI Type in pdiType dictionary
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1017
        cnt_pdi_type = self.Controler.CommonMethod.SmartViewInfosFromXML["pdi_type"]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1018
        for i in self.PDIType.keys():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1019
            if cnt_pdi_type == i:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1020
                cnt_pdi_type = self.PDIType[i][0]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1021
                break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1022
        #  Set Config Data
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1023
        for treelist, data in [("EEPROM Size (Bytes)",
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1024
                                str(self.Controler.CommonMethod.SmartViewInfosFromXML["eeprom_size"])),
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1025
                               ("PDI Type",
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1026
                                cnt_pdi_type),
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1027
                               ("Device Emulation",
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1028
                                self.Controler.CommonMethod.SmartViewInfosFromXML["device_emulation"])]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1029
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.ConfigData[treelist], data, 1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1030
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1031
        # Device Identity: Vendor ID, Product Code, Revision No., Serial No.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1032
        #  Set Device Identity
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1033
        for treelist, data in [("Vendor ID", self.Controler.CommonMethod.SmartViewInfosFromXML["vendor_id"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1034
                               ("Product Code", self.Controler.CommonMethod.SmartViewInfosFromXML["product_code"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1035
                               ("Revision No.", self.Controler.CommonMethod.SmartViewInfosFromXML["revision_no"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1036
                               ("Serial No.", self.Controler.CommonMethod.SmartViewInfosFromXML["serial_no"])]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1037
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.DeviceIdentity[treelist], data, 1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1038
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1039
        # Mailbox: Supported Mailbox, Bootstrap Configuration, Standard Configuration
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1040
        #  Set Mailbox
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1041
        for treelist, data in [("Supported Mailbox", self.Controler.CommonMethod.SmartViewInfosFromXML["supported_mailbox"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1042
                               ("Bootstrap Configuration", ""),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1043
                               ("Standard Configuration", "")]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1044
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.Mailbox[treelist], data, 1)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1045
        #  Set Bootstrap Configuration: Receive Offset, Receive Size, Send Offset, Send Size
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1046
        for treelist, data in [("Receive Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_outstart"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1047
                               ("Receive Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_outlength"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1048
                               ("Send Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_instart"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1049
                               ("Send Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_inlength"])]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1050
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.BootstrapConfig[treelist], data, 1)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1051
        #  Set Standard Configuration: Receive Offset, Receive Size, Send Offset, Send Size
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1052
        for treelist, data in [("Receive Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_outstart"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1053
                               ("Receive Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_outlength"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1054
                               ("Send Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_instart"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1055
                               ("Send Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_inlength"])]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1056
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.StandardConfig[treelist], data, 1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1057
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1058
    def SetEEPROMData(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1059
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1060
        Set data based on slave EEPROM.
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1061
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1062
        # sii_dict = { Parameter : (WordAddress, WordSize) }
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2364
diff changeset
  1063
        sii_dict = {
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1064
            'PDIControl':                          ('0', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1065
            'PDIConfiguration':                    ('1', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1066
            'PulseLengthOfSYNCSignals':            ('2', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1067
            'ExtendedPDIConfiguration':            ('3', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1068
            'ConfiguredStationAlias':              ('4', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1069
            'Checksum':                            ('7', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1070
            'VendorID':                            ('8', 2),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1071
            'ProductCode':                         ('a', 2),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1072
            'RevisionNumber':                      ('c', 2),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1073
            'SerialNumber':                        ('e', 2),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1074
            'Execution Delay':                     ('10', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1075
            'Port0Delay':                          ('11', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1076
            'Port1Delay':                          ('12', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1077
            'BootstrapReceiveMailboxOffset':       ('14', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1078
            'BootstrapReceiveMailboxSize':         ('15', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1079
            'BootstrapSendMailboxOffset':          ('16', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1080
            'BootstrapSendMailboxSize':            ('17', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1081
            'StandardReceiveMailboxOffset':        ('18', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1082
            'StandardReceiveMailboxSize':          ('19', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1083
            'StandardSendMailboxOffset':           ('1a', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1084
            'StandardSendMailboxSize':             ('1b', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1085
            'MailboxProtocol':                     ('1c', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1086
            'Size':                                ('3e', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1087
            'Version':                             ('3f', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1088
            'First Category Type/Vendor Specific': ('40', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1089
            'Following Category Word Size':        ('41', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1090
            'Category Data':                       ('42', 1),
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2364
diff changeset
  1091
        }
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1092
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1093
        # Config Data: EEPROM Size, PDI Type, Device Emulation
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1094
        # EEPROM's data in address '0x003f' is Size of EEPROM in KBit-1
2369
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1095
        eeprom_size = str((int(self.GetWordAddressData(sii_dict.get('Size'), 10))+1)/8*1024)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1096
        # Find PDI Type in pdiType dictionary
2369
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1097
        cnt_pdi_type = int(self.GetWordAddressData(sii_dict.get('PDIControl'), 16).split('x')[1][2:4], 16)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1098
        for i in self.PDIType.keys():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1099
            if cnt_pdi_type == i:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1100
                cnt_pdi_type = self.PDIType[i][0]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1101
                break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1102
        #  Get Device Emulation
2369
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1103
        device_emulation = str(bool(int("{:0>16b}".format(int(self.GetWordAddressData(sii_dict.get('PDIControl'), 16), 16))[7])))
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1104
        #  Set Config Data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1105
        for treelist, data in [("EEPROM Size (Bytes)", eeprom_size),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1106
                               ("PDI Type", cnt_pdi_type),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1107
                               ("Device Emulation", device_emulation)]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1108
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.ConfigData[treelist], data, 1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1109
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1110
        # Device Identity: Vendor ID, Product Code, Revision No., Serial No.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1111
        #  Set Device Identity
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1112
        for treelist, data in [
2369
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1113
                ("Vendor ID", self.GetWordAddressData(sii_dict.get('VendorID'), 16)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1114
                ("Product Code", self.GetWordAddressData(sii_dict.get('ProductCode'), 16)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1115
                ("Revision No.", self.GetWordAddressData(sii_dict.get('RevisionNumber'), 16)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1116
                ("Serial No.", self.GetWordAddressData(sii_dict.get('SerialNumber'), 16))]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1117
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.DeviceIdentity[treelist], data, 1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1118
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1119
        # Mailbox
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1120
        # EEORPOM's word address '1c' indicates supported mailbox protocol.
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1121
        # each value of mailbox protocol :
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1122
        # VoE(0x0020), SoE(0x0010), FoE(0x0008), CoE(0x0004), EoE(0x0002), AoE(0x0001)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1123
        supported_mailbox = ""
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2364
diff changeset
  1124
        mailbox_protocol = ["VoE,  ", "SoE,  ", "FoE,  ", "CoE,  ", "EoE,  ", "AoE,  "]
2369
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1125
        mailbox_data = "{:0>8b}".format(int(self.GetWordAddressData(sii_dict.get('MailboxProtocol'), 16), 16))
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1126
        for protocol in range(6):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1127
            if mailbox_data[protocol+2] == '1':
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1128
                supported_mailbox += mailbox_protocol[protocol]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1129
        supported_mailbox = supported_mailbox.strip(",  ")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1130
        #  Set Mailbox
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1131
        for treelist, data in [("Supported Mailbox", supported_mailbox),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1132
                               ("Bootstrap Configuration", ""),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1133
                               ("Standard Configuration", "")]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1134
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.Mailbox[treelist], data, 1)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1135
        #  Set Bootstrap Configuration: Receive Offset, Receive Size, Send Offset, Send Size
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1136
        for treelist, data in [
2369
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1137
                ("Receive Offset", self.GetWordAddressData(sii_dict.get('BootstrapReceiveMailboxOffset'), 10)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1138
                ("Receive Size", self.GetWordAddressData(sii_dict.get('BootstrapReceiveMailboxSize'), 10)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1139
                ("Send Offset", self.GetWordAddressData(sii_dict.get('BootstrapSendMailboxOffset'), 10)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1140
                ("Send Size", self.GetWordAddressData(sii_dict.get('BootstrapSendMailboxSize'), 10))]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1141
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.BootstrapConfig[treelist], data, 1)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1142
        #  Set Standard Configuration: Receive Offset, Receive Size, Send Offset, Send Size
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1143
        for treelist, data in [
2369
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1144
                ("Receive Offset", self.GetWordAddressData(sii_dict.get('StandardReceiveMailboxOffset'), 10)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1145
                ("Receive Size", self.GetWordAddressData(sii_dict.get('StandardReceiveMailboxSize'), 10)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1146
                ("Send Offset", self.GetWordAddressData(sii_dict.get('StandardSendMailboxOffset'), 10)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1147
                ("Send Size", self.GetWordAddressData(sii_dict.get('StandardSendMailboxSize'), 10))]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1148
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.StandardConfig[treelist], data, 1)
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1149
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1150
    def MakeStaticBoxSizer(self, boxlabel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1151
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1152
        Make StaticBoxSizer
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1153
        @param boxlabel : label of box sizer
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1154
        @return sizer : the StaticBoxSizer labeled 'boxlabel'
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1155
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1156
        box = wx.StaticBox(self, -1, boxlabel)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1157
        sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1158
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1159
        return sizer
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1160
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1161
    def GetWordAddressData(self, dict_tuple, format):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1162
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1163
        This method converts word address data from EEPROM binary.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1164
        @param dict_tuple : element of 'sii_dict' dictionary in SetEEPROMData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1165
        @param format : format of data. It can be 16(hex), 10(decimal) and 2(binary).
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1166
        @return formatted value
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1167
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1168
        offset = int(str(dict_tuple[0]), 16) * 2
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1169
        length = int(str(dict_tuple[1]), 16) * 2
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1170
        list = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1171
        data = ''
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1172
        for index in range(length):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1173
            hexdata = hex(ord(self.SiiBinary[offset + index]))[2:]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1174
            list.append(hexdata.zfill(2))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1175
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1176
        list.reverse()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1177
        data = list[0:length]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1178
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1179
        if format == 16:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1180
            return '0x' + ''.join(data)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1181
        elif format == 10:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1182
            return str(int(str(''.join(data)), 16))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1183
        elif format == 2:
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1184
            ''.join(data)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1185
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1186
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1187
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1188
#                    For Smart View TreeListCtrl
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1189
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1190
class SmartViewTreeListCtrl(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1191
    def __init__(self, parent, Controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1192
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1193
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1194
        @param parent: Reference to the parent SlaveSiiSmartView class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1195
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1196
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1197
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1198
        wx.Panel.__init__(self, parent, -1, size=(350, 500))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1199
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1200
        self.Tree = wx.gizmos.TreeListCtrl(self, -1, size=(350, 500),
2386
d00f1430d57a clean etherlab: pep8, W503 line break before binary operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2385
diff changeset
  1201
                                           style=(wx.TR_DEFAULT_STYLE |
d00f1430d57a clean etherlab: pep8, W503 line break before binary operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2385
diff changeset
  1202
                                                  wx.TR_FULL_ROW_HIGHLIGHT |
d00f1430d57a clean etherlab: pep8, W503 line break before binary operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2385
diff changeset
  1203
                                                  wx.TR_HIDE_ROOT |
d00f1430d57a clean etherlab: pep8, W503 line break before binary operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2385
diff changeset
  1204
                                                  wx.TR_COLUMN_LINES |
d00f1430d57a clean etherlab: pep8, W503 line break before binary operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2385
diff changeset
  1205
                                                  wx.TR_ROW_LINES))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1206
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1207
        self.Tree.AddColumn("Description", width=200)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1208
        self.Tree.AddColumn("Value", width=140)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1209
        self.Tree.SetMainColumn(0)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1210
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1211
        self.Root = self.Tree.AddRoot("")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1212
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1213
        # Add item
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1214
        #  Level 1 nodes
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1215
        self.Level1Nodes = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1216
        for lv1 in ["Config Data", "Device Identity", "Mailbox"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1217
            self.Level1Nodes[lv1] = self.Tree.AppendItem(self.Root, lv1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1218
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1219
        #  Level 2 nodes
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1220
        #   Config Data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1221
        self.ConfigData = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1222
        for lv2 in ["EEPROM Size (Bytes)", "PDI Type", "Device Emulation"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1223
            self.ConfigData[lv2] = self.Tree.AppendItem(self.Level1Nodes["Config Data"], lv2)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1224
        #   Device Identity
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1225
        self.DeviceIdentity = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1226
        for lv2 in ["Vendor ID", "Product Code", "Revision No.", "Serial No."]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1227
            self.DeviceIdentity[lv2] = self.Tree.AppendItem(self.Level1Nodes["Device Identity"], lv2)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1228
        #   Mailbox
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1229
        self.Mailbox = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1230
        for lv2 in ["Supported Mailbox", "Bootstrap Configuration", "Standard Configuration"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1231
            self.Mailbox[lv2] = self.Tree.AppendItem(self.Level1Nodes["Mailbox"], lv2)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1232
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1233
        #  Level 3 nodes
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1234
        #   Children of Bootstrap Configuration
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1235
        self.BootstrapConfig = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1236
        for lv3 in ["Receive Offset", "Receive Size", "Send Offset", "Send Size"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1237
            self.BootstrapConfig[lv3] = self.Tree.AppendItem(self.Mailbox["Bootstrap Configuration"], lv3)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1238
        #   Children of Standard Configuration
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1239
        self.StandardConfig = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1240
        for lv3 in ["Receive Offset", "Receive Size", "Send Offset", "Send Size"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1241
            self.StandardConfig[lv3] = self.Tree.AppendItem(self.Mailbox["Standard Configuration"], lv3)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1242
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1243
        # Expand Tree
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1244
        for tree in [self.Root,
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1245
                     self.Level1Nodes["Config Data"],
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1246
                     self.Level1Nodes["Device Identity"],
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1247
                     self.Level1Nodes["Mailbox"],
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1248
                     self.Mailbox["Bootstrap Configuration"],
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1249
                     self.Mailbox["Standard Configuration"]]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1250
            self.Tree.Expand(tree)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1251
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1252
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1253
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1254
#                         For Hex View Panel
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1255
#            shows EEPROM binary as hex data and characters.
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1256
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1257
class HexView(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1258
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1259
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1260
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1261
        @param parent: Reference to the parent EtherCATManagementTreebook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1262
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1263
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1264
        wx.Panel.__init__(self, parent, -1)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1265
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1266
        self.Controler = controler
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1267
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1268
        self.HexRow = 8
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1269
        self.HexCol = 17
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1270
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1271
        self.HexViewSizer = {"view": wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1272
                             "siiButton": wx.BoxSizer()}
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1273
        self.HexViewButton = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1274
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
  1275
        for key, evt_handler in [
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
  1276
                ("Sii Upload", self.OnButtonSiiUpload),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
  1277
                ("Sii Download", self.OnButtonSiiDownload),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
  1278
                ("Write to File", self.OnButtonWriteToBinFile),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
  1279
                ("Read from File", self.OnButtonReadFromBinFile),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
  1280
                ("XML to EEPROM Image", self.OnButtonXmlToEEPROMImg)]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1281
            self.HexViewButton[key] = wx.Button(self, -1, key)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1282
            self.HexViewButton[key].Bind(wx.EVT_BUTTON, evt_handler)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1283
            self.HexViewSizer["siiButton"].Add(self.HexViewButton[key])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1284
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1285
        self.SiiBinary = self.Controler.CommonMethod.XmlToEeprom()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1286
        self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1287
        self.SiiGrid = SiiGridTable(self, self.Controler, self.HexRow, self.HexCol)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1288
        self.HexViewSizer["view"].AddMany([self.HexViewSizer["siiButton"], self.SiiGrid])
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1289
        self.SiiGrid.CreateGrid(self.HexRow, self.HexCol)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1290
        self.SetSizer(self.HexViewSizer["view"])
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1291
        self.HexViewSizer["view"].FitInside(self.parent.parent)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1292
        self.parent.parent.FitInside()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1293
        self.SiiGrid.SetValue(self.HexCode)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1294
        self.SiiGrid.Update()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1295
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1296
    def UpdateSiiGridTable(self, row, col):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1297
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1298
        Destroy existing grid and recreate
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1299
        @param row, col : Hex View grid size
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1300
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1301
        self.HexViewSizer["view"].Detach(self.SiiGrid)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1302
        self.SiiGrid.Destroy()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1303
        self.SiiGrid = SiiGridTable(self, self.Controler, row, col)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1304
        self.HexViewSizer["view"].Add(self.SiiGrid)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1305
        self.SiiGrid.CreateGrid(row, col)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1306
        self.SetSizer(self.HexViewSizer["view"])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1307
        self.HexViewSizer["view"].FitInside(self.parent.parent)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1308
        self.parent.parent.FitInside()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1309
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1310
    def OnButtonSiiUpload(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1311
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1312
        Load EEPROM data from slave and refresh Hex View grid
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1313
        Binded to 'Sii Upload' button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1314
        @param event : wx.EVT_BUTTON object
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1315
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1316
        # Check whether beremiz connected or not.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1317
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1318
        if check_connect_flag:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1319
            # load from EEPROM data and parsing
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1320
            self.SiiBinary = self.Controler.CommonMethod.LoadData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1321
            self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1322
            self.UpdateSiiGridTable(self.HexRow, self.HexCol)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1323
            self.SiiGrid.SetValue(self.HexCode)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1324
            self.SiiGrid.Update()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1325
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1326
    def OnButtonSiiDownload(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1327
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1328
        Write current EEPROM data to slave and refresh data structure kept by master
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1329
        Binded to 'Sii Download' button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1330
        @param event : wx.EVT_BUTTON object
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1331
        """
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1332
        # Check whether beremiz connected or not,
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1333
        # and whether status is "Started" or not.
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1334
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1335
        if check_connect_flag:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1336
            status, count = self.Controler.GetCTRoot()._connector.GetPLCstatus()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1337
            if status is not "Started":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1338
                self.Controler.CommonMethod.SiiWrite(self.SiiBinary)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1339
                self.Controler.CommonMethod.Rescan()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1340
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1341
    def OnButtonWriteToBinFile(self, event):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1342
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1343
        Save current EEPROM data to binary file through FileDialog
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1344
        Binded to 'Write to File' button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1345
        @param event : wx.EVT_BUTTON object
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1346
        """
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1347
        dialog = wx.FileDialog(self, _("Save as..."), os.getcwd(), "slave0.bin",
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
  1348
                               _("bin files (*.bin)|*.bin|All files|*.*"), wx.SAVE | wx.OVERWRITE_PROMPT)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1349
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1350
        if dialog.ShowModal() == wx.ID_OK:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1351
            filepath = dialog.GetPath()
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1352
            binfile = open(filepath, "wb")
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1353
            binfile.write(self.SiiBinary)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1354
            binfile.close()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1356
        dialog.Destroy()
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1357
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1358
    def OnButtonReadFromBinFile(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1359
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1360
        Load binary file through FileDialog
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1361
        Binded to 'Read from File' button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1362
        @param event : wx.EVT_BUTTON object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1363
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1364
        dialog = wx.FileDialog(self, _("Choose a binary file"), os.getcwd(), "",
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1365
                               _("bin files (*.bin)|*.bin"), wx.OPEN)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1366
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1367
        if dialog.ShowModal() == wx.ID_OK:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1368
            filepath = dialog.GetPath()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1369
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1370
            try:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1371
                binfile = open(filepath, "rb")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1372
                self.SiiBinary = binfile.read()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1373
                self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1374
                self.UpdateSiiGridTable(self.HexRow, self.HexCol)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1375
                self.SiiGrid.SetValue(self.HexCode)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1376
                self.SiiGrid.Update()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1377
            except Exception:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1378
                self.Controler.CommonMethod.CreateErrorDialog('The file does not exist!')
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1379
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1380
        dialog.Destroy()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1381
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1382
    def OnButtonXmlToEEPROMImg(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1383
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1384
        Create EEPROM data based XML data that current imported
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1385
        Binded to 'XML to EEPROM' button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1386
        @param event : wx.EVT_BUTTON object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1387
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1388
        self.SiiBinary = self.Controler.CommonMethod.XmlToEeprom()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1389
        self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1390
        self.UpdateSiiGridTable(self.HexRow, self.HexCol)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1391
        self.SiiGrid.SetValue(self.HexCode)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1392
        self.SiiGrid.Update()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1393
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1394
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1395
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1396
#                    For Hex View grid (fill hex data)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1397
# -------------------------------------------------------------------------------
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1398
class SiiGridTable(wx.grid.Grid):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1399
    def __init__(self, parent, controler, row, col):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1400
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1401
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1402
        @param parent: Reference to the parent HexView class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1403
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1404
        @param row, col: Hex View grid size
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1405
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1406
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1407
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1408
        self.Row = row
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1409
        self.Col = col
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1410
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1411
        wx.grid.Grid.__init__(self, parent, -1, size=(830, 450),
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
  1412
                              style=wx.ALIGN_CENTRE_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1413
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1414
    def SetValue(self, value):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1415
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1416
        Set data in the table
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1417
        @param value: EEPROM data list of which element is 1 Byte hex data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1418
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1419
        # set label name and size
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1420
        self.SetRowLabelSize(100)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1421
        for col in range(self.Col):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1422
            if col == 16:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1423
                self.SetColLabelValue(16, "Text View")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1424
                self.SetColSize(16, (self.GetSize().x-120)*4/20)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1425
            else:
2358
8e5a9830867e cleanup etherlab: pep8, E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
  1426
                self.SetColLabelValue(col, '%s' % col)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1427
                self.SetColSize(col, (self.GetSize().x-120)/20)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1428
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1429
        # set data into table
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1430
        row = col = 0
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1431
        for row_idx in value:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1432
            col = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1433
            self.SetRowLabelValue(row, "0x"+"{:0>4x}".format(row*(self.Col-1)))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1434
            for hex in row_idx:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1435
                self.SetCellValue(row, col, hex)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1436
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1437
                if col == 16:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1438
                    self.SetCellAlignment(row, col, wx.ALIGN_LEFT, wx.ALIGN_CENTER)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1439
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1440
                    self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTER)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1441
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1442
                self.SetReadOnly(row, col, True)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1443
                col = col + 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1444
            row = row + 1
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1445
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1446
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1447
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1448
#                    For Register Access Panel
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1449
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1450
class RegisterAccessPanel(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1451
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1452
        """
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1453
        Constructor
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1454
        @param parent: EEPROMAccessPanel object
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1455
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1456
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1457
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1458
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1459
        self.__init_data()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1460
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1461
        wx.Panel.__init__(self, parent, -1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1462
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1463
        sizer = wx.FlexGridSizer(cols=1, hgap=20, rows=2, vgap=5)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1464
        button_sizer = wx.FlexGridSizer(cols=2, hgap=10, rows=1, vgap=10)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1465
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1466
        self.ReloadButton = wx.Button(self, -1, "Reload")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1467
        self.CompactViewCheckbox = wx.CheckBox(self, -1, "Compact View")
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1468
        self.RegisterNotebook = RegisterNotebook(self, self.Controler)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1469
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1470
        button_sizer.AddMany([self.ReloadButton, self.CompactViewCheckbox])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1471
        sizer.AddMany([button_sizer, self.RegisterNotebook])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1472
        self.SetSizer(sizer)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1473
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1474
        self.ReloadButton.Bind(wx.EVT_BUTTON, self.OnReloadButton)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1475
        self.CompactViewCheckbox.Bind(wx.EVT_CHECKBOX, self.ToggleCompactViewCheckbox)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1476
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1477
        for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1478
            self.RegisterNotebook.RegPage[index].MainTable.CreateGrid(self.MainRow[index], self.MainCol)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1479
            self.RegisterNotebook.RegPage[index].MainTable.SetValue(self, 0, index*512, (index+1)*512)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1480
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1481
        # data default setting
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1482
        if self.Controler.CommonMethod.RegData == "":
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1483
            self.CompactViewCheckbox.Disable()
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1484
            for index in range(4):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1485
                self.RegisterNotebook.RegPage[index].MainTable.SetValue(self, 0, index*512, (index+1)*512)
2361
5d6ce74f7835 cleanup etherlab: pep8, E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
  1486
        else:  # If data was saved,
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1487
            self.BasicSetData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1488
            self.ParseData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1489
            for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1490
                self.RegisterNotebook.RegPage[index].MainTable.SetValue(self, self.RegMonitorData, index*512, (index+1)*512)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1491
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1492
    def __init_data(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1493
        """
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1494
        Declare initial data.
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1495
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1496
        # flag for compact view
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1497
        self.CompactFlag = False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1498
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1499
        # main grid의 rows and cols
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1500
        self.MainRow = [512, 512, 512, 512]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1501
        self.MainCol = 4
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1502
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1503
        # main grids' data range
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1504
        self.PageRange = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1505
        for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1506
            self.PageRange.append([512*index, 512*(index+1)])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1507
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1508
        #  Previous value of register data for register description configuration
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1509
        self.PreRegSpec = {"ESCType": "",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1510
                           "FMMUNumber": "",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1511
                           "SMNumber": "",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1512
                           "PDIType": ""}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1513
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1514
    def LoadData(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1515
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1516
        Get data from the register.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1517
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1518
        self.Controler.CommonMethod.RegData = ""
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1519
        # ethercat reg_read
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1520
        # ex : ethercat reg_read -p 0 0x0000 0x0001
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1521
        # return value : 0x11
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1522
        for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1523
            self.Controler.CommonMethod.RegData = self.Controler.CommonMethod.RegData + " " + self.Controler.CommonMethod.RegRead("0x"+"{:0>4x}".format(index*1024), "0x0400")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1524
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1525
        # store previous value
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1526
        # (ESC type, port number of FMMU, port number of SM, and PDI type))
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1527
        for reg_spec in ["ESCType", "FMMUNumber", "SMNumber", "PDIType"]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1528
            self.PreRegSpec[reg_spec] = self.Controler.CommonMethod.CrtRegSpec[reg_spec]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1529
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1530
        # update registers' description
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1531
        # (ESC type, port number of FMMU, port number of SM, and PDI type)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1532
        for reg_spec, address in [("ESCType", "0x0000"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1533
                                  ("FMMUNumber", "0x0004"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1534
                                  ("SMNumber", "0x0005"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1535
                                  ("PDIType", "0x0140")]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1536
            self.Controler.CommonMethod.CrtRegSpec[reg_spec] = self.Controler.CommonMethod.RegRead(address, "0x0001")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1537
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1538
        # Enable compactView checkbox
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1539
        self.CompactViewCheckbox.Enable()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1540
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1541
    def BasicSetData(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1542
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1543
        Get and save the description of registers.
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1544
        It's done by parsing register_information.xml.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1545
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1546
        # parse the above register's value
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1547
        # If the value is 0x12, the result is 12
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1548
        self.ESCType = self.Controler.CommonMethod.CrtRegSpec["ESCType"].split('x')[1]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1549
        self.PDIType = self.Controler.CommonMethod.CrtRegSpec["PDIType"].split('x')[1]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1550
        # If the value is 0x12, the result is 18 (It's converted to decimal value)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1551
        self.FMMUNumber = int(self.Controler.CommonMethod.CrtRegSpec["FMMUNumber"], 16)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1552
        self.SMNumber = int(self.Controler.CommonMethod.CrtRegSpec["SMNumber"], 16)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1553
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1554
        # initialize description dictionary of register main table and register sub table.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1555
        self.RegisterDescriptionDict = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1556
        self.RegisterSubGridDict = {}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1557
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1558
        # ./EthercatMaster/register_information.xml contains register description.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1559
        if wx.Platform == '__WXMSW__':
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1560
            reg_info_file = open("../../EthercatMaster/register_information.xml", 'r')
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1561
        else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1562
            reg_info_file = open("./EthercatMaster/register_information.xml", 'r')
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1563
        reg_info_tree = minidom.parse(reg_info_file)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1564
        reg_info_file.close()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1565
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1566
        # parse register description
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1567
        for register_info in reg_info_tree.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1568
            for register in register_info.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1569
                if register.nodeType == reg_info_tree.ELEMENT_NODE and register.nodeName == "Register":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1570
                    # If it depends on the property(ESC type, PDI type, FMMU number, SM number)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1571
                    for property, type, value in [("esc", "type", self.ESCType),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1572
                                                  ("pdi", "type", self.PDIType),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1573
                                                  ("fmmu", "number", self.FMMUNumber),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1574
                                                  ("sm", "number", self.SMNumber)]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1575
                        if property in register.attributes.keys():
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1576
                            if type == "type":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1577
                                if register.attributes[property].value == value:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1578
                                    self.GetRegisterInfo(reg_info_tree, register)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1579
                                    break
2361
5d6ce74f7835 cleanup etherlab: pep8, E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
  1580
                            else:  # type == "number"
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1581
                                if register.attributes[property].value < value:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1582
                                    self.GetRegisterInfo(reg_info_tree, register)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1583
                                    break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1584
                        else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1585
                            self.GetRegisterInfo(reg_info_tree, register)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1586
                            break
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1587
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1588
    def GetRegisterInfo(self, reg_info_tree, register):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1589
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1590
        Save the register's description into the dictionary.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1591
        reg_info_tree is based on the register_information.xml.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1592
        @param reg_info_tree: XML tree
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1593
        @param register: register which you want to get the description
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1594
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1595
        # temporary variables for register main table idescription dictionary
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1596
        reg_index = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1597
        reg_main_description = ""
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1598
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1599
        for data in register.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1600
            if data.nodeType == reg_info_tree.ELEMENT_NODE and data.nodeName == "Index":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1601
                for index in data.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1602
                    reg_index = index.nodeValue
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1603
            if data.nodeType == reg_info_tree.ELEMENT_NODE and data.nodeName == "Description":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1604
                for description in data.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1605
                    reg_main_description = description.nodeValue
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1606
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1607
            # Add description for register main table
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1608
            if reg_index is not "" and reg_main_description is not "":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1609
                self.RegisterDescriptionDict[reg_index] = reg_main_description
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1610
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1611
            if data.nodeType == reg_info_tree.ELEMENT_NODE and data.nodeName == "Details":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1612
                # declare register sub table description dictionary about this index
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1613
                self.RegisterSubGridDict[reg_index] = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1614
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1615
                for detail in data.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1616
                    if detail.nodeType == reg_info_tree.ELEMENT_NODE and detail.nodeName == "Detail":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1617
                        # If it depends on the property(ESC type, PDI type, FMMU number, SM number)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1618
                        for property, type, value in [("esc", "type", self.ESCType),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1619
                                                      ("pdi", "type", self.PDIType),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1620
                                                      ("fmmu", "number", self.FMMUNumber),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1621
                                                      ("sm", "number", self.SMNumber)]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1622
                            if property in detail.attributes.keys():
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1623
                                if type == "type":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1624
                                    if detail.attributes[property].value == value:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1625
                                        self.GetRegisterDetailInfo(reg_info_tree, reg_index, detail)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1626
                                        break
2361
5d6ce74f7835 cleanup etherlab: pep8, E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
  1627
                                else:  # type == "number"
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1628
                                    if detail.attributes[property].value < value:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1629
                                        self.GetRegisterDetailInfo(reg_info_tree, reg_index, detail)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1630
                                        break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1631
                            else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1632
                                self.GetRegisterDetailInfo(reg_info_tree, reg_index, detail)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1633
                                break
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1634
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1635
    def GetRegisterDetailInfo(self, reg_info_tree, reg_index, detail):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1636
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1637
        Get the resgister's detailed description(for sub table) from the reg_info_tree.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1638
        @param reg_info_tree: XML tree (register_information.xml)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1639
        @param reg_index: index of the register
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1640
        @param detail: description of the register
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1641
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1642
        # temporary variables for register sub table description dictionary
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1643
        # - It is initialized in every sub description
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1644
        reg_bit_range = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1645
        reg_sub_description = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1646
        reg_enum_dictionary = {}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1647
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1648
        for detail_data in detail.childNodes:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1649
            if detail_data.nodeType == reg_info_tree.ELEMENT_NODE and detail_data.nodeName == "Range":
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1650
                for range in detail_data.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1651
                    reg_bit_range = range.nodeValue
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1652
            if detail_data.nodeType == reg_info_tree.ELEMENT_NODE and detail_data.nodeName == "Description":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1653
                for description in detail_data.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1654
                    reg_sub_description = description.nodeValue
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1655
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1656
            if detail_data.nodeType == reg_info_tree.ELEMENT_NODE and detail_data.nodeName == "Enum":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1657
                for enum in detail_data.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1658
                    if enum.nodeType == reg_info_tree.ELEMENT_NODE and enum.nodeName == "item":
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1659
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1660
                        # temporary variables for a description of each value
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1661
                        # For example, if the bit is 1, it is 'enabled'('On', 'True', etc.),
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1662
                        # otherwise 'disabled'('Off', 'False', etc.).
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1663
                        reg_sub_value = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1664
                        reg_sub_value_description = ""
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1665
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1666
                        for item in enum.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1667
                            if item.nodeType == reg_info_tree.ELEMENT_NODE and item.nodeName == "value":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1668
                                for value in item.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1669
                                    reg_sub_value = value.nodeValue
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1670
                            if item.nodeType == reg_info_tree.ELEMENT_NODE and item.nodeName == "Description":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1671
                                for description in item.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1672
                                    reg_sub_value_description = description.nodeValue
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1673
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1674
                            # Add a description of each value to register enum dictionary
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1675
                            if reg_sub_value is not "" and reg_sub_value_description is not "":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1676
                                reg_enum_dictionary[reg_sub_value] = reg_sub_value_description
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1677
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1678
        # add a description to register sub table description dictionary
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1679
        if reg_bit_range is not "" and reg_sub_description is not "":
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1680
            self.RegisterSubGridDict[reg_index].append([reg_bit_range,
2380
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1681
                                                        reg_sub_description,
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1682
                                                        reg_enum_dictionary])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1683
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1684
    def ParseData(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1685
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1686
        Transform the data into dec, hex, string, and description
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1687
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1688
        row_data = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1689
        self.RegMonitorData = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1690
        reg_word = ""
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1691
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1692
        reg_data = self.Controler.CommonMethod.RegData.split()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1693
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1694
        # loop for register(0x0000:0x0fff)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1695
        for address in range(0x1000):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1696
            # arrange 2 Bytes of register data
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1697
            reg_word = reg_data[address].split('x')[1] + reg_word
2358
8e5a9830867e cleanup etherlab: pep8, E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
  1698
            if (address % 2) == 1:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1699
                # append address
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1700
                hex_address = "{:0>4x}".format(address-1)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1701
                row_data.append(hex_address)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1702
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1703
                # append description
2377
88a9d64560d3 clean etherlab: pep8, W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2375
diff changeset
  1704
                if hex_address in self.RegisterDescriptionDict:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1705
                    row_data.append(self.RegisterDescriptionDict[hex_address])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1706
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1707
                    row_data.append("")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1708
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1709
                # append Decimal value
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1710
                row_data.append(str(int(reg_word, 16)))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1711
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1712
                # append Hex value
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1713
                row_data.append('0x'+reg_word)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1714
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1715
                # append ASCII value
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1716
                char_data = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1717
                for iter in range(2):
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2364
diff changeset
  1718
                    if int(reg_word[iter*2:iter*2+2], 16) >= 32 and int(reg_word[iter*2:iter*2+2], 16) <= 126:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1719
                        char_data = char_data + chr(int(reg_word[iter*2:iter*2+2], 16))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1720
                    else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1721
                        char_data = char_data + "."
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1722
                row_data.append(char_data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1723
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1724
                self.RegMonitorData.append(row_data)
2361
5d6ce74f7835 cleanup etherlab: pep8, E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
  1725
                reg_word = ""  # initialize regWord
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1726
                row_data = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1727
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1728
    def OnReloadButton(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1729
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1730
        Handle the click event of the 'Reload' button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1731
        Get the data from registers again, and update the table.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1732
        @param event: wx.EVT_BUTTON object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1733
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1734
        # Check whether beremiz connected or not.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1735
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1736
        if check_connect_flag:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1737
            self.LoadData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1738
            self.BasicSetData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1739
            self.ParseData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1740
            # set data into UI
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1741
            if self.CompactFlag:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1742
                self.ToggleCompactViewCheckbox(True)
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1743
            else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1744
                for index in range(4):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1745
                    self.RegisterNotebook.RegPage[index].UpdateMainTable(self.MainRow[index], self.MainCol,
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1746
                                                                         self.PageRange[index][0], self.PageRange[index][1],
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1747
                                                                         self.RegMonitorData)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1748
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1749
    def ToggleCompactViewCheckbox(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1750
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1751
        Handles the event of the 'Compact view' check box.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1752
        If it's checked, show only the registers that have a description.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1753
        If not, show all the registers.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1754
        @param event: wx.EVT_CHECKBOX object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1755
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1756
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1757
        # If "Compact View" Checkbox is True
2385
f2a53fa6e5d7 clean etherlab: pep8, E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2384
diff changeset
  1758
        # 'event' is argument of this method or event of checkbox.
2374
aed3ca79a10a clean etherlab: pep8, E712 comparison to True should be 'if cond is True:' or 'if cond:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2373
diff changeset
  1759
        if event is True or event.GetEventObject().GetValue():
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1760
            self.CompactFlag = True
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1761
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1762
            reg_compact_data = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1763
            page_row = [0, 0, 0, 0]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1764
            for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1765
                self.PageRange[index] = [0, 0]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1766
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1767
            for reg_row_data in self.RegMonitorData:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1768
                if reg_row_data[1] is not "":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1769
                    # data structure for "compact view"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1770
                    reg_compact_data.append(reg_row_data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1771
                    # count for each register notebooks' row
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1772
                    # It compare with register's address.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1773
                    for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1774
                        if int('0x'+reg_row_data[0], 16) < (index+1)*1024:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1775
                            page_row[index] += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1776
                            break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1777
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1778
            # Setting tables' rows and cols, range for compact view
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1779
            for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1780
                self.MainRow[index] = page_row[index]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1781
                self.PageRange[index][1] = page_row[index]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1782
                for iter in range(index):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1783
                    self.PageRange[index][0] += page_row[iter]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1784
                    self.PageRange[index][1] += page_row[iter]
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1785
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1786
            # Update table
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1787
            for index in range(4):
2380
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1788
                self.RegisterNotebook.RegPage[index].UpdateMainTable(
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1789
                    self.MainRow[index],
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1790
                    self.MainCol,
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1791
                    self.PageRange[index][0],
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1792
                    self.PageRange[index][1],
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1793
                    reg_compact_data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1794
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1795
        # Compact View Checkbox is False
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1796
        else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1797
            self.CompactFlag = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1798
            # Setting original rows, cols and range
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1799
            self.MainRow = [512, 512, 512, 512]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1800
            self.PageRange = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1801
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1802
            for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1803
                self.PageRange.append([512*index, 512*(index+1)])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1804
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1805
            # Update table
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1806
            for index in range(4):
2380
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1807
                self.RegisterNotebook.RegPage[index].UpdateMainTable(
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1808
                    self.MainRow[index],
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1809
                    self.MainCol,
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1810
                    self.PageRange[index][0],
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1811
                    self.PageRange[index][1],
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1812
                    self.RegMonitorData)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1813
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1814
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1815
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1816
#                    For Register Access Notebook (divide index range)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1817
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1818
class RegisterNotebook(wx.Notebook):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1819
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1820
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1821
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1822
        @param parent: RegisterAccessPanel object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1823
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1824
        """
2366
d635680e4c2c cleanup etherlab: pep8, E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2365
diff changeset
  1825
        wx.Notebook.__init__(self, parent, id=-1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1826
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1827
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1828
        self.Controler = controler
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1829
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1830
        # Initialize pages
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1831
        self.RegPage = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1832
        for iter in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1833
            self.RegPage.append(None)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1834
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1835
        for index in range(4):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1836
            self.RegPage[index] = RegisterNotebookPanel(self, self.Controler,
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
  1837
                                                        parent.MainRow[index], parent.MainCol)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1838
            self.AddPage(self.RegPage[index],
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1839
                         "0x"+"{:0>4x}".format(index*1024)+" - 0x"+"{:0>4x}".format((index+1)*1024-1))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1840
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1841
        self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1842
        self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1843
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1844
    def OnPageChanged(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1845
        old = event.GetOldSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1846
        new = event.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1847
        sel = self.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1848
        event.Skip()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1849
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1850
    def OnPageChanging(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1851
        old = event.GetOldSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1852
        new = event.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1853
        sel = self.GetSelection()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1854
        event.Skip()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1855
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1856
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1857
# -------------------------------------------------------------------------------
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1858
#                    For Register Access Notebook Panel
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1859
#                  (Main UI : including main, sub table)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1860
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1861
class RegisterNotebookPanel(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1862
    def __init__(self, parent, controler, row, col):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1863
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1864
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1865
        @param parent: RegisterAccessPanel object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1866
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1867
        @param row, col: size of the table
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1868
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1869
        wx.Panel.__init__(self, parent, -1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1870
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1871
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1872
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1873
        self.Row = row
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1874
        self.Col = col
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1875
        sub_row = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1876
        sub_col = 4
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1877
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1878
        self.Sizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=30)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1879
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1880
        self.MainTable = RegisterMainTable(self, self.Row, self.Col, self.Controler)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1881
        self.SubTable = RegisterSubTable(self, sub_row, sub_col)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1882
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1883
        self.SubTable.CreateGrid(sub_row, sub_col)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1884
        self.SubTable.SetValue(self, [])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1885
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1886
        self.Sizer.AddMany([self.MainTable, self.SubTable])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1887
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1888
        self.SetSizer(self.Sizer)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1889
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1890
    def UpdateMainTable(self, row, col, low_index, high_index, data):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1891
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1892
        Updates main table.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1893
        It's done by deleting the main table and creating it again.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1894
        @param row, col: size of the table
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1895
        @param low_index: the lowest index of the page
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1896
        @param high_index: the highest index of the page
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1897
        @param data: data
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1898
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1899
        self.MainTable.Destroy()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1900
        self.MainTable = RegisterMainTable(self, row, col, self.Controler)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1901
        self.Sizer.Detach(self.SubTable)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1902
        self.Sizer.AddMany([self.MainTable, self.SubTable])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1903
        self.SetSizer(self.Sizer)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1904
        self.MainTable.CreateGrid(row, col)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1905
        self.MainTable.SetValue(self, data, low_index, high_index)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1906
        self.MainTable.Update()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1907
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1908
    def UpdateSubTable(self, row, col, data):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1909
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1910
        Updates sub table.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1911
        It's done by deleting the sub table and creating it again.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1912
        @param row, col: size of the table
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1913
        @param data: data
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1914
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1915
        self.SubTable.Destroy()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1916
        self.SubTable = RegisterSubTable(self, row, col)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1917
        self.Sizer.Detach(self.MainTable)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1918
        self.Sizer.AddMany([self.MainTable, self.SubTable])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1919
        self.Sizer.Layout()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1920
        self.SetSizer(self.Sizer)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1921
        self.SubTable.CreateGrid(row, col)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1922
        self.SubTable.SetValue(self, data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1923
        self.SubTable.Update()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1924
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1925
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1926
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1927
#                    For Register Access Notebook Panel (Main Table)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1928
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1929
class RegisterMainTable(wx.grid.Grid):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1930
    def __init__(self, parent, row, col, controler):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1931
        """
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1932
            Constructor
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1933
            @param parent: RegisterNotebook object
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1934
            @param row, col: size of the table
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1935
            @param controler: _EthercatSlaveCTN class in EthercatSlave.py
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1936
            """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1937
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1938
        self.Data = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1939
        self.Row = row
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1940
        self.Col = col
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1941
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1942
        self.RegisterAccessPanel = self.parent.parent.parent
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1943
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1944
        wx.grid.Grid.__init__(self, parent, -1, size=(820, 300),
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
  1945
                              style=wx.EXPAND | wx.ALIGN_CENTRE_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1946
2389
f86eefc8d378 clean etherlab: pylint, W0404 # reimported module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2386
diff changeset
  1947
        for evt, mapping_method in [(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnSelectCell),
f86eefc8d378 clean etherlab: pylint, W0404 # reimported module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2386
diff changeset
  1948
                                    (wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnSelectCell),
f86eefc8d378 clean etherlab: pylint, W0404 # reimported module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2386
diff changeset
  1949
                                    (wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.OnRegModifyDialog)]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1950
            self.Bind(evt, mapping_method)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1951
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1952
    def SetValue(self, parent, reg_monitor_data, low_index, high_index):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1953
        """
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1954
            Set the RegMonitorData into the main table.
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1955
            @param parent: RegisterNotebook object
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1956
            @param reg_monitor_data: data
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1957
            @param low_index: the lowest index of the page
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1958
            @param high_index: the highest index of the page
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1959
            """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1960
        self.RegMonitorData = reg_monitor_data
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1961
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1962
        # set label name and size
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1963
        register_maintable_label = [(0, "Description"), (1, "Dec"),
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1964
                                    (2, "Hex"), (3, "Char")]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1965
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1966
        for (index, label) in register_maintable_label:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1967
            self.SetColLabelValue(index, label)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1968
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1969
        self.SetColSize(0, 200)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1970
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1971
        # if reg_monitor_data is 0, it is initialization of register access.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1972
        if reg_monitor_data == 0:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1973
            return 0
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1974
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1975
        # set data into UI
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1976
        row = col = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1977
        for row_index in reg_monitor_data[low_index:high_index]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1978
            col = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1979
            self.SetRowLabelValue(row, row_index[0])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1980
            for data_index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1981
                self.SetCellValue(row, col, row_index[data_index+1])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1982
                self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTER)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1983
                self.SetReadOnly(row, col, True)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1984
                col = col + 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1985
            row = row + 1
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1986
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1987
    def OnSelectCell(self, event):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1988
        """
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1989
            Handles the event of the cell of the main table.
2389
f86eefc8d378 clean etherlab: pylint, W0404 # reimported module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2386
diff changeset
  1990
            @param event: wx.grid object (left click)
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1991
            """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1992
        # if reg_monitor_data is 0, it is initialization of register access.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1993
        if self.RegMonitorData == 0:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1994
            event.Skip()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1995
            return 0
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1996
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1997
        sub_row = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1998
        sub_col = 4
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1999
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2000
        address = self.GetRowLabelValue(event.GetRow())
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2001
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2002
        reg_sub_grid_data = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2003
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2004
        BIT_RANGE, NAME, DESCRIPTIONS = range(3)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2005
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2006
        # Check if this register's detail description is exist or not,
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2007
        # and create data structure for the detail description table ; sub grid
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2008
        if address in self.RegisterAccessPanel.RegisterSubGridDict:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2009
            for element in self.RegisterAccessPanel.RegisterSubGridDict[address]:
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2364
diff changeset
  2010
                row_data = []
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2011
                row_data.append(element[BIT_RANGE])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2012
                row_data.append(element[NAME])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2013
                bin_data = "{:0>16b}".format(int(self.GetCellValue(event.GetRow(), 1)))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2014
                value_range = element[BIT_RANGE].split('-')
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2015
                value = (bin_data[8:16][::-1]+bin_data[0:8][::-1])[int(value_range[0]):(int(value_range[-1])+1)][::-1]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2016
                row_data.append(str(int(('0b'+str(value)), 2)))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2017
                if value in element[DESCRIPTIONS]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2018
                    row_data.append(element[DESCRIPTIONS][value])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2019
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2020
                    row_data.append('')
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2021
                reg_sub_grid_data.append(row_data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2022
                sub_row = sub_row + 1
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2023
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2024
        self.parent.UpdateSubTable(sub_row, sub_col, reg_sub_grid_data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2025
        # event.Skip() updates UI of selecting cell
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2026
        event.Skip()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2027
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2028
    def OnRegModifyDialog(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2029
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2030
        Handle the event of the cell of the main table.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2031
        Display the window where the user modifies the value of the cell.
2389
f86eefc8d378 clean etherlab: pylint, W0404 # reimported module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2386
diff changeset
  2032
        @param event: wx.grid object (double click)
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2033
            """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2034
        # user can enter a value in case that user double-clicked 'Dec' or 'Hex' value.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2035
        if event.GetCol() == 1 or event.GetCol() == 2:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2036
            dlg = wx.TextEntryDialog(self, "Enter hex(0xnnnn) or dec(n) value",
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
  2037
                                     "Register Modify Dialog", style=wx.OK | wx.CANCEL)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2038
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2039
            # Setting value in initial dialog value
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2040
            start_value = self.GetCellValue(event.GetRow(), event.GetCol())
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2041
            dlg.SetValue(start_value)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2042
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2043
            if dlg.ShowModal() == wx.ID_OK:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2044
                try:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2045
                    # It int(input) success, this input is dev or hex value.
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2046
                    # Otherwise, it's error, so it goes except.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2047
                    int(dlg.GetValue(), 0)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2048
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2049
                    # reg_write
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2050
                    # ex) ethercat reg_write -p 0 -t uint16 0x0000 0x0000
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2051
                    return_val = self.Controler.CommonMethod.RegWrite('0x'+self.GetRowLabelValue(event.GetRow()), dlg.GetValue())
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2052
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2364
diff changeset
  2053
                    if len(return_val) == 0:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2054
                        # set dec
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2055
                        self.SetCellValue(event.GetRow(), 1, str(int(dlg.GetValue(), 0)))
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2056
                        # set hex
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2057
                        hex_data = '0x'+"{:0>4x}".format(int(dlg.GetValue(), 0))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2058
                        self.SetCellValue(event.GetRow(), 2, hex_data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2059
                        # set char
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2060
                        char_data = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2061
                        # If hex_data is been able to convert to ascii code, append ascii code.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2062
                        for iter in range(2):
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2364
diff changeset
  2063
                            if int(hex_data[(iter+1)*2:(iter+2)*2], 16) >= 32 and int(hex_data[(iter+1)*2:(iter+2)*2], 16) <= 126:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2064
                                char_data = char_data + chr(int(hex_data[(iter+1)*2:(iter+2)*2], 16))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2065
                            else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2066
                                char_data = char_data + "."
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2067
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2068
                        self.SetCellValue(event.GetRow(), 3, char_data)
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2069
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2070
                    else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2071
                        self.Controler.CommonMethod.CreateErrorDialog('You can\'t modify it. This register is read-only or it\'s not connected.')
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2072
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2073
                except ValueError:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2074
                    self.Controler.CommonMethod.CreateErrorDialog('You entered wrong value. You can enter dec or hex value only.')
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2075
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2076
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  2077
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2078
#                    For Register Access Notebook Panel (Sub Table)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  2079
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2080
class RegisterSubTable(wx.grid.Grid):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2081
    def __init__(self, parent, row, col):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2082
        """
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2083
         Constructor
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2084
         @param parent: RegisterNotebook object
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2085
         @param row, col: size of the table
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2086
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2087
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2088
        self.Data = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2089
        self.Row = row
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2090
        self.Col = col
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2091
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  2092
        wx.grid.Grid.__init__(self, parent, -1, size=(820, 150),
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
  2093
                              style=wx.EXPAND | wx.ALIGN_CENTRE_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2094
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2095
    def SetValue(self, parent, data):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2096
        """
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2097
            Set the data into the subtable.
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2098
            @param parent: RegisterNotebook object
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2099
            @param data: data
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2100
            """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2101
        # lset label name and size
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2102
        Register_SubTable_Label = [(0, "Bits"), (1, "Name"),
2380
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  2103
                                   (2, "Value"), (3, "Enum")]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2104
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2105
        for (index, label) in Register_SubTable_Label:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2106
            self.SetColLabelValue(index, label)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2107
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2108
        self.SetColSize(1, 200)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2109
        self.SetColSize(3, 200)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2110
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2111
        # set data into table
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2112
        row = col = 0
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2113
        for rowData in data:
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2114
            col = 0
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2115
            for element in rowData:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2116
                self.SetCellValue(row, col, element)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2117
                self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTER)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2118
                self.SetReadOnly(row, col, True)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2119
                col = col + 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2120
            row = row + 1
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2121
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2122
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  2123
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2124
#                    For Master State Panel
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  2125
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2126
class MasterStatePanelClass(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2127
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2128
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2129
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2130
        @param parent: wx.ScrollWindow object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2131
        @Param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2132
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2133
        wx.Panel.__init__(self, parent, -1, (0, 0),
2366
d635680e4c2c cleanup etherlab: pep8, E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2365
diff changeset
  2134
                          size=wx.DefaultSize, style=wx.SUNKEN_BORDER)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2135
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2136
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2137
        self.StaticBox = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2138
        self.StaticText = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2139
        self.TextCtrl = {}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2140
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2141
        # ----------------------- Main Sizer and Update Button --------------------------------------------
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  2142
        self.MasterStateSizer = {"main": wx.BoxSizer(wx.VERTICAL)}
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2143
        for key, attr in [
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2144
                ("innerMain",           [1, 10, 2, 10]),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2145
                ("innerTopHalf",        [2, 10, 1, 10]),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2146
                ("innerBottomHalf",     [2, 10, 1, 10]),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2147
                ("innerMasterState",    [2, 10, 3, 10]),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2148
                ("innerDeviceInfo",     [4, 10, 3, 10]),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2149
                ("innerFrameInfo",      [4, 10, 5, 10])]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2150
            self.MasterStateSizer[key] = wx.FlexGridSizer(cols=attr[0], hgap=attr[1], rows=attr[2], vgap=attr[3])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2151
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2152
        self.UpdateButton = wx.Button(self, label=_('Update'))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2153
        self.UpdateButton.Bind(wx.EVT_BUTTON, self.OnButtonClick)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2154
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2155
        for key, label in [
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2156
                ('masterState', 'EtherCAT Master State'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2157
                ('deviceInfo', 'Ethernet Network Card Information'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2158
                ('frameInfo', 'Network Frame Information')]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2159
            self.StaticBox[key] = wx.StaticBox(self, label=_(label))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2160
            self.MasterStateSizer[key] = wx.StaticBoxSizer(self.StaticBox[key])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2161
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2162
        # ----------------------- Master State -----------------------------------------------------------
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2163
        for key, label in [
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2164
                ('Phase', 'Phase:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2165
                ('Active', 'Active:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2166
                ('Slaves', 'Slave Count:')]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2167
            self.StaticText[key] = wx.StaticText(self, label=_(label))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2168
            self.TextCtrl[key] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2169
            self.MasterStateSizer['innerMasterState'].AddMany([self.StaticText[key], self.TextCtrl[key]])
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2170
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2171
        self.MasterStateSizer['masterState'].AddSizer(self.MasterStateSizer['innerMasterState'])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2172
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2173
        # ----------------------- Ethernet Network Card Information ---------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2174
        for key, label in [
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2175
                ('Main', 'MAC Address:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2176
                ('Link', 'Link State:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2177
                ('Tx frames', 'Tx Frames:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2178
                ('Rx frames', 'Rx Frames:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2179
                ('Lost frames', 'Lost Frames:')]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2180
            self.StaticText[key] = wx.StaticText(self, label=_(label))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2181
            self.TextCtrl[key] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2182
            self.MasterStateSizer['innerDeviceInfo'].AddMany([self.StaticText[key], self.TextCtrl[key]])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2183
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2184
        self.MasterStateSizer['deviceInfo'].AddSizer(self.MasterStateSizer['innerDeviceInfo'])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2185
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2186
        # ----------------------- Network Frame Information -----------------------------------------------
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2187
        for key, label in [
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2188
                ('Tx frame rate [1/s]', 'Tx Frame Rate [1/s]:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2189
                ('Rx frame rate [1/s]', 'Tx Rate [kByte/s]:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2190
                ('Loss rate [1/s]', 'Loss Rate [1/s]:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2191
                ('Frame loss [%]', 'Frame Loss [%]:')]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2192
            self.StaticText[key] = wx.StaticText(self, label=_(label))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2193
            self.MasterStateSizer['innerFrameInfo'].Add(self.StaticText[key])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2194
            self.TextCtrl[key] = {}
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2195
            for index in ['0', '1', '2']:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2196
                self.TextCtrl[key][index] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2197
                self.MasterStateSizer['innerFrameInfo'].Add(self.TextCtrl[key][index])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2198
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2199
        self.MasterStateSizer['frameInfo'].AddSizer(self.MasterStateSizer['innerFrameInfo'])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2200
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2201
        # --------------------------------- Main Sizer ----------------------------------------------------
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2202
        for key, sub, in [
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2203
            ('innerTopHalf', [
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2204
                    'masterState', 'deviceInfo']),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2205
            ('innerBottomHalf', [
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2206
                    'frameInfo']),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2207
            ('innerMain', [
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2208
                    'innerTopHalf', 'innerBottomHalf'])]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2209
            for key2 in sub:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2210
                self.MasterStateSizer[key].AddSizer(self.MasterStateSizer[key2])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2211
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2212
        self.MasterStateSizer['main'].AddSizer(self.UpdateButton)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2213
        self.MasterStateSizer['main'].AddSizer(self.MasterStateSizer['innerMain'])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2214
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2215
        self.SetSizer(self.MasterStateSizer['main'])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2216
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2217
    def OnButtonClick(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2218
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2219
        Handle the event of the 'Update' button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2220
        Update the data of the master state.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2221
        @param event: wx.EVT_BUTTON object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2222
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2223
        if self.Controler.GetCTRoot()._connector is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2224
            self.MasterState = self.Controler.CommonMethod.GetMasterState()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2225
            # Update each TextCtrl
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2226
            if self.MasterState:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2227
                for key in self.TextCtrl:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2228
                    if isinstance(self.TextCtrl[key], dict):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2229
                        for index in self.TextCtrl[key]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2230
                            self.TextCtrl[key][index].SetValue(self.MasterState[key][int(index)])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2231
                    else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2232
                        self.TextCtrl[key].SetValue(self.MasterState[key][0])
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  2233
        else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2234
            self.Controler.CommonMethod.CreateErrorDialog('PLC not connected!')