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