plugins/canfestival/SlaveEditor.py
author laurent
Mon, 27 Feb 2012 16:51:43 +0100
changeset 696 9265781619b7
parent 680 61746934df41
permissions -rw-r--r--
Fix bug in killing debug thread when closing Beremiz window
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
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    11
[ID_SLAVEEDITORPLUGINMENUNODEINFOS, ID_SLAVEEDITORPLUGINMENUDS301PROFILE,
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    12
 ID_SLAVEEDITORPLUGINMENUDS302PROFILE, ID_SLAVEEDITORPLUGINMENUDSOTHERPROFILE,
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    13
 ID_SLAVEEDITORPLUGINMENUADD, 
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    14
] = [wx.NewId() for _init_coll_PluginMenu_Items in range(5)]
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
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    37
    def GetPluginMenuItems(self):
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
            
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    55
            return [(wx.ITEM_NORMAL, (_('Node infos'), ID_SLAVEEDITORPLUGINMENUNODEINFOS, '', self.OnNodeInfosMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    56
                    (wx.ITEM_NORMAL, (_('DS-301 Profile'), ID_SLAVEEDITORPLUGINMENUDS301PROFILE, '', self.OnCommunicationMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    57
                    (wx.ITEM_NORMAL, (_('DS-302 Profile'), ID_SLAVEEDITORPLUGINMENUDS302PROFILE, '', self.OnOtherCommunicationMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    58
                    (wx.ITEM_NORMAL, (other_profile_text, ID_SLAVEEDITORPLUGINMENUDSOTHERPROFILE, '', self.OnEditProfileMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    59
                    (wx.ITEM_SEPARATOR, None),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    60
                    (add_menu, (_('Add'), ID_SLAVEEDITORPLUGINMENUADD))]
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
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    63
    def RefreshPluginMenu(self, plugin_menu):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    64
        plugin_menu.Enable(ID_SLAVEEDITORPLUGINMENUDSOTHERPROFILE, False)
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):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    67
        fullname = self.Controler.PlugFullName()
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