objdictgen/networkeditortemplate.py
author Laurent Bessard
Wed, 08 May 2013 09:14:59 +0200
changeset 784 8aefbd0d39ff
parent 780 884a60cbb83e
permissions -rw-r--r--
Fixed set usage in eds_utils
778
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
     1
import wx
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
     2
780
884a60cbb83e Fixed bug when importing NodeEditorTemplate
Laurent Bessard
parents: 778
diff changeset
     3
from nodeeditortemplate import NodeEditorTemplate
778
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
     4
from subindextable import *
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
     5
from commondialogs import *
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
     6
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
     7
[ID_NETWORKEDITNETWORKNODES,
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
     8
] = [wx.NewId() for _init_ctrls in range(1)]
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
     9
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    10
class NetworkEditorTemplate(NodeEditorTemplate):
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    11
    
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    12
    def _init_ctrls(self, prnt):
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    13
        self.NetworkNodes = wx.Notebook(id=ID_NETWORKEDITNETWORKNODES,
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    14
              name='NetworkNodes', parent=prnt, pos=wx.Point(0, 0),
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    15
              size=wx.Size(0, 0), style=wx.NB_LEFT)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    16
        self.NetworkNodes.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    17
              self.OnNodeSelectedChanged, id=ID_NETWORKEDITNETWORKNODES)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    18
    
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    19
    def __init__(self, manager, frame, mode_solo):
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    20
        self.NodeList = manager
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    21
        NodeEditorTemplate.__init__(self, self.NodeList.GetManager(), frame, mode_solo)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    22
    
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    23
    def GetCurrentNodeId(self):
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    24
        selected = self.NetworkNodes.GetSelection()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    25
        # At init selected = -1
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    26
        if selected > 0:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    27
            window = self.NetworkNodes.GetPage(selected)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    28
            return window.GetIndex()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    29
        else:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    30
            return 0
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    31
    
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    32
    def RefreshCurrentIndexList(self):
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    33
        selected = self.NetworkNodes.GetSelection()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    34
        if selected == 0:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    35
            window = self.NetworkNodes.GetPage(selected)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    36
            window.RefreshIndexList()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    37
        else:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    38
            pass
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    39
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    40
    def RefreshNetworkNodes(self):
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    41
        if self.NetworkNodes.GetPageCount() > 0:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    42
            self.NetworkNodes.DeleteAllPages()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    43
        if self.NodeList:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    44
            new_editingpanel = EditingPanel(self.NetworkNodes, self, self.Manager)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    45
            new_editingpanel.SetIndex(self.Manager.GetCurrentNodeID())
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    46
            self.NetworkNodes.AddPage(new_editingpanel, "")
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    47
            for idx in self.NodeList.GetSlaveIDs():
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    48
                new_editingpanel = EditingPanel(self.NetworkNodes, self, self.NodeList, False)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    49
                new_editingpanel.SetIndex(idx)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    50
                self.NetworkNodes.AddPage(new_editingpanel, "")
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    51
    
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    52
    def OnNodeSelectedChanged(self, event):
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    53
        if not self.Closing:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    54
            selected = event.GetSelection()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    55
            # At init selected = -1
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    56
            if selected >= 0:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    57
                window = self.NetworkNodes.GetPage(selected)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    58
                self.NodeList.SetCurrentSelected(window.GetIndex())
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    59
            wx.CallAfter(self.RefreshMainMenu)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    60
            wx.CallAfter(self.RefreshStatusBar)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    61
        event.Skip()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    62
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    63
#-------------------------------------------------------------------------------
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    64
#                              Buffer Functions
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    65
#-------------------------------------------------------------------------------
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    66
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    67
    def RefreshBufferState(self):
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    68
        if self.NodeList is not None:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    69
            nodeID = self.Manager.GetCurrentNodeID()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    70
            if nodeID != None:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    71
                nodename = "0x%2.2X %s"%(nodeID, self.Manager.GetCurrentNodeName())
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    72
            else:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    73
                nodename = self.Manager.GetCurrentNodeName()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    74
            self.NetworkNodes.SetPageText(0, nodename)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    75
            for idx, name in enumerate(self.NodeList.GetSlaveNames()):
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    76
                self.NetworkNodes.SetPageText(idx + 1, name)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    77
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    78
#-------------------------------------------------------------------------------
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    79
#                             Slave Nodes Management
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    80
#-------------------------------------------------------------------------------
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    81
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    82
    def OnAddSlaveMenu(self, event):
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    83
        dialog = AddSlaveDialog(self.Frame)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    84
        dialog.SetNodeList(self.NodeList)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    85
        if dialog.ShowModal() == wx.ID_OK:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    86
            values = dialog.GetValues()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    87
            result = self.NodeList.AddSlaveNode(values["slaveName"], values["slaveNodeID"], values["edsFile"])
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    88
            if not result:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    89
                new_editingpanel = EditingPanel(self.NetworkNodes, self, self.NodeList, False)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    90
                new_editingpanel.SetIndex(values["slaveNodeID"])
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    91
                idx = self.NodeList.GetOrderNumber(values["slaveNodeID"])
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    92
                self.NetworkNodes.InsertPage(idx, new_editingpanel, "")
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    93
                self.NodeList.SetCurrentSelected(idx)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    94
                self.NetworkNodes.SetSelection(idx)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    95
                self.RefreshBufferState()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    96
            else:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    97
                self.ShowErrorMessage(result)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    98
        dialog.Destroy()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
    99
        
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   100
    def OnRemoveSlaveMenu(self, event):
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   101
        slavenames = self.NodeList.GetSlaveNames()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   102
        slaveids = self.NodeList.GetSlaveIDs()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   103
        dialog = wx.SingleChoiceDialog(self.Frame, _("Choose a slave to remove"), _("Remove slave"), slavenames)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   104
        if dialog.ShowModal() == wx.ID_OK:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   105
            choice = dialog.GetSelection()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   106
            result = self.NodeList.RemoveSlaveNode(slaveids[choice])
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   107
            if not result:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   108
                slaveids.pop(choice)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   109
                current = self.NetworkNodes.GetSelection()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   110
                self.NetworkNodes.DeletePage(choice + 1)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   111
                if self.NetworkNodes.GetPageCount() > 0:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   112
                    new_selection = min(current, self.NetworkNodes.GetPageCount() - 1)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   113
                    self.NetworkNodes.SetSelection(new_selection)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   114
                    if new_selection > 0:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   115
                        self.NodeList.SetCurrentSelected(slaveids[new_selection - 1])
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   116
                self.RefreshBufferState()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   117
            else:
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   118
                self.ShowErrorMessage(result)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   119
        dialog.Destroy()
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   120
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   121
    def OpenMasterDCFDialog(self, node_id):
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   122
        self.NetworkNodes.SetSelection(0)
9edaa9d21cf9 Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
diff changeset
   123
        self.NetworkNodes.GetPage(0).OpenDCFDialog(node_id)