|
1 import os, sys |
|
2 base_folder = os.path.split(sys.path[0])[0] |
|
3 CanFestivalPath = os.path.join(base_folder, "CanFestival-3") |
|
4 |
|
5 import wx |
|
6 |
|
7 from subindextable import EditingPanel |
|
8 from nodeeditor import NodeEditorTemplate |
|
9 from controls import EditorPanel |
|
10 |
|
11 [ID_SLAVEEDITORPLUGINMENUNODEINFOS, ID_SLAVEEDITORPLUGINMENUDS301PROFILE, |
|
12 ID_SLAVEEDITORPLUGINMENUDS302PROFILE, ID_SLAVEEDITORPLUGINMENUDSOTHERPROFILE, |
|
13 ID_SLAVEEDITORPLUGINMENUADD, |
|
14 ] = [wx.NewId() for _init_coll_PluginMenu_Items in range(5)] |
|
15 |
|
16 [ID_SLAVEEDITORADDMENUSDOSERVER, ID_SLAVEEDITORADDMENUSDOCLIENT, |
|
17 ID_SLAVEEDITORADDMENUPDOTRANSMIT, ID_SLAVEEDITORADDMENUPDORECEIVE, |
|
18 ID_SLAVEEDITORADDMENUMAPVARIABLE, ID_SLAVEEDITORADDMENUUSERTYPE, |
|
19 ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)] |
|
20 |
|
21 class SlaveEditor(EditorPanel, NodeEditorTemplate): |
|
22 |
|
23 def _init_Editor(self, prnt): |
|
24 self.Editor = EditingPanel(prnt, self, self.Controler, self.Editable) |
|
25 |
|
26 def __init__(self, parent, controler, window, editable=True): |
|
27 self.Editable = editable |
|
28 EditorPanel.__init__(self, parent, "", window, controler) |
|
29 NodeEditorTemplate.__init__(self, controler, window, False) |
|
30 |
|
31 img = wx.Bitmap(os.path.join(CanFestivalPath, "objdictgen", "networkedit.png"), wx.BITMAP_TYPE_PNG).ConvertToImage() |
|
32 self.SetIcon(wx.BitmapFromImage(img.Rescale(16, 16))) |
|
33 |
|
34 def __del__(self): |
|
35 self.Controler.OnCloseEditor(self) |
|
36 |
|
37 def GetPluginMenuItems(self): |
|
38 if self.Editable: |
|
39 add_menu = [(wx.ITEM_NORMAL, (_('SDO Server'), ID_SLAVEEDITORADDMENUSDOSERVER, '', self.OnAddSDOServerMenu)), |
|
40 (wx.ITEM_NORMAL, (_('SDO Client'), ID_SLAVEEDITORADDMENUSDOCLIENT, '', self.OnAddSDOClientMenu)), |
|
41 (wx.ITEM_NORMAL, (_('PDO Transmit'), ID_SLAVEEDITORADDMENUPDOTRANSMIT, '', self.OnAddPDOTransmitMenu)), |
|
42 (wx.ITEM_NORMAL, (_('PDO Receive'), ID_SLAVEEDITORADDMENUPDORECEIVE, '', self.OnAddPDOReceiveMenu)), |
|
43 (wx.ITEM_NORMAL, (_('Map Variable'), ID_SLAVEEDITORADDMENUMAPVARIABLE, '', self.OnAddMapVariableMenu)), |
|
44 (wx.ITEM_NORMAL, (_('User Type'), ID_SLAVEEDITORADDMENUUSERTYPE, '', self.OnAddUserTypeMenu))] |
|
45 |
|
46 profile = self.Controler.GetCurrentProfileName() |
|
47 if profile not in ("None", "DS-301"): |
|
48 other_profile_text = _("%s Profile") % profile |
|
49 add_menu.append((wx.ITEM_SEPARATOR, None)) |
|
50 for text, indexes in self.Manager.GetCurrentSpecificMenu(): |
|
51 add_menu.append((wx.ITEM_NORMAL, (text, wx.NewId(), '', self.GetProfileCallBack(text)))) |
|
52 else: |
|
53 other_profile_text = _('Other Profile') |
|
54 |
|
55 return [(wx.ITEM_NORMAL, (_('Node infos'), ID_SLAVEEDITORPLUGINMENUNODEINFOS, '', self.OnNodeInfosMenu)), |
|
56 (wx.ITEM_NORMAL, (_('DS-301 Profile'), ID_SLAVEEDITORPLUGINMENUDS301PROFILE, '', self.OnCommunicationMenu)), |
|
57 (wx.ITEM_NORMAL, (_('DS-302 Profile'), ID_SLAVEEDITORPLUGINMENUDS302PROFILE, '', self.OnOtherCommunicationMenu)), |
|
58 (wx.ITEM_NORMAL, (other_profile_text, ID_SLAVEEDITORPLUGINMENUDSOTHERPROFILE, '', self.OnEditProfileMenu)), |
|
59 (wx.ITEM_SEPARATOR, None), |
|
60 (add_menu, (_('Add'), ID_SLAVEEDITORPLUGINMENUADD))] |
|
61 return [] |
|
62 |
|
63 def RefreshPluginMenu(self, plugin_menu): |
|
64 plugin_menu.Enable(ID_SLAVEEDITORPLUGINMENUDSOTHERPROFILE, False) |
|
65 |
|
66 def GetTitle(self): |
|
67 fullname = self.Controler.PlugFullName() |
|
68 if not self.Controler.CurrentIsSaved(): |
|
69 return "~%s~" % fullname |
|
70 return fullname |
|
71 |
|
72 def RefreshView(self): |
|
73 self.Editor.RefreshIndexList() |
|
74 |
|
75 def RefreshCurrentIndexList(self): |
|
76 self.RefreshView() |
|
77 |
|
78 def RefreshBufferState(self): |
|
79 self.ParentWindow.RefreshTitle() |
|
80 self.ParentWindow.RefreshFileMenu() |
|
81 self.ParentWindow.RefreshEditMenu() |
|
82 self.ParentWindow.RefreshPageTitles() |
|
83 |