|
1 import wx |
|
2 |
|
3 from node import OD_Subindex, OD_MultipleSubindexes, OD_IdenticalSubindexes, OD_IdenticalIndexes |
|
4 from commondialogs import * |
|
5 |
|
6 class NodeEditorTemplate: |
|
7 |
|
8 EDITMENU_ID = None |
|
9 |
|
10 def __init__(self, manager, frame, mode_solo): |
|
11 self.Manager = manager |
|
12 self.Frame = frame |
|
13 self.ModeSolo = mode_solo |
|
14 |
|
15 self.BusId = None |
|
16 self.Closing = False |
|
17 |
|
18 def SetBusId(self, bus_id): |
|
19 self.BusId = bus_id |
|
20 |
|
21 def GetBusId(self): |
|
22 return self.BusId |
|
23 |
|
24 def IsClosing(self): |
|
25 return self.Closing |
|
26 |
|
27 def OnAddSDOServerMenu(self, event): |
|
28 self.Manager.AddSDOServerToCurrent() |
|
29 self.RefreshBufferState() |
|
30 self.RefreshCurrentIndexList() |
|
31 |
|
32 def OnAddSDOClientMenu(self, event): |
|
33 self.Manager.AddSDOClientToCurrent() |
|
34 self.RefreshBufferState() |
|
35 self.RefreshCurrentIndexList() |
|
36 |
|
37 def OnAddPDOTransmitMenu(self, event): |
|
38 self.Manager.AddPDOTransmitToCurrent() |
|
39 self.RefreshBufferState() |
|
40 self.RefreshCurrentIndexList() |
|
41 |
|
42 def OnAddPDOReceiveMenu(self, event): |
|
43 self.Manager.AddPDOReceiveToCurrent() |
|
44 self.RefreshBufferState() |
|
45 self.RefreshCurrentIndexList() |
|
46 |
|
47 def OnAddMapVariableMenu(self, event): |
|
48 self.AddMapVariable() |
|
49 |
|
50 def OnAddUserTypeMenu(self, event): |
|
51 self.AddUserType() |
|
52 |
|
53 def OnRefreshMenu(self, event): |
|
54 self.RefreshCurrentIndexList() |
|
55 |
|
56 def RefreshCurrentIndexList(self): |
|
57 pass |
|
58 |
|
59 def RefreshStatusBar(self): |
|
60 pass |
|
61 |
|
62 def SetStatusBarText(self, selection, manager): |
|
63 if selection: |
|
64 index, subIndex = selection |
|
65 if manager.IsCurrentEntry(index): |
|
66 self.Frame.HelpBar.SetStatusText(_("Index: 0x%04X")%index, 0) |
|
67 self.Frame.HelpBar.SetStatusText(_("Subindex: 0x%02X")%subIndex, 1) |
|
68 entryinfos = manager.GetEntryInfos(index) |
|
69 name = entryinfos["name"] |
|
70 category = _("Optional") |
|
71 if entryinfos["need"]: |
|
72 category = _("Mandatory") |
|
73 struct = "VAR" |
|
74 number = "" |
|
75 if entryinfos["struct"] & OD_IdenticalIndexes: |
|
76 number = _(" possibly defined %d times")%entryinfos["nbmax"] |
|
77 if entryinfos["struct"] & OD_IdenticalSubindexes: |
|
78 struct = "REC" |
|
79 elif entryinfos["struct"] & OD_MultipleSubindexes: |
|
80 struct = "ARRAY" |
|
81 text = _("%s: %s entry of struct %s%s.")%(name,category,struct,number) |
|
82 self.Frame.HelpBar.SetStatusText(text, 2) |
|
83 else: |
|
84 for i in xrange(3): |
|
85 self.Frame.HelpBar.SetStatusText("", i) |
|
86 else: |
|
87 for i in xrange(3): |
|
88 self.Frame.HelpBar.SetStatusText("", i) |
|
89 |
|
90 def RefreshProfileMenu(self): |
|
91 if self.EDITMENU_ID is not None: |
|
92 profile = self.Manager.GetCurrentProfileName() |
|
93 edititem = self.Frame.EditMenu.FindItemById(self.EDITMENU_ID) |
|
94 if edititem: |
|
95 length = self.Frame.AddMenu.GetMenuItemCount() |
|
96 for i in xrange(length-6): |
|
97 additem = self.Frame.AddMenu.FindItemByPosition(6) |
|
98 self.Frame.AddMenu.Delete(additem.GetId()) |
|
99 if profile not in ("None", "DS-301"): |
|
100 edititem.SetText(_("%s Profile")%profile) |
|
101 edititem.Enable(True) |
|
102 self.Frame.AddMenu.AppendSeparator() |
|
103 for text, indexes in self.Manager.GetCurrentSpecificMenu(): |
|
104 new_id = wx.NewId() |
|
105 self.Frame.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text) |
|
106 self.Frame.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id) |
|
107 else: |
|
108 edititem.SetText(_("Other Profile")) |
|
109 edititem.Enable(False) |
|
110 |
|
111 #------------------------------------------------------------------------------- |
|
112 # Buffer Functions |
|
113 #------------------------------------------------------------------------------- |
|
114 |
|
115 def RefreshBufferState(self): |
|
116 pass |
|
117 |
|
118 def OnUndoMenu(self, event): |
|
119 self.Manager.LoadCurrentPrevious() |
|
120 self.RefreshCurrentIndexList() |
|
121 self.RefreshBufferState() |
|
122 |
|
123 def OnRedoMenu(self, event): |
|
124 self.Manager.LoadCurrentNext() |
|
125 self.RefreshCurrentIndexList() |
|
126 self.RefreshBufferState() |
|
127 |
|
128 #------------------------------------------------------------------------------- |
|
129 # Editing Profiles functions |
|
130 #------------------------------------------------------------------------------- |
|
131 |
|
132 def OnCommunicationMenu(self, event): |
|
133 dictionary,current = self.Manager.GetCurrentCommunicationLists() |
|
134 self.EditProfile(_("Edit DS-301 Profile"), dictionary, current) |
|
135 |
|
136 def OnOtherCommunicationMenu(self, event): |
|
137 dictionary,current = self.Manager.GetCurrentDS302Lists() |
|
138 self.EditProfile(_("Edit DS-302 Profile"), dictionary, current) |
|
139 |
|
140 def OnEditProfileMenu(self, event): |
|
141 title = _("Edit %s Profile") % self.Manager.GetCurrentProfileName() |
|
142 dictionary,current = self.Manager.GetCurrentProfileLists() |
|
143 self.EditProfile(title, dictionary, current) |
|
144 |
|
145 def EditProfile(self, title, dictionary, current): |
|
146 dialog = CommunicationDialog(self.Frame) |
|
147 dialog.SetTitle(title) |
|
148 dialog.SetIndexDictionary(dictionary) |
|
149 dialog.SetCurrentList(current) |
|
150 dialog.RefreshLists() |
|
151 if dialog.ShowModal() == wx.ID_OK: |
|
152 new_profile = dialog.GetCurrentList() |
|
153 addinglist = [] |
|
154 removinglist = [] |
|
155 for index in new_profile: |
|
156 if index not in current: |
|
157 addinglist.append(index) |
|
158 for index in current: |
|
159 if index not in new_profile: |
|
160 removinglist.append(index) |
|
161 self.Manager.ManageEntriesOfCurrent(addinglist, removinglist) |
|
162 self.Manager.BufferCurrentNode() |
|
163 self.RefreshBufferState() |
|
164 |
|
165 dialog.Destroy() |
|
166 |
|
167 def GetProfileCallBack(self, text): |
|
168 def ProfileCallBack(event): |
|
169 self.Manager.AddSpecificEntryToCurrent(text) |
|
170 self.RefreshBufferState() |
|
171 self.RefreshCurrentIndexList() |
|
172 return ProfileCallBack |
|
173 |
|
174 #------------------------------------------------------------------------------- |
|
175 # Edit Node informations function |
|
176 #------------------------------------------------------------------------------- |
|
177 |
|
178 def OnNodeInfosMenu(self, event): |
|
179 dialog = NodeInfosDialog(self.Frame) |
|
180 name, id, type, description = self.Manager.GetCurrentNodeInfos() |
|
181 defaultstringsize = self.Manager.GetCurrentNodeDefaultStringSize() |
|
182 dialog.SetValues(name, id, type, description, defaultstringsize) |
|
183 if dialog.ShowModal() == wx.ID_OK: |
|
184 name, id, type, description, defaultstringsize = dialog.GetValues() |
|
185 self.Manager.SetCurrentNodeInfos(name, id, type, description) |
|
186 self.Manager.SetCurrentNodeDefaultStringSize(defaultstringsize) |
|
187 self.RefreshBufferState() |
|
188 self.RefreshCurrentIndexList() |
|
189 self.RefreshProfileMenu() |
|
190 |
|
191 #------------------------------------------------------------------------------- |
|
192 # Add User Types and Variables |
|
193 #------------------------------------------------------------------------------- |
|
194 |
|
195 def AddMapVariable(self): |
|
196 index = self.Manager.GetCurrentNextMapIndex() |
|
197 if index: |
|
198 dialog = MapVariableDialog(self.Frame) |
|
199 dialog.SetIndex(index) |
|
200 if dialog.ShowModal() == wx.ID_OK: |
|
201 result = self.Manager.AddMapVariableToCurrent(*dialog.GetValues()) |
|
202 if not isinstance(result, (StringType, UnicodeType)): |
|
203 self.RefreshBufferState() |
|
204 self.RefreshCurrentIndexList() |
|
205 else: |
|
206 self.ShowErrorMessage(result) |
|
207 dialog.Destroy() |
|
208 else: |
|
209 self.ShowErrorMessage(_("No map variable index left!")) |
|
210 |
|
211 def AddUserType(self): |
|
212 dialog = UserTypeDialog(self) |
|
213 dialog.SetTypeList(self.Manager.GetCustomisableTypes()) |
|
214 if dialog.ShowModal() == wx.ID_OK: |
|
215 result = self.Manager.AddUserTypeToCurrent(*dialog.GetValues()) |
|
216 if not isinstance(result, (StringType, UnicodeType)): |
|
217 self.RefreshBufferState() |
|
218 self.RefreshCurrentIndexList() |
|
219 else: |
|
220 self.ShowErrorMessage(result) |
|
221 dialog.Destroy() |
|
222 |
|
223 def ShowErrorMessage(self, message): |
|
224 message = wx.MessageDialog(self.Frame, message, _("Error"), wx.OK|wx.ICON_ERROR) |
|
225 message.ShowModal() |
|
226 message.Destroy() |