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