author | etisserant |
Thu, 28 Feb 2008 18:07:52 +0100 | |
changeset 179 | 32f269883027 |
parent 177 | a3f6670949ba |
child 181 | 2981c3d3b088 |
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 |
# |
|
58 | 7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
0 | 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 |
|
58 | 19 |
#General Public License for more details. |
0 | 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 datetime import datetime |
|
120 | 26 |
import wx, wx.grid |
27 |
||
28 |
if wx.VERSION >= (2, 8, 0): |
|
29 |
import wx.aui |
|
0 | 30 |
|
31 |
from SFCViewer import * |
|
32 |
from LDViewer import * |
|
33 |
from Viewer import * |
|
27 | 34 |
from TextViewer import * |
35 |
from RessourceEditor import * |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
36 |
from DataTypeEditor import * |
0 | 37 |
from PLCControler import * |
38 |
from plcopen import OpenPDFDoc |
|
107 | 39 |
from plcopen.structures import LOCATIONDATATYPES |
0 | 40 |
|
41 |
import os, re, platform, sys, time, traceback, getopt |
|
42 |
||
43 |
__version__ = "$Revision$" |
|
44 |
||
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
45 |
CWD = os.path.split(os.path.realpath(__file__))[0] |
0 | 46 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
47 |
[ID_PLCOPENEDITOR, ID_PLCOPENEDITORPROJECTTREE, |
121 | 48 |
ID_PLCOPENEDITORMAINSPLITTER, ID_PLCOPENEDITORSECONDSPLITTER, |
49 |
ID_PLCOPENEDITOREDITORPANEL, ID_PLCOPENEDITORTABSOPENED, |
|
50 |
ID_PLCOPENEDITORTOOLBAR, ID_PLCOPENEDITORDEFAULTTOOLBAR, |
|
51 |
ID_PLCOPENEDITORSFCTOOLBAR, ID_PLCOPENEDITORFBDTOOLBAR, |
|
52 |
ID_PLCOPENEDITORLDTOOLBAR, |
|
53 |
] = [wx.NewId() for _init_ctrls in range(11)] |
|
6 | 54 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
55 |
[ID_PLCOPENEDITORFILEMENUITEMS0, ID_PLCOPENEDITORFILEMENUITEMS1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
56 |
ID_PLCOPENEDITORFILEMENUITEMS2, ID_PLCOPENEDITORFILEMENUITEMS3, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
57 |
ID_PLCOPENEDITORFILEMENUITEMS5, ID_PLCOPENEDITORFILEMENUITEMS6, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
58 |
ID_PLCOPENEDITORFILEMENUITEMS7, ID_PLCOPENEDITORFILEMENUITEMS9, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
59 |
ID_PLCOPENEDITORFILEMENUITEMS11, |
0 | 60 |
] = [wx.NewId() for _init_coll_FileMenu_Items in range(9)] |
61 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
62 |
[ID_PLCOPENEDITORHELPMENUITEMS0, ID_PLCOPENEDITORHELPMENUITEMS1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
63 |
ID_PLCOPENEDITORHELPMENUITEMS2, ID_PLCOPENEDITORHELPMENUITEMS3, |
0 | 64 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(4)] |
65 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
66 |
[ID_PLCOPENEDITORSFCMENUITEMS0, ID_PLCOPENEDITORSFCMENUITEMS1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
67 |
ID_PLCOPENEDITORSFCMENUITEMS2, ID_PLCOPENEDITORSFCMENUITEMS3, |
0 | 68 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(4)] |
69 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
70 |
[ID_PLCOPENEDITORCONFIGMENUITEMS0, ID_PLCOPENEDITORCONFIGMENUITEMS1, |
0 | 71 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(2)] |
72 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
73 |
[ID_PLCOPENEDITOREDITMENUITEMS0, ID_PLCOPENEDITOREDITMENUITEMS1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
74 |
ID_PLCOPENEDITOREDITMENUITEMS2, ID_PLCOPENEDITOREDITMENUITEMS4, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
75 |
ID_PLCOPENEDITOREDITMENUITEMS5, ID_PLCOPENEDITOREDITMENUITEMS6, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
76 |
ID_PLCOPENEDITOREDITMENUITEMS8, ID_PLCOPENEDITOREDITMENUITEMS9, |
163 | 77 |
ID_PLCOPENEDITOREDITMENUITEMS10, ID_PLCOPENEDITOREDITMENUITEMS11, |
78 |
ID_PLCOPENEDITOREDITMENUITEMS12, ID_PLCOPENEDITOREDITMENUITEMS13, |
|
79 |
ID_PLCOPENEDITOREDITMENUITEMS14, |
|
80 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(13)] |
|
0 | 81 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
82 |
[ID_PLCOPENEDITORSFCMENUITEMS0, ID_PLCOPENEDITORSFCMENUITEMS1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
83 |
ID_PLCOPENEDITORSFCMENUITEMS2, ID_PLCOPENEDITORSFCMENUITEMS3, |
0 | 84 |
] = [wx.NewId() for _init_coll_SFCMenu_Items in range(4)] |
85 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
86 |
[ID_PLCOPENEDITORCONFIGMENUITEMS0, ID_PLCOPENEDITORCONFIGMENUITEMS1, |
0 | 87 |
] = [wx.NewId() for _init_coll_ConfigMenu_Items in range(2)] |
88 |
||
27 | 89 |
|
90 |
#------------------------------------------------------------------------------- |
|
91 |
# ToolBars definitions |
|
92 |
#------------------------------------------------------------------------------- |
|
93 |
||
94 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
95 |
[ID_PLCOPENEDITORTOOLBARSELECTION, ID_PLCOPENEDITORTOOLBARCOMMENT, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
96 |
ID_PLCOPENEDITORTOOLBARVARIABLE, ID_PLCOPENEDITORTOOLBARBLOCK, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
97 |
ID_PLCOPENEDITORTOOLBARCONNECTION, ID_PLCOPENEDITORTOOLBARWIRE, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
98 |
ID_PLCOPENEDITORTOOLBARPOWERRAIL, ID_PLCOPENEDITORTOOLBARRUNG, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
99 |
ID_PLCOPENEDITORTOOLBARCOIL, ID_PLCOPENEDITORTOOLBARCONTACT, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
100 |
ID_PLCOPENEDITORTOOLBARBRANCH, ID_PLCOPENEDITORTOOLBARINITIALSTEP, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
101 |
ID_PLCOPENEDITORTOOLBARSTEP, ID_PLCOPENEDITORTOOLBARTRANSITION, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
102 |
ID_PLCOPENEDITORTOOLBARACTIONBLOCK, ID_PLCOPENEDITORTOOLBARDIVERGENCE, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
103 |
ID_PLCOPENEDITORTOOLBARJUMP, |
27 | 104 |
] = [wx.NewId() for _init_coll_DefaultToolBar_Items in range(17)] |
105 |
||
106 |
ToolBarItems = { |
|
95 | 107 |
"FBD" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", "comment.png", "Create a new comment"), |
108 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", "variable.png", "Create a new variable"), |
|
109 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", "block.png", "Create a new block"), |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
135
diff
changeset
|
110 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", "connection.png", "Create a new connection")], |
95 | 111 |
"LD" : [(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", "comment.png", "Create a new comment"), |
112 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARPOWERRAIL, "OnPowerRailTool", "powerrail.png", "Create a new power rail"), |
|
113 |
(False, DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARRUNG, "OnRungTool", "rung.png", "Create a new rung"), |
|
114 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCOIL, "OnCoilTool", "coil.png", "Create a new coil"), |
|
115 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCONTACT, "OnContactTool", "contact.png", "Create a new contact"), |
|
116 |
(False, DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARBRANCH, "OnBranchTool", "branch.png", "Create a new branch"), |
|
117 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", "variable.png", "Create a new variable"), |
|
118 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", "block.png", "Create a new block"), |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
135
diff
changeset
|
119 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", "connection.png", "Create a new connection")], |
95 | 120 |
"SFC" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", "comment.png", "Create a new comment"), |
121 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARINITIALSTEP, "OnInitialStepTool", "initial_step.png", "Create a new initial step"), |
|
122 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARSTEP, "OnStepTool", "step.png", "Create a new step"), |
|
123 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARTRANSITION, "OnTransitionTool", "transition.png", "Create a new transition"), |
|
124 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARACTIONBLOCK, "OnActionBlockTool", "action.png", "Create a new action block"), |
|
125 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARDIVERGENCE, "OnDivergenceTool", "divergence.png", "Create a new divergence"), |
|
126 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARJUMP, "OnJumpTool", "jump.png", "Create a new jump"), |
|
127 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", "variable.png", "Create a new variable"), |
|
128 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", "block.png", "Create a new block"), |
|
129 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", "connection.png", "Create a new connection"), |
|
130 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARPOWERRAIL, "OnPowerRailTool", "powerrail.png", "Create a new power rail"), |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
135
diff
changeset
|
131 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCONTACT, "OnContactTool", "contact.png", "Create a new contact")], |
82 | 132 |
"ST" : [], |
133 |
"IL" : [] |
|
27 | 134 |
} |
135 |
||
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
136 |
def AppendMenu(parent, help, id, kind, text): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
137 |
if wx.VERSION >= (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
138 |
parent.Append(help=help, id=id, kind=kind, text=text) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
139 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
140 |
parent.Append(helpString=help, id=id, kind=kind, item=text) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
141 |
|
121 | 142 |
if wx.VERSION >= (2, 8, 0): |
143 |
base_class = wx.aui.AuiMDIParentFrame |
|
144 |
else: |
|
145 |
base_class = wx.Frame |
|
146 |
||
147 |
class PLCOpenEditor(base_class): |
|
0 | 148 |
_custom_classes = {'wx.SashWindow' : ['Viewer']} |
149 |
||
163 | 150 |
CopyBuffer = None |
151 |
||
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
152 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
153 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
154 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
155 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
156 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
157 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
158 |
|
0 | 159 |
def _init_coll_EditMenu_Items(self, parent): |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
160 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS0, |
0 | 161 |
kind=wx.ITEM_NORMAL, text=u'Refresh\tCTRL+R') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
162 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS1, |
0 | 163 |
kind=wx.ITEM_NORMAL, text=u'Undo\tCTRL+Z') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
164 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS2, |
0 | 165 |
kind=wx.ITEM_NORMAL, text=u'Redo\tCTRL+Y') |
166 |
parent.AppendSeparator() |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
167 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS4, |
0 | 168 |
kind=wx.ITEM_NORMAL, text=u'Cut\tCTRL+X') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
169 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS5, |
0 | 170 |
kind=wx.ITEM_NORMAL, text=u'Copy\tCTRL+C') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
171 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS6, |
0 | 172 |
kind=wx.ITEM_NORMAL, text=u'Paste\tCTRL+V') |
173 |
parent.AppendSeparator() |
|
163 | 174 |
addmenu = wx.Menu(title='') |
175 |
parent.AppendMenu(ID_PLCOPENEDITOREDITMENUITEMS8, "Add Element", addmenu) |
|
176 |
AppendMenu(addmenu, help='', id=ID_PLCOPENEDITOREDITMENUITEMS9, |
|
177 |
kind=wx.ITEM_NORMAL, text=u'Data Type') |
|
178 |
AppendMenu(addmenu, help='', id=ID_PLCOPENEDITOREDITMENUITEMS10, |
|
179 |
kind=wx.ITEM_NORMAL, text=u'Function') |
|
180 |
AppendMenu(addmenu, help='', id=ID_PLCOPENEDITOREDITMENUITEMS11, |
|
181 |
kind=wx.ITEM_NORMAL, text=u'Function Block') |
|
182 |
AppendMenu(addmenu, help='', id=ID_PLCOPENEDITOREDITMENUITEMS12, |
|
183 |
kind=wx.ITEM_NORMAL, text=u'Program') |
|
184 |
AppendMenu(addmenu, help='', id=ID_PLCOPENEDITOREDITMENUITEMS13, |
|
185 |
kind=wx.ITEM_NORMAL, text=u'Configuration') |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
186 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS14, |
163 | 187 |
kind=wx.ITEM_NORMAL, text=u'Delete') |
0 | 188 |
self.Bind(wx.EVT_MENU, self.OnRefreshMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
189 |
id=ID_PLCOPENEDITOREDITMENUITEMS0) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
190 |
self.Bind(wx.EVT_MENU, self.OnUndoMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
191 |
id=ID_PLCOPENEDITOREDITMENUITEMS1) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
192 |
self.Bind(wx.EVT_MENU, self.OnRedoMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
193 |
id=ID_PLCOPENEDITOREDITMENUITEMS2) |
0 | 194 |
self.Bind(wx.EVT_MENU, self.OnCutMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
195 |
id=ID_PLCOPENEDITOREDITMENUITEMS4) |
0 | 196 |
self.Bind(wx.EVT_MENU, self.OnCopyMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
197 |
id=ID_PLCOPENEDITOREDITMENUITEMS5) |
0 | 198 |
self.Bind(wx.EVT_MENU, self.OnPasteMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
199 |
id=ID_PLCOPENEDITOREDITMENUITEMS6) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
200 |
self.Bind(wx.EVT_MENU, self.OnAddDataTypeMenu, |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
201 |
id=ID_PLCOPENEDITOREDITMENUITEMS9) |
163 | 202 |
self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("function"), |
203 |
id=ID_PLCOPENEDITOREDITMENUITEMS10) |
|
204 |
self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("functionBlock"), |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
205 |
id=ID_PLCOPENEDITOREDITMENUITEMS11) |
163 | 206 |
self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("program"), |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
207 |
id=ID_PLCOPENEDITOREDITMENUITEMS12) |
0 | 208 |
self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu, |
163 | 209 |
id=ID_PLCOPENEDITOREDITMENUITEMS13) |
210 |
self.Bind(wx.EVT_MENU, self.OnDeleteMenu, |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
211 |
id=ID_PLCOPENEDITOREDITMENUITEMS14) |
0 | 212 |
|
213 |
def _init_coll_menuBar1_Menus(self, parent): |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
214 |
if self.ModeSolo: |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
215 |
parent.Append(menu=self.FileMenu, title=u'File') |
0 | 216 |
parent.Append(menu=self.EditMenu, title=u'Edit') |
217 |
parent.Append(menu=self.HelpMenu, title=u'Help') |
|
218 |
||
219 |
def _init_coll_HelpMenu_Items(self, parent): |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
220 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORHELPMENUITEMS0, |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
221 |
kind=wx.ITEM_NORMAL, text=u'PLCOpenEditor\tF1') |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
222 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORHELPMENUITEMS1, |
0 | 223 |
kind=wx.ITEM_NORMAL, text=u'PLCOpen\tF2') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
224 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORHELPMENUITEMS2, |
0 | 225 |
kind=wx.ITEM_NORMAL, text=u'IEC 61131-3\tF3') |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
226 |
if self.ModeSolo: |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
227 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORHELPMENUITEMS3, |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
228 |
kind=wx.ITEM_NORMAL, text=u'About') |
0 | 229 |
self.Bind(wx.EVT_MENU, self.OnPLCOpenMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
230 |
id=ID_PLCOPENEDITORHELPMENUITEMS1) |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
231 |
|
0 | 232 |
def _init_coll_FileMenu_Items(self, parent): |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
233 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS0, |
0 | 234 |
kind=wx.ITEM_NORMAL, text=u'New\tCTRL+N') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
235 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS1, |
0 | 236 |
kind=wx.ITEM_NORMAL, text=u'Open\tCTRL+O') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
237 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS2, |
0 | 238 |
kind=wx.ITEM_NORMAL, text=u'Close Tab\tCTRL+W') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
239 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS3, |
0 | 240 |
kind=wx.ITEM_NORMAL, text=u'Close Project') |
241 |
parent.AppendSeparator() |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
242 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS5, |
0 | 243 |
kind=wx.ITEM_NORMAL, text=u'Save\tCTRL+S') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
244 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS6, |
0 | 245 |
kind=wx.ITEM_NORMAL, text=u'Save As...\tCTRL+SHIFT+S') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
246 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS7, |
0 | 247 |
kind=wx.ITEM_NORMAL, text=u'Generate Program\tCTRL+G') |
248 |
parent.AppendSeparator() |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
249 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS9, |
0 | 250 |
kind=wx.ITEM_NORMAL, text=u'Properties') |
251 |
parent.AppendSeparator() |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
252 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS11, |
0 | 253 |
kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q') |
254 |
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
255 |
id=ID_PLCOPENEDITORFILEMENUITEMS0) |
0 | 256 |
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
257 |
id=ID_PLCOPENEDITORFILEMENUITEMS1) |
0 | 258 |
self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
259 |
id=ID_PLCOPENEDITORFILEMENUITEMS2) |
0 | 260 |
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
261 |
id=ID_PLCOPENEDITORFILEMENUITEMS3) |
0 | 262 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
263 |
id=ID_PLCOPENEDITORFILEMENUITEMS5) |
0 | 264 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
265 |
id=ID_PLCOPENEDITORFILEMENUITEMS6) |
0 | 266 |
self.Bind(wx.EVT_MENU, self.OnGenerateProgramMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
267 |
id=ID_PLCOPENEDITORFILEMENUITEMS7) |
27 | 268 |
self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
269 |
id=ID_PLCOPENEDITORFILEMENUITEMS9) |
0 | 270 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
271 |
id=ID_PLCOPENEDITORFILEMENUITEMS11) |
0 | 272 |
|
273 |
def _init_utils(self): |
|
274 |
self.menuBar1 = wx.MenuBar() |
|
275 |
||
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
276 |
if self.ModeSolo: |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
277 |
self.FileMenu = wx.Menu(title='') |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
278 |
else: |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
279 |
self.FileMenu = None |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
280 |
self.EditMenu = wx.Menu(title='') |
0 | 281 |
self.HelpMenu = wx.Menu(title='') |
163 | 282 |
|
0 | 283 |
self._init_coll_menuBar1_Menus(self.menuBar1) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
284 |
if self.ModeSolo: |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
285 |
self._init_coll_FileMenu_Items(self.FileMenu) |
0 | 286 |
self._init_coll_EditMenu_Items(self.EditMenu) |
287 |
self._init_coll_HelpMenu_Items(self.HelpMenu) |
|
163 | 288 |
|
0 | 289 |
def _init_ctrls(self, prnt): |
121 | 290 |
if wx.VERSION >= (2, 8, 0): |
291 |
wx.aui.AuiMDIParentFrame.__init__(self, winid=ID_PLCOPENEDITOR, name=u'PLCOpenEditor', |
|
292 |
parent=prnt, pos=wx.DefaultPosition, size=wx.Size(1000, 600), |
|
293 |
style=wx.DEFAULT_FRAME_STYLE|wx.SUNKEN_BORDER|wx.CLIP_CHILDREN, title=u'PLCOpenEditor') |
|
294 |
else: |
|
295 |
wx.Frame.__init__(self, id=ID_PLCOPENEDITOR, name=u'PLCOpenEditor', |
|
296 |
parent=prnt, pos=wx.DefaultPosition, size=wx.Size(1000, 600), |
|
297 |
style=wx.DEFAULT_FRAME_STYLE, title=u'PLCOpenEditor') |
|
0 | 298 |
self._init_utils() |
299 |
self.SetClientSize(wx.Size(1000, 600)) |
|
300 |
self.SetMenuBar(self.menuBar1) |
|
92
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
301 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
302 |
if not self.ModeSolo: |
121 | 303 |
self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=ID_PLCOPENEDITORFILEMENUITEMS2) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
304 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=ID_PLCOPENEDITORFILEMENUITEMS5) |
121 | 305 |
accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, 119, ID_PLCOPENEDITORFILEMENUITEMS2), |
306 |
wx.AcceleratorEntry(wx.ACCEL_CTRL, 83, ID_PLCOPENEDITORFILEMENUITEMS5)]) |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
307 |
self.SetAcceleratorTable(accel) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
308 |
|
120 | 309 |
if wx.VERSION >= (2, 8, 0): |
310 |
self.AUIManager = wx.aui.AuiManager(self) |
|
121 | 311 |
self.AUIManager.SetDockSizeConstraint(0.5, 0.5) |
120 | 312 |
self.Panes = {} |
313 |
||
314 |
if wx.VERSION < (2, 8, 0): |
|
315 |
self.MainSplitter = wx.SplitterWindow(id=ID_PLCOPENEDITORMAINSPLITTER, |
|
316 |
name='MainSplitter', parent=self, point=wx.Point(0, 0), |
|
317 |
size=wx.Size(0, 0), style=wx.SP_3D) |
|
318 |
self.MainSplitter.SetNeedUpdating(True) |
|
319 |
self.MainSplitter.SetMinimumPaneSize(1) |
|
320 |
||
321 |
self.ProjectTree = wx.TreeCtrl(id=ID_PLCOPENEDITORPROJECTTREE, |
|
322 |
name='treeCtrl1', parent=self.MainSplitter, pos=wx.Point(0, 0), |
|
323 |
size=wx.Size(-1, -1), |
|
324 |
style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER) |
|
325 |
else: |
|
326 |
self.ProjectTree = wx.TreeCtrl(id=ID_PLCOPENEDITORPROJECTTREE, |
|
327 |
name='treeCtrl1', parent=self, pos=wx.Point(0, 0), |
|
328 |
size=wx.Size(200, -1), |
|
329 |
style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER) |
|
121 | 330 |
self.AUIManager.AddPane(self.ProjectTree, wx.aui.AuiPaneInfo().Caption("Project Tree").Left().Layer(1).BestSize(wx.Size(200, 500)).CloseButton(False)) |
131 | 331 |
if wx.Platform == '__WXMSW__': |
332 |
self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnProjectTreeRightUp, |
|
333 |
id=ID_PLCOPENEDITORPROJECTTREE) |
|
132 | 334 |
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnProjectTreeItemSelected, |
131 | 335 |
id=ID_PLCOPENEDITORPROJECTTREE) |
336 |
else: |
|
337 |
if wx.VERSION >= (2, 6, 0): |
|
338 |
self.ProjectTree.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp) |
|
339 |
self.ProjectTree.Bind(wx.EVT_LEFT_UP, self.OnProjectTreeLeftUp) |
|
340 |
else: |
|
341 |
wx.EVT_RIGHT_UP(self.ProjectTree, self.OnProjectTreeRightUp) |
|
342 |
wx.EVT_LEFT_UP(self.ProjectTree, self.OnProjectTreeLeftUp) |
|
343 |
self.Bind(wx.EVT_TREE_SEL_CHANGING, self.OnProjectTreeItemChanging, |
|
344 |
id=ID_PLCOPENEDITORPROJECTTREE) |
|
7 | 345 |
self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnProjectTreeBeginDrag, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
346 |
id=ID_PLCOPENEDITORPROJECTTREE) |
0 | 347 |
self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
348 |
id=ID_PLCOPENEDITORPROJECTTREE) |
0 | 349 |
self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnProjectTreeItemEndEdit, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
350 |
id=ID_PLCOPENEDITORPROJECTTREE) |
0 | 351 |
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnProjectTreeItemActivated, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
352 |
id=ID_PLCOPENEDITORPROJECTTREE) |
95 | 353 |
|
120 | 354 |
if wx.VERSION < (2, 8, 0): |
355 |
self.ToolBar = self.CreateToolBar(wx.TB_HORIZONTAL|wx.TB_FLAT|wx.NO_BORDER, |
|
356 |
ID_PLCOPENEDITORTOOLBAR, 'ToolBar') |
|
357 |
self.ToolBar.SetToolBitmapSize(wx.Size(25, 25)) |
|
358 |
self.ToolBar.AddRadioTool(ID_PLCOPENEDITORTOOLBARSELECTION, |
|
359 |
wx.Bitmap(os.path.join(CWD, 'Images', 'select.png')), wx.NullBitmap, "Select an object") |
|
360 |
self.ToolBar.Realize() |
|
361 |
else: |
|
362 |
ToolBar = wx.ToolBar(self, ID_PLCOPENEDITORTOOLBAR, wx.DefaultPosition, wx.DefaultSize, |
|
363 |
wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER) |
|
364 |
ToolBar.SetToolBitmapSize(wx.Size(25, 25)) |
|
365 |
ToolBar.AddRadioTool(ID_PLCOPENEDITORTOOLBARSELECTION, |
|
366 |
wx.Bitmap(os.path.join(CWD, 'Images', 'select.png')), wx.NullBitmap, "Select an object") |
|
367 |
ToolBar.Realize() |
|
368 |
self.Panes["ToolBar"] = ToolBar |
|
369 |
self.AUIManager.AddPane(ToolBar, wx.aui.AuiPaneInfo(). |
|
370 |
Name("ToolBar").Caption("Toolbar"). |
|
371 |
ToolbarPane().Top(). |
|
372 |
LeftDockable(False).RightDockable(False)) |
|
373 |
||
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
374 |
self.Bind(wx.EVT_TOOL, self.OnSelectionTool, |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
375 |
id=ID_PLCOPENEDITORTOOLBARSELECTION) |
120 | 376 |
|
377 |
if wx.VERSION < (2, 8, 0): |
|
121 | 378 |
self.SecondSplitter = wx.SplitterWindow(id=ID_PLCOPENEDITORSECONDSPLITTER, |
379 |
name='SecondSplitter', parent=self.MainSplitter, point=wx.Point(0, 0), |
|
380 |
size=wx.Size(0, 0), style=wx.SP_3D) |
|
381 |
self.SecondSplitter.SetMinimumPaneSize(1) |
|
382 |
||
383 |
self.MainSplitter.SplitVertically(self.ProjectTree, self.SecondSplitter, 200) |
|
384 |
||
120 | 385 |
self.TabsOpened = wx.Notebook(id=ID_PLCOPENEDITORTABSOPENED, |
121 | 386 |
name='TabsOpened', parent=self.SecondSplitter, pos=wx.Point(0, |
120 | 387 |
0), size=wx.Size(0, 0), style=0) |
121 | 388 |
if wx.VERSION >= (2, 6, 0): |
389 |
self.TabsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, |
|
390 |
self.OnPouSelectedChanged, id=ID_PLCOPENEDITORTABSOPENED) |
|
391 |
else: |
|
392 |
wx.EVT_NOTEBOOK_PAGE_CHANGED(self.TabsOpened, ID_PLCOPENEDITORTABSOPENED, |
|
393 |
self.OnPouSelectedChanged) |
|
394 |
||
395 |
if wx.VERSION < (2, 8, 0): |
|
145 | 396 |
self.VariablePanelIndexer = VariablePanelIndexer(self.SecondSplitter, self, self.Controler) |
121 | 397 |
|
398 |
self.SecondSplitter.SplitHorizontally(self.TabsOpened, self.VariablePanelIndexer, -200) |
|
399 |
else: |
|
145 | 400 |
self.VariablePanelIndexer = VariablePanelIndexer(self, self, self.Controler) |
121 | 401 |
self.AUIManager.AddPane(self.VariablePanelIndexer, wx.aui.AuiPaneInfo().Caption("Variable Panel").Bottom().Layer(0).BestSize(wx.Size(800, 200)).CloseButton(False)) |
402 |
||
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
403 |
self.AUIManager.Update() |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
404 |
|
92
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
405 |
def __init__(self, parent, controler = None, fileOpen = None): |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
406 |
self.ModeSolo = controler == None |
121 | 407 |
if self.ModeSolo: |
408 |
self.Controler = PLCControler() |
|
409 |
if fileOpen is not None: |
|
410 |
self.Controler.OpenXMLFile(fileOpen) |
|
411 |
else: |
|
412 |
self.Controler = controler |
|
413 |
||
0 | 414 |
self._init_ctrls(parent) |
415 |
||
176 | 416 |
# Add beremiz's icon in top left corner of the frame |
417 |
if wx.Platform == '__WXMSW__': |
|
418 |
icon = wx.Icon(os.path.join(CWD,"poe.ico"),wx.BITMAP_TYPE_ICO) |
|
419 |
else: |
|
420 |
icon = wx.Icon(os.path.join(CWD,"poe.png"),wx.BITMAP_TYPE_PNG) |
|
421 |
self.SetIcon(icon) |
|
422 |
||
95 | 423 |
if wx.Platform != '__WXMSW__': |
424 |
self.TreeImageList = wx.ImageList(16, 16) |
|
425 |
for language in LANGUAGES: |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
426 |
self.TreeImageList.Add(wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%language))) |
95 | 427 |
self.ProjectTree.AssignImageList(self.TreeImageList) |
9 | 428 |
|
6 | 429 |
self.CurrentToolBar = [] |
27 | 430 |
self.CurrentLanguage = "" |
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
431 |
self.SelectedItem = None |
71 | 432 |
self.DrawingMode = FREEDRAWING_MODE |
433 |
#self.DrawingMode = DRIVENDRAWING_MODE |
|
6 | 434 |
|
121 | 435 |
if not self.ModeSolo or fileOpen is not None: |
436 |
self.RefreshProjectTree() |
|
437 |
||
0 | 438 |
self.RefreshFileMenu() |
439 |
self.RefreshEditMenu() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
440 |
self.RefreshTitle() |
0 | 441 |
self.RefreshToolBar() |
442 |
||
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
443 |
def ResetSelectedItem(self): |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
444 |
self.SelectedItem = None |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
445 |
|
121 | 446 |
def OnPageClose(self, event): |
447 |
selected = self.GetPageSelection() |
|
448 |
if selected >= 0: |
|
449 |
tagname = self.GetPage(selected).GetTagName() |
|
450 |
self.VariablePanelIndexer.RemoveVariablePanel(tagname) |
|
451 |
if self.GetPageCount() > 0: |
|
452 |
new_index = min(selected, self.GetPageCount() - 1) |
|
453 |
tagname = self.GetPage(new_index).GetTagName() |
|
454 |
self.SetPageSelection(new_index) |
|
455 |
self.VariablePanelIndexer.ChangeVariablePanel(tagname) |
|
456 |
self.RefreshTitle() |
|
457 |
self.RefreshFileMenu() |
|
458 |
self.RefreshEditMenu() |
|
459 |
self.RefreshToolBar() |
|
460 |
event.Skip() |
|
461 |
||
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
462 |
def GetCopyBuffer(self): |
163 | 463 |
return PLCOpenEditor.CopyBuffer |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
464 |
|
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
465 |
def SetCopyBuffer(self, element): |
163 | 466 |
PLCOpenEditor.CopyBuffer = element |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
467 |
self.RefreshEditMenu() |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
468 |
|
27 | 469 |
def GetDrawingMode(self): |
470 |
return self.DrawingMode |
|
471 |
||
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
472 |
def RefreshTitle(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
473 |
if self.Controler.HasOpenedProject() > 0: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
474 |
self.SetTitle("PLCOpenEditor - %s"%self.Controler.GetFilename()) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
475 |
else: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
476 |
self.SetTitle("PLCOpenEditor") |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
477 |
|
27 | 478 |
def ShowProperties(self): |
479 |
old_values = self.Controler.GetProjectProperties() |
|
480 |
dialog = ProjectDialog(self) |
|
481 |
dialog.SetValues(old_values) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
482 |
if dialog.ShowModal() == wx.ID_OK: |
27 | 483 |
new_values = dialog.GetValues() |
484 |
new_values["creationDateTime"] = old_values["creationDateTime"] |
|
145 | 485 |
if new_values != old_values: |
486 |
self.Controler.SetProjectProperties(None, new_values) |
|
487 |
self.RefreshTitle() |
|
488 |
self.RefreshFileMenu() |
|
489 |
self.RefreshEditMenu() |
|
490 |
self.RefreshProjectTree() |
|
491 |
for i in xrange(self.GetPageCount()): |
|
492 |
editor = self.GetPage(i) |
|
493 |
editor.RefreshScaling() |
|
27 | 494 |
dialog.Destroy() |
495 |
||
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
496 |
def OnCloseFrame(self, event): |
107 | 497 |
if not self.ModeSolo and getattr(self, "_onclose", None) is not None: |
121 | 498 |
self.AUIManager.UnInit() |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
499 |
self._onclose() |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
500 |
event.Skip() |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
501 |
elif not self.Controler.ProjectIsSaved(): |
80 | 502 |
dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close Application", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
503 |
answer = dialog.ShowModal() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
504 |
dialog.Destroy() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
505 |
if answer == wx.ID_YES: |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
506 |
self.SaveProject() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
507 |
event.Skip() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
508 |
elif answer == wx.ID_NO: |
80 | 509 |
self.Controler.Reset() |
121 | 510 |
self.AUIManager.UnInit() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
511 |
event.Skip() |
80 | 512 |
else: |
513 |
event.Veto() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
514 |
else: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
515 |
event.Skip() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
516 |
|
163 | 517 |
#------------------------------------------------------------------------------- |
518 |
# Notebook Unified Functions |
|
519 |
#------------------------------------------------------------------------------- |
|
520 |
||
521 |
def GetPageCount(self): |
|
522 |
if wx.VERSION >= (2, 8, 0): |
|
523 |
notebook = self.GetNotebook() |
|
524 |
if notebook is not None: |
|
525 |
return notebook.GetPageCount() |
|
526 |
else: |
|
527 |
return 0 |
|
528 |
else: |
|
529 |
return self.TabsOpened.GetPageCount() |
|
530 |
||
531 |
def GetPage(self, idx): |
|
532 |
if wx.VERSION >= (2, 8, 0): |
|
533 |
notebook = self.GetNotebook() |
|
534 |
if notebook is not None: |
|
535 |
return notebook.GetPage(idx).GetViewer() |
|
536 |
else: |
|
537 |
return None |
|
538 |
else: |
|
539 |
return self.TabsOpened.GetPage(idx) |
|
540 |
||
541 |
def GetPageSelection(self): |
|
542 |
if wx.VERSION >= (2, 8, 0): |
|
543 |
notebook = self.GetNotebook() |
|
544 |
if notebook is not None: |
|
545 |
return notebook.GetSelection() |
|
546 |
else: |
|
547 |
return -1 |
|
548 |
else: |
|
549 |
return self.TabsOpened.GetSelection() |
|
550 |
||
551 |
def SetPageSelection(self, idx): |
|
552 |
if wx.VERSION >= (2, 8, 0): |
|
553 |
notebook = self.GetNotebook() |
|
554 |
if notebook is not None: |
|
555 |
notebook.SetSelection(idx) |
|
556 |
else: |
|
557 |
self.TabsOpened.SetSelection(idx) |
|
558 |
||
559 |
def DeletePage(self, idx): |
|
560 |
if wx.VERSION >= (2, 8, 0): |
|
561 |
notebook = self.GetNotebook() |
|
562 |
if notebook is not None: |
|
563 |
notebook.DeletePage(idx) |
|
564 |
else: |
|
565 |
self.TabsOpened.DeletePage(idx) |
|
566 |
||
567 |
def DeleteAllPages(self): |
|
568 |
if wx.VERSION >= (2, 8, 0): |
|
569 |
notebook = self.GetNotebook() |
|
570 |
if notebook is not None: |
|
571 |
for idx in xrange(notebook.GetPageCount()): |
|
572 |
notebook.DeletePage(0) |
|
573 |
else: |
|
574 |
self.TabsOpened.DeleteAllPages() |
|
575 |
||
576 |
def SetPageText(self, idx, text): |
|
577 |
if wx.VERSION >= (2, 8, 0): |
|
578 |
notebook = self.GetNotebook() |
|
579 |
if notebook is not None: |
|
580 |
return notebook.SetPageText(idx, text) |
|
581 |
else: |
|
582 |
return self.TabsOpened.SetPageText(idx, text) |
|
583 |
||
584 |
def GetPageText(self, idx): |
|
585 |
if wx.VERSION >= (2, 8, 0): |
|
586 |
notebook = self.GetNotebook() |
|
587 |
if notebook is not None: |
|
588 |
return notebook.GetPageText(idx) |
|
589 |
else: |
|
590 |
return "" |
|
591 |
else: |
|
592 |
return self.TabsOpened.GetPageText(idx) |
|
593 |
||
594 |
||
595 |
#------------------------------------------------------------------------------- |
|
596 |
# File Menu Functions |
|
597 |
#------------------------------------------------------------------------------- |
|
598 |
||
599 |
def RefreshFileMenu(self): |
|
600 |
if self.FileMenu: |
|
601 |
if self.Controler.HasOpenedProject(): |
|
602 |
if self.GetPageCount() > 0: |
|
603 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS2, True) |
|
604 |
else: |
|
605 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS2, False) |
|
606 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS3, True) |
|
607 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS5, True) |
|
608 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS6, True) |
|
609 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS7, True) |
|
610 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS9, True) |
|
611 |
else: |
|
612 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS2, False) |
|
613 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS3, False) |
|
614 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS5, False) |
|
615 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS6, False) |
|
616 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS7, False) |
|
617 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS9, False) |
|
618 |
||
0 | 619 |
def OnNewProjectMenu(self, event): |
620 |
dialog = ProjectDialog(self) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
621 |
if dialog.ShowModal() == wx.ID_OK: |
145 | 622 |
properties = dialog.GetValues() |
623 |
self.Controler.CreateNewProject(properties) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
624 |
self.RefreshTitle() |
0 | 625 |
self.RefreshFileMenu() |
626 |
self.RefreshEditMenu() |
|
627 |
self.RefreshProjectTree() |
|
628 |
event.Skip() |
|
629 |
||
630 |
def OnOpenProjectMenu(self, event): |
|
144 | 631 |
if not self.Controler.ProjectIsSaved(): |
632 |
dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close Application", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) |
|
633 |
answer = dialog.ShowModal() |
|
634 |
dialog.Destroy() |
|
635 |
if answer == wx.ID_YES: |
|
636 |
self.SaveProject() |
|
637 |
elif answer == wx.ID_CANCEL: |
|
638 |
return |
|
0 | 639 |
filepath = self.Controler.GetFilePath() |
640 |
if filepath != "": |
|
641 |
directory = os.path.dirname(filepath) |
|
642 |
else: |
|
643 |
directory = os.getcwd() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
644 |
dialog = wx.FileDialog(self, "Choose a file", directory, "", "PLCOpen files (*.xml)|*.xml|All files|*.*", wx.OPEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
645 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 646 |
filepath = dialog.GetPath() |
647 |
if os.path.isfile(filepath): |
|
144 | 648 |
self.DeleteAllPages() |
649 |
self.VariablePanelIndexer.RemoveAllPanels() |
|
0 | 650 |
self.Controler.OpenXMLFile(filepath) |
651 |
self.RefreshProjectTree() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
652 |
self.RefreshTitle() |
0 | 653 |
self.RefreshFileMenu() |
654 |
self.RefreshEditMenu() |
|
655 |
self.RefreshToolBar() |
|
656 |
dialog.Destroy() |
|
657 |
event.Skip() |
|
658 |
||
659 |
def OnCloseTabMenu(self, event): |
|
121 | 660 |
selected = self.GetPageSelection() |
0 | 661 |
if selected >= 0: |
121 | 662 |
tagname = self.GetPage(selected).GetTagName() |
663 |
self.DeletePage(selected) |
|
664 |
self.VariablePanelIndexer.RemoveVariablePanel(tagname) |
|
665 |
if self.GetPageCount() > 0: |
|
666 |
new_index = min(selected, self.GetPageCount() - 1) |
|
667 |
tagname = self.GetPage(new_index).GetTagName() |
|
668 |
self.SetPageSelection(new_index) |
|
669 |
self.VariablePanelIndexer.ChangeVariablePanel(tagname) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
670 |
self.RefreshTitle() |
0 | 671 |
self.RefreshFileMenu() |
672 |
self.RefreshEditMenu() |
|
673 |
self.RefreshToolBar() |
|
674 |
event.Skip() |
|
675 |
||
676 |
def OnCloseProjectMenu(self, event): |
|
144 | 677 |
if not self.Controler.ProjectIsSaved(): |
678 |
dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close Application", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) |
|
679 |
answer = dialog.ShowModal() |
|
680 |
dialog.Destroy() |
|
681 |
if answer == wx.ID_YES: |
|
682 |
self.SaveProject() |
|
683 |
elif answer == wx.ID_CANCEL: |
|
684 |
return |
|
121 | 685 |
self.DeleteAllPages() |
686 |
self.VariablePanelIndexer.RemoveAllPanels() |
|
0 | 687 |
self.ProjectTree.DeleteAllItems() |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
688 |
self.Controler.Reset() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
689 |
self.RefreshTitle() |
0 | 690 |
self.RefreshFileMenu() |
691 |
self.RefreshEditMenu() |
|
692 |
self.RefreshToolBar() |
|
693 |
event.Skip() |
|
694 |
||
695 |
def OnSaveProjectMenu(self, event): |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
696 |
if not self.ModeSolo and getattr(self, "_onsave", None) != None: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
697 |
self._onsave() |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
698 |
else: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
699 |
self.SaveProject() |
0 | 700 |
event.Skip() |
701 |
||
702 |
def OnSaveProjectAsMenu(self, event): |
|
703 |
self.SaveProjectAs() |
|
704 |
event.Skip() |
|
705 |
||
706 |
def OnGenerateProgramMenu(self, event): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
707 |
dialog = wx.FileDialog(self, "Choose a file", os.getcwd(), self.Controler.GetProgramFilePath(), "ST files (*.st)|*.st|All files|*.*", wx.SAVE|wx.CHANGE_DIR) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
708 |
if dialog.ShowModal() == wx.ID_OK: |
4
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
709 |
filepath = dialog.GetPath() |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
710 |
if os.path.isdir(os.path.dirname(filepath)): |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
711 |
result = self.Controler.GenerateProgram(filepath) |
171 | 712 |
if result is not None: |
713 |
message = wx.MessageDialog(self, "Can't generate program to file %s :\n%s"%(filepath, result), "Error", wx.OK|wx.ICON_ERROR) |
|
4
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
714 |
message.ShowModal() |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
715 |
message.Destroy() |
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
65
diff
changeset
|
716 |
else: |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
65
diff
changeset
|
717 |
message = wx.MessageDialog(self, "Program was successfully generated!", "Done", wx.OK|wx.ICON_INFORMATION) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
65
diff
changeset
|
718 |
message.ShowModal() |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
65
diff
changeset
|
719 |
message.Destroy() |
4
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
720 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
721 |
message = wx.MessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR) |
4
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
722 |
message.ShowModal() |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
723 |
message.Destroy() |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
724 |
dialog.Destroy() |
0 | 725 |
event.Skip() |
726 |
||
727 |
def SaveProject(self): |
|
728 |
result = self.Controler.SaveXMLFile() |
|
729 |
if not result: |
|
730 |
self.SaveProjectAs() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
731 |
else: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
732 |
self.RefreshTitle() |
0 | 733 |
|
734 |
def SaveProjectAs(self): |
|
735 |
filepath = self.Controler.GetFilePath() |
|
736 |
if filepath != "": |
|
737 |
directory, filename = os.path.split(filepath) |
|
738 |
else: |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
739 |
directory, filename = os.getcwd(), "%(projectName)s.xml"%self.Controler.GetProjectProperties() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
740 |
dialog = wx.FileDialog(self, "Choose a file", directory, filename, "PLCOpen files (*.xml)|*.xml|All files|*.*", wx.SAVE|wx.OVERWRITE_PROMPT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
741 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 742 |
filepath = dialog.GetPath() |
743 |
if os.path.isdir(os.path.dirname(filepath)): |
|
744 |
result = self.Controler.SaveXMLFile(filepath) |
|
745 |
if not result: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
746 |
message = wx.MessageDialog(self, "Can't save project to file %s!"%filepath, "Error", wx.OK|wx.ICON_ERROR) |
0 | 747 |
message.ShowModal() |
748 |
message.Destroy() |
|
749 |
else: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
750 |
message = wx.MessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR) |
0 | 751 |
message.ShowModal() |
752 |
message.Destroy() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
753 |
self.RefreshTitle() |
0 | 754 |
dialog.Destroy() |
755 |
||
27 | 756 |
def OnPropertiesMenu(self, event): |
757 |
self.ShowProperties() |
|
758 |
event.Skip() |
|
759 |
||
0 | 760 |
def OnQuitMenu(self, event): |
761 |
self.Close() |
|
762 |
event.Skip() |
|
763 |
||
163 | 764 |
|
765 |
#------------------------------------------------------------------------------- |
|
766 |
# Edit Project Menu Functions |
|
767 |
#------------------------------------------------------------------------------- |
|
768 |
||
769 |
def RefreshEditMenu(self): |
|
770 |
if self.EditMenu: |
|
771 |
if self.Controler.HasOpenedProject(): |
|
772 |
undo, redo = self.Controler.GetBufferState() |
|
773 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS1, undo) |
|
774 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS2, redo) |
|
775 |
else: |
|
776 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS1, False) |
|
777 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS2, False) |
|
778 |
if self.Controler.HasOpenedProject(): |
|
779 |
if self.GetPageCount() > 0: |
|
780 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS0, True) |
|
781 |
else: |
|
782 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS0, False) |
|
783 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS8, True) |
|
784 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS14, True) |
|
785 |
else: |
|
786 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS0, False) |
|
787 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS8, False) |
|
788 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS14, False) |
|
789 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS4, True) |
|
790 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS5, True) |
|
791 |
if self.CopyBuffer is not None: |
|
792 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS6, True) |
|
793 |
else: |
|
794 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS6, False) |
|
795 |
||
796 |
def OnRefreshMenu(self, event): |
|
121 | 797 |
selected = self.GetPageSelection() |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
798 |
if selected != -1: |
121 | 799 |
window = self.GetPage(selected) |
163 | 800 |
window.RefreshView() |
801 |
self.VariablePanelIndexer.RefreshVariablePanel(window.GetTagName()) |
|
802 |
event.Skip() |
|
803 |
||
804 |
def OnUndoMenu(self, event): |
|
805 |
self.Controler.LoadPrevious() |
|
806 |
idxs = range(self.GetPageCount()) |
|
807 |
idxs.reverse() |
|
808 |
for idx in idxs: |
|
809 |
tagname = self.GetPage(idx).GetTagName() |
|
810 |
if self.Controler.GetEditedElement(tagname) is None: |
|
811 |
self.VariablePanelIndexer.RemoveVariablePanel(tagname) |
|
812 |
self.DeletePage(idx) |
|
813 |
selected = self.GetPageSelection() |
|
814 |
if selected != -1: |
|
815 |
window = self.GetPage(selected) |
|
816 |
window.RefreshView() |
|
817 |
self.VariablePanelIndexer.RefreshVariablePanel(window.GetTagName()) |
|
818 |
self.RefreshTitle() |
|
819 |
self.RefreshEditMenu() |
|
820 |
self.RefreshProjectTree() |
|
821 |
event.Skip() |
|
822 |
||
823 |
def OnRedoMenu(self, event): |
|
824 |
self.Controler.LoadNext() |
|
825 |
idxs = range(self.GetPageCount()) |
|
826 |
idxs.reverse() |
|
827 |
for idx in idxs: |
|
828 |
tagname = self.GetPage(idx).GetTagName() |
|
829 |
if self.Controler.GetEditedElement(tagname) is None: |
|
830 |
self.VariablePanelIndexer.RemoveVariablePanel(tagname) |
|
831 |
self.DeletePage(idx) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
832 |
selected = self.GetPageSelection() |
0 | 833 |
if selected != -1: |
163 | 834 |
window = self.GetPage(selected) |
835 |
window.RefreshView() |
|
836 |
self.VariablePanelIndexer.RefreshVariablePanel(window.GetTagName()) |
|
837 |
self.RefreshTitle() |
|
838 |
self.RefreshEditMenu() |
|
839 |
self.RefreshProjectTree() |
|
840 |
event.Skip() |
|
841 |
||
842 |
def OnCutMenu(self, event): |
|
121 | 843 |
selected = self.GetPageSelection() |
0 | 844 |
if selected != -1: |
163 | 845 |
try: |
846 |
self.GetPage(selected).Cut() |
|
847 |
except: |
|
848 |
pass |
|
849 |
event.Skip() |
|
850 |
||
851 |
def OnCopyMenu(self, event): |
|
121 | 852 |
selected = self.GetPageSelection() |
0 | 853 |
if selected != -1: |
163 | 854 |
try: |
855 |
self.GetPage(selected).Copy() |
|
856 |
except: |
|
857 |
pass |
|
858 |
event.Skip() |
|
859 |
||
860 |
def OnPasteMenu(self, event): |
|
121 | 861 |
selected = self.GetPageSelection() |
0 | 862 |
if selected != -1: |
163 | 863 |
try: |
864 |
self.GetPage(selected).Paste() |
|
865 |
except: |
|
866 |
pass |
|
867 |
event.Skip() |
|
868 |
||
869 |
def OnDeleteMenu(self, event): |
|
870 |
window = self.FindFocus() |
|
871 |
if window == self.ProjectTree: |
|
872 |
selected = self.ProjectTree.GetSelection() |
|
873 |
if selected.IsOk(): |
|
874 |
type = self.ProjectTree.GetPyData(selected) |
|
875 |
tagname = "" |
|
876 |
if type == ITEM_DATATYPE: |
|
877 |
name = self.ProjectTree.GetItemText(selected) |
|
878 |
if not self.Controler.DataTypeIsUsed(name): |
|
879 |
self.Controler.ProjectRemoveDataType(name) |
|
880 |
tagname = self.Controler.ComputeDataTypeName(name) |
|
881 |
else: |
|
882 |
message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR) |
|
883 |
message.ShowModal() |
|
884 |
message.Destroy() |
|
885 |
elif type == ITEM_POU: |
|
886 |
name = self.ProjectTree.GetItemText(selected) |
|
887 |
if not self.Controler.DataTypeIsUsed(name): |
|
888 |
self.Controler.ProjectRemoveDataType(name) |
|
889 |
tagname = self.Controler.ComputeDataTypeName(name) |
|
890 |
else: |
|
891 |
message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR) |
|
892 |
message.ShowModal() |
|
893 |
message.Destroy() |
|
894 |
elif type in [ITEM_TRANSITION, ITEM_ACTION]: |
|
895 |
item = self.ProjectTree.GetItemParent(selected) |
|
896 |
item_type = self.ProjectTree.GetPyData(item) |
|
897 |
while item_type != ITEM_POU: |
|
898 |
item = self.ProjectTree.GetItemParent(item) |
|
899 |
item_type = self.ProjectTree.GetPyData(item) |
|
900 |
pou_name = self.ProjectTree.GetItemText(item) |
|
901 |
if type == ITEM_TRANSITION: |
|
902 |
transition = self.ProjectTree.GetItemText(selected) |
|
903 |
self.Controler.ProjectRemovePouTransition(pou_name, transition) |
|
904 |
tagname = self.Controler.ComputePouTransitionName(pou_name, transition) |
|
905 |
elif type == ITEM_ACTION: |
|
906 |
action = self.ProjectTree.GetItemText(selected) |
|
907 |
self.Controler.ProjectRemovePouAction(pou_name, action) |
|
908 |
tagname = self.Controler.ComputePouActionName(pou_name, action) |
|
909 |
elif type == ITEM_CONFIGURATION: |
|
910 |
name = self.ProjectTree.GetItemText(selected) |
|
911 |
self.Controler.ProjectRemoveConfiguration(name) |
|
912 |
tagname = self.Controler.ComputeConfigurationName(name) |
|
913 |
elif type == ITEM_RESOURCE: |
|
914 |
resource = self.ProjectTree.GetItemText(selected) |
|
915 |
item = self.ProjectTree.GetItemParent(selected) |
|
916 |
item_type = self.ProjectTree.GetPyData(item) |
|
917 |
while item_type != ITEM_CONFIGURATION: |
|
918 |
item = self.ProjectTree.GetItemParent(item) |
|
919 |
item_type = self.ProjectTree.GetPyData(item) |
|
920 |
config_name = self.ProjectTree.GetItemText(item) |
|
921 |
self.Controler.ProjectRemoveConfigurationResource(config_name, resource) |
|
922 |
tagname = self.Controler.ComputeConfigurationResourceName(config_name, selected) |
|
923 |
idx = self.IsOpened(tagname) |
|
924 |
if idx is not None: |
|
925 |
self.VariablePanelIndexer.RemoveVariablePanel(tagname) |
|
926 |
self.DeletePage(idx) |
|
927 |
self.RefreshTitle() |
|
928 |
self.RefreshEditMenu() |
|
929 |
self.RefreshProjectTree() |
|
930 |
self.RefreshToolBar() |
|
931 |
elif isinstance(window, (Viewer, TextViewer)): |
|
932 |
event = wx.KeyEvent(wx.EVT_CHAR._getEvtType()) |
|
933 |
event.m_keyCode = wx.WXK_DELETE |
|
934 |
window.ProcessEvent(event) |
|
935 |
event.Skip() |
|
936 |
||
937 |
||
938 |
#------------------------------------------------------------------------------- |
|
939 |
# Project Editor Panels Management Functions |
|
940 |
#------------------------------------------------------------------------------- |
|
941 |
||
0 | 942 |
def OnPouSelectedChanged(self, event): |
121 | 943 |
if wx.VERSION < (2, 8, 0) or event.GetActive(): |
944 |
old_selected = self.GetPageSelection() |
|
945 |
if old_selected >= 0: |
|
946 |
self.GetPage(old_selected).ResetBuffer() |
|
947 |
if wx.VERSION >= (2, 8, 0): |
|
948 |
window = event.GetEventObject().GetViewer() |
|
949 |
else: |
|
950 |
selected = event.GetSelection() |
|
951 |
if selected >= 0: |
|
952 |
window = self.GetPage(selected) |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
953 |
else: |
121 | 954 |
window = None |
955 |
if window: |
|
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
956 |
if self.ProjectTree: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
957 |
root = self.ProjectTree.GetRootItem() |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
958 |
words = window.GetTagName().split("::") |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
959 |
if words[0] == "P": |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
960 |
self.SelectProjectTreeItem(root, [(words[1], ITEM_POU)]) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
961 |
elif words[0] == "T": |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
962 |
self.SelectProjectTreeItem(root, [(words[1], ITEM_POU), (words[2], ITEM_TRANSITION)]) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
963 |
elif words[0] == "A": |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
964 |
self.SelectProjectTreeItem(root, [(words[1], ITEM_POU), (words[2], ITEM_ACTION)]) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
965 |
elif words[0] == "C": |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
966 |
self.SelectProjectTreeItem(root, [(words[1], ITEM_CONFIGURATION)]) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
967 |
elif words[0] == "R": |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
968 |
self.SelectProjectTreeItem(root, [(words[1], ITEM_CONFIGURATION), (words[2], ITEM_RESOURCE)]) |
121 | 969 |
window.RefreshView() |
970 |
self.VariablePanelIndexer.ChangeVariablePanel(window.GetTagName()) |
|
971 |
self.RefreshFileMenu() |
|
972 |
self.RefreshEditMenu() |
|
973 |
self.RefreshToolBar() |
|
0 | 974 |
event.Skip() |
975 |
||
163 | 976 |
def RefreshEditor(self, variablepanel = True): |
977 |
selected = self.GetPageSelection() |
|
978 |
if selected != -1: |
|
979 |
window = self.GetPage(selected) |
|
980 |
window.RefreshView() |
|
981 |
if variablepanel: |
|
982 |
self.RefreshVariablePanel(window.GetTagName()) |
|
983 |
||
984 |
def RefreshVariablePanel(self, tagname): |
|
985 |
self.VariablePanelIndexer.RefreshVariablePanel(tagname) |
|
986 |
||
987 |
def RefreshEditorNames(self, old_tagname, new_tagname): |
|
988 |
for i in xrange(self.GetPageCount()): |
|
989 |
editor = self.GetPage(i) |
|
990 |
if editor.GetTagName() == old_tagname: |
|
991 |
editor.SetTagName(new_tagname) |
|
992 |
self.VariablePanelIndexer.UpdateVariablePanelTagName(old_tagname, new_tagname) |
|
993 |
||
994 |
def IsOpened(self, tagname): |
|
995 |
for idx in xrange(self.GetPageCount()): |
|
996 |
if self.GetPage(idx).IsViewing(tagname): |
|
997 |
return idx |
|
998 |
return None |
|
999 |
||
1000 |
def RefreshPageTitles(self): |
|
1001 |
for idx in xrange(self.GetPageCount()): |
|
1002 |
window = self.GetPage(idx) |
|
1003 |
words = window.GetTagName().split("::") |
|
1004 |
self.SetPageText(idx, "-".join(words[1:])) |
|
1005 |
||
1006 |
||
1007 |
#------------------------------------------------------------------------------- |
|
1008 |
# Project Tree Management Functions |
|
1009 |
#------------------------------------------------------------------------------- |
|
1010 |
||
1011 |
def RefreshProjectTree(self): |
|
1012 |
infos = self.Controler.GetProjectInfos() |
|
1013 |
root = self.ProjectTree.GetRootItem() |
|
1014 |
if not root.IsOk(): |
|
1015 |
root = self.ProjectTree.AddRoot(infos["name"]) |
|
1016 |
self.GenerateTreeBranch(root, infos) |
|
1017 |
self.ProjectTree.Expand(self.ProjectTree.GetRootItem()) |
|
1018 |
||
1019 |
def GenerateTreeBranch(self, root, infos): |
|
1020 |
to_delete = [] |
|
1021 |
self.ProjectTree.SetItemText(root, infos["name"]) |
|
1022 |
self.ProjectTree.SetPyData(root, infos["type"]) |
|
1023 |
if infos["type"] == ITEM_POU and wx.Platform != '__WXMSW__': |
|
1024 |
self.ProjectTree.SetItemImage(root, LANGUAGES.index(self.Controler.GetPouBodyType(infos["name"]))) |
|
1025 |
if wx.VERSION >= (2, 6, 0): |
|
1026 |
item, root_cookie = self.ProjectTree.GetFirstChild(root) |
|
1027 |
else: |
|
1028 |
item, root_cookie = self.ProjectTree.GetFirstChild(root, 0) |
|
1029 |
for values in infos["values"]: |
|
1030 |
if not item.IsOk(): |
|
1031 |
item = self.ProjectTree.AppendItem(root, "") |
|
1032 |
if wx.Platform != '__WXMSW__': |
|
1033 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
|
1034 |
self.GenerateTreeBranch(item, values) |
|
1035 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
|
1036 |
while item.IsOk(): |
|
1037 |
to_delete.append(item) |
|
1038 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
|
1039 |
for item in to_delete: |
|
1040 |
self.ProjectTree.Delete(item) |
|
1041 |
||
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1042 |
def SelectProjectTreeItem(self, root, items): |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1043 |
found = False |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1044 |
if self.ProjectTree: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1045 |
if wx.VERSION >= (2, 6, 0): |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1046 |
item, root_cookie = self.ProjectTree.GetFirstChild(root) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1047 |
else: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1048 |
item, root_cookie = self.ProjectTree.GetFirstChild(root, 0) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1049 |
while item.IsOk() and not found: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1050 |
if (self.ProjectTree.GetItemText(item), self.ProjectTree.GetPyData(item)) == items[0]: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1051 |
if len(items) == 1: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1052 |
self.SelectedItem = item |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1053 |
self.ProjectTree.SelectItem(item) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1054 |
wx.CallAfter(self.ResetSelectedItem) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1055 |
return True |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1056 |
else: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1057 |
found = self.SelectProjectTreeItem(item, items[1:]) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1058 |
else: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1059 |
found = self.SelectProjectTreeItem(item, items) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1060 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1061 |
return found |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1062 |
|
7 | 1063 |
def OnProjectTreeBeginDrag(self, event): |
131 | 1064 |
if wx.Platform == '__WXMSW__': |
134 | 1065 |
self.SelectedItem = event.GetItem() |
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1066 |
if self.SelectedItem is not None and self.ProjectTree.GetPyData(self.SelectedItem) == ITEM_POU: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1067 |
block_name = self.ProjectTree.GetItemText(self.SelectedItem) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
1068 |
block_type = self.Controler.GetPouType(block_name) |
53 | 1069 |
if block_type != "program": |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1070 |
data = wx.TextDataObject(str((block_name, block_type, ""))) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1071 |
dragSource = wx.DropSource(self.ProjectTree) |
53 | 1072 |
dragSource.SetData(data) |
1073 |
dragSource.DoDragDrop() |
|
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1074 |
self.ResetSelectedItem() |
7 | 1075 |
|
163 | 1076 |
def OnProjectTreeItemBeginEdit(self, event): |
1077 |
selected = event.GetItem() |
|
1078 |
if self.ProjectTree.GetPyData(selected) == ITEM_UNEDITABLE: |
|
1079 |
event.Veto() |
|
1080 |
else: |
|
1081 |
event.Skip() |
|
107 | 1082 |
|
0 | 1083 |
def OnProjectTreeItemEndEdit(self, event): |
6 | 1084 |
message = None |
1085 |
abort = False |
|
0 | 1086 |
new_name = event.GetLabel() |
1087 |
if new_name != "": |
|
6 | 1088 |
if not TestIdentifier(new_name): |
1089 |
message = "\"%s\" is not a valid identifier!"%new_name |
|
1090 |
elif new_name.upper() in IEC_KEYWORDS: |
|
1091 |
message = "\"%s\" is a keyword. It can't be used!"%new_name |
|
1092 |
else: |
|
0 | 1093 |
item = event.GetItem() |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1094 |
old_name = self.ProjectTree.GetItemText(item) |
0 | 1095 |
itemtype = self.ProjectTree.GetPyData(item) |
1096 |
if itemtype == ITEM_PROJECT: |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1097 |
self.Controler.SetProjectProperties(name = new_name) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1098 |
elif itemtype == ITEM_DATATYPE: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1099 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectDataTypeNames() if name != old_name]: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1100 |
message = "\"%s\" data type already exists!"%new_name |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1101 |
abort = True |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1102 |
if not abort: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1103 |
self.Controler.ChangeDataTypeName(old_name, new_name) |
145 | 1104 |
self.RefreshEditorNames(self.Controler.ComputeDataTypeName(old_name), |
1105 |
self.Controler.ComputeDataTypeName(new_name)) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1106 |
self.RefreshPageTitles() |
0 | 1107 |
elif itemtype == ITEM_POU: |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1108 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames() if name != old_name]: |
6 | 1109 |
message = "\"%s\" pou already exists!"%new_name |
1110 |
abort = True |
|
70 | 1111 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables()]: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1112 |
messageDialog = wx.MessageDialog(self, "A variable is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wx.YES_NO|wx.ICON_QUESTION) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1113 |
if messageDialog.ShowModal() == wx.ID_NO: |
6 | 1114 |
abort = True |
1115 |
messageDialog.Destroy() |
|
1116 |
if not abort: |
|
1117 |
self.Controler.ChangePouName(old_name, new_name) |
|
145 | 1118 |
self.RefreshEditorNames(self.Controler.ComputePouName(old_name), |
1119 |
self.Controler.ComputePouName(new_name)) |
|
121 | 1120 |
self.RefreshPageTitles() |
0 | 1121 |
elif itemtype == ITEM_TRANSITION: |
108 | 1122 |
parent = self.ProjectTree.GetItemParent(item) |
107 | 1123 |
parent_type = self.ProjectTree.GetPyData(parent) |
1124 |
while parent_type != ITEM_POU: |
|
1125 |
parent = self.ProjectTree.GetItemParent(parent) |
|
1126 |
parent_type = self.ProjectTree.GetPyData(parent) |
|
1127 |
pou_name = self.ProjectTree.GetItemText(parent) |
|
70 | 1128 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]: |
6 | 1129 |
message = "A pou with \"%s\" as name exists!"%new_name |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1130 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables(pou_name) if name != old_name]: |
6 | 1131 |
message = "A variable with \"%s\" as name already exists in this pou!"%new_name |
1132 |
else: |
|
1133 |
self.Controler.ChangePouTransitionName(pou_name, old_name, new_name) |
|
145 | 1134 |
self.RefreshEditorNames(self.Controler.ComputePouTransitionName(pou_name, old_name), |
1135 |
self.Controler.ComputePouTransitionName(pou_name, new_name)) |
|
121 | 1136 |
self.RefreshPageTitles() |
0 | 1137 |
elif itemtype == ITEM_ACTION: |
108 | 1138 |
parent = self.ProjectTree.GetItemParent(item) |
107 | 1139 |
parent_type = self.ProjectTree.GetPyData(parent) |
1140 |
while parent_type != ITEM_POU: |
|
1141 |
parent = self.ProjectTree.GetItemParent(parent) |
|
1142 |
parent_type = self.ProjectTree.GetPyData(parent) |
|
1143 |
pou_name = self.ProjectTree.GetItemText(parent) |
|
70 | 1144 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]: |
6 | 1145 |
message = "A pou with \"%s\" as name exists!"%new_name |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1146 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables(pou_name) if name != old_name]: |
6 | 1147 |
message = "A variable with \"%s\" as name already exists in this pou!"%new_name |
1148 |
else: |
|
1149 |
self.Controler.ChangePouActionName(pou_name, old_name, new_name) |
|
145 | 1150 |
self.RefreshEditorNames(self.Controler.ComputePouActionName(pou_name, old_name), |
1151 |
self.Controler.ComputePouActionName(pou_name, new_name)) |
|
121 | 1152 |
self.RefreshPageTitles() |
107 | 1153 |
elif itemtype == ITEM_CONFIGURATION: |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1154 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectConfigNames() if name != old_name]: |
107 | 1155 |
message = "\"%s\" config already exists!"%new_name |
1156 |
abort = True |
|
1157 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]: |
|
1158 |
messageDialog = wx.MessageDialog(self, "A pou is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wx.YES_NO|wx.ICON_QUESTION) |
|
1159 |
if messageDialog.ShowModal() == wx.ID_NO: |
|
1160 |
abort = True |
|
1161 |
messageDialog.Destroy() |
|
1162 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables()]: |
|
1163 |
messageDialog = wx.MessageDialog(self, "A variable is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wx.YES_NO|wx.ICON_QUESTION) |
|
1164 |
if messageDialog.ShowModal() == wx.ID_NO: |
|
1165 |
abort = True |
|
1166 |
messageDialog.Destroy() |
|
1167 |
if not abort: |
|
1168 |
self.Controler.ChangeConfigurationName(old_name, new_name) |
|
145 | 1169 |
self.RefreshEditorNames(self.Controler.ComputeConfigurationName(old_name), |
1170 |
self.Controler.ComputeConfigurationName(new_name)) |
|
121 | 1171 |
self.RefreshPageTitles() |
107 | 1172 |
elif itemtype == ITEM_RESOURCE: |
108 | 1173 |
parent = self.ProjectTree.GetItemParent(item) |
107 | 1174 |
parent_type = self.ProjectTree.GetPyData(parent) |
1175 |
while parent_type != ITEM_CONFIGURATION: |
|
1176 |
parent = self.ProjectTree.GetItemParent(parent) |
|
1177 |
parent_type = self.ProjectTree.GetPyData(parent) |
|
1178 |
config_name = self.ProjectTree.GetItemText(parent) |
|
1179 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectConfigNames()]: |
|
1180 |
message = "\"%s\" config already exists!"%new_name |
|
1181 |
abort = True |
|
1182 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]: |
|
1183 |
messageDialog = wx.MessageDialog(self, "A pou is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wx.YES_NO|wx.ICON_QUESTION) |
|
1184 |
if messageDialog.ShowModal() == wx.ID_NO: |
|
1185 |
abort = True |
|
1186 |
messageDialog.Destroy() |
|
1187 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables()]: |
|
1188 |
messageDialog = wx.MessageDialog(self, "A variable is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wx.YES_NO|wx.ICON_QUESTION) |
|
1189 |
if messageDialog.ShowModal() == wx.ID_NO: |
|
1190 |
abort = True |
|
1191 |
messageDialog.Destroy() |
|
1192 |
if not abort: |
|
1193 |
self.Controler.ChangeConfigurationResourceName(config_name, old_name, new_name) |
|
145 | 1194 |
self.RefreshEditorNames(self.Controler.ComputeConfigurationResourceName(config_name, old_name), |
1195 |
self.Controler.ComputeConfigurationResourceName(config_name, new_name)) |
|
121 | 1196 |
self.RefreshPageTitles() |
6 | 1197 |
if message or abort: |
1198 |
if message: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1199 |
messageDialog = wx.MessageDialog(self, message, "Error", wx.OK|wx.ICON_ERROR) |
6 | 1200 |
messageDialog.ShowModal() |
1201 |
messageDialog.Destroy() |
|
0 | 1202 |
item = event.GetItem() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1203 |
wx.CallAfter(self.ProjectTree.EditLabel, item) |
0 | 1204 |
event.Veto() |
6 | 1205 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1206 |
wx.CallAfter(self.RefreshProjectTree) |
121 | 1207 |
selected = self.GetPageSelection() |
1208 |
if selected != -1: |
|
1209 |
self.GetPage(selected).RefreshView() |
|
6 | 1210 |
event.Skip() |
0 | 1211 |
|
1212 |
def OnProjectTreeItemActivated(self, event): |
|
1213 |
selected = event.GetItem() |
|
1214 |
if self.ProjectTree.IsExpanded(selected): |
|
1215 |
self.ProjectTree.Collapse(selected) |
|
1216 |
else: |
|
1217 |
self.ProjectTree.Expand(selected) |
|
1218 |
name = self.ProjectTree.GetItemText(selected) |
|
1219 |
data = self.ProjectTree.GetPyData(selected) |
|
1220 |
if name == "Properties": |
|
27 | 1221 |
self.ShowProperties() |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1222 |
if data == ITEM_DATATYPE: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1223 |
self.EditProjectElement(data, self.Controler.ComputeDataTypeName(name)) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1224 |
elif data == ITEM_POU: |
121 | 1225 |
self.EditProjectElement(data, self.Controler.ComputePouName(name)) |
1226 |
elif data == ITEM_CONFIGURATION: |
|
1227 |
self.EditProjectElement(data, self.Controler.ComputeConfigurationName(name)) |
|
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1228 |
elif data == ITEM_RESOURCE: |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1229 |
item = self.ProjectTree.GetItemParent(selected) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1230 |
item_type = self.ProjectTree.GetPyData(item) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1231 |
while item_type != ITEM_CONFIGURATION: |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1232 |
item = self.ProjectTree.GetItemParent(item) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1233 |
item_type = self.ProjectTree.GetPyData(item) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1234 |
config_name = self.ProjectTree.GetItemText(item) |
121 | 1235 |
self.EditProjectElement(data, self.Controler.ComputeConfigurationResourceName(config_name, name)) |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1236 |
elif data in [ITEM_TRANSITION, ITEM_ACTION]: |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1237 |
item = self.ProjectTree.GetItemParent(selected) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1238 |
item_type = self.ProjectTree.GetPyData(item) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1239 |
while item_type != ITEM_POU: |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1240 |
item = self.ProjectTree.GetItemParent(item) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1241 |
item_type = self.ProjectTree.GetPyData(item) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1242 |
pou_name = self.ProjectTree.GetItemText(item) |
121 | 1243 |
if data == ITEM_TRANSITION: |
1244 |
tagname = self.Controler.ComputePouTransitionName(pou_name, name) |
|
1245 |
elif data == ITEM_ACTION: |
|
1246 |
tagname = self.Controler.ComputePouActionName(pou_name, name) |
|
1247 |
self.EditProjectElement(data, tagname) |
|
129 | 1248 |
event.Skip() |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1249 |
|
131 | 1250 |
def ProjectTreeItemSelect(self, select_item): |
1251 |
name = self.ProjectTree.GetItemText(select_item) |
|
1252 |
data = self.ProjectTree.GetPyData(select_item) |
|
1253 |
if data == ITEM_DATATYPE: |
|
1254 |
self.EditProjectElement(data, self.Controler.ComputeDataTypeName(name), True) |
|
1255 |
elif data == ITEM_POU: |
|
1256 |
self.EditProjectElement(data, self.Controler.ComputePouName(name), True) |
|
1257 |
elif data == ITEM_CONFIGURATION: |
|
1258 |
self.EditProjectElement(data, self.Controler.ComputeConfigurationName(name), True) |
|
1259 |
elif data == ITEM_RESOURCE: |
|
1260 |
item = self.ProjectTree.GetItemParent(select_item) |
|
1261 |
item_type = self.ProjectTree.GetPyData(item) |
|
1262 |
while item_type != ITEM_CONFIGURATION: |
|
1263 |
item = self.ProjectTree.GetItemParent(item) |
|
1264 |
item_type = self.ProjectTree.GetPyData(item) |
|
1265 |
config_name = self.ProjectTree.GetItemText(item) |
|
1266 |
self.EditProjectElement(data, self.Controler.ComputeConfigurationResourceName(config_name, name), True) |
|
1267 |
elif data in [ITEM_TRANSITION, ITEM_ACTION]: |
|
135 | 1268 |
item = self.ProjectTree.GetItemParent(select_item) |
131 | 1269 |
item_type = self.ProjectTree.GetPyData(item) |
1270 |
while item_type != ITEM_POU: |
|
1271 |
item = self.ProjectTree.GetItemParent(item) |
|
1272 |
item_type = self.ProjectTree.GetPyData(item) |
|
1273 |
pou_name = self.ProjectTree.GetItemText(item) |
|
1274 |
if data == ITEM_TRANSITION: |
|
1275 |
tagname = self.Controler.ComputePouTransitionName(pou_name, name) |
|
1276 |
elif data == ITEM_ACTION: |
|
1277 |
tagname = self.Controler.ComputePouActionName(pou_name, name) |
|
1278 |
self.EditProjectElement(data, tagname, True) |
|
1279 |
||
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1280 |
def OnProjectTreeLeftUp(self, event): |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1281 |
if self.SelectedItem is not None: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1282 |
self.ProjectTree.SelectItem(self.SelectedItem) |
131 | 1283 |
self.ProjectTreeItemSelect(self.SelectedItem) |
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1284 |
wx.CallAfter(self.ResetSelectedItem) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1285 |
event.Skip() |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1286 |
|
131 | 1287 |
def OnProjectTreeItemSelected(self, event): |
1288 |
self.ProjectTreeItemSelect(event.GetItem()) |
|
1289 |
event.Skip() |
|
1290 |
||
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1291 |
def OnProjectTreeItemChanging(self, event): |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1292 |
if self.ProjectTree.GetPyData(event.GetItem()) != ITEM_UNEDITABLE and self.SelectedItem is None: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1293 |
self.SelectedItem = event.GetItem() |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1294 |
event.Veto() |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1295 |
else: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1296 |
event.Skip() |
121 | 1297 |
|
1298 |
def EditProjectElement(self, elementtype, tagname, onlyopened = False): |
|
1299 |
openedidx = self.IsOpened(tagname) |
|
1300 |
if openedidx is not None: |
|
1301 |
old_selected = self.GetPageSelection() |
|
1302 |
if old_selected != openedidx: |
|
1303 |
if old_selected >= 0: |
|
1304 |
self.GetPage(old_selected).ResetBuffer() |
|
1305 |
self.SetPageSelection(openedidx) |
|
1306 |
self.GetPage(openedidx).RefreshView() |
|
1307 |
self.VariablePanelIndexer.ChangeVariablePanel(tagname) |
|
1308 |
self.RefreshPageTitles() |
|
1309 |
self.RefreshFileMenu() |
|
1310 |
self.RefreshEditMenu() |
|
1311 |
self.RefreshToolBar() |
|
1312 |
elif not onlyopened: |
|
1313 |
if wx.VERSION >= (2, 8, 0): |
|
1314 |
if elementtype == ITEM_CONFIGURATION: |
|
1315 |
new_window = MDIConfigurationEditor(self, tagname, self, self.Controler) |
|
1316 |
elif elementtype == ITEM_RESOURCE: |
|
1317 |
new_window = MDIResourceEditor(self, tagname, self, self.Controler) |
|
1318 |
elif elementtype in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]: |
|
1319 |
bodytype = self.Controler.GetEditedElementBodyType(tagname) |
|
1320 |
if bodytype == "FBD": |
|
1321 |
new_window = MDIViewer(self, tagname, self, self.Controler) |
|
145 | 1322 |
new_window.GetViewer().RefreshScaling(False) |
121 | 1323 |
elif bodytype == "LD": |
1324 |
new_window = LD_MDIViewer(self, tagname, self, self.Controler) |
|
145 | 1325 |
new_window.GetViewer().RefreshScaling(False) |
121 | 1326 |
elif bodytype == "SFC": |
1327 |
new_window = SFC_MDIViewer(self, tagname, self, self.Controler) |
|
145 | 1328 |
new_window.GetViewer().RefreshScaling(False) |
121 | 1329 |
else: |
1330 |
new_window = TextMDIViewer(self, tagname, self, self.Controler) |
|
1331 |
viewer = new_window.GetViewer() |
|
1332 |
viewer.SetTextSyntax(elementtype) |
|
1333 |
if bodytype == "IL": |
|
1334 |
viewer.SetKeywords(IL_KEYWORDS) |
|
1335 |
else: |
|
1336 |
viewer.SetKeywords(ST_KEYWORDS) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1337 |
elif elementtype == ITEM_DATATYPE: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1338 |
new_window = MDIDataTypeEditor(self, tagname, self, self.Controler) |
121 | 1339 |
new_window.Bind(wx.EVT_ACTIVATE, self.OnPouSelectedChanged) |
1340 |
new_window.Bind(wx.EVT_CLOSE, self.OnPageClose) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1341 |
new_window.Layout() |
121 | 1342 |
else: |
1343 |
if elementtype == ITEM_CONFIGURATION: |
|
1344 |
new_window = ConfigurationEditor(self.TabsOpened, tagname, self, self.Controler) |
|
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1345 |
self.TabsOpened.AddPage(new_window, "") |
121 | 1346 |
elif elementtype == ITEM_RESOURCE: |
1347 |
new_window = ResourceEditor(self.TabsOpened, tagname, self, self.Controler) |
|
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1348 |
self.TabsOpened.AddPage(new_window, "") |
121 | 1349 |
elif elementtype in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]: |
1350 |
bodytype = self.Controler.GetEditedElementBodyType(tagname) |
|
1351 |
if bodytype == "FBD": |
|
1352 |
new_window = Viewer(self.TabsOpened, tagname, self, self.Controler) |
|
145 | 1353 |
new_window.RefreshScaling(False) |
121 | 1354 |
elif bodytype == "LD": |
1355 |
new_window = LD_Viewer(self.TabsOpened, tagname, self, self.Controler) |
|
145 | 1356 |
new_window.RefreshScaling(False) |
121 | 1357 |
elif bodytype == "SFC": |
1358 |
new_window = SFC_Viewer(self.TabsOpened, tagname, self, self.Controler) |
|
145 | 1359 |
new_window.RefreshScaling(False) |
121 | 1360 |
else: |
1361 |
new_window = TextViewer(self.TabsOpened, tagname, self, self.Controler) |
|
1362 |
new_window.SetTextSyntax(elementtype) |
|
1363 |
if bodytype == "IL": |
|
1364 |
new_window.SetKeywords(IL_KEYWORDS) |
|
1365 |
else: |
|
1366 |
new_window.SetKeywords(ST_KEYWORDS) |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
1367 |
self.TabsOpened.AddPage(new_window, "") |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1368 |
elif elementtype == ITEM_DATATYPE: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1369 |
new_window = DataTypeEditor(self.TabsOpened, tagname, self, self.Controler) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1370 |
self.TabsOpened.AddPage(new_window, "") |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1371 |
if elementtype == ITEM_CONFIGURATION: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1372 |
self.VariablePanelIndexer.AddVariablePanel(tagname, "config") |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1373 |
elif elementtype == ITEM_RESOURCE: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1374 |
self.VariablePanelIndexer.AddVariablePanel(tagname, "resource") |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1375 |
elif elementtype in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]: |
121 | 1376 |
words = tagname.split("::") |
1377 |
self.VariablePanelIndexer.AddVariablePanel(tagname, self.Controler.GetPouType(words[1])) |
|
1378 |
self.VariablePanelIndexer.ChangeVariablePanel(tagname) |
|
1379 |
openedidx = self.IsOpened(tagname) |
|
1380 |
old_selected = self.GetPageSelection() |
|
1381 |
if old_selected != openedidx: |
|
1382 |
if old_selected >= 0: |
|
1383 |
self.GetPage(old_selected).ResetBuffer() |
|
1384 |
for i in xrange(self.GetPageCount()): |
|
1385 |
window = self.GetPage(i) |
|
1386 |
if window.GetTagName() == tagname: |
|
1387 |
self.SetPageSelection(i) |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1388 |
window.RefreshView() |
129 | 1389 |
window.SetFocus() |
121 | 1390 |
self.RefreshPageTitles() |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1391 |
self.RefreshFileMenu() |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1392 |
self.RefreshEditMenu() |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1393 |
self.RefreshToolBar() |
0 | 1394 |
|
1395 |
def OnProjectTreeRightUp(self, event): |
|
159 | 1396 |
if wx.Platform == '__WXMSW__': |
163 | 1397 |
item = event.GetItem() |
1398 |
else: |
|
1399 |
item = self.ProjectTree.GetSelection() |
|
1400 |
name = self.ProjectTree.GetItemText(item) |
|
1401 |
type = self.ProjectTree.GetPyData(item) |
|
1402 |
if type == ITEM_POU: |
|
1403 |
menu = wx.Menu(title='') |
|
0 | 1404 |
if self.Controler.GetPouBodyType(name) == "SFC": |
163 | 1405 |
new_id = wx.NewId() |
1406 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Transition") |
|
1407 |
self.Bind(wx.EVT_MENU, self.GenerateAddTransitionFunction(name), id=new_id) |
|
1408 |
new_id = wx.NewId() |
|
1409 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Action") |
|
1410 |
self.Bind(wx.EVT_MENU, self.GenerateAddActionFunction(name), id=new_id) |
|
1411 |
menu.AppendSeparator() |
|
1412 |
new_id = wx.NewId() |
|
1413 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Delete") |
|
1414 |
self.Bind(wx.EVT_MENU, self.OnRemovePouMenu, id=new_id) |
|
1415 |
self.PopupMenu(menu) |
|
1416 |
elif type == ITEM_CONFIGURATION: |
|
1417 |
menu = wx.Menu(title='') |
|
1418 |
new_id = wx.NewId() |
|
1419 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Resource") |
|
1420 |
self.Bind(wx.EVT_MENU, self.GenerateAddResourceFunction(name), id=new_id) |
|
1421 |
new_id = wx.NewId() |
|
1422 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Delete") |
|
1423 |
self.Bind(wx.EVT_MENU, self.OnRemoveConfigurationMenu, id=new_id) |
|
1424 |
self.PopupMenu(menu) |
|
1425 |
elif type in [ITEM_DATATYPE, ITEM_TRANSITION, ITEM_ACTION, ITEM_RESOURCE]: |
|
1426 |
menu = wx.Menu(title='') |
|
1427 |
new_id = wx.NewId() |
|
1428 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Delete") |
|
1429 |
if type == ITEM_DATATYPE: |
|
1430 |
self.Bind(wx.EVT_MENU, self.OnRemoveDataTypeMenu, id=new_id) |
|
1431 |
elif type == ITEM_TRANSITION: |
|
1432 |
self.Bind(wx.EVT_MENU, self.OnRemoveTransitionMenu, id=new_id) |
|
1433 |
elif type == ITEM_ACTION: |
|
1434 |
self.Bind(wx.EVT_MENU, self.OnRemoveActionMenu, id=new_id) |
|
1435 |
elif type == ITEM_RESOURCE: |
|
1436 |
self.Bind(wx.EVT_MENU, self.OnRemoveResourceMenu, id=new_id) |
|
1437 |
self.PopupMenu(menu) |
|
1438 |
elif type == ITEM_UNEDITABLE: |
|
1439 |
if name == "Data Types": |
|
1440 |
menu = wx.Menu(title='') |
|
1441 |
new_id = wx.NewId() |
|
1442 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add DataType") |
|
1443 |
self.Bind(wx.EVT_MENU, self.OnAddDataTypeMenu, id=new_id) |
|
1444 |
self.PopupMenu(menu) |
|
1445 |
elif name in ["Functions", "Function Blocks", "Programs"]: |
|
1446 |
menu = wx.Menu(title='') |
|
1447 |
new_id = wx.NewId() |
|
1448 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Pou") |
|
1449 |
self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction({"Functions" : "function", "Function Blocks" : "functionBlock", "Programs" : "program"}[name]), id=new_id) |
|
1450 |
self.PopupMenu(menu) |
|
1451 |
elif name == "Configurations": |
|
1452 |
menu = wx.Menu(title='') |
|
1453 |
new_id = wx.NewId() |
|
1454 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Configuration") |
|
1455 |
self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu, id=new_id) |
|
1456 |
self.PopupMenu(menu) |
|
1457 |
elif name == "Transitions": |
|
1458 |
menu = wx.Menu(title='') |
|
1459 |
new_id = wx.NewId() |
|
1460 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Transition") |
|
1461 |
parent = self.ProjectTree.GetItemParent(item) |
|
1462 |
parent_type = self.ProjectTree.GetPyData(parent) |
|
1463 |
while parent_type != ITEM_POU: |
|
1464 |
parent = self.ProjectTree.GetItemParent(parent) |
|
1465 |
parent_type = self.ProjectTree.GetPyData(parent) |
|
1466 |
self.Bind(wx.EVT_MENU, self.GenerateAddTransitionFunction(self.ProjectTree.GetItemText(parent)), id=new_id) |
|
1467 |
self.PopupMenu(menu) |
|
1468 |
elif name == "Actions": |
|
1469 |
menu = wx.Menu(title='') |
|
1470 |
new_id = wx.NewId() |
|
1471 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Action") |
|
1472 |
parent = self.ProjectTree.GetItemParent(item) |
|
1473 |
parent_type = self.ProjectTree.GetPyData(parent) |
|
1474 |
while parent_type != ITEM_POU: |
|
1475 |
parent = self.ProjectTree.GetItemParent(parent) |
|
1476 |
parent_type = self.ProjectTree.GetPyData(parent) |
|
1477 |
self.Bind(wx.EVT_MENU, self.GenerateAddActionFunction(self.ProjectTree.GetItemText(parent)), id=new_id) |
|
1478 |
self.PopupMenu(menu) |
|
1479 |
elif name == "Resources": |
|
1480 |
menu = wx.Menu(title='') |
|
1481 |
new_id = wx.NewId() |
|
1482 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Resource") |
|
1483 |
parent = self.ProjectTree.GetItemParent(item) |
|
1484 |
parent_type = self.ProjectTree.GetPyData(parent) |
|
1485 |
while parent_type != ITEM_CONFIGURATION: |
|
1486 |
parent = self.ProjectTree.GetItemParent(parent) |
|
1487 |
parent_type = self.ProjectTree.GetPyData(parent) |
|
1488 |
self.Bind(wx.EVT_MENU, self.GenerateAddResourceFunction(self.ProjectTree.GetItemText(parent)), id=new_id) |
|
1489 |
self.PopupMenu(menu) |
|
1490 |
event.Skip() |
|
1491 |
||
1492 |
||
1493 |
#------------------------------------------------------------------------------- |
|
1494 |
# ToolBar Management Functions |
|
1495 |
#------------------------------------------------------------------------------- |
|
1496 |
||
6 | 1497 |
def ResetToolBar(self): |
1498 |
for item in self.CurrentToolBar: |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1499 |
if wx.VERSION >= (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1500 |
self.Unbind(wx.EVT_MENU, id=item) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1501 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1502 |
self.Disconnect(id=item, eventType=wx.wxEVT_COMMAND_MENU_SELECTED) |
120 | 1503 |
|
1504 |
if wx.VERSION < (2, 8, 0): |
|
1505 |
ToolBar = self.ToolBar |
|
1506 |
else: |
|
1507 |
ToolBar = self.Panes["ToolBar"] |
|
121 | 1508 |
if ToolBar: |
1509 |
ToolBar.DeleteTool(item) |
|
1510 |
ToolBar.Realize() |
|
1511 |
if wx.VERSION >= (2, 8, 0): |
|
1512 |
self.AUIManager.GetPane("ToolBar").BestSize(ToolBar.GetBestSize()) |
|
1513 |
self.AUIManager.Update() |
|
6 | 1514 |
|
0 | 1515 |
def RefreshToolBar(self): |
121 | 1516 |
selected = self.GetPageSelection() |
1517 |
if selected != -1: |
|
1518 |
language = self.Controler.GetEditedElementBodyType(self.GetPage(selected).GetTagName()) |
|
1519 |
else: |
|
1520 |
language = None |
|
1521 |
if language is not None and language != self.CurrentLanguage: |
|
27 | 1522 |
self.ResetToolBar() |
1523 |
self.CurrentLanguage = language |
|
1524 |
self.CurrentToolBar = [] |
|
120 | 1525 |
if wx.VERSION < (2, 8, 0): |
1526 |
ToolBar = self.ToolBar |
|
1527 |
else: |
|
1528 |
ToolBar = self.Panes["ToolBar"] |
|
121 | 1529 |
if ToolBar: |
1530 |
for radio, modes, id, method, picture, help in ToolBarItems[language]: |
|
1531 |
if modes & self.DrawingMode: |
|
1532 |
if radio or self.DrawingMode == FREEDRAWING_MODE: |
|
1533 |
ToolBar.AddRadioTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), wx.NullBitmap, help) |
|
1534 |
else: |
|
1535 |
ToolBar.AddSimpleTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), help) |
|
1536 |
self.Bind(wx.EVT_TOOL, getattr(self, method), id=id) |
|
1537 |
self.CurrentToolBar.append(id) |
|
1538 |
ToolBar.Realize() |
|
1539 |
if wx.VERSION >= (2, 8, 0): |
|
1540 |
self.AUIManager.GetPane("ToolBar").BestSize(ToolBar.GetBestSize()) |
|
1541 |
self.AUIManager.Update() |
|
95 | 1542 |
elif not language: |
1543 |
self.ResetToolBar() |
|
1544 |
self.CurrentLanguage = language |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1545 |
self.ResetCurrentMode() |
0 | 1546 |
|
163 | 1547 |
|
1548 |
#------------------------------------------------------------------------------- |
|
1549 |
# Tool Bar Items Functions |
|
1550 |
#------------------------------------------------------------------------------- |
|
1551 |
||
1552 |
def ResetCurrentMode(self): |
|
121 | 1553 |
selected = self.GetPageSelection() |
0 | 1554 |
if selected != -1: |
121 | 1555 |
window = self.GetPage(selected) |
163 | 1556 |
window.SetMode(MODE_SELECTION) |
1557 |
if wx.VERSION < (2, 8, 0): |
|
1558 |
ToolBar = self.ToolBar |
|
1559 |
else: |
|
1560 |
ToolBar = self.Panes["ToolBar"] |
|
1561 |
if ToolBar: |
|
1562 |
ToolBar.ToggleTool(ID_PLCOPENEDITORTOOLBARSELECTION, True) |
|
1563 |
||
1564 |
def ResetToolToggle(self, id): |
|
1565 |
if wx.VERSION < (2, 8, 0): |
|
1566 |
tool = self.ToolBar.FindById(id) |
|
1567 |
else: |
|
1568 |
tool = self.Panes["ToolBar"].FindById(id) |
|
1569 |
tool.SetToggle(False) |
|
1570 |
||
1571 |
def OnSelectionTool(self, event): |
|
121 | 1572 |
selected = self.GetPageSelection() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1573 |
if selected != -1: |
163 | 1574 |
self.GetPage(selected).SetMode(MODE_SELECTION) |
1575 |
event.Skip() |
|
1576 |
||
1577 |
def OnCommentTool(self, event): |
|
1578 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCOMMENT) |
|
121 | 1579 |
selected = self.GetPageSelection() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1580 |
if selected != -1: |
163 | 1581 |
self.GetPage(selected).SetMode(MODE_COMMENT) |
1582 |
event.Skip() |
|
1583 |
||
1584 |
def OnVariableTool(self, event): |
|
1585 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARVARIABLE) |
|
121 | 1586 |
selected = self.GetPageSelection() |
0 | 1587 |
if selected != -1: |
163 | 1588 |
self.GetPage(selected).SetMode(MODE_VARIABLE) |
1589 |
event.Skip() |
|
1590 |
||
1591 |
def OnBlockTool(self, event): |
|
1592 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARBLOCK) |
|
121 | 1593 |
selected = self.GetPageSelection() |
0 | 1594 |
if selected != -1: |
163 | 1595 |
self.GetPage(selected).SetMode(MODE_BLOCK) |
1596 |
event.Skip() |
|
1597 |
||
1598 |
def OnConnectionTool(self, event): |
|
1599 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCONNECTION) |
|
121 | 1600 |
selected = self.GetPageSelection() |
0 | 1601 |
if selected != -1: |
163 | 1602 |
self.GetPage(selected).SetMode(MODE_CONNECTION) |
1603 |
event.Skip() |
|
1604 |
||
1605 |
def OnPowerRailTool(self, event): |
|
1606 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARPOWERRAIL) |
|
1607 |
selected = self.GetPageSelection() |
|
1608 |
if selected != -1: |
|
1609 |
self.GetPage(selected).SetMode(MODE_POWERRAIL) |
|
1610 |
event.Skip() |
|
1611 |
||
1612 |
def OnRungTool(self, event): |
|
1613 |
selected = self.GetPageSelection() |
|
1614 |
if selected != -1: |
|
1615 |
self.GetPage(selected).AddLadderRung() |
|
1616 |
event.Skip() |
|
1617 |
||
1618 |
def OnCoilTool(self, event): |
|
1619 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCOIL) |
|
1620 |
selected = self.GetPageSelection() |
|
1621 |
if selected != -1: |
|
1622 |
self.GetPage(selected).SetMode(MODE_COIL) |
|
1623 |
event.Skip() |
|
1624 |
||
1625 |
def OnContactTool(self, event): |
|
1626 |
if self.DrawingMode == FREEDRAWING_MODE: |
|
1627 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCONTACT) |
|
1628 |
selected = self.GetPageSelection() |
|
1629 |
if selected != -1: |
|
1630 |
if self.DrawingMode == FREEDRAWING_MODE: |
|
1631 |
self.GetPage(selected).SetMode(MODE_CONTACT) |
|
1632 |
else: |
|
1633 |
self.GetPage(selected).AddLadderContact() |
|
1634 |
event.Skip() |
|
1635 |
||
1636 |
def OnBranchTool(self, event): |
|
1637 |
selected = self.GetPageSelection() |
|
1638 |
if selected != -1: |
|
1639 |
self.GetPage(selected).AddLadderBranch() |
|
1640 |
event.Skip() |
|
1641 |
||
1642 |
def OnInitialStepTool(self, event): |
|
1643 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARINITIALSTEP) |
|
1644 |
selected = self.GetPageSelection() |
|
1645 |
if selected != -1: |
|
1646 |
self.GetPage(selected).SetMode(MODE_INITIALSTEP) |
|
1647 |
event.Skip() |
|
1648 |
||
1649 |
def OnStepTool(self, event): |
|
1650 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1651 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARSTEP) |
|
1652 |
selected = self.GetPageSelection() |
|
1653 |
if selected != -1: |
|
1654 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1655 |
self.GetPage(selected).SetMode(MODE_STEP) |
|
1656 |
else: |
|
1657 |
self.GetPage(selected).AddStep() |
|
1658 |
event.Skip() |
|
1659 |
||
1660 |
def OnActionBlockTool(self, event): |
|
1661 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1662 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARACTIONBLOCK) |
|
1663 |
selected = self.GetPageSelection() |
|
1664 |
if selected != -1: |
|
1665 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1666 |
self.GetPage(selected).SetMode(MODE_ACTION) |
|
1667 |
else: |
|
1668 |
self.GetPage(selected).AddStepAction() |
|
1669 |
event.Skip() |
|
1670 |
||
1671 |
def OnTransitionTool(self, event): |
|
1672 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARTRANSITION) |
|
1673 |
selected = self.GetPageSelection() |
|
1674 |
if selected != -1: |
|
1675 |
self.GetPage(selected).SetMode(MODE_TRANSITION) |
|
1676 |
event.Skip() |
|
1677 |
||
1678 |
def OnDivergenceTool(self, event): |
|
1679 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1680 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARDIVERGENCE) |
|
1681 |
selected = self.GetPageSelection() |
|
1682 |
if selected != -1: |
|
1683 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1684 |
self.GetPage(selected).SetMode(MODE_DIVERGENCE) |
|
1685 |
else: |
|
1686 |
self.GetPage(selected).AddDivergence() |
|
1687 |
event.Skip() |
|
1688 |
||
1689 |
def OnJumpTool(self, event): |
|
1690 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1691 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARJUMP) |
|
1692 |
selected = self.GetPageSelection() |
|
1693 |
if selected != -1: |
|
1694 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1695 |
self.GetPage(selected).SetMode(MODE_JUMP) |
|
1696 |
else: |
|
1697 |
self.GetPage(selected).AddJump() |
|
1698 |
event.Skip() |
|
1699 |
||
1700 |
||
1701 |
#------------------------------------------------------------------------------- |
|
1702 |
# Add Project Elements Functions |
|
1703 |
#------------------------------------------------------------------------------- |
|
1704 |
||
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1705 |
def OnAddDataTypeMenu(self, event): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1706 |
dialog = DataTypeDialog(self, "Add a new data type", "Please enter data type name", "", wx.OK|wx.CANCEL) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1707 |
dialog.SetDataTypeNames(self.Controler.GetProjectDataTypeNames()) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1708 |
if dialog.ShowModal() == wx.ID_OK: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1709 |
self.Controler.ProjectAddDataType(dialog.GetValue()) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1710 |
self.RefreshTitle() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1711 |
self.RefreshEditMenu() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1712 |
self.RefreshProjectTree() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1713 |
dialog.Destroy() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1714 |
event.Skip() |
163 | 1715 |
|
1716 |
def GenerateAddPouFunction(self, pou_type): |
|
1717 |
def OnAddPouMenu(event): |
|
1718 |
dialog = PouDialog(self, pou_type) |
|
1719 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
|
1720 |
dialog.SetPouElementNames(self.Controler.GetProjectPouVariables()) |
|
1721 |
if dialog.ShowModal() == wx.ID_OK: |
|
1722 |
values = dialog.GetValues() |
|
1723 |
self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"]) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1724 |
self.RefreshTitle() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1725 |
self.RefreshEditMenu() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
1726 |
self.RefreshProjectTree() |
163 | 1727 |
dialog.Destroy() |
1728 |
event.Skip() |
|
1729 |
return OnAddPouMenu |
|
1730 |
||
1731 |
def GenerateAddTransitionFunction(self, pou_name): |
|
1732 |
def OnAddTransitionMenu(event): |
|
1733 |
dialog = PouTransitionDialog(self) |
|
1734 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
|
1735 |
dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pou_name)) |
|
1736 |
if dialog.ShowModal() == wx.ID_OK: |
|
1737 |
values = dialog.GetValues() |
|
1738 |
self.Controler.ProjectAddPouTransition(pou_name, values["transitionName"], values["language"]) |
|
80 | 1739 |
self.RefreshTitle() |
1740 |
self.RefreshEditMenu() |
|
0 | 1741 |
self.RefreshProjectTree() |
163 | 1742 |
dialog.Destroy() |
1743 |
event.Skip() |
|
1744 |
return OnAddTransitionMenu |
|
1745 |
||
1746 |
def GenerateAddActionFunction(self, pou_name): |
|
1747 |
def OnAddActionMenu(event): |
|
1748 |
dialog = PouActionDialog(self) |
|
1749 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
|
1750 |
dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pou_name)) |
|
1751 |
if dialog.ShowModal() == wx.ID_OK: |
|
1752 |
values = dialog.GetValues() |
|
1753 |
self.Controler.ProjectAddPouAction(pou_name, values["actionName"], values["language"]) |
|
1754 |
self.RefreshTitle() |
|
1755 |
self.RefreshEditMenu() |
|
1756 |
self.RefreshProjectTree() |
|
1757 |
dialog.Destroy() |
|
1758 |
event.Skip() |
|
1759 |
return OnAddActionMenu |
|
0 | 1760 |
|
1761 |
def OnAddConfigurationMenu(self, event): |
|
80 | 1762 |
dialog = ConfigurationNameDialog(self, "Please enter configuration name", "Add new configuration") |
1763 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
|
1764 |
dialog.SetPouElementNames(self.Controler.GetProjectPouVariables()) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1765 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 1766 |
value = dialog.GetValue() |
1767 |
self.Controler.ProjectAddConfiguration(value) |
|
80 | 1768 |
self.RefreshTitle() |
1769 |
self.RefreshEditMenu() |
|
0 | 1770 |
self.RefreshProjectTree() |
1771 |
dialog.Destroy() |
|
1772 |
event.Skip() |
|
1773 |
||
163 | 1774 |
def GenerateAddResourceFunction(self, config_name): |
177 | 1775 |
def OnAddResourceMenu(event): |
80 | 1776 |
dialog = ResourceNameDialog(self, "Please enter resource name", "Add new resource") |
1777 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
|
1778 |
dialog.SetPouElementNames(self.Controler.GetProjectPouVariables()) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1779 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 1780 |
value = dialog.GetValue() |
1781 |
self.Controler.ProjectAddConfigurationResource(config_name, value) |
|
163 | 1782 |
self.RefreshTitle() |
1783 |
self.RefreshEditMenu() |
|
1784 |
self.RefreshProjectTree() |
|
1785 |
dialog.Destroy() |
|
1786 |
event.Skip() |
|
1787 |
return OnAddResourceMenu |
|
1788 |
||
1789 |
||
1790 |
#------------------------------------------------------------------------------- |
|
1791 |
# Remove Project Elements Functions |
|
1792 |
#------------------------------------------------------------------------------- |
|
1793 |
||
1794 |
def OnRemoveDataTypeMenu(self, event): |
|
1795 |
selected = self.ProjectTree.GetSelection() |
|
1796 |
if self.ProjectTree.GetPyData(selected) == ITEM_DATATYPE: |
|
1797 |
name = self.ProjectTree.GetItemText(selected) |
|
1798 |
if not self.Controler.DataTypeIsUsed(name): |
|
1799 |
self.Controler.ProjectRemoveDataType(name) |
|
1800 |
tagname = self.Controler.ComputeDataTypeName(name) |
|
121 | 1801 |
idx = self.IsOpened(tagname) |
1802 |
if idx is not None: |
|
1803 |
self.DeletePage(idx) |
|
80 | 1804 |
self.RefreshTitle() |
1805 |
self.RefreshEditMenu() |
|
0 | 1806 |
self.RefreshProjectTree() |
163 | 1807 |
self.RefreshToolBar() |
1808 |
else: |
|
1809 |
message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR) |
|
1810 |
message.ShowModal() |
|
1811 |
message.Destroy() |
|
1812 |
event.Skip() |
|
1813 |
||
1814 |
def OnRemovePouMenu(self, event): |
|
0 | 1815 |
selected = self.ProjectTree.GetSelection() |
163 | 1816 |
if self.ProjectTree.GetPyData(selected) == ITEM_POU: |
1817 |
name = self.ProjectTree.GetItemText(selected) |
|
1818 |
if not self.Controler.PouIsUsed(name): |
|
1819 |
self.Controler.ProjectRemovePou(name) |
|
1820 |
tagname = self.Controler.ComputePouName(name) |
|
1821 |
idx = self.IsOpened(tagname) |
|
1822 |
if idx is not None: |
|
1823 |
self.VariablePanelIndexer.RemoveVariablePanel(tagname) |
|
1824 |
self.DeletePage(idx) |
|
80 | 1825 |
self.RefreshTitle() |
1826 |
self.RefreshEditMenu() |
|
0 | 1827 |
self.RefreshProjectTree() |
163 | 1828 |
self.RefreshToolBar() |
1829 |
else: |
|
1830 |
message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR) |
|
1831 |
message.ShowModal() |
|
1832 |
message.Destroy() |
|
1833 |
event.Skip() |
|
1834 |
||
1835 |
def OnRemoveConfigurationMenu(self, event): |
|
1836 |
selected = self.ProjectTree.GetSelection() |
|
1837 |
if self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION: |
|
1838 |
name = self.ProjectTree.GetItemText(selected) |
|
1839 |
self.Controler.ProjectRemoveConfiguration(name) |
|
1840 |
tagname = self.Controler.ComputeConfigurationName(name) |
|
1841 |
idx = self.IsOpened(tagname) |
|
1842 |
if idx is not None: |
|
1843 |
self.VariablePanelIndexer.RemoveVariablePanel(tagname) |
|
1844 |
self.DeletePage(idx) |
|
1845 |
self.RefreshTitle() |
|
1846 |
self.RefreshEditMenu() |
|
1847 |
self.RefreshProjectTree() |
|
1848 |
event.Skip() |
|
1849 |
||
1850 |
def OnRemoveTransitionMenu(self, event): |
|
1851 |
selected = self.ProjectTree.GetSelection() |
|
1852 |
if self.ProjectTree.GetPyData(selected) == ITEM_TRANSITION: |
|
1853 |
transition = self.ProjectTree.GetItemText(selected) |
|
1854 |
item = self.ProjectTree.GetItemParent(selected) |
|
1855 |
item_type = self.ProjectTree.GetPyData(item) |
|
1856 |
while item_type != ITEM_POU: |
|
1857 |
item = self.ProjectTree.GetItemParent(item) |
|
1858 |
item_type = self.ProjectTree.GetPyData(item) |
|
1859 |
pou_name = self.ProjectTree.GetItemText(item) |
|
1860 |
self.Controler.ProjectRemovePouTransition(pou_name, transition) |
|
1861 |
tagname = self.Controler.ComputePouTransitionName(pou_name, transition) |
|
1862 |
idx = self.IsOpened(tagname) |
|
1863 |
if idx is not None: |
|
1864 |
self.VariablePanelIndexer.RemoveVariablePanel(tagname) |
|
1865 |
self.DeletePage(idx) |
|
1866 |
self.RefreshTitle() |
|
1867 |
self.RefreshEditMenu() |
|
1868 |
self.RefreshProjectTree() |
|
1869 |
event.Skip() |
|
1870 |
||
1871 |
def OnRemoveActionMenu(self, event): |
|
1872 |
selected = self.ProjectTree.GetSelection() |
|
1873 |
if self.ProjectTree.GetPyData(selected) == ITEM_ACTION: |
|
1874 |
transition = self.ProjectTree.GetItemText(selected) |
|
1875 |
item = self.ProjectTree.GetItemParent(selected) |
|
1876 |
item_type = self.ProjectTree.GetPyData(item) |
|
1877 |
while item_type != ITEM_POU: |
|
1878 |
item = self.ProjectTree.GetItemParent(item) |
|
1879 |
item_type = self.ProjectTree.GetPyData(item) |
|
1880 |
pou_name = self.ProjectTree.GetItemText(item) |
|
1881 |
self.Controler.ProjectRemovePouAction(pou_name, action) |
|
1882 |
tagname = self.Controler.ComputePouActionName(pou_name, action) |
|
1883 |
idx = self.IsOpened(tagname) |
|
1884 |
if idx is not None: |
|
1885 |
self.VariablePanelIndexer.RemoveVariablePanel(tagname) |
|
1886 |
self.DeletePage(idx) |
|
1887 |
self.RefreshTitle() |
|
1888 |
self.RefreshEditMenu() |
|
1889 |
self.RefreshProjectTree() |
|
1890 |
event.Skip() |
|
1891 |
||
1892 |
def OnRemoveResourceMenu(self, event): |
|
1893 |
selected = self.ProjectTree.GetSelection() |
|
1894 |
if self.ProjectTree.GetPyData(selected) == ITEM_RESOURCE: |
|
1895 |
resource = self.ProjectTree.GetItemText(selected) |
|
1896 |
item = self.ProjectTree.GetItemParent(selected) |
|
1897 |
item_type = self.ProjectTree.GetPyData(item) |
|
1898 |
while item_type != ITEM_CONFIGURATION: |
|
1899 |
item = self.ProjectTree.GetItemParent(item) |
|
1900 |
item_type = self.ProjectTree.GetPyData(item) |
|
1901 |
config_name = self.ProjectTree.GetItemText(item) |
|
1902 |
self.Controler.ProjectRemoveConfigurationResource(config_name, resource) |
|
1903 |
tagname = self.Controler.ComputeConfigurationResourceName(config_name, selected) |
|
1904 |
idx = self.IsOpened(tagname) |
|
1905 |
if idx is not None: |
|
1906 |
self.VariablePanelIndexer.RemoveVariablePanel(tagname) |
|
1907 |
self.DeletePage(idx) |
|
1908 |
self.RefreshTitle() |
|
1909 |
self.RefreshEditMenu() |
|
1910 |
self.RefreshProjectTree() |
|
0 | 1911 |
event.Skip() |
1912 |
||
1913 |
def OnPLCOpenMenu(self, event): |
|
1914 |
result = OpenPDFDoc() |
|
1915 |
if type(result) == StringType: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1916 |
message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) |
0 | 1917 |
message.ShowModal() |
1918 |
message.Destroy() |
|
1919 |
event.Skip() |
|
1920 |
||
1921 |
current_num = 0 |
|
1922 |
def GetNewNum(): |
|
1923 |
global current_num |
|
1924 |
current_num += 1 |
|
1925 |
return current_num |
|
1926 |
||
1927 |
#------------------------------------------------------------------------------- |
|
1928 |
# Create Project Dialog |
|
1929 |
#------------------------------------------------------------------------------- |
|
1930 |
||
145 | 1931 |
[ID_SCALINGPANEL, ID_SCALINGPANELXSCALE, |
1932 |
ID_SCALINGPANELYSCALE, ID_SCALINGPANELSTATICTEXT1, |
|
1933 |
ID_SCALINGPANELSTATICTEXT2, |
|
1934 |
] = [wx.NewId() for _init_ctrls in range(5)] |
|
1935 |
||
1936 |
class ScalingPanel(wx.Panel): |
|
1937 |
||
1938 |
def _init_coll_ScalingPanelSizer_Items(self, parent): |
|
1939 |
parent.AddWindow(self.staticText1, 0, border=10, flag=wx.GROW|wx.TOP|wx.LEFT) |
|
1940 |
parent.AddWindow(self.XScale, 0, border=10, flag=wx.GROW|wx.TOP|wx.RIGHT) |
|
1941 |
parent.AddWindow(self.staticText2, 0, border=10, flag=wx.GROW|wx.BOTTOM|wx.LEFT) |
|
1942 |
parent.AddWindow(self.YScale, 0, border=10, flag=wx.GROW|wx.BOTTOM|wx.RIGHT) |
|
1943 |
||
1944 |
def _init_coll_ScalingPanelSizer_Growables(self, parent): |
|
1945 |
parent.AddGrowableCol(1) |
|
1946 |
||
1947 |
def _init_sizers(self): |
|
1948 |
self.ScalingPanelSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=2, vgap=5) |
|
1949 |
||
1950 |
self._init_coll_ScalingPanelSizer_Items(self.ScalingPanelSizer) |
|
1951 |
self._init_coll_ScalingPanelSizer_Growables(self.ScalingPanelSizer) |
|
1952 |
||
1953 |
self.SetSizer(self.ScalingPanelSizer) |
|
1954 |
||
1955 |
def _init_ctrls(self, prnt): |
|
1956 |
wx.Panel.__init__(self, id=ID_SCALINGPANEL, |
|
1957 |
name='ScalingPanel', parent=prnt, pos=wx.Point(0, 0), |
|
163 | 1958 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
145 | 1959 |
|
1960 |
self.staticText1 = wx.StaticText(id=ID_SCALINGPANELSTATICTEXT1, |
|
1961 |
label='X Scale:', name='staticText1', parent=self, |
|
1962 |
pos=wx.Point(0, 0), size=wx.Size(150, 17), style=0) |
|
1963 |
||
1964 |
self.XScale = wx.SpinCtrl(id=ID_SCALINGPANELXSCALE, |
|
1965 |
name='XScale', parent=self, pos=wx.Point(0, 0), |
|
1966 |
size=wx.Size(0, 24), style=0, min=0, max=2**16) |
|
1967 |
||
1968 |
self.staticText2 = wx.StaticText(id=ID_SCALINGPANELSTATICTEXT2, |
|
1969 |
label='Y Scale:', name='staticText2', parent=self, |
|
1970 |
pos=wx.Point(0, 0), size=wx.Size(150, 17), style=0) |
|
1971 |
||
1972 |
self.YScale = wx.SpinCtrl(id=ID_SCALINGPANELYSCALE, |
|
1973 |
name='YScale', parent=self, pos=wx.Point(0, 0), |
|
1974 |
size=wx.Size(0, 24), style=0, min=0, max=2**16) |
|
1975 |
||
1976 |
self._init_sizers() |
|
1977 |
||
1978 |
def __init__(self, parent): |
|
1979 |
self._init_ctrls(parent) |
|
1980 |
||
1981 |
def SetScaling(self, x, y): |
|
1982 |
self.XScale.SetValue(x) |
|
1983 |
self.YScale.SetValue(y) |
|
1984 |
||
1985 |
def GetScaling(self): |
|
1986 |
return self.XScale.GetValue(), self.YScale.GetValue() |
|
1987 |
||
1988 |
[ID_PROJECTDIALOG, ID_PROJECTDIALOGMAINNOTEBOOK, |
|
1989 |
ID_PROJECTDIALOGPROJECTPANEL, ID_PROJECTDIALOGAUTHORPANEL, |
|
1990 |
ID_PROJECTDIALOGGRAPHICSPANEL, ID_PROJECTDIALOGMISCELLANEOUSPANEL, |
|
1991 |
ID_PROJECTDIALOGPROJECTNAME, ID_PROJECTDIALOGPROJECTVERSION, |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1992 |
ID_PROJECTDIALOGPRODUCTNAME, ID_PROJECTDIALOGPRODUCTVERSION, |
145 | 1993 |
ID_PROJECTDIALOGPRODUCTRELEASE, ID_PROJECTDIALOGCOMPANYNAME, |
1994 |
ID_PROJECTDIALOGCOMPANYURL, ID_PROJECTDIALOGAUTHORNAME, |
|
1995 |
ID_PROJECTDIALOGORGANIZATION, ID_PROJECTDIALOGLANGUAGE, |
|
1996 |
ID_PROJECTDIALOGCONTENTDESCRIPTION, ID_PROJECTDIALOGSCALINGNOTEBOOK, |
|
1997 |
ID_PROJECTDIALOGPAGEWIDTH, ID_PROJECTDIALOGPAGEHEIGHT, |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1998 |
ID_PROJECTDIALOGSTATICTEXT1, ID_PROJECTDIALOGSTATICTEXT2, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1999 |
ID_PROJECTDIALOGSTATICTEXT3, ID_PROJECTDIALOGSTATICTEXT4, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2000 |
ID_PROJECTDIALOGSTATICTEXT5, ID_PROJECTDIALOGSTATICTEXT6, |
145 | 2001 |
ID_PROJECTDIALOGSTATICTEXT7, ID_PROJECTDIALOGSTATICTEXT8, |
2002 |
ID_PROJECTDIALOGSTATICTEXT9, ID_PROJECTDIALOGSTATICTEXT10, |
|
2003 |
ID_PROJECTDIALOGSTATICTEXT11, ID_PROJECTDIALOGSTATICTEXT12, |
|
2004 |
ID_PROJECTDIALOGSTATICTEXT13, ID_PROJECTDIALOGSTATICTEXT14, |
|
2005 |
ID_PROJECTDIALOGSTATICTEXT15, |
|
2006 |
] = [wx.NewId() for _init_ctrls in range(35)] |
|
2007 |
||
0 | 2008 |
class ProjectDialog(wx.Dialog): |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2009 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2010 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2011 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2012 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2013 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2014 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2015 |
|
0 | 2016 |
def _init_coll_flexGridSizer1_Items(self, parent): |
145 | 2017 |
parent.AddSizer(self.MainNotebook, 0, border=0, flag=wx.GROW) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2018 |
parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2019 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2020 |
def _init_coll_flexGridSizer1_Growables(self, parent): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2021 |
parent.AddGrowableCol(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2022 |
parent.AddGrowableRow(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2023 |
|
145 | 2024 |
def _init_coll_ProjectPanelSizer_Items(self, parent): |
2025 |
parent.AddWindow(self.staticText1, 0, border=10, flag=wx.GROW|wx.TOP|wx.LEFT) |
|
2026 |
parent.AddWindow(self.ProjectName, 0, border=10, flag=wx.GROW|wx.TOP|wx.RIGHT) |
|
2027 |
parent.AddWindow(self.staticText2, 0, border=10, flag=wx.GROW|wx.LEFT) |
|
2028 |
parent.AddWindow(self.ProjectVersion, 0, border=10, flag=wx.GROW|wx.RIGHT) |
|
2029 |
parent.AddWindow(self.staticText3, 0, border=10, flag=wx.GROW|wx.LEFT) |
|
2030 |
parent.AddWindow(self.ProductName, 0, border=10, flag=wx.GROW|wx.RIGHT) |
|
2031 |
parent.AddWindow(self.staticText4, 0, border=10, flag=wx.GROW|wx.LEFT) |
|
2032 |
parent.AddWindow(self.ProductVersion, 0, border=10, flag=wx.GROW|wx.RIGHT) |
|
2033 |
parent.AddWindow(self.staticText5, 0, border=10, flag=wx.GROW|wx.BOTTOM|wx.LEFT) |
|
2034 |
parent.AddWindow(self.ProductRelease, 0, border=10, flag=wx.GROW|wx.BOTTOM|wx.RIGHT) |
|
2035 |
||
2036 |
def _init_coll_ProjectPanelSizer_Growables(self, parent): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2037 |
parent.AddGrowableCol(1) |
145 | 2038 |
|
2039 |
def _init_coll_AuthorPanelSizer_Items(self, parent): |
|
2040 |
parent.AddWindow(self.staticText6, 0, border=10, flag=wx.GROW|wx.TOP|wx.LEFT) |
|
2041 |
parent.AddWindow(self.CompanyName, 0, border=10, flag=wx.GROW|wx.TOP|wx.RIGHT) |
|
2042 |
parent.AddWindow(self.staticText7, 0, border=10, flag=wx.GROW|wx.LEFT) |
|
2043 |
parent.AddWindow(self.CompanyURL, 0, border=10, flag=wx.GROW|wx.RIGHT) |
|
2044 |
parent.AddWindow(self.staticText8, 0, border=10, flag=wx.GROW|wx.LEFT) |
|
2045 |
parent.AddWindow(self.AuthorName, 0, border=10, flag=wx.GROW|wx.RIGHT) |
|
2046 |
parent.AddWindow(self.staticText9, 0, border=10, flag=wx.GROW|wx.BOTTOM|wx.LEFT) |
|
2047 |
parent.AddWindow(self.Organization, 0, border=10, flag=wx.GROW|wx.BOTTOM|wx.RIGHT) |
|
2048 |
||
2049 |
def _init_coll_AuthorPanelSizer_Growables(self, parent): |
|
2050 |
parent.AddGrowableCol(1) |
|
2051 |
||
2052 |
def _init_coll_GraphicsPanelSizer_Items(self, parent): |
|
2053 |
parent.AddWindow(self.staticText12, 0, border=10, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
|
2054 |
parent.AddSizer(self.GraphicsPageSizeSizer, 0, border=10, flag=wx.GROW|wx.LEFT|wx.RIGHT) |
|
2055 |
parent.AddWindow(self.staticText15, 0, border=10, flag=wx.GROW|wx.LEFT|wx.RIGHT) |
|
2056 |
parent.AddWindow(self.ScalingNotebook, 0, border=10, flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
|
2057 |
||
2058 |
def _init_coll_GraphicsPanelSizer_Growables(self, parent): |
|
2059 |
parent.AddGrowableCol(0) |
|
2060 |
parent.AddGrowableRow(3) |
|
2061 |
||
2062 |
def _init_coll_GraphicsPageSizeSizer_Items(self, parent): |
|
2063 |
parent.AddWindow(self.staticText13, 0, border=12, flag=wx.GROW|wx.LEFT) |
|
2064 |
parent.AddWindow(self.PageWidth, 0, border=0, flag=wx.GROW) |
|
2065 |
parent.AddWindow(self.staticText14, 0, border=12, flag=wx.GROW|wx.LEFT) |
|
2066 |
parent.AddWindow(self.PageHeight, 0, border=0, flag=wx.GROW) |
|
2067 |
||
2068 |
def _init_coll_GraphicsPageSizeSizer_Growables(self, parent): |
|
2069 |
parent.AddGrowableCol(1) |
|
2070 |
||
2071 |
def _init_coll_MiscellaneousPanelSizer_Items(self, parent): |
|
2072 |
parent.AddWindow(self.staticText10, 0, border=10, flag=wx.GROW|wx.TOP|wx.LEFT) |
|
2073 |
parent.AddWindow(self.Language, 0, border=10, flag=wx.GROW|wx.TOP|wx.RIGHT) |
|
2074 |
parent.AddWindow(self.staticText11, 0, border=10, flag=wx.GROW|wx.BOTTOM|wx.LEFT) |
|
2075 |
parent.AddWindow(self.ContentDescription, 0, border=10, flag=wx.GROW|wx.BOTTOM|wx.RIGHT) |
|
2076 |
||
2077 |
def _init_coll_MiscellaneousPanelSizer_Growables(self, parent): |
|
2078 |
parent.AddGrowableCol(1) |
|
2079 |
parent.AddGrowableRow(1) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2080 |
|
0 | 2081 |
def _init_sizers(self): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2082 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
145 | 2083 |
self.ProjectPanelSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=5, vgap=15) |
2084 |
self.AuthorPanelSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=4, vgap=15) |
|
2085 |
self.GraphicsPanelSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=5) |
|
2086 |
self.GraphicsPageSizeSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=2, vgap=5) |
|
2087 |
self.MiscellaneousPanelSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=2, vgap=15) |
|
0 | 2088 |
|
2089 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2090 |
self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) |
145 | 2091 |
self._init_coll_ProjectPanelSizer_Items(self.ProjectPanelSizer) |
2092 |
self._init_coll_ProjectPanelSizer_Growables(self.ProjectPanelSizer) |
|
2093 |
self._init_coll_AuthorPanelSizer_Items(self.AuthorPanelSizer) |
|
2094 |
self._init_coll_AuthorPanelSizer_Growables(self.AuthorPanelSizer) |
|
2095 |
self._init_coll_GraphicsPanelSizer_Items(self.GraphicsPanelSizer) |
|
2096 |
self._init_coll_GraphicsPanelSizer_Growables(self.GraphicsPanelSizer) |
|
2097 |
self._init_coll_GraphicsPageSizeSizer_Items(self.GraphicsPageSizeSizer) |
|
2098 |
self._init_coll_GraphicsPageSizeSizer_Growables(self.GraphicsPageSizeSizer) |
|
2099 |
self._init_coll_MiscellaneousPanelSizer_Items(self.MiscellaneousPanelSizer) |
|
2100 |
self._init_coll_MiscellaneousPanelSizer_Growables(self.MiscellaneousPanelSizer) |
|
0 | 2101 |
|
2102 |
self.SetSizer(self.flexGridSizer1) |
|
145 | 2103 |
self.ProjectPanel.SetSizer(self.ProjectPanelSizer) |
2104 |
self.AuthorPanel.SetSizer(self.AuthorPanelSizer) |
|
2105 |
self.GraphicsPanel.SetSizer(self.GraphicsPanelSizer) |
|
2106 |
self.MiscellaneousPanel.SetSizer(self.MiscellaneousPanelSizer) |
|
0 | 2107 |
|
2108 |
def _init_ctrls(self, prnt): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2109 |
wx.Dialog.__init__(self, id=ID_PROJECTDIALOG, |
0 | 2110 |
name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223), |
145 | 2111 |
size=wx.Size(500, 350), style=wx.DEFAULT_DIALOG_STYLE, |
0 | 2112 |
title='Create a new project') |
145 | 2113 |
self.SetClientSize(wx.Size(500, 350)) |
2114 |
||
2115 |
self.MainNotebook = wx.Notebook(id=ID_PROJECTDIALOGMAINNOTEBOOK, |
|
2116 |
name='MainNotebook', parent=self, pos=wx.Point(0, |
|
2117 |
0), size=wx.Size(0, 0), style=0) |
|
2118 |
||
2119 |
# Project Panel elements |
|
2120 |
||
2121 |
self.ProjectPanel = wx.Panel(id=ID_PROJECTDIALOGPROJECTPANEL, |
|
2122 |
name='ProjectPanel', parent=self.MainNotebook, pos=wx.Point(0, 0), |
|
2123 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
0 | 2124 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2125 |
self.staticText1 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT1, |
145 | 2126 |
label='Project Name (required):', name='staticText1', parent=self.ProjectPanel, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2127 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2128 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2129 |
self.ProjectName = wx.TextCtrl(id=ID_PROJECTDIALOGPROJECTNAME, |
145 | 2130 |
name='ProjectName', parent=self.ProjectPanel, pos=wx.Point(0, 0), |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2131 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2132 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2133 |
self.staticText2 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT2, |
145 | 2134 |
label='Project Version (optional):', name='staticText2', parent=self.ProjectPanel, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2135 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2136 |
|
145 | 2137 |
self.ProjectVersion = wx.TextCtrl(id=ID_PROJECTDIALOGPROJECTVERSION, |
2138 |
name='ProjectVersion', parent=self.ProjectPanel, pos=wx.Point(0, 0), |
|
2139 |
size=wx.Size(0, 24), style=0) |
|
2140 |
||
2141 |
self.staticText3 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT3, |
|
2142 |
label='Product Name (required):', name='staticText3', parent=self.ProjectPanel, |
|
2143 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
|
2144 |
||
2145 |
self.ProductName = wx.TextCtrl(id=ID_PROJECTDIALOGPRODUCTNAME, |
|
2146 |
name='ProductName', parent=self.ProjectPanel, pos=wx.Point(0, 0), |
|
2147 |
size=wx.Size(0, 24), style=0) |
|
2148 |
||
2149 |
self.staticText4 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT4, |
|
2150 |
label='Product Version (required):', name='staticText4', parent=self.ProjectPanel, |
|
2151 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
|
2152 |
||
2153 |
self.ProductVersion = wx.TextCtrl(id=ID_PROJECTDIALOGPRODUCTVERSION, |
|
2154 |
name='ProductVersion', parent=self.ProjectPanel, pos=wx.Point(0, 0), |
|
2155 |
size=wx.Size(0, 24), style=0) |
|
2156 |
||
2157 |
self.staticText5 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT5, |
|
2158 |
label='Product Release (optional):', name='staticText5', parent=self.ProjectPanel, |
|
2159 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
|
2160 |
||
2161 |
self.ProductRelease = wx.TextCtrl(id=ID_PROJECTDIALOGPRODUCTRELEASE, |
|
2162 |
name='ProductRelease', parent=self.ProjectPanel, pos=wx.Point(0, 0), |
|
2163 |
size=wx.Size(0, 24), style=0) |
|
2164 |
||
2165 |
self.MainNotebook.AddPage(self.ProjectPanel, "Project") |
|
2166 |
||
2167 |
# Author Panel elements |
|
2168 |
||
2169 |
self.AuthorPanel = wx.Panel(id=ID_PROJECTDIALOGAUTHORPANEL, |
|
2170 |
name='AuthorPanel', parent=self.MainNotebook, pos=wx.Point(0, 0), |
|
2171 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
2172 |
||
2173 |
self.staticText6 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT6, |
|
2174 |
label='Company Name (required):', name='staticText6', parent=self.AuthorPanel, |
|
2175 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
|
2176 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2177 |
self.CompanyName = wx.TextCtrl(id=ID_PROJECTDIALOGCOMPANYNAME, |
145 | 2178 |
name='CompanyName', parent=self.AuthorPanel, pos=wx.Point(0, 0), |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2179 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2180 |
|
145 | 2181 |
self.staticText7 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT7, |
2182 |
label='Company URL (optional):', name='staticText7', parent=self.AuthorPanel, |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2183 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2184 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2185 |
self.CompanyURL = wx.TextCtrl(id=ID_PROJECTDIALOGCOMPANYURL, |
145 | 2186 |
name='CompanyURL', parent=self.AuthorPanel, pos=wx.Point(0, 0), |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2187 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2188 |
|
145 | 2189 |
self.staticText8 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT8, |
2190 |
label='Author Name (optional):', name='staticText8', parent=self.AuthorPanel, |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2191 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2192 |
|
145 | 2193 |
self.AuthorName = wx.TextCtrl(id=ID_PROJECTDIALOGAUTHORNAME, |
2194 |
name='AuthorName', parent=self.AuthorPanel, pos=wx.Point(0, 0), |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2195 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2196 |
|
145 | 2197 |
self.staticText9 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT9, |
2198 |
label='Organization (optional):', name='staticText9', parent=self.AuthorPanel, |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2199 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2200 |
|
145 | 2201 |
self.Organization = wx.TextCtrl(id=ID_PROJECTDIALOGORGANIZATION, |
2202 |
name='Organization', parent=self.AuthorPanel, pos=wx.Point(0, 0), |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2203 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2204 |
|
145 | 2205 |
self.MainNotebook.AddPage(self.AuthorPanel, "Author") |
2206 |
||
2207 |
# Graphics Panel elements |
|
2208 |
||
2209 |
self.GraphicsPanel = wx.Panel(id=ID_PROJECTDIALOGGRAPHICSPANEL, |
|
2210 |
name='GraphicsPanel', parent=self.MainNotebook, pos=wx.Point(0, 0), |
|
2211 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
2212 |
||
2213 |
self.staticText12 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT12, |
|
2214 |
label='Page Size (optional):', name='staticText12', parent=self.GraphicsPanel, |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2215 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2216 |
|
145 | 2217 |
self.staticText13 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT13, |
2218 |
label='Width:', name='staticText13', parent=self.GraphicsPanel, |
|
2219 |
pos=wx.Point(0, 0), size=wx.Size(150, 17), style=0) |
|
2220 |
||
2221 |
self.PageWidth = wx.SpinCtrl(id=ID_PROJECTDIALOGPAGEWIDTH, |
|
2222 |
name='PageWidth', parent=self.GraphicsPanel, pos=wx.Point(0, 0), |
|
2223 |
size=wx.Size(0, 24), style=0, min=0, max=2**16) |
|
2224 |
||
2225 |
self.staticText14 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT14, |
|
2226 |
label='Height:', name='staticText14', parent=self.GraphicsPanel, |
|
2227 |
pos=wx.Point(0, 0), size=wx.Size(150, 17), style=0) |
|
2228 |
||
2229 |
self.PageHeight = wx.SpinCtrl(id=ID_PROJECTDIALOGPAGEHEIGHT, |
|
2230 |
name='PageHeight', parent=self.GraphicsPanel, pos=wx.Point(0, 0), |
|
2231 |
size=wx.Size(0, 24), style=0, min=0, max=2**16) |
|
2232 |
||
2233 |
self.staticText15 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT15, |
|
2234 |
label='Scaling:', name='staticText15', parent=self.GraphicsPanel, |
|
2235 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
|
2236 |
||
2237 |
self.ScalingNotebook = wx.Notebook(id=ID_PROJECTDIALOGSCALINGNOTEBOOK, |
|
2238 |
name='ScalingNotebook', parent=self.GraphicsPanel, pos=wx.Point(0, |
|
2239 |
0), size=wx.Size(0, 0), style=0) |
|
2240 |
||
2241 |
self.Scalings = {} |
|
2242 |
for language in ["FBD", "LD", "SFC"]: |
|
2243 |
window = ScalingPanel(self.ScalingNotebook) |
|
2244 |
self.Scalings[language] = window |
|
2245 |
self.ScalingNotebook.AddPage(window, language) |
|
2246 |
||
2247 |
self.MainNotebook.AddPage(self.GraphicsPanel, "Graphics") |
|
2248 |
||
2249 |
# Miscellaneous Panel elements |
|
2250 |
||
2251 |
self.MiscellaneousPanel = wx.Panel(id=ID_PROJECTDIALOGMISCELLANEOUSPANEL, |
|
2252 |
name='MiscellaneousPanel', parent=self.MainNotebook, pos=wx.Point(0, 0), |
|
2253 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
2254 |
||
2255 |
self.staticText10 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT10, |
|
2256 |
label='Language (optional):', name='staticText10', parent=self.MiscellaneousPanel, |
|
2257 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
|
2258 |
||
2259 |
self.Language = wx.Choice(id=ID_PROJECTDIALOGLANGUAGE, |
|
2260 |
name='Language', parent=self.MiscellaneousPanel, pos=wx.Point(0, 0), |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2261 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2262 |
|
145 | 2263 |
self.staticText11 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT11, |
2264 |
label='Content Description (optional):', name='staticText11', parent=self.MiscellaneousPanel, |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2265 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2266 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2267 |
self.ContentDescription = wx.TextCtrl(id=ID_PROJECTDIALOGCONTENTDESCRIPTION, |
145 | 2268 |
name='ContentDescription', parent=self.MiscellaneousPanel, pos=wx.Point(0, 0), |
2269 |
size=wx.Size(0, 24), style=wx.TE_MULTILINE) |
|
2270 |
||
2271 |
self.MainNotebook.AddPage(self.MiscellaneousPanel, "Miscellaneous") |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2272 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2273 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2274 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2275 |
|
0 | 2276 |
self._init_sizers() |
2277 |
||
2278 |
def __init__(self, parent): |
|
2279 |
self._init_ctrls(parent) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2280 |
|
145 | 2281 |
languages = ["", "en-US", "fr-FR"] |
2282 |
||
2283 |
for language in languages: |
|
2284 |
self.Language.Append(language) |
|
2285 |
||
0 | 2286 |
def OnOK(self, event): |
2287 |
error = [] |
|
2288 |
if self.ProjectName.GetValue() == "": |
|
2289 |
error.append("Project Name") |
|
2290 |
if self.CompanyName.GetValue() == "": |
|
2291 |
error.append("Company Name") |
|
2292 |
if self.ProductName.GetValue() == "": |
|
2293 |
error.append("Product Name") |
|
2294 |
if self.ProductVersion.GetValue() == "": |
|
2295 |
error.append("Product Version") |
|
2296 |
if len(error) > 0: |
|
2297 |
text = "" |
|
2298 |
for i, item in enumerate(error): |
|
2299 |
if i == 0: |
|
2300 |
text += item |
|
2301 |
elif i == len(error) - 1: |
|
2302 |
text += " and %s"%item |
|
2303 |
else: |
|
145 | 2304 |
text += ", %s"%item |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2305 |
message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR) |
0 | 2306 |
message.ShowModal() |
2307 |
message.Destroy() |
|
2308 |
else: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2309 |
self.EndModal(wx.ID_OK) |
0 | 2310 |
|
2311 |
def SetValues(self, values): |
|
2312 |
for item, value in values.items(): |
|
2313 |
if item == "projectName": |
|
2314 |
self.ProjectName.SetValue(value) |
|
145 | 2315 |
elif item == "projectVersion": |
2316 |
self.ProjectVersion.SetValue(value) |
|
0 | 2317 |
elif item == "productName": |
2318 |
self.ProductName.SetValue(value) |
|
2319 |
elif item == "productVersion": |
|
2320 |
self.ProductVersion.SetValue(value) |
|
2321 |
elif item == "productRelease": |
|
2322 |
self.ProductRelease.SetValue(value) |
|
145 | 2323 |
elif item == "companyName": |
2324 |
self.CompanyName.SetValue(value) |
|
2325 |
elif item == "companyURL": |
|
2326 |
self.CompanyURL.SetValue(value) |
|
2327 |
elif item == "authorName": |
|
2328 |
self.AuthorName.SetValue(value) |
|
2329 |
elif item == "organization": |
|
2330 |
self.Organization.SetValue(value) |
|
2331 |
elif item == "language": |
|
2332 |
self.Language.SetStringSelection(value) |
|
0 | 2333 |
elif item == "contentDescription": |
2334 |
self.ContentDescription.SetValue(value) |
|
145 | 2335 |
elif item == "pageSize": |
2336 |
self.PageWidth.SetValue(value[0]) |
|
2337 |
self.PageHeight.SetValue(value[1]) |
|
2338 |
elif item == "scaling": |
|
2339 |
for language, (x, y) in value.items(): |
|
2340 |
if language in self.Scalings: |
|
2341 |
self.Scalings[language].SetScaling(x, y) |
|
2342 |
||
0 | 2343 |
def GetValues(self): |
2344 |
values = {} |
|
2345 |
values["projectName"] = self.ProjectName.GetValue() |
|
145 | 2346 |
if self.ProjectVersion.GetValue() != "": |
2347 |
values["projectVersion"] = self.ProjectVersion.GetValue() |
|
0 | 2348 |
values["productName"] = self.ProductName.GetValue() |
2349 |
values["productVersion"] = self.ProductVersion.GetValue() |
|
145 | 2350 |
if self.ProductRelease.GetValue() != "": |
0 | 2351 |
values["productRelease"] = self.ProductRelease.GetValue() |
145 | 2352 |
values["companyName"] = self.CompanyName.GetValue() |
2353 |
if self.CompanyURL.GetValue() != "": |
|
2354 |
values["companyURL"] = self.CompanyURL.GetValue() |
|
2355 |
if self.AuthorName.GetValue() != "": |
|
2356 |
values["authorName"] = self.AuthorName.GetValue() |
|
2357 |
if self.Organization.GetValue() != "": |
|
2358 |
values["organization"] = self.Organization.GetValue() |
|
2359 |
if self.Language.GetStringSelection() != "": |
|
2360 |
values["language"] = self.Language.GetStringSelection() |
|
2361 |
if self.ProductRelease.GetValue() != "": |
|
0 | 2362 |
values["contentDescription"] = self.ContentDescription.GetValue() |
145 | 2363 |
values["pageSize"] = (self.PageWidth.GetValue(), self.PageHeight.GetValue()) |
2364 |
values["scaling"] = {} |
|
2365 |
for language in ["FBD", "LD", "SFC"]: |
|
2366 |
values["scaling"][language] = self.Scalings[language].GetScaling() |
|
0 | 2367 |
return values |
2368 |
||
2369 |
#------------------------------------------------------------------------------- |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2370 |
# Edit Step Name Dialog |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2371 |
#------------------------------------------------------------------------------- |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2372 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2373 |
class DataTypeDialog(wx.TextEntryDialog): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2374 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2375 |
if wx.VERSION < (2, 6, 0): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2376 |
def Bind(self, event, function, id = None): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2377 |
if id is not None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2378 |
event(self, id, function) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2379 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2380 |
event(self, function) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2381 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2382 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2383 |
def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2384 |
style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2385 |
wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2386 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2387 |
self.DataTypeNames = [] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2388 |
if wx.VERSION >= (2, 8, 0): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2389 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId()) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2390 |
elif wx.VERSION >= (2, 6, 0): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2391 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2392 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2393 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2394 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2395 |
def OnOK(self, event): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2396 |
datatype_name = self.GetSizer().GetItem(1).GetWindow().GetValue() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2397 |
if datatype_name == "": |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2398 |
message = wx.MessageDialog(self, "You must type a name!", "Error", wx.OK|wx.ICON_ERROR) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2399 |
message.ShowModal() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2400 |
message.Destroy() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2401 |
elif not TestIdentifier(datatype_name): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2402 |
message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%datatype_name, "Error", wx.OK|wx.ICON_ERROR) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2403 |
message.ShowModal() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2404 |
message.Destroy() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2405 |
elif datatype_name.upper() in IEC_KEYWORDS: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2406 |
message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%datatype_name, "Error", wx.OK|wx.ICON_ERROR) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2407 |
message.ShowModal() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2408 |
message.Destroy() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2409 |
elif datatype_name.upper() in self.DataTypeNames: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2410 |
message = wx.MessageDialog(self, "\"%s\" data type already exists!"%datatype_name, "Error", wx.OK|wx.ICON_ERROR) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2411 |
message.ShowModal() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2412 |
message.Destroy() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2413 |
else: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2414 |
self.EndModal(wx.ID_OK) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2415 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2416 |
def SetDataTypeNames(self, datatype_names): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2417 |
self.DataTypeNames = [datatype_name.upper() for datatype_name in datatype_names] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2418 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2419 |
def GetValue(self): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2420 |
return self.GetSizer().GetItem(1).GetWindow().GetValue() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2421 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
2422 |
#------------------------------------------------------------------------------- |
0 | 2423 |
# Create Pou Dialog |
2424 |
#------------------------------------------------------------------------------- |
|
2425 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2426 |
[ID_POUDIALOG, ID_POUDIALOGPOUNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2427 |
ID_POUDIALOGPOUTYPE, ID_POUDIALOGLANGUAGE, ID_POUDIALOGSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2428 |
ID_POUDIALOGSTATICTEXT2, ID_POUDIALOGSTATICTEXT3, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2429 |
] = [wx.NewId() for _init_ctrls in range(7)] |
0 | 2430 |
|
2431 |
class PouDialog(wx.Dialog): |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2432 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2433 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2434 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2435 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2436 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2437 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2438 |
|
0 | 2439 |
def _init_coll_flexGridSizer1_Items(self, parent): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2440 |
parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2441 |
parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2442 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2443 |
def _init_coll_flexGridSizer1_Growables(self, parent): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2444 |
parent.AddGrowableCol(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2445 |
parent.AddGrowableRow(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2446 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2447 |
def _init_coll_MainSizer_Items(self, parent): |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
2448 |
parent.AddWindow(self.staticText1, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2449 |
parent.AddWindow(self.PouName, 0, border=0, flag=wx.GROW) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
2450 |
parent.AddWindow(self.staticText2, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2451 |
parent.AddWindow(self.PouType, 0, border=0, flag=wx.GROW) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
2452 |
parent.AddWindow(self.staticText3, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2453 |
parent.AddWindow(self.Language, 0, border=0, flag=wx.GROW) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2454 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2455 |
def _init_coll_MainSizer_Growables(self, parent): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2456 |
parent.AddGrowableCol(1) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2457 |
|
0 | 2458 |
def _init_sizers(self): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2459 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2460 |
self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=3, vgap=15) |
0 | 2461 |
|
2462 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2463 |
self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2464 |
self._init_coll_MainSizer_Items(self.MainSizer) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2465 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
0 | 2466 |
|
2467 |
self.SetSizer(self.flexGridSizer1) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2468 |
|
0 | 2469 |
def _init_ctrls(self, prnt): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2470 |
wx.Dialog.__init__(self, id=ID_POUDIALOG, |
16 | 2471 |
name='PouDialog', parent=prnt, pos=wx.Point(376, 223), |
0 | 2472 |
size=wx.Size(300, 200), style=wx.DEFAULT_DIALOG_STYLE, |
16 | 2473 |
title='Create a new POU') |
0 | 2474 |
self.SetClientSize(wx.Size(300, 200)) |
2475 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2476 |
self.staticText1 = wx.StaticText(id=ID_POUDIALOGSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2477 |
label='POU Name:', name='staticText1', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2478 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2479 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2480 |
self.PouName = wx.TextCtrl(id=ID_POUDIALOGPOUNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2481 |
name='POUName', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2482 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2483 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2484 |
self.staticText2 = wx.StaticText(id=ID_POUDIALOGSTATICTEXT2, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2485 |
label='POU Type:', name='staticText2', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2486 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2487 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2488 |
self.PouType = wx.Choice(id=ID_POUDIALOGPOUTYPE, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2489 |
name='POUType', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2490 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2491 |
self.Bind(wx.EVT_CHOICE, self.OnTypeChanged, id=ID_POUDIALOGPOUTYPE) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2492 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2493 |
self.staticText3 = wx.StaticText(id=ID_POUDIALOGSTATICTEXT3, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2494 |
label='Language:', name='staticText3', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2495 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2496 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2497 |
self.Language = wx.Choice(id=ID_POUDIALOGLANGUAGE, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2498 |
name='Language', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2499 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2500 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2501 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2502 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2503 |
|
0 | 2504 |
self._init_sizers() |
2505 |
||
163 | 2506 |
def __init__(self, parent, pou_type = None): |
0 | 2507 |
self._init_ctrls(parent) |
2508 |
||
163 | 2509 |
for option in ["function", "functionBlock", "program"]: |
0 | 2510 |
self.PouType.Append(option) |
163 | 2511 |
if pou_type is not None: |
2512 |
self.PouType.SetStringSelection(pou_type) |
|
0 | 2513 |
self.RefreshLanguage() |
2514 |
||
6 | 2515 |
self.PouNames = [] |
70 | 2516 |
self.PouElementNames = [] |
6 | 2517 |
|
0 | 2518 |
def OnOK(self, event): |
2519 |
error = [] |
|
2520 |
pou_name = self.PouName.GetValue() |
|
2521 |
if pou_name == "": |
|
2522 |
error.append("POU Name") |
|
2523 |
if self.PouType.GetStringSelection() == "": |
|
2524 |
error.append("POU Type") |
|
2525 |
if self.Language.GetStringSelection() == "": |
|
2526 |
error.append("Language") |
|
2527 |
if len(error) > 0: |
|
2528 |
text = "" |
|
2529 |
for i, item in enumerate(error): |
|
2530 |
if i == 0: |
|
2531 |
text += item |
|
2532 |
elif i == len(error) - 1: |
|
2533 |
text += " and %s"%item |
|
2534 |
else: |
|
2535 |
text += ", %s"%item |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2536 |
message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR) |
0 | 2537 |
message.ShowModal() |
2538 |
message.Destroy() |
|
2539 |
elif not TestIdentifier(pou_name): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2540 |
message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%pou_name, "Error", wx.OK|wx.ICON_ERROR) |
0 | 2541 |
message.ShowModal() |
2542 |
message.Destroy() |
|
2543 |
elif pou_name.upper() in IEC_KEYWORDS: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2544 |
message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%pou_name, "Error", wx.OK|wx.ICON_ERROR) |
0 | 2545 |
message.ShowModal() |
2546 |
message.Destroy() |
|
2547 |
elif pou_name.upper() in self.PouNames: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2548 |
message = wx.MessageDialog(self, "\"%s\" pou already exists!"%pou_name, "Error", wx.OK|wx.ICON_ERROR) |
0 | 2549 |
message.ShowModal() |
2550 |
message.Destroy() |
|
70 | 2551 |
elif pou_name.upper() in self.PouElementNames: |
2552 |
message = wx.MessageDialog(self, "A pou has an element with \"%s\" for name. It can generate a conflict. Do you wish to continue?"%pou_name, "Warning", wx.YES_NO|wx.ICON_EXCLAMATION) |
|
2553 |
result = message.ShowModal() |
|
2554 |
message.Destroy() |
|
2555 |
if result == wx.ID_YES: |
|
2556 |
self.EndModal(wx.ID_OK) |
|
0 | 2557 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2558 |
self.EndModal(wx.ID_OK) |
0 | 2559 |
|
2560 |
def RefreshLanguage(self): |
|
2561 |
selection = self.Language.GetStringSelection() |
|
2562 |
self.Language.Clear() |
|
2563 |
for option in ["IL","ST","LD","FBD","SFC"]: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2564 |
if option != "SFC" or self.PouType.GetStringSelection() != "function": |
0 | 2565 |
self.Language.Append(option) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2566 |
if self.Language.FindString(selection) != wx.NOT_FOUND: |
0 | 2567 |
self.Language.SetStringSelection(selection) |
2568 |
||
2569 |
def OnTypeChanged(self, event): |
|
2570 |
self.RefreshLanguage() |
|
2571 |
event.Skip() |
|
2572 |
||
2573 |
def SetPouNames(self, pou_names): |
|
2574 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
2575 |
||
70 | 2576 |
def SetPouElementNames(self, element_names): |
2577 |
self.PouElementNames = [element_name.upper() for element_name in element_names] |
|
2578 |
||
0 | 2579 |
def SetValues(self, values): |
2580 |
for item, value in values.items(): |
|
2581 |
if item == "pouName": |
|
2582 |
self.PouName.SetValue(value) |
|
2583 |
elif item == "pouType": |
|
2584 |
self.PouType.SetStringSelection(value) |
|
2585 |
elif item == "language": |
|
2586 |
self.Language.SetStringSelection(value) |
|
2587 |
||
2588 |
def GetValues(self): |
|
2589 |
values = {} |
|
2590 |
values["pouName"] = self.PouName.GetValue() |
|
2591 |
values["pouType"] = self.PouType.GetStringSelection() |
|
2592 |
values["language"] = self.Language.GetStringSelection() |
|
2593 |
return values |
|
2594 |
||
2595 |
||
2596 |
#------------------------------------------------------------------------------- |
|
2597 |
# Create Pou Transition Dialog |
|
2598 |
#------------------------------------------------------------------------------- |
|
2599 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2600 |
[ID_POUTRANSITIONDIALOG, ID_POUTRANSITIONDIALOGTRANSITIONNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2601 |
ID_POUTRANSITIONDIALOGLANGUAGE, ID_POUTRANSITIONDIALOGSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2602 |
ID_POUTRANSITIONDIALOGSTATICTEXT2, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2603 |
] = [wx.NewId() for _init_ctrls in range(5)] |
0 | 2604 |
|
2605 |
class PouTransitionDialog(wx.Dialog): |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2606 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2607 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2608 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2609 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2610 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2611 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2612 |
|
0 | 2613 |
def _init_coll_flexGridSizer1_Items(self, parent): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2614 |
parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2615 |
parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2616 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2617 |
def _init_coll_flexGridSizer1_Growables(self, parent): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2618 |
parent.AddGrowableCol(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2619 |
parent.AddGrowableRow(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2620 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2621 |
def _init_coll_MainSizer_Items(self, parent): |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
2622 |
parent.AddWindow(self.staticText1, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2623 |
parent.AddWindow(self.TransitionName, 0, border=0, flag=wx.GROW) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
2624 |
parent.AddWindow(self.staticText2, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2625 |
parent.AddWindow(self.Language, 0, border=0, flag=wx.GROW) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2626 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2627 |
def _init_coll_MainSizer_Growables(self, parent): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2628 |
parent.AddGrowableCol(1) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2629 |
|
0 | 2630 |
def _init_sizers(self): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2631 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2632 |
self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=2, vgap=15) |
0 | 2633 |
|
2634 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2635 |
self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2636 |
self._init_coll_MainSizer_Items(self.MainSizer) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2637 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
0 | 2638 |
|
2639 |
self.SetSizer(self.flexGridSizer1) |
|
2640 |
||
2641 |
def _init_ctrls(self, prnt): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2642 |
wx.Dialog.__init__(self, id=ID_POUTRANSITIONDIALOG, |
45 | 2643 |
name='PouTransitionDialog', parent=prnt, pos=wx.Point(376, 223), |
0 | 2644 |
size=wx.Size(350, 200), style=wx.DEFAULT_DIALOG_STYLE, |
45 | 2645 |
title='Create a new transition') |
2646 |
self.SetClientSize(wx.Size(350, 160)) |
|
0 | 2647 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2648 |
self.staticText1 = wx.StaticText(id=ID_POUTRANSITIONDIALOGSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2649 |
label='Transition Name:', name='staticText1', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2650 |
pos=wx.Point(0, 0), size=wx.Size(120, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2651 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2652 |
self.TransitionName = wx.TextCtrl(id=ID_POUTRANSITIONDIALOGTRANSITIONNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2653 |
name='TransitionName', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2654 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2655 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2656 |
self.staticText2 = wx.StaticText(id=ID_POUTRANSITIONDIALOGSTATICTEXT2, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2657 |
label='Language:', name='staticText2', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2658 |
pos=wx.Point(0, 0), size=wx.Size(120, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2659 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2660 |
self.Language = wx.Choice(id=ID_POUTRANSITIONDIALOGLANGUAGE, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2661 |
name='Language', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2662 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2663 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2664 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2665 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2666 |
|
0 | 2667 |
self._init_sizers() |
2668 |
||
2669 |
def __init__(self, parent): |
|
2670 |
self._init_ctrls(parent) |
|
45 | 2671 |
|
0 | 2672 |
for option in ["IL","ST","LD","FBD"]: |
2673 |
self.Language.Append(option) |
|
70 | 2674 |
|
2675 |
self.PouNames = [] |
|
2676 |
self.PouElementNames = [] |
|
0 | 2677 |
|
2678 |
def OnOK(self, event): |
|
2679 |
error = [] |
|
70 | 2680 |
transition_name = self.TransitionName.GetValue() |
0 | 2681 |
if self.TransitionName.GetValue() == "": |
2682 |
error.append("Transition Name") |
|
2683 |
if self.Language.GetStringSelection() == "": |
|
2684 |
error.append("Language") |
|
2685 |
if len(error) > 0: |
|
2686 |
text = "" |
|
2687 |
for i, item in enumerate(error): |
|
2688 |
if i == 0: |
|
2689 |
text += item |
|
2690 |
elif i == len(error) - 1: |
|
2691 |
text += " and %s"%item |
|
2692 |
else: |
|
2693 |
text += ", %s"%item |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2694 |
message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR) |
0 | 2695 |
message.ShowModal() |
2696 |
message.Destroy() |
|
70 | 2697 |
elif not TestIdentifier(transition_name): |
2698 |
message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%transition_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2699 |
message.ShowModal() |
|
2700 |
message.Destroy() |
|
2701 |
elif transition_name.upper() in IEC_KEYWORDS: |
|
2702 |
message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%transition_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2703 |
message.ShowModal() |
|
2704 |
message.Destroy() |
|
2705 |
elif transition_name.upper() in self.PouNames: |
|
2706 |
message = wx.MessageDialog(self, "A pou with \"%s\" for name exists!"%transition_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2707 |
message.ShowModal() |
|
2708 |
message.Destroy() |
|
2709 |
elif transition_name.upper() in self.PouElementNames: |
|
2710 |
message = wx.MessageDialog(self, "\"%s\" element for this pou already exists!"%transition_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2711 |
message.ShowModal() |
|
2712 |
message.Destroy() |
|
0 | 2713 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2714 |
self.EndModal(wx.ID_OK) |
70 | 2715 |
|
2716 |
def SetPouNames(self, pou_names): |
|
2717 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
2718 |
||
2719 |
def SetPouElementNames(self, pou_names): |
|
2720 |
self.PouElementNames = [pou_name.upper() for pou_name in pou_names] |
|
2721 |
||
0 | 2722 |
def SetValues(self, values): |
2723 |
for item, value in values.items(): |
|
45 | 2724 |
if item == "transitionName": |
0 | 2725 |
self.TransitionName.SetValue(value) |
2726 |
elif item == "language": |
|
2727 |
self.Language.SetStringSelection(value) |
|
2728 |
||
2729 |
def GetValues(self): |
|
2730 |
values = {} |
|
2731 |
values["transitionName"] = self.TransitionName.GetValue() |
|
2732 |
values["language"] = self.Language.GetStringSelection() |
|
2733 |
return values |
|
2734 |
||
2735 |
#------------------------------------------------------------------------------- |
|
2736 |
# Create Pou Action Dialog |
|
2737 |
#------------------------------------------------------------------------------- |
|
2738 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2739 |
[ID_POUACTIONDIALOG, ID_POUACTIONDIALOGACTIONNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2740 |
ID_POUACTIONDIALOGLANGUAGE, ID_POUACTIONDIALOGSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2741 |
ID_POUACTIONDIALOGSTATICTEXT2, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2742 |
] = [wx.NewId() for _init_ctrls in range(5)] |
0 | 2743 |
|
2744 |
class PouActionDialog(wx.Dialog): |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2745 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2746 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2747 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2748 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2749 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2750 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2751 |
|
0 | 2752 |
def _init_coll_flexGridSizer1_Items(self, parent): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2753 |
parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2754 |
parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2755 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2756 |
def _init_coll_flexGridSizer1_Growables(self, parent): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2757 |
parent.AddGrowableCol(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2758 |
parent.AddGrowableRow(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2759 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2760 |
def _init_coll_MainSizer_Items(self, parent): |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
2761 |
parent.AddWindow(self.staticText1, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2762 |
parent.AddWindow(self.ActionName, 0, border=0, flag=wx.GROW) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
2763 |
parent.AddWindow(self.staticText2, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2764 |
parent.AddWindow(self.Language, 0, border=0, flag=wx.GROW) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2765 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2766 |
def _init_coll_MainSizer_Growables(self, parent): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2767 |
parent.AddGrowableCol(1) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2768 |
|
0 | 2769 |
def _init_sizers(self): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2770 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2771 |
self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=2, vgap=15) |
0 | 2772 |
|
2773 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2774 |
self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2775 |
self._init_coll_MainSizer_Items(self.MainSizer) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2776 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
0 | 2777 |
|
2778 |
self.SetSizer(self.flexGridSizer1) |
|
2779 |
||
2780 |
def _init_ctrls(self, prnt): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2781 |
wx.Dialog.__init__(self, id=ID_POUACTIONDIALOG, |
45 | 2782 |
name='PouActionDialog', parent=prnt, pos=wx.Point(376, 223), |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2783 |
size=wx.Size(320, 200), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER, |
45 | 2784 |
title='Create a new action') |
2785 |
self.SetClientSize(wx.Size(320, 160)) |
|
0 | 2786 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2787 |
self.staticText1 = wx.StaticText(id=ID_POUACTIONDIALOGSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2788 |
label='Action Name:', name='staticText1', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2789 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2790 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2791 |
self.ActionName = wx.TextCtrl(id=ID_POUACTIONDIALOGACTIONNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2792 |
name='ActionName', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2793 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2794 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2795 |
self.staticText2 = wx.StaticText(id=ID_POUACTIONDIALOGSTATICTEXT2, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2796 |
label='Language:', name='staticText2', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2797 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2798 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2799 |
self.Language = wx.Choice(id=ID_POUACTIONDIALOGLANGUAGE, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2800 |
name='Language', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2801 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2802 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2803 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2804 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2805 |
|
0 | 2806 |
self._init_sizers() |
2807 |
||
2808 |
def __init__(self, parent): |
|
2809 |
self._init_ctrls(parent) |
|
45 | 2810 |
|
0 | 2811 |
for option in ["IL","ST","LD","FBD"]: |
2812 |
self.Language.Append(option) |
|
2813 |
||
70 | 2814 |
self.PouNames = [] |
2815 |
self.PouElementNames = [] |
|
2816 |
||
0 | 2817 |
def OnOK(self, event): |
2818 |
error = [] |
|
70 | 2819 |
action_name = self.ActionName.GetValue() |
2820 |
if action_name == "": |
|
0 | 2821 |
error.append("Action Name") |
2822 |
if self.Language.GetStringSelection() == "": |
|
2823 |
error.append("Language") |
|
2824 |
if len(error) > 0: |
|
2825 |
text = "" |
|
2826 |
for i, item in enumerate(error): |
|
2827 |
if i == 0: |
|
2828 |
text += item |
|
2829 |
elif i == len(error) - 1: |
|
2830 |
text += " and %s"%item |
|
2831 |
else: |
|
2832 |
text += ", %s"%item |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2833 |
message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR) |
0 | 2834 |
message.ShowModal() |
2835 |
message.Destroy() |
|
70 | 2836 |
elif not TestIdentifier(action_name): |
2837 |
message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%action_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2838 |
message.ShowModal() |
|
2839 |
message.Destroy() |
|
2840 |
elif action_name.upper() in IEC_KEYWORDS: |
|
2841 |
message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%action_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2842 |
message.ShowModal() |
|
2843 |
message.Destroy() |
|
2844 |
elif action_name.upper() in self.PouNames: |
|
2845 |
message = wx.MessageDialog(self, "A pou with \"%s\" for name exists!"%action_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2846 |
message.ShowModal() |
|
2847 |
message.Destroy() |
|
2848 |
elif action_name.upper() in self.PouElementNames: |
|
2849 |
message = wx.MessageDialog(self, "\"%s\" element for this pou already exists!"%action_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2850 |
message.ShowModal() |
|
2851 |
message.Destroy() |
|
0 | 2852 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2853 |
self.EndModal(wx.ID_OK) |
70 | 2854 |
|
2855 |
def SetPouNames(self, pou_names): |
|
2856 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
2857 |
||
2858 |
def SetPouElementNames(self, element_names): |
|
2859 |
self.PouElementNames = [element_name.upper() for element_name in element_names] |
|
2860 |
||
0 | 2861 |
def SetValues(self, values): |
2862 |
for item, value in values.items(): |
|
45 | 2863 |
if item == "actionName": |
0 | 2864 |
self.ActionName.SetValue(value) |
2865 |
elif item == "language": |
|
2866 |
self.Language.SetStringSelection(value) |
|
2867 |
||
2868 |
def GetValues(self): |
|
2869 |
values = {} |
|
2870 |
values["actionName"] = self.ActionName.GetValue() |
|
2871 |
values["language"] = self.Language.GetStringSelection() |
|
2872 |
return values |
|
2873 |
||
2874 |
#------------------------------------------------------------------------------- |
|
80 | 2875 |
# Configuration Name Dialog |
2876 |
#------------------------------------------------------------------------------- |
|
2877 |
||
2878 |
class ConfigurationNameDialog(wx.TextEntryDialog): |
|
2879 |
||
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2880 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2881 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2882 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2883 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2884 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2885 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2886 |
|
80 | 2887 |
def __init__(self, parent, message, caption = "Please enter configuration name", defaultValue = "", |
2888 |
style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): |
|
2889 |
wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
|
2890 |
||
2891 |
self.PouNames = [] |
|
2892 |
self.PouElementNames = [] |
|
2893 |
||
144 | 2894 |
if wx.VERSION >= (2, 8, 0): |
2895 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId()) |
|
2896 |
elif wx.VERSION >= (2, 6, 0): |
|
2897 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) |
|
2898 |
else: |
|
2899 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) |
|
2900 |
||
80 | 2901 |
def OnOK(self, event): |
2902 |
config_name = self.GetSizer().GetItem(1).GetWindow().GetValue() |
|
2903 |
if config_name == "": |
|
2904 |
message = wx.MessageDialog(self, "You must type a name!", "Error", wx.OK|wx.ICON_ERROR) |
|
2905 |
message.ShowModal() |
|
2906 |
message.Destroy() |
|
2907 |
elif not TestIdentifier(config_name): |
|
2908 |
message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%config_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2909 |
message.ShowModal() |
|
2910 |
message.Destroy() |
|
2911 |
elif config_name.upper() in IEC_KEYWORDS: |
|
2912 |
message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%config_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2913 |
message.ShowModal() |
|
2914 |
message.Destroy() |
|
2915 |
elif config_name.upper() in self.PouNames: |
|
2916 |
message = wx.MessageDialog(self, "A pou with \"%s\" as name exists!"%config_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2917 |
message.ShowModal() |
|
2918 |
message.Destroy() |
|
2919 |
elif config_name.upper() in self.PouElementNames: |
|
2920 |
message = wx.MessageDialog(self, "A pou has an element with \"%s\" for name. It can generate a conflict. Do you wish to continue?"%config_name, "Warning", wx.YES_NO|wx.ICON_EXCLAMATION) |
|
2921 |
result = message.ShowModal() |
|
2922 |
message.Destroy() |
|
2923 |
if result == wx.ID_YES: |
|
2924 |
self.EndModal(wx.ID_OK) |
|
2925 |
else: |
|
2926 |
self.EndModal(wx.ID_OK) |
|
2927 |
||
2928 |
def SetPouNames(self, pou_names): |
|
2929 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
2930 |
||
2931 |
def SetPouElementNames(self, pou_names): |
|
2932 |
self.PouElementNames = [pou_name.upper() for pou_name in pou_names] |
|
2933 |
||
2934 |
def GetValue(self): |
|
2935 |
return self.GetSizer().GetItem(1).GetWindow().GetValue() |
|
2936 |
||
2937 |
#------------------------------------------------------------------------------- |
|
2938 |
# Resource Name Dialog |
|
2939 |
#------------------------------------------------------------------------------- |
|
2940 |
||
2941 |
class ResourceNameDialog(wx.TextEntryDialog): |
|
2942 |
||
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2943 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2944 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2945 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2946 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2947 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2948 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2949 |
|
80 | 2950 |
def __init__(self, parent, message, caption = "Please enter resource name", defaultValue = "", |
2951 |
style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): |
|
2952 |
wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
|
2953 |
||
2954 |
self.PouNames = [] |
|
2955 |
self.PouElementNames = [] |
|
2956 |
||
144 | 2957 |
if wx.VERSION >= (2, 8, 0): |
2958 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId()) |
|
2959 |
elif wx.VERSION >= (2, 6, 0): |
|
2960 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) |
|
2961 |
else: |
|
2962 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) |
|
2963 |
||
80 | 2964 |
def OnOK(self, event): |
2965 |
resource_name = self.GetSizer().GetItem(1).GetWindow().GetValue() |
|
2966 |
if resource_name == "": |
|
2967 |
message = wx.MessageDialog(self, "You must type a name!", "Error", wx.OK|wx.ICON_ERROR) |
|
2968 |
message.ShowModal() |
|
2969 |
message.Destroy() |
|
2970 |
elif not TestIdentifier(resource_name): |
|
2971 |
message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%resource_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2972 |
message.ShowModal() |
|
2973 |
message.Destroy() |
|
2974 |
elif resource_name.upper() in IEC_KEYWORDS: |
|
2975 |
message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%resource_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2976 |
message.ShowModal() |
|
2977 |
message.Destroy() |
|
2978 |
elif resource_name.upper() in self.PouNames: |
|
2979 |
message = wx.MessageDialog(self, "A pou with \"%s\" as name exists!"%resource_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2980 |
message.ShowModal() |
|
2981 |
message.Destroy() |
|
2982 |
elif resource_name.upper() in self.PouElementNames: |
|
2983 |
message = wx.MessageDialog(self, "A pou has an element with \"%s\" for name. It can generate a conflict. Do you wish to continue?"%resource_name, "Warning", wx.YES_NO|wx.ICON_EXCLAMATION) |
|
2984 |
result = message.ShowModal() |
|
2985 |
message.Destroy() |
|
2986 |
if result == wx.ID_YES: |
|
2987 |
self.EndModal(wx.ID_OK) |
|
2988 |
else: |
|
2989 |
self.EndModal(wx.ID_OK) |
|
2990 |
||
2991 |
def SetPouNames(self, pou_names): |
|
2992 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
2993 |
||
2994 |
def SetPouElementNames(self, pou_names): |
|
2995 |
self.PouElementNames = [pou_name.upper() for pou_name in pou_names] |
|
2996 |
||
2997 |
def GetValue(self): |
|
2998 |
return self.GetSizer().GetItem(1).GetWindow().GetValue() |
|
2999 |
||
3000 |
#------------------------------------------------------------------------------- |
|
121 | 3001 |
# Variables Editor Panel |
3002 |
#------------------------------------------------------------------------------- |
|
3003 |
||
3004 |
class VariablePanelIndexer(wx.Panel): |
|
3005 |
||
3006 |
def _init_sizers(self): |
|
3007 |
self.MainSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
3008 |
||
3009 |
self.SetSizer(self.MainSizer) |
|
3010 |
||
3011 |
def _init_ctrls(self, prnt): |
|
3012 |
wx.Panel.__init__(self, id=wx.NewId(), |
|
3013 |
name='VariablePanelIndexer', parent=prnt, pos=wx.Point(0, 0), |
|
3014 |
size=wx.Size(0, 300), style=wx.TAB_TRAVERSAL) |
|
3015 |
||
3016 |
self._init_sizers() |
|
3017 |
||
145 | 3018 |
def __init__(self, parent, window, controler): |
121 | 3019 |
self._init_ctrls(parent) |
3020 |
||
145 | 3021 |
self.ParentWindow = window |
121 | 3022 |
self.Controler = controler |
3023 |
||
3024 |
self.VariablePanelList = {} |
|
3025 |
self.CurrentPanel = None |
|
3026 |
||
3027 |
def AddVariablePanel(self, tagname, element_type): |
|
3028 |
new_panel = VariablePanel(self, self.ParentWindow, self.Controler, element_type) |
|
3029 |
new_panel.SetTagName(tagname) |
|
3030 |
new_panel.Hide() |
|
3031 |
new_panel.RefreshView() |
|
3032 |
self.MainSizer.AddWindow(new_panel, 1, border=0, flag=wx.GROW) |
|
3033 |
self.VariablePanelList[tagname] = new_panel |
|
3034 |
||
3035 |
def RemoveVariablePanel(self, tagname): |
|
3036 |
if tagname in self.VariablePanelList: |
|
3037 |
panel = self.VariablePanelList.pop(tagname) |
|
3038 |
panel.Hide() |
|
3039 |
self.MainSizer.Remove(panel) |
|
3040 |
if self.CurrentPanel == tagname: |
|
3041 |
self.CurrentPanel = None |
|
3042 |
||
3043 |
def RemoveAllPanels(self): |
|
3044 |
if self.CurrentPanel is not None and self.CurrentPanel in self.VariablePanelList: |
|
3045 |
self.VariablePanelList[self.CurrentPanel].Hide() |
|
3046 |
self.VariablePanelList = {} |
|
3047 |
self.MainSizer.Clear() |
|
3048 |
self.CurrentPanel = None |
|
3049 |
||
3050 |
def UpdateVariablePanelTagName(self, old_tagname, new_tagname): |
|
145 | 3051 |
if old_tagname in self.VariablePanelList: |
121 | 3052 |
self.VariablePanelList[new_tagname] = self.VariablePanelList.pop(old_tagname) |
3053 |
if self.CurrentPanel == old_tagname: |
|
3054 |
self.CurrentPanel = new_tagname |
|
3055 |
||
3056 |
def ChangeVariablePanel(self, tagname): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3057 |
if tagname in self.VariablePanelList: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3058 |
if tagname != self.CurrentPanel: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3059 |
if self.CurrentPanel is not None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3060 |
self.VariablePanelList[self.CurrentPanel].Hide() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3061 |
self.CurrentPanel = tagname |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3062 |
self.VariablePanelList[self.CurrentPanel].RefreshView() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3063 |
self.VariablePanelList[self.CurrentPanel].Show() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3064 |
self.MainSizer.Layout() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3065 |
else: |
121 | 3066 |
if self.CurrentPanel is not None: |
3067 |
self.VariablePanelList[self.CurrentPanel].Hide() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3068 |
self.CurrentPanel = None |
121 | 3069 |
self.MainSizer.Layout() |
3070 |
||
3071 |
def RefreshVariablePanel(self, tagname): |
|
3072 |
if tagname in self.VariablePanelList: |
|
3073 |
self.VariablePanelList[self.CurrentPanel].RefreshView() |
|
3074 |
||
3075 |
#------------------------------------------------------------------------------- |
|
3076 |
# Variables Editor Panel |
|
0 | 3077 |
#------------------------------------------------------------------------------- |
3078 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3079 |
class VariableTable(wx.grid.PyGridTableBase): |
0 | 3080 |
|
3081 |
""" |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3082 |
A custom wx.grid.Grid Table using user supplied data |
0 | 3083 |
""" |
3084 |
def __init__(self, parent, data, colnames): |
|
3085 |
# The base class must be initialized *first* |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3086 |
wx.grid.PyGridTableBase.__init__(self) |
0 | 3087 |
self.data = data |
58 | 3088 |
self.old_value = None |
0 | 3089 |
self.colnames = colnames |
3090 |
self.Parent = parent |
|
3091 |
# XXX |
|
3092 |
# we need to store the row length and collength to |
|
3093 |
# see if the table has changed size |
|
3094 |
self._rows = self.GetNumberRows() |
|
3095 |
self._cols = self.GetNumberCols() |
|
3096 |
||
3097 |
def GetNumberCols(self): |
|
3098 |
return len(self.colnames) |
|
3099 |
||
3100 |
def GetNumberRows(self): |
|
3101 |
return len(self.data) |
|
3102 |
||
3103 |
def GetColLabelValue(self, col): |
|
3104 |
if col < len(self.colnames): |
|
3105 |
return self.colnames[col] |
|
3106 |
||
3107 |
def GetRowLabelValues(self, row): |
|
3108 |
return row |
|
3109 |
||
3110 |
def GetValue(self, row, col): |
|
3111 |
if row < self.GetNumberRows(): |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3112 |
if col == 0: |
80 | 3113 |
return self.data[row]["Number"] |
0 | 3114 |
name = str(self.data[row].get(self.GetColLabelValue(col), "")) |
3115 |
return name |
|
3116 |
||
3117 |
def SetValue(self, row, col, value): |
|
3118 |
if col < len(self.colnames): |
|
58 | 3119 |
colname = self.GetColLabelValue(col) |
3120 |
if colname == "Name": |
|
3121 |
self.old_value = self.data[row][colname] |
|
3122 |
self.data[row][colname] = value |
|
3123 |
||
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3124 |
def GetValueByName(self, row, colname): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3125 |
if row < self.GetNumberRows(): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3126 |
return self.data[row].get(colname) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3127 |
|
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3128 |
def SetValueByName(self, row, colname, value): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3129 |
if row < self.GetNumberRows(): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3130 |
self.data[row][colname] = value |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3131 |
|
58 | 3132 |
def GetOldValue(self): |
3133 |
return self.old_value |
|
3134 |
||
0 | 3135 |
def ResetView(self, grid): |
3136 |
""" |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3137 |
(wx.grid.Grid) -> Reset the grid view. Call this to |
0 | 3138 |
update the grid if rows and columns have been added or deleted |
3139 |
""" |
|
3140 |
grid.BeginBatch() |
|
3141 |
for current, new, delmsg, addmsg in [ |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3142 |
(self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3143 |
(self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), |
0 | 3144 |
]: |
3145 |
if new < current: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3146 |
msg = wx.grid.GridTableMessage(self,delmsg,new,current-new) |
0 | 3147 |
grid.ProcessTableMessage(msg) |
3148 |
elif new > current: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3149 |
msg = wx.grid.GridTableMessage(self,addmsg,new-current) |
0 | 3150 |
grid.ProcessTableMessage(msg) |
3151 |
self.UpdateValues(grid) |
|
3152 |
grid.EndBatch() |
|
3153 |
||
3154 |
self._rows = self.GetNumberRows() |
|
3155 |
self._cols = self.GetNumberCols() |
|
3156 |
# update the column rendering scheme |
|
3157 |
self._updateColAttrs(grid) |
|
3158 |
||
3159 |
# update the scrollbars and the displayed part of the grid |
|
3160 |
grid.AdjustScrollbars() |
|
3161 |
grid.ForceRefresh() |
|
3162 |
||
3163 |
def UpdateValues(self, grid): |
|
3164 |
"""Update all displayed values""" |
|
3165 |
# This sends an event to the grid table to update all of the values |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3166 |
msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) |
0 | 3167 |
grid.ProcessTableMessage(msg) |
3168 |
||
3169 |
def _updateColAttrs(self, grid): |
|
3170 |
""" |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3171 |
wx.grid.Grid -> update the column attributes to add the |
0 | 3172 |
appropriate renderer given the column name. |
3173 |
||
3174 |
Otherwise default to the default renderer. |
|
3175 |
""" |
|
3176 |
||
3177 |
typelist = None |
|
3178 |
accesslist = None |
|
3179 |
for row in range(self.GetNumberRows()): |
|
3180 |
for col in range(self.GetNumberCols()): |
|
3181 |
editor = None |
|
3182 |
renderer = None |
|
3183 |
colname = self.GetColLabelValue(col) |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3184 |
if col != 0 and self.GetValueByName(row, "Edit"): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3185 |
grid.SetReadOnly(row, col, False) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3186 |
if colname == "Name": |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3187 |
if self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3188 |
grid.SetReadOnly(row, col, True) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3189 |
else: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3190 |
editor = wx.grid.GridCellTextEditor() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3191 |
renderer = wx.grid.GridCellStringRenderer() |
107 | 3192 |
elif colname == "Initial Value": |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3193 |
editor = wx.grid.GridCellTextEditor() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3194 |
renderer = wx.grid.GridCellStringRenderer() |
107 | 3195 |
elif colname == "Location": |
3196 |
if self.GetValueByName(row, "Class") in ["Local", "Global"]: |
|
3197 |
editor = wx.grid.GridCellTextEditor() |
|
3198 |
renderer = wx.grid.GridCellStringRenderer() |
|
3199 |
else: |
|
3200 |
grid.SetReadOnly(row, col, True) |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3201 |
elif colname == "Class": |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3202 |
if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3203 |
grid.SetReadOnly(row, col, True) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3204 |
else: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3205 |
editor = wx.grid.GridCellChoiceEditor() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3206 |
excluded = [] |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3207 |
if self.Parent.PouIsUsed: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3208 |
excluded.extend(["Input","Output","InOut"]) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3209 |
editor.SetParameters(",".join([choice for choice in self.Parent.ClassList if choice not in excluded])) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3210 |
elif colname in ["Retain", "Constant"]: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3211 |
editor = wx.grid.GridCellChoiceEditor() |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3212 |
editor.SetParameters(self.Parent.OptionList) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3213 |
elif colname == "Type": |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3214 |
editor = wx.grid.GridCellTextEditor() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3215 |
else: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3216 |
grid.SetReadOnly(row, col, True) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3217 |
|
0 | 3218 |
grid.SetCellEditor(row, col, editor) |
3219 |
grid.SetCellRenderer(row, col, renderer) |
|
3220 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3221 |
grid.SetCellBackgroundColour(row, col, wx.WHITE) |
0 | 3222 |
|
3223 |
def SetData(self, data): |
|
3224 |
self.data = data |
|
3225 |
||
3226 |
def GetData(self): |
|
3227 |
return self.data |
|
3228 |
||
3229 |
def GetCurrentIndex(self): |
|
3230 |
return self.CurrentIndex |
|
3231 |
||
3232 |
def SetCurrentIndex(self, index): |
|
3233 |
self.CurrentIndex = index |
|
3234 |
||
3235 |
def AppendRow(self, row_content): |
|
3236 |
self.data.append(row_content) |
|
3237 |
||
3238 |
def RemoveRow(self, row_index): |
|
3239 |
self.data.pop(row_index) |
|
12 | 3240 |
|
3241 |
def GetRow(self, row_index): |
|
3242 |
return self.data[row_index] |
|
0 | 3243 |
|
3244 |
def Empty(self): |
|
3245 |
self.data = [] |
|
3246 |
self.editors = [] |
|
3247 |
||
53 | 3248 |
class VariableDropTarget(wx.TextDropTarget): |
3249 |
||
3250 |
def __init__(self, parent): |
|
3251 |
wx.TextDropTarget.__init__(self) |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
3252 |
self.ParentWindow = parent |
53 | 3253 |
|
3254 |
def OnDropText(self, x, y, data): |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
3255 |
col = self.ParentWindow.VariablesGrid.XToCol(x) |
97 | 3256 |
row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize()) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3257 |
if col != wx.NOT_FOUND and row != wx.NOT_FOUND: |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
3258 |
if self.ParentWindow.Table.GetColLabelValue(col) != "Location": |
53 | 3259 |
return |
107 | 3260 |
message = None |
3261 |
if not self.ParentWindow.Table.GetValueByName(row, "Edit"): |
|
3262 |
message = "Can't affect a location to a function block instance" |
|
3263 |
elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]: |
|
3264 |
message = "Can affect a location only to local or global variables" |
|
3265 |
else: |
|
3266 |
try: |
|
3267 |
values = eval(data) |
|
3268 |
except: |
|
3269 |
values = None |
|
3270 |
if values and values[1] == "location": |
|
3271 |
location = values[0] |
|
3272 |
variable_type = self.ParentWindow.Table.GetValueByName(row, "Type") |
|
3273 |
message = None |
|
3274 |
if location[0].isdigit() and variable_type != "BOOL": |
|
3275 |
message = "Incompatible size of data between \"%s\" and \"BOOL\""%location |
|
3276 |
elif location[0] not in LOCATIONDATATYPES: |
|
3277 |
message = "Unrecognized data size \"%s\""%location[0] |
|
3278 |
elif variable_type not in LOCATIONDATATYPES[location[0]]: |
|
3279 |
message = "Incompatible size of data between \"%s\" and \"%s\""%(location, variable_type) |
|
53 | 3280 |
else: |
107 | 3281 |
dialog = wx.SingleChoiceDialog(self.ParentWindow, "Select a variable class:", "Variable class", ["Input", "Output", "Memory"], wx.OK|wx.CANCEL) |
3282 |
if dialog.ShowModal() == wx.ID_OK: |
|
3283 |
selected = dialog.GetSelection() |
|
3284 |
if selected == 0: |
|
3285 |
location = "%I" + location |
|
3286 |
elif selected == 1: |
|
3287 |
location = "%Q" + location |
|
3288 |
else: |
|
3289 |
location = "%M" + location |
|
3290 |
self.ParentWindow.Table.SetValue(row, col, location) |
|
3291 |
self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid) |
|
3292 |
self.ParentWindow.SaveValues() |
|
3293 |
dialog.Destroy() |
|
3294 |
if message is not None: |
|
3295 |
message = wx.MessageDialog(self.ParentWindow, message, "Error", wx.OK|wx.ICON_ERROR) |
|
3296 |
message.ShowModal() |
|
3297 |
message.Destroy() |
|
53 | 3298 |
|
121 | 3299 |
[ID_VARIABLEEDITORPANEL, ID_VARIABLEEDITORPANELVARIABLESGRID, |
3300 |
ID_VARIABLEEDITORPANELRETURNTYPE, ID_VARIABLEEDITORPANELCLASSFILTER, |
|
3301 |
ID_VARIABLEEDITORPANELADDBUTTON, ID_VARIABLEEDITORPANELDELETEBUTTON, |
|
3302 |
ID_VARIABLEEDITORPANELUPBUTTON, ID_VARIABLEEDITORPANELDOWNBUTTON, |
|
3303 |
ID_VARIABLEEDITORPANELSTATICTEXT1, ID_VARIABLEEDITORPANELSTATICTEXT2, |
|
3304 |
ID_VARIABLEEDITORPANELSTATICTEXT3, |
|
3305 |
] = [wx.NewId() for _init_ctrls in range(11)] |
|
3306 |
||
3307 |
class VariablePanel(wx.Panel): |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3308 |
|
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3309 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3310 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3311 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3312 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3313 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3314 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3315 |
|
121 | 3316 |
def _init_coll_MainSizer_Items(self, parent): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3317 |
parent.AddWindow(self.VariablesGrid, 0, border=0, flag=wx.GROW) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3318 |
parent.AddSizer(self.ControlPanelSizer, 0, border=0, flag=wx.GROW) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3319 |
|
121 | 3320 |
def _init_coll_MainSizer_Growables(self, parent): |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3321 |
parent.AddGrowableCol(0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3322 |
parent.AddGrowableRow(0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3323 |
|
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3324 |
def _init_coll_ControlPanelSizer_Items(self, parent): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3325 |
parent.AddSizer(self.ChoicePanelSizer, 0, border=0, flag=wx.GROW) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3326 |
parent.AddSizer(self.ButtonPanelSizer, 0, border=0, flag=wx.ALIGN_CENTER) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3327 |
|
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3328 |
def _init_coll_ControlPanelSizer_Growables(self, parent): |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3329 |
parent.AddGrowableCol(0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3330 |
parent.AddGrowableRow(0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3331 |
parent.AddGrowableRow(1) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3332 |
|
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3333 |
def _init_coll_ChoicePanelSizer_Items(self, parent): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3334 |
parent.AddWindow(self.staticText1, 0, border=0, flag=wx.ALIGN_BOTTOM) |
52 | 3335 |
parent.AddWindow(self.ReturnType, 0, border=0, flag=0) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3336 |
parent.AddWindow(self.staticText2, 0, border=0, flag=wx.ALIGN_BOTTOM) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3337 |
parent.AddWindow(self.ClassFilter, 0, border=0, flag=0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3338 |
|
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3339 |
def _init_coll_ButtonPanelSizer_Items(self, parent): |
52 | 3340 |
parent.AddWindow(self.UpButton, 0, border=0, flag=0) |
51 | 3341 |
parent.AddWindow(self.AddButton, 0, border=0, flag=0) |
52 | 3342 |
parent.AddWindow(self.DownButton, 0, border=0, flag=0) |
51 | 3343 |
parent.AddWindow(self.DeleteButton, 0, border=0, flag=0) |
52 | 3344 |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3345 |
def _init_coll_ButtonPanelSizer_Growables(self, parent): |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3346 |
parent.AddGrowableCol(0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3347 |
parent.AddGrowableCol(1) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3348 |
parent.AddGrowableCol(2) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3349 |
parent.AddGrowableCol(3) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3350 |
parent.AddGrowableRow(0) |
0 | 3351 |
|
3352 |
def _init_sizers(self): |
|
121 | 3353 |
self.MainSizer = wx.FlexGridSizer(cols=2, hgap=10, rows=1, vgap=0) |
52 | 3354 |
self.ControlPanelSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
3355 |
self.ChoicePanelSizer = wx.GridSizer(cols=1, hgap=5, rows=4, vgap=5) |
|
3356 |
self.ButtonPanelSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=0) |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3357 |
|
121 | 3358 |
self._init_coll_MainSizer_Items(self.MainSizer) |
3359 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3360 |
self._init_coll_ControlPanelSizer_Items(self.ControlPanelSizer) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3361 |
self._init_coll_ControlPanelSizer_Growables(self.ControlPanelSizer) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3362 |
self._init_coll_ChoicePanelSizer_Items(self.ChoicePanelSizer) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3363 |
self._init_coll_ButtonPanelSizer_Items(self.ButtonPanelSizer) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3364 |
self._init_coll_ButtonPanelSizer_Growables(self.ButtonPanelSizer) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3365 |
|
121 | 3366 |
self.SetSizer(self.MainSizer) |
3367 |
||
3368 |
def _init_ctrls(self, prnt): |
|
3369 |
wx.Panel.__init__(self, id=ID_VARIABLEEDITORPANEL, |
|
3370 |
name='VariableEditorPanel', parent=prnt, pos=wx.Point(0, 0), |
|
80 | 3371 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3372 |
|
121 | 3373 |
self.staticText1 = wx.StaticText(id=ID_VARIABLEEDITORPANELSTATICTEXT1, |
3374 |
label='Return Type:', name='staticText1', parent=self, |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3375 |
pos=wx.Point(0, 0), size=wx.Size(95, 17), style=0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3376 |
|
121 | 3377 |
self.ReturnType = wx.Choice(id=ID_VARIABLEEDITORPANELRETURNTYPE, |
3378 |
name='ReturnType', parent=self, pos=wx.Point(0, 0), |
|
52 | 3379 |
size=wx.Size(145, 24), style=0) |
121 | 3380 |
self.Bind(wx.EVT_CHOICE, self.OnReturnTypeChanged, id=ID_VARIABLEEDITORPANELRETURNTYPE) |
3381 |
||
3382 |
self.staticText2 = wx.StaticText(id=ID_VARIABLEEDITORPANELSTATICTEXT2, |
|
3383 |
label='Class Filter:', name='staticText2', parent=self, |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3384 |
pos=wx.Point(0, 0), size=wx.Size(95, 17), style=0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3385 |
|
121 | 3386 |
self.ClassFilter = wx.Choice(id=ID_VARIABLEEDITORPANELCLASSFILTER, |
3387 |
name='ClassFilter', parent=self, pos=wx.Point(0, 0), |
|
52 | 3388 |
size=wx.Size(145, 24), style=0) |
121 | 3389 |
self.Bind(wx.EVT_CHOICE, self.OnClassFilter, id=ID_VARIABLEEDITORPANELCLASSFILTER) |
3390 |
||
3391 |
self.VariablesGrid = wx.grid.Grid(id=ID_VARIABLEEDITORPANELVARIABLESGRID, |
|
3392 |
name='VariablesGrid', parent=self, pos=wx.Point(0, 0), |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3393 |
size=wx.Size(0, 150), style=wx.VSCROLL) |
0 | 3394 |
self.VariablesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
3395 |
'Sans')) |
|
3396 |
self.VariablesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
3397 |
False, 'Sans')) |
|
107 | 3398 |
self.VariablesGrid.SetSelectionBackground(wx.WHITE) |
3399 |
self.VariablesGrid.SetSelectionForeground(wx.BLACK) |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3400 |
if wx.VERSION >= (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3401 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3402 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnVariablesGridSelectCell) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3403 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3404 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3405 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3406 |
wx.grid.EVT_GRID_CELL_CHANGE(self.VariablesGrid, self.OnVariablesGridCellChange) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3407 |
wx.grid.EVT_GRID_SELECT_CELL(self.VariablesGrid, self.OnVariablesGridSelectCell) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3408 |
wx.grid.EVT_GRID_CELL_LEFT_CLICK(self.VariablesGrid, self.OnVariablesGridCellLeftClick) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3409 |
wx.grid.EVT_GRID_EDITOR_SHOWN(self.VariablesGrid, self.OnVariablesGridEditorShown) |
53 | 3410 |
self.VariablesGrid.SetDropTarget(VariableDropTarget(self)) |
3411 |
||
121 | 3412 |
self.AddButton = wx.Button(id=ID_VARIABLEEDITORPANELADDBUTTON, label='Add', |
3413 |
name='AddButton', parent=self, pos=wx.Point(345, 340), |
|
0 | 3414 |
size=wx.Size(72, 32), style=0) |
121 | 3415 |
self.Bind(wx.EVT_BUTTON, self.OnAddButton, id=ID_VARIABLEEDITORPANELADDBUTTON) |
3416 |
||
3417 |
self.DeleteButton = wx.Button(id=ID_VARIABLEEDITORPANELDELETEBUTTON, label='Delete', |
|
3418 |
name='DeleteButton', parent=self, pos=wx.Point(425, 340), |
|
0 | 3419 |
size=wx.Size(72, 32), style=0) |
121 | 3420 |
self.Bind(wx.EVT_BUTTON, self.OnDeleteButton, id=ID_VARIABLEEDITORPANELDELETEBUTTON) |
3421 |
||
3422 |
self.UpButton = wx.Button(id=ID_VARIABLEEDITORPANELUPBUTTON, label='^', |
|
3423 |
name='UpButton', parent=self, pos=wx.Point(505, 340), |
|
0 | 3424 |
size=wx.Size(32, 32), style=0) |
121 | 3425 |
self.Bind(wx.EVT_BUTTON, self.OnUpButton, id=ID_VARIABLEEDITORPANELUPBUTTON) |
3426 |
||
3427 |
self.DownButton = wx.Button(id=ID_VARIABLEEDITORPANELDOWNBUTTON, label='v', |
|
3428 |
name='DownButton', parent=self, pos=wx.Point(545, 340), |
|
0 | 3429 |
size=wx.Size(32, 32), style=0) |
121 | 3430 |
self.Bind(wx.EVT_BUTTON, self.OnDownButton, id=ID_VARIABLEEDITORPANELDOWNBUTTON) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3431 |
|
0 | 3432 |
self._init_sizers() |
3433 |
||
121 | 3434 |
def __init__(self, parent, window, controler, element_type): |
3435 |
self._init_ctrls(parent) |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
3436 |
self.ParentWindow = window |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3437 |
self.Controler = controler |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3438 |
self.ElementType = element_type |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3439 |
|
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3440 |
self.Filter = "All" |
0 | 3441 |
self.FilterChoices = [] |
3442 |
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
|
3443 |
" Input" : "Input", " Output" : "Output", " InOut" : "InOut", |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3444 |
" External" : "External", "Variables" : "Variables", " Local" : "Local", |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3445 |
" Temp" : "Temp", "Global" : "Global", "Access" : "Access"} |
0 | 3446 |
|
121 | 3447 |
if element_type in ["config", "resource"]: |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3448 |
self.DefaultTypes = {"All" : "Global"} |
80 | 3449 |
self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No", "Edit" : True} |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3450 |
else: |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3451 |
self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"} |
80 | 3452 |
self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No", "Edit" : True} |
121 | 3453 |
if element_type in ["config", "resource"] or element_type in ["program", "transition", "action"]: |
70 | 3454 |
self.Table = VariableTable(self, [], ["#", "Name", "Class", "Type", "Location", "Initial Value", "Retain", "Constant"]) |
121 | 3455 |
if element_type not in ["config", "resource"]: |
0 | 3456 |
self.FilterChoices = ["All","Interface"," Input"," Output"," InOut"," External","Variables"," Local"," Temp","Global","Access"] |
3457 |
else: |
|
3458 |
self.FilterChoices = ["All","Global","Access"] |
|
70 | 3459 |
self.ColSizes = [40, 80, 70, 80, 80, 80, 60, 70] |
3460 |
self.ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_CENTER] |
|
3461 |
else: |
|
3462 |
self.Table = VariableTable(self, [], ["#", "Name", "Class", "Type", "Initial Value", "Retain", "Constant"]) |
|
0 | 3463 |
self.FilterChoices = ["All","Interface"," Input"," Output"," InOut"," External","Variables"," Local"," Temp"] |
70 | 3464 |
self.ColSizes = [40, 120, 70, 80, 120, 60, 70] |
3465 |
self.ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_CENTER] |
|
0 | 3466 |
for choice in self.FilterChoices: |
3467 |
self.ClassFilter.Append(choice) |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3468 |
reverse_transfer = {} |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3469 |
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
|
3470 |
reverse_transfer[choice] = filter |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3471 |
self.ClassFilter.SetStringSelection(reverse_transfer[self.Filter]) |
0 | 3472 |
self.RefreshTypeList() |
3473 |
||
3474 |
self.OptionList = "Yes,No" |
|
3475 |
||
121 | 3476 |
if element_type == "function": |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3477 |
for base_type in self.Controler.GetBaseTypes(): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3478 |
self.ReturnType.Append(base_type) |
0 | 3479 |
self.ReturnType.Enable(True) |
3480 |
else: |
|
3481 |
self.ReturnType.Enable(False) |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3482 |
self.staticText1.Hide() |
0 | 3483 |
self.ReturnType.Hide() |
3484 |
||
3485 |
self.VariablesGrid.SetTable(self.Table) |
|
3486 |
self.VariablesGrid.SetRowLabelSize(0) |
|
107 | 3487 |
for col in range(self.Table.GetNumberCols()): |
3488 |
attr = wx.grid.GridCellAttr() |
|
3489 |
attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
|
3490 |
self.VariablesGrid.SetColAttr(col, attr) |
|
3491 |
self.VariablesGrid.SetColSize(col, self.ColSizes[col]) |
|
3492 |
||
121 | 3493 |
def SetTagName(self, tagname): |
3494 |
self.TagName = tagname |
|
3495 |
||
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3496 |
def RefreshView(self): |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3497 |
self.PouNames = self.Controler.GetProjectPouNames() |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3498 |
|
121 | 3499 |
words = self.TagName.split("::") |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3500 |
if self.ElementType == "config": |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3501 |
self.PouIsUsed = False |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3502 |
returnType = None |
121 | 3503 |
self.Values = self.Controler.GetConfigurationGlobalVars(words[1]) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3504 |
elif self.ElementType == "resource": |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3505 |
self.PouIsUsed = False |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3506 |
returnType = None |
121 | 3507 |
self.Values = self.Controler.GetConfigurationResourceGlobalVars(words[1], words[2]) |
3508 |
else: |
|
3509 |
self.PouIsUsed = self.Controler.PouIsUsed(words[1]) |
|
3510 |
returnType = self.Controler.GetEditedElementInterfaceReturnType(self.TagName) |
|
3511 |
self.Values = self.Controler.GetEditedElementInterfaceVars(self.TagName) |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3512 |
|
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3513 |
if returnType and self.ReturnType.IsEnabled(): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3514 |
self.ReturnType.SetStringSelection(returnType) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3515 |
|
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3516 |
self.RefreshValues() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3517 |
self.RefreshButtons() |
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
65
diff
changeset
|
3518 |
|
80 | 3519 |
def OnReturnTypeChanged(self, event): |
121 | 3520 |
words = self.TagName.split("::") |
3521 |
self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection()) |
|
80 | 3522 |
self.Controler.BufferProject() |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
3523 |
self.ParentWindow.RefreshTitle() |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
3524 |
self.ParentWindow.RefreshEditMenu() |
80 | 3525 |
event.Skip() |
3526 |
||
0 | 3527 |
def OnClassFilter(self, event): |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3528 |
self.Filter = self.FilterChoiceTransfer[self.ClassFilter.GetStringSelection()] |
0 | 3529 |
self.RefreshTypeList() |
3530 |
self.RefreshValues() |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3531 |
self.RefreshButtons() |
0 | 3532 |
event.Skip() |
3533 |
||
3534 |
def RefreshTypeList(self): |
|
3535 |
if self.Filter == "All": |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3536 |
self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All","Interface","Variables"]] |
0 | 3537 |
elif self.Filter == "Interface": |
3538 |
self.ClassList = ["Input","Output","InOut","External"] |
|
3539 |
elif self.Filter == "Variables": |
|
3540 |
self.ClassList = ["Local","Temp"] |
|
3541 |
else: |
|
3542 |
self.ClassList = [self.Filter] |
|
3543 |
||
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3544 |
def RefreshButtons(self): |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
3545 |
if getattr(self, "Table", None): |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
3546 |
table_length = len(self.Table.data) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
3547 |
row_class = None |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
3548 |
if table_length and self.PouIsUsed: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
3549 |
row = self.VariablesGrid.GetGridCursorRow() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
3550 |
row_class = self.Table.GetValueByName(row, "Class") |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
3551 |
self.AddButton.Enable(not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
3552 |
self.DeleteButton.Enable(table_length > 0 and row_class not in ["Input", "Output", "InOut"]) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
3553 |
self.UpButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
3554 |
self.DownButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3555 |
|
0 | 3556 |
def OnAddButton(self, event): |
11 | 3557 |
new_row = self.DefaultValue.copy() |
3558 |
if self.Filter in self.DefaultTypes: |
|
3559 |
new_row["Class"] = self.DefaultTypes[self.Filter] |
|
3560 |
else: |
|
3561 |
new_row["Class"] = self.Filter |
|
12 | 3562 |
self.Values.append(new_row) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3563 |
self.SaveValues() |
12 | 3564 |
self.RefreshValues() |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3565 |
self.RefreshButtons() |
0 | 3566 |
event.Skip() |
3567 |
||
3568 |
def OnDeleteButton(self, event): |
|
12 | 3569 |
row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow()) |
3570 |
self.Values.remove(row) |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3571 |
self.SaveValues() |
12 | 3572 |
self.RefreshValues() |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3573 |
self.RefreshButtons() |
0 | 3574 |
event.Skip() |
3575 |
||
3576 |
def OnUpButton(self, event): |
|
12 | 3577 |
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
|
3578 |
self.RefreshButtons() |
0 | 3579 |
event.Skip() |
3580 |
||
3581 |
def OnDownButton(self, event): |
|
12 | 3582 |
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
|
3583 |
self.RefreshButtons() |
0 | 3584 |
event.Skip() |
3585 |
||
6 | 3586 |
def OnVariablesGridCellChange(self, event): |
3587 |
row, col = event.GetRow(), event.GetCol() |
|
3588 |
colname = self.Table.GetColLabelValue(col) |
|
3589 |
value = self.Table.GetValue(row, col) |
|
3590 |
if colname == "Name": |
|
3591 |
if not TestIdentifier(value): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3592 |
message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%value, "Error", wx.OK|wx.ICON_ERROR) |
6 | 3593 |
message.ShowModal() |
3594 |
message.Destroy() |
|
3595 |
event.Veto() |
|
3596 |
elif value.upper() in IEC_KEYWORDS: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3597 |
message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%value, "Error", wx.OK|wx.ICON_ERROR) |
6 | 3598 |
message.ShowModal() |
3599 |
message.Destroy() |
|
3600 |
event.Veto() |
|
3601 |
elif value.upper() in self.PouNames: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3602 |
message = wx.MessageDialog(self, "A pou with \"%s\" as name exists!"%value, "Error", wx.OK|wx.ICON_ERROR) |
6 | 3603 |
message.ShowModal() |
3604 |
message.Destroy() |
|
3605 |
event.Veto() |
|
3606 |
elif value.upper() in [var["Name"].upper() for var in self.Values if var != self.Table.data[row]]: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3607 |
message = wx.MessageDialog(self, "A variable with \"%s\" as name exists in this pou!"%value, "Error", wx.OK|wx.ICON_ERROR) |
6 | 3608 |
message.ShowModal() |
3609 |
message.Destroy() |
|
3610 |
event.Veto() |
|
3611 |
else: |
|
58 | 3612 |
self.SaveValues(False) |
3613 |
old_value = self.Table.GetOldValue() |
|
3614 |
if old_value != "": |
|
121 | 3615 |
self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value) |
58 | 3616 |
self.Controler.BufferProject() |
121 | 3617 |
self.ParentWindow.RefreshEditor(variablepanel = False) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
3618 |
self.ParentWindow.RefreshTitle() |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
3619 |
self.ParentWindow.RefreshEditMenu() |
6 | 3620 |
event.Skip() |
3621 |
else: |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3622 |
self.SaveValues() |
107 | 3623 |
if colname == "Class": |
3624 |
self.Table.ResetView(self.VariablesGrid) |
|
6 | 3625 |
event.Skip() |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3626 |
|
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3627 |
def OnVariablesGridEditorShown(self, event): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3628 |
row, col = event.GetRow(), event.GetCol() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3629 |
if self.Table.GetColLabelValue(col) == "Type": |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3630 |
type_menu = wx.Menu(title='') |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3631 |
base_menu = wx.Menu(title='') |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3632 |
for base_type in self.Controler.GetBaseTypes(): |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3633 |
new_id = wx.NewId() |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3634 |
AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3635 |
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id) |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3636 |
type_menu.AppendMenu(wx.NewId(), "Base Types", base_menu) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3637 |
datatype_menu = wx.Menu(title='') |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3638 |
for datatype in self.Controler.GetDataTypes(basetypes = False): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3639 |
new_id = wx.NewId() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3640 |
AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3641 |
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
3642 |
type_menu.AppendMenu(wx.NewId(), "User Data Types", datatype_menu) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3643 |
functionblock_menu = wx.Menu(title='') |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3644 |
for functionblock_type in self.Controler.GetFunctionBlockTypes(): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3645 |
new_id = wx.NewId() |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3646 |
AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3647 |
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id) |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3648 |
type_menu.AppendMenu(wx.NewId(), "Function Block Types", functionblock_menu) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3649 |
rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col)) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3650 |
self.VariablesGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize()) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3651 |
event.Veto() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3652 |
else: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3653 |
event.Skip() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3654 |
|
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3655 |
def GetVariableTypeFunction(self, base_type): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3656 |
def VariableTypeFunction(event): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3657 |
row = self.VariablesGrid.GetGridCursorRow() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3658 |
self.Table.SetValueByName(row, "Type", base_type) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3659 |
self.Table.ResetView(self.VariablesGrid) |
98 | 3660 |
self.SaveValues(False) |
121 | 3661 |
self.ParentWindow.RefreshEditor(variablepanel = False) |
98 | 3662 |
self.Controler.BufferProject() |
3663 |
self.ParentWindow.RefreshTitle() |
|
3664 |
self.ParentWindow.RefreshEditMenu() |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3665 |
event.Skip() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3666 |
return VariableTypeFunction |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3667 |
|
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3668 |
def OnVariablesGridCellLeftClick(self, event): |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3669 |
if event.GetCol() == 0: |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3670 |
row = event.GetRow() |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3671 |
var_name = self.Table.GetValueByName(row, "Name") |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3672 |
var_class = self.Table.GetValueByName(row, "Class") |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3673 |
var_type = self.Table.GetValueByName(row, "Type") |
121 | 3674 |
data = wx.TextDataObject(str((var_name, var_class, var_type, self.TagName))) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3675 |
dragSource = wx.DropSource(self.VariablesGrid) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3676 |
dragSource.SetData(data) |
135 | 3677 |
dragSource.DoDragDrop() |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3678 |
event.Skip() |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3679 |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3680 |
def OnVariablesGridSelectCell(self, event): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3681 |
wx.CallAfter(self.RefreshButtons) |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3682 |
event.Skip() |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3683 |
|
12 | 3684 |
def MoveValue(self, value_index, move): |
3685 |
new_index = max(0, min(value_index + move, len(self.Values) - 1)) |
|
3686 |
if new_index != value_index: |
|
3687 |
self.Values.insert(new_index, self.Values.pop(value_index)) |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
3688 |
self.RefreshValues() |
12 | 3689 |
self.VariablesGrid.SetGridCursor(new_index, self.VariablesGrid.GetGridCursorCol()) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
3690 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
3691 |
self.RefreshValues() |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3692 |
self.SaveValues() |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3693 |
|
0 | 3694 |
def RefreshValues(self): |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3695 |
if len(self.Table.data) > 0: |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3696 |
self.VariablesGrid.SetGridCursor(0, 1) |
0 | 3697 |
data = [] |
80 | 3698 |
for num, variable in enumerate(self.Values): |
0 | 3699 |
if variable["Class"] in self.ClassList: |
80 | 3700 |
variable["Number"] = num + 1 |
0 | 3701 |
data.append(variable) |
3702 |
self.Table.SetData(data) |
|
3703 |
self.Table.ResetView(self.VariablesGrid) |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3704 |
|
58 | 3705 |
def SaveValues(self, buffer = True): |
121 | 3706 |
words = self.TagName.split("::") |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3707 |
if self.ElementType == "config": |
121 | 3708 |
self.Controler.SetConfigurationGlobalVars(words[1], self.Values) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3709 |
elif self.ElementType == "resource": |
121 | 3710 |
self.Controler.SetConfigurationResourceGlobalVars(words[1], words[2], self.Values) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3711 |
else: |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3712 |
if self.ReturnType.IsEnabled(): |
121 | 3713 |
self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection()) |
3714 |
self.Controler.SetPouInterfaceVars(words[1], self.Values) |
|
58 | 3715 |
if buffer: |
3716 |
self.Controler.BufferProject() |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
3717 |
self.ParentWindow.RefreshTitle() |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
3718 |
self.ParentWindow.RefreshEditMenu() |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3719 |
|
0 | 3720 |
#------------------------------------------------------------------------------- |
3721 |
# Exception Handler |
|
3722 |
#------------------------------------------------------------------------------- |
|
3723 |
||
3724 |
Max_Traceback_List_Size = 20 |
|
3725 |
||
3726 |
def Display_Exception_Dialog(e_type,e_value,e_tb): |
|
3727 |
trcbck_lst = [] |
|
3728 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
|
3729 |
trcbck = " " + str(i+1) + ". " |
|
3730 |
if line[0].find(os.getcwd()) == -1: |
|
3731 |
trcbck += "file : " + str(line[0]) + ", " |
|
3732 |
else: |
|
3733 |
trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " |
|
3734 |
trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) |
|
3735 |
trcbck_lst.append(trcbck) |
|
3736 |
||
3737 |
# Allow clicking.... |
|
3738 |
cap = wx.Window_GetCapture() |
|
3739 |
if cap: |
|
3740 |
cap.ReleaseMouse() |
|
3741 |
||
3742 |
dlg = wx.SingleChoiceDialog(None, |
|
3743 |
""" |
|
3744 |
An error happens. |
|
3745 |
||
3746 |
Click on OK for saving an error report. |
|
3747 |
||
3748 |
Please contact LOLITech at: |
|
3749 |
+33 (0)3 29 52 95 67 |
|
3750 |
bugs_PLCOpenEditor@lolitech.fr |
|
3751 |
||
3752 |
||
3753 |
Error: |
|
3754 |
""" + |
|
3755 |
str(e_type) + " : " + str(e_value), |
|
3756 |
"Error", |
|
3757 |
trcbck_lst) |
|
3758 |
try: |
|
3759 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
3760 |
finally: |
|
3761 |
dlg.Destroy() |
|
3762 |
||
3763 |
return res |
|
3764 |
||
3765 |
def Display_Error_Dialog(e_value): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3766 |
message = wx.MessageDialog(None, str(e_value), "Error", wx.OK|wx.ICON_ERROR) |
0 | 3767 |
message.ShowModal() |
3768 |
message.Destroy() |
|
3769 |
||
3770 |
def get_last_traceback(tb): |
|
3771 |
while tb.tb_next: |
|
3772 |
tb = tb.tb_next |
|
3773 |
return tb |
|
3774 |
||
3775 |
||
3776 |
def format_namespace(d, indent=' '): |
|
3777 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
3778 |
||
3779 |
||
3780 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
|
3781 |
||
65
cb6bed0720f0
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
64
diff
changeset
|
3782 |
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
0 | 3783 |
|
3784 |
def handle_exception(e_type, e_value, e_traceback): |
|
3785 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
|
3786 |
last_tb = get_last_traceback(e_traceback) |
|
3787 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
3788 |
if str(e_value).startswith("!!!"): |
|
3789 |
Display_Error_Dialog(e_value) |
|
3790 |
elif ex not in ignored_exceptions: |
|
3791 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback) |
|
3792 |
if result: |
|
3793 |
ignored_exceptions.append(ex) |
|
3794 |
info = { |
|
3795 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
|
3796 |
'app-version' : app_version, |
|
3797 |
'wx-version' : wx.VERSION_STRING, |
|
3798 |
'wx-platform' : wx.Platform, |
|
3799 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
|
3800 |
'platform' : platform.platform(), |
|
3801 |
'e-type' : e_type, |
|
3802 |
'e-value' : e_value, |
|
3803 |
'date' : time.ctime(), |
|
3804 |
'cwd' : os.getcwd(), |
|
3805 |
} |
|
3806 |
if e_traceback: |
|
3807 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
3808 |
last_tb = get_last_traceback(e_traceback) |
|
3809 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
3810 |
info['locals'] = format_namespace(exception_locals) |
|
3811 |
if 'self' in exception_locals: |
|
3812 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
3813 |
||
3814 |
output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') |
|
3815 |
lst = info.keys() |
|
3816 |
lst.sort() |
|
3817 |
for a in lst: |
|
3818 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
3819 |
||
3820 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
3821 |
sys.excepthook = handle_exception |
|
3822 |
||
3823 |
if __name__ == '__main__': |
|
92
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3824 |
def usage(): |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3825 |
print "\nUsage of PLCOpenEditor.py :" |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3826 |
print "\n %s [Filepath]\n"%sys.argv[0] |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3827 |
|
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3828 |
try: |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3829 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3830 |
except getopt.GetoptError: |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3831 |
# print help information and exit: |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3832 |
usage() |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3833 |
sys.exit(2) |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3834 |
|
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3835 |
for o, a in opts: |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3836 |
if o in ("-h", "--help"): |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3837 |
usage() |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3838 |
sys.exit() |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3839 |
|
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3840 |
fileOpen = None |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3841 |
if len(args) > 1: |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3842 |
usage() |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3843 |
sys.exit() |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3844 |
elif len(args) == 1: |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3845 |
fileOpen = args[0] |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3846 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3847 |
app = wx.PySimpleApp() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3848 |
wx.InitAllImageHandlers() |
0 | 3849 |
|
3850 |
# Install a exception handle for bug reports |
|
65
cb6bed0720f0
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
64
diff
changeset
|
3851 |
AddExceptHook(os.getcwd(),__version__) |
0 | 3852 |
|
92
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3853 |
frame = PLCOpenEditor(None, fileOpen=fileOpen) |
0 | 3854 |
|
3855 |
frame.Show() |
|
3856 |
app.MainLoop() |
|
3857 |