author | lbessard |
Thu, 19 Jul 2007 11:53:14 +0200 | |
changeset 45 | 42637f721b5b |
parent 42 | 4a8400732001 |
child 46 | 4379e98a30aa |
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 |
||
39 |
import os, re, platform, sys, time, traceback, getopt |
|
40 |
||
41 |
__version__ = "$Revision$" |
|
42 |
||
43 |
def create(parent): |
|
44 |
return PLCOpenEditor(parent) |
|
45 |
||
46 |
def usage(): |
|
47 |
print "\nUsage of PLCOpenEditor.py :" |
|
48 |
print "\n %s [Filepath]\n"%sys.argv[0] |
|
49 |
||
50 |
try: |
|
51 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
|
52 |
except getopt.GetoptError: |
|
53 |
# print help information and exit: |
|
54 |
usage() |
|
55 |
sys.exit(2) |
|
56 |
||
57 |
for o, a in opts: |
|
58 |
if o in ("-h", "--help"): |
|
59 |
usage() |
|
60 |
sys.exit() |
|
61 |
||
62 |
fileOpen = None |
|
63 |
if len(args) > 1: |
|
64 |
usage() |
|
65 |
sys.exit() |
|
66 |
elif len(args) == 1: |
|
67 |
fileOpen = args[0] |
|
6 | 68 |
CWD = sys.path[0] |
0 | 69 |
|
70 |
[wxID_PLCOPENEDITOR, wxID_PLCOPENEDITORPROJECTTREE, |
|
6 | 71 |
wxID_PLCOPENEDITORSPLITTERWINDOW1, wxID_PLCOPENEDITOREDITORPANEL, |
72 |
wxID_PLCOPENEDITORTABSOPENED, wxID_PLCOPENEDITORTOOLBAR, |
|
73 |
wxID_PLCOPENEDITORDEFAULTTOOLBAR, wxID_PLCOPENEDITORSFCTOOLBAR, |
|
0 | 74 |
wxID_PLCOPENEDITORFBDTOOLBAR, wxID_PLCOPENEDITORLDTOOLBAR, |
6 | 75 |
] = [wx.NewId() for _init_ctrls in range(10)] |
76 |
||
0 | 77 |
[wxID_PLCOPENEDITORFILEMENUITEMS0, wxID_PLCOPENEDITORFILEMENUITEMS1, |
78 |
wxID_PLCOPENEDITORFILEMENUITEMS2, wxID_PLCOPENEDITORFILEMENUITEMS3, |
|
79 |
wxID_PLCOPENEDITORFILEMENUITEMS5, wxID_PLCOPENEDITORFILEMENUITEMS6, |
|
80 |
wxID_PLCOPENEDITORFILEMENUITEMS7, wxID_PLCOPENEDITORFILEMENUITEMS9, |
|
81 |
wxID_PLCOPENEDITORFILEMENUITEMS11, |
|
82 |
] = [wx.NewId() for _init_coll_FileMenu_Items in range(9)] |
|
83 |
||
84 |
[wxID_PLCOPENEDITORHELPMENUITEMS0, wxID_PLCOPENEDITORHELPMENUITEMS1, |
|
85 |
wxID_PLCOPENEDITORHELPMENUITEMS2, wxID_PLCOPENEDITORHELPMENUITEMS3, |
|
86 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(4)] |
|
87 |
||
88 |
[wxID_PLCOPENEDITORSFCMENUITEMS0, wxID_PLCOPENEDITORSFCMENUITEMS1, |
|
89 |
wxID_PLCOPENEDITORSFCMENUITEMS2, wxID_PLCOPENEDITORSFCMENUITEMS3, |
|
90 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(4)] |
|
91 |
||
92 |
[wxID_PLCOPENEDITORCONFIGMENUITEMS0, wxID_PLCOPENEDITORCONFIGMENUITEMS1, |
|
93 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(2)] |
|
94 |
||
95 |
[wxID_PLCOPENEDITOREDITMENUITEMS0, wxID_PLCOPENEDITOREDITMENUITEMS1, |
|
96 |
wxID_PLCOPENEDITOREDITMENUITEMS11, wxID_PLCOPENEDITOREDITMENUITEMS12, |
|
97 |
wxID_PLCOPENEDITOREDITMENUITEMS2, wxID_PLCOPENEDITOREDITMENUITEMS4, |
|
98 |
wxID_PLCOPENEDITOREDITMENUITEMS5, wxID_PLCOPENEDITOREDITMENUITEMS6, |
|
99 |
wxID_PLCOPENEDITOREDITMENUITEMS8, wxID_PLCOPENEDITOREDITMENUITEMS9, |
|
100 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(10)] |
|
101 |
||
102 |
[wxID_PLCOPENEDITORSFCMENUITEMS0, wxID_PLCOPENEDITORSFCMENUITEMS1, |
|
103 |
wxID_PLCOPENEDITORSFCMENUITEMS2, wxID_PLCOPENEDITORSFCMENUITEMS3, |
|
104 |
] = [wx.NewId() for _init_coll_SFCMenu_Items in range(4)] |
|
105 |
||
106 |
[wxID_PLCOPENEDITORCONFIGMENUITEMS0, wxID_PLCOPENEDITORCONFIGMENUITEMS1, |
|
107 |
] = [wx.NewId() for _init_coll_ConfigMenu_Items in range(2)] |
|
108 |
||
27 | 109 |
|
110 |
#------------------------------------------------------------------------------- |
|
111 |
# ToolBars definitions |
|
112 |
#------------------------------------------------------------------------------- |
|
113 |
||
114 |
||
115 |
[wxID_PLCOPENEDITORTOOLBARSELECTION, wxID_PLCOPENEDITORTOOLBARCOMMENT, |
|
116 |
wxID_PLCOPENEDITORTOOLBARVARIABLE, wxID_PLCOPENEDITORTOOLBARBLOCK, |
|
117 |
wxID_PLCOPENEDITORTOOLBARCONNECTION, wxID_PLCOPENEDITORTOOLBARWIRE, |
|
118 |
wxID_PLCOPENEDITORTOOLBARPOWERRAIL, wxID_PLCOPENEDITORTOOLBARRUNG, |
|
119 |
wxID_PLCOPENEDITORTOOLBARCOIL, wxID_PLCOPENEDITORTOOLBARCONTACT, |
|
120 |
wxID_PLCOPENEDITORTOOLBARBRANCH, wxID_PLCOPENEDITORTOOLBARINITIALSTEP, |
|
121 |
wxID_PLCOPENEDITORTOOLBARSTEP, wxID_PLCOPENEDITORTOOLBARTRANSITION, |
|
122 |
wxID_PLCOPENEDITORTOOLBARACTIONBLOCK, wxID_PLCOPENEDITORTOOLBARDIVERGENCE, |
|
123 |
wxID_PLCOPENEDITORTOOLBARJUMP, |
|
124 |
] = [wx.NewId() for _init_coll_DefaultToolBar_Items in range(17)] |
|
125 |
||
126 |
ToolBarItems = { |
|
127 |
"FBD" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", "Images/comment.png", "Create a new comment"), |
|
128 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", "Images/variable.png", "Create a new variable"), |
|
129 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", "Images/block.png", "Create a new block"), |
|
130 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", "Images/connection.png", "Create a new connection"), |
|
131 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARWIRE, "OnWireTool", "Images/wire.png", "Create a new wire")], |
|
132 |
"LD" : [(True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", "Images/comment.png", "Create a new comment"), |
|
133 |
(True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARPOWERRAIL, "OnPowerRailTool", "Images/powerrail.png", "Create a new power rail"), |
|
134 |
(False, DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARRUNG, "OnRungTool", "Images/rung.png", "Create a new rung"), |
|
135 |
(True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCOIL, "OnCoilTool", "Images/coil.png", "Create a new coil"), |
|
136 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCONTACT, "OnContactTool", "Images/contact.png", "Create a new contact"), |
|
137 |
(False, DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARBRANCH, "OnBranchTool", "Images/branch.png", "Create a new branch"), |
|
138 |
(True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", "Images/variable.png", "Create a new variable"), |
|
139 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", "Images/block.png", "Create a new block"), |
|
140 |
(True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", "Images/connection.png", "Create a new connection"), |
|
141 |
(True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARWIRE, "OnWireTool", "Images/wire.png", "Create a new wire")], |
|
142 |
"SFC" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", "Images/comment.png", "Create a new comment"), |
|
143 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARINITIALSTEP, "OnInitialStepTool", "Images/initial_step.png", "Create a new initial step"), |
|
144 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARSTEP, "OnStepTool", "Images/step.png", "Create a new step"), |
|
145 |
(True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARTRANSITION, "OnTransitionTool", "Images/transition.png", "Create a new transition"), |
|
146 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARACTIONBLOCK, "OnActionBlockTool", "Images/action.png", "Create a new action block"), |
|
147 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARDIVERGENCE, "OnDivergenceTool", "Images/divergence.png", "Create a new divergence"), |
|
148 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARJUMP, "OnJumpTool", "Images/jump.png", "Create a new jump"), |
|
149 |
(True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", "Images/variable.png", "Create a new variable"), |
|
150 |
(True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", "Images/block.png", "Create a new block"), |
|
151 |
(True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", "Images/connection.png", "Create a new connection"), |
|
152 |
(True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARPOWERRAIL, "OnPowerRailTool", "Images/powerrail.png", "Create a new power rail"), |
|
153 |
(True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCONTACT, "OnContactTool", "Images/contact.png", "Create a new contact"), |
|
154 |
(True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARWIRE, "OnWireTool", "Images/wire.png", "Create a new wire")], |
|
155 |
"ST" : [], |
|
156 |
"IL" : [] |
|
157 |
} |
|
158 |
||
0 | 159 |
class PLCOpenEditor(wx.Frame): |
160 |
_custom_classes = {'wx.SashWindow' : ['Viewer']} |
|
161 |
||
162 |
def _init_coll_EditMenu_Items(self, parent): |
|
163 |
# generated method, don't edit |
|
164 |
||
165 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS0, |
|
166 |
kind=wx.ITEM_NORMAL, text=u'Refresh\tCTRL+R') |
|
167 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS1, |
|
168 |
kind=wx.ITEM_NORMAL, text=u'Undo\tCTRL+Z') |
|
169 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS2, |
|
170 |
kind=wx.ITEM_NORMAL, text=u'Redo\tCTRL+Y') |
|
171 |
parent.AppendSeparator() |
|
172 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS4, |
|
173 |
kind=wx.ITEM_NORMAL, text=u'Cut\tCTRL+X') |
|
174 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS5, |
|
175 |
kind=wx.ITEM_NORMAL, text=u'Copy\tCTRL+C') |
|
176 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS6, |
|
177 |
kind=wx.ITEM_NORMAL, text=u'Paste\tCTRL+V') |
|
178 |
parent.AppendSeparator() |
|
179 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS8, |
|
180 |
kind=wx.ITEM_NORMAL, text=u'Add POU') |
|
181 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS9, |
|
182 |
kind=wx.ITEM_NORMAL, text=u'Remove POU') |
|
183 |
parent.AppendSeparator() |
|
184 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS11, |
|
185 |
kind=wx.ITEM_NORMAL, text=u'Add Configuration') |
|
186 |
parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS12, |
|
187 |
kind=wx.ITEM_NORMAL, text=u'Remove Configuration') |
|
188 |
self.Bind(wx.EVT_MENU, self.OnRefreshMenu, |
|
189 |
id=wxID_PLCOPENEDITOREDITMENUITEMS0) |
|
190 |
self.Bind(wx.EVT_MENU, self.OnCutMenu, |
|
191 |
id=wxID_PLCOPENEDITOREDITMENUITEMS4) |
|
192 |
self.Bind(wx.EVT_MENU, self.OnCopyMenu, |
|
193 |
id=wxID_PLCOPENEDITOREDITMENUITEMS5) |
|
194 |
self.Bind(wx.EVT_MENU, self.OnPasteMenu, |
|
195 |
id=wxID_PLCOPENEDITOREDITMENUITEMS6) |
|
196 |
self.Bind(wx.EVT_MENU, self.OnAddPouMenu, |
|
197 |
id=wxID_PLCOPENEDITOREDITMENUITEMS8) |
|
198 |
self.Bind(wx.EVT_MENU, self.OnRemovePouMenu, |
|
199 |
id=wxID_PLCOPENEDITOREDITMENUITEMS9) |
|
200 |
self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu, |
|
201 |
id=wxID_PLCOPENEDITOREDITMENUITEMS11) |
|
202 |
self.Bind(wx.EVT_MENU, self.OnRemoveConfigurationMenu, |
|
203 |
id=wxID_PLCOPENEDITOREDITMENUITEMS12) |
|
204 |
||
205 |
def _init_coll_menuBar1_Menus(self, parent): |
|
206 |
# generated method, don't edit |
|
207 |
||
208 |
parent.Append(menu=self.FileMenu, title=u'File') |
|
209 |
parent.Append(menu=self.EditMenu, title=u'Edit') |
|
210 |
parent.Append(menu=self.HelpMenu, title=u'Help') |
|
211 |
||
212 |
def _init_coll_ConfigMenu_Items(self, parent): |
|
213 |
# generated method, don't edit |
|
214 |
||
215 |
parent.Append(help='', id=wxID_PLCOPENEDITORCONFIGMENUITEMS0, |
|
216 |
kind=wx.ITEM_NORMAL, text=u'Add Resource') |
|
217 |
parent.Append(help='', id=wxID_PLCOPENEDITORCONFIGMENUITEMS1, |
|
218 |
kind=wx.ITEM_NORMAL, text=u'Remove Resource') |
|
219 |
self.Bind(wx.EVT_MENU, self.OnAddResourceMenu, |
|
220 |
id=wxID_PLCOPENEDITORCONFIGMENUITEMS0) |
|
221 |
self.Bind(wx.EVT_MENU, self.OnRemoveResourceMenu, |
|
222 |
id=wxID_PLCOPENEDITORCONFIGMENUITEMS1) |
|
223 |
||
224 |
def _init_coll_HelpMenu_Items(self, parent): |
|
225 |
# generated method, don't edit |
|
226 |
||
227 |
parent.Append(help='', id=wxID_PLCOPENEDITORHELPMENUITEMS0, |
|
228 |
kind=wx.ITEM_NORMAL, text=u'PLCOpenEditor\tF1') |
|
229 |
parent.Append(help='', id=wxID_PLCOPENEDITORHELPMENUITEMS1, |
|
230 |
kind=wx.ITEM_NORMAL, text=u'PLCOpen\tF2') |
|
231 |
parent.Append(help='', id=wxID_PLCOPENEDITORHELPMENUITEMS2, |
|
232 |
kind=wx.ITEM_NORMAL, text=u'IEC 61131-3\tF3') |
|
233 |
parent.Append(help='', id=wxID_PLCOPENEDITORHELPMENUITEMS3, |
|
234 |
kind=wx.ITEM_NORMAL, text=u'About') |
|
235 |
self.Bind(wx.EVT_MENU, self.OnPLCOpenMenu, |
|
236 |
id=wxID_PLCOPENEDITORHELPMENUITEMS1) |
|
237 |
||
238 |
def _init_coll_FileMenu_Items(self, parent): |
|
239 |
# generated method, don't edit |
|
240 |
||
241 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS0, |
|
242 |
kind=wx.ITEM_NORMAL, text=u'New\tCTRL+N') |
|
243 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS1, |
|
244 |
kind=wx.ITEM_NORMAL, text=u'Open\tCTRL+O') |
|
245 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS2, |
|
246 |
kind=wx.ITEM_NORMAL, text=u'Close Tab\tCTRL+W') |
|
247 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS3, |
|
248 |
kind=wx.ITEM_NORMAL, text=u'Close Project') |
|
249 |
parent.AppendSeparator() |
|
250 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS5, |
|
251 |
kind=wx.ITEM_NORMAL, text=u'Save\tCTRL+S') |
|
252 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS6, |
|
253 |
kind=wx.ITEM_NORMAL, text=u'Save As...\tCTRL+SHIFT+S') |
|
254 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS7, |
|
255 |
kind=wx.ITEM_NORMAL, text=u'Generate Program\tCTRL+G') |
|
256 |
parent.AppendSeparator() |
|
257 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS9, |
|
258 |
kind=wx.ITEM_NORMAL, text=u'Properties') |
|
259 |
parent.AppendSeparator() |
|
260 |
parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS11, |
|
261 |
kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q') |
|
262 |
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, |
|
263 |
id=wxID_PLCOPENEDITORFILEMENUITEMS0) |
|
264 |
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, |
|
265 |
id=wxID_PLCOPENEDITORFILEMENUITEMS1) |
|
266 |
self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, |
|
267 |
id=wxID_PLCOPENEDITORFILEMENUITEMS2) |
|
268 |
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, |
|
269 |
id=wxID_PLCOPENEDITORFILEMENUITEMS3) |
|
270 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, |
|
271 |
id=wxID_PLCOPENEDITORFILEMENUITEMS5) |
|
272 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, |
|
273 |
id=wxID_PLCOPENEDITORFILEMENUITEMS6) |
|
274 |
self.Bind(wx.EVT_MENU, self.OnGenerateProgramMenu, |
|
275 |
id=wxID_PLCOPENEDITORFILEMENUITEMS7) |
|
27 | 276 |
self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, |
277 |
id=wxID_PLCOPENEDITORFILEMENUITEMS9) |
|
0 | 278 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, |
279 |
id=wxID_PLCOPENEDITORFILEMENUITEMS11) |
|
280 |
||
281 |
def _init_coll_SFCMenu_Items(self, parent): |
|
282 |
# generated method, don't edit |
|
283 |
||
284 |
parent.Append(help='', id=wxID_PLCOPENEDITORSFCMENUITEMS0, |
|
285 |
kind=wx.ITEM_NORMAL, text=u'Add Transition') |
|
286 |
parent.Append(help='', id=wxID_PLCOPENEDITORSFCMENUITEMS1, |
|
287 |
kind=wx.ITEM_NORMAL, text=u'Add Action') |
|
288 |
parent.Append(help='', id=wxID_PLCOPENEDITORSFCMENUITEMS2, |
|
289 |
kind=wx.ITEM_NORMAL, text=u'Remove Transition') |
|
290 |
parent.Append(help='', id=wxID_PLCOPENEDITORSFCMENUITEMS3, |
|
291 |
kind=wx.ITEM_NORMAL, text=u'Remove Action') |
|
292 |
self.Bind(wx.EVT_MENU, self.OnAddPouTransitionMenu, |
|
293 |
id=wxID_PLCOPENEDITORSFCMENUITEMS0) |
|
294 |
self.Bind(wx.EVT_MENU, self.OnAddPouActionMenu, |
|
295 |
id=wxID_PLCOPENEDITORSFCMENUITEMS1) |
|
296 |
self.Bind(wx.EVT_MENU, self.OnRemovePouTransitionMenu, |
|
297 |
id=wxID_PLCOPENEDITORSFCMENUITEMS2) |
|
298 |
self.Bind(wx.EVT_MENU, self.OnRemovePouActionMenu, |
|
299 |
id=wxID_PLCOPENEDITORSFCMENUITEMS3) |
|
300 |
||
301 |
def _init_utils(self): |
|
302 |
# generated method, don't edit |
|
303 |
self.menuBar1 = wx.MenuBar() |
|
304 |
||
305 |
self.FileMenu = wx.Menu(title=u'') |
|
306 |
||
307 |
self.EditMenu = wx.Menu(title=u'') |
|
308 |
||
309 |
self.HelpMenu = wx.Menu(title='') |
|
310 |
||
311 |
self.SFCMenu = wx.Menu(title='') |
|
312 |
||
313 |
self.ConfigMenu = wx.Menu(title='') |
|
314 |
||
315 |
self._init_coll_menuBar1_Menus(self.menuBar1) |
|
316 |
self._init_coll_FileMenu_Items(self.FileMenu) |
|
317 |
self._init_coll_EditMenu_Items(self.EditMenu) |
|
318 |
self._init_coll_HelpMenu_Items(self.HelpMenu) |
|
319 |
self._init_coll_SFCMenu_Items(self.SFCMenu) |
|
320 |
self._init_coll_ConfigMenu_Items(self.ConfigMenu) |
|
321 |
||
322 |
def _init_coll_MainGridSizer_Items(self, parent): |
|
323 |
# generated method, don't edit |
|
324 |
||
325 |
parent.AddWindow(self.splitterWindow1, 0, border=0, flag=wxGROW) |
|
326 |
||
6 | 327 |
def _init_coll_EditorGridSizer_Items(self, parent): |
328 |
# generated method, don't edit |
|
329 |
||
330 |
parent.AddWindow(self.ToolBar, 0, border=0, flag=wxGROW) |
|
331 |
parent.AddWindow(self.TabsOpened, 0, border=0, flag=wxGROW) |
|
332 |
||
0 | 333 |
def _init_coll_MainGridSizer_Growables(self, parent): |
334 |
# generated method, don't edit |
|
335 |
||
336 |
parent.AddGrowableCol(0) |
|
337 |
parent.AddGrowableRow(0) |
|
338 |
||
6 | 339 |
def _init_coll_EditorGridSizer_Growables(self, parent): |
340 |
# generated method, don't edit |
|
341 |
||
342 |
parent.AddGrowableCol(0) |
|
343 |
parent.AddGrowableRow(1) |
|
344 |
||
0 | 345 |
def _init_sizers(self): |
346 |
# generated method, don't edit |
|
347 |
self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=0) |
|
348 |
||
6 | 349 |
self.EditorGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
350 |
||
0 | 351 |
self._init_coll_MainGridSizer_Growables(self.MainGridSizer) |
352 |
self._init_coll_MainGridSizer_Items(self.MainGridSizer) |
|
6 | 353 |
self._init_coll_EditorGridSizer_Growables(self.EditorGridSizer) |
354 |
self._init_coll_EditorGridSizer_Items(self.EditorGridSizer) |
|
355 |
||
0 | 356 |
self.SetSizer(self.MainGridSizer) |
6 | 357 |
self.EditorPanel.SetSizer(self.EditorGridSizer) |
0 | 358 |
|
359 |
def _init_ctrls(self, prnt): |
|
360 |
# generated method, don't edit |
|
361 |
wx.Frame.__init__(self, id=wxID_PLCOPENEDITOR, name=u'PLCOpenEditor', |
|
362 |
parent=prnt, pos=wx.Point(235, 287), size=wx.Size(1000, 600), |
|
363 |
style=wx.DEFAULT_FRAME_STYLE, title=u'PLCOpenEditor') |
|
364 |
self._init_utils() |
|
365 |
self.SetClientSize(wx.Size(1000, 600)) |
|
366 |
self.SetMenuBar(self.menuBar1) |
|
7 | 367 |
|
368 |
self.splitterWindow1 = wx.SplitterWindow(id=wxID_PLCOPENEDITORSPLITTERWINDOW1, |
|
369 |
name='splitterWindow1', parent=self, point=wx.Point(0, 0), |
|
370 |
size=wx.Size(-1, -1), style=wx.SP_3D) |
|
371 |
self.splitterWindow1.SetNeedUpdating(True) |
|
372 |
self.splitterWindow1.SetMinimumPaneSize(1) |
|
373 |
||
374 |
self.EditorPanel = wx.Panel(id=wxID_PLCOPENEDITOREDITORPANEL, |
|
375 |
name='TabPanel', parent=self.splitterWindow1, pos=wx.Point(0, 0), |
|
376 |
size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) |
|
377 |
||
378 |
self.TabsOpened = wx.Notebook(id=wxID_PLCOPENEDITORTABSOPENED, |
|
379 |
name='TabsOpened', parent=self.EditorPanel, pos=wx.Point(0, |
|
380 |
0), size=wx.Size(-1, -1), style=0) |
|
381 |
self.TabsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, |
|
382 |
self.OnPouSelectedChanged, id=wxID_PLCOPENEDITORTABSOPENED) |
|
383 |
||
384 |
self.ToolBar = wxToolBar(id=wxID_PLCOPENEDITORTOOLBAR, name='ToolBar', |
|
385 |
parent=self.EditorPanel, pos=wx.Point(0, 0), size=wx.Size(0, 40), |
|
386 |
style=wxTB_HORIZONTAL | wxNO_BORDER) |
|
27 | 387 |
self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORTOOLBARSELECTION, |
7 | 388 |
wxBitmap(os.path.join(CWD, 'Images/select.png')), wxNullBitmap, "Select an object") |
389 |
self.Bind(wx.EVT_TOOL, self.OnSelectionTool, |
|
27 | 390 |
id=wxID_PLCOPENEDITORTOOLBARSELECTION) |
7 | 391 |
|
392 |
self.ProjectTree = wx.TreeCtrl(id=wxID_PLCOPENEDITORPROJECTTREE, |
|
393 |
name='treeCtrl1', parent=self.splitterWindow1, pos=wx.Point(0, 0), |
|
394 |
size=wx.Size(-1, -1), |
|
395 |
style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER) |
|
27 | 396 |
self.ProjectTree.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp) |
7 | 397 |
self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnProjectTreeBeginDrag, |
398 |
id=wxID_PLCOPENEDITORPROJECTTREE) |
|
0 | 399 |
self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit, |
400 |
id=wxID_PLCOPENEDITORPROJECTTREE) |
|
401 |
self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnProjectTreeItemEndEdit, |
|
402 |
id=wxID_PLCOPENEDITORPROJECTTREE) |
|
403 |
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnProjectTreeItemActivated, |
|
404 |
id=wxID_PLCOPENEDITORPROJECTTREE) |
|
405 |
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnProjectTreeItemSelected, |
|
406 |
id=wxID_PLCOPENEDITORPROJECTTREE) |
|
6 | 407 |
self.splitterWindow1.SplitVertically(self.ProjectTree, self.EditorPanel, |
0 | 408 |
200) |
409 |
||
410 |
self._init_sizers() |
|
411 |
||
412 |
def __init__(self, parent): |
|
413 |
self._init_ctrls(parent) |
|
414 |
||
9 | 415 |
self.TreeImageList = wxImageList(16, 16) |
416 |
for language in LANGUAGES: |
|
417 |
self.TreeImageList.Add(wxBitmap(os.path.join(CWD, 'Images/%s.png'%language))) |
|
418 |
self.ProjectTree.SetImageList(self.TreeImageList) |
|
419 |
||
0 | 420 |
self.Controler = PLCControler() |
421 |
||
422 |
if fileOpen: |
|
423 |
self.Controler.OpenXMLFile(fileOpen) |
|
424 |
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
|
425 |
|
6 | 426 |
self.CurrentToolBar = [] |
27 | 427 |
self.CurrentLanguage = "" |
41 | 428 |
#self.DrawingMode = FREEDRAWING_MODE |
429 |
self.DrawingMode = DRIVENDRAWING_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): |
|
42 | 559 |
dialog = wxFileDialog(self, "Choose a file", os.getcwd(), self.Controler.GetProgramFilePath(), "ST files (*.st)|*.st|All files|*.*", wxSAVE|wxCHANGE_DIR) |
4
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): |
0 | 644 |
selected = self.TabsOpened.GetSelection() |
645 |
if selected != -1: |
|
646 |
self.TabsOpened.GetPage(selected).SetMode(MODE_BLOCK) |
|
647 |
event.Skip() |
|
648 |
||
27 | 649 |
def OnConnectionTool(self, event): |
650 |
self.ResetToolToggle(wxID_PLCOPENEDITORTOOLBARCONNECTION) |
|
0 | 651 |
selected = self.TabsOpened.GetSelection() |
652 |
if selected != -1: |
|
653 |
self.TabsOpened.GetPage(selected).SetMode(MODE_CONNECTION) |
|
654 |
event.Skip() |
|
655 |
||
27 | 656 |
def OnWireTool(self, event): |
657 |
self.ResetToolToggle(wxID_PLCOPENEDITORTOOLBARWIRE) |
|
6 | 658 |
selected = self.TabsOpened.GetSelection() |
659 |
if selected != -1: |
|
660 |
self.TabsOpened.GetPage(selected).SetMode(MODE_WIRE) |
|
661 |
event.Skip() |
|
662 |
||
27 | 663 |
def OnPowerRailTool(self, event): |
664 |
self.ResetToolToggle(wxID_PLCOPENEDITORTOOLBARPOWERRAIL) |
|
665 |
selected = self.TabsOpened.GetSelection() |
|
666 |
if selected != -1: |
|
667 |
self.TabsOpened.GetPage(selected).SetMode(MODE_POWERRAIL) |
|
668 |
event.Skip() |
|
669 |
||
670 |
def OnRungTool(self, event): |
|
0 | 671 |
selected = self.TabsOpened.GetSelection() |
672 |
if selected != -1: |
|
42 | 673 |
self.TabsOpened.GetPage(selected).AddLadderRung() |
0 | 674 |
event.Skip() |
675 |
||
27 | 676 |
def OnCoilTool(self, event): |
677 |
self.ResetToolToggle(wxID_PLCOPENEDITORTOOLBARCOIL) |
|
0 | 678 |
selected = self.TabsOpened.GetSelection() |
679 |
if selected != -1: |
|
27 | 680 |
self.TabsOpened.GetPage(selected).SetMode(MODE_COIL) |
681 |
event.Skip() |
|
682 |
||
683 |
def OnContactTool(self, event): |
|
684 |
if self.DrawingMode == FREEDRAWING_MODE: |
|
685 |
self.ResetToolToggle(wxID_PLCOPENEDITORTOOLBARCONTACT) |
|
0 | 686 |
selected = self.TabsOpened.GetSelection() |
687 |
if selected != -1: |
|
27 | 688 |
if self.DrawingMode == FREEDRAWING_MODE: |
689 |
self.TabsOpened.GetPage(selected).SetMode(MODE_CONTACT) |
|
690 |
else: |
|
42 | 691 |
self.TabsOpened.GetPage(selected).AddLadderContact() |
27 | 692 |
event.Skip() |
693 |
||
694 |
def OnBranchTool(self, event): |
|
0 | 695 |
selected = self.TabsOpened.GetSelection() |
696 |
if selected != -1: |
|
42 | 697 |
self.TabsOpened.GetPage(selected).AddLadderBranch() |
27 | 698 |
event.Skip() |
699 |
||
700 |
def OnInitialStepTool(self, event): |
|
701 |
self.ResetToolToggle(wxID_PLCOPENEDITORTOOLBARINITIALSTEP) |
|
702 |
selected = self.TabsOpened.GetSelection() |
|
703 |
if selected != -1: |
|
704 |
self.TabsOpened.GetPage(selected).SetMode(MODE_INITIALSTEP) |
|
705 |
event.Skip() |
|
706 |
||
707 |
def OnStepTool(self, event): |
|
708 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
709 |
self.ResetToolToggle(wxID_PLCOPENEDITORTOOLBARSTEP) |
|
710 |
selected = self.TabsOpened.GetSelection() |
|
711 |
if selected != -1: |
|
712 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
713 |
self.TabsOpened.GetPage(selected).SetMode(MODE_STEP) |
|
714 |
else: |
|
715 |
self.TabsOpened.GetPage(selected).AddStep() |
|
716 |
event.Skip() |
|
717 |
||
718 |
def OnActionBlockTool(self, event): |
|
719 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
720 |
self.ResetToolToggle(wxID_PLCOPENEDITORTOOLBARACTIONBLOCK) |
|
721 |
selected = self.TabsOpened.GetSelection() |
|
722 |
if selected != -1: |
|
723 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
724 |
self.TabsOpened.GetPage(selected).SetMode(MODE_ACTION) |
|
725 |
else: |
|
726 |
self.TabsOpened.GetPage(selected).AddStepAction() |
|
727 |
event.Skip() |
|
728 |
||
729 |
def OnTransitionTool(self, event): |
|
730 |
self.ResetToolToggle(wxID_PLCOPENEDITORTOOLBARTRANSITION) |
|
731 |
selected = self.TabsOpened.GetSelection() |
|
732 |
if selected != -1: |
|
733 |
self.TabsOpened.GetPage(selected).SetMode(MODE_TRANSITION) |
|
734 |
event.Skip() |
|
735 |
||
736 |
def OnDivergenceTool(self, event): |
|
737 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
738 |
self.ResetToolToggle(wxID_PLCOPENEDITORTOOLBARDIVERGENCE) |
|
739 |
selected = self.TabsOpened.GetSelection() |
|
740 |
if selected != -1: |
|
741 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
742 |
self.TabsOpened.GetPage(selected).SetMode(MODE_DIVERGENCE) |
|
743 |
else: |
|
744 |
self.TabsOpened.GetPage(selected).AddDivergence() |
|
745 |
event.Skip() |
|
746 |
||
747 |
def OnJumpTool(self, event): |
|
748 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
749 |
self.ResetToolToggle(wxID_PLCOPENEDITORTOOLBARJUMP) |
|
750 |
selected = self.TabsOpened.GetSelection() |
|
751 |
if selected != -1: |
|
752 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
753 |
self.TabsOpened.GetPage(selected).SetMode(MODE_JUMP) |
|
754 |
else: |
|
755 |
self.TabsOpened.GetPage(selected).AddJump() |
|
0 | 756 |
event.Skip() |
757 |
||
758 |
def OnPouSelectedChanged(self, event): |
|
759 |
selected = event.GetSelection() |
|
760 |
if selected >= 0: |
|
761 |
self.Controler.RefreshCurrentElementEditing(selected) |
|
762 |
found = False |
|
763 |
name = self.TabsOpened.GetPageText(selected) |
|
764 |
root = self.ProjectTree.GetRootItem() |
|
765 |
item, root_cookie = self.ProjectTree.GetFirstChild(root) |
|
766 |
while item.IsOk() and not found: |
|
767 |
if self.ProjectTree.GetItemText(item) == name: |
|
768 |
self.ProjectTree.SelectItem(item) |
|
769 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
|
770 |
self.RefreshFileMenu() |
|
771 |
self.RefreshEditMenu() |
|
772 |
self.RefreshToolBar() |
|
773 |
event.Skip() |
|
774 |
||
7 | 775 |
def OnProjectTreeBeginDrag(self, event): |
776 |
item = event.GetItem() |
|
777 |
if self.ProjectTree.GetPyData(item) == ITEM_VARIABLE: |
|
778 |
data = wxTextDataObject(self.ProjectTree.GetItemText(item)) |
|
779 |
dragSource = wxDropSource(self.ProjectTree) |
|
780 |
dragSource.SetData(data) |
|
781 |
dragSource.DoDragDrop() |
|
782 |
event.Skip() |
|
783 |
||
0 | 784 |
def OnProjectTreeItemEndEdit(self, event): |
6 | 785 |
message = None |
786 |
abort = False |
|
0 | 787 |
new_name = event.GetLabel() |
788 |
if new_name != "": |
|
6 | 789 |
if not TestIdentifier(new_name): |
790 |
message = "\"%s\" is not a valid identifier!"%new_name |
|
791 |
elif new_name.upper() in IEC_KEYWORDS: |
|
792 |
message = "\"%s\" is a keyword. It can't be used!"%new_name |
|
793 |
else: |
|
0 | 794 |
item = event.GetItem() |
795 |
itemtype = self.ProjectTree.GetPyData(item) |
|
796 |
if itemtype == ITEM_PROJECT: |
|
797 |
self.Controler.SetProjectName(new_name) |
|
798 |
elif itemtype == ITEM_POU: |
|
6 | 799 |
if new_name.upper() in self.Controler.GetProjectPouNames(): |
800 |
message = "\"%s\" pou already exists!"%new_name |
|
801 |
abort = True |
|
802 |
elif new_name.upper() in self.Controler.GetProjectPouVariables(): |
|
803 |
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) |
|
804 |
if messageDialog.ShowModal() == wxID_NO: |
|
805 |
abort = True |
|
806 |
messageDialog.Destroy() |
|
807 |
if not abort: |
|
808 |
old_name = self.ProjectTree.GetItemText(item) |
|
809 |
self.Controler.ChangePouName(old_name, new_name) |
|
810 |
self.RefreshTabsOpenedTitles() |
|
0 | 811 |
elif itemtype == ITEM_TRANSITION: |
6 | 812 |
category = self.ProjectTree.GetItemParent(item) |
813 |
pou = self.ProjectTree.GetItemParent(category) |
|
814 |
pou_name = self.ProjectTree.GetItemText(pou) |
|
815 |
if new_name.upper() in self.Controler.GetProjectPouNames(): |
|
816 |
message = "A pou with \"%s\" as name exists!"%new_name |
|
817 |
elif new_name.upper() in self.Controler.GetProjectPouVariables(pou_name): |
|
818 |
message = "A variable with \"%s\" as name already exists in this pou!"%new_name |
|
819 |
else: |
|
820 |
old_name = self.ProjectTree.GetItemText(item) |
|
821 |
self.Controler.ChangePouTransitionName(pou_name, old_name, new_name) |
|
822 |
self.RefreshTabsOpenedTitles() |
|
0 | 823 |
elif itemtype == ITEM_ACTION: |
6 | 824 |
category = self.ProjectTree.GetItemParent(item) |
825 |
pou = self.ProjectTree.GetItemParent(category) |
|
826 |
pou_name = self.ProjectTree.GetItemText(pou) |
|
827 |
if new_name.upper() in self.Controler.GetProjectPouNames(): |
|
828 |
message = "A pou with \"%s\" as name exists!"%new_name |
|
829 |
elif new_name.upper() in self.Controler.GetProjectPouVariables(pou_name): |
|
830 |
message = "A variable with \"%s\" as name already exists in this pou!"%new_name |
|
831 |
else: |
|
832 |
old_name = self.ProjectTree.GetItemText(item) |
|
833 |
self.Controler.ChangePouActionName(pou_name, old_name, new_name) |
|
834 |
self.RefreshTabsOpenedTitles() |
|
835 |
elif itemtype == ITEM_VARIABLE: |
|
836 |
category = self.ProjectTree.GetItemParent(item) |
|
837 |
if self.ProjectTree.GetItemText(category) != 'Global': |
|
838 |
category = self.ProjectTree.GetItemParent(category) |
|
839 |
pou = self.ProjectTree.GetItemParent(category) |
|
840 |
pou_name = self.ProjectTree.GetItemText(pou) |
|
841 |
if new_name.upper() in self.Controler.GetProjectPouNames(): |
|
842 |
message = "A pou with \"%s\" as name exists!"%new_name |
|
843 |
elif new_name.upper() in self.Controler.GetProjectPouVariables(pou_name): |
|
844 |
message = "A variable with \"%s\" as name already exists in this pou!"%new_name |
|
845 |
else: |
|
846 |
old_name = self.ProjectTree.GetItemText(item) |
|
847 |
self.Controler.ChangePouVariableName(pou_name, old_name, new_name) |
|
848 |
self.RefreshTabsOpenedTitles() |
|
849 |
if message or abort: |
|
850 |
if message: |
|
851 |
messageDialog = wxMessageDialog(self, message, "Error", wxOK|wxICON_ERROR) |
|
852 |
messageDialog.ShowModal() |
|
853 |
messageDialog.Destroy() |
|
0 | 854 |
item = event.GetItem() |
855 |
wxCallAfter(self.ProjectTree.EditLabel, item) |
|
856 |
event.Veto() |
|
6 | 857 |
else: |
858 |
wxCallAfter(self.RefreshProjectTree) |
|
859 |
event.Skip() |
|
0 | 860 |
|
861 |
def OnProjectTreeItemBeginEdit(self, event): |
|
862 |
selected = event.GetItem() |
|
863 |
if self.ProjectTree.GetPyData(selected) == ITEM_UNEDITABLE: |
|
864 |
event.Veto() |
|
865 |
else: |
|
866 |
event.Skip() |
|
867 |
||
868 |
def OnProjectTreeItemActivated(self, event): |
|
869 |
selected = event.GetItem() |
|
870 |
if self.ProjectTree.IsExpanded(selected): |
|
871 |
self.ProjectTree.Collapse(selected) |
|
872 |
else: |
|
873 |
self.ProjectTree.Expand(selected) |
|
874 |
name = self.ProjectTree.GetItemText(selected) |
|
875 |
data = self.ProjectTree.GetPyData(selected) |
|
876 |
if name == "Properties": |
|
27 | 877 |
self.ShowProperties() |
0 | 878 |
elif data == ITEM_CLASS: |
879 |
item = self.ProjectTree.GetItemParent(selected) |
|
880 |
item_type = self.ProjectTree.GetPyData(item) |
|
10
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
881 |
while item_type not in [ITEM_POU, ITEM_RESOURCE, ITEM_CONFIGURATION] and item.IsOk(): |
0 | 882 |
item = self.ProjectTree.GetItemParent(item) |
883 |
item_type = self.ProjectTree.GetPyData(item) |
|
10
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
884 |
item_name = self.ProjectTree.GetItemText(item) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
885 |
if item_type == ITEM_POU: |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
886 |
dialog = EditVariableDialog(self, item_name, self.Controler.GetPouType(item_name), self.Controler.PouIsUsed(item_name), name) |
10
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
887 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
888 |
values = {} |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
889 |
values["returnType"] = self.Controler.GetPouInterfaceReturnTypeByName(item_name) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
890 |
values["data"] = self.Controler.GetPouInterfaceVarsByName(item_name) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
891 |
dialog.SetValues(values) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
892 |
if dialog.ShowModal() == wxID_OK: |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
893 |
new_values = dialog.GetValues() |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
894 |
if "returnType" in new_values: |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
895 |
self.Controler.SetPouInterfaceReturnType(item_name, new_values["returnType"]) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
896 |
self.Controler.SetPouInterfaceVars(item_name, new_values["data"]) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
897 |
pou_names = self.Controler.GetElementsOpenedNames() |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
898 |
if item_name in pou_names: |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
899 |
window = self.TabsOpened.GetPage(pou_names.index(item_name)) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
900 |
if isinstance(window, TextViewer): |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
901 |
varlist = [] |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
902 |
if "returnType" in new_values: |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
903 |
varlist.append(name) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
904 |
for var in new_values["data"]: |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
905 |
varlist.append(var["Name"]) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
906 |
window.SetVariables(varlist) |
10
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
907 |
dialog.Destroy() |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
908 |
self.RefreshProjectTree() |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
909 |
elif item_type == ITEM_CONFIGURATION: |
45 | 910 |
dialog = EditVariableDialog(self, item_name, None, False, name) |
10
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
911 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
912 |
values = {"data" : self.Controler.GetConfigurationGlobalVars(item_name)} |
0 | 913 |
dialog.SetValues(values) |
914 |
if dialog.ShowModal() == wxID_OK: |
|
915 |
new_values = dialog.GetValues() |
|
10
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
916 |
self.Controler.SetConfigurationGlobalVars(item_name, new_values["data"]) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
917 |
dialog.Destroy() |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
918 |
self.RefreshProjectTree() |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
919 |
elif item_type == ITEM_RESOURCE: |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
920 |
config = self.ProjectTree.GetItemParent(item) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
921 |
config_type = self.ProjectTree.GetPyData(config) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
922 |
while config_type != ITEM_CONFIGURATION and config.IsOk(): |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
923 |
config = self.ProjectTree.GetItemParent(config) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
924 |
config_type = self.ProjectTree.GetPyData(config) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
925 |
if config.IsOk(): |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
926 |
config_name = self.ProjectTree.GetItemText(config) |
45 | 927 |
dialog = EditVariableDialog(self, item_name, None, False, name) |
10
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
928 |
values = {"data" : self.Controler.GetConfigurationResourceGlobalVars(config_name, item_name)} |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
929 |
dialog.SetValues(values) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
930 |
if dialog.ShowModal() == wxID_OK: |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
931 |
new_values = dialog.GetValues() |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
932 |
self.Controler.SetConfigurationResourceGlobalVars(config_name, item_name, new_values["data"]) |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
933 |
dialog.Destroy() |
112985848e1d
Bug on Configuration and Resource variables editing corrected
lbessard
parents:
9
diff
changeset
|
934 |
self.RefreshProjectTree() |
0 | 935 |
elif data in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]: |
936 |
if data == ITEM_POU: |
|
937 |
idx = self.Controler.OpenElementEditing(name) |
|
938 |
language = self.Controler.GetPouBodyType(name) |
|
939 |
varlist = [] |
|
940 |
returnType = self.Controler.GetPouInterfaceReturnTypeByName(name) |
|
941 |
if returnType: |
|
942 |
varlist.append(name) |
|
943 |
vars = self.Controler.GetPouInterfaceVarsByName(name) |
|
944 |
if vars: |
|
945 |
for var in vars: |
|
946 |
varlist.append(var["Name"]) |
|
947 |
else: |
|
948 |
parent = self.ProjectTree.GetItemParent(selected) |
|
949 |
parent_name = self.ProjectTree.GetItemText(parent) |
|
950 |
grandparent = self.ProjectTree.GetItemParent(parent) |
|
951 |
grandparent_name = self.ProjectTree.GetItemText(grandparent) |
|
952 |
if data == ITEM_TRANSITION: |
|
953 |
idx = self.Controler.OpenPouTransitionEditing(grandparent_name, name) |
|
954 |
language = self.Controler.GetTransitionBodyType(grandparent_name, name) |
|
955 |
elif data == ITEM_ACTION: |
|
956 |
idx = self.Controler.OpenPouActionEditing(grandparent_name, name) |
|
957 |
language = self.Controler.GetActionBodyType(grandparent_name, name) |
|
958 |
varlist = [name] |
|
959 |
vars = self.Controler.GetPouInterfaceVarsByName(grandparent_name) |
|
960 |
if vars: |
|
961 |
for var in vars: |
|
962 |
varlist.append(var["Name"]) |
|
963 |
if idx != None: |
|
964 |
if language == "FBD": |
|
27 | 965 |
new_window = Viewer(self.TabsOpened, self, self.Controler) |
0 | 966 |
elif language == "LD": |
967 |
new_window = LD_Viewer(self.TabsOpened, self, self.Controler) |
|
968 |
elif language == "SFC": |
|
969 |
new_window = SFC_Viewer(self.TabsOpened, self, self.Controler) |
|
970 |
elif language in ["IL", "ST"]: |
|
971 |
new_window = TextViewer(self.TabsOpened, self, self.Controler) |
|
8 | 972 |
new_window.SetTextSyntax(language) |
0 | 973 |
if language == "IL": |
974 |
new_window.SetKeywords(IL_KEYWORDS) |
|
975 |
else: |
|
976 |
new_window.SetKeywords(ST_KEYWORDS) |
|
977 |
new_window.SetVariables(varlist) |
|
978 |
new_window.SetFunctions(self.Controler.GetBlockTypes()) |
|
979 |
else: |
|
980 |
return |
|
981 |
new_window.RefreshView() |
|
982 |
self.TabsOpened.AddPage(new_window, "") |
|
983 |
self.TabsOpened.SetSelection(idx) |
|
984 |
self.RefreshTabsOpenedTitles() |
|
985 |
self.RefreshFileMenu() |
|
986 |
self.RefreshEditMenu() |
|
987 |
self.RefreshToolBar() |
|
988 |
else: |
|
989 |
if data == ITEM_POU: |
|
990 |
idx = self.Controler.ChangeElementEditing(name) |
|
991 |
elif data == ITEM_TRANSITION: |
|
992 |
idx = self.Controler.ChangePouTransitionEditing(grandparent_name, name) |
|
993 |
elif data == ITEM_ACTION: |
|
994 |
idx = self.Controler.ChangePouActionEditing(grandparent_name, name) |
|
995 |
if idx != None: |
|
996 |
self.TabsOpened.SetSelection(idx) |
|
997 |
self.RefreshFileMenu() |
|
998 |
self.RefreshEditMenu() |
|
999 |
self.RefreshToolBar() |
|
1000 |
elif data == ITEM_RESOURCE: |
|
1001 |
item = self.ProjectTree.GetItemParent(selected) |
|
1002 |
item_type = self.ProjectTree.GetPyData(item) |
|
1003 |
while item_type != ITEM_CONFIGURATION: |
|
1004 |
item = self.ProjectTree.GetItemParent(item) |
|
1005 |
item_type = self.ProjectTree.GetPyData(item) |
|
1006 |
config_name = self.ProjectTree.GetItemText(item) |
|
1007 |
idx = self.Controler.OpenConfigurationResourceEditing(config_name, name) |
|
1008 |
if idx != None: |
|
1009 |
new_window = ResourceEditor(self.TabsOpened, self, self.Controler) |
|
1010 |
new_window.RefreshView() |
|
1011 |
self.TabsOpened.AddPage(new_window, "") |
|
1012 |
self.TabsOpened.SetSelection(idx) |
|
1013 |
self.RefreshTabsOpenedTitles() |
|
1014 |
self.RefreshFileMenu() |
|
1015 |
self.RefreshEditMenu() |
|
1016 |
self.RefreshToolBar() |
|
1017 |
else: |
|
1018 |
idx = self.Controler.ChangeConfigurationResourceEditing(parent_name, name) |
|
1019 |
if idx != None: |
|
1020 |
self.TabsOpened.SetSelection(idx) |
|
1021 |
self.RefreshFileMenu() |
|
1022 |
self.RefreshEditMenu() |
|
1023 |
self.RefreshToolBar() |
|
1024 |
||
1025 |
def OnProjectTreeRightUp(self, event): |
|
1026 |
selected = self.ProjectTree.GetSelection() |
|
1027 |
if self.ProjectTree.GetPyData(selected) == ITEM_POU: |
|
1028 |
name = self.ProjectTree.GetItemText(selected) |
|
1029 |
if self.Controler.GetPouBodyType(name) == "SFC": |
|
1030 |
self.PopupMenu(self.SFCMenu) |
|
1031 |
elif self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION: |
|
1032 |
self.PopupMenu(self.ConfigMenu) |
|
1033 |
event.Skip() |
|
1034 |
||
1035 |
def OnProjectTreeItemSelected(self, event): |
|
1036 |
selected = event.GetItem() |
|
1037 |
name = self.ProjectTree.GetItemText(selected) |
|
1038 |
if self.ProjectTree.GetItemParent(selected) == self.ProjectTree.GetRootItem() and name != "Properties": |
|
1039 |
if self.Controler.IsElementEditing(name): |
|
1040 |
idx = self.Controler.ChangeElementEditing(name) |
|
1041 |
if idx != None: |
|
1042 |
self.TabsOpened.SetSelection(idx) |
|
1043 |
self.RefreshFileMenu() |
|
1044 |
self.RefreshEditMenu() |
|
1045 |
self.RefreshToolBar() |
|
1046 |
else: |
|
1047 |
name = self.ProjectTree.GetItemText(selected) |
|
1048 |
parent = self.ProjectTree.GetItemParent(selected) |
|
1049 |
parent_name = self.ProjectTree.GetItemText(parent) |
|
1050 |
grandparent = self.ProjectTree.GetItemParent(parent) |
|
1051 |
grandparent_name = self.ProjectTree.GetItemText(grandparent) |
|
1052 |
if parent_name == "Transitions": |
|
1053 |
idx = self.Controler.ChangePouTransitionEditing(grandparent_name, name) |
|
1054 |
if idx != None: |
|
1055 |
self.TabsOpened.SetSelection(idx) |
|
1056 |
self.RefreshFileMenu() |
|
1057 |
self.RefreshEditMenu() |
|
1058 |
self.RefreshToolBar() |
|
1059 |
elif parent_name == "Action": |
|
1060 |
idx = self.Controler.ChangePouActionEditing(grandparent_name, name) |
|
1061 |
if idx != None: |
|
1062 |
self.TabsOpened.SetSelection(idx) |
|
1063 |
self.RefreshFileMenu() |
|
1064 |
self.RefreshEditMenu() |
|
1065 |
self.RefreshToolBar() |
|
1066 |
event.Skip() |
|
1067 |
||
1068 |
def RefreshProjectTree(self): |
|
1069 |
infos = self.Controler.GetProjectInfos() |
|
1070 |
root = self.ProjectTree.GetRootItem() |
|
1071 |
self.GenerateTreeBranch(root, infos) |
|
1072 |
self.ProjectTree.Expand(self.ProjectTree.GetRootItem()) |
|
1073 |
||
1074 |
def GenerateTreeBranch(self, root, infos): |
|
1075 |
to_delete = [] |
|
1076 |
if root.IsOk(): |
|
1077 |
self.ProjectTree.SetItemText(root, infos["name"]) |
|
1078 |
else: |
|
1079 |
root = self.ProjectTree.AddRoot(infos["name"]) |
|
1080 |
self.ProjectTree.SetPyData(root, infos["type"]) |
|
9 | 1081 |
if infos["type"] == ITEM_POU: |
1082 |
self.ProjectTree.SetItemImage(root, LANGUAGES.index(self.Controler.GetPouBodyType(infos["name"]))) |
|
0 | 1083 |
item, root_cookie = self.ProjectTree.GetFirstChild(root) |
1084 |
if len(infos["values"]) > 0: |
|
1085 |
for values in infos["values"]: |
|
1086 |
if not item.IsOk(): |
|
1087 |
item = self.ProjectTree.AppendItem(root, "") |
|
1088 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
|
1089 |
self.GenerateTreeBranch(item, values) |
|
1090 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
|
1091 |
while item.IsOk(): |
|
1092 |
to_delete.append(item) |
|
27 | 1093 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
0 | 1094 |
for item in to_delete: |
1095 |
self.ProjectTree.Delete(item) |
|
27 | 1096 |
|
6 | 1097 |
def ResetToolBar(self): |
1098 |
for item in self.CurrentToolBar: |
|
27 | 1099 |
self.Unbind(wx.EVT_MENU, id=item) |
6 | 1100 |
self.ToolBar.DeleteTool(item) |
1101 |
||
0 | 1102 |
def RefreshToolBar(self): |
1103 |
language = self.Controler.GetCurrentElementEditingBodyType() |
|
27 | 1104 |
if language and language != self.CurrentLanguage: |
1105 |
self.ResetToolBar() |
|
1106 |
self.CurrentLanguage = language |
|
1107 |
self.CurrentToolBar = [] |
|
1108 |
for radio, modes, id, method, picture, help in ToolBarItems[language]: |
|
1109 |
if modes & self.DrawingMode: |
|
1110 |
if radio or self.DrawingMode == FREEDRAWING_MODE: |
|
1111 |
self.ToolBar.AddRadioTool(id, wxBitmap(os.path.join(CWD, picture)), wxNullBitmap, help) |
|
1112 |
else: |
|
1113 |
self.ToolBar.AddSimpleTool(id, wxBitmap(os.path.join(CWD, picture)), help) |
|
1114 |
self.Bind(wx.EVT_TOOL, getattr(self, method), id=id) |
|
1115 |
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
|
1116 |
self.ResetCurrentMode() |
0 | 1117 |
|
1118 |
def RefreshTabsOpenedTitles(self): |
|
1119 |
pous = self.Controler.GetElementsOpenedNames() |
|
1120 |
for i, pou in enumerate(pous): |
|
1121 |
self.TabsOpened.SetPageText(i, pou) |
|
1122 |
||
1123 |
def OnRefreshMenu(self, event): |
|
1124 |
selected = self.TabsOpened.GetSelection() |
|
1125 |
if selected != -1: |
|
1126 |
self.TabsOpened.GetPage(selected).Refresh() |
|
1127 |
event.Skip() |
|
1128 |
||
1129 |
def OnCutMenu(self, event): |
|
1130 |
selected = self.TabsOpened.GetSelection() |
|
1131 |
if selected != -1: |
|
1132 |
self.TabsOpened.GetPage(selected).Cut() |
|
1133 |
event.Skip() |
|
1134 |
||
1135 |
def OnCopyMenu(self, event): |
|
1136 |
selected = self.TabsOpened.GetSelection() |
|
1137 |
if selected != -1: |
|
1138 |
self.TabsOpened.GetPage(selected).Copy() |
|
1139 |
event.Skip() |
|
1140 |
||
1141 |
def OnPasteMenu(self, event): |
|
1142 |
selected = self.TabsOpened.GetSelection() |
|
1143 |
if selected != -1: |
|
1144 |
self.TabsOpened.GetPage(selected).Paste() |
|
1145 |
event.Skip() |
|
1146 |
||
1147 |
def OnAddPouMenu(self, event): |
|
1148 |
dialog = PouDialog(self) |
|
1149 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
|
1150 |
if dialog.ShowModal() == wxID_OK: |
|
1151 |
values = dialog.GetValues() |
|
1152 |
self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"]) |
|
1153 |
self.RefreshProjectTree() |
|
1154 |
dialog.Destroy() |
|
1155 |
event.Skip() |
|
1156 |
||
1157 |
def OnRemovePouMenu(self, event): |
|
1158 |
pous = self.Controler.GetProjectPouNames() |
|
1159 |
dialog = wxSingleChoiceDialog(self, "Select POU to remove:", "POU Remove", pous, wxOK|wxCANCEL) |
|
1160 |
if dialog.ShowModal() == wxID_OK: |
|
1161 |
selected = dialog.GetStringSelection() |
|
1162 |
if not self.Controler.PouIsUsed(selected): |
|
1163 |
self.Controler.ProjectRemovePou(selected) |
|
1164 |
for i in xrange(self.TabsOpened.GetPageCount()): |
|
1165 |
if self.TabsOpened.GetPageText(i) == selected: |
|
1166 |
self.TabsOpened.DeletePage(i) |
|
1167 |
self.RefreshProjectTree() |
|
1168 |
self.RefreshToolBar() |
|
1169 |
else: |
|
1170 |
message = wxMessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wxOK|wxICON_ERROR) |
|
1171 |
message.ShowModal() |
|
1172 |
message.Destroy() |
|
1173 |
event.Skip() |
|
1174 |
||
1175 |
def OnAddConfigurationMenu(self, event): |
|
1176 |
dialog = wxTextEntryDialog(self, "Enter configuration name:", "Create new configuration", "", wxOK|wxCANCEL) |
|
1177 |
if dialog.ShowModal() == wxID_OK: |
|
1178 |
value = dialog.GetValue() |
|
1179 |
self.Controler.ProjectAddConfiguration(value) |
|
1180 |
self.RefreshProjectTree() |
|
1181 |
dialog.Destroy() |
|
1182 |
event.Skip() |
|
1183 |
||
1184 |
def OnRemoveConfigurationMenu(self, event): |
|
1185 |
configs = self.Controler.GetProjectConfigNames() |
|
1186 |
dialog = wxSingleChoiceDialog(self, "Select Configuration to remove:", "Configuration Remove", configs, wxOK|wxCANCEL) |
|
1187 |
if dialog.ShowModal() == wxID_OK: |
|
1188 |
selected = dialog.GetStringSelection() |
|
1189 |
self.Controler.ProjectRemoveConfiguration(selected) |
|
1190 |
self.RefreshProjectTree() |
|
1191 |
event.Skip() |
|
1192 |
||
1193 |
def OnAddPouTransitionMenu(self, event): |
|
45 | 1194 |
selected = self.ProjectTree.GetSelection() |
1195 |
if self.ProjectTree.GetPyData(selected) == ITEM_POU: |
|
1196 |
pouname = self.ProjectTree.GetItemText(selected) |
|
1197 |
if self.Controler.GetPouBodyType(pouname) == "SFC": |
|
1198 |
dialog = PouTransitionDialog(self) |
|
1199 |
if dialog.ShowModal() == wxID_OK: |
|
1200 |
values = dialog.GetValues() |
|
1201 |
self.Controler.ProjectAddPouTransition(pouname, values["transitionName"], values["language"]) |
|
1202 |
self.RefreshProjectTree() |
|
1203 |
dialog.Destroy() |
|
0 | 1204 |
event.Skip() |
1205 |
||
1206 |
def OnRemovePouTransitionMenu(self, event): |
|
1207 |
event.Skip() |
|
1208 |
||
1209 |
def OnAddPouActionMenu(self, event): |
|
45 | 1210 |
selected = self.ProjectTree.GetSelection() |
1211 |
if self.ProjectTree.GetPyData(selected) == ITEM_POU: |
|
1212 |
pouname = self.ProjectTree.GetItemText(selected) |
|
1213 |
if self.Controler.GetPouBodyType(pouname) == "SFC": |
|
1214 |
dialog = PouActionDialog(self) |
|
1215 |
if dialog.ShowModal() == wxID_OK: |
|
1216 |
values = dialog.GetValues() |
|
1217 |
self.Controler.ProjectAddPouAction(pouname, values["actionName"], values["language"]) |
|
1218 |
self.RefreshProjectTree() |
|
1219 |
dialog.Destroy() |
|
0 | 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, |
|
45 | 1580 |
wxID_POUTRANSITIONDIALOGTRANSITIONNAME, wxID_POUTRANSITIONDIALOGLANGUAGE, |
1581 |
wxID_POUTRANSITIONDIALOGSTATICTEXT1, wxID_POUTRANSITIONDIALOGSTATICTEXT2, |
|
1582 |
] = [wx.NewId() for _init_ctrls in range(6)] |
|
0 | 1583 |
|
1584 |
class PouTransitionDialog(wx.Dialog): |
|
1585 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
1586 |
# generated method, don't edit |
|
1587 |
||
1588 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1589 |
||
1590 |
def _init_sizers(self): |
|
1591 |
# generated method, don't edit |
|
1592 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1593 |
||
1594 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1595 |
||
1596 |
self.SetSizer(self.flexGridSizer1) |
|
1597 |
||
1598 |
def _init_ctrls(self, prnt): |
|
1599 |
# generated method, don't edit |
|
1600 |
wx.Dialog.__init__(self, id=wxID_POUTRANSITIONDIALOG, |
|
45 | 1601 |
name='PouTransitionDialog', parent=prnt, pos=wx.Point(376, 223), |
0 | 1602 |
size=wx.Size(350, 200), style=wx.DEFAULT_DIALOG_STYLE, |
45 | 1603 |
title='Create a new transition') |
1604 |
self.SetClientSize(wx.Size(350, 160)) |
|
0 | 1605 |
|
1606 |
self.MainPanel = wx.Panel(id=wxID_POUTRANSITIONDIALOGMAINPANEL, |
|
1607 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1608 |
size=wx.Size(350, 200), style=wx.TAB_TRAVERSAL) |
|
1609 |
self.MainPanel.SetAutoLayout(True) |
|
1610 |
||
1611 |
self.staticText1 = wx.StaticText(id=wxID_POUTRANSITIONDIALOGSTATICTEXT1, |
|
45 | 1612 |
label='Transition Name:', name='staticText1', parent=self.MainPanel, |
0 | 1613 |
pos=wx.Point(24, 24), size=wx.Size(145, 17), style=0) |
1614 |
||
45 | 1615 |
self.TransitionName = wx.TextCtrl(id=wxID_POUTRANSITIONDIALOGTRANSITIONNAME, |
1616 |
name='TransitionName', parent=self.MainPanel, pos=wx.Point(154, 24), |
|
0 | 1617 |
size=wx.Size(150, 24), style=0) |
1618 |
||
1619 |
self.staticText2 = wx.StaticText(id=wxID_POUTRANSITIONDIALOGSTATICTEXT2, |
|
45 | 1620 |
label='Language:', name='staticText2', parent=self.MainPanel, |
0 | 1621 |
pos=wx.Point(24, 64), size=wx.Size(145, 17), style=0) |
1622 |
||
1623 |
self.Language = wx.Choice(id=wxID_POUTRANSITIONDIALOGLANGUAGE, |
|
45 | 1624 |
name='Language', parent=self.MainPanel, pos=wx.Point(154, 64), |
0 | 1625 |
size=wx.Size(150, 24), style=0) |
1626 |
||
1627 |
self._init_sizers() |
|
1628 |
||
1629 |
def __init__(self, parent): |
|
1630 |
self._init_ctrls(parent) |
|
9 | 1631 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
0 | 1632 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
45 | 1633 |
|
0 | 1634 |
for option in ["IL","ST","LD","FBD"]: |
1635 |
self.Language.Append(option) |
|
1636 |
||
1637 |
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
|
1638 |
||
1639 |
def OnOK(self, event): |
|
1640 |
error = [] |
|
1641 |
if self.TransitionName.GetValue() == "": |
|
1642 |
error.append("Transition Name") |
|
1643 |
if self.Language.GetStringSelection() == "": |
|
1644 |
error.append("Language") |
|
1645 |
if len(error) > 0: |
|
1646 |
text = "" |
|
1647 |
for i, item in enumerate(error): |
|
1648 |
if i == 0: |
|
1649 |
text += item |
|
1650 |
elif i == len(error) - 1: |
|
1651 |
text += " and %s"%item |
|
1652 |
else: |
|
1653 |
text += ", %s"%item |
|
1654 |
message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) |
|
1655 |
message.ShowModal() |
|
1656 |
message.Destroy() |
|
1657 |
else: |
|
1658 |
self.EndModal(wxID_OK) |
|
1659 |
||
1660 |
def SetValues(self, values): |
|
1661 |
for item, value in values.items(): |
|
45 | 1662 |
if item == "transitionName": |
0 | 1663 |
self.TransitionName.SetValue(value) |
1664 |
elif item == "language": |
|
1665 |
self.Language.SetStringSelection(value) |
|
1666 |
||
1667 |
def GetValues(self): |
|
1668 |
values = {} |
|
1669 |
values["transitionName"] = self.TransitionName.GetValue() |
|
1670 |
values["language"] = self.Language.GetStringSelection() |
|
1671 |
return values |
|
1672 |
||
1673 |
#------------------------------------------------------------------------------- |
|
1674 |
# Create Pou Action Dialog |
|
1675 |
#------------------------------------------------------------------------------- |
|
1676 |
||
1677 |
[wxID_POUACTIONDIALOG, wxID_POUACTIONDIALOGMAINPANEL, |
|
45 | 1678 |
wxID_POUACTIONDIALOGACTIONNAME, wxID_POUACTIONDIALOGLANGUAGE, |
1679 |
wxID_POUACTIONDIALOGSTATICTEXT1, wxID_POUACTIONDIALOGSTATICTEXT2, |
|
1680 |
] = [wx.NewId() for _init_ctrls in range(6)] |
|
0 | 1681 |
|
1682 |
class PouActionDialog(wx.Dialog): |
|
1683 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
1684 |
# generated method, don't edit |
|
1685 |
||
1686 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1687 |
||
1688 |
def _init_sizers(self): |
|
1689 |
# generated method, don't edit |
|
1690 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1691 |
||
1692 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1693 |
||
1694 |
self.SetSizer(self.flexGridSizer1) |
|
1695 |
||
1696 |
def _init_ctrls(self, prnt): |
|
1697 |
# generated method, don't edit |
|
1698 |
wx.Dialog.__init__(self, id=wxID_POUACTIONDIALOG, |
|
45 | 1699 |
name='PouActionDialog', parent=prnt, pos=wx.Point(376, 223), |
0 | 1700 |
size=wx.Size(320, 200), style=wx.DEFAULT_DIALOG_STYLE, |
45 | 1701 |
title='Create a new action') |
1702 |
self.SetClientSize(wx.Size(320, 160)) |
|
0 | 1703 |
|
1704 |
self.MainPanel = wx.Panel(id=wxID_POUACTIONDIALOGMAINPANEL, |
|
1705 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1706 |
size=wx.Size(350, 200), style=wx.TAB_TRAVERSAL) |
|
1707 |
self.MainPanel.SetAutoLayout(True) |
|
1708 |
||
1709 |
self.staticText1 = wx.StaticText(id=wxID_POUACTIONDIALOGSTATICTEXT1, |
|
45 | 1710 |
label='Action Name:', name='staticText1', parent=self.MainPanel, |
0 | 1711 |
pos=wx.Point(24, 24), size=wx.Size(145, 17), style=0) |
1712 |
||
45 | 1713 |
self.ActionName = wx.TextCtrl(id=wxID_POUACTIONDIALOGACTIONNAME, |
1714 |
name='ActionName', parent=self.MainPanel, pos=wx.Point(124, 24), |
|
0 | 1715 |
size=wx.Size(150, 24), style=0) |
1716 |
||
45 | 1717 |
self.staticText3 = wx.StaticText(id=wxID_POUACTIONDIALOGSTATICTEXT2, |
1718 |
label='Language:', name='staticText2', parent=self.MainPanel, |
|
0 | 1719 |
pos=wx.Point(24, 64), size=wx.Size(145, 17), style=0) |
1720 |
||
1721 |
self.Language = wx.Choice(id=wxID_POUACTIONDIALOGLANGUAGE, |
|
45 | 1722 |
name='Language', parent=self.MainPanel, pos=wx.Point(124, 64), |
0 | 1723 |
size=wx.Size(150, 24), style=0) |
1724 |
||
1725 |
self._init_sizers() |
|
1726 |
||
1727 |
def __init__(self, parent): |
|
1728 |
self._init_ctrls(parent) |
|
9 | 1729 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
0 | 1730 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
45 | 1731 |
|
0 | 1732 |
for option in ["IL","ST","LD","FBD"]: |
1733 |
self.Language.Append(option) |
|
1734 |
||
1735 |
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
|
1736 |
||
1737 |
def OnOK(self, event): |
|
1738 |
error = [] |
|
1739 |
if self.ActionName.GetValue() == "": |
|
1740 |
error.append("Action Name") |
|
1741 |
if self.Language.GetStringSelection() == "": |
|
1742 |
error.append("Language") |
|
1743 |
if len(error) > 0: |
|
1744 |
text = "" |
|
1745 |
for i, item in enumerate(error): |
|
1746 |
if i == 0: |
|
1747 |
text += item |
|
1748 |
elif i == len(error) - 1: |
|
1749 |
text += " and %s"%item |
|
1750 |
else: |
|
1751 |
text += ", %s"%item |
|
1752 |
message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) |
|
1753 |
message.ShowModal() |
|
1754 |
message.Destroy() |
|
1755 |
else: |
|
1756 |
self.EndModal(wxID_OK) |
|
1757 |
||
1758 |
def SetValues(self, values): |
|
1759 |
for item, value in values.items(): |
|
45 | 1760 |
if item == "actionName": |
0 | 1761 |
self.ActionName.SetValue(value) |
1762 |
elif item == "language": |
|
1763 |
self.Language.SetStringSelection(value) |
|
1764 |
||
1765 |
def GetValues(self): |
|
1766 |
values = {} |
|
1767 |
values["actionName"] = self.ActionName.GetValue() |
|
1768 |
values["language"] = self.Language.GetStringSelection() |
|
1769 |
return values |
|
1770 |
||
1771 |
#------------------------------------------------------------------------------- |
|
1772 |
# Pou Interface Dialog |
|
1773 |
#------------------------------------------------------------------------------- |
|
1774 |
||
1775 |
class VariableTable(wxPyGridTableBase): |
|
1776 |
||
1777 |
""" |
|
1778 |
A custom wxGrid Table using user supplied data |
|
1779 |
""" |
|
1780 |
def __init__(self, parent, data, colnames): |
|
1781 |
# The base class must be initialized *first* |
|
1782 |
wxPyGridTableBase.__init__(self) |
|
1783 |
self.data = data |
|
1784 |
self.colnames = colnames |
|
1785 |
self.Parent = parent |
|
1786 |
# XXX |
|
1787 |
# we need to store the row length and collength to |
|
1788 |
# see if the table has changed size |
|
1789 |
self._rows = self.GetNumberRows() |
|
1790 |
self._cols = self.GetNumberCols() |
|
1791 |
||
1792 |
def GetNumberCols(self): |
|
1793 |
return len(self.colnames) |
|
1794 |
||
1795 |
def GetNumberRows(self): |
|
1796 |
return len(self.data) |
|
1797 |
||
1798 |
def GetColLabelValue(self, col): |
|
1799 |
if col < len(self.colnames): |
|
1800 |
return self.colnames[col] |
|
1801 |
||
1802 |
def GetRowLabelValues(self, row): |
|
1803 |
return row |
|
1804 |
||
1805 |
def GetValue(self, row, col): |
|
1806 |
if row < self.GetNumberRows(): |
|
1807 |
name = str(self.data[row].get(self.GetColLabelValue(col), "")) |
|
1808 |
return name |
|
1809 |
||
1810 |
def GetValueByName(self, row, colname): |
|
1811 |
return self.data[row].get(colname) |
|
1812 |
||
1813 |
def SetValue(self, row, col, value): |
|
1814 |
if col < len(self.colnames): |
|
1815 |
self.data[row][self.GetColLabelValue(col)] = value |
|
1816 |
||
1817 |
def ResetView(self, grid): |
|
1818 |
""" |
|
1819 |
(wxGrid) -> Reset the grid view. Call this to |
|
1820 |
update the grid if rows and columns have been added or deleted |
|
1821 |
""" |
|
1822 |
grid.BeginBatch() |
|
1823 |
for current, new, delmsg, addmsg in [ |
|
1824 |
(self._rows, self.GetNumberRows(), wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_NOTIFY_ROWS_APPENDED), |
|
1825 |
(self._cols, self.GetNumberCols(), wxGRIDTABLE_NOTIFY_COLS_DELETED, wxGRIDTABLE_NOTIFY_COLS_APPENDED), |
|
1826 |
]: |
|
1827 |
if new < current: |
|
1828 |
msg = wxGridTableMessage(self,delmsg,new,current-new) |
|
1829 |
grid.ProcessTableMessage(msg) |
|
1830 |
elif new > current: |
|
1831 |
msg = wxGridTableMessage(self,addmsg,new-current) |
|
1832 |
grid.ProcessTableMessage(msg) |
|
1833 |
self.UpdateValues(grid) |
|
1834 |
grid.EndBatch() |
|
1835 |
||
1836 |
self._rows = self.GetNumberRows() |
|
1837 |
self._cols = self.GetNumberCols() |
|
1838 |
# update the column rendering scheme |
|
1839 |
self._updateColAttrs(grid) |
|
1840 |
||
1841 |
# update the scrollbars and the displayed part of the grid |
|
1842 |
grid.AdjustScrollbars() |
|
1843 |
grid.ForceRefresh() |
|
1844 |
||
1845 |
def UpdateValues(self, grid): |
|
1846 |
"""Update all displayed values""" |
|
1847 |
# This sends an event to the grid table to update all of the values |
|
1848 |
msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES) |
|
1849 |
grid.ProcessTableMessage(msg) |
|
1850 |
||
1851 |
def _updateColAttrs(self, grid): |
|
1852 |
""" |
|
1853 |
wxGrid -> update the column attributes to add the |
|
1854 |
appropriate renderer given the column name. |
|
1855 |
||
1856 |
Otherwise default to the default renderer. |
|
1857 |
""" |
|
1858 |
||
1859 |
for col in range(self.GetNumberCols()): |
|
1860 |
attr = wxGridCellAttr() |
|
1861 |
attr.SetAlignment(self.Parent.ColAlignements[col], wxALIGN_CENTRE) |
|
1862 |
grid.SetColAttr(col, attr) |
|
1863 |
grid.SetColSize(col, self.Parent.ColSizes[col]) |
|
1864 |
||
1865 |
typelist = None |
|
1866 |
accesslist = None |
|
1867 |
for row in range(self.GetNumberRows()): |
|
1868 |
for col in range(self.GetNumberCols()): |
|
1869 |
editor = None |
|
1870 |
renderer = None |
|
1871 |
colname = self.GetColLabelValue(col) |
|
1872 |
grid.SetReadOnly(row, col, False) |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1873 |
if colname == "Name": |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1874 |
if self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]: |
0 | 1875 |
grid.SetReadOnly(row, col, True) |
1876 |
else: |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1877 |
editor = wxGridCellTextEditor() |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1878 |
renderer = wxGridCellStringRenderer() |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1879 |
if colname in ["Initial Value","Location"]: |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1880 |
editor = wxGridCellTextEditor() |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1881 |
renderer = wxGridCellStringRenderer() |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1882 |
elif colname == "Class": |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1883 |
if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]: |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1884 |
grid.SetReadOnly(row, col, True) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1885 |
else: |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1886 |
editor = wxGridCellChoiceEditor() |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1887 |
excluded = [] |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1888 |
if self.Parent.PouIsUsed: |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1889 |
excluded.extend(["Input","Output","InOut"]) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1890 |
editor.SetParameters(",".join([choice for choice in self.Parent.ClassList if choice not in excluded])) |
0 | 1891 |
elif colname == "Type": |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1892 |
if self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]: |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1893 |
grid.SetReadOnly(row, col, True) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1894 |
else: |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1895 |
editor = wxGridCellChoiceEditor() |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1896 |
editor.SetParameters(self.Parent.TypeList) |
0 | 1897 |
elif colname in ["Retain", "Constant"]: |
1898 |
editor = wxGridCellChoiceEditor() |
|
1899 |
editor.SetParameters(self.Parent.OptionList) |
|
1900 |
||
1901 |
grid.SetCellEditor(row, col, editor) |
|
1902 |
grid.SetCellRenderer(row, col, renderer) |
|
1903 |
||
1904 |
grid.SetCellBackgroundColour(row, col, wxWHITE) |
|
1905 |
||
1906 |
def SetData(self, data): |
|
1907 |
self.data = data |
|
1908 |
||
1909 |
def GetData(self): |
|
1910 |
return self.data |
|
1911 |
||
1912 |
def GetCurrentIndex(self): |
|
1913 |
return self.CurrentIndex |
|
1914 |
||
1915 |
def SetCurrentIndex(self, index): |
|
1916 |
self.CurrentIndex = index |
|
1917 |
||
1918 |
def AppendRow(self, row_content): |
|
1919 |
self.data.append(row_content) |
|
1920 |
||
1921 |
def RemoveRow(self, row_index): |
|
1922 |
self.data.pop(row_index) |
|
12 | 1923 |
|
1924 |
def GetRow(self, row_index): |
|
1925 |
return self.data[row_index] |
|
0 | 1926 |
|
1927 |
def Empty(self): |
|
1928 |
self.data = [] |
|
1929 |
self.editors = [] |
|
1930 |
||
1931 |
[wxID_EDITVARIABLEDIALOG, wxID_EDITVARIABLEDIALOGMAINPANEL, |
|
1932 |
wxID_EDITVARIABLEDIALOGVARIABLESGRID, wxID_EDITVARIABLEDIALOGRETURNTYPE, |
|
1933 |
wxID_EDITVARIABLEDIALOGCLASSFILTER, wxID_EDITVARIABLEDIALOGADDBUTTON, |
|
1934 |
wxID_EDITVARIABLEDIALOGDELETEBUTTON, wxID_EDITVARIABLEDIALOGUPBUTTON, |
|
1935 |
wxID_EDITVARIABLEDIALOGDOWNBUTTON, wxID_EDITVARIABLEDIALOGSTATICTEXT1, |
|
1936 |
wxID_EDITVARIABLEDIALOGSTATICTEXT2, wxID_EDITVARIABLEDIALOGSTATICTEXT3, |
|
1937 |
] = [wx.NewId() for _init_ctrls in range(12)] |
|
1938 |
||
1939 |
class EditVariableDialog(wx.Dialog): |
|
1940 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
1941 |
# generated method, don't edit |
|
1942 |
||
1943 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1944 |
||
1945 |
def _init_sizers(self): |
|
1946 |
# generated method, don't edit |
|
1947 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1948 |
||
1949 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1950 |
||
1951 |
self.SetSizer(self.flexGridSizer1) |
|
1952 |
||
1953 |
def _init_ctrls(self, prnt, name): |
|
1954 |
# generated method, don't edit |
|
1955 |
wx.Dialog.__init__(self, id=wxID_EDITVARIABLEDIALOG, |
|
1956 |
name='EditVariableDialog', parent=prnt, pos=wx.Point(376, 223), |
|
1957 |
size=wx.Size(600, 440), style=wx.DEFAULT_DIALOG_STYLE, |
|
1958 |
title='Edit variables of %s'%name) |
|
1959 |
self.SetClientSize(wx.Size(600, 440)) |
|
1960 |
||
1961 |
self.MainPanel = wx.Panel(id=wxID_EDITVARIABLEDIALOGMAINPANEL, |
|
1962 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1963 |
size=wx.Size(600, 440), style=wx.TAB_TRAVERSAL) |
|
1964 |
self.MainPanel.SetAutoLayout(True) |
|
1965 |
||
1966 |
self.staticText1 = wx.StaticText(id=wxID_EDITVARIABLEDIALOGSTATICTEXT1, |
|
1967 |
label='Return Type:', name='staticText1', parent=self.MainPanel, |
|
1968 |
pos=wx.Point(24, 29), size=wx.Size(95, 17), style=0) |
|
1969 |
||
1970 |
self.ReturnType = wx.Choice(id=wxID_EDITVARIABLEDIALOGRETURNTYPE, |
|
1971 |
name='ReturnType', parent=self.MainPanel, pos=wx.Point(124, 24), |
|
1972 |
size=wx.Size(145, 24), style=0) |
|
1973 |
||
1974 |
self.staticText2 = wx.StaticText(id=wxID_EDITVARIABLEDIALOGSTATICTEXT2, |
|
1975 |
label='Class Filter:', name='staticText2', parent=self.MainPanel, |
|
1976 |
pos=wx.Point(324, 29), size=wx.Size(95, 17), style=0) |
|
1977 |
||
1978 |
self.ClassFilter = wx.Choice(id=wxID_EDITVARIABLEDIALOGCLASSFILTER, |
|
1979 |
name='ClassFilter', parent=self.MainPanel, pos=wx.Point(424, 24), |
|
1980 |
size=wx.Size(145, 24), style=0) |
|
1981 |
EVT_CHOICE(self, wxID_EDITVARIABLEDIALOGCLASSFILTER, self.OnClassFilter) |
|
1982 |
||
1983 |
self.staticText3 = wx.StaticText(id=wxID_EDITVARIABLEDIALOGSTATICTEXT3, |
|
1984 |
label='Variables:', name='staticText3', parent=self.MainPanel, |
|
1985 |
pos=wx.Point(24, 60), size=wx.Size(95, 17), style=0) |
|
1986 |
||
1987 |
self.VariablesGrid = wx.grid.Grid(id=wxID_EDITVARIABLEDIALOGVARIABLESGRID, |
|
1988 |
name='VariablesGrid', parent=self.MainPanel, pos=wx.Point(24, 80), |
|
1989 |
size=wx.Size(550, 250), style=wxVSCROLL) |
|
1990 |
self.VariablesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
|
1991 |
'Sans')) |
|
1992 |
self.VariablesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
1993 |
False, 'Sans')) |
|
1994 |
self.VariablesGrid.DisableDragGridSize() |
|
1995 |
self.VariablesGrid.EnableScrolling(False, True) |
|
6 | 1996 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange) |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
1997 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnVariablesGridSelectCell) |
0 | 1998 |
|
1999 |
self.AddButton = wx.Button(id=wxID_EDITVARIABLEDIALOGADDBUTTON, label='Add', |
|
2000 |
name='AddButton', parent=self.MainPanel, pos=wx.Point(345, 340), |
|
2001 |
size=wx.Size(72, 32), style=0) |
|
2002 |
EVT_BUTTON(self, wxID_EDITVARIABLEDIALOGADDBUTTON, self.OnAddButton) |
|
2003 |
||
2004 |
self.DeleteButton = wx.Button(id=wxID_EDITVARIABLEDIALOGDELETEBUTTON, label='Delete', |
|
2005 |
name='DeleteButton', parent=self.MainPanel, pos=wx.Point(425, 340), |
|
2006 |
size=wx.Size(72, 32), style=0) |
|
2007 |
EVT_BUTTON(self, wxID_EDITVARIABLEDIALOGDELETEBUTTON, self.OnDeleteButton) |
|
2008 |
||
2009 |
self.UpButton = wx.Button(id=wxID_EDITVARIABLEDIALOGUPBUTTON, label='^', |
|
2010 |
name='UpButton', parent=self.MainPanel, pos=wx.Point(505, 340), |
|
2011 |
size=wx.Size(32, 32), style=0) |
|
2012 |
EVT_BUTTON(self, wxID_EDITVARIABLEDIALOGUPBUTTON, self.OnUpButton) |
|
2013 |
||
2014 |
self.DownButton = wx.Button(id=wxID_EDITVARIABLEDIALOGDOWNBUTTON, label='v', |
|
2015 |
name='DownButton', parent=self.MainPanel, pos=wx.Point(545, 340), |
|
2016 |
size=wx.Size(32, 32), style=0) |
|
2017 |
EVT_BUTTON(self, wxID_EDITVARIABLEDIALOGDOWNBUTTON, self.OnDownButton) |
|
2018 |
||
2019 |
self._init_sizers() |
|
2020 |
||
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2021 |
def __init__(self, parent, name, pou_type, pou_is_used, filter = "All"): |
0 | 2022 |
self._init_ctrls(parent, name) |
9 | 2023 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) |
0 | 2024 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) |
2025 |
self.Filter = filter |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2026 |
self.PouIsUsed = pou_is_used |
0 | 2027 |
self.FilterChoices = [] |
2028 |
self.FilterChoiceTransfer = {"All" : "All", "Interface" : "Interface", |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2029 |
" Input" : "Input", " Output" : "Output", " InOut" : "InOut", |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2030 |
" External" : "External", "Variables" : "Variables", " Local" : "Local", |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2031 |
" Temp" : "Temp", "Global" : "Global", "Access" : "Access"} |
0 | 2032 |
|
2033 |
if pou_type: |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2034 |
self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"} |
11 | 2035 |
self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No"} |
0 | 2036 |
else: |
11 | 2037 |
self.DefaultTypes = {"All" : "Global"} |
2038 |
self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No"} |
|
0 | 2039 |
if not pou_type or pou_type == "program": |
2040 |
self.Table = VariableTable(self, [], ["Name", "Class", "Type", "Location", "Initial Value", "Retain", "Constant"]) |
|
2041 |
if pou_type: |
|
2042 |
self.FilterChoices = ["All","Interface"," Input"," Output"," InOut"," External","Variables"," Local"," Temp","Global","Access"] |
|
2043 |
else: |
|
2044 |
self.FilterChoices = ["All","Global","Access"] |
|
2045 |
self.ColSizes = [80, 70, 80, 80, 80, 60, 70] |
|
2046 |
self.ColAlignements = [wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_CENTER, wxALIGN_CENTER] |
|
2047 |
else: |
|
2048 |
self.Table = VariableTable(self, [], ["Name", "Class", "Type", "Initial Value", "Retain", "Constant"]) |
|
2049 |
self.FilterChoices = ["All","Interface"," Input"," Output"," InOut"," External","Variables"," Local"," Temp"] |
|
2050 |
self.ColSizes = [120, 70, 80, 120, 60, 70] |
|
2051 |
self.ColAlignements = [wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_CENTER, wxALIGN_CENTER] |
|
2052 |
for choice in self.FilterChoices: |
|
2053 |
self.ClassFilter.Append(choice) |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2054 |
reverse_transfer = {} |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2055 |
for filter, choice in self.FilterChoiceTransfer.items(): |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2056 |
reverse_transfer[choice] = filter |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2057 |
self.ClassFilter.SetStringSelection(reverse_transfer[self.Filter]) |
0 | 2058 |
self.RefreshTypeList() |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2059 |
self.RefreshButtons() |
0 | 2060 |
|
2061 |
self.OptionList = "Yes,No" |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
2062 |
self.TypeList = ",".join([value for value, parent in TypeHierarchy_list if not value.startswith("ANY")]) |
0 | 2063 |
|
2064 |
if pou_type == "function": |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
2065 |
for value, parent in TypeHierarchy_list: |
0 | 2066 |
if not value.startswith("ANY"): |
2067 |
self.ReturnType.Append(value) |
|
2068 |
self.ReturnType.Enable(True) |
|
2069 |
else: |
|
2070 |
self.ReturnType.Enable(False) |
|
2071 |
self.staticText2.Hide() |
|
2072 |
self.ReturnType.Hide() |
|
2073 |
||
2074 |
self.VariablesGrid.SetTable(self.Table) |
|
2075 |
self.VariablesGrid.SetRowLabelSize(0) |
|
2076 |
||
2077 |
self.Table.ResetView(self.VariablesGrid) |
|
2078 |
||
6 | 2079 |
self.PouNames = [] |
2080 |
||
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2081 |
if self.PouIsUsed: |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2082 |
wxCallAfter(self.WarningMessage, name) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2083 |
|
0 | 2084 |
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
2085 |
||
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2086 |
def WarningMessage(self, name): |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2087 |
message = wxMessageDialog(self, "\"%s\" is used by one or more POUs. Its interface can't be changed!"%name, "WARNING", wxOK|wxICON_EXCLAMATION) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2088 |
message.ShowModal() |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2089 |
message.Destroy() |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2090 |
|
0 | 2091 |
def OnOK(self, event): |
2092 |
self.VariablesGrid.SetGridCursor(0, 0) |
|
2093 |
error = [] |
|
2094 |
if self.ReturnType.IsEnabled() and self.ReturnType.GetStringSelection() == "": |
|
2095 |
error.append("Return Type") |
|
2096 |
if len(error) > 0: |
|
2097 |
text = "" |
|
2098 |
for i, item in enumerate(error): |
|
2099 |
if i == 0: |
|
2100 |
text += item |
|
2101 |
elif i == len(error) - 1: |
|
2102 |
text += " and %s"%item |
|
2103 |
else: |
|
2104 |
text += ", %s"%item |
|
2105 |
message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) |
|
2106 |
message.ShowModal() |
|
2107 |
message.Destroy() |
|
2108 |
else: |
|
2109 |
self.EndModal(wxID_OK) |
|
2110 |
||
2111 |
def OnClassFilter(self, event): |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2112 |
self.Filter = self.FilterChoiceTransfer[self.ClassFilter.GetStringSelection()] |
0 | 2113 |
self.RefreshTypeList() |
2114 |
self.RefreshValues() |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2115 |
self.RefreshButtons() |
0 | 2116 |
event.Skip() |
2117 |
||
2118 |
def RefreshTypeList(self): |
|
2119 |
if self.Filter == "All": |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2120 |
self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All","Interface","Variables"]] |
0 | 2121 |
elif self.Filter == "Interface": |
2122 |
self.ClassList = ["Input","Output","InOut","External"] |
|
2123 |
elif self.Filter == "Variables": |
|
2124 |
self.ClassList = ["Local","Temp"] |
|
2125 |
else: |
|
2126 |
self.ClassList = [self.Filter] |
|
2127 |
||
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2128 |
def RefreshButtons(self): |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2129 |
table_length = len(self.Table.data) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2130 |
row_class = None |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2131 |
if table_length and self.PouIsUsed: |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2132 |
row = self.VariablesGrid.GetGridCursorRow() |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2133 |
row_class = self.Table.GetValueByName(row, "Class") |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2134 |
self.AddButton.Enable(not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2135 |
self.DeleteButton.Enable(table_length > 0 and row_class not in ["Input", "Output", "InOut"]) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2136 |
self.UpButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2137 |
self.DownButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2138 |
|
0 | 2139 |
def OnAddButton(self, event): |
11 | 2140 |
new_row = self.DefaultValue.copy() |
2141 |
if self.Filter in self.DefaultTypes: |
|
2142 |
new_row["Class"] = self.DefaultTypes[self.Filter] |
|
2143 |
else: |
|
2144 |
new_row["Class"] = self.Filter |
|
12 | 2145 |
self.Values.append(new_row) |
2146 |
self.RefreshValues() |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2147 |
self.RefreshButtons() |
0 | 2148 |
event.Skip() |
2149 |
||
2150 |
def OnDeleteButton(self, event): |
|
12 | 2151 |
row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow()) |
2152 |
self.Values.remove(row) |
|
2153 |
self.RefreshValues() |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2154 |
self.RefreshButtons() |
0 | 2155 |
event.Skip() |
2156 |
||
2157 |
def OnUpButton(self, event): |
|
12 | 2158 |
self.MoveValue(self.VariablesGrid.GetGridCursorRow(), -1) |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2159 |
self.RefreshButtons() |
0 | 2160 |
event.Skip() |
2161 |
||
2162 |
def OnDownButton(self, event): |
|
12 | 2163 |
self.MoveValue(self.VariablesGrid.GetGridCursorRow(), 1) |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2164 |
self.RefreshButtons() |
0 | 2165 |
event.Skip() |
2166 |
||
6 | 2167 |
def OnVariablesGridCellChange(self, event): |
2168 |
row, col = event.GetRow(), event.GetCol() |
|
2169 |
colname = self.Table.GetColLabelValue(col) |
|
2170 |
value = self.Table.GetValue(row, col) |
|
2171 |
if colname == "Name": |
|
2172 |
if not TestIdentifier(value): |
|
2173 |
message = wxMessageDialog(self, "\"%s\" is not a valid identifier!"%value, "Error", wxOK|wxICON_ERROR) |
|
2174 |
message.ShowModal() |
|
2175 |
message.Destroy() |
|
2176 |
event.Veto() |
|
2177 |
elif value.upper() in IEC_KEYWORDS: |
|
2178 |
message = wxMessageDialog(self, "\"%s\" is a keyword. It can't be used!"%value, "Error", wxOK|wxICON_ERROR) |
|
2179 |
message.ShowModal() |
|
2180 |
message.Destroy() |
|
2181 |
event.Veto() |
|
2182 |
elif value.upper() in self.PouNames: |
|
2183 |
message = wxMessageDialog(self, "A pou with \"%s\" as name exists!"%value, "Error", wxOK|wxICON_ERROR) |
|
2184 |
message.ShowModal() |
|
2185 |
message.Destroy() |
|
2186 |
event.Veto() |
|
2187 |
elif value.upper() in [var["Name"].upper() for var in self.Values if var != self.Table.data[row]]: |
|
2188 |
message = wxMessageDialog(self, "A variable with \"%s\" as name exists in this pou!"%value, "Error", wxOK|wxICON_ERROR) |
|
2189 |
message.ShowModal() |
|
2190 |
message.Destroy() |
|
2191 |
event.Veto() |
|
2192 |
else: |
|
2193 |
event.Skip() |
|
2194 |
else: |
|
2195 |
event.Skip() |
|
2196 |
||
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2197 |
def OnVariablesGridSelectCell(self, event): |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2198 |
wxCallAfter(self.RefreshButtons) |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2199 |
event.Skip() |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2200 |
|
6 | 2201 |
def SetPouNames(self, pou_names): |
2202 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
2203 |
||
0 | 2204 |
def SetValues(self, values): |
2205 |
for item, value in values.items(): |
|
2206 |
if item == "returnType" and value and self.ReturnType.IsEnabled(): |
|
2207 |
self.ReturnType.SetStringSelection(value) |
|
2208 |
if item == "data": |
|
2209 |
self.Values = value |
|
2210 |
self.RefreshValues() |
|
12 | 2211 |
|
2212 |
def MoveValue(self, value_index, move): |
|
2213 |
new_index = max(0, min(value_index + move, len(self.Values) - 1)) |
|
2214 |
if new_index != value_index: |
|
2215 |
self.Values.insert(new_index, self.Values.pop(value_index)) |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
2216 |
self.RefreshValues() |
12 | 2217 |
self.VariablesGrid.SetGridCursor(new_index, self.VariablesGrid.GetGridCursorCol()) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
2218 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
2219 |
self.RefreshValues() |
12 | 2220 |
|
0 | 2221 |
def RefreshValues(self): |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2222 |
if len(self.Table.data) > 0: |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2223 |
self.VariablesGrid.SetGridCursor(0, 0) |
0 | 2224 |
data = [] |
2225 |
for variable in self.Values: |
|
2226 |
if variable["Class"] in self.ClassList: |
|
2227 |
data.append(variable) |
|
2228 |
self.Table.SetData(data) |
|
2229 |
self.Table.ResetView(self.VariablesGrid) |
|
2230 |
||
2231 |
def GetValues(self): |
|
2232 |
values = {} |
|
2233 |
if self.ReturnType.IsEnabled(): |
|
2234 |
values["returnType"] = self.ReturnType.GetStringSelection() |
|
12 | 2235 |
values["data"] = self.Values |
0 | 2236 |
return values |
2237 |
||
2238 |
#------------------------------------------------------------------------------- |
|
2239 |
# Exception Handler |
|
2240 |
#------------------------------------------------------------------------------- |
|
2241 |
||
2242 |
Max_Traceback_List_Size = 20 |
|
2243 |
||
2244 |
def Display_Exception_Dialog(e_type,e_value,e_tb): |
|
2245 |
trcbck_lst = [] |
|
2246 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
|
2247 |
trcbck = " " + str(i+1) + ". " |
|
2248 |
if line[0].find(os.getcwd()) == -1: |
|
2249 |
trcbck += "file : " + str(line[0]) + ", " |
|
2250 |
else: |
|
2251 |
trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " |
|
2252 |
trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) |
|
2253 |
trcbck_lst.append(trcbck) |
|
2254 |
||
2255 |
# Allow clicking.... |
|
2256 |
cap = wx.Window_GetCapture() |
|
2257 |
if cap: |
|
2258 |
cap.ReleaseMouse() |
|
2259 |
||
2260 |
dlg = wx.SingleChoiceDialog(None, |
|
2261 |
""" |
|
2262 |
An error happens. |
|
2263 |
||
2264 |
Click on OK for saving an error report. |
|
2265 |
||
2266 |
Please contact LOLITech at: |
|
2267 |
+33 (0)3 29 52 95 67 |
|
2268 |
bugs_PLCOpenEditor@lolitech.fr |
|
2269 |
||
2270 |
||
2271 |
Error: |
|
2272 |
""" + |
|
2273 |
str(e_type) + " : " + str(e_value), |
|
2274 |
"Error", |
|
2275 |
trcbck_lst) |
|
2276 |
try: |
|
2277 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
2278 |
finally: |
|
2279 |
dlg.Destroy() |
|
2280 |
||
2281 |
return res |
|
2282 |
||
2283 |
def Display_Error_Dialog(e_value): |
|
2284 |
message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR) |
|
2285 |
message.ShowModal() |
|
2286 |
message.Destroy() |
|
2287 |
||
2288 |
def get_last_traceback(tb): |
|
2289 |
while tb.tb_next: |
|
2290 |
tb = tb.tb_next |
|
2291 |
return tb |
|
2292 |
||
2293 |
||
2294 |
def format_namespace(d, indent=' '): |
|
2295 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
2296 |
||
2297 |
||
2298 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
|
2299 |
||
2300 |
def wxAddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
|
2301 |
||
2302 |
def handle_exception(e_type, e_value, e_traceback): |
|
2303 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
|
2304 |
last_tb = get_last_traceback(e_traceback) |
|
2305 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
2306 |
if str(e_value).startswith("!!!"): |
|
2307 |
Display_Error_Dialog(e_value) |
|
2308 |
elif ex not in ignored_exceptions: |
|
2309 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback) |
|
2310 |
if result: |
|
2311 |
ignored_exceptions.append(ex) |
|
2312 |
info = { |
|
2313 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
|
2314 |
'app-version' : app_version, |
|
2315 |
'wx-version' : wx.VERSION_STRING, |
|
2316 |
'wx-platform' : wx.Platform, |
|
2317 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
|
2318 |
'platform' : platform.platform(), |
|
2319 |
'e-type' : e_type, |
|
2320 |
'e-value' : e_value, |
|
2321 |
'date' : time.ctime(), |
|
2322 |
'cwd' : os.getcwd(), |
|
2323 |
} |
|
2324 |
if e_traceback: |
|
2325 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
2326 |
last_tb = get_last_traceback(e_traceback) |
|
2327 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
2328 |
info['locals'] = format_namespace(exception_locals) |
|
2329 |
if 'self' in exception_locals: |
|
2330 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
2331 |
||
2332 |
output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') |
|
2333 |
lst = info.keys() |
|
2334 |
lst.sort() |
|
2335 |
for a in lst: |
|
2336 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
2337 |
||
2338 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
2339 |
sys.excepthook = handle_exception |
|
2340 |
||
2341 |
if __name__ == '__main__': |
|
2342 |
app = wxPySimpleApp() |
|
2343 |
wxInitAllImageHandlers() |
|
2344 |
||
2345 |
# Install a exception handle for bug reports |
|
2346 |
wxAddExceptHook(os.getcwd(),__version__) |
|
2347 |
||
2348 |
frame = PLCOpenEditor(None) |
|
2349 |
||
2350 |
frame.Show() |
|
2351 |
app.MainLoop() |
|
2352 |