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