confnodes/canfestival/SlaveEditor.py
author Edouard Tisserant
Tue, 08 May 2012 16:31:12 +0200
changeset 720 6be032177e2a
parent 718 5d4dc150b956
permissions -rw-r--r--
refactoring
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     1
import os, sys
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     2
base_folder = os.path.split(sys.path[0])[0]
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     3
CanFestivalPath = os.path.join(base_folder, "CanFestival-3")
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     4
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     5
import wx
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     6
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     7
from subindextable import EditingPanel
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     8
from nodeeditor import NodeEditorTemplate
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     9
from controls import EditorPanel
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    10
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    11
[ID_SLAVEEDITORCONFNODEMENUNODEINFOS, ID_SLAVEEDITORCONFNODEMENUDS301PROFILE,
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    12
 ID_SLAVEEDITORCONFNODEMENUDS302PROFILE, ID_SLAVEEDITORCONFNODEMENUDSOTHERPROFILE,
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    13
 ID_SLAVEEDITORCONFNODEMENUADD, 
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    14
] = [wx.NewId() for _init_coll_ConfNodeMenu_Items in range(5)]
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    15
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    16
[ID_SLAVEEDITORADDMENUSDOSERVER, ID_SLAVEEDITORADDMENUSDOCLIENT,
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    17
 ID_SLAVEEDITORADDMENUPDOTRANSMIT, ID_SLAVEEDITORADDMENUPDORECEIVE,
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    18
 ID_SLAVEEDITORADDMENUMAPVARIABLE, ID_SLAVEEDITORADDMENUUSERTYPE,
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    19
] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)]
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    20
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    21
class SlaveEditor(EditorPanel, NodeEditorTemplate):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    22
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    23
    def _init_Editor(self, prnt):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    24
        self.Editor = EditingPanel(prnt, self, self.Controler, self.Editable)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    25
        
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    26
    def __init__(self, parent, controler, window, editable=True):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    27
        self.Editable = editable
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    28
        EditorPanel.__init__(self, parent, "", window, controler)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    29
        NodeEditorTemplate.__init__(self, controler, window, False)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    30
        
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    31
        img = wx.Bitmap(os.path.join(CanFestivalPath, "objdictgen", "networkedit.png"), wx.BITMAP_TYPE_PNG).ConvertToImage()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    32
        self.SetIcon(wx.BitmapFromImage(img.Rescale(16, 16)))
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    33
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    34
    def __del__(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    35
        self.Controler.OnCloseEditor(self)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    36
    
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    37
    def GetConfNodeMenuItems(self):
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    38
        if self.Editable:
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    39
            add_menu = [(wx.ITEM_NORMAL, (_('SDO Server'), ID_SLAVEEDITORADDMENUSDOSERVER, '', self.OnAddSDOServerMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    40
                        (wx.ITEM_NORMAL, (_('SDO Client'), ID_SLAVEEDITORADDMENUSDOCLIENT, '', self.OnAddSDOClientMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    41
                        (wx.ITEM_NORMAL, (_('PDO Transmit'), ID_SLAVEEDITORADDMENUPDOTRANSMIT, '', self.OnAddPDOTransmitMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    42
                        (wx.ITEM_NORMAL, (_('PDO Receive'), ID_SLAVEEDITORADDMENUPDORECEIVE, '', self.OnAddPDOReceiveMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    43
                        (wx.ITEM_NORMAL, (_('Map Variable'), ID_SLAVEEDITORADDMENUMAPVARIABLE, '', self.OnAddMapVariableMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    44
                        (wx.ITEM_NORMAL, (_('User Type'), ID_SLAVEEDITORADDMENUUSERTYPE, '', self.OnAddUserTypeMenu))]
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    45
            
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    46
            profile = self.Controler.GetCurrentProfileName()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    47
            if profile not in ("None", "DS-301"):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    48
                other_profile_text = _("%s Profile") % profile
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    49
                add_menu.append((wx.ITEM_SEPARATOR, None))
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    50
                for text, indexes in self.Manager.GetCurrentSpecificMenu():
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    51
                    add_menu.append((wx.ITEM_NORMAL, (text, wx.NewId(), '', self.GetProfileCallBack(text))))
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    52
            else:
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    53
                other_profile_text = _('Other Profile')
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    54
            
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    55
            return [(wx.ITEM_NORMAL, (_('Node infos'), ID_SLAVEEDITORCONFNODEMENUNODEINFOS, '', self.OnNodeInfosMenu)),
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    56
                    (wx.ITEM_NORMAL, (_('DS-301 Profile'), ID_SLAVEEDITORCONFNODEMENUDS301PROFILE, '', self.OnCommunicationMenu)),
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    57
                    (wx.ITEM_NORMAL, (_('DS-302 Profile'), ID_SLAVEEDITORCONFNODEMENUDS302PROFILE, '', self.OnOtherCommunicationMenu)),
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    58
                    (wx.ITEM_NORMAL, (other_profile_text, ID_SLAVEEDITORCONFNODEMENUDSOTHERPROFILE, '', self.OnEditProfileMenu)),
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    59
                    (wx.ITEM_SEPARATOR, None),
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    60
                    (add_menu, (_('Add'), ID_SLAVEEDITORCONFNODEMENUADD))]
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    61
        return []
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    62
    
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    63
    def RefreshConfNodeMenu(self, confnode_menu):
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    64
        confnode_menu.Enable(ID_SLAVEEDITORCONFNODEMENUDSOTHERPROFILE, False)
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    65
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    66
    def GetTitle(self):
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
    67
        fullname = self.Controler.CTNFullName()
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    68
        if not self.Controler.CurrentIsSaved():
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    69
            return "~%s~" % fullname
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    70
        return fullname
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    71
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    72
    def RefreshView(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    73
        self.Editor.RefreshIndexList()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    74
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    75
    def RefreshCurrentIndexList(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    76
        self.RefreshView()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    77
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    78
    def RefreshBufferState(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    79
        self.ParentWindow.RefreshTitle()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    80
        self.ParentWindow.RefreshFileMenu()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    81
        self.ParentWindow.RefreshEditMenu()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    82
        self.ParentWindow.RefreshPageTitles()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    83