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