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