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