author | lbessard |
Mon, 25 Jun 2007 18:57:14 +0200 | |
changeset 24 | 364320323b4d |
parent 16 | 20dcc0dce64b |
child 27 | dae55dd9ee14 |
permissions | -rw-r--r-- |
0 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
7 |
#Copyright (C): Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
5 | 12 |
#modify it under the terms of the GNU General Public |
0 | 13 |
#License as published by the Free Software Foundation; either |
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#Lesser General Public License for more details. |
|
20 |
# |
|
5 | 21 |
#You should have received a copy of the GNU General Public |
0 | 22 |
#License along with this library; if not, write to the Free Software |
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
from wxPython.wx import * |
|
26 |
from wxPython.grid import * |
|
27 |
from time import localtime |
|
28 |
from datetime import datetime |
|
29 |
import wx |
|
30 |
||
31 |
from SFCViewer import * |
|
32 |
from FBDViewer import * |
|
33 |
from LDViewer import * |
|
34 |
from Viewer import * |
|
35 |
from PLCControler import * |
|
36 |
from plcopen import OpenPDFDoc |
|
37 |
from plcopen.structures import * |
|
38 |
||
39 |
import os, re, platform, sys, time, traceback, getopt |
|
40 |
||
41 |
__version__ = "$Revision$" |
|
42 |
||
43 |
def create(parent): |
|
44 |
return PLCOpenEditor(parent) |
|
45 |
||
46 |
def usage(): |
|
47 |
print "\nUsage of PLCOpenEditor.py :" |
|
48 |
print "\n %s [Filepath]\n"%sys.argv[0] |
|
49 |
||
50 |
try: |
|
51 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
|
52 |
except getopt.GetoptError: |
|
53 |
# print help information and exit: |
|
54 |
usage() |
|
55 |
sys.exit(2) |
|
56 |
||
57 |
for o, a in opts: |
|
58 |
if o in ("-h", "--help"): |
|
59 |
usage() |
|
60 |
sys.exit() |
|
61 |
||
62 |
fileOpen = None |
|
63 |
if len(args) > 1: |
|
64 |
usage() |
|
65 |
sys.exit() |
|
66 |
elif len(args) == 1: |
|
67 |
fileOpen = args[0] |
|
6 | 68 |
CWD = sys.path[0] |
0 | 69 |
|
70 |
[wxID_PLCOPENEDITOR, wxID_PLCOPENEDITORPROJECTTREE, |
|
6 | 71 |
wxID_PLCOPENEDITORSPLITTERWINDOW1, wxID_PLCOPENEDITOREDITORPANEL, |
72 |
wxID_PLCOPENEDITORTABSOPENED, wxID_PLCOPENEDITORTOOLBAR, |
|
73 |
wxID_PLCOPENEDITORDEFAULTTOOLBAR, wxID_PLCOPENEDITORSFCTOOLBAR, |
|
0 | 74 |
wxID_PLCOPENEDITORFBDTOOLBAR, wxID_PLCOPENEDITORLDTOOLBAR, |
6 | 75 |
] = [wx.NewId() for _init_ctrls in range(10)] |
76 |
||
77 |
[wxID_PLCOPENEDITORTOOLBARITEMS0, |
|
0 | 78 |
] = [wx.NewId() for _init_coll_DefaultToolBar_Items in range(1)] |
79 |
||
6 | 80 |
SFC_ITEMS = [wxID_PLCOPENEDITORSFCTOOLBARITEMS1, |
0 | 81 |
wxID_PLCOPENEDITORSFCTOOLBARITEMS2, wxID_PLCOPENEDITORSFCTOOLBARITEMS3, |
82 |
wxID_PLCOPENEDITORSFCTOOLBARITEMS4, wxID_PLCOPENEDITORSFCTOOLBARITEMS5, |
|
83 |
wxID_PLCOPENEDITORSFCTOOLBARITEMS6, |
|
6 | 84 |
] = [wx.NewId() for _init_coll_SFCToolBar_Items in range(6)] |
85 |
||
86 |
FBD_ITEMS = [wxID_PLCOPENEDITORFBDTOOLBARITEMS1, |
|
0 | 87 |
wxID_PLCOPENEDITORFBDTOOLBARITEMS2, wxID_PLCOPENEDITORFBDTOOLBARITEMS3, |
88 |
wxID_PLCOPENEDITORFBDTOOLBARITEMS4, wxID_PLCOPENEDITORFBDTOOLBARITEMS5, |
|
6 | 89 |
] = [wx.NewId() for _init_coll_FBDToolBar_Items in range(5)] |
90 |
||
91 |
LD_ITEMS = [wxID_PLCOPENEDITORLDTOOLBARITEMS1, |
|
0 | 92 |
wxID_PLCOPENEDITORLDTOOLBARITEMS2, wxID_PLCOPENEDITORLDTOOLBARITEMS3, |
93 |
wxID_PLCOPENEDITORLDTOOLBARITEMS4, |
|
6 | 94 |
] = [wx.NewId() for _init_coll_LDToolBar_Items in range(4)] |
0 | 95 |
|
96 |
[wxID_PLCOPENEDITORFILEMENUITEMS0, wxID_PLCOPENEDITORFILEMENUITEMS1, |
|
97 |
wxID_PLCOPENEDITORFILEMENUITEMS2, wxID_PLCOPENEDITORFILEMENUITEMS3, |
|
98 |
wxID_PLCOPENEDITORFILEMENUITEMS5, wxID_PLCOPENEDITORFILEMENUITEMS6, |
|
99 |
wxID_PLCOPENEDITORFILEMENUITEMS7, wxID_PLCOPENEDITORFILEMENUITEMS9, |
|
100 |
wxID_PLCOPENEDITORFILEMENUITEMS11, |
|
101 |
] = [wx.NewId() for _init_coll_FileMenu_Items in range(9)] |
|
102 |
||
103 |
[wxID_PLCOPENEDITORHELPMENUITEMS0, wxID_PLCOPENEDITORHELPMENUITEMS1, |
|
104 |
wxID_PLCOPENEDITORHELPMENUITEMS2, wxID_PLCOPENEDITORHELPMENUITEMS3, |
|
105 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(4)] |
|
106 |
||
107 |
[wxID_PLCOPENEDITORSFCMENUITEMS0, wxID_PLCOPENEDITORSFCMENUITEMS1, |
|
108 |
wxID_PLCOPENEDITORSFCMENUITEMS2, wxID_PLCOPENEDITORSFCMENUITEMS3, |
|
109 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(4)] |
|
110 |
||
111 |
[wxID_PLCOPENEDITORCONFIGMENUITEMS0, wxID_PLCOPENEDITORCONFIGMENUITEMS1, |
|
112 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(2)] |
|
113 |
||
114 |
[wxID_PLCOPENEDITOREDITMENUITEMS0, wxID_PLCOPENEDITOREDITMENUITEMS1, |
|
115 |
wxID_PLCOPENEDITOREDITMENUITEMS11, wxID_PLCOPENEDITOREDITMENUITEMS12, |
|
116 |
wxID_PLCOPENEDITOREDITMENUITEMS2, wxID_PLCOPENEDITOREDITMENUITEMS4, |
|
117 |
wxID_PLCOPENEDITOREDITMENUITEMS5, wxID_PLCOPENEDITOREDITMENUITEMS6, |
|
118 |
wxID_PLCOPENEDITOREDITMENUITEMS8, wxID_PLCOPENEDITOREDITMENUITEMS9, |
|
119 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(10)] |
|
120 |
||
121 |
[wxID_PLCOPENEDITORSFCMENUITEMS0, wxID_PLCOPENEDITORSFCMENUITEMS1, |
|
122 |
wxID_PLCOPENEDITORSFCMENUITEMS2, wxID_PLCOPENEDITORSFCMENUITEMS3, |
|
123 |
] = [wx.NewId() for _init_coll_SFCMenu_Items in range(4)] |
|
124 |
||
125 |
[wxID_PLCOPENEDITORCONFIGMENUITEMS0, wxID_PLCOPENEDITORCONFIGMENUITEMS1, |
|
126 |
] = [wx.NewId() for _init_coll_ConfigMenu_Items in range(2)] |
|
127 |
||
128 |
class PLCOpenEditor(wx.Frame): |
|
129 |
_custom_classes = {'wx.SashWindow' : ['Viewer']} |
|
130 |
||
131 |
def _init_coll_EditMenu_Items(self, parent): |
|
132 |
# generated method, don't edit |
|
133 |
||
134 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS0, |
|
135 |
kind=wx.ITEM_NORMAL, text=u'Refresh\tCTRL+R') |
|
136 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS1, |
|
137 |
kind=wx.ITEM_NORMAL, text=u'Undo\tCTRL+Z') |
|
138 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS2, |
|
139 |
kind=wx.ITEM_NORMAL, text=u'Redo\tCTRL+Y') |
|
140 |
parent.AppendSeparator() |
|
141 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS4, |
|
142 |
kind=wx.ITEM_NORMAL, text=u'Cut\tCTRL+X') |
|
143 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS5, |
|
144 |
kind=wx.ITEM_NORMAL, text=u'Copy\tCTRL+C') |
|
145 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS6, |
|
146 |
kind=wx.ITEM_NORMAL, text=u'Paste\tCTRL+V') |
|
147 |
parent.AppendSeparator() |
|
148 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS8, |
|
149 |
kind=wx.ITEM_NORMAL, text=u'Add POU') |
|
150 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS9, |
|
151 |
kind=wx.ITEM_NORMAL, text=u'Remove POU') |
|
152 |
parent.AppendSeparator() |
|
153 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS11, |
|
154 |
kind=wx.ITEM_NORMAL, text=u'Add Configuration') |
|
155 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS12, |
|
156 |
kind=wx.ITEM_NORMAL, text=u'Remove Configuration') |
|
157 |
self.Bind(wx.EVT_MENU, self.OnRefreshMenu, |
|
158 |
id=wxID_PLCOPENEDITOREDITMENUITEMS0) |
|
159 |
self.Bind(wx.EVT_MENU, self.OnCutMenu, |
|
160 |
id=wxID_PLCOPENEDITOREDITMENUITEMS4) |
|
161 |
self.Bind(wx.EVT_MENU, self.OnCopyMenu, |
|
162 |
id=wxID_PLCOPENEDITOREDITMENUITEMS5) |
|
163 |
self.Bind(wx.EVT_MENU, self.OnPasteMenu, |
|
164 |
id=wxID_PLCOPENEDITOREDITMENUITEMS6) |
|
165 |
self.Bind(wx.EVT_MENU, self.OnAddPouMenu, |
|
166 |
id=wxID_PLCOPENEDITOREDITMENUITEMS8) |
|
167 |
self.Bind(wx.EVT_MENU, self.OnRemovePouMenu, |
|
168 |
id=wxID_PLCOPENEDITOREDITMENUITEMS9) |
|
169 |
self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu, |
|
170 |
id=wxID_PLCOPENEDITOREDITMENUITEMS11) |
|
171 |
self.Bind(wx.EVT_MENU, self.OnRemoveConfigurationMenu, |
|
172 |
id=wxID_PLCOPENEDITOREDITMENUITEMS12) |
|
173 |
||
174 |
def _init_coll_menuBar1_Menus(self, parent): |
|
175 |
# generated method, don't edit |
|
176 |
||
177 |
parent.Append(menu=self.FileMenu, title=u'File') |
|
178 |
parent.Append(menu=self.EditMenu, title=u'Edit') |
|
179 |
parent.Append(menu=self.HelpMenu, title=u'Help') |
|
180 |
||
181 |
def _init_coll_ConfigMenu_Items(self, parent): |
|
182 |
# generated method, don't edit |
|
183 |
||
184 |
parent.Append(help='', id=wxID_PLCOPENEDITORCONFIGMENUITEMS0, |
|
185 |
kind=wx.ITEM_NORMAL, text=u'Add Resource') |
|
186 |
parent.Append(help='', id=wxID_PLCOPENEDITORCONFIGMENUITEMS1, |
|
187 |
kind=wx.ITEM_NORMAL, text=u'Remove Resource') |
|
188 |
self.Bind(wx.EVT_MENU, self.OnAddResourceMenu, |
|
189 |
id=wxID_PLCOPENEDITORCONFIGMENUITEMS0) |
|
190 |
self.Bind(wx.EVT_MENU, self.OnRemoveResourceMenu, |
|
191 |
id=wxID_PLCOPENEDITORCONFIGMENUITEMS1) |
|
192 |
||
193 |
def _init_coll_HelpMenu_Items(self, parent): |
|
194 |
# generated method, don't edit |
|
195 |
||
196 |
parent.Append(help='', id=wxID_PLCOPENEDITORHELPMENUITEMS0, |
|
197 |
kind=wx.ITEM_NORMAL, text=u'PLCOpenEditor\tF1') |
|
198 |
parent.Append(help='', id=wxID_PLCOPENEDITORHELPMENUITEMS1, |
|
199 |
kind=wx.ITEM_NORMAL, text=u'PLCOpen\tF2') |
|
200 |
parent.Append(help='', id=wxID_PLCOPENEDITORHELPMENUITEMS2, |
|
201 |
kind=wx.ITEM_NORMAL, text=u'IEC 61131-3\tF3') |
|
202 |
parent.Append(help='', id=wxID_PLCOPENEDITORHELPMENUITEMS3, |
|
203 |
kind=wx.ITEM_NORMAL, text=u'About') |
|
204 |
self.Bind(wx.EVT_MENU, self.OnPLCOpenMenu, |
|
205 |
id=wxID_PLCOPENEDITORHELPMENUITEMS1) |
|
206 |
||
207 |
def _init_coll_FileMenu_Items(self, parent): |
|
208 |
# generated method, don't edit |
|
209 |
||
210 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS0, |
|
211 |
kind=wx.ITEM_NORMAL, text=u'New\tCTRL+N') |
|
212 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS1, |
|
213 |
kind=wx.ITEM_NORMAL, text=u'Open\tCTRL+O') |
|
214 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS2, |
|
215 |
kind=wx.ITEM_NORMAL, text=u'Close Tab\tCTRL+W') |
|
216 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS3, |
|
217 |
kind=wx.ITEM_NORMAL, text=u'Close Project') |
|
218 |
parent.AppendSeparator() |
|
219 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS5, |
|
220 |
kind=wx.ITEM_NORMAL, text=u'Save\tCTRL+S') |
|
221 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS6, |
|
222 |
kind=wx.ITEM_NORMAL, text=u'Save As...\tCTRL+SHIFT+S') |
|
223 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS7, |
|
224 |
kind=wx.ITEM_NORMAL, text=u'Generate Program\tCTRL+G') |
|
225 |
parent.AppendSeparator() |
|
226 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS9, |
|
227 |
kind=wx.ITEM_NORMAL, text=u'Properties') |
|
228 |
parent.AppendSeparator() |
|
229 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS11, |
|
230 |
kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q') |
|
231 |
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, |
|
232 |
id=wxID_PLCOPENEDITORFILEMENUITEMS0) |
|
233 |
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, |
|
234 |
id=wxID_PLCOPENEDITORFILEMENUITEMS1) |
|
235 |
self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, |
|
236 |
id=wxID_PLCOPENEDITORFILEMENUITEMS2) |
|
237 |
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, |
|
238 |
id=wxID_PLCOPENEDITORFILEMENUITEMS3) |
|
239 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, |
|
240 |
id=wxID_PLCOPENEDITORFILEMENUITEMS5) |
|
241 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, |
|
242 |
id=wxID_PLCOPENEDITORFILEMENUITEMS6) |
|
243 |
self.Bind(wx.EVT_MENU, self.OnGenerateProgramMenu, |
|
244 |
id=wxID_PLCOPENEDITORFILEMENUITEMS7) |
|
245 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, |
|
246 |
id=wxID_PLCOPENEDITORFILEMENUITEMS11) |
|
247 |
||
248 |
def _init_coll_SFCMenu_Items(self, parent): |
|
249 |
# generated method, don't edit |
|
250 |
||
251 |
parent.Append(help='', id=wxID_PLCOPENEDITORSFCMENUITEMS0, |
|
252 |
kind=wx.ITEM_NORMAL, text=u'Add Transition') |
|
253 |
parent.Append(help='', id=wxID_PLCOPENEDITORSFCMENUITEMS1, |
|
254 |
kind=wx.ITEM_NORMAL, text=u'Add Action') |
|
255 |
parent.Append(help='', id=wxID_PLCOPENEDITORSFCMENUITEMS2, |
|
256 |
kind=wx.ITEM_NORMAL, text=u'Remove Transition') |
|
257 |
parent.Append(help='', id=wxID_PLCOPENEDITORSFCMENUITEMS3, |
|
258 |
kind=wx.ITEM_NORMAL, text=u'Remove Action') |
|
259 |
self.Bind(wx.EVT_MENU, self.OnAddPouTransitionMenu, |
|
260 |
id=wxID_PLCOPENEDITORSFCMENUITEMS0) |
|
261 |
self.Bind(wx.EVT_MENU, self.OnAddPouActionMenu, |
|
262 |
id=wxID_PLCOPENEDITORSFCMENUITEMS1) |
|
263 |
self.Bind(wx.EVT_MENU, self.OnRemovePouTransitionMenu, |
|
264 |
id=wxID_PLCOPENEDITORSFCMENUITEMS2) |
|
265 |
self.Bind(wx.EVT_MENU, self.OnRemovePouActionMenu, |
|
266 |
id=wxID_PLCOPENEDITORSFCMENUITEMS3) |
|
267 |
||
268 |
def _init_utils(self): |
|
269 |
# generated method, don't edit |
|
270 |
self.menuBar1 = wx.MenuBar() |
|
271 |
||
272 |
self.FileMenu = wx.Menu(title=u'') |
|
273 |
||
274 |
self.EditMenu = wx.Menu(title=u'') |
|
275 |
||
276 |
self.HelpMenu = wx.Menu(title='') |
|
277 |
||
278 |
self.SFCMenu = wx.Menu(title='') |
|
279 |
||
280 |
self.ConfigMenu = wx.Menu(title='') |
|
281 |
||
282 |
self._init_coll_menuBar1_Menus(self.menuBar1) |
|
283 |
self._init_coll_FileMenu_Items(self.FileMenu) |
|
284 |
self._init_coll_EditMenu_Items(self.EditMenu) |
|
285 |
self._init_coll_HelpMenu_Items(self.HelpMenu) |
|
286 |
self._init_coll_SFCMenu_Items(self.SFCMenu) |
|
287 |
self._init_coll_ConfigMenu_Items(self.ConfigMenu) |
|
288 |
||
289 |
def _init_coll_MainGridSizer_Items(self, parent): |
|
290 |
# generated method, don't edit |
|
291 |
||
292 |
parent.AddWindow(self.splitterWindow1, 0, border=0, flag=wxGROW) |
|
293 |
||
6 | 294 |
def _init_coll_EditorGridSizer_Items(self, parent): |
295 |
# generated method, don't edit |
|
296 |
||
297 |
parent.AddWindow(self.ToolBar, 0, border=0, flag=wxGROW) |
|
298 |
parent.AddWindow(self.TabsOpened, 0, border=0, flag=wxGROW) |
|
299 |
||
0 | 300 |
def _init_coll_MainGridSizer_Growables(self, parent): |
301 |
# generated method, don't edit |
|
302 |
||
303 |
parent.AddGrowableCol(0) |
|
304 |
parent.AddGrowableRow(0) |
|
305 |
||
6 | 306 |
def _init_coll_EditorGridSizer_Growables(self, parent): |
307 |
# generated method, don't edit |
|
308 |
||
309 |
parent.AddGrowableCol(0) |
|
310 |
parent.AddGrowableRow(1) |
|
311 |
||
0 | 312 |
def _init_sizers(self): |
313 |
# generated method, don't edit |
|
314 |
self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=0) |
|
315 |
||
6 | 316 |
self.EditorGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
317 |
||
0 | 318 |
self._init_coll_MainGridSizer_Growables(self.MainGridSizer) |
319 |
self._init_coll_MainGridSizer_Items(self.MainGridSizer) |
|
6 | 320 |
self._init_coll_EditorGridSizer_Growables(self.EditorGridSizer) |
321 |
self._init_coll_EditorGridSizer_Items(self.EditorGridSizer) |
|
322 |
||
0 | 323 |
self.SetSizer(self.MainGridSizer) |
6 | 324 |
self.EditorPanel.SetSizer(self.EditorGridSizer) |
0 | 325 |
|
326 |
def _init_ctrls(self, prnt): |
|
327 |
# generated method, don't edit |
|
328 |
wx.Frame.__init__(self, id=wxID_PLCOPENEDITOR, name=u'PLCOpenEditor', |
|
329 |
parent=prnt, pos=wx.Point(235, 287), size=wx.Size(1000, 600), |
|
330 |
style=wx.DEFAULT_FRAME_STYLE, title=u'PLCOpenEditor') |
|
331 |
self._init_utils() |
|
332 |
self.SetClientSize(wx.Size(1000, 600)) |
|
333 |
self.SetMenuBar(self.menuBar1) |
|
7 | 334 |
|
335 |
self.splitterWindow1 = wx.SplitterWindow(id=wxID_PLCOPENEDITORSPLITTERWINDOW1, |
|
336 |
name='splitterWindow1', parent=self, point=wx.Point(0, 0), |
|
337 |
size=wx.Size(-1, -1), style=wx.SP_3D) |
|
338 |
self.splitterWindow1.SetNeedUpdating(True) |
|
339 |
self.splitterWindow1.SetMinimumPaneSize(1) |
|
340 |
||
341 |
self.EditorPanel = wx.Panel(id=wxID_PLCOPENEDITOREDITORPANEL, |
|
342 |
name='TabPanel', parent=self.splitterWindow1, pos=wx.Point(0, 0), |
|
343 |
size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) |
|
344 |
||
345 |
self.TabsOpened = wx.Notebook(id=wxID_PLCOPENEDITORTABSOPENED, |
|
346 |
name='TabsOpened', parent=self.EditorPanel, pos=wx.Point(0, |
|
347 |
0), size=wx.Size(-1, -1), style=0) |
|
348 |
self.TabsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, |
|
349 |
self.OnPouSelectedChanged, id=wxID_PLCOPENEDITORTABSOPENED) |
|
350 |
||
351 |
self.ToolBar = wxToolBar(id=wxID_PLCOPENEDITORTOOLBAR, name='ToolBar', |
|
352 |
parent=self.EditorPanel, pos=wx.Point(0, 0), size=wx.Size(0, 40), |
|
353 |
style=wxTB_HORIZONTAL | wxNO_BORDER) |
|
354 |
self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORTOOLBARITEMS0, |
|
355 |
wxBitmap(os.path.join(CWD, 'Images/select.png')), wxNullBitmap, "Select an object") |
|
356 |
self.Bind(wx.EVT_TOOL, self.OnSelectionTool, |
|
357 |
id=wxID_PLCOPENEDITORTOOLBARITEMS0) |
|
358 |
||
359 |
self.ProjectTree = wx.TreeCtrl(id=wxID_PLCOPENEDITORPROJECTTREE, |
|
360 |
name='treeCtrl1', parent=self.splitterWindow1, pos=wx.Point(0, 0), |
|
361 |
size=wx.Size(-1, -1), |
|
362 |
style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER) |
|
363 |
self.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp) |
|
364 |
self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnProjectTreeBeginDrag, |
|
365 |
id=wxID_PLCOPENEDITORPROJECTTREE) |
|
0 | 366 |
self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit, |
367 |
id=wxID_PLCOPENEDITORPROJECTTREE) |
|
368 |
self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnProjectTreeItemEndEdit, |
|
369 |
id=wxID_PLCOPENEDITORPROJECTTREE) |
|
370 |
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnProjectTreeItemActivated, |
|
371 |
id=wxID_PLCOPENEDITORPROJECTTREE) |
|
372 |
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnProjectTreeItemSelected, |
|
373 |
id=wxID_PLCOPENEDITORPROJECTTREE) |
|
6 | 374 |
self.splitterWindow1.SplitVertically(self.ProjectTree, self.EditorPanel, |
0 | 375 |
200) |
376 |
||
377 |
self._init_sizers() |
|
378 |
||
379 |
def __init__(self, parent): |
|
380 |
self._init_ctrls(parent) |
|
381 |
||
9 | 382 |
self.TreeImageList = wxImageList(16, 16) |
383 |
for language in LANGUAGES: |
|
384 |
self.TreeImageList.Add(wxBitmap(os.path.join(CWD, 'Images/%s.png'%language))) |
|
385 |
self.ProjectTree.SetImageList(self.TreeImageList) |
|
386 |
||
0 | 387 |
self.Controler = PLCControler() |
388 |
||
389 |
if fileOpen: |
|
390 |
self.Controler.OpenXMLFile(fileOpen) |
|
391 |
self.RefreshProjectTree() |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
392 |
|
6 | 393 |
self.CurrentToolBar = [] |
394 |
||
0 | 395 |
self.RefreshFileMenu() |
396 |
self.RefreshEditMenu() |
|
397 |
self.RefreshToolBar() |
|
398 |
||
399 |
def RefreshFileMenu(self): |
|
9 | 400 |
if self.FileMenu: |
401 |
if self.Controler.HasOpenedProject(): |
|
402 |
if self.TabsOpened.GetPageCount() > 0: |
|
403 |
self.FileMenu.FindItemByPosition(2).Enable(True) |
|
404 |
else: |
|
405 |
self.FileMenu.FindItemByPosition(2).Enable(False) |
|
406 |
self.FileMenu.FindItemByPosition(3).Enable(True) |
|
407 |
self.FileMenu.FindItemByPosition(5).Enable(True) |
|
408 |
self.FileMenu.FindItemByPosition(6).Enable(True) |
|
409 |
self.FileMenu.FindItemByPosition(7).Enable(True) |
|
410 |
self.FileMenu.FindItemByPosition(9).Enable(True) |
|
0 | 411 |
else: |
412 |
self.FileMenu.FindItemByPosition(2).Enable(False) |
|
9 | 413 |
self.FileMenu.FindItemByPosition(3).Enable(False) |
414 |
self.FileMenu.FindItemByPosition(5).Enable(False) |
|
415 |
self.FileMenu.FindItemByPosition(6).Enable(False) |
|
416 |
self.FileMenu.FindItemByPosition(7).Enable(False) |
|
417 |
self.FileMenu.FindItemByPosition(9).Enable(False) |
|
0 | 418 |
|
419 |
def RefreshEditMenu(self): |
|
9 | 420 |
if self.EditMenu: |
421 |
self.EditMenu.FindItemByPosition(1).Enable(False) |
|
422 |
self.EditMenu.FindItemByPosition(2).Enable(False) |
|
423 |
if self.Controler.HasOpenedProject(): |
|
424 |
if self.TabsOpened.GetPageCount() > 0: |
|
425 |
self.EditMenu.FindItemByPosition(0).Enable(True) |
|
426 |
else: |
|
427 |
self.EditMenu.FindItemByPosition(0).Enable(False) |
|
428 |
self.EditMenu.FindItemByPosition(8).Enable(True) |
|
429 |
self.EditMenu.FindItemByPosition(9).Enable(True) |
|
0 | 430 |
else: |
431 |
self.EditMenu.FindItemByPosition(0).Enable(False) |
|
9 | 432 |
self.EditMenu.FindItemByPosition(8).Enable(False) |
433 |
self.EditMenu.FindItemByPosition(9).Enable(False) |
|
434 |
bodytype = self.Controler.GetCurrentElementEditingBodyType() |
|
435 |
if bodytype in ["IL","ST"]: |
|
436 |
self.EditMenu.FindItemByPosition(4).Enable(True) |
|
437 |
self.EditMenu.FindItemByPosition(5).Enable(True) |
|
438 |
self.EditMenu.FindItemByPosition(6).Enable(True) |
|
439 |
else: |
|
440 |
self.EditMenu.FindItemByPosition(4).Enable(False) |
|
441 |
self.EditMenu.FindItemByPosition(5).Enable(False) |
|
0 | 442 |
self.EditMenu.FindItemByPosition(6).Enable(False) |
443 |
||
444 |
def OnNewProjectMenu(self, event): |
|
445 |
dialog = ProjectDialog(self) |
|
446 |
if dialog.ShowModal() == wxID_OK: |
|
447 |
values = dialog.GetValues() |
|
448 |
projectname = values.pop("projectName") |
|
449 |
values["creationDateTime"] = datetime(*localtime()[:6]) |
|
450 |
self.Controler.CreateNewProject(projectname) |
|
451 |
self.Controler.SetProjectProperties(values) |
|
452 |
self.RefreshFileMenu() |
|
453 |
self.RefreshEditMenu() |
|
454 |
self.RefreshProjectTree() |
|
455 |
event.Skip() |
|
456 |
||
457 |
def OnOpenProjectMenu(self, event): |
|
458 |
filepath = self.Controler.GetFilePath() |
|
459 |
if filepath != "": |
|
460 |
directory = os.path.dirname(filepath) |
|
461 |
else: |
|
462 |
directory = os.getcwd() |
|
463 |
dialog = wxFileDialog(self, "Choose a file", directory, "", "PLCOpen files (*.xml)|*.xml|All files|*.*", wxOPEN) |
|
464 |
if dialog.ShowModal() == wxID_OK: |
|
465 |
filepath = dialog.GetPath() |
|
466 |
if os.path.isfile(filepath): |
|
467 |
self.Controler.OpenXMLFile(filepath) |
|
468 |
self.TabsOpened.DeleteAllPages() |
|
469 |
self.RefreshProjectTree() |
|
470 |
self.RefreshFileMenu() |
|
471 |
self.RefreshEditMenu() |
|
472 |
self.RefreshToolBar() |
|
473 |
dialog.Destroy() |
|
474 |
event.Skip() |
|
475 |
||
476 |
def OnCloseTabMenu(self, event): |
|
477 |
selected = self.TabsOpened.GetSelection() |
|
478 |
if selected >= 0: |
|
479 |
self.Controler.CloseElementEditing() |
|
480 |
self.TabsOpened.DeletePage(selected) |
|
481 |
if self.TabsOpened.GetPageCount() > 0: |
|
482 |
self.TabsOpened.SetSelection(min(selected, self.TabsOpened.GetPageCount() - 1)) |
|
483 |
self.RefreshFileMenu() |
|
484 |
self.RefreshEditMenu() |
|
485 |
self.RefreshToolBar() |
|
486 |
event.Skip() |
|
487 |
||
488 |
def OnCloseProjectMenu(self, event): |
|
489 |
self.Controler.Reset() |
|
490 |
self.TabsOpened.DeleteAllPages() |
|
491 |
self.ProjectTree.DeleteAllItems() |
|
492 |
self.RefreshFileMenu() |
|
493 |
self.RefreshEditMenu() |
|
494 |
self.RefreshToolBar() |
|
495 |
event.Skip() |
|
496 |
||
497 |
def OnSaveProjectMenu(self, event): |
|
498 |
self.SaveProject() |
|
499 |
event.Skip() |
|
500 |
||
501 |
def OnSaveProjectAsMenu(self, event): |
|
502 |
self.SaveProjectAs() |
|
503 |
event.Skip() |
|
504 |
||
505 |
def OnGenerateProgramMenu(self, event): |
|
4
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
506 |
dialog = wxFileDialog(self, "Choose a file", os.getcwd(), "", "ST files (*.st)|*.st|All files|*.*", wxSAVE|wxCHANGE_DIR) |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
507 |
if dialog.ShowModal() == wxID_OK: |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
508 |
filepath = dialog.GetPath() |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
509 |
if os.path.isdir(os.path.dirname(filepath)): |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
510 |
result = self.Controler.GenerateProgram(filepath) |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
511 |
if not result: |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
512 |
message = wxMessageDialog(self, "Can't generate program to file %s!"%filepath, "Error", wxOK|wxICON_ERROR) |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
513 |
message.ShowModal() |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
514 |
message.Destroy() |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
515 |
else: |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
516 |
message = wxMessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR) |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
517 |
message.ShowModal() |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
518 |
message.Destroy() |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
519 |
dialog.Destroy() |
0 | 520 |
event.Skip() |
521 |
||
522 |
def SaveProject(self): |
|
523 |
result = self.Controler.SaveXMLFile() |
|
524 |
if not result: |
|
525 |
self.SaveProjectAs() |
|
526 |
||
527 |
def SaveProjectAs(self): |
|
528 |
filepath = self.Controler.GetFilePath() |
|
529 |
if filepath != "": |
|
530 |
directory, filename = os.path.split(filepath) |
|
531 |
else: |
|
532 |
directory, filename = os.getcwd(), "%s.od"%self.Controler.GetProjectName() |
|
533 |
dialog = wxFileDialog(self, "Choose a file", directory, filename, "PLCOpen files (*.xml)|*.xml|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT) |
|
534 |
if dialog.ShowModal() == wxID_OK: |
|
535 |
filepath = dialog.GetPath() |
|
536 |
if os.path.isdir(os.path.dirname(filepath)): |
|
537 |
result = self.Controler.SaveXMLFile(filepath) |
|
538 |
if not result: |
|
539 |
message = wxMessageDialog(self, "Can't save project to file %s!"%filepath, "Error", wxOK|wxICON_ERROR) |
|
540 |
message.ShowModal() |
|
541 |
message.Destroy() |
|
542 |
else: |
|
543 |
message = wxMessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR) |
|
544 |
message.ShowModal() |
|
545 |
message.Destroy() |
|
546 |
dialog.Destroy() |
|
547 |
||
548 |
def OnQuitMenu(self, event): |
|
6 | 549 |
self.ToolBar.Reparent(self) |
550 |
self.Controler.Reset() |
|
0 | 551 |
self.Close() |
552 |
event.Skip() |
|
553 |
||
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
554 |
def ResetCurrentMode(self): |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
555 |
selected = self.TabsOpened.GetSelection() |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
556 |
if selected != -1: |
6 | 557 |
window = self.TabsOpened.GetPage(selected) |
558 |
if not isinstance(window, TextViewer): |
|
559 |
window.SetMode(MODE_SELECTION) |
|
560 |
self.ToolBar.ToggleTool(wxID_PLCOPENEDITORTOOLBARITEMS0, True) |
|
561 |
||
562 |
def ResetToolToggle(self, id): |
|
563 |
tool = self.ToolBar.FindById(id) |
|
564 |
tool.SetToggle(False) |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
565 |
|
0 | 566 |
def OnSelectionTool(self, event): |
567 |
selected = self.TabsOpened.GetSelection() |
|
568 |
if selected != -1: |
|
569 |
self.TabsOpened.GetPage(selected).SetMode(MODE_SELECTION) |
|
570 |
event.Skip() |
|
571 |
||
6 | 572 |
def OnSFCCommentTool(self, event): |
573 |
self.ResetToolToggle(wxID_PLCOPENEDITORSFCTOOLBARITEMS1) |
|
0 | 574 |
selected = self.TabsOpened.GetSelection() |
575 |
if selected != -1: |
|
576 |
self.TabsOpened.GetPage(selected).SetMode(MODE_COMMENT) |
|
577 |
event.Skip() |
|
578 |
||
579 |
def OnSFCInitialStepTool(self, event): |
|
6 | 580 |
self.ResetToolToggle(wxID_PLCOPENEDITORSFCTOOLBARITEMS2) |
0 | 581 |
selected = self.TabsOpened.GetSelection() |
582 |
if selected != -1: |
|
583 |
self.TabsOpened.GetPage(selected).SetMode(MODE_INITIAL_STEP) |
|
584 |
event.Skip() |
|
585 |
||
586 |
def OnSFCStepTool(self, event): |
|
587 |
selected = self.TabsOpened.GetSelection() |
|
588 |
if selected != -1: |
|
589 |
self.TabsOpened.GetPage(selected).AddStep() |
|
590 |
event.Skip() |
|
591 |
||
592 |
def OnSFCActionBlockTool(self, event): |
|
593 |
selected = self.TabsOpened.GetSelection() |
|
594 |
if selected != -1: |
|
595 |
self.TabsOpened.GetPage(selected).AddStepAction() |
|
596 |
event.Skip() |
|
597 |
||
598 |
def OnSFCDivergenceTool(self, event): |
|
599 |
selected = self.TabsOpened.GetSelection() |
|
600 |
if selected != -1: |
|
601 |
self.TabsOpened.GetPage(selected).AddDivergence() |
|
602 |
event.Skip() |
|
603 |
||
604 |
def OnSFCJumpTool(self, event): |
|
605 |
selected = self.TabsOpened.GetSelection() |
|
606 |
if selected != -1: |
|
607 |
self.TabsOpened.GetPage(selected).AddJump() |
|
608 |
event.Skip() |
|
609 |
||
6 | 610 |
def OnFBDCommentTool(self, event): |
611 |
self.ResetToolToggle(wxID_PLCOPENEDITORFBDTOOLBARITEMS1) |
|
612 |
selected = self.TabsOpened.GetSelection() |
|
613 |
if selected != -1: |
|
614 |
self.TabsOpened.GetPage(selected).SetMode(MODE_COMMENT) |
|
615 |
event.Skip() |
|
616 |
||
0 | 617 |
def OnFBDVariableTool(self, event): |
6 | 618 |
self.ResetToolToggle(wxID_PLCOPENEDITORFBDTOOLBARITEMS2) |
0 | 619 |
selected = self.TabsOpened.GetSelection() |
620 |
if selected != -1: |
|
621 |
self.TabsOpened.GetPage(selected).SetMode(MODE_VARIABLE) |
|
622 |
event.Skip() |
|
623 |
||
624 |
def OnFBDBlockTool(self, event): |
|
6 | 625 |
self.ResetToolToggle(wxID_PLCOPENEDITORFBDTOOLBARITEMS3) |
0 | 626 |
selected = self.TabsOpened.GetSelection() |
627 |
if selected != -1: |
|
628 |
self.TabsOpened.GetPage(selected).SetMode(MODE_BLOCK) |
|
629 |
event.Skip() |
|
630 |
||
631 |
def OnFBDConnectionTool(self, event): |
|
6 | 632 |
self.ResetToolToggle(wxID_PLCOPENEDITORFBDTOOLBARITEMS4) |
0 | 633 |
selected = self.TabsOpened.GetSelection() |
634 |
if selected != -1: |
|
635 |
self.TabsOpened.GetPage(selected).SetMode(MODE_CONNECTION) |
|
636 |
event.Skip() |
|
637 |
||
6 | 638 |
def OnFBDWireTool(self, event): |
639 |
self.ResetToolToggle(wxID_PLCOPENEDITORFBDTOOLBARITEMS5) |
|
640 |
selected = self.TabsOpened.GetSelection() |
|
641 |
if selected != -1: |
|
642 |
self.TabsOpened.GetPage(selected).SetMode(MODE_WIRE) |
|
643 |
event.Skip() |
|
644 |
||
0 | 645 |
def OnLDCoilTool(self, event): |
646 |
selected = self.TabsOpened.GetSelection() |
|
647 |
if selected != -1: |
|
648 |
self.TabsOpened.GetPage(selected).AddRung() |
|
649 |
event.Skip() |
|
650 |
||
651 |
def OnLDContactTool(self, event): |
|
652 |
selected = self.TabsOpened.GetSelection() |
|
653 |
if selected != -1: |
|
654 |
self.TabsOpened.GetPage(selected).AddContact() |
|
655 |
event.Skip() |
|
656 |
||
657 |
def OnLDBlockTool(self, event): |
|
658 |
selected = self.TabsOpened.GetSelection() |
|
659 |
if selected != -1: |
|
7 | 660 |
self.TabsOpened.GetPage(selected).AddBlock() |
0 | 661 |
event.Skip() |
662 |
||
663 |
def OnLDBranchTool(self, event): |
|
664 |
selected = self.TabsOpened.GetSelection() |
|
665 |
if selected != -1: |
|
666 |
self.TabsOpened.GetPage(selected).AddBranch() |
|
667 |
event.Skip() |
|
668 |
||
669 |
def OnPouSelectedChanged(self, event): |
|
670 |
selected = event.GetSelection() |
|
671 |
if selected >= 0: |
|
672 |
self.Controler.RefreshCurrentElementEditing(selected) |
|
673 |
found = False |
|
674 |
name = self.TabsOpened.GetPageText(selected) |
|
675 |
root = self.ProjectTree.GetRootItem() |
|
676 |
item, root_cookie = self.ProjectTree.GetFirstChild(root) |
|
677 |
while item.IsOk() and not found: |
|
678 |
if self.ProjectTree.GetItemText(item) == name: |
|
679 |
self.ProjectTree.SelectItem(item) |
|
680 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
|
681 |
self.RefreshFileMenu() |
|
682 |
self.RefreshEditMenu() |
|
683 |
self.RefreshToolBar() |
|
684 |
event.Skip() |
|
685 |
||
7 | 686 |
def OnProjectTreeBeginDrag(self, event): |
687 |
item = event.GetItem() |
|
688 |
if self.ProjectTree.GetPyData(item) == ITEM_VARIABLE: |
|
689 |
data = wxTextDataObject(self.ProjectTree.GetItemText(item)) |
|
690 |
dragSource = wxDropSource(self.ProjectTree) |
|
691 |
dragSource.SetData(data) |
|
692 |
dragSource.DoDragDrop() |
|
693 |
event.Skip() |
|
694 |
||
0 | 695 |
def OnProjectTreeItemEndEdit(self, event): |
6 | 696 |
message = None |
697 |
abort = False |
|
0 | 698 |
new_name = event.GetLabel() |
699 |
if new_name != "": |
|
6 | 700 |
if not TestIdentifier(new_name): |
701 |
message = "\"%s\" is not a valid identifier!"%new_name |
|
702 |
elif new_name.upper() in IEC_KEYWORDS: |
|
703 |
message = "\"%s\" is a keyword. It can't be used!"%new_name |
|
704 |
else: |
|
0 | 705 |
item = event.GetItem() |
706 |
itemtype = self.ProjectTree.GetPyData(item) |
|
707 |
if itemtype == ITEM_PROJECT: |
|
708 |
self.Controler.SetProjectName(new_name) |
|
709 |
elif itemtype == ITEM_POU: |
|
6 | 710 |
if new_name.upper() in self.Controler.GetProjectPouNames(): |
711 |
message = "\"%s\" pou already exists!"%new_name |
|
712 |
abort = True |
|
713 |
elif new_name.upper() in self.Controler.GetProjectPouVariables(): |
|
714 |
messageDialog = wxMessageDialog(self, "A variable is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wxYES_NO|wxICON_QUESTION) |
|
715 |
if messageDialog.ShowModal() == wxID_NO: |
|
716 |
abort = True |
|
717 |
messageDialog.Destroy() |
|
718 |
if not abort: |
|
719 |
old_name = self.ProjectTree.GetItemText(item) |
|
720 |
self.Controler.ChangePouName(old_name, new_name) |
|
721 |
self.RefreshTabsOpenedTitles() |
|
0 | 722 |
elif itemtype == ITEM_TRANSITION: |
6 | 723 |
category = self.ProjectTree.GetItemParent(item) |
724 |
pou = self.ProjectTree.GetItemParent(category) |
|
725 |
pou_name = self.ProjectTree.GetItemText(pou) |
|
726 |
if new_name.upper() in self.Controler.GetProjectPouNames(): |
|
727 |
message = "A pou with \"%s\" as name exists!"%new_name |
|
728 |
elif new_name.upper() in self.Controler.GetProjectPouVariables(pou_name): |
|
729 |
message = "A variable with \"%s\" as name already exists in this pou!"%new_name |
|
730 |
else: |
|
731 |
old_name = self.ProjectTree.GetItemText(item) |
|
732 |
self.Controler.ChangePouTransitionName(pou_name, old_name, new_name) |
|
733 |
self.RefreshTabsOpenedTitles() |
|
0 | 734 |
elif itemtype == ITEM_ACTION: |
6 | 735 |
category = self.ProjectTree.GetItemParent(item) |
736 |
pou = self.ProjectTree.GetItemParent(category) |
|
737 |
pou_name = self.ProjectTree.GetItemText(pou) |
|
738 |
if new_name.upper() in self.Controler.GetProjectPouNames(): |
|
739 |
message = "A pou with \"%s\" as name exists!"%new_name |
|
740 |
elif new_name.upper() in self.Controler.GetProjectPouVariables(pou_name): |
|
741 |
message = "A variable with \"%s\" as name already exists in this pou!"%new_name |
|
742 |
else: |
|
743 |
old_name = self.ProjectTree.GetItemText(item) |
|
744 |
self.Controler.ChangePouActionName(pou_name, old_name, new_name) |
|
745 |
self.RefreshTabsOpenedTitles() |
|
746 |
elif itemtype == ITEM_VARIABLE: |
|
747 |
category = self.ProjectTree.GetItemParent(item) |
|
748 |
if self.ProjectTree.GetItemText(category) != 'Global': |
|
749 |
category = self.ProjectTree.GetItemParent(category) |
|
750 |
pou = self.ProjectTree.GetItemParent(category) |
|
751 |
pou_name = self.ProjectTree.GetItemText(pou) |
|
752 |
if new_name.upper() in self.Controler.GetProjectPouNames(): |
|
753 |
message = "A pou with \"%s\" as name exists!"%new_name |
|
754 |
elif new_name.upper() in self.Controler.GetProjectPouVariables(pou_name): |
|
755 |
message = "A variable with \"%s\" as name already exists in this pou!"%new_name |
|
756 |
else: |
|
757 |
old_name = self.ProjectTree.GetItemText(item) |
|
758 |
self.Controler.ChangePouVariableName(pou_name, old_name, new_name) |
|
759 |
self.RefreshTabsOpenedTitles() |
|
760 |
if message or abort: |
|
761 |
if message: |
|
762 |
messageDialog = wxMessageDialog(self, message, "Error", wxOK|wxICON_ERROR) |
|
763 |
messageDialog.ShowModal() |
|
764 |
messageDialog.Destroy() |
|
0 | 765 |
item = event.GetItem() |
766 |
wxCallAfter(self.ProjectTree.EditLabel, item) |
|
767 |
event.Veto() |
|
6 | 768 |
else: |
769 |
wxCallAfter(self.RefreshProjectTree) |
|
770 |
event.Skip() |
|
0 | 771 |
|
772 |
def OnProjectTreeItemBeginEdit(self, event): |
|
773 |
selected = event.GetItem() |
|
774 |
if self.ProjectTree.GetPyData(selected) == ITEM_UNEDITABLE: |
|
775 |
event.Veto() |
|
776 |
else: |
|
777 |
event.Skip() |
|
778 |
||
779 |
def OnProjectTreeItemActivated(self, event): |
|
780 |
selected = event.GetItem() |
|
781 |
if self.ProjectTree.IsExpanded(selected): |
|
782 |
self.ProjectTree.Collapse(selected) |
|
783 |
else: |
|
784 |
self.ProjectTree.Expand(selected) |
|
785 |
name = self.ProjectTree.GetItemText(selected) |
|
786 |
data = self.ProjectTree.GetPyData(selected) |
|
787 |
if name == "Properties": |
|
788 |
old_values = self.Controler.GetProjectProperties() |
|
789 |
old_values["projectName"] = self.Controler.GetProjectName() |
|
790 |
dialog = ProjectDialog(self) |
|
791 |
dialog.SetValues(old_values) |
|
792 |
if dialog.ShowModal() == wxID_OK: |
|
793 |
new_values = dialog.GetValues() |
|
794 |
projectname = new_values.pop("projectName") |
|
795 |
new_values["creationDateTime"] = old_values["creationDateTime"] |
|
796 |
self.Controler.SetProjectName(projectname) |
|
797 |
self.Controler.SetProjectProperties(new_values) |
|
798 |
self.RefreshProjectTree() |
|
799 |
dialog.Destroy() |
|
800 |
elif data == ITEM_CLASS: |
|
801 |
item = self.ProjectTree.GetItemParent(selected) |
|
802 |
item_type = self.ProjectTree.GetPyData(item) |
|
10
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
803 |
while item_type not in [ITEM_POU, ITEM_RESOURCE, ITEM_CONFIGURATION] and item.IsOk(): |
0 | 804 |
item = self.ProjectTree.GetItemParent(item) |
805 |
item_type = self.ProjectTree.GetPyData(item) |
|
10
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
806 |
item_name = self.ProjectTree.GetItemText(item) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
807 |
if item_type == ITEM_POU: |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
808 |
dialog = EditVariableDialog(self, item_name, self.Controler.GetPouType(item_name), name) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
809 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
810 |
values = {} |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
811 |
values["returnType"] = self.Controler.GetPouInterfaceReturnTypeByName(item_name) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
812 |
values["data"] = self.Controler.GetPouInterfaceVarsByName(item_name) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
813 |
dialog.SetValues(values) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
814 |
if dialog.ShowModal() == wxID_OK: |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
815 |
if not self.Controler.PouIsUsed(item_name): |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
816 |
new_values = dialog.GetValues() |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
817 |
if "returnType" in new_values: |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
818 |
self.Controler.SetPouInterfaceReturnType(item_name, new_values["returnType"]) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
819 |
self.Controler.SetPouInterfaceVars(item_name, new_values["data"]) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
820 |
pou_names = self.Controler.GetElementsOpenedNames() |
11 | 821 |
if item_name in pou_names: |
10
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
822 |
window = self.TabsOpened.GetPage(pou_names.index(item_name)) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
823 |
if isinstance(window, TextViewer): |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
824 |
varlist = [] |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
825 |
if "returnType" in new_values: |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
826 |
varlist.append(name) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
827 |
for var in new_values["data"]: |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
828 |
varlist.append(var["Name"]) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
829 |
window.SetVariables(varlist) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
830 |
else: |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
831 |
message = wxMessageDialog(self, "\"%s\" is used by one or more POUs. Its interface can't be changed!"%pou_name, "Error", wxOK|wxICON_ERROR) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
832 |
message.ShowModal() |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
833 |
message.Destroy() |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
834 |
dialog.Destroy() |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
835 |
self.RefreshProjectTree() |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
836 |
elif item_type == ITEM_CONFIGURATION: |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
837 |
dialog = EditVariableDialog(self, item_name, None, name) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
838 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
839 |
values = {"data" : self.Controler.GetConfigurationGlobalVars(item_name)} |
0 | 840 |
dialog.SetValues(values) |
841 |
if dialog.ShowModal() == wxID_OK: |
|
842 |
new_values = dialog.GetValues() |
|
10
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
843 |
self.Controler.SetConfigurationGlobalVars(item_name, new_values["data"]) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
844 |
dialog.Destroy() |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
845 |
self.RefreshProjectTree() |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
846 |
elif item_type == ITEM_RESOURCE: |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
847 |
config = self.ProjectTree.GetItemParent(item) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
848 |
config_type = self.ProjectTree.GetPyData(config) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
849 |
while config_type != ITEM_CONFIGURATION and config.IsOk(): |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
850 |
config = self.ProjectTree.GetItemParent(config) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
851 |
config_type = self.ProjectTree.GetPyData(config) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
852 |
if config.IsOk(): |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
853 |
config_name = self.ProjectTree.GetItemText(config) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
854 |
dialog = EditVariableDialog(self, item_name, None, name) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
855 |
values = {"data" : self.Controler.GetConfigurationResourceGlobalVars(config_name, item_name)} |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
856 |
dialog.SetValues(values) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
857 |
if dialog.ShowModal() == wxID_OK: |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
858 |
new_values = dialog.GetValues() |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
859 |
self.Controler.SetConfigurationResourceGlobalVars(config_name, item_name, new_values["data"]) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
860 |
dialog.Destroy() |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
861 |
self.RefreshProjectTree() |
0 | 862 |
elif data in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]: |
863 |
if data == ITEM_POU: |
|
864 |
idx = self.Controler.OpenElementEditing(name) |
|
865 |
language = self.Controler.GetPouBodyType(name) |
|
866 |
varlist = [] |
|
867 |
returnType = self.Controler.GetPouInterfaceReturnTypeByName(name) |
|
868 |
if returnType: |
|
869 |
varlist.append(name) |
|
870 |
vars = self.Controler.GetPouInterfaceVarsByName(name) |
|
871 |
if vars: |
|
872 |
for var in vars: |
|
873 |
varlist.append(var["Name"]) |
|
874 |
else: |
|
875 |
parent = self.ProjectTree.GetItemParent(selected) |
|
876 |
parent_name = self.ProjectTree.GetItemText(parent) |
|
877 |
grandparent = self.ProjectTree.GetItemParent(parent) |
|
878 |
grandparent_name = self.ProjectTree.GetItemText(grandparent) |
|
879 |
if data == ITEM_TRANSITION: |
|
880 |
idx = self.Controler.OpenPouTransitionEditing(grandparent_name, name) |
|
881 |
language = self.Controler.GetTransitionBodyType(grandparent_name, name) |
|
882 |
elif data == ITEM_ACTION: |
|
883 |
idx = self.Controler.OpenPouActionEditing(grandparent_name, name) |
|
884 |
language = self.Controler.GetActionBodyType(grandparent_name, name) |
|
885 |
varlist = [name] |
|
886 |
vars = self.Controler.GetPouInterfaceVarsByName(grandparent_name) |
|
887 |
if vars: |
|
888 |
for var in vars: |
|
889 |
varlist.append(var["Name"]) |
|
890 |
if idx != None: |
|
891 |
if language == "FBD": |
|
892 |
new_window = FBD_Viewer(self.TabsOpened, self, self.Controler) |
|
893 |
elif language == "LD": |
|
894 |
new_window = LD_Viewer(self.TabsOpened, self, self.Controler) |
|
895 |
elif language == "SFC": |
|
896 |
new_window = SFC_Viewer(self.TabsOpened, self, self.Controler) |
|
897 |
elif language in ["IL", "ST"]: |
|
898 |
new_window = TextViewer(self.TabsOpened, self, self.Controler) |
|
8 | 899 |
new_window.SetTextSyntax(language) |
0 | 900 |
if language == "IL": |
901 |
new_window.SetKeywords(IL_KEYWORDS) |
|
902 |
else: |
|
903 |
new_window.SetKeywords(ST_KEYWORDS) |
|
904 |
new_window.SetVariables(varlist) |
|
905 |
new_window.SetFunctions(self.Controler.GetBlockTypes()) |
|
906 |
else: |
|
907 |
return |
|
908 |
new_window.RefreshView() |
|
909 |
self.TabsOpened.AddPage(new_window, "") |
|
910 |
self.TabsOpened.SetSelection(idx) |
|
911 |
self.RefreshTabsOpenedTitles() |
|
912 |
self.RefreshFileMenu() |
|
913 |
self.RefreshEditMenu() |
|
914 |
self.RefreshToolBar() |
|
915 |
else: |
|
916 |
if data == ITEM_POU: |
|
917 |
idx = self.Controler.ChangeElementEditing(name) |
|
918 |
elif data == ITEM_TRANSITION: |
|
919 |
idx = self.Controler.ChangePouTransitionEditing(grandparent_name, name) |
|
920 |
elif data == ITEM_ACTION: |
|
921 |
idx = self.Controler.ChangePouActionEditing(grandparent_name, name) |
|
922 |
if idx != None: |
|
923 |
self.TabsOpened.SetSelection(idx) |
|
924 |
self.RefreshFileMenu() |
|
925 |
self.RefreshEditMenu() |
|
926 |
self.RefreshToolBar() |
|
927 |
elif data == ITEM_RESOURCE: |
|
928 |
item = self.ProjectTree.GetItemParent(selected) |
|
929 |
item_type = self.ProjectTree.GetPyData(item) |
|
930 |
while item_type != ITEM_CONFIGURATION: |
|
931 |
item = self.ProjectTree.GetItemParent(item) |
|
932 |
item_type = self.ProjectTree.GetPyData(item) |
|
933 |
config_name = self.ProjectTree.GetItemText(item) |
|
934 |
idx = self.Controler.OpenConfigurationResourceEditing(config_name, name) |
|
935 |
if idx != None: |
|
936 |
new_window = ResourceEditor(self.TabsOpened, self, self.Controler) |
|
937 |
new_window.RefreshView() |
|
938 |
self.TabsOpened.AddPage(new_window, "") |
|
939 |
self.TabsOpened.SetSelection(idx) |
|
940 |
self.RefreshTabsOpenedTitles() |
|
941 |
self.RefreshFileMenu() |
|
942 |
self.RefreshEditMenu() |
|
943 |
self.RefreshToolBar() |
|
944 |
else: |
|
945 |
idx = self.Controler.ChangeConfigurationResourceEditing(parent_name, name) |
|
946 |
if idx != None: |
|
947 |
self.TabsOpened.SetSelection(idx) |
|
948 |
self.RefreshFileMenu() |
|
949 |
self.RefreshEditMenu() |
|
950 |
self.RefreshToolBar() |
|
951 |
||
952 |
def OnProjectTreeRightUp(self, event): |
|
953 |
selected = self.ProjectTree.GetSelection() |
|
954 |
if self.ProjectTree.GetPyData(selected) == ITEM_POU: |
|
955 |
name = self.ProjectTree.GetItemText(selected) |
|
956 |
if self.Controler.GetPouBodyType(name) == "SFC": |
|
957 |
self.PopupMenu(self.SFCMenu) |
|
958 |
elif self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION: |
|
959 |
self.PopupMenu(self.ConfigMenu) |
|
960 |
event.Skip() |
|
961 |
||
962 |
def OnProjectTreeItemSelected(self, event): |
|
963 |
selected = event.GetItem() |
|
964 |
name = self.ProjectTree.GetItemText(selected) |
|
965 |
if self.ProjectTree.GetItemParent(selected) == self.ProjectTree.GetRootItem() and name != "Properties": |
|
966 |
if self.Controler.IsElementEditing(name): |
|
967 |
idx = self.Controler.ChangeElementEditing(name) |
|
968 |
if idx != None: |
|
969 |
self.TabsOpened.SetSelection(idx) |
|
970 |
self.RefreshFileMenu() |
|
971 |
self.RefreshEditMenu() |
|
972 |
self.RefreshToolBar() |
|
973 |
else: |
|
974 |
name = self.ProjectTree.GetItemText(selected) |
|
975 |
parent = self.ProjectTree.GetItemParent(selected) |
|
976 |
parent_name = self.ProjectTree.GetItemText(parent) |
|
977 |
grandparent = self.ProjectTree.GetItemParent(parent) |
|
978 |
grandparent_name = self.ProjectTree.GetItemText(grandparent) |
|
979 |
if parent_name == "Transitions": |
|
980 |
idx = self.Controler.ChangePouTransitionEditing(grandparent_name, name) |
|
981 |
if idx != None: |
|
982 |
self.TabsOpened.SetSelection(idx) |
|
983 |
self.RefreshFileMenu() |
|
984 |
self.RefreshEditMenu() |
|
985 |
self.RefreshToolBar() |
|
986 |
elif parent_name == "Action": |
|
987 |
idx = self.Controler.ChangePouActionEditing(grandparent_name, name) |
|
988 |
if idx != None: |
|
989 |
self.TabsOpened.SetSelection(idx) |
|
990 |
self.RefreshFileMenu() |
|
991 |
self.RefreshEditMenu() |
|
992 |
self.RefreshToolBar() |
|
993 |
event.Skip() |
|
994 |
||
995 |
def RefreshProjectTree(self): |
|
996 |
infos = self.Controler.GetProjectInfos() |
|
997 |
root = self.ProjectTree.GetRootItem() |
|
998 |
self.GenerateTreeBranch(root, infos) |
|
999 |
self.ProjectTree.Expand(self.ProjectTree.GetRootItem()) |
|
1000 |
||
1001 |
def GenerateTreeBranch(self, root, infos): |
|
1002 |
to_delete = [] |
|
1003 |
if root.IsOk(): |
|
1004 |
self.ProjectTree.SetItemText(root, infos["name"]) |
|
1005 |
else: |
|
1006 |
root = self.ProjectTree.AddRoot(infos["name"]) |
|
1007 |
self.ProjectTree.SetPyData(root, infos["type"]) |
|
9 | 1008 |
if infos["type"] == ITEM_POU: |
1009 |
self.ProjectTree.SetItemImage(root, LANGUAGES.index(self.Controler.GetPouBodyType(infos["name"]))) |
|
0 | 1010 |
item, root_cookie = self.ProjectTree.GetFirstChild(root) |
1011 |
if len(infos["values"]) > 0: |
|
1012 |
for values in infos["values"]: |
|
1013 |
if not item.IsOk(): |
|
1014 |
item = self.ProjectTree.AppendItem(root, "") |
|
1015 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
|
1016 |
self.GenerateTreeBranch(item, values) |
|
1017 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
|
1018 |
while item.IsOk(): |
|
1019 |
to_delete.append(item) |
|
1020 |
item, root_cookie = self.ProjectTree.GetNextChild(item, root_cookie) |
|
1021 |
for item in to_delete: |
|
1022 |
self.ProjectTree.Delete(item) |
|
1023 |
||
6 | 1024 |
def ResetToolBar(self): |
1025 |
for item in self.CurrentToolBar: |
|
1026 |
self.ToolBar.DeleteTool(item) |
|
1027 |
||
0 | 1028 |
def RefreshToolBar(self): |
1029 |
language = self.Controler.GetCurrentElementEditingBodyType() |
|
1030 |
if language == "SFC": |
|
6 | 1031 |
if self.CurrentToolBar != SFC_ITEMS: |
1032 |
self.ResetToolBar() |
|
1033 |
self.CurrentToolBar = SFC_ITEMS |
|
1034 |
self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS1, |
|
1035 |
wxBitmap(os.path.join(CWD, 'Images/comment.png')), wxNullBitmap, "Create a new comment") |
|
1036 |
self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS2, |
|
1037 |
wxBitmap(os.path.join(CWD, 'Images/initial_step.png')), wxNullBitmap, "Create a new initial step") |
|
1038 |
self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS3, |
|
1039 |
wxBitmap(os.path.join(CWD, 'Images/step.png')), "Create a new step") |
|
1040 |
self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS4, |
|
1041 |
wxBitmap(os.path.join(CWD, 'Images/action.png')), "Add action block to step") |
|
1042 |
self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS5, |
|
1043 |
wxBitmap(os.path.join(CWD, 'Images/divergence.png')), "Create a new divergence") |
|
1044 |
self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS6, |
|
1045 |
wxBitmap(os.path.join(CWD, 'Images/jump.png')), "Create a new jump") |
|
1046 |
self.Bind(wx.EVT_TOOL, self.OnSFCCommentTool, |
|
1047 |
id=wxID_PLCOPENEDITORSFCTOOLBARITEMS1) |
|
1048 |
self.Bind(wx.EVT_TOOL, self.OnSFCInitialStepTool, |
|
1049 |
id=wxID_PLCOPENEDITORSFCTOOLBARITEMS2) |
|
1050 |
self.Bind(wx.EVT_TOOL, self.OnSFCStepTool, |
|
1051 |
id=wxID_PLCOPENEDITORSFCTOOLBARITEMS3) |
|
1052 |
self.Bind(wx.EVT_TOOL, self.OnSFCActionBlockTool, |
|
1053 |
id=wxID_PLCOPENEDITORSFCTOOLBARITEMS4) |
|
1054 |
self.Bind(wx.EVT_TOOL, self.OnSFCDivergenceTool, |
|
1055 |
id=wxID_PLCOPENEDITORSFCTOOLBARITEMS5) |
|
1056 |
self.Bind(wx.EVT_TOOL, self.OnSFCJumpTool, |
|
1057 |
id=wxID_PLCOPENEDITORSFCTOOLBARITEMS6) |
|
0 | 1058 |
elif language == "FBD": |
6 | 1059 |
if self.CurrentToolBar != FBD_ITEMS: |
1060 |
self.ResetToolBar() |
|
1061 |
self.CurrentToolBar = FBD_ITEMS |
|
1062 |
self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS1, |
|
1063 |
wxBitmap(os.path.join(CWD, 'Images/comment.png')), wxNullBitmap, "Create a new comment") |
|
1064 |
self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS2, |
|
1065 |
wxBitmap(os.path.join(CWD, 'Images/variable.png')), wxNullBitmap, "Create a new variable") |
|
1066 |
self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS3, |
|
1067 |
wxBitmap(os.path.join(CWD, 'Images/block.png')), wxNullBitmap, "Create a new block") |
|
1068 |
self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS4, |
|
1069 |
wxBitmap(os.path.join(CWD, 'Images/connection.png')), wxNullBitmap, "Create a new connection") |
|
1070 |
self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS5, |
|
1071 |
wxBitmap(os.path.join(CWD, 'Images/wire.png')), wxNullBitmap, "Create a new wire") |
|
1072 |
self.Bind(wx.EVT_TOOL, self.OnFBDCommentTool, |
|
1073 |
id=wxID_PLCOPENEDITORFBDTOOLBARITEMS1) |
|
1074 |
self.Bind(wx.EVT_TOOL, self.OnFBDVariableTool, |
|
1075 |
id=wxID_PLCOPENEDITORFBDTOOLBARITEMS2) |
|
1076 |
self.Bind(wx.EVT_TOOL, self.OnFBDBlockTool, |
|
1077 |
id=wxID_PLCOPENEDITORFBDTOOLBARITEMS3) |
|
1078 |
self.Bind(wx.EVT_TOOL, self.OnFBDConnectionTool, |
|
1079 |
id=wxID_PLCOPENEDITORFBDTOOLBARITEMS4) |
|
1080 |
self.Bind(wx.EVT_TOOL, self.OnFBDWireTool, |
|
1081 |
id=wxID_PLCOPENEDITORFBDTOOLBARITEMS5) |
|
0 | 1082 |
elif language == "LD": |
6 | 1083 |
if self.CurrentToolBar != LD_ITEMS: |
1084 |
self.ResetToolBar() |
|
1085 |
self.CurrentToolBar = LD_ITEMS |
|
1086 |
self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS1, |
|
1087 |
wxBitmap(os.path.join(CWD, 'Images/coil.png')), "Create a new rung") |
|
1088 |
self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS2, |
|
1089 |
wxBitmap(os.path.join(CWD, 'Images/contact.png')), "Create a new contact") |
|
1090 |
self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS3, |
|
1091 |
wxBitmap(os.path.join(CWD, 'Images/block.png')), "Create a new block") |
|
1092 |
self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS4, |
|
1093 |
wxBitmap(os.path.join(CWD, 'Images/branch.png')), "Create a new branch") |
|
1094 |
self.Bind(wx.EVT_TOOL, self.OnLDCoilTool, |
|
1095 |
id=wxID_PLCOPENEDITORLDTOOLBARITEMS1) |
|
1096 |
self.Bind(wx.EVT_TOOL, self.OnLDContactTool, |
|
1097 |
id=wxID_PLCOPENEDITORLDTOOLBARITEMS2) |
|
1098 |
self.Bind(wx.EVT_TOOL, self.OnLDBlockTool, |
|
1099 |
id=wxID_PLCOPENEDITORLDTOOLBARITEMS3) |
|
1100 |
self.Bind(wx.EVT_TOOL, self.OnLDBranchTool, |
|
1101 |
id=wxID_PLCOPENEDITORLDTOOLBARITEMS4) |
|
0 | 1102 |
else: |
6 | 1103 |
if len(self.CurrentToolBar) > 0: |
1104 |
self.ResetToolBar() |
|
1105 |
self.CurrentToolBar = [] |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1106 |
self.ResetCurrentMode() |
0 | 1107 |
|
1108 |
def RefreshTabsOpenedTitles(self): |
|
1109 |
pous = self.Controler.GetElementsOpenedNames() |
|
1110 |
for i, pou in enumerate(pous): |
|
1111 |
self.TabsOpened.SetPageText(i, pou) |
|
1112 |
||
1113 |
def OnRefreshMenu(self, event): |
|
1114 |
selected = self.TabsOpened.GetSelection() |
|
1115 |
if selected != -1: |
|
1116 |
self.TabsOpened.GetPage(selected).Refresh() |
|
1117 |
event.Skip() |
|
1118 |
||
1119 |
def OnCutMenu(self, event): |
|
1120 |
selected = self.TabsOpened.GetSelection() |
|
1121 |
if selected != -1: |
|
1122 |
self.TabsOpened.GetPage(selected).Cut() |
|
1123 |
event.Skip() |
|
1124 |
||
1125 |
def OnCopyMenu(self, event): |
|
1126 |
selected = self.TabsOpened.GetSelection() |
|
1127 |
if selected != -1: |
|
1128 |
self.TabsOpened.GetPage(selected).Copy() |
|
1129 |
event.Skip() |
|
1130 |
||
1131 |
def OnPasteMenu(self, event): |
|
1132 |
selected = self.TabsOpened.GetSelection() |
|
1133 |
if selected != -1: |
|
1134 |
self.TabsOpened.GetPage(selected).Paste() |
|
1135 |
event.Skip() |
|
1136 |
||
1137 |
def OnAddPouMenu(self, event): |
|
1138 |
dialog = PouDialog(self) |
|
1139 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
|
1140 |
if dialog.ShowModal() == wxID_OK: |
|
1141 |
values = dialog.GetValues() |
|
1142 |
self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"]) |
|
1143 |
self.RefreshProjectTree() |
|
1144 |
dialog.Destroy() |
|
1145 |
event.Skip() |
|
1146 |
||
1147 |
def OnRemovePouMenu(self, event): |
|
1148 |
pous = self.Controler.GetProjectPouNames() |
|
1149 |
dialog = wxSingleChoiceDialog(self, "Select POU to remove:", "POU Remove", pous, wxOK|wxCANCEL) |
|
1150 |
if dialog.ShowModal() == wxID_OK: |
|
1151 |
selected = dialog.GetStringSelection() |
|
1152 |
if not self.Controler.PouIsUsed(selected): |
|
1153 |
self.Controler.ProjectRemovePou(selected) |
|
1154 |
for i in xrange(self.TabsOpened.GetPageCount()): |
|
1155 |
if self.TabsOpened.GetPageText(i) == selected: |
|
1156 |
self.TabsOpened.DeletePage(i) |
|
1157 |
self.RefreshProjectTree() |
|
1158 |
self.RefreshToolBar() |
|
1159 |
else: |
|
1160 |
message = wxMessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wxOK|wxICON_ERROR) |
|
1161 |
message.ShowModal() |
|
1162 |
message.Destroy() |
|
1163 |
event.Skip() |
|
1164 |
||
1165 |
def OnAddConfigurationMenu(self, event): |
|
1166 |
dialog = wxTextEntryDialog(self, "Enter configuration name:", "Create new configuration", "", wxOK|wxCANCEL) |
|
1167 |
if dialog.ShowModal() == wxID_OK: |
|
1168 |
value = dialog.GetValue() |
|
1169 |
self.Controler.ProjectAddConfiguration(value) |
|
1170 |
self.RefreshProjectTree() |
|
1171 |
dialog.Destroy() |
|
1172 |
event.Skip() |
|
1173 |
||
1174 |
def OnRemoveConfigurationMenu(self, event): |
|
1175 |
configs = self.Controler.GetProjectConfigNames() |
|
1176 |
dialog = wxSingleChoiceDialog(self, "Select Configuration to remove:", "Configuration Remove", configs, wxOK|wxCANCEL) |
|
1177 |
if dialog.ShowModal() == wxID_OK: |
|
1178 |
selected = dialog.GetStringSelection() |
|
1179 |
self.Controler.ProjectRemoveConfiguration(selected) |
|
1180 |
self.RefreshProjectTree() |
|
1181 |
event.Skip() |
|
1182 |
||
1183 |
def OnAddPouTransitionMenu(self, event): |
|
1184 |
dialog = PouTransitionDialog(self) |
|
1185 |
dialog.SetPous(self.Controler.GetSFCPous()) |
|
1186 |
if dialog.ShowModal() == wxID_OK: |
|
1187 |
values = dialog.GetValues() |
|
1188 |
self.Controler.ProjectAddPouTransition(values["pouName"], values["transitionName"], values["language"]) |
|
1189 |
self.RefreshProjectTree() |
|
1190 |
dialog.Destroy() |
|
1191 |
event.Skip() |
|
1192 |
||
1193 |
def OnRemovePouTransitionMenu(self, event): |
|
1194 |
event.Skip() |
|
1195 |
||
1196 |
def OnAddPouActionMenu(self, event): |
|
1197 |
dialog = PouActionDialog(self) |
|
1198 |
dialog.SetPous(self.Controler.GetSFCPous()) |
|
1199 |
if dialog.ShowModal() == wxID_OK: |
|
1200 |
values = dialog.GetValues() |
|
1201 |
self.Controler.ProjectAddPouAction(values["pouName"], values["actionName"], values["language"]) |
|
1202 |
self.RefreshProjectTree() |
|
1203 |
dialog.Destroy() |
|
1204 |
event.Skip() |
|
1205 |
||
1206 |
def OnRemovePouActionMenu(self, event): |
|
1207 |
event.Skip() |
|
1208 |
||
1209 |
def OnAddResourceMenu(self, event): |
|
1210 |
selected = self.ProjectTree.GetSelection() |
|
1211 |
if self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION: |
|
1212 |
config_name = self.ProjectTree.GetItemText(selected) |
|
1213 |
dialog = wxTextEntryDialog(self, "Enter Resource name:", "Create new Resource", "", wxOK|wxCANCEL) |
|
1214 |
if dialog.ShowModal() == wxID_OK: |
|
1215 |
value = dialog.GetValue() |
|
1216 |
self.Controler.ProjectAddConfigurationResource(config_name, value) |
|
1217 |
self.RefreshProjectTree() |
|
1218 |
dialog.Destroy() |
|
1219 |
event.Skip() |
|
1220 |
||
1221 |
def OnRemoveResourceMenu(self, event): |
|
1222 |
selected = self.ProjectTree.GetSelection() |
|
1223 |
if self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION: |
|
1224 |
config_name = self.ProjectTree.GetItemText(selected) |
|
1225 |
infos = self.Controler.GetProjectInfos() |
|
1226 |
resources = [] |
|
1227 |
for config in infos["configs"]: |
|
1228 |
if config["name"] == config_name: |
|
1229 |
resources = config["resources"] |
|
1230 |
dialog = wxSingleChoiceDialog(self, "Select Resource to remove:", "Resource Remove", resources, wxOK|wxCANCEL) |
|
1231 |
if dialog.ShowModal() == wxID_OK: |
|
1232 |
resource = dialog.GetStringSelection() |
|
1233 |
self.Controler.ProjectRemoveConfigurationResource(config_name, resource) |
|
1234 |
self.RefreshProjectTree() |
|
1235 |
dialog.Destroy() |
|
1236 |
event.Skip() |
|
1237 |
||
1238 |
def OnPLCOpenMenu(self, event): |
|
1239 |
result = OpenPDFDoc() |
|
1240 |
if type(result) == StringType: |
|
1241 |
message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR) |
|
1242 |
message.ShowModal() |
|
1243 |
message.Destroy() |
|
1244 |
event.Skip() |
|
1245 |
||
1246 |
current_num = 0 |
|
1247 |
def GetNewNum(): |
|
1248 |
global current_num |
|
1249 |
current_num += 1 |
|
1250 |
return current_num |
|
1251 |
||
1252 |
#------------------------------------------------------------------------------- |
|
1253 |
# Create Project Dialog |
|
1254 |
#------------------------------------------------------------------------------- |
|
1255 |
||
1256 |
[wxID_PROJECTDIALOG, wxID_PROJECTDIALOGMAINPANEL, |
|
1257 |
wxID_PROJECTDIALOGPROJECTNAME, wxID_PROJECTDIALOGCOMPANYNAME, |
|
1258 |
wxID_PROJECTDIALOGCOMPANYURL, wxID_PROJECTDIALOGPRODUCTNAME, |
|
1259 |
wxID_PROJECTDIALOGPRODUCTVERSION, wxID_PROJECTDIALOGPRODUCTRELEASE, |
|
1260 |
wxID_PROJECTDIALOGCONTENTDESCRIPTION, wxID_PROJECTDIALOGSTATICTEXT1, |
|
1261 |
wxID_PROJECTDIALOGSTATICTEXT2, wxID_PROJECTDIALOGSTATICTEXT3, |
|
1262 |
wxID_PROJECTDIALOGSTATICTEXT4, wxID_PROJECTDIALOGSTATICTEXT5, |
|
1263 |
wxID_PROJECTDIALOGSTATICTEXT6, wxID_PROJECTDIALOGSTATICTEXT7, |
|
1264 |
] = [wx.NewId() for _init_ctrls in range(16)] |
|
1265 |
||
1266 |
class ProjectDialog(wx.Dialog): |
|
1267 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
1268 |
# generated method, don't edit |
|
1269 |
||
1270 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1271 |
||
1272 |
def _init_sizers(self): |
|
1273 |
# generated method, don't edit |
|
1274 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1275 |
||
1276 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1277 |
||
1278 |
self.SetSizer(self.flexGridSizer1) |
|
1279 |
||
1280 |
def _init_ctrls(self, prnt): |
|
1281 |
# generated method, don't edit |
|
1282 |
wx.Dialog.__init__(self, id=wxID_PROJECTDIALOG, |
|
1283 |
name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223), |
|
1284 |
size=wx.Size(550, 450), style=wx.DEFAULT_DIALOG_STYLE, |
|
1285 |
title='Create a new project') |
|
1286 |
self.SetClientSize(wx.Size(550, 450)) |
|
1287 |
||
1288 |
self.MainPanel = wx.Panel(id=wxID_PROJECTDIALOGMAINPANEL, |
|
1289 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1290 |
size=wx.Size(450, 400), style=wx.TAB_TRAVERSAL) |
|
1291 |
self.MainPanel.SetAutoLayout(True) |
|
1292 |
||
1293 |
self.staticText1 = wx.StaticText(id=wxID_PROJECTDIALOGSTATICTEXT1, |
|
1294 |
label='Project Name (required):', name='staticText1', parent=self.MainPanel, |
|
1295 |
pos=wx.Point(24, 24), size=wx.Size(215, 17), style=0) |
|
1296 |
||
1297 |
self.ProjectName = wx.TextCtrl(id=wxID_PROJECTDIALOGPROJECTNAME, |
|
1298 |
name='ProjectName', parent=self.MainPanel, pos=wx.Point(224, 24), |
|
1299 |
size=wx.Size(295, 24), style=0) |
|
1300 |
||
1301 |
self.staticText2 = wx.StaticText(id=wxID_PROJECTDIALOGSTATICTEXT2, |
|
1302 |
label='Company Name (required):', name='staticText2', parent=self.MainPanel, |
|
1303 |
pos=wx.Point(24, 64), size=wx.Size(215, 17), style=0) |
|
1304 |
||
1305 |
self.CompanyName = wx.TextCtrl(id=wxID_PROJECTDIALOGCOMPANYNAME, |
|
1306 |
name='CompanyName', parent=self.MainPanel, pos=wx.Point(224, 64), |
|
1307 |
size=wx.Size(295, 24), style=0) |
|
1308 |
||
1309 |
self.staticText3 = wx.StaticText(id=wxID_PROJECTDIALOGSTATICTEXT3, |
|
1310 |
label='Company URL (optional):', name='staticText3', parent=self.MainPanel, |
|
1311 |
pos=wx.Point(24, 104), size=wx.Size(215, 17), style=0) |
|
1312 |
||
1313 |
self.CompanyURL = wx.TextCtrl(id=wxID_PROJECTDIALOGCOMPANYURL, |
|
1314 |
name='CompanyURL', parent=self.MainPanel, pos=wx.Point(224, 104), |
|
1315 |
size=wx.Size(295, 24), style=0) |
|
1316 |
||
1317 |
self.staticText4 = wx.StaticText(id=wxID_PROJECTDIALOGSTATICTEXT4, |
|
1318 |
label='Product Name (required):', name='staticText4', parent=self.MainPanel, |
|
1319 |
pos=wx.Point(24, 144), size=wx.Size(215, 17), style=0) |
|
1320 |
||
1321 |
self.ProductName = wx.TextCtrl(id=wxID_PROJECTDIALOGPRODUCTNAME, |
|
1322 |
name='ProductName', parent=self.MainPanel, pos=wx.Point(224, 144), |
|
1323 |
size=wx.Size(295, 24), style=0) |
|
1324 |
||
1325 |
self.staticText5 = wx.StaticText(id=wxID_PROJECTDIALOGSTATICTEXT5, |
|
1326 |
label='Product Version (required):', name='staticText5', parent=self.MainPanel, |
|
1327 |
pos=wx.Point(24, 184), size=wx.Size(215, 17), style=0) |
|
1328 |
||
1329 |
self.ProductVersion = wx.TextCtrl(id=wxID_PROJECTDIALOGPRODUCTVERSION, |
|
1330 |
name='ProductVersion', parent=self.MainPanel, pos=wx.Point(224, 184), |
|
1331 |
size=wx.Size(295, 24), style=0) |
|
1332 |
||
1333 |
self.staticText6 = wx.StaticText(id=wxID_PROJECTDIALOGSTATICTEXT6, |
|
1334 |
label='Product Release (optional):', name='staticText6', parent=self.MainPanel, |
|
1335 |
pos=wx.Point(24, 224), size=wx.Size(215, 17), style=0) |
|
1336 |
||
1337 |
self.ProductRelease = wx.TextCtrl(id=wxID_PROJECTDIALOGPRODUCTRELEASE, |
|
1338 |
name='ProductRelease', parent=self.MainPanel, pos=wx.Point(224, 224), |
|
1339 |
size=wx.Size(295, 24), style=0) |
|
1340 |
||
1341 |
self.staticText7 = wx.StaticText(id=wxID_PROJECTDIALOGSTATICTEXT7, |
|
1342 |
label='Content Description (optional):', name='staticText7', parent=self.MainPanel, |
|
1343 |
pos=wx.Point(24, 264), size=wx.Size(215, 17), style=0) |
|
1344 |
||
1345 |
self.ContentDescription = wx.TextCtrl(id=wxID_PROJECTDIALOGCONTENTDESCRIPTION, |
|
1346 |
name='ProductRelease', parent=self.MainPanel, pos=wx.Point(224, 264), |
|
1347 |
size=wx.Size(295, 120), style=wxTE_MULTILINE) |
|
1348 |
||
1349 |
self._init_sizers() |
|
1350 |
||
1351 |
def __init__(self, parent): |
|
1352 |
self._init_ctrls(parent) |
|
9 | 1353 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
0 | 1354 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
1355 |
||
1356 |
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
|
1357 |
||
1358 |
def OnOK(self, event): |
|
1359 |
error = [] |
|
1360 |
if self.ProjectName.GetValue() == "": |
|
1361 |
error.append("Project Name") |
|
1362 |
if self.CompanyName.GetValue() == "": |
|
1363 |
error.append("Company Name") |
|
1364 |
if self.ProductName.GetValue() == "": |
|
1365 |
error.append("Product Name") |
|
1366 |
if self.ProductVersion.GetValue() == "": |
|
1367 |
error.append("Product Version") |
|
1368 |
if len(error) > 0: |
|
1369 |
text = "" |
|
1370 |
for i, item in enumerate(error): |
|
1371 |
if i == 0: |
|
1372 |
text += item |
|
1373 |
elif i == len(error) - 1: |
|
1374 |
text += " and %s"%item |
|
1375 |
else: |
|
1376 |
text += ", %s"%item |
|
1377 |
message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) |
|
1378 |
message.ShowModal() |
|
1379 |
message.Destroy() |
|
1380 |
else: |
|
1381 |
self.EndModal(wxID_OK) |
|
1382 |
||
1383 |
def SetValues(self, values): |
|
1384 |
for item, value in values.items(): |
|
1385 |
if item == "projectName": |
|
1386 |
self.ProjectName.SetValue(value) |
|
1387 |
elif item == "companyName": |
|
1388 |
self.CompanyName.SetValue(value) |
|
1389 |
elif item == "companyURL": |
|
1390 |
self.CompanyURL.SetValue(value) |
|
1391 |
elif item == "productName": |
|
1392 |
self.ProductName.SetValue(value) |
|
1393 |
elif item == "productVersion": |
|
1394 |
self.ProductVersion.SetValue(value) |
|
1395 |
elif item == "productRelease": |
|
1396 |
self.ProductRelease.SetValue(value) |
|
1397 |
elif item == "contentDescription": |
|
1398 |
self.ContentDescription.SetValue(value) |
|
1399 |
||
1400 |
def GetValues(self): |
|
1401 |
values = {} |
|
1402 |
values["projectName"] = self.ProjectName.GetValue() |
|
1403 |
values["companyName"] = self.CompanyName.GetValue() |
|
1404 |
if self.CompanyURL.GetValue() != None: |
|
1405 |
values["companyURL"] = self.CompanyURL.GetValue() |
|
1406 |
values["productName"] = self.ProductName.GetValue() |
|
1407 |
values["productVersion"] = self.ProductVersion.GetValue() |
|
1408 |
if self.ProductRelease.GetValue() != None: |
|
1409 |
values["productRelease"] = self.ProductRelease.GetValue() |
|
1410 |
if self.ProductRelease.GetValue() != None: |
|
1411 |
values["contentDescription"] = self.ContentDescription.GetValue() |
|
1412 |
return values |
|
1413 |
||
1414 |
#------------------------------------------------------------------------------- |
|
1415 |
# Create Pou Dialog |
|
1416 |
#------------------------------------------------------------------------------- |
|
1417 |
||
1418 |
[wxID_POUDIALOG, wxID_POUDIALOGMAINPANEL, wxID_POUDIALOGPOUNAME, |
|
1419 |
wxID_POUDIALOGPOUTYPE, wxID_POUDIALOGLANGUAGE, wxID_POUDIALOGSTATICTEXT1, |
|
1420 |
wxID_POUDIALOGSTATICTEXT2, wxID_POUDIALOGSTATICTEXT3, |
|
1421 |
] = [wx.NewId() for _init_ctrls in range(8)] |
|
1422 |
||
1423 |
class PouDialog(wx.Dialog): |
|
1424 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
1425 |
# generated method, don't edit |
|
1426 |
||
1427 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1428 |
||
1429 |
def _init_sizers(self): |
|
1430 |
# generated method, don't edit |
|
1431 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1432 |
||
1433 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1434 |
||
1435 |
self.SetSizer(self.flexGridSizer1) |
|
1436 |
||
1437 |
def _init_ctrls(self, prnt): |
|
1438 |
# generated method, don't edit |
|
1439 |
wx.Dialog.__init__(self, id=wxID_POUDIALOG, |
|
16 | 1440 |
name='PouDialog', parent=prnt, pos=wx.Point(376, 223), |
0 | 1441 |
size=wx.Size(300, 200), style=wx.DEFAULT_DIALOG_STYLE, |
16 | 1442 |
title='Create a new POU') |
0 | 1443 |
self.SetClientSize(wx.Size(300, 200)) |
1444 |
||
1445 |
self.MainPanel = wx.Panel(id=wxID_POUDIALOGMAINPANEL, |
|
1446 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1447 |
size=wx.Size(300, 200), style=wx.TAB_TRAVERSAL) |
|
1448 |
self.MainPanel.SetAutoLayout(True) |
|
1449 |
||
1450 |
self.staticText1 = wx.StaticText(id=wxID_POUDIALOGSTATICTEXT1, |
|
1451 |
label='POU Name:', name='staticText1', parent=self.MainPanel, |
|
1452 |
pos=wx.Point(24, 24), size=wx.Size(95, 17), style=0) |
|
1453 |
||
1454 |
self.PouName = wx.TextCtrl(id=wxID_POUDIALOGPOUNAME, |
|
1455 |
name='POUName', parent=self.MainPanel, pos=wx.Point(104, 24), |
|
1456 |
size=wx.Size(150, 24), style=0) |
|
1457 |
||
1458 |
self.staticText2 = wx.StaticText(id=wxID_POUDIALOGSTATICTEXT2, |
|
1459 |
label='POU Type:', name='staticText2', parent=self.MainPanel, |
|
1460 |
pos=wx.Point(24, 64), size=wx.Size(95, 17), style=0) |
|
1461 |
||
1462 |
self.PouType = wx.Choice(id=wxID_POUDIALOGPOUTYPE, |
|
1463 |
name='POUType', parent=self.MainPanel, pos=wx.Point(104, 64), |
|
1464 |
size=wx.Size(150, 24), style=0) |
|
1465 |
EVT_CHOICE(self, wxID_POUDIALOGPOUTYPE, self.OnTypeChanged) |
|
1466 |
||
1467 |
self.staticText3 = wx.StaticText(id=wxID_POUDIALOGSTATICTEXT3, |
|
1468 |
label='Language:', name='staticText3', parent=self.MainPanel, |
|
1469 |
pos=wx.Point(24, 104), size=wx.Size(95, 17), style=0) |
|
1470 |
||
1471 |
self.Language = wx.Choice(id=wxID_POUDIALOGLANGUAGE, |
|
1472 |
name='Language', parent=self.MainPanel, pos=wx.Point(104, 104), |
|
1473 |
size=wx.Size(150, 24), style=0) |
|
1474 |
||
1475 |
self._init_sizers() |
|
1476 |
||
1477 |
def __init__(self, parent): |
|
1478 |
self._init_ctrls(parent) |
|
9 | 1479 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
0 | 1480 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
1481 |
||
1482 |
for option in ["function","functionBlock","program"]: |
|
1483 |
self.PouType.Append(option) |
|
1484 |
self.RefreshLanguage() |
|
1485 |
||
6 | 1486 |
self.PouNames = [] |
1487 |
||
0 | 1488 |
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
1489 |
||
1490 |
def OnOK(self, event): |
|
1491 |
error = [] |
|
1492 |
pou_name = self.PouName.GetValue() |
|
1493 |
if pou_name == "": |
|
1494 |
error.append("POU Name") |
|
1495 |
if self.PouType.GetStringSelection() == "": |
|
1496 |
error.append("POU Type") |
|
1497 |
if self.Language.GetStringSelection() == "": |
|
1498 |
error.append("Language") |
|
1499 |
if len(error) > 0: |
|
1500 |
text = "" |
|
1501 |
for i, item in enumerate(error): |
|
1502 |
if i == 0: |
|
1503 |
text += item |
|
1504 |
elif i == len(error) - 1: |
|
1505 |
text += " and %s"%item |
|
1506 |
else: |
|
1507 |
text += ", %s"%item |
|
1508 |
message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) |
|
1509 |
message.ShowModal() |
|
1510 |
message.Destroy() |
|
1511 |
elif not TestIdentifier(pou_name): |
|
1512 |
message = wxMessageDialog(self, "\"%s\" is not a valid identifier!"%pou_name, "Error", wxOK|wxICON_ERROR) |
|
1513 |
message.ShowModal() |
|
1514 |
message.Destroy() |
|
1515 |
elif pou_name.upper() in IEC_KEYWORDS: |
|
1516 |
message = wxMessageDialog(self, "\"%s\" is a keyword. It can't be used!"%pou_name, "Error", wxOK|wxICON_ERROR) |
|
1517 |
message.ShowModal() |
|
1518 |
message.Destroy() |
|
1519 |
elif pou_name.upper() in self.PouNames: |
|
1520 |
message = wxMessageDialog(self, "\"%s\" pou already exists!"%pou_name, "Error", wxOK|wxICON_ERROR) |
|
1521 |
message.ShowModal() |
|
1522 |
message.Destroy() |
|
1523 |
else: |
|
1524 |
self.EndModal(wxID_OK) |
|
1525 |
||
1526 |
def RefreshLanguage(self): |
|
1527 |
selection = self.Language.GetStringSelection() |
|
1528 |
self.Language.Clear() |
|
1529 |
for option in ["IL","ST","LD","FBD","SFC"]: |
|
1530 |
if option != "SFC" or self.PouType.GetStringSelection() == "program": |
|
1531 |
self.Language.Append(option) |
|
1532 |
if self.Language.FindString(selection) != wxNOT_FOUND: |
|
1533 |
self.Language.SetStringSelection(selection) |
|
1534 |
||
1535 |
def OnTypeChanged(self, event): |
|
1536 |
self.RefreshLanguage() |
|
1537 |
event.Skip() |
|
1538 |
||
1539 |
def SetPouNames(self, pou_names): |
|
1540 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
1541 |
||
1542 |
def SetValues(self, values): |
|
1543 |
for item, value in values.items(): |
|
1544 |
if item == "pouName": |
|
1545 |
self.PouName.SetValue(value) |
|
1546 |
elif item == "pouType": |
|
1547 |
self.PouType.SetStringSelection(value) |
|
1548 |
elif item == "language": |
|
1549 |
self.Language.SetStringSelection(value) |
|
1550 |
||
1551 |
def GetValues(self): |
|
1552 |
values = {} |
|
1553 |
values["pouName"] = self.PouName.GetValue() |
|
1554 |
values["pouType"] = self.PouType.GetStringSelection() |
|
1555 |
values["language"] = self.Language.GetStringSelection() |
|
1556 |
return values |
|
1557 |
||
1558 |
||
1559 |
#------------------------------------------------------------------------------- |
|
1560 |
# Create Pou Transition Dialog |
|
1561 |
#------------------------------------------------------------------------------- |
|
1562 |
||
1563 |
[wxID_POUTRANSITIONDIALOG, wxID_POUTRANSITIONDIALOGMAINPANEL, |
|
1564 |
wxID_POUTRANSITIONDIALOGPOUNAME, wxID_POUTRANSITIONDIALOGTRANSITIONNAME, |
|
1565 |
wxID_POUTRANSITIONDIALOGLANGUAGE, wxID_POUTRANSITIONDIALOGSTATICTEXT1, |
|
1566 |
wxID_POUTRANSITIONDIALOGSTATICTEXT2, wxID_POUTRANSITIONDIALOGSTATICTEXT3, |
|
1567 |
] = [wx.NewId() for _init_ctrls in range(8)] |
|
1568 |
||
1569 |
class PouTransitionDialog(wx.Dialog): |
|
1570 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
1571 |
# generated method, don't edit |
|
1572 |
||
1573 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1574 |
||
1575 |
def _init_sizers(self): |
|
1576 |
# generated method, don't edit |
|
1577 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1578 |
||
1579 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1580 |
||
1581 |
self.SetSizer(self.flexGridSizer1) |
|
1582 |
||
1583 |
def _init_ctrls(self, prnt): |
|
1584 |
# generated method, don't edit |
|
1585 |
wx.Dialog.__init__(self, id=wxID_POUTRANSITIONDIALOG, |
|
1586 |
name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223), |
|
1587 |
size=wx.Size(350, 200), style=wx.DEFAULT_DIALOG_STYLE, |
|
1588 |
title='Create a new project') |
|
1589 |
self.SetClientSize(wx.Size(350, 200)) |
|
1590 |
||
1591 |
self.MainPanel = wx.Panel(id=wxID_POUTRANSITIONDIALOGMAINPANEL, |
|
1592 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1593 |
size=wx.Size(350, 200), style=wx.TAB_TRAVERSAL) |
|
1594 |
self.MainPanel.SetAutoLayout(True) |
|
1595 |
||
1596 |
self.staticText1 = wx.StaticText(id=wxID_POUTRANSITIONDIALOGSTATICTEXT1, |
|
1597 |
label='POU Name:', name='staticText1', parent=self.MainPanel, |
|
1598 |
pos=wx.Point(24, 24), size=wx.Size(145, 17), style=0) |
|
1599 |
||
1600 |
self.PouName = wx.Choice(id=wxID_POUTRANSITIONDIALOGPOUNAME, |
|
1601 |
name='POUName', parent=self.MainPanel, pos=wx.Point(154, 24), |
|
1602 |
size=wx.Size(150, 24), style=0) |
|
1603 |
||
1604 |
self.staticText2 = wx.StaticText(id=wxID_POUTRANSITIONDIALOGSTATICTEXT2, |
|
1605 |
label='Transition Name:', name='staticText2', parent=self.MainPanel, |
|
1606 |
pos=wx.Point(24, 64), size=wx.Size(145, 17), style=0) |
|
1607 |
||
1608 |
self.TransitionName = wx.TextCtrl(id=wxID_POUTRANSITIONDIALOGTRANSITIONNAME, |
|
1609 |
name='TransitionName', parent=self.MainPanel, pos=wx.Point(154, 64), |
|
1610 |
size=wx.Size(150, 24), style=0) |
|
1611 |
||
1612 |
self.staticText3 = wx.StaticText(id=wxID_POUTRANSITIONDIALOGSTATICTEXT3, |
|
1613 |
label='Language:', name='staticText3', parent=self.MainPanel, |
|
1614 |
pos=wx.Point(24, 104), size=wx.Size(145, 17), style=0) |
|
1615 |
||
1616 |
self.Language = wx.Choice(id=wxID_POUTRANSITIONDIALOGLANGUAGE, |
|
1617 |
name='Language', parent=self.MainPanel, pos=wx.Point(154, 104), |
|
1618 |
size=wx.Size(150, 24), style=0) |
|
1619 |
||
1620 |
self._init_sizers() |
|
1621 |
||
1622 |
def __init__(self, parent): |
|
1623 |
self._init_ctrls(parent) |
|
9 | 1624 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
0 | 1625 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
1626 |
||
1627 |
for option in ["IL","ST","LD","FBD"]: |
|
1628 |
self.Language.Append(option) |
|
1629 |
||
1630 |
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
|
1631 |
||
1632 |
def OnOK(self, event): |
|
1633 |
error = [] |
|
1634 |
if self.PouName.GetStringSelection() == "": |
|
1635 |
error.append("POU Name") |
|
1636 |
if self.TransitionName.GetValue() == "": |
|
1637 |
error.append("Transition Name") |
|
1638 |
if self.Language.GetStringSelection() == "": |
|
1639 |
error.append("Language") |
|
1640 |
if len(error) > 0: |
|
1641 |
text = "" |
|
1642 |
for i, item in enumerate(error): |
|
1643 |
if i == 0: |
|
1644 |
text += item |
|
1645 |
elif i == len(error) - 1: |
|
1646 |
text += " and %s"%item |
|
1647 |
else: |
|
1648 |
text += ", %s"%item |
|
1649 |
message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) |
|
1650 |
message.ShowModal() |
|
1651 |
message.Destroy() |
|
1652 |
else: |
|
1653 |
self.EndModal(wxID_OK) |
|
1654 |
||
1655 |
def SetPous(self, pous): |
|
1656 |
for pou in pous: |
|
1657 |
self.PouName.Append(pou) |
|
1658 |
||
1659 |
def SetValues(self, values): |
|
1660 |
for item, value in values.items(): |
|
1661 |
if item == "pouName": |
|
1662 |
self.PouName.SetStringSelection(value) |
|
1663 |
elif item == "transitionName": |
|
1664 |
self.TransitionName.SetValue(value) |
|
1665 |
elif item == "language": |
|
1666 |
self.Language.SetStringSelection(value) |
|
1667 |
||
1668 |
def GetValues(self): |
|
1669 |
values = {} |
|
1670 |
values["pouName"] = self.PouName.GetStringSelection() |
|
1671 |
values["transitionName"] = self.TransitionName.GetValue() |
|
1672 |
values["language"] = self.Language.GetStringSelection() |
|
1673 |
return values |
|
1674 |
||
1675 |
#------------------------------------------------------------------------------- |
|
1676 |
# Create Pou Action Dialog |
|
1677 |
#------------------------------------------------------------------------------- |
|
1678 |
||
1679 |
[wxID_POUACTIONDIALOG, wxID_POUACTIONDIALOGMAINPANEL, |
|
1680 |
wxID_POUACTIONDIALOGPOUNAME, wxID_POUACTIONDIALOGACTIONNAME, |
|
1681 |
wxID_POUACTIONDIALOGLANGUAGE, wxID_POUACTIONDIALOGSTATICTEXT1, |
|
1682 |
wxID_POUACTIONDIALOGSTATICTEXT2, wxID_POUACTIONDIALOGSTATICTEXT3, |
|
1683 |
] = [wx.NewId() for _init_ctrls in range(8)] |
|
1684 |
||
1685 |
class PouActionDialog(wx.Dialog): |
|
1686 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
1687 |
# generated method, don't edit |
|
1688 |
||
1689 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1690 |
||
1691 |
def _init_sizers(self): |
|
1692 |
# generated method, don't edit |
|
1693 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1694 |
||
1695 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1696 |
||
1697 |
self.SetSizer(self.flexGridSizer1) |
|
1698 |
||
1699 |
def _init_ctrls(self, prnt): |
|
1700 |
# generated method, don't edit |
|
1701 |
wx.Dialog.__init__(self, id=wxID_POUACTIONDIALOG, |
|
1702 |
name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223), |
|
1703 |
size=wx.Size(320, 200), style=wx.DEFAULT_DIALOG_STYLE, |
|
1704 |
title='Create a new project') |
|
1705 |
self.SetClientSize(wx.Size(320, 200)) |
|
1706 |
||
1707 |
self.MainPanel = wx.Panel(id=wxID_POUACTIONDIALOGMAINPANEL, |
|
1708 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1709 |
size=wx.Size(350, 200), style=wx.TAB_TRAVERSAL) |
|
1710 |
self.MainPanel.SetAutoLayout(True) |
|
1711 |
||
1712 |
self.staticText1 = wx.StaticText(id=wxID_POUACTIONDIALOGSTATICTEXT1, |
|
1713 |
label='POU Name:', name='staticText1', parent=self.MainPanel, |
|
1714 |
pos=wx.Point(24, 24), size=wx.Size(145, 17), style=0) |
|
1715 |
||
1716 |
self.PouName = wx.Choice(id=wxID_POUACTIONDIALOGPOUNAME, |
|
1717 |
name='POUName', parent=self.MainPanel, pos=wx.Point(124, 24), |
|
1718 |
size=wx.Size(150, 24), style=0) |
|
1719 |
||
1720 |
self.staticText2 = wx.StaticText(id=wxID_POUACTIONDIALOGSTATICTEXT2, |
|
1721 |
label='Action Name:', name='staticText2', parent=self.MainPanel, |
|
1722 |
pos=wx.Point(24, 64), size=wx.Size(145, 17), style=0) |
|
1723 |
||
1724 |
self.ActionName = wx.TextCtrl(id=wxID_POUACTIONDIALOGACTIONNAME, |
|
1725 |
name='ActionName', parent=self.MainPanel, pos=wx.Point(124, 64), |
|
1726 |
size=wx.Size(150, 24), style=0) |
|
1727 |
||
1728 |
self.staticText3 = wx.StaticText(id=wxID_POUACTIONDIALOGSTATICTEXT3, |
|
1729 |
label='Language:', name='staticText3', parent=self.MainPanel, |
|
1730 |
pos=wx.Point(24, 104), size=wx.Size(145, 17), style=0) |
|
1731 |
||
1732 |
self.Language = wx.Choice(id=wxID_POUACTIONDIALOGLANGUAGE, |
|
1733 |
name='Language', parent=self.MainPanel, pos=wx.Point(124, 104), |
|
1734 |
size=wx.Size(150, 24), style=0) |
|
1735 |
||
1736 |
self._init_sizers() |
|
1737 |
||
1738 |
def __init__(self, parent): |
|
1739 |
self._init_ctrls(parent) |
|
9 | 1740 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
0 | 1741 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
1742 |
||
1743 |
for option in ["IL","ST","LD","FBD"]: |
|
1744 |
self.Language.Append(option) |
|
1745 |
||
1746 |
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
|
1747 |
||
1748 |
def OnOK(self, event): |
|
1749 |
error = [] |
|
1750 |
if self.PouName.GetStringSelection() == "": |
|
1751 |
error.append("POU Name") |
|
1752 |
if self.ActionName.GetValue() == "": |
|
1753 |
error.append("Action Name") |
|
1754 |
if self.Language.GetStringSelection() == "": |
|
1755 |
error.append("Language") |
|
1756 |
if len(error) > 0: |
|
1757 |
text = "" |
|
1758 |
for i, item in enumerate(error): |
|
1759 |
if i == 0: |
|
1760 |
text += item |
|
1761 |
elif i == len(error) - 1: |
|
1762 |
text += " and %s"%item |
|
1763 |
else: |
|
1764 |
text += ", %s"%item |
|
1765 |
message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) |
|
1766 |
message.ShowModal() |
|
1767 |
message.Destroy() |
|
1768 |
else: |
|
1769 |
self.EndModal(wxID_OK) |
|
1770 |
||
1771 |
def SetPous(self, pous): |
|
1772 |
for pou in pous: |
|
1773 |
self.PouName.Append(pou) |
|
1774 |
||
1775 |
def SetValues(self, values): |
|
1776 |
for item, value in values.items(): |
|
1777 |
if item == "pouName": |
|
1778 |
self.PouName.SetStringSelection(value) |
|
1779 |
elif item == "actionName": |
|
1780 |
self.ActionName.SetValue(value) |
|
1781 |
elif item == "language": |
|
1782 |
self.Language.SetStringSelection(value) |
|
1783 |
||
1784 |
def GetValues(self): |
|
1785 |
values = {} |
|
1786 |
values["pouName"] = self.PouName.GetStringSelection() |
|
1787 |
values["actionName"] = self.ActionName.GetValue() |
|
1788 |
values["language"] = self.Language.GetStringSelection() |
|
1789 |
return values |
|
1790 |
||
1791 |
#------------------------------------------------------------------------------- |
|
1792 |
# Pou Interface Dialog |
|
1793 |
#------------------------------------------------------------------------------- |
|
1794 |
||
1795 |
class VariableTable(wxPyGridTableBase): |
|
1796 |
||
1797 |
""" |
|
1798 |
A custom wxGrid Table using user supplied data |
|
1799 |
""" |
|
1800 |
def __init__(self, parent, data, colnames): |
|
1801 |
# The base class must be initialized *first* |
|
1802 |
wxPyGridTableBase.__init__(self) |
|
1803 |
self.data = data |
|
1804 |
self.colnames = colnames |
|
1805 |
self.Parent = parent |
|
1806 |
# XXX |
|
1807 |
# we need to store the row length and collength to |
|
1808 |
# see if the table has changed size |
|
1809 |
self._rows = self.GetNumberRows() |
|
1810 |
self._cols = self.GetNumberCols() |
|
1811 |
||
1812 |
def GetNumberCols(self): |
|
1813 |
return len(self.colnames) |
|
1814 |
||
1815 |
def GetNumberRows(self): |
|
1816 |
return len(self.data) |
|
1817 |
||
1818 |
def GetColLabelValue(self, col): |
|
1819 |
if col < len(self.colnames): |
|
1820 |
return self.colnames[col] |
|
1821 |
||
1822 |
def GetRowLabelValues(self, row): |
|
1823 |
return row |
|
1824 |
||
1825 |
def GetValue(self, row, col): |
|
1826 |
if row < self.GetNumberRows(): |
|
1827 |
name = str(self.data[row].get(self.GetColLabelValue(col), "")) |
|
1828 |
return name |
|
1829 |
||
1830 |
def GetValueByName(self, row, colname): |
|
1831 |
return self.data[row].get(colname) |
|
1832 |
||
1833 |
def SetValue(self, row, col, value): |
|
1834 |
if col < len(self.colnames): |
|
1835 |
self.data[row][self.GetColLabelValue(col)] = value |
|
1836 |
||
1837 |
def ResetView(self, grid): |
|
1838 |
""" |
|
1839 |
(wxGrid) -> Reset the grid view. Call this to |
|
1840 |
update the grid if rows and columns have been added or deleted |
|
1841 |
""" |
|
1842 |
grid.BeginBatch() |
|
1843 |
for current, new, delmsg, addmsg in [ |
|
1844 |
(self._rows, self.GetNumberRows(), wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_NOTIFY_ROWS_APPENDED), |
|
1845 |
(self._cols, self.GetNumberCols(), wxGRIDTABLE_NOTIFY_COLS_DELETED, wxGRIDTABLE_NOTIFY_COLS_APPENDED), |
|
1846 |
]: |
|
1847 |
if new < current: |
|
1848 |
msg = wxGridTableMessage(self,delmsg,new,current-new) |
|
1849 |
grid.ProcessTableMessage(msg) |
|
1850 |
elif new > current: |
|
1851 |
msg = wxGridTableMessage(self,addmsg,new-current) |
|
1852 |
grid.ProcessTableMessage(msg) |
|
1853 |
self.UpdateValues(grid) |
|
1854 |
grid.EndBatch() |
|
1855 |
||
1856 |
self._rows = self.GetNumberRows() |
|
1857 |
self._cols = self.GetNumberCols() |
|
1858 |
# update the column rendering scheme |
|
1859 |
self._updateColAttrs(grid) |
|
1860 |
||
1861 |
# update the scrollbars and the displayed part of the grid |
|
1862 |
grid.AdjustScrollbars() |
|
1863 |
grid.ForceRefresh() |
|
1864 |
||
1865 |
def UpdateValues(self, grid): |
|
1866 |
"""Update all displayed values""" |
|
1867 |
# This sends an event to the grid table to update all of the values |
|
1868 |
msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES) |
|
1869 |
grid.ProcessTableMessage(msg) |
|
1870 |
||
1871 |
def _updateColAttrs(self, grid): |
|
1872 |
""" |
|
1873 |
wxGrid -> update the column attributes to add the |
|
1874 |
appropriate renderer given the column name. |
|
1875 |
||
1876 |
Otherwise default to the default renderer. |
|
1877 |
""" |
|
1878 |
||
1879 |
for col in range(self.GetNumberCols()): |
|
1880 |
attr = wxGridCellAttr() |
|
1881 |
attr.SetAlignment(self.Parent.ColAlignements[col], wxALIGN_CENTRE) |
|
1882 |
grid.SetColAttr(col, attr) |
|
1883 |
grid.SetColSize(col, self.Parent.ColSizes[col]) |
|
1884 |
||
1885 |
typelist = None |
|
1886 |
accesslist = None |
|
1887 |
for row in range(self.GetNumberRows()): |
|
1888 |
for col in range(self.GetNumberCols()): |
|
1889 |
editor = None |
|
1890 |
renderer = None |
|
1891 |
colname = self.GetColLabelValue(col) |
|
1892 |
grid.SetReadOnly(row, col, False) |
|
1893 |
if colname in ["Name","Initial Value","Location"]: |
|
1894 |
editor = wxGridCellTextEditor() |
|
1895 |
renderer = wxGridCellStringRenderer() |
|
1896 |
elif colname == "Class": |
|
1897 |
if len(self.Parent.ClassList) == 1: |
|
1898 |
grid.SetReadOnly(row, col, True) |
|
1899 |
else: |
|
1900 |
editor = wxGridCellChoiceEditor() |
|
1901 |
editor.SetParameters(",".join(self.Parent.ClassList)) |
|
1902 |
elif colname == "Type": |
|
1903 |
editor = wxGridCellChoiceEditor() |
|
1904 |
editor.SetParameters(self.Parent.TypeList) |
|
1905 |
elif colname in ["Retain", "Constant"]: |
|
1906 |
editor = wxGridCellChoiceEditor() |
|
1907 |
editor.SetParameters(self.Parent.OptionList) |
|
1908 |
||
1909 |
grid.SetCellEditor(row, col, editor) |
|
1910 |
grid.SetCellRenderer(row, col, renderer) |
|
1911 |
||
1912 |
grid.SetCellBackgroundColour(row, col, wxWHITE) |
|
1913 |
||
1914 |
def SetData(self, data): |
|
1915 |
self.data = data |
|
1916 |
||
1917 |
def GetData(self): |
|
1918 |
return self.data |
|
1919 |
||
1920 |
def GetCurrentIndex(self): |
|
1921 |
return self.CurrentIndex |
|
1922 |
||
1923 |
def SetCurrentIndex(self, index): |
|
1924 |
self.CurrentIndex = index |
|
1925 |
||
1926 |
def AppendRow(self, row_content): |
|
1927 |
self.data.append(row_content) |
|
1928 |
||
1929 |
def RemoveRow(self, row_index): |
|
1930 |
self.data.pop(row_index) |
|
12 | 1931 |
|
1932 |
def GetRow(self, row_index): |
|
1933 |
return self.data[row_index] |
|
0 | 1934 |
|
1935 |
def Empty(self): |
|
1936 |
self.data = [] |
|
1937 |
self.editors = [] |
|
1938 |
||
1939 |
[wxID_EDITVARIABLEDIALOG, wxID_EDITVARIABLEDIALOGMAINPANEL, |
|
1940 |
wxID_EDITVARIABLEDIALOGVARIABLESGRID, wxID_EDITVARIABLEDIALOGRETURNTYPE, |
|
1941 |
wxID_EDITVARIABLEDIALOGCLASSFILTER, wxID_EDITVARIABLEDIALOGADDBUTTON, |
|
1942 |
wxID_EDITVARIABLEDIALOGDELETEBUTTON, wxID_EDITVARIABLEDIALOGUPBUTTON, |
|
1943 |
wxID_EDITVARIABLEDIALOGDOWNBUTTON, wxID_EDITVARIABLEDIALOGSTATICTEXT1, |
|
1944 |
wxID_EDITVARIABLEDIALOGSTATICTEXT2, wxID_EDITVARIABLEDIALOGSTATICTEXT3, |
|
1945 |
] = [wx.NewId() for _init_ctrls in range(12)] |
|
1946 |
||
1947 |
class EditVariableDialog(wx.Dialog): |
|
1948 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
1949 |
# generated method, don't edit |
|
1950 |
||
1951 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1952 |
||
1953 |
def _init_sizers(self): |
|
1954 |
# generated method, don't edit |
|
1955 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1956 |
||
1957 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1958 |
||
1959 |
self.SetSizer(self.flexGridSizer1) |
|
1960 |
||
1961 |
def _init_ctrls(self, prnt, name): |
|
1962 |
# generated method, don't edit |
|
1963 |
wx.Dialog.__init__(self, id=wxID_EDITVARIABLEDIALOG, |
|
1964 |
name='EditVariableDialog', parent=prnt, pos=wx.Point(376, 223), |
|
1965 |
size=wx.Size(600, 440), style=wx.DEFAULT_DIALOG_STYLE, |
|
1966 |
title='Edit variables of %s'%name) |
|
1967 |
self.SetClientSize(wx.Size(600, 440)) |
|
1968 |
||
1969 |
self.MainPanel = wx.Panel(id=wxID_EDITVARIABLEDIALOGMAINPANEL, |
|
1970 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1971 |
size=wx.Size(600, 440), style=wx.TAB_TRAVERSAL) |
|
1972 |
self.MainPanel.SetAutoLayout(True) |
|
1973 |
||
1974 |
self.staticText1 = wx.StaticText(id=wxID_EDITVARIABLEDIALOGSTATICTEXT1, |
|
1975 |
label='Return Type:', name='staticText1', parent=self.MainPanel, |
|
1976 |
pos=wx.Point(24, 29), size=wx.Size(95, 17), style=0) |
|
1977 |
||
1978 |
self.ReturnType = wx.Choice(id=wxID_EDITVARIABLEDIALOGRETURNTYPE, |
|
1979 |
name='ReturnType', parent=self.MainPanel, pos=wx.Point(124, 24), |
|
1980 |
size=wx.Size(145, 24), style=0) |
|
1981 |
||
1982 |
self.staticText2 = wx.StaticText(id=wxID_EDITVARIABLEDIALOGSTATICTEXT2, |
|
1983 |
label='Class Filter:', name='staticText2', parent=self.MainPanel, |
|
1984 |
pos=wx.Point(324, 29), size=wx.Size(95, 17), style=0) |
|
1985 |
||
1986 |
self.ClassFilter = wx.Choice(id=wxID_EDITVARIABLEDIALOGCLASSFILTER, |
|
1987 |
name='ClassFilter', parent=self.MainPanel, pos=wx.Point(424, 24), |
|
1988 |
size=wx.Size(145, 24), style=0) |
|
1989 |
EVT_CHOICE(self, wxID_EDITVARIABLEDIALOGCLASSFILTER, self.OnClassFilter) |
|
1990 |
||
1991 |
self.staticText3 = wx.StaticText(id=wxID_EDITVARIABLEDIALOGSTATICTEXT3, |
|
1992 |
label='Variables:', name='staticText3', parent=self.MainPanel, |
|
1993 |
pos=wx.Point(24, 60), size=wx.Size(95, 17), style=0) |
|
1994 |
||
1995 |
self.VariablesGrid = wx.grid.Grid(id=wxID_EDITVARIABLEDIALOGVARIABLESGRID, |
|
1996 |
name='VariablesGrid', parent=self.MainPanel, pos=wx.Point(24, 80), |
|
1997 |
size=wx.Size(550, 250), style=wxVSCROLL) |
|
1998 |
self.VariablesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
|
1999 |
'Sans')) |
|
2000 |
self.VariablesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
2001 |
False, 'Sans')) |
|
2002 |
self.VariablesGrid.DisableDragGridSize() |
|
2003 |
self.VariablesGrid.EnableScrolling(False, True) |
|
6 | 2004 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange) |
0 | 2005 |
|
2006 |
self.AddButton = wx.Button(id=wxID_EDITVARIABLEDIALOGADDBUTTON, label='Add', |
|
2007 |
name='AddButton', parent=self.MainPanel, pos=wx.Point(345, 340), |
|
2008 |
size=wx.Size(72, 32), style=0) |
|
2009 |
EVT_BUTTON(self, wxID_EDITVARIABLEDIALOGADDBUTTON, self.OnAddButton) |
|
2010 |
||
2011 |
self.DeleteButton = wx.Button(id=wxID_EDITVARIABLEDIALOGDELETEBUTTON, label='Delete', |
|
2012 |
name='DeleteButton', parent=self.MainPanel, pos=wx.Point(425, 340), |
|
2013 |
size=wx.Size(72, 32), style=0) |
|
2014 |
EVT_BUTTON(self, wxID_EDITVARIABLEDIALOGDELETEBUTTON, self.OnDeleteButton) |
|
2015 |
||
2016 |
self.UpButton = wx.Button(id=wxID_EDITVARIABLEDIALOGUPBUTTON, label='^', |
|
2017 |
name='UpButton', parent=self.MainPanel, pos=wx.Point(505, 340), |
|
2018 |
size=wx.Size(32, 32), style=0) |
|
2019 |
EVT_BUTTON(self, wxID_EDITVARIABLEDIALOGUPBUTTON, self.OnUpButton) |
|
2020 |
||
2021 |
self.DownButton = wx.Button(id=wxID_EDITVARIABLEDIALOGDOWNBUTTON, label='v', |
|
2022 |
name='DownButton', parent=self.MainPanel, pos=wx.Point(545, 340), |
|
2023 |
size=wx.Size(32, 32), style=0) |
|
2024 |
EVT_BUTTON(self, wxID_EDITVARIABLEDIALOGDOWNBUTTON, self.OnDownButton) |
|
2025 |
||
2026 |
self._init_sizers() |
|
2027 |
||
2028 |
def __init__(self, parent, name, pou_type, filter = "All"): |
|
2029 |
self._init_ctrls(parent, name) |
|
9 | 2030 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
0 | 2031 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
2032 |
self.Filter = filter |
|
2033 |
self.FilterChoices = [] |
|
2034 |
self.FilterChoiceTransfer = {"All" : "All", "Interface" : "Interface", |
|
2035 |
"Input" : " Input", "Output" : " Output", "InOut" : " InOut", |
|
2036 |
"External" : " External", "Variables" : "Variables", "Local" : " Local", |
|
2037 |
"Temp" : " Temp", "Global" : "Global", "Access" : "Access"} |
|
2038 |
||
2039 |
if pou_type: |
|
11 | 2040 |
self.DefaultTypes = {"All" : "Input", "Interface" : "Input", "Variables" : "Local"} |
2041 |
self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No"} |
|
0 | 2042 |
else: |
11 | 2043 |
self.DefaultTypes = {"All" : "Global"} |
2044 |
self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No"} |
|
0 | 2045 |
if not pou_type or pou_type == "program": |
2046 |
self.Table = VariableTable(self, [], ["Name", "Class", "Type", "Location", "Initial Value", "Retain", "Constant"]) |
|
2047 |
if pou_type: |
|
2048 |
self.FilterChoices = ["All","Interface"," Input"," Output"," InOut"," External","Variables"," Local"," Temp","Global","Access"] |
|
2049 |
else: |
|
2050 |
self.FilterChoices = ["All","Global","Access"] |
|
2051 |
self.ColSizes = [80, 70, 80, 80, 80, 60, 70] |
|
2052 |
self.ColAlignements = [wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_CENTER, wxALIGN_CENTER] |
|
2053 |
else: |
|
2054 |
self.Table = VariableTable(self, [], ["Name", "Class", "Type", "Initial Value", "Retain", "Constant"]) |
|
2055 |
self.FilterChoices = ["All","Interface"," Input"," Output"," InOut"," External","Variables"," Local"," Temp"] |
|
2056 |
self.ColSizes = [120, 70, 80, 120, 60, 70] |
|
2057 |
self.ColAlignements = [wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_CENTER, wxALIGN_CENTER] |
|
2058 |
for choice in self.FilterChoices: |
|
2059 |
self.ClassFilter.Append(choice) |
|
2060 |
self.ClassFilter.SetStringSelection(self.FilterChoiceTransfer[self.Filter]) |
|
2061 |
self.RefreshTypeList() |
|
2062 |
self.RefreshUpDownButtons() |
|
2063 |
||
2064 |
self.OptionList = "Yes,No" |
|
2065 |
self.TypeList = "" |
|
2066 |
for value in TypeHierarchy.keys(): |
|
2067 |
if not value.startswith("ANY"): |
|
2068 |
self.TypeList += "%s,"%value |
|
2069 |
self.TypeList = self.TypeList[:-1] |
|
2070 |
||
2071 |
if pou_type == "function": |
|
2072 |
for value in TypeHierarchy.keys(): |
|
2073 |
if not value.startswith("ANY"): |
|
2074 |
self.ReturnType.Append(value) |
|
2075 |
self.ReturnType.Enable(True) |
|
2076 |
else: |
|
2077 |
self.ReturnType.Enable(False) |
|
2078 |
self.staticText2.Hide() |
|
2079 |
self.ReturnType.Hide() |
|
2080 |
||
2081 |
self.VariablesGrid.SetTable(self.Table) |
|
2082 |
self.VariablesGrid.SetRowLabelSize(0) |
|
2083 |
||
2084 |
self.Table.ResetView(self.VariablesGrid) |
|
2085 |
||
6 | 2086 |
self.PouNames = [] |
2087 |
||
0 | 2088 |
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
2089 |
||
2090 |
def OnOK(self, event): |
|
2091 |
self.VariablesGrid.SetGridCursor(0, 0) |
|
2092 |
error = [] |
|
2093 |
if self.ReturnType.IsEnabled() and self.ReturnType.GetStringSelection() == "": |
|
2094 |
error.append("Return Type") |
|
2095 |
if len(error) > 0: |
|
2096 |
text = "" |
|
2097 |
for i, item in enumerate(error): |
|
2098 |
if i == 0: |
|
2099 |
text += item |
|
2100 |
elif i == len(error) - 1: |
|
2101 |
text += " and %s"%item |
|
2102 |
else: |
|
2103 |
text += ", %s"%item |
|
2104 |
message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) |
|
2105 |
message.ShowModal() |
|
2106 |
message.Destroy() |
|
2107 |
else: |
|
2108 |
self.EndModal(wxID_OK) |
|
2109 |
||
2110 |
def OnClassFilter(self, event): |
|
2111 |
reverse_transfer = {} |
|
2112 |
for filter, choice in self.FilterChoiceTransfer.items(): |
|
2113 |
reverse_transfer[choice] = filter |
|
2114 |
self.Filter = reverse_transfer[self.ClassFilter.GetStringSelection()] |
|
2115 |
self.RefreshTypeList() |
|
2116 |
self.RefreshValues() |
|
2117 |
self.RefreshUpDownButtons() |
|
2118 |
event.Skip() |
|
2119 |
||
2120 |
def RefreshTypeList(self): |
|
2121 |
if self.Filter == "All": |
|
1 | 2122 |
self.ClassList = [choice for choice in self.FilterChoiceTransfer.keys() if choice not in ["All","Interface","Variables"]] |
0 | 2123 |
elif self.Filter == "Interface": |
2124 |
self.ClassList = ["Input","Output","InOut","External"] |
|
2125 |
elif self.Filter == "Variables": |
|
2126 |
self.ClassList = ["Local","Temp"] |
|
2127 |
else: |
|
2128 |
self.ClassList = [self.Filter] |
|
2129 |
||
2130 |
def RefreshUpDownButtons(self): |
|
2131 |
if self.Filter == "All": |
|
2132 |
self.UpButton.Enable(True) |
|
2133 |
self.DownButton.Enable(True) |
|
2134 |
else: |
|
2135 |
self.UpButton.Enable(False) |
|
2136 |
self.DownButton.Enable(False) |
|
2137 |
||
2138 |
def OnAddButton(self, event): |
|
11 | 2139 |
new_row = self.DefaultValue.copy() |
2140 |
if self.Filter in self.DefaultTypes: |
|
2141 |
new_row["Class"] = self.DefaultTypes[self.Filter] |
|
2142 |
else: |
|
2143 |
new_row["Class"] = self.Filter |
|
12 | 2144 |
self.Values.append(new_row) |
2145 |
self.RefreshValues() |
|
0 | 2146 |
event.Skip() |
2147 |
||
2148 |
def OnDeleteButton(self, event): |
|
12 | 2149 |
row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow()) |
2150 |
self.Values.remove(row) |
|
2151 |
self.RefreshValues() |
|
0 | 2152 |
event.Skip() |
2153 |
||
2154 |
def OnUpButton(self, event): |
|
12 | 2155 |
self.MoveValue(self.VariablesGrid.GetGridCursorRow(), -1) |
0 | 2156 |
event.Skip() |
2157 |
||
2158 |
def OnDownButton(self, event): |
|
12 | 2159 |
self.MoveValue(self.VariablesGrid.GetGridCursorRow(), 1) |
0 | 2160 |
event.Skip() |
2161 |
||
6 | 2162 |
def OnVariablesGridCellChange(self, event): |
2163 |
row, col = event.GetRow(), event.GetCol() |
|
2164 |
colname = self.Table.GetColLabelValue(col) |
|
2165 |
value = self.Table.GetValue(row, col) |
|
2166 |
if colname == "Name": |
|
2167 |
if not TestIdentifier(value): |
|
2168 |
message = wxMessageDialog(self, "\"%s\" is not a valid identifier!"%value, "Error", wxOK|wxICON_ERROR) |
|
2169 |
message.ShowModal() |
|
2170 |
message.Destroy() |
|
2171 |
event.Veto() |
|
2172 |
elif value.upper() in IEC_KEYWORDS: |
|
2173 |
message = wxMessageDialog(self, "\"%s\" is a keyword. It can't be used!"%value, "Error", wxOK|wxICON_ERROR) |
|
2174 |
message.ShowModal() |
|
2175 |
message.Destroy() |
|
2176 |
event.Veto() |
|
2177 |
elif value.upper() in self.PouNames: |
|
2178 |
message = wxMessageDialog(self, "A pou with \"%s\" as name exists!"%value, "Error", wxOK|wxICON_ERROR) |
|
2179 |
message.ShowModal() |
|
2180 |
message.Destroy() |
|
2181 |
event.Veto() |
|
2182 |
elif value.upper() in [var["Name"].upper() for var in self.Values if var != self.Table.data[row]]: |
|
2183 |
message = wxMessageDialog(self, "A variable with \"%s\" as name exists in this pou!"%value, "Error", wxOK|wxICON_ERROR) |
|
2184 |
message.ShowModal() |
|
2185 |
message.Destroy() |
|
2186 |
event.Veto() |
|
2187 |
else: |
|
2188 |
event.Skip() |
|
2189 |
else: |
|
2190 |
event.Skip() |
|
2191 |
||
2192 |
def SetPouNames(self, pou_names): |
|
2193 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
2194 |
||
0 | 2195 |
def SetValues(self, values): |
2196 |
for item, value in values.items(): |
|
2197 |
if item == "returnType" and value and self.ReturnType.IsEnabled(): |
|
2198 |
self.ReturnType.SetStringSelection(value) |
|
2199 |
if item == "data": |
|
2200 |
self.Values = value |
|
2201 |
self.RefreshValues() |
|
12 | 2202 |
|
2203 |
def MoveValue(self, value_index, move): |
|
2204 |
new_index = max(0, min(value_index + move, len(self.Values) - 1)) |
|
2205 |
if new_index != value_index: |
|
2206 |
self.Values.insert(new_index, self.Values.pop(value_index)) |
|
2207 |
self.VariablesGrid.SetGridCursor(new_index, self.VariablesGrid.GetGridCursorCol()) |
|
2208 |
self.RefreshValues() |
|
2209 |
||
0 | 2210 |
def RefreshValues(self): |
2211 |
data = [] |
|
2212 |
for variable in self.Values: |
|
2213 |
if variable["Class"] in self.ClassList: |
|
2214 |
data.append(variable) |
|
2215 |
self.Table.SetData(data) |
|
2216 |
self.Table.ResetView(self.VariablesGrid) |
|
2217 |
||
2218 |
def GetValues(self): |
|
2219 |
values = {} |
|
2220 |
if self.ReturnType.IsEnabled(): |
|
2221 |
values["returnType"] = self.ReturnType.GetStringSelection() |
|
12 | 2222 |
values["data"] = self.Values |
0 | 2223 |
return values |
2224 |
||
2225 |
#------------------------------------------------------------------------------- |
|
2226 |
# Exception Handler |
|
2227 |
#------------------------------------------------------------------------------- |
|
2228 |
||
2229 |
Max_Traceback_List_Size = 20 |
|
2230 |
||
2231 |
def Display_Exception_Dialog(e_type,e_value,e_tb): |
|
2232 |
trcbck_lst = [] |
|
2233 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
|
2234 |
trcbck = " " + str(i+1) + ". " |
|
2235 |
if line[0].find(os.getcwd()) == -1: |
|
2236 |
trcbck += "file : " + str(line[0]) + ", " |
|
2237 |
else: |
|
2238 |
trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " |
|
2239 |
trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) |
|
2240 |
trcbck_lst.append(trcbck) |
|
2241 |
||
2242 |
# Allow clicking.... |
|
2243 |
cap = wx.Window_GetCapture() |
|
2244 |
if cap: |
|
2245 |
cap.ReleaseMouse() |
|
2246 |
||
2247 |
dlg = wx.SingleChoiceDialog(None, |
|
2248 |
""" |
|
2249 |
An error happens. |
|
2250 |
||
2251 |
Click on OK for saving an error report. |
|
2252 |
||
2253 |
Please contact LOLITech at: |
|
2254 |
+33 (0)3 29 52 95 67 |
|
2255 |
bugs_PLCOpenEditor@lolitech.fr |
|
2256 |
||
2257 |
||
2258 |
Error: |
|
2259 |
""" + |
|
2260 |
str(e_type) + " : " + str(e_value), |
|
2261 |
"Error", |
|
2262 |
trcbck_lst) |
|
2263 |
try: |
|
2264 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
2265 |
finally: |
|
2266 |
dlg.Destroy() |
|
2267 |
||
2268 |
return res |
|
2269 |
||
2270 |
def Display_Error_Dialog(e_value): |
|
2271 |
message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR) |
|
2272 |
message.ShowModal() |
|
2273 |
message.Destroy() |
|
2274 |
||
2275 |
def get_last_traceback(tb): |
|
2276 |
while tb.tb_next: |
|
2277 |
tb = tb.tb_next |
|
2278 |
return tb |
|
2279 |
||
2280 |
||
2281 |
def format_namespace(d, indent=' '): |
|
2282 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
2283 |
||
2284 |
||
2285 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
|
2286 |
||
2287 |
def wxAddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
|
2288 |
||
2289 |
def handle_exception(e_type, e_value, e_traceback): |
|
2290 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
|
2291 |
last_tb = get_last_traceback(e_traceback) |
|
2292 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
2293 |
if str(e_value).startswith("!!!"): |
|
2294 |
Display_Error_Dialog(e_value) |
|
2295 |
elif ex not in ignored_exceptions: |
|
2296 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback) |
|
2297 |
if result: |
|
2298 |
ignored_exceptions.append(ex) |
|
2299 |
info = { |
|
2300 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
|
2301 |
'app-version' : app_version, |
|
2302 |
'wx-version' : wx.VERSION_STRING, |
|
2303 |
'wx-platform' : wx.Platform, |
|
2304 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
|
2305 |
'platform' : platform.platform(), |
|
2306 |
'e-type' : e_type, |
|
2307 |
'e-value' : e_value, |
|
2308 |
'date' : time.ctime(), |
|
2309 |
'cwd' : os.getcwd(), |
|
2310 |
} |
|
2311 |
if e_traceback: |
|
2312 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
2313 |
last_tb = get_last_traceback(e_traceback) |
|
2314 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
2315 |
info['locals'] = format_namespace(exception_locals) |
|
2316 |
if 'self' in exception_locals: |
|
2317 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
2318 |
||
2319 |
output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') |
|
2320 |
lst = info.keys() |
|
2321 |
lst.sort() |
|
2322 |
for a in lst: |
|
2323 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
2324 |
||
2325 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
2326 |
sys.excepthook = handle_exception |
|
2327 |
||
2328 |
if __name__ == '__main__': |
|
2329 |
app = wxPySimpleApp() |
|
2330 |
wxInitAllImageHandlers() |
|
2331 |
||
2332 |
# Install a exception handle for bug reports |
|
2333 |
wxAddExceptHook(os.getcwd(),__version__) |
|
2334 |
||
2335 |
frame = PLCOpenEditor(None) |
|
2336 |
||
2337 |
frame.Show() |
|
2338 |
app.MainLoop() |
|
2339 |