author | Paul Beltyukov <beltyukov.p.a@gmail.com> |
Fri, 09 Sep 2016 11:47:00 +0500 | |
changeset 1527 | 642bae8e8607 |
parent 1514 | 968e7898d66b |
child 1530 | 24d8e8c233bd |
permissions | -rw-r--r-- |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
1 |
#!/usr/bin/env python |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
3 |
|
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
6 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
8 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
10 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
15 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
19 |
# GNU General Public License for more details. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
20 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1490
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
25 |
import os, sys |
|
26 |
import cPickle |
|
27 |
from types import TupleType |
|
28 |
||
29 |
import wx, wx.grid |
|
30 |
import wx.aui |
|
31 |
||
32 |
from editors.EditorPanel import EditorPanel |
|
33 |
from editors.SFCViewer import SFC_Viewer |
|
34 |
from editors.LDViewer import LD_Viewer |
|
35 |
from editors.TextViewer import TextViewer |
|
36 |
from editors.Viewer import Viewer, ZOOM_FACTORS |
|
37 |
from editors.ResourceEditor import ConfigurationEditor, ResourceEditor |
|
38 |
from editors.DataTypeEditor import DataTypeEditor |
|
39 |
from PLCControler import * |
|
1193
59c196884fec
Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents:
1188
diff
changeset
|
40 |
from controls import CustomTree, LibraryPanel, PouInstanceVariablesPanel, SearchResultPanel |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1193
diff
changeset
|
41 |
from controls.DebugVariablePanel import DebugVariablePanel |
819 | 42 |
from dialogs import ProjectDialog, PouDialog, PouTransitionDialog, PouActionDialog, FindInPouDialog, SearchInProjectDialog |
814 | 43 |
from util.BitmapLibrary import GetBitmap |
44 |
||
45 |
# Define PLCOpenEditor controls id |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
46 |
[ID_PLCOPENEDITOR, ID_PLCOPENEDITORLEFTNOTEBOOK, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
47 |
ID_PLCOPENEDITORBOTTOMNOTEBOOK, ID_PLCOPENEDITORRIGHTNOTEBOOK, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
48 |
ID_PLCOPENEDITORPROJECTTREE, ID_PLCOPENEDITORMAINSPLITTER, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
49 |
ID_PLCOPENEDITORSECONDSPLITTER, ID_PLCOPENEDITORTHIRDSPLITTER, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
50 |
ID_PLCOPENEDITORLIBRARYPANEL, ID_PLCOPENEDITORLIBRARYSEARCHCTRL, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
51 |
ID_PLCOPENEDITORLIBRARYTREE, ID_PLCOPENEDITORLIBRARYCOMMENT, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
52 |
ID_PLCOPENEDITORTABSOPENED, ID_PLCOPENEDITORTABSOPENED, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
53 |
ID_PLCOPENEDITOREDITORMENUTOOLBAR, ID_PLCOPENEDITOREDITORTOOLBAR, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
54 |
ID_PLCOPENEDITORPROJECTPANEL, |
814 | 55 |
] = [wx.NewId() for _init_ctrls in range(17)] |
56 |
||
57 |
# Define PLCOpenEditor EditMenu extra items id |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
58 |
[ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, ID_PLCOPENEDITOREDITMENUADDDATATYPE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
59 |
ID_PLCOPENEDITOREDITMENUADDFUNCTION, ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK, |
814 | 60 |
ID_PLCOPENEDITOREDITMENUADDPROGRAM, ID_PLCOPENEDITOREDITMENUADDCONFIGURATION, |
61 |
ID_PLCOPENEDITOREDITMENUFINDNEXT, ID_PLCOPENEDITOREDITMENUFINDPREVIOUS, |
|
1401
611fded24ce4
Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents:
1364
diff
changeset
|
62 |
ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, ID_PLCOPENEDITOREDITMENUADDRESOURCE |
611fded24ce4
Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents:
1364
diff
changeset
|
63 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(10)] |
814 | 64 |
|
65 |
# Define PLCOpenEditor DisplayMenu extra items id |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
66 |
[ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE, |
814 | 67 |
] = [wx.NewId() for _init_coll_DisplayMenu_Items in range(1)] |
68 |
||
69 |
#------------------------------------------------------------------------------- |
|
70 |
# EditorToolBar definitions |
|
71 |
#------------------------------------------------------------------------------- |
|
72 |
||
73 |
# Define PLCOpenEditor Toolbar items id |
|
74 |
[ID_PLCOPENEDITOREDITORTOOLBARSELECTION, ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, |
|
75 |
ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, ID_PLCOPENEDITOREDITORTOOLBARBLOCK, |
|
76 |
ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, ID_PLCOPENEDITOREDITORTOOLBARWIRE, |
|
77 |
ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, ID_PLCOPENEDITOREDITORTOOLBARRUNG, |
|
78 |
ID_PLCOPENEDITOREDITORTOOLBARCOIL, ID_PLCOPENEDITOREDITORTOOLBARCONTACT, |
|
79 |
ID_PLCOPENEDITOREDITORTOOLBARBRANCH, ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP, |
|
80 |
ID_PLCOPENEDITOREDITORTOOLBARSTEP, ID_PLCOPENEDITOREDITORTOOLBARTRANSITION, |
|
81 |
ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE, |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
82 |
ID_PLCOPENEDITOREDITORTOOLBARJUMP, ID_PLCOPENEDITOREDITORTOOLBARMOTION, |
814 | 83 |
] = [wx.NewId() for _init_coll_DefaultEditorToolBar_Items in range(18)] |
84 |
||
85 |
||
86 |
||
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
87 |
# Define behaviour of each Toolbar item according to current POU body type |
814 | 88 |
# Informations meaning are in this order: |
89 |
# - Item is toggled |
|
90 |
# - PLCOpenEditor mode where item is displayed (could be more then one) |
|
91 |
# - Item id |
|
92 |
# - Item callback function name |
|
93 |
# - Item icon filename |
|
94 |
# - Item tooltip text |
|
95 |
EditorToolBarItems = { |
|
96 |
"FBD" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
|
97 |
ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool", |
|
98 |
"move", _("Move the view")), |
|
99 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
|
100 |
ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool", |
|
101 |
"add_comment", _("Create a new comment")), |
|
102 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
|
103 |
ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool", |
|
104 |
"add_variable", _("Create a new variable")), |
|
105 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
|
106 |
ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool", |
|
107 |
"add_block", _("Create a new block")), |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
108 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
109 |
ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool", |
814 | 110 |
"add_connection", _("Create a new connection"))], |
111 |
"LD" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
|
112 |
ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool", |
|
113 |
"move", _("Move the view")), |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
114 |
(True, FREEDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
115 |
ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool", |
814 | 116 |
"add_comment", _("Create a new comment")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
117 |
(True, FREEDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
118 |
ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool", |
814 | 119 |
"add_powerrail", _("Create a new power rail")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
120 |
(False, DRIVENDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
121 |
ID_PLCOPENEDITOREDITORTOOLBARRUNG, "OnRungTool", |
814 | 122 |
"add_rung", _("Create a new rung")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
123 |
(True, FREEDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
124 |
ID_PLCOPENEDITOREDITORTOOLBARCOIL, "OnCoilTool", |
814 | 125 |
"add_coil", _("Create a new coil")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
126 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
127 |
ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool", |
814 | 128 |
"add_contact", _("Create a new contact")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
129 |
(False, DRIVENDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
130 |
ID_PLCOPENEDITOREDITORTOOLBARBRANCH, "OnBranchTool", |
814 | 131 |
"add_branch", _("Create a new branch")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
132 |
(True, FREEDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
133 |
ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool", |
814 | 134 |
"add_variable", _("Create a new variable")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
135 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
136 |
ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool", |
814 | 137 |
"add_block", _("Create a new block")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
138 |
(True, FREEDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
139 |
ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool", |
814 | 140 |
"add_connection", _("Create a new connection"))], |
141 |
"SFC" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
|
142 |
ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool", |
|
143 |
"move", _("Move the view")), |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
144 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
145 |
ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool", |
814 | 146 |
"add_comment", _("Create a new comment")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
147 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
148 |
ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP, "OnInitialStepTool", |
814 | 149 |
"add_initial_step", _("Create a new initial step")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
150 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
151 |
ID_PLCOPENEDITOREDITORTOOLBARSTEP, "OnStepTool", |
814 | 152 |
"add_step", _("Create a new step")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
153 |
(True, FREEDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
154 |
ID_PLCOPENEDITOREDITORTOOLBARTRANSITION, "OnTransitionTool", |
814 | 155 |
"add_transition", _("Create a new transition")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
156 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
157 |
ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, "OnActionBlockTool", |
814 | 158 |
"add_action", _("Create a new action block")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
159 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
160 |
ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE, "OnDivergenceTool", |
814 | 161 |
"add_divergence", _("Create a new divergence")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
162 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
163 |
ID_PLCOPENEDITOREDITORTOOLBARJUMP, "OnJumpTool", |
814 | 164 |
"add_jump", _("Create a new jump")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
165 |
(True, FREEDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
166 |
ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool", |
814 | 167 |
"add_variable", _("Create a new variable")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
168 |
(True, FREEDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
169 |
ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool", |
814 | 170 |
"add_block", _("Create a new block")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
171 |
(True, FREEDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
172 |
ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool", |
814 | 173 |
"add_connection", _("Create a new connection")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
174 |
(True, FREEDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
175 |
ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool", |
814 | 176 |
"add_powerrail", _("Create a new power rail")), |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
177 |
(True, FREEDRAWING_MODE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
178 |
ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool", |
814 | 179 |
"add_contact", _("Create a new contact"))], |
180 |
"ST" : [], |
|
181 |
"IL" : [], |
|
182 |
"debug": [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
|
183 |
ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool", |
|
184 |
"move", _("Move the view"))], |
|
185 |
} |
|
186 |
||
187 |
#------------------------------------------------------------------------------- |
|
188 |
# Helper Functions |
|
189 |
#------------------------------------------------------------------------------- |
|
190 |
||
191 |
import base64 |
|
192 |
||
193 |
def EncodeFileSystemPath(path, use_base64=True): |
|
194 |
path = path.encode(sys.getfilesystemencoding()) |
|
195 |
if use_base64: |
|
196 |
return base64.encodestring(path) |
|
197 |
return path |
|
198 |
||
199 |
def DecodeFileSystemPath(path, is_base64=True): |
|
200 |
if is_base64: |
|
201 |
path = base64.decodestring(path) |
|
202 |
return unicode(path, sys.getfilesystemencoding()) |
|
203 |
||
204 |
# Compatibility function for wx versions < 2.6 |
|
205 |
def AppendMenu(parent, help, id, kind, text): |
|
206 |
if wx.VERSION >= (2, 6, 0): |
|
207 |
parent.Append(help=help, id=id, kind=kind, text=text) |
|
208 |
else: |
|
209 |
parent.Append(helpString=help, id=id, kind=kind, item=text) |
|
210 |
||
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
211 |
[TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, |
814 | 212 |
POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES |
213 |
] = range(10) |
|
214 |
||
215 |
def GetShortcutKeyCallbackFunction(viewer_function): |
|
216 |
def ShortcutKeyFunction(self, event): |
|
217 |
control = self.FindFocus() |
|
218 |
if control is not None and control.GetName() in ["Viewer", "TextViewer"]: |
|
219 |
getattr(control.ParentWindow, viewer_function)() |
|
220 |
elif isinstance(control, wx.stc.StyledTextCtrl): |
|
221 |
getattr(control, viewer_function)() |
|
222 |
elif isinstance(control, wx.TextCtrl): |
|
223 |
control.ProcessEvent(event) |
|
224 |
return ShortcutKeyFunction |
|
225 |
||
226 |
def GetDeleteElementFunction(remove_function, parent_type=None, check_function=None): |
|
227 |
def DeleteElementFunction(self, selected): |
|
228 |
name = self.ProjectTree.GetItemText(selected) |
|
1129
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
229 |
if check_function is None or check_function(name): |
814 | 230 |
if parent_type is not None: |
231 |
item_infos = self.ProjectTree.GetPyData(selected) |
|
232 |
parent_name = item_infos["tagname"].split("::")[1] |
|
233 |
remove_function(self.Controler, parent_name, name) |
|
234 |
else: |
|
235 |
remove_function(self.Controler, name) |
|
236 |
return DeleteElementFunction |
|
237 |
||
238 |
if wx.Platform == '__WXMSW__': |
|
239 |
TAB_BORDER = 6 |
|
240 |
NOTEBOOK_BORDER = 6 |
|
241 |
else: |
|
242 |
TAB_BORDER = 7 |
|
243 |
NOTEBOOK_BORDER = 2 |
|
244 |
||
245 |
def SimplifyTabLayout(tabs, rect): |
|
246 |
for tab in tabs: |
|
247 |
if tab["pos"][0] == rect.x: |
|
248 |
others = [t for t in tabs if t != tab] |
|
249 |
others.sort(lambda x,y: cmp(x["pos"][0], y["pos"][0])) |
|
250 |
for other in others: |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
251 |
if (other["pos"][1] == tab["pos"][1] and |
814 | 252 |
other["size"][1] == tab["size"][1] and |
253 |
other["pos"][0] == tab["pos"][0] + tab["size"][0] + TAB_BORDER): |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
254 |
|
814 | 255 |
tab["size"] = (tab["size"][0] + other["size"][0] + TAB_BORDER, tab["size"][1]) |
256 |
tab["pages"].extend(other["pages"]) |
|
257 |
tabs.remove(other) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
258 |
|
814 | 259 |
if tab["size"][0] == rect.width: |
260 |
return True |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
261 |
|
814 | 262 |
elif tab["pos"][1] == rect.y: |
263 |
others = [t for t in tabs if t != tab] |
|
264 |
others.sort(lambda x,y: cmp(x["pos"][1], y["pos"][1])) |
|
265 |
for other in others: |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
266 |
if (other["pos"][0] == tab["pos"][0] and |
814 | 267 |
other["size"][0] == tab["size"][0] and |
268 |
other["pos"][1] == tab["pos"][1] + tab["size"][1] + TAB_BORDER): |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
269 |
|
814 | 270 |
tab["size"] = (tab["size"][0], tab["size"][1] + other["size"][1] + TAB_BORDER) |
271 |
tab["pages"].extend(other["pages"]) |
|
272 |
tabs.remove(other) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
273 |
|
814 | 274 |
if tab["size"][1] == rect.height: |
275 |
return True |
|
276 |
return False |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
277 |
|
814 | 278 |
def ComputeTabsLayout(tabs, rect): |
279 |
if len(tabs) == 0: |
|
280 |
return tabs |
|
281 |
if len(tabs) == 1: |
|
282 |
return tabs[0] |
|
283 |
split = None |
|
284 |
for idx, tab in enumerate(tabs): |
|
285 |
if len(tab["pages"]) == 0: |
|
286 |
raise ValueError, "Not possible" |
|
287 |
if tab["size"][0] == rect.width: |
|
288 |
if tab["pos"][1] == rect.y: |
|
289 |
split = (wx.TOP, float(tab["size"][1]) / float(rect.height)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
290 |
split_rect = wx.Rect(rect.x, rect.y + tab["size"][1] + TAB_BORDER, |
814 | 291 |
rect.width, rect.height - tab["size"][1] - TAB_BORDER) |
292 |
elif tab["pos"][1] == rect.height + 1 - tab["size"][1]: |
|
293 |
split = (wx.BOTTOM, 1.0 - float(tab["size"][1]) / float(rect.height)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
294 |
split_rect = wx.Rect(rect.x, rect.y, |
814 | 295 |
rect.width, rect.height - tab["size"][1] - TAB_BORDER) |
296 |
break |
|
297 |
elif tab["size"][1] == rect.height: |
|
298 |
if tab["pos"][0] == rect.x: |
|
299 |
split = (wx.LEFT, float(tab["size"][0]) / float(rect.width)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
300 |
split_rect = wx.Rect(rect.x + tab["size"][0] + TAB_BORDER, rect.y, |
814 | 301 |
rect.width - tab["size"][0] - TAB_BORDER, rect.height) |
302 |
elif tab["pos"][0] == rect.width + 1 - tab["size"][0]: |
|
303 |
split = (wx.RIGHT, 1.0 - float(tab["size"][0]) / float(rect.width)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
304 |
split_rect = wx.Rect(rect.x, rect.y, |
814 | 305 |
rect.width - tab["size"][0] - TAB_BORDER, rect.height) |
306 |
break |
|
307 |
if split != None: |
|
308 |
split_tab = tabs.pop(idx) |
|
309 |
return {"split": split, |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
310 |
"tab": split_tab, |
814 | 311 |
"others": ComputeTabsLayout(tabs, split_rect)} |
312 |
else: |
|
313 |
if SimplifyTabLayout(tabs, rect): |
|
314 |
return ComputeTabsLayout(tabs, rect) |
|
315 |
return tabs |
|
316 |
||
317 |
#------------------------------------------------------------------------------- |
|
318 |
# IDEFrame Base Class |
|
319 |
#------------------------------------------------------------------------------- |
|
320 |
||
321 |
UNEDITABLE_NAMES_DICT = dict([(_(name), name) for name in UNEDITABLE_NAMES]) |
|
322 |
||
323 |
class IDEFrame(wx.Frame): |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
324 |
|
814 | 325 |
# Compatibility function for wx versions < 2.6 |
326 |
if wx.VERSION < (2, 6, 0): |
|
327 |
def Bind(self, event, function, id = None): |
|
328 |
if id is not None: |
|
329 |
event(self, id, function) |
|
330 |
else: |
|
331 |
event(self, function) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
332 |
|
814 | 333 |
def _init_coll_MenuBar_Menus(self, parent): |
334 |
parent.Append(menu=self.FileMenu, title=_(u'&File')) |
|
335 |
parent.Append(menu=self.EditMenu, title=_(u'&Edit')) |
|
336 |
parent.Append(menu=self.DisplayMenu, title=_(u'&Display')) |
|
337 |
parent.Append(menu=self.HelpMenu, title=_(u'&Help')) |
|
338 |
||
339 |
def _init_coll_FileMenu_Items(self, parent): |
|
340 |
pass |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
341 |
|
814 | 342 |
def _init_coll_AddMenu_Items(self, parent, add_config=True): |
343 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDDATATYPE, |
|
344 |
kind=wx.ITEM_NORMAL, text=_(u'&Data Type')) |
|
345 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDFUNCTION, |
|
346 |
kind=wx.ITEM_NORMAL, text=_(u'&Function')) |
|
347 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK, |
|
348 |
kind=wx.ITEM_NORMAL, text=_(u'Function &Block')) |
|
349 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDPROGRAM, |
|
350 |
kind=wx.ITEM_NORMAL, text=_(u'&Program')) |
|
1401
611fded24ce4
Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents:
1364
diff
changeset
|
351 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDRESOURCE, |
611fded24ce4
Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents:
1364
diff
changeset
|
352 |
kind=wx.ITEM_NORMAL, text=_(u'&Resource')) |
814 | 353 |
if add_config: |
354 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION, |
|
355 |
kind=wx.ITEM_NORMAL, text=_(u'&Configuration')) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
356 |
|
814 | 357 |
def _init_coll_EditMenu_Items(self, parent): |
358 |
AppendMenu(parent, help='', id=wx.ID_UNDO, |
|
359 |
kind=wx.ITEM_NORMAL, text=_(u'Undo') + '\tCTRL+Z') |
|
360 |
AppendMenu(parent, help='', id=wx.ID_REDO, |
|
361 |
kind=wx.ITEM_NORMAL, text=_(u'Redo') + '\tCTRL+Y') |
|
362 |
#AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, |
|
363 |
# kind=wx.ITEM_CHECK, text=_(u'Enable Undo/Redo')) |
|
364 |
enable_undo_redo = _(u'Enable Undo/Redo') # Keeping text in translations for possible menu reactivation |
|
365 |
parent.AppendSeparator() |
|
366 |
AppendMenu(parent, help='', id=wx.ID_CUT, |
|
367 |
kind=wx.ITEM_NORMAL, text=_(u'Cut') + '\tCTRL+X') |
|
368 |
AppendMenu(parent, help='', id=wx.ID_COPY, |
|
369 |
kind=wx.ITEM_NORMAL, text=_(u'Copy') + '\tCTRL+C') |
|
370 |
AppendMenu(parent, help='', id=wx.ID_PASTE, |
|
371 |
kind=wx.ITEM_NORMAL, text=_(u'Paste') + '\tCTRL+V') |
|
372 |
parent.AppendSeparator() |
|
373 |
AppendMenu(parent, help='', id=wx.ID_FIND, |
|
374 |
kind=wx.ITEM_NORMAL, text=_(u'Find') + '\tCTRL+F') |
|
375 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUFINDNEXT, |
|
376 |
kind=wx.ITEM_NORMAL, text=_(u'Find Next') + '\tCTRL+K') |
|
377 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUFINDPREVIOUS, |
|
378 |
kind=wx.ITEM_NORMAL, text=_(u'Find Previous') + '\tCTRL+SHIFT+K') |
|
379 |
parent.AppendSeparator() |
|
380 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, |
|
381 |
kind=wx.ITEM_NORMAL, text=_(u'Search in Project') + '\tCTRL+SHIFT+F') |
|
382 |
parent.AppendSeparator() |
|
383 |
add_menu = wx.Menu(title='') |
|
384 |
self._init_coll_AddMenu_Items(add_menu) |
|
385 |
parent.AppendMenu(wx.ID_ADD, _(u"&Add Element"), add_menu) |
|
386 |
AppendMenu(parent, help='', id=wx.ID_SELECTALL, |
|
387 |
kind=wx.ITEM_NORMAL, text=_(u'Select All') + '\tCTRL+A') |
|
388 |
AppendMenu(parent, help='', id=wx.ID_DELETE, |
|
389 |
kind=wx.ITEM_NORMAL, text=_(u'&Delete')) |
|
390 |
self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO) |
|
391 |
self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO) |
|
392 |
#self.Bind(wx.EVT_MENU, self.OnEnableUndoRedoMenu, id=ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO) |
|
393 |
self.Bind(wx.EVT_MENU, self.OnCutMenu, id=wx.ID_CUT) |
|
394 |
self.Bind(wx.EVT_MENU, self.OnCopyMenu, id=wx.ID_COPY) |
|
395 |
self.Bind(wx.EVT_MENU, self.OnPasteMenu, id=wx.ID_PASTE) |
|
396 |
self.Bind(wx.EVT_MENU, self.OnFindMenu, id=wx.ID_FIND) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
397 |
self.Bind(wx.EVT_MENU, self.OnFindNextMenu, |
814 | 398 |
id=ID_PLCOPENEDITOREDITMENUFINDNEXT) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
399 |
self.Bind(wx.EVT_MENU, self.OnFindPreviousMenu, |
814 | 400 |
id=ID_PLCOPENEDITOREDITMENUFINDPREVIOUS) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
401 |
self.Bind(wx.EVT_MENU, self.OnSearchInProjectMenu, |
814 | 402 |
id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
403 |
self.Bind(wx.EVT_MENU, self.OnSearchInProjectMenu, |
814 | 404 |
id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT) |
405 |
self.Bind(wx.EVT_MENU, self.OnAddDataTypeMenu, |
|
406 |
id=ID_PLCOPENEDITOREDITMENUADDDATATYPE) |
|
407 |
self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("function"), |
|
408 |
id=ID_PLCOPENEDITOREDITMENUADDFUNCTION) |
|
409 |
self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("functionBlock"), |
|
410 |
id=ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK) |
|
411 |
self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("program"), |
|
412 |
id=ID_PLCOPENEDITOREDITMENUADDPROGRAM) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
413 |
self.Bind(wx.EVT_MENU, self.AddResourceMenu, |
1401
611fded24ce4
Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents:
1364
diff
changeset
|
414 |
id=ID_PLCOPENEDITOREDITMENUADDRESOURCE) |
814 | 415 |
self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu, |
416 |
id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION) |
|
417 |
self.Bind(wx.EVT_MENU, self.OnSelectAllMenu, id=wx.ID_SELECTALL) |
|
418 |
self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=wx.ID_DELETE) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
419 |
|
814 | 420 |
self.AddToMenuToolBar([(wx.ID_UNDO, "undo", _(u'Undo'), None), |
421 |
(wx.ID_REDO, "redo", _(u'Redo'), None), |
|
422 |
None, |
|
423 |
(wx.ID_CUT, "cut", _(u'Cut'), None), |
|
424 |
(wx.ID_COPY, "copy", _(u'Copy'), None), |
|
425 |
(wx.ID_PASTE, "paste", _(u'Paste'), None), |
|
426 |
None, |
|
427 |
(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, "find", _(u'Search in Project'), None)]) |
|
428 |
||
429 |
def _init_coll_DisplayMenu_Items(self, parent): |
|
430 |
AppendMenu(parent, help='', id=wx.ID_REFRESH, |
|
431 |
kind=wx.ITEM_NORMAL, text=_(u'Refresh') + '\tCTRL+R') |
|
432 |
if self.EnableDebug: |
|
433 |
AppendMenu(parent, help='', id=wx.ID_CLEAR, |
|
434 |
kind=wx.ITEM_NORMAL, text=_(u'Clear Errors') + '\tCTRL+K') |
|
435 |
parent.AppendSeparator() |
|
436 |
zoommenu = wx.Menu(title='') |
|
437 |
parent.AppendMenu(wx.ID_ZOOM_FIT, _("Zoom"), zoommenu) |
|
438 |
for idx, value in enumerate(ZOOM_FACTORS): |
|
439 |
new_id = wx.NewId() |
|
440 |
AppendMenu(zoommenu, help='', id=new_id, |
|
441 |
kind=wx.ITEM_RADIO, text=str(int(round(value * 100))) + "%") |
|
442 |
self.Bind(wx.EVT_MENU, self.GenerateZoomFunction(idx), id=new_id) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
443 |
|
814 | 444 |
parent.AppendSeparator() |
445 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE, |
|
446 |
kind=wx.ITEM_NORMAL, text=_(u'Reset Perspective')) |
|
447 |
self.Bind(wx.EVT_MENU, self.OnResetPerspective, id=ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
448 |
|
814 | 449 |
self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH) |
450 |
if self.EnableDebug: |
|
451 |
self.Bind(wx.EVT_MENU, self.OnClearErrorsMenu, id=wx.ID_CLEAR) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
452 |
|
814 | 453 |
def _init_coll_HelpMenu_Items(self, parent): |
454 |
pass |
|
455 |
||
456 |
def _init_utils(self): |
|
457 |
self.MenuBar = wx.MenuBar() |
|
458 |
||
459 |
self.FileMenu = wx.Menu(title='') |
|
460 |
self.EditMenu = wx.Menu(title='') |
|
461 |
self.DisplayMenu = wx.Menu(title='') |
|
462 |
self.HelpMenu = wx.Menu(title='') |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
463 |
|
814 | 464 |
self._init_coll_MenuBar_Menus(self.MenuBar) |
465 |
self._init_coll_FileMenu_Items(self.FileMenu) |
|
466 |
self._init_coll_EditMenu_Items(self.EditMenu) |
|
467 |
self._init_coll_DisplayMenu_Items(self.DisplayMenu) |
|
468 |
self._init_coll_HelpMenu_Items(self.HelpMenu) |
|
469 |
||
1490
f03bc6c9c146
make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1480
diff
changeset
|
470 |
def _init_icon(self, parent): |
f03bc6c9c146
make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1480
diff
changeset
|
471 |
if self.icon: |
f03bc6c9c146
make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1480
diff
changeset
|
472 |
self.SetIcon(self.icon) |
f03bc6c9c146
make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1480
diff
changeset
|
473 |
elif parent and parent.icon: |
f03bc6c9c146
make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1480
diff
changeset
|
474 |
self.SetIcon(parent.icon) |
f03bc6c9c146
make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1480
diff
changeset
|
475 |
|
814 | 476 |
def _init_ctrls(self, prnt): |
477 |
wx.Frame.__init__(self, id=ID_PLCOPENEDITOR, name='IDEFrame', |
|
478 |
parent=prnt, pos=wx.DefaultPosition, size=wx.Size(1000, 600), |
|
479 |
style=wx.DEFAULT_FRAME_STYLE) |
|
1490
f03bc6c9c146
make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1480
diff
changeset
|
480 |
self._init_icon(prnt) |
814 | 481 |
self.SetClientSize(wx.Size(1000, 600)) |
482 |
self.Bind(wx.EVT_ACTIVATE, self.OnActivated) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
483 |
|
814 | 484 |
self.TabsImageList = wx.ImageList(31, 16) |
485 |
self.TabsImageListIndexes = {} |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
486 |
|
814 | 487 |
#----------------------------------------------------------------------- |
488 |
# Creating main structure |
|
489 |
#----------------------------------------------------------------------- |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
490 |
|
814 | 491 |
self.AUIManager = wx.aui.AuiManager(self) |
492 |
self.AUIManager.SetDockSizeConstraint(0.5, 0.5) |
|
493 |
self.Panes = {} |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
494 |
|
814 | 495 |
self.LeftNoteBook = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORLEFTNOTEBOOK, |
496 |
style=wx.aui.AUI_NB_TOP|wx.aui.AUI_NB_TAB_SPLIT|wx.aui.AUI_NB_TAB_MOVE| |
|
497 |
wx.aui.AUI_NB_SCROLL_BUTTONS|wx.aui.AUI_NB_TAB_EXTERNAL_MOVE) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
498 |
self.LeftNoteBook.Bind(wx.aui.EVT_AUINOTEBOOK_ALLOW_DND, |
814 | 499 |
self.OnAllowNotebookDnD) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
500 |
self.AUIManager.AddPane(self.LeftNoteBook, |
814 | 501 |
wx.aui.AuiPaneInfo().Name("ProjectPane"). |
502 |
Left().Layer(1). |
|
503 |
BestSize(wx.Size(300, 500)).CloseButton(False)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
504 |
|
814 | 505 |
self.BottomNoteBook = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORBOTTOMNOTEBOOK, |
506 |
style=wx.aui.AUI_NB_TOP|wx.aui.AUI_NB_TAB_SPLIT|wx.aui.AUI_NB_TAB_MOVE| |
|
507 |
wx.aui.AUI_NB_SCROLL_BUTTONS|wx.aui.AUI_NB_TAB_EXTERNAL_MOVE) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
508 |
self.BottomNoteBook.Bind(wx.aui.EVT_AUINOTEBOOK_ALLOW_DND, |
814 | 509 |
self.OnAllowNotebookDnD) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
510 |
self.AUIManager.AddPane(self.BottomNoteBook, |
814 | 511 |
wx.aui.AuiPaneInfo().Name("ResultPane"). |
512 |
Bottom().Layer(0). |
|
513 |
BestSize(wx.Size(800, 300)).CloseButton(False)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
514 |
|
814 | 515 |
self.RightNoteBook = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORRIGHTNOTEBOOK, |
516 |
style=wx.aui.AUI_NB_TOP|wx.aui.AUI_NB_TAB_SPLIT|wx.aui.AUI_NB_TAB_MOVE| |
|
517 |
wx.aui.AUI_NB_SCROLL_BUTTONS|wx.aui.AUI_NB_TAB_EXTERNAL_MOVE) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
518 |
self.RightNoteBook.Bind(wx.aui.EVT_AUINOTEBOOK_ALLOW_DND, |
814 | 519 |
self.OnAllowNotebookDnD) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
520 |
self.AUIManager.AddPane(self.RightNoteBook, |
814 | 521 |
wx.aui.AuiPaneInfo().Name("LibraryPane"). |
522 |
Right().Layer(0). |
|
523 |
BestSize(wx.Size(250, 400)).CloseButton(False)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
524 |
|
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
525 |
self.TabsOpened = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORTABSOPENED, |
814 | 526 |
style=wx.aui.AUI_NB_DEFAULT_STYLE|wx.aui.AUI_NB_WINDOWLIST_BUTTON) |
527 |
self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGING, |
|
528 |
self.OnPouSelectedChanging) |
|
529 |
self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, |
|
530 |
self.OnPouSelectedChanged) |
|
531 |
self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, |
|
532 |
self.OnPageClose) |
|
533 |
self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_END_DRAG, |
|
534 |
self.OnPageDragged) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
535 |
self.AUIManager.AddPane(self.TabsOpened, |
814 | 536 |
wx.aui.AuiPaneInfo().CentrePane().Name("TabsPane")) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
537 |
|
814 | 538 |
#----------------------------------------------------------------------- |
539 |
# Creating PLCopen Project Types Tree |
|
540 |
#----------------------------------------------------------------------- |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
541 |
|
814 | 542 |
self.MainTabs = {} |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
543 |
|
814 | 544 |
self.ProjectPanel = wx.SplitterWindow(id=ID_PLCOPENEDITORPROJECTPANEL, |
545 |
name='ProjectPanel', parent=self.LeftNoteBook, point=wx.Point(0, 0), |
|
546 |
size=wx.Size(0, 0), style=wx.SP_3D) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
547 |
|
814 | 548 |
self.ProjectTree = CustomTree(id=ID_PLCOPENEDITORPROJECTTREE, |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
549 |
name='ProjectTree', parent=self.ProjectPanel, |
814 | 550 |
pos=wx.Point(0, 0), size=wx.Size(0, 0), |
1167
a2f9b44c17c9
Fixed bug ProjectTree items label can't be edited
Laurent Bessard
parents:
1165
diff
changeset
|
551 |
style=wx.SUNKEN_BORDER, |
a2f9b44c17c9
Fixed bug ProjectTree items label can't be edited
Laurent Bessard
parents:
1165
diff
changeset
|
552 |
agwStyle=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.TR_EDIT_LABELS) |
814 | 553 |
self.ProjectTree.SetBackgroundBitmap(GetBitmap("custom_tree_background"), |
554 |
wx.ALIGN_RIGHT|wx.ALIGN_BOTTOM) |
|
555 |
add_menu = wx.Menu() |
|
556 |
self._init_coll_AddMenu_Items(add_menu) |
|
557 |
self.ProjectTree.SetAddMenu(add_menu) |
|
1240
ceaf9b4c0f86
Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents:
1233
diff
changeset
|
558 |
self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnProjectTreeRightUp, |
ceaf9b4c0f86
Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents:
1233
diff
changeset
|
559 |
id=ID_PLCOPENEDITORPROJECTTREE) |
ceaf9b4c0f86
Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents:
1233
diff
changeset
|
560 |
self.ProjectTree.Bind(wx.EVT_LEFT_UP, self.OnProjectTreeLeftUp) |
ceaf9b4c0f86
Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents:
1233
diff
changeset
|
561 |
self.Bind(wx.EVT_TREE_SEL_CHANGING, self.OnProjectTreeItemChanging, |
ceaf9b4c0f86
Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents:
1233
diff
changeset
|
562 |
id=ID_PLCOPENEDITORPROJECTTREE) |
814 | 563 |
self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnProjectTreeBeginDrag, |
564 |
id=ID_PLCOPENEDITORPROJECTTREE) |
|
565 |
self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit, |
|
566 |
id=ID_PLCOPENEDITORPROJECTTREE) |
|
567 |
self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnProjectTreeItemEndEdit, |
|
568 |
id=ID_PLCOPENEDITORPROJECTTREE) |
|
569 |
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnProjectTreeItemActivated, |
|
570 |
id=ID_PLCOPENEDITORPROJECTTREE) |
|
1106
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
571 |
self.ProjectTree.Bind(wx.EVT_MOTION, self.OnProjectTreeMotion) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
572 |
|
814 | 573 |
#----------------------------------------------------------------------- |
574 |
# Creating PLCopen Project POU Instance Variables Panel |
|
575 |
#----------------------------------------------------------------------- |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
576 |
|
814 | 577 |
self.PouInstanceVariablesPanel = PouInstanceVariablesPanel(self.ProjectPanel, self, self.Controler, self.EnableDebug) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
578 |
|
814 | 579 |
self.MainTabs["ProjectPanel"] = (self.ProjectPanel, _("Project")) |
580 |
self.LeftNoteBook.AddPage(*self.MainTabs["ProjectPanel"]) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
581 |
|
814 | 582 |
self.ProjectPanel.SplitHorizontally(self.ProjectTree, self.PouInstanceVariablesPanel, 300) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
583 |
|
814 | 584 |
#----------------------------------------------------------------------- |
585 |
# Creating Tool Bar |
|
586 |
#----------------------------------------------------------------------- |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
587 |
|
814 | 588 |
MenuToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORMENUTOOLBAR, wx.DefaultPosition, wx.DefaultSize, |
589 |
wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER) |
|
590 |
MenuToolBar.SetToolBitmapSize(wx.Size(25, 25)) |
|
591 |
MenuToolBar.Realize() |
|
592 |
self.Panes["MenuToolBar"] = MenuToolBar |
|
593 |
self.AUIManager.AddPane(MenuToolBar, wx.aui.AuiPaneInfo(). |
|
594 |
Name("MenuToolBar").Caption(_("Menu ToolBar")). |
|
595 |
ToolbarPane().Top(). |
|
596 |
LeftDockable(False).RightDockable(False)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
597 |
|
814 | 598 |
EditorToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORTOOLBAR, wx.DefaultPosition, wx.DefaultSize, |
599 |
wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER) |
|
600 |
EditorToolBar.SetToolBitmapSize(wx.Size(25, 25)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
601 |
EditorToolBar.AddRadioTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION, |
814 | 602 |
GetBitmap("select"), wx.NullBitmap, _("Select an object")) |
603 |
EditorToolBar.Realize() |
|
604 |
self.Panes["EditorToolBar"] = EditorToolBar |
|
605 |
self.AUIManager.AddPane(EditorToolBar, wx.aui.AuiPaneInfo(). |
|
606 |
Name("EditorToolBar").Caption(_("Editor ToolBar")). |
|
607 |
ToolbarPane().Top().Position(1). |
|
608 |
LeftDockable(False).RightDockable(False)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
609 |
|
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
610 |
self.Bind(wx.EVT_MENU, self.OnSelectionTool, |
814 | 611 |
id=ID_PLCOPENEDITOREDITORTOOLBARSELECTION) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
612 |
|
814 | 613 |
#----------------------------------------------------------------------- |
614 |
# Creating Search Panel |
|
615 |
#----------------------------------------------------------------------- |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
616 |
|
814 | 617 |
self.SearchResultPanel = SearchResultPanel(self.BottomNoteBook, self) |
618 |
self.MainTabs["SearchResultPanel"] = (self.SearchResultPanel, _("Search")) |
|
619 |
self.BottomNoteBook.AddPage(*self.MainTabs["SearchResultPanel"]) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
620 |
|
814 | 621 |
#----------------------------------------------------------------------- |
622 |
# Creating Library Panel |
|
623 |
#----------------------------------------------------------------------- |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
624 |
|
814 | 625 |
self.LibraryPanel = LibraryPanel(self, True) |
626 |
self.MainTabs["LibraryPanel"] = (self.LibraryPanel, _("Library")) |
|
627 |
self.RightNoteBook.AddPage(*self.MainTabs["LibraryPanel"]) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
628 |
|
814 | 629 |
self._init_utils() |
630 |
self.SetMenuBar(self.MenuBar) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
631 |
|
814 | 632 |
if self.EnableDebug: |
902
ffa8ee5ee2fe
Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents:
897
diff
changeset
|
633 |
self.DebugVariablePanel = DebugVariablePanel(self.RightNoteBook, self.Controler, self) |
814 | 634 |
self.MainTabs["DebugVariablePanel"] = (self.DebugVariablePanel, _("Debugger")) |
635 |
self.RightNoteBook.AddPage(*self.MainTabs["DebugVariablePanel"]) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
636 |
|
814 | 637 |
self.AUIManager.Update() |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
638 |
|
814 | 639 |
self.FindDialog = FindInPouDialog(self) |
640 |
self.FindDialog.Hide() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
641 |
|
814 | 642 |
## Constructor of the PLCOpenEditor class. |
643 |
# @param parent The parent window. |
|
644 |
# @param controler The controler been used by PLCOpenEditor (default: None). |
|
645 |
# @param fileOpen The filepath to open if no controler defined (default: None). |
|
646 |
# @param debug The filepath to open if no controler defined (default: False). |
|
647 |
def __init__(self, parent, enable_debug = False): |
|
648 |
self.Controler = None |
|
649 |
self.Config = wx.ConfigBase.Get() |
|
650 |
self.EnableDebug = enable_debug |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
651 |
|
814 | 652 |
self._init_ctrls(parent) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
653 |
|
814 | 654 |
# Define Tree item icon list |
655 |
self.TreeImageList = wx.ImageList(16, 16) |
|
656 |
self.TreeImageDict = {} |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
657 |
|
814 | 658 |
# Icons for languages |
659 |
for language in LANGUAGES: |
|
660 |
self.TreeImageDict[language] = self.TreeImageList.Add(GetBitmap(language)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
661 |
|
814 | 662 |
# Icons for other items |
663 |
for imgname, itemtype in [ |
|
664 |
#editables |
|
665 |
("PROJECT", ITEM_PROJECT), |
|
666 |
#("POU", ITEM_POU), |
|
667 |
#("VARIABLE", ITEM_VARIABLE), |
|
668 |
("TRANSITION", ITEM_TRANSITION), |
|
669 |
("ACTION", ITEM_ACTION), |
|
670 |
("CONFIGURATION", ITEM_CONFIGURATION), |
|
671 |
("RESOURCE", ITEM_RESOURCE), |
|
672 |
("DATATYPE", ITEM_DATATYPE), |
|
673 |
# uneditables |
|
674 |
("DATATYPES", ITEM_DATATYPES), |
|
675 |
("FUNCTION", ITEM_FUNCTION), |
|
676 |
("FUNCTIONBLOCK", ITEM_FUNCTIONBLOCK), |
|
677 |
("PROGRAM", ITEM_PROGRAM), |
|
678 |
("VAR_LOCAL", ITEM_VAR_LOCAL), |
|
679 |
("VAR_LOCAL", ITEM_VAR_GLOBAL), |
|
680 |
("VAR_LOCAL", ITEM_VAR_EXTERNAL), |
|
681 |
("VAR_LOCAL", ITEM_VAR_TEMP), |
|
682 |
("VAR_INPUT", ITEM_VAR_INPUT), |
|
683 |
("VAR_OUTPUT", ITEM_VAR_OUTPUT), |
|
684 |
("VAR_INOUT", ITEM_VAR_INOUT), |
|
685 |
("TRANSITIONS", ITEM_TRANSITIONS), |
|
686 |
("ACTIONS", ITEM_ACTIONS), |
|
687 |
("CONFIGURATIONS", ITEM_CONFIGURATIONS), |
|
688 |
("RESOURCES", ITEM_RESOURCES), |
|
689 |
("PROPERTIES", ITEM_PROPERTIES)]: |
|
690 |
self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(imgname)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
691 |
|
814 | 692 |
# Assign icon list to TreeCtrls |
693 |
self.ProjectTree.SetImageList(self.TreeImageList) |
|
694 |
self.PouInstanceVariablesPanel.SetTreeImageList(self.TreeImageList) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
695 |
|
814 | 696 |
self.CurrentEditorToolBar = [] |
697 |
self.CurrentMenu = None |
|
698 |
self.SelectedItem = None |
|
1106
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
699 |
self.LastToolTipItem = None |
814 | 700 |
self.SearchParams = None |
701 |
self.Highlights = {} |
|
702 |
self.DrawingMode = FREEDRAWING_MODE |
|
703 |
#self.DrawingMode = DRIVENDRAWING_MODE |
|
704 |
self.AuiTabCtrl = [] |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
705 |
|
980
c7ba67d01d65
Completely removed restore perspective and project layout process
Laurent Bessard
parents:
970
diff
changeset
|
706 |
# Save default perspective |
c7ba67d01d65
Completely removed restore perspective and project layout process
Laurent Bessard
parents:
970
diff
changeset
|
707 |
notebooks = {} |
c7ba67d01d65
Completely removed restore perspective and project layout process
Laurent Bessard
parents:
970
diff
changeset
|
708 |
for notebook, entry_name in [(self.LeftNoteBook, "leftnotebook"), |
c7ba67d01d65
Completely removed restore perspective and project layout process
Laurent Bessard
parents:
970
diff
changeset
|
709 |
(self.BottomNoteBook, "bottomnotebook"), |
c7ba67d01d65
Completely removed restore perspective and project layout process
Laurent Bessard
parents:
970
diff
changeset
|
710 |
(self.RightNoteBook, "rightnotebook")]: |
c7ba67d01d65
Completely removed restore perspective and project layout process
Laurent Bessard
parents:
970
diff
changeset
|
711 |
notebooks[entry_name] = self.SaveTabLayout(notebook) |
c7ba67d01d65
Completely removed restore perspective and project layout process
Laurent Bessard
parents:
970
diff
changeset
|
712 |
self.DefaultPerspective = { |
c7ba67d01d65
Completely removed restore perspective and project layout process
Laurent Bessard
parents:
970
diff
changeset
|
713 |
"perspective": self.AUIManager.SavePerspective(), |
c7ba67d01d65
Completely removed restore perspective and project layout process
Laurent Bessard
parents:
970
diff
changeset
|
714 |
"notebooks": notebooks, |
c7ba67d01d65
Completely removed restore perspective and project layout process
Laurent Bessard
parents:
970
diff
changeset
|
715 |
} |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
716 |
|
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
717 |
|
814 | 718 |
# Initialize Printing configuring elements |
719 |
self.PrintData = wx.PrintData() |
|
720 |
self.PrintData.SetPaperId(wx.PAPER_A4) |
|
721 |
self.PrintData.SetPrintMode(wx.PRINT_MODE_PRINTER) |
|
722 |
self.PageSetupData = wx.PageSetupDialogData(self.PrintData) |
|
723 |
self.PageSetupData.SetMarginTopLeft(wx.Point(10, 15)) |
|
724 |
self.PageSetupData.SetMarginBottomRight(wx.Point(10, 20)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
725 |
|
814 | 726 |
self.SetRefreshFunctions() |
1129
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
727 |
self.SetDeleteFunctions() |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
728 |
|
814 | 729 |
def __del__(self): |
730 |
self.FindDialog.Destroy() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
731 |
|
814 | 732 |
def Show(self): |
733 |
wx.Frame.Show(self) |
|
734 |
wx.CallAfter(self.RestoreLastState) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
735 |
|
814 | 736 |
def OnActivated(self, event): |
737 |
if event.GetActive(): |
|
738 |
wx.CallAfter(self._Refresh, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU) |
|
739 |
event.Skip() |
|
740 |
||
999
cbab4c1635bd
Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents:
989
diff
changeset
|
741 |
def SelectTab(self, tab): |
cbab4c1635bd
Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents:
989
diff
changeset
|
742 |
for notebook in [self.LeftNoteBook, self.BottomNoteBook, self.RightNoteBook]: |
cbab4c1635bd
Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents:
989
diff
changeset
|
743 |
idx = notebook.GetPageIndex(tab) |
1015
50bb7cc12a84
Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents:
1010
diff
changeset
|
744 |
if idx != wx.NOT_FOUND and idx != notebook.GetSelection(): |
999
cbab4c1635bd
Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents:
989
diff
changeset
|
745 |
notebook.SetSelection(idx) |
cbab4c1635bd
Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents:
989
diff
changeset
|
746 |
return |
cbab4c1635bd
Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents:
989
diff
changeset
|
747 |
|
814 | 748 |
#------------------------------------------------------------------------------- |
749 |
# Saving and restoring frame organization functions |
|
750 |
#------------------------------------------------------------------------------- |
|
751 |
||
752 |
def GetTabInfos(self, tab): |
|
980
c7ba67d01d65
Completely removed restore perspective and project layout process
Laurent Bessard
parents:
970
diff
changeset
|
753 |
for page_name, (page_ref, page_title) in self.MainTabs.iteritems(): |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
980
diff
changeset
|
754 |
if page_ref == tab: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
980
diff
changeset
|
755 |
return ("main", page_name) |
814 | 756 |
return None |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
757 |
|
814 | 758 |
def SaveTabLayout(self, notebook): |
759 |
tabs = [] |
|
760 |
for child in notebook.GetChildren(): |
|
761 |
if isinstance(child, wx.aui.AuiTabCtrl): |
|
762 |
if child.GetPageCount() > 0: |
|
763 |
pos = child.GetPosition() |
|
764 |
tab = {"pos": (pos.x, pos.y), "pages": []} |
|
765 |
tab_size = child.GetSize() |
|
766 |
for page_idx in xrange(child.GetPageCount()): |
|
767 |
page = child.GetWindowFromIdx(page_idx) |
|
768 |
if not tab.has_key("size"): |
|
769 |
tab["size"] = (tab_size[0], tab_size[1] + page.GetSize()[1]) |
|
770 |
tab_infos = self.GetTabInfos(page) |
|
771 |
if tab_infos is not None: |
|
772 |
tab["pages"].append((tab_infos, page_idx == child.GetActivePage())) |
|
773 |
tabs.append(tab) |
|
774 |
tabs.sort(lambda x, y: cmp(x["pos"], y["pos"])) |
|
775 |
size = notebook.GetSize() |
|
776 |
return ComputeTabsLayout(tabs, wx.Rect(1, 1, size[0] - NOTEBOOK_BORDER, size[1] - NOTEBOOK_BORDER)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
777 |
|
814 | 778 |
def LoadTab(self, notebook, page_infos): |
779 |
if page_infos[0] == "main": |
|
780 |
infos = self.MainTabs.get(page_infos[1]) |
|
781 |
if infos is not None: |
|
782 |
page_ref, page_title = infos |
|
783 |
notebook.AddPage(page_ref, page_title) |
|
784 |
return notebook.GetPageIndex(page_ref) |
|
785 |
elif page_infos[0] == "editor": |
|
786 |
tagname = page_infos[1] |
|
787 |
page_ref = self.EditProjectElement(self.Controler.GetElementType(tagname), tagname) |
|
788 |
if page_ref is not None: |
|
789 |
page_ref.RefreshView() |
|
790 |
return notebook.GetPageIndex(page_ref) |
|
791 |
elif page_infos[0] == "debug": |
|
792 |
instance_path = page_infos[1] |
|
793 |
instance_infos = self.Controler.GetInstanceInfos(instance_path, self.EnableDebug) |
|
794 |
if instance_infos is not None: |
|
795 |
return notebook.GetPageIndex(self.OpenDebugViewer(instance_infos["class"], instance_path, instance_infos["type"])) |
|
796 |
return None |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
797 |
|
814 | 798 |
def LoadTabLayout(self, notebook, tabs, mode="all", first_index=None): |
799 |
if isinstance(tabs, ListType): |
|
800 |
if len(tabs) == 0: |
|
801 |
return |
|
802 |
raise ValueError, "Not supported" |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
803 |
|
814 | 804 |
if tabs.has_key("split"): |
805 |
self.LoadTabLayout(notebook, tabs["others"]) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
806 |
|
814 | 807 |
split_dir, split_ratio = tabs["split"] |
808 |
first_index = self.LoadTabLayout(notebook, tabs["tab"], mode="first") |
|
809 |
notebook.Split(first_index, split_dir) |
|
810 |
self.LoadTabLayout(notebook, tabs["tab"], mode="others", first_index=first_index) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
811 |
|
814 | 812 |
elif mode == "first": |
813 |
return self.LoadTab(notebook, tabs["pages"][0][0]) |
|
814 |
else: |
|
815 |
selected = first_index |
|
816 |
if mode == "others": |
|
817 |
add_tabs = tabs["pages"][1:] |
|
818 |
else: |
|
819 |
add_tabs = tabs["pages"] |
|
820 |
for page_infos, page_selected in add_tabs: |
|
821 |
page_idx = self.LoadTab(notebook, page_infos) |
|
822 |
if page_selected: |
|
823 |
selected = page_idx |
|
824 |
if selected is not None: |
|
825 |
wx.CallAfter(notebook.SetSelection, selected) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
826 |
|
814 | 827 |
def ResetPerspective(self): |
828 |
if self.DefaultPerspective is not None: |
|
829 |
self.AUIManager.LoadPerspective(self.DefaultPerspective["perspective"]) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
830 |
|
814 | 831 |
for notebook in [self.LeftNoteBook, self.BottomNoteBook, self.RightNoteBook]: |
832 |
for idx in xrange(notebook.GetPageCount()): |
|
833 |
notebook.RemovePage(0) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
834 |
|
814 | 835 |
notebooks = self.DefaultPerspective["notebooks"] |
836 |
for notebook, entry_name in [(self.LeftNoteBook, "leftnotebook"), |
|
837 |
(self.BottomNoteBook, "bottomnotebook"), |
|
838 |
(self.RightNoteBook, "rightnotebook")]: |
|
839 |
self.LoadTabLayout(notebook, notebooks.get(entry_name)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
840 |
|
814 | 841 |
self._Refresh(EDITORTOOLBAR) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
842 |
|
814 | 843 |
def RestoreLastState(self): |
844 |
frame_size = None |
|
845 |
if self.Config.HasEntry("framesize"): |
|
846 |
frame_size = cPickle.loads(str(self.Config.Read("framesize"))) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
847 |
|
814 | 848 |
if frame_size is None: |
849 |
self.Maximize() |
|
850 |
else: |
|
851 |
self.SetClientSize(frame_size) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
852 |
|
814 | 853 |
def SaveLastState(self): |
854 |
if not self.IsMaximized(): |
|
855 |
self.Config.Write("framesize", cPickle.dumps(self.GetClientSize())) |
|
856 |
elif self.Config.HasEntry("framesize"): |
|
857 |
self.Config.DeleteEntry("framesize") |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
858 |
|
814 | 859 |
self.Config.Flush() |
860 |
||
861 |
#------------------------------------------------------------------------------- |
|
862 |
# General Functions |
|
863 |
#------------------------------------------------------------------------------- |
|
864 |
||
865 |
def SetRefreshFunctions(self): |
|
866 |
self.RefreshFunctions = { |
|
867 |
TITLE : self.RefreshTitle, |
|
868 |
EDITORTOOLBAR : self.RefreshEditorToolBar, |
|
869 |
FILEMENU : self.RefreshFileMenu, |
|
870 |
EDITMENU : self.RefreshEditMenu, |
|
871 |
DISPLAYMENU : self.RefreshDisplayMenu, |
|
872 |
PROJECTTREE : self.RefreshProjectTree, |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
873 |
POUINSTANCEVARIABLESPANEL : self.RefreshPouInstanceVariablesPanel, |
814 | 874 |
LIBRARYTREE : self.RefreshLibraryPanel, |
875 |
SCALING : self.RefreshScaling, |
|
876 |
PAGETITLES: self.RefreshPageTitles} |
|
877 |
||
878 |
## Call PLCOpenEditor refresh functions. |
|
879 |
# @param elements List of elements to refresh. |
|
880 |
def _Refresh(self, *elements): |
|
881 |
try: |
|
882 |
for element in elements: |
|
883 |
self.RefreshFunctions[element]() |
|
884 |
except wx.PyDeadObjectError: |
|
885 |
# ignore exceptions caused by refresh while quitting |
|
886 |
pass |
|
887 |
||
888 |
## Callback function when AUINotebook Page closed with CloseButton |
|
889 |
# @param event AUINotebook Event. |
|
890 |
def OnPageClose(self, event): |
|
891 |
selected = self.TabsOpened.GetSelection() |
|
892 |
if selected > -1: |
|
893 |
window = self.TabsOpened.GetPage(selected) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
894 |
|
814 | 895 |
if window.CheckSaveBeforeClosing(): |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
896 |
|
814 | 897 |
# Refresh all window elements that have changed |
898 |
wx.CallAfter(self._Refresh, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU) |
|
899 |
wx.CallAfter(self.RefreshTabCtrlEvent) |
|
900 |
wx.CallAfter(self.CloseFindInPouDialog) |
|
901 |
event.Skip() |
|
902 |
else: |
|
903 |
event.Veto() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
904 |
|
814 | 905 |
|
1015
50bb7cc12a84
Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents:
1010
diff
changeset
|
906 |
def GetCopyBuffer(self, primary_selection=False): |
814 | 907 |
data = None |
1028 | 908 |
if primary_selection and wx.Platform == '__WXMSW__': |
909 |
return data |
|
910 |
else: |
|
911 |
wx.TheClipboard.UsePrimarySelection(primary_selection) |
|
814 | 912 |
if wx.TheClipboard.Open(): |
913 |
dataobj = wx.TextDataObject() |
|
914 |
if wx.TheClipboard.GetData(dataobj): |
|
915 |
data = dataobj.GetText() |
|
916 |
wx.TheClipboard.Close() |
|
917 |
return data |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
918 |
|
1015
50bb7cc12a84
Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents:
1010
diff
changeset
|
919 |
def SetCopyBuffer(self, text, primary_selection=False): |
1028 | 920 |
if primary_selection and wx.Platform == '__WXMSW__': |
921 |
return |
|
922 |
else: |
|
923 |
wx.TheClipboard.UsePrimarySelection(primary_selection) |
|
814 | 924 |
if wx.TheClipboard.Open(): |
925 |
data = wx.TextDataObject() |
|
926 |
data.SetText(text) |
|
927 |
wx.TheClipboard.SetData(data) |
|
928 |
wx.TheClipboard.Flush() |
|
929 |
wx.TheClipboard.Close() |
|
1087 | 930 |
self.RefreshEditMenu() |
814 | 931 |
|
932 |
def GetDrawingMode(self): |
|
933 |
return self.DrawingMode |
|
934 |
||
935 |
def RefreshScaling(self): |
|
936 |
for i in xrange(self.TabsOpened.GetPageCount()): |
|
937 |
editor = self.TabsOpened.GetPage(i) |
|
938 |
editor.RefreshScaling() |
|
939 |
||
940 |
def EditProjectSettings(self): |
|
941 |
old_values = self.Controler.GetProjectProperties() |
|
942 |
dialog = ProjectDialog(self) |
|
943 |
dialog.SetValues(old_values) |
|
944 |
if dialog.ShowModal() == wx.ID_OK: |
|
945 |
new_values = dialog.GetValues() |
|
946 |
new_values["creationDateTime"] = old_values["creationDateTime"] |
|
947 |
if new_values != old_values: |
|
948 |
self.Controler.SetProjectProperties(None, new_values) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
949 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, |
814 | 950 |
PROJECTTREE, POUINSTANCEVARIABLESPANEL, SCALING) |
951 |
dialog.Destroy() |
|
952 |
||
953 |
#------------------------------------------------------------------------------- |
|
954 |
# Notebook Unified Functions |
|
955 |
#------------------------------------------------------------------------------- |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
956 |
|
814 | 957 |
## Function that add a tab in Notebook, calling refresh for tab DClick event |
958 |
# for wx.aui.AUINotebook. |
|
959 |
# @param window Panel to display in tab. |
|
960 |
# @param text title for the tab ctrl. |
|
961 |
def AddPage(self, window, text): |
|
962 |
self.TabsOpened.AddPage(window, text) |
|
963 |
self.RefreshTabCtrlEvent() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
964 |
|
814 | 965 |
## Function that add a tab in Notebook, calling refresh for tab DClick event |
966 |
# for wx.aui.AUINotebook. |
|
967 |
# @param window Panel to display in tab. |
|
968 |
# @param text title for the tab ctrl. |
|
969 |
def DeletePage(self, window): |
|
970 |
for idx in xrange(self.TabsOpened.GetPageCount()): |
|
971 |
if self.TabsOpened.GetPage(idx) == window: |
|
972 |
self.TabsOpened.DeletePage(idx) |
|
973 |
self.RefreshTabCtrlEvent() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
974 |
return |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
975 |
|
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
976 |
## Function that fix difference in deleting all tabs between |
814 | 977 |
# wx.Notebook and wx.aui.AUINotebook. |
978 |
def DeleteAllPages(self): |
|
979 |
for idx in xrange(self.TabsOpened.GetPageCount()): |
|
980 |
self.TabsOpened.DeletePage(0) |
|
981 |
self.RefreshTabCtrlEvent() |
|
982 |
||
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
983 |
## Function that fix difference in setting picture on tab between |
814 | 984 |
# wx.Notebook and wx.aui.AUINotebook. |
985 |
# @param idx Tab index. |
|
986 |
# @param bitmap wx.Bitmap to define on tab. |
|
987 |
# @return True if operation succeeded |
|
988 |
def SetPageBitmap(self, idx, bitmap): |
|
989 |
return self.TabsOpened.SetPageBitmap(idx, bitmap) |
|
990 |
||
991 |
#------------------------------------------------------------------------------- |
|
992 |
# Dialog Message Functions |
|
993 |
#------------------------------------------------------------------------------- |
|
994 |
||
995 |
## Function displaying an Error dialog in PLCOpenEditor. |
|
996 |
# @param message The message to display. |
|
997 |
def ShowErrorMessage(self, message): |
|
998 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
|
999 |
dialog.ShowModal() |
|
1000 |
dialog.Destroy() |
|
1001 |
||
1002 |
## Function displaying an Error dialog in PLCOpenEditor. |
|
1003 |
# @return False if closing cancelled. |
|
1004 |
def CheckSaveBeforeClosing(self, title=_("Close Project")): |
|
1005 |
if not self.Controler.ProjectIsSaved(): |
|
1006 |
dialog = wx.MessageDialog(self, _("There are changes, do you want to save?"), title, wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) |
|
1007 |
answer = dialog.ShowModal() |
|
1008 |
dialog.Destroy() |
|
1009 |
if answer == wx.ID_YES: |
|
1010 |
self.SaveProject() |
|
1011 |
elif answer == wx.ID_CANCEL: |
|
1012 |
return False |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1013 |
|
814 | 1014 |
for idx in xrange(self.TabsOpened.GetPageCount()): |
1015 |
window = self.TabsOpened.GetPage(idx) |
|
1016 |
if not window.CheckSaveBeforeClosing(): |
|
1017 |
return False |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1018 |
|
814 | 1019 |
return True |
1020 |
||
1021 |
#------------------------------------------------------------------------------- |
|
1022 |
# File Menu Functions |
|
1023 |
#------------------------------------------------------------------------------- |
|
1024 |
||
1025 |
def RefreshFileMenu(self): |
|
1026 |
pass |
|
1027 |
||
1028 |
def ResetView(self): |
|
1029 |
self.DeleteAllPages() |
|
1030 |
self.ProjectTree.DeleteAllItems() |
|
1031 |
self.ProjectTree.Enable(False) |
|
1032 |
self.PouInstanceVariablesPanel.ResetView() |
|
1033 |
self.LibraryPanel.ResetTree() |
|
1034 |
self.LibraryPanel.SetController(None) |
|
1035 |
if self.EnableDebug: |
|
916
697d8b77d716
Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents:
909
diff
changeset
|
1036 |
self.DebugVariablePanel.ResetView() |
814 | 1037 |
self.Controler = None |
1038 |
||
1039 |
def OnCloseTabMenu(self, event): |
|
1040 |
selected = self.TabsOpened.GetSelection() |
|
1041 |
if selected >= 0: |
|
1042 |
self.TabsOpened.DeletePage(selected) |
|
1043 |
if self.TabsOpened.GetPageCount() > 0: |
|
1044 |
new_index = min(selected, self.TabsOpened.GetPageCount() - 1) |
|
1045 |
self.TabsOpened.SetSelection(new_index) |
|
1046 |
# Refresh all window elements that have changed |
|
1047 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU) |
|
1048 |
self.RefreshTabCtrlEvent() |
|
1049 |
||
1050 |
def OnPageSetupMenu(self, event): |
|
1051 |
dialog = wx.PageSetupDialog(self, self.PageSetupData) |
|
1052 |
if dialog.ShowModal() == wx.ID_OK: |
|
1053 |
self.PageSetupData = wx.PageSetupDialogData(dialog.GetPageSetupData()) |
|
1054 |
self.PrintData = wx.PrintData(self.PageSetupData.GetPrintData()) |
|
1055 |
dialog.Destroy() |
|
1056 |
||
1057 |
def OnPreviewMenu(self, event): |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1058 |
selected = self.TabsOpened.GetSelection() |
814 | 1059 |
if selected != -1: |
1060 |
window = self.TabsOpened.GetPage(selected) |
|
1061 |
data = wx.PrintDialogData(self.PrintData) |
|
1062 |
properties = self.Controler.GetProjectProperties(window.IsDebugging()) |
|
1063 |
page_size = map(int, properties["pageSize"]) |
|
1064 |
margins = (self.PageSetupData.GetMarginTopLeft(), self.PageSetupData.GetMarginBottomRight()) |
|
1065 |
printout = GraphicPrintout(window, page_size, margins, True) |
|
1066 |
printout2 = GraphicPrintout(window, page_size, margins, True) |
|
1067 |
preview = wx.PrintPreview(printout, printout2, data) |
|
1068 |
||
1069 |
if preview.Ok(): |
|
1070 |
preview_frame = wx.PreviewFrame(preview, self, _("Print preview"), style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_FLOAT_ON_PARENT) |
|
1071 |
||
1072 |
preview_frame.Initialize() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1073 |
|
814 | 1074 |
preview_canvas = preview.GetCanvas() |
1075 |
preview_canvas.SetMinSize(preview_canvas.GetVirtualSize()) |
|
1076 |
preview_frame.Fit() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1077 |
|
814 | 1078 |
preview_frame.Show(True) |
1079 |
||
1080 |
def OnPrintMenu(self, event): |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1081 |
selected = self.TabsOpened.GetSelection() |
814 | 1082 |
if selected != -1: |
1083 |
window = self.TabsOpened.GetPage(selected) |
|
1084 |
dialog_data = wx.PrintDialogData(self.PrintData) |
|
1085 |
dialog_data.SetToPage(1) |
|
1086 |
properties = self.Controler.GetProjectProperties(window.IsDebugging()) |
|
1087 |
page_size = map(int, properties["pageSize"]) |
|
1088 |
margins = (self.PageSetupData.GetMarginTopLeft(), self.PageSetupData.GetMarginBottomRight()) |
|
1089 |
printer = wx.Printer(dialog_data) |
|
1090 |
printout = GraphicPrintout(window, page_size, margins) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1091 |
|
814 | 1092 |
if not printer.Print(self, printout, True) and printer.GetLastError() != wx.PRINTER_CANCELLED: |
1093 |
self.ShowErrorMessage(_("There was a problem printing.\nPerhaps your current printer is not set correctly?")) |
|
1094 |
printout.Destroy() |
|
1095 |
||
1096 |
def OnPropertiesMenu(self, event): |
|
1097 |
self.EditProjectSettings() |
|
1098 |
||
1099 |
def OnQuitMenu(self, event): |
|
1100 |
self.Close() |
|
1101 |
||
1102 |
#------------------------------------------------------------------------------- |
|
1103 |
# Edit Menu Functions |
|
1104 |
#------------------------------------------------------------------------------- |
|
1105 |
||
1106 |
def RefreshEditMenu(self): |
|
1107 |
MenuToolBar = self.Panes["MenuToolBar"] |
|
1108 |
if self.Controler is not None: |
|
1109 |
selected = self.TabsOpened.GetSelection() |
|
1110 |
if selected > -1: |
|
1111 |
window = self.TabsOpened.GetPage(selected) |
|
1112 |
undo, redo = window.GetBufferState() |
|
1113 |
else: |
|
1114 |
undo, redo = self.Controler.GetBufferState() |
|
1115 |
self.EditMenu.Enable(wx.ID_UNDO, undo) |
|
1116 |
MenuToolBar.EnableTool(wx.ID_UNDO, undo) |
|
1117 |
self.EditMenu.Enable(wx.ID_REDO, redo) |
|
1118 |
MenuToolBar.EnableTool(wx.ID_REDO, redo) |
|
1119 |
#self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, True) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1120 |
#self.EditMenu.Check(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, |
814 | 1121 |
# self.Controler.IsProjectBufferEnabled()) |
1122 |
self.EditMenu.Enable(wx.ID_FIND, selected > -1) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1123 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUFINDNEXT, |
814 | 1124 |
selected > -1 and self.SearchParams is not None) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1125 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUFINDPREVIOUS, |
814 | 1126 |
selected > -1 and self.SearchParams is not None) |
1127 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, True) |
|
1128 |
MenuToolBar.EnableTool(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, True) |
|
1129 |
self.EditMenu.Enable(wx.ID_ADD, True) |
|
1130 |
self.EditMenu.Enable(wx.ID_DELETE, True) |
|
1131 |
if self.TabsOpened.GetPageCount() > 0: |
|
1132 |
self.EditMenu.Enable(wx.ID_CUT, True) |
|
1133 |
MenuToolBar.EnableTool(wx.ID_CUT, True) |
|
1134 |
self.EditMenu.Enable(wx.ID_COPY, True) |
|
1135 |
MenuToolBar.EnableTool(wx.ID_COPY, True) |
|
1136 |
if self.GetCopyBuffer() is not None: |
|
1137 |
self.EditMenu.Enable(wx.ID_PASTE, True) |
|
1138 |
MenuToolBar.EnableTool(wx.ID_PASTE, True) |
|
1139 |
else: |
|
1140 |
self.EditMenu.Enable(wx.ID_PASTE, False) |
|
1141 |
MenuToolBar.EnableTool(wx.ID_PASTE, False) |
|
1142 |
self.EditMenu.Enable(wx.ID_SELECTALL, True) |
|
1143 |
else: |
|
1144 |
self.EditMenu.Enable(wx.ID_CUT, False) |
|
1145 |
MenuToolBar.EnableTool(wx.ID_CUT, False) |
|
1146 |
self.EditMenu.Enable(wx.ID_COPY, False) |
|
1147 |
MenuToolBar.EnableTool(wx.ID_COPY, False) |
|
1148 |
self.EditMenu.Enable(wx.ID_PASTE, False) |
|
1149 |
MenuToolBar.EnableTool(wx.ID_PASTE, False) |
|
1150 |
self.EditMenu.Enable(wx.ID_SELECTALL, False) |
|
1151 |
else: |
|
1152 |
self.EditMenu.Enable(wx.ID_UNDO, False) |
|
1153 |
MenuToolBar.EnableTool(wx.ID_UNDO, False) |
|
1154 |
self.EditMenu.Enable(wx.ID_REDO, False) |
|
1155 |
MenuToolBar.EnableTool(wx.ID_REDO, False) |
|
1156 |
#self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, False) |
|
1157 |
self.EditMenu.Enable(wx.ID_CUT, False) |
|
1158 |
MenuToolBar.EnableTool(wx.ID_CUT, False) |
|
1159 |
self.EditMenu.Enable(wx.ID_COPY, False) |
|
1160 |
MenuToolBar.EnableTool(wx.ID_COPY, False) |
|
1161 |
self.EditMenu.Enable(wx.ID_PASTE, False) |
|
1162 |
MenuToolBar.EnableTool(wx.ID_PASTE, False) |
|
1163 |
self.EditMenu.Enable(wx.ID_SELECTALL, False) |
|
1164 |
self.EditMenu.Enable(wx.ID_FIND, False) |
|
1165 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUFINDNEXT, False) |
|
1166 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUFINDPREVIOUS, False) |
|
1167 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, False) |
|
1168 |
MenuToolBar.EnableTool(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, False) |
|
1169 |
self.EditMenu.Enable(wx.ID_ADD, False) |
|
1170 |
self.EditMenu.Enable(wx.ID_DELETE, False) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1171 |
|
814 | 1172 |
def CloseTabsWithoutModel(self, refresh=True): |
1173 |
idxs = range(self.TabsOpened.GetPageCount()) |
|
1174 |
idxs.reverse() |
|
1175 |
for idx in idxs: |
|
1176 |
window = self.TabsOpened.GetPage(idx) |
|
1177 |
if window.HasNoModel(): |
|
1178 |
self.TabsOpened.DeletePage(idx) |
|
1179 |
if refresh: |
|
1180 |
self.RefreshEditor() |
|
1181 |
||
1182 |
def OnUndoMenu(self, event): |
|
1183 |
selected = self.TabsOpened.GetSelection() |
|
1184 |
if selected != -1: |
|
1185 |
window = self.TabsOpened.GetPage(selected) |
|
1186 |
window.Undo() |
|
1187 |
else: |
|
1188 |
self.Controler.LoadPrevious() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1189 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1190 |
SCALING, PAGETITLES) |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1191 |
|
814 | 1192 |
def OnRedoMenu(self, event): |
1193 |
selected = self.TabsOpened.GetSelection() |
|
1194 |
if selected != -1: |
|
1195 |
window = self.TabsOpened.GetPage(selected) |
|
1196 |
window.Redo() |
|
1197 |
else: |
|
1198 |
self.Controler.LoadNext() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1199 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE, |
814 | 1200 |
SCALING, PAGETITLES) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1201 |
|
814 | 1202 |
def OnEnableUndoRedoMenu(self, event): |
1203 |
self.Controler.EnableProjectBuffer(event.IsChecked()) |
|
1204 |
self.RefreshEditMenu() |
|
1205 |
||
1206 |
OnCutMenu = GetShortcutKeyCallbackFunction("Cut") |
|
1207 |
OnCopyMenu = GetShortcutKeyCallbackFunction("Copy") |
|
1208 |
OnPasteMenu = GetShortcutKeyCallbackFunction("Paste") |
|
1209 |
||
1210 |
def OnSelectAllMenu(self, event): |
|
1211 |
control = self.FindFocus() |
|
1212 |
if control is not None and control.GetName() == "Viewer": |
|
1213 |
control.Parent.SelectAll() |
|
1214 |
elif isinstance(control, wx.stc.StyledTextCtrl): |
|
1215 |
control.SelectAll() |
|
1216 |
elif isinstance(control, wx.TextCtrl): |
|
1217 |
control.SetSelection(0, control.GetLastPosition()) |
|
1218 |
elif isinstance(control, wx.ComboBox): |
|
1219 |
control.SetMark(0, control.GetLastPosition() + 1) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1220 |
|
1129
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
1221 |
def SetDeleteFunctions(self): |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
1222 |
self.DeleteFunctions = { |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
1223 |
ITEM_DATATYPE: GetDeleteElementFunction( |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1224 |
PLCControler.ProjectRemoveDataType, |
1129
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
1225 |
check_function=self.CheckDataTypeIsUsedBeforeDeletion), |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
1226 |
ITEM_POU: GetDeleteElementFunction( |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1227 |
PLCControler.ProjectRemovePou, |
1129
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
1228 |
check_function=self.CheckPouIsUsedBeforeDeletion), |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
1229 |
ITEM_TRANSITION: GetDeleteElementFunction( |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
1230 |
PLCControler.ProjectRemovePouTransition, ITEM_POU), |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
1231 |
ITEM_ACTION: GetDeleteElementFunction( |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
1232 |
PLCControler.ProjectRemovePouAction, ITEM_POU), |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
1233 |
ITEM_CONFIGURATION: GetDeleteElementFunction( |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
1234 |
PLCControler.ProjectRemoveConfiguration), |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
1235 |
ITEM_RESOURCE: GetDeleteElementFunction( |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
1236 |
PLCControler.ProjectRemoveConfigurationResource, ITEM_CONFIGURATION) |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
1237 |
} |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1238 |
|
814 | 1239 |
def OnDeleteMenu(self, event): |
1240 |
window = self.FindFocus() |
|
1241 |
if window == self.ProjectTree or window is None: |
|
1242 |
selected = self.ProjectTree.GetSelection() |
|
1165
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
1243 |
if selected is not None and selected.IsOk(): |
814 | 1244 |
function = self.DeleteFunctions.get(self.ProjectTree.GetPyData(selected)["type"], None) |
1245 |
if function is not None: |
|
1246 |
function(self, selected) |
|
1247 |
self.CloseTabsWithoutModel() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1248 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, |
814 | 1249 |
POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
1250 |
elif isinstance(window, (Viewer, TextViewer)): |
|
1251 |
event = wx.KeyEvent(wx.EVT_CHAR._getEvtType()) |
|
1252 |
event.m_keyCode = wx.WXK_DELETE |
|
1253 |
window.ProcessEvent(event) |
|
1254 |
||
1255 |
def OnFindMenu(self, event): |
|
1256 |
if not self.FindDialog.IsShown(): |
|
1257 |
self.FindDialog.Show() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1258 |
|
814 | 1259 |
def CloseFindInPouDialog(self): |
1260 |
selected = self.TabsOpened.GetSelection() |
|
1261 |
if selected == -1 and self.FindDialog.IsShown(): |
|
1262 |
self.FindDialog.Hide() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1263 |
|
814 | 1264 |
def OnFindNextMenu(self, event): |
1265 |
self.FindInPou(1) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1266 |
|
814 | 1267 |
def OnFindPreviousMenu(self, event): |
1268 |
self.FindInPou(-1) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1269 |
|
814 | 1270 |
def FindInPou(self, direction, search_params=None): |
1271 |
if search_params is not None: |
|
1272 |
self.SearchParams = search_params |
|
1273 |
selected = self.TabsOpened.GetSelection() |
|
1274 |
if selected != -1: |
|
1275 |
window = self.TabsOpened.GetPage(selected) |
|
1276 |
window.Find(direction, self.SearchParams) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1277 |
|
814 | 1278 |
def OnSearchInProjectMenu(self, event): |
1279 |
dialog = SearchInProjectDialog(self) |
|
1280 |
if dialog.ShowModal() == wx.ID_OK: |
|
1281 |
criteria = dialog.GetCriteria() |
|
1282 |
result = self.Controler.SearchInProject(criteria) |
|
1283 |
self.ClearSearchResults() |
|
1284 |
self.SearchResultPanel.SetSearchResults(criteria, result) |
|
999
cbab4c1635bd
Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents:
989
diff
changeset
|
1285 |
self.SelectTab(self.SearchResultPanel) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1286 |
|
814 | 1287 |
#------------------------------------------------------------------------------- |
1288 |
# Display Menu Functions |
|
1289 |
#------------------------------------------------------------------------------- |
|
1290 |
||
1291 |
def RefreshDisplayMenu(self): |
|
1292 |
if self.Controler is not None: |
|
1293 |
if self.TabsOpened.GetPageCount() > 0: |
|
1294 |
self.DisplayMenu.Enable(wx.ID_REFRESH, True) |
|
1295 |
selected = self.TabsOpened.GetSelection() |
|
1296 |
if selected != -1: |
|
1297 |
window = self.TabsOpened.GetPage(selected) |
|
1298 |
if isinstance(window, Viewer): |
|
1299 |
self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, True) |
|
1300 |
zoommenu = self.DisplayMenu.FindItemById(wx.ID_ZOOM_FIT).GetSubMenu() |
|
1301 |
zoomitem = zoommenu.FindItemByPosition(window.GetScale()) |
|
1302 |
zoomitem.Check(True) |
|
1303 |
else: |
|
1304 |
self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False) |
|
1305 |
else: |
|
1306 |
self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False) |
|
1307 |
else: |
|
1308 |
self.DisplayMenu.Enable(wx.ID_REFRESH, False) |
|
1309 |
self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False) |
|
1310 |
if self.EnableDebug: |
|
1311 |
self.DisplayMenu.Enable(wx.ID_CLEAR, True) |
|
1312 |
else: |
|
1313 |
self.DisplayMenu.Enable(wx.ID_REFRESH, False) |
|
1314 |
if self.EnableDebug: |
|
1315 |
self.DisplayMenu.Enable(wx.ID_CLEAR, False) |
|
1316 |
self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1317 |
|
814 | 1318 |
def OnRefreshMenu(self, event): |
1319 |
self.RefreshEditor() |
|
1320 |
||
1321 |
def OnClearErrorsMenu(self, event): |
|
1322 |
self.ClearErrors() |
|
1323 |
||
1324 |
def GenerateZoomFunction(self, idx): |
|
1325 |
def ZoomFunction(event): |
|
1326 |
selected = self.TabsOpened.GetSelection() |
|
1327 |
if selected != -1: |
|
1328 |
window = self.TabsOpened.GetPage(selected) |
|
1329 |
window.SetScale(idx) |
|
1330 |
window.RefreshVisibleElements() |
|
1331 |
window.RefreshScrollBars() |
|
1332 |
event.Skip() |
|
1333 |
return ZoomFunction |
|
1334 |
||
1335 |
def OnResetPerspective(self, event): |
|
1336 |
self.ResetPerspective() |
|
1337 |
||
1338 |
#------------------------------------------------------------------------------- |
|
1339 |
# Project Editor Panels Management Functions |
|
1340 |
#------------------------------------------------------------------------------- |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1341 |
|
814 | 1342 |
def OnPageDragged(self, event): |
1343 |
wx.CallAfter(self.RefreshTabCtrlEvent) |
|
1344 |
event.Skip() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1345 |
|
814 | 1346 |
def OnAllowNotebookDnD(self, event): |
1347 |
event.Allow() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1348 |
|
814 | 1349 |
def RefreshTabCtrlEvent(self): |
1350 |
auitabctrl = [] |
|
1351 |
for child in self.TabsOpened.GetChildren(): |
|
1352 |
if isinstance(child, wx.aui.AuiTabCtrl): |
|
1353 |
auitabctrl.append(child) |
|
1354 |
if child not in self.AuiTabCtrl: |
|
1355 |
child.Bind(wx.EVT_LEFT_DCLICK, self.GetTabsOpenedDClickFunction(child)) |
|
1356 |
self.AuiTabCtrl = auitabctrl |
|
1357 |
if self.TabsOpened.GetPageCount() == 0: |
|
1358 |
pane = self.AUIManager.GetPane(self.TabsOpened) |
|
1359 |
if pane.IsMaximized(): |
|
1360 |
self.AUIManager.RestorePane(pane) |
|
1361 |
self.AUIManager.Update() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1362 |
|
814 | 1363 |
def EnsureTabVisible(self, tab): |
1364 |
notebook = tab.GetParent() |
|
1365 |
notebook.SetSelection(notebook.GetPageIndex(tab)) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1366 |
|
814 | 1367 |
def OnPouSelectedChanging(self, event): |
989 | 1368 |
selected = self.TabsOpened.GetSelection() |
1369 |
if selected >= 0: |
|
1370 |
window = self.TabsOpened.GetPage(selected) |
|
1371 |
if not window.IsDebugging(): |
|
1372 |
window.ResetBuffer() |
|
814 | 1373 |
event.Skip() |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1374 |
|
814 | 1375 |
def OnPouSelectedChanged(self, event): |
989 | 1376 |
selected = self.TabsOpened.GetSelection() |
1377 |
if selected >= 0: |
|
1378 |
window = self.TabsOpened.GetPage(selected) |
|
1379 |
tagname = window.GetTagName() |
|
1380 |
if not window.IsDebugging(): |
|
1158
193e6cd9010f
Fixed bug tabs selected cyclically when drag'n dropping variable into Editor
Laurent Bessard
parents:
1129
diff
changeset
|
1381 |
self.SelectProjectTreeItem(tagname) |
1233
5e6d0969bb5d
Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents:
1222
diff
changeset
|
1382 |
self.PouInstanceVariablesPanel.SetPouType(tagname) |
989 | 1383 |
window.RefreshView() |
1384 |
self.EnsureTabVisible(self.LibraryPanel) |
|
1385 |
else: |
|
1386 |
instance_path = window.GetInstancePath() |
|
1387 |
if tagname == "": |
|
1388 |
instance_path = instance_path.rsplit(".", 1)[0] |
|
1389 |
tagname = self.Controler.GetPouInstanceTagName(instance_path, self.EnableDebug) |
|
1390 |
self.EnsureTabVisible(self.DebugVariablePanel) |
|
1391 |
wx.CallAfter(self.PouInstanceVariablesPanel.SetPouType, tagname, instance_path) |
|
1392 |
wx.CallAfter(self._Refresh, FILEMENU, EDITMENU, DISPLAYMENU, EDITORTOOLBAR) |
|
814 | 1393 |
event.Skip() |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1394 |
|
814 | 1395 |
def RefreshEditor(self): |
1396 |
selected = self.TabsOpened.GetSelection() |
|
1397 |
if selected >= 0: |
|
1398 |
window = self.TabsOpened.GetPage(selected) |
|
1399 |
tagname = window.GetTagName() |
|
1400 |
if not window.IsDebugging(): |
|
1401 |
self.SelectProjectTreeItem(tagname) |
|
1402 |
self.PouInstanceVariablesPanel.SetPouType(tagname) |
|
1403 |
else: |
|
1404 |
instance_path = window.GetInstancePath() |
|
1405 |
if tagname == "": |
|
1406 |
instance_path = instance_path.rsplit(".", 1)[0] |
|
1407 |
tagname = self.Controler.GetPouInstanceTagName(instance_path, self.EnableDebug) |
|
1408 |
self.PouInstanceVariablesPanel.SetPouType(tagname, instance_path) |
|
1409 |
for child in self.TabsOpened.GetChildren(): |
|
1410 |
if isinstance(child, wx.aui.AuiTabCtrl): |
|
1411 |
active_page = child.GetActivePage() |
|
1412 |
if active_page >= 0: |
|
1413 |
window = child.GetWindowFromIdx(active_page) |
|
1414 |
window.RefreshView() |
|
1415 |
self._Refresh(FILEMENU, EDITMENU, DISPLAYMENU, EDITORTOOLBAR) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1416 |
|
814 | 1417 |
def RefreshEditorNames(self, old_tagname, new_tagname): |
1418 |
for i in xrange(self.TabsOpened.GetPageCount()): |
|
1419 |
editor = self.TabsOpened.GetPage(i) |
|
1420 |
if editor.GetTagName() == old_tagname: |
|
1421 |
editor.SetTagName(new_tagname) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1422 |
|
814 | 1423 |
def IsOpened(self, tagname): |
1424 |
for idx in xrange(self.TabsOpened.GetPageCount()): |
|
1425 |
if self.TabsOpened.GetPage(idx).IsViewing(tagname): |
|
1426 |
return idx |
|
1427 |
return None |
|
1428 |
||
1429 |
def RefreshPageTitles(self): |
|
1430 |
for idx in xrange(self.TabsOpened.GetPageCount()): |
|
1431 |
window = self.TabsOpened.GetPage(idx) |
|
1432 |
icon = window.GetIcon() |
|
1433 |
if icon is not None: |
|
1434 |
self.SetPageBitmap(idx, icon) |
|
1435 |
self.TabsOpened.SetPageText(idx, window.GetTitle()) |
|
1436 |
||
1437 |
def GetTabsOpenedDClickFunction(self, tabctrl): |
|
1438 |
def OnTabsOpenedDClick(event): |
|
1439 |
pos = event.GetPosition() |
|
1440 |
if tabctrl.TabHitTest(pos.x, pos.y, None): |
|
1441 |
pane = self.AUIManager.GetPane(self.TabsOpened) |
|
1442 |
if pane.IsMaximized(): |
|
1443 |
self.AUIManager.RestorePane(pane) |
|
1444 |
else: |
|
1445 |
self.AUIManager.MaximizePane(pane) |
|
1446 |
self.AUIManager.Update() |
|
1447 |
event.Skip() |
|
1448 |
return OnTabsOpenedDClick |
|
1449 |
||
1450 |
#------------------------------------------------------------------------------- |
|
1451 |
# Types Tree Management Functions |
|
1452 |
#------------------------------------------------------------------------------- |
|
1453 |
||
1454 |
def RefreshProjectTree(self): |
|
1105
f0e5b475a074
Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents:
1089
diff
changeset
|
1455 |
# Extract current selected item tagname |
f0e5b475a074
Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents:
1089
diff
changeset
|
1456 |
selected = self.ProjectTree.GetSelection() |
f0e5b475a074
Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents:
1089
diff
changeset
|
1457 |
if selected is not None and selected.IsOk(): |
f0e5b475a074
Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents:
1089
diff
changeset
|
1458 |
item_infos = self.ProjectTree.GetPyData(selected) |
f0e5b475a074
Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents:
1089
diff
changeset
|
1459 |
tagname = item_infos.get("tagname", None) |
f0e5b475a074
Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents:
1089
diff
changeset
|
1460 |
else: |
f0e5b475a074
Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents:
1089
diff
changeset
|
1461 |
tagname = None |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1462 |
|
1105
f0e5b475a074
Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents:
1089
diff
changeset
|
1463 |
# Refresh treectrl items according to project infos |
814 | 1464 |
infos = self.Controler.GetProjectInfos() |
1465 |
root = self.ProjectTree.GetRootItem() |
|
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
1159
diff
changeset
|
1466 |
if root is None or not root.IsOk(): |
814 | 1467 |
root = self.ProjectTree.AddRoot(infos["name"]) |
1468 |
self.GenerateProjectTreeBranch(root, infos) |
|
1469 |
self.ProjectTree.Expand(root) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1470 |
|
1105
f0e5b475a074
Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents:
1089
diff
changeset
|
1471 |
# Select new item corresponding to previous selected item |
f0e5b475a074
Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents:
1089
diff
changeset
|
1472 |
if tagname is not None: |
1158
193e6cd9010f
Fixed bug tabs selected cyclically when drag'n dropping variable into Editor
Laurent Bessard
parents:
1129
diff
changeset
|
1473 |
self.SelectProjectTreeItem(tagname) |
814 | 1474 |
|
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
1159
diff
changeset
|
1475 |
def GenerateProjectTreeBranch(self, root, infos, item_alone=False): |
814 | 1476 |
to_delete = [] |
1477 |
item_name = infos["name"] |
|
1478 |
if infos["type"] in ITEMS_UNEDITABLE: |
|
1479 |
if len(infos["values"]) == 1: |
|
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
1159
diff
changeset
|
1480 |
return self.GenerateProjectTreeBranch(root, infos["values"][0], True) |
814 | 1481 |
item_name = _(item_name) |
1482 |
self.ProjectTree.SetItemText(root, item_name) |
|
1483 |
self.ProjectTree.SetPyData(root, infos) |
|
1484 |
highlight_colours = self.Highlights.get(infos.get("tagname", None), (wx.WHITE, wx.BLACK)) |
|
1485 |
self.ProjectTree.SetItemBackgroundColour(root, highlight_colours[0]) |
|
1486 |
self.ProjectTree.SetItemTextColour(root, highlight_colours[1]) |
|
1188
63afb5833bd8
Fixed bug two icons displayed for POU category item in Project Tree when adding a second POU
Laurent Bessard
parents:
1176
diff
changeset
|
1487 |
self.ProjectTree.SetItemExtraImage(root, None) |
814 | 1488 |
if infos["type"] == ITEM_POU: |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1489 |
self.ProjectTree.SetItemImage(root, |
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
1159
diff
changeset
|
1490 |
self.TreeImageDict[self.Controler.GetPouBodyType(infos["name"])]) |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
1159
diff
changeset
|
1491 |
if item_alone: |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
1159
diff
changeset
|
1492 |
self.ProjectTree.SetItemExtraImage(root, self.Controler.GetPouType(infos["name"])) |
814 | 1493 |
elif infos.has_key("icon") and infos["icon"] is not None: |
1494 |
icon_name = infos["icon"] |
|
1495 |
if not self.TreeImageDict.has_key(icon_name): |
|
1496 |
self.TreeImageDict[icon_name] = self.TreeImageList.Add(GetBitmap(icon_name)) |
|
1497 |
self.ProjectTree.SetItemImage(root, self.TreeImageDict[icon_name]) |
|
1498 |
elif self.TreeImageDict.has_key(infos["type"]): |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1499 |
self.ProjectTree.SetItemImage(root, self.TreeImageDict[infos["type"]]) |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1500 |
|
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
1159
diff
changeset
|
1501 |
item, root_cookie = self.ProjectTree.GetFirstChild(root) |
814 | 1502 |
for values in infos["values"]: |
1503 |
if values["type"] not in ITEMS_UNEDITABLE or len(values["values"]) > 0: |
|
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
1159
diff
changeset
|
1504 |
if item is None or not item.IsOk(): |
814 | 1505 |
item = self.ProjectTree.AppendItem(root, "") |
1165
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
1506 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
814 | 1507 |
self.GenerateProjectTreeBranch(item, values) |
1508 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
|
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
1159
diff
changeset
|
1509 |
while item is not None and item.IsOk(): |
814 | 1510 |
to_delete.append(item) |
1511 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
|
1512 |
for item in to_delete: |
|
1513 |
self.ProjectTree.Delete(item) |
|
1514 |
||
1165
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
1515 |
TagNamePartsItemTypes = { |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
1516 |
"D": [ITEM_DATATYPE], |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
1517 |
"P": [ITEM_POU], |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
1518 |
"T": [ITEM_POU, ITEM_TRANSITION], |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
1519 |
"A": [ITEM_POU, ITEM_ACTION], |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
1520 |
"C": [ITEM_CONFIGURATION], |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
1521 |
"R": [ITEM_CONFIGURATION, ITEM_RESOURCE]} |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
1522 |
|
814 | 1523 |
def SelectProjectTreeItem(self, tagname): |
1158
193e6cd9010f
Fixed bug tabs selected cyclically when drag'n dropping variable into Editor
Laurent Bessard
parents:
1129
diff
changeset
|
1524 |
result = False |
814 | 1525 |
if self.ProjectTree is not None: |
1526 |
root = self.ProjectTree.GetRootItem() |
|
1165
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
1527 |
if root is not None and root.IsOk(): |
814 | 1528 |
words = tagname.split("::") |
1165
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
1529 |
result = self.RecursiveProjectTreeItemSelection(root, |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
1530 |
zip(words[1:], self.TagNamePartsItemTypes.get(words[0], []))) |
1158
193e6cd9010f
Fixed bug tabs selected cyclically when drag'n dropping variable into Editor
Laurent Bessard
parents:
1129
diff
changeset
|
1531 |
return result |
814 | 1532 |
|
1533 |
def RecursiveProjectTreeItemSelection(self, root, items): |
|
1534 |
found = False |
|
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
1159
diff
changeset
|
1535 |
item, root_cookie = self.ProjectTree.GetFirstChild(root) |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
1159
diff
changeset
|
1536 |
while item is not None and item.IsOk() and not found: |
814 | 1537 |
item_infos = self.ProjectTree.GetPyData(item) |
1538 |
if (item_infos["name"].split(":")[-1].strip(), item_infos["type"]) == items[0]: |
|
1539 |
if len(items) == 1: |
|
1540 |
self.SelectedItem = item |
|
1158
193e6cd9010f
Fixed bug tabs selected cyclically when drag'n dropping variable into Editor
Laurent Bessard
parents:
1129
diff
changeset
|
1541 |
self.ProjectTree.SelectItem(item) |
193e6cd9010f
Fixed bug tabs selected cyclically when drag'n dropping variable into Editor
Laurent Bessard
parents:
1129
diff
changeset
|
1542 |
self.ResetSelectedItem() |
814 | 1543 |
return True |
1544 |
else: |
|
1545 |
found = self.RecursiveProjectTreeItemSelection(item, items[1:]) |
|
1546 |
else: |
|
1547 |
found = self.RecursiveProjectTreeItemSelection(item, items) |
|
1548 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
|
1549 |
return found |
|
1550 |
||
1243
e77c95c4c7fc
Fixed bug when drag'n dropping POU from project tree and POU is selected
Laurent Bessard
parents:
1240
diff
changeset
|
1551 |
def ResetSelectedItem(self): |
e77c95c4c7fc
Fixed bug when drag'n dropping POU from project tree and POU is selected
Laurent Bessard
parents:
1240
diff
changeset
|
1552 |
self.SelectedItem = None |
e77c95c4c7fc
Fixed bug when drag'n dropping POU from project tree and POU is selected
Laurent Bessard
parents:
1240
diff
changeset
|
1553 |
|
814 | 1554 |
def OnProjectTreeBeginDrag(self, event): |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1555 |
selected_item = (self.SelectedItem |
1243
e77c95c4c7fc
Fixed bug when drag'n dropping POU from project tree and POU is selected
Laurent Bessard
parents:
1240
diff
changeset
|
1556 |
if self.SelectedItem is not None |
e77c95c4c7fc
Fixed bug when drag'n dropping POU from project tree and POU is selected
Laurent Bessard
parents:
1240
diff
changeset
|
1557 |
else event.GetItem()) |
e77c95c4c7fc
Fixed bug when drag'n dropping POU from project tree and POU is selected
Laurent Bessard
parents:
1240
diff
changeset
|
1558 |
if selected_item.IsOk() and self.ProjectTree.GetPyData(selected_item)["type"] == ITEM_POU: |
e77c95c4c7fc
Fixed bug when drag'n dropping POU from project tree and POU is selected
Laurent Bessard
parents:
1240
diff
changeset
|
1559 |
block_name = self.ProjectTree.GetItemText(selected_item) |
814 | 1560 |
block_type = self.Controler.GetPouType(block_name) |
1561 |
if block_type != "program": |
|
1562 |
data = wx.TextDataObject(str((block_name, block_type, ""))) |
|
1563 |
dragSource = wx.DropSource(self.ProjectTree) |
|
1564 |
dragSource.SetData(data) |
|
1565 |
dragSource.DoDragDrop() |
|
1566 |
self.ResetSelectedItem() |
|
1567 |
||
1568 |
def OnProjectTreeItemBeginEdit(self, event): |
|
1569 |
selected = event.GetItem() |
|
1570 |
if self.ProjectTree.GetPyData(selected)["type"] in ITEMS_UNEDITABLE: |
|
1571 |
event.Veto() |
|
1572 |
else: |
|
1573 |
event.Skip() |
|
1574 |
||
1575 |
def OnProjectTreeItemEndEdit(self, event): |
|
1576 |
message = None |
|
1577 |
abort = False |
|
1578 |
new_name = event.GetLabel() |
|
1579 |
if new_name != "": |
|
1580 |
if not TestIdentifier(new_name): |
|
1581 |
message = _("\"%s\" is not a valid identifier!")%new_name |
|
1582 |
elif new_name.upper() in IEC_KEYWORDS: |
|
1583 |
message = _("\"%s\" is a keyword. It can't be used!")%new_name |
|
1584 |
else: |
|
1585 |
item = event.GetItem() |
|
1586 |
old_name = self.ProjectTree.GetItemText(item) |
|
1587 |
item_infos = self.ProjectTree.GetPyData(item) |
|
1588 |
if item_infos["type"] == ITEM_PROJECT: |
|
1589 |
self.Controler.SetProjectProperties(name = new_name) |
|
1590 |
elif item_infos["type"] == ITEM_DATATYPE: |
|
1591 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectDataTypeNames() if name != old_name]: |
|
1592 |
message = _("\"%s\" data type already exists!")%new_name |
|
1593 |
abort = True |
|
1594 |
if not abort: |
|
1595 |
self.Controler.ChangeDataTypeName(old_name, new_name) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1596 |
self.RefreshEditorNames(self.Controler.ComputeDataTypeName(old_name), |
814 | 1597 |
self.Controler.ComputeDataTypeName(new_name)) |
1598 |
self.RefreshPageTitles() |
|
1599 |
elif item_infos["type"] == ITEM_POU: |
|
1600 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames() if name != old_name]: |
|
1601 |
message = _("\"%s\" pou already exists!")%new_name |
|
1602 |
abort = True |
|
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1167
diff
changeset
|
1603 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariableNames()]: |
814 | 1604 |
messageDialog = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION) |
1605 |
if messageDialog.ShowModal() == wx.ID_NO: |
|
1606 |
abort = True |
|
1607 |
messageDialog.Destroy() |
|
1608 |
if not abort: |
|
1609 |
self.Controler.ChangePouName(old_name, new_name) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1610 |
self.RefreshEditorNames(self.Controler.ComputePouName(old_name), |
814 | 1611 |
self.Controler.ComputePouName(new_name)) |
1612 |
self.RefreshLibraryPanel() |
|
1613 |
self.RefreshPageTitles() |
|
1614 |
elif item_infos["type"] == ITEM_TRANSITION: |
|
1615 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]: |
|
1616 |
message = _("A POU named \"%s\" already exists!")%new_name |
|
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1167
diff
changeset
|
1617 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariableNames(pou_name) if name != old_name]: |
814 | 1618 |
message = _("A variable with \"%s\" as name already exists in this pou!")%new_name |
1619 |
else: |
|
1620 |
words = item_infos["tagname"].split("::") |
|
1621 |
self.Controler.ChangePouTransitionName(words[1], old_name, new_name) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1622 |
self.RefreshEditorNames(self.Controler.ComputePouTransitionName(words[1], old_name), |
814 | 1623 |
self.Controler.ComputePouTransitionName(words[1], new_name)) |
1624 |
self.RefreshPageTitles() |
|
1625 |
elif item_infos["type"] == ITEM_ACTION: |
|
1626 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]: |
|
1627 |
message = _("A POU named \"%s\" already exists!")%new_name |
|
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1167
diff
changeset
|
1628 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariableNames(pou_name) if name != old_name]: |
814 | 1629 |
message = _("A variable with \"%s\" as name already exists in this pou!")%new_name |
1630 |
else: |
|
1631 |
words = item_infos["tagname"].split("::") |
|
1632 |
self.Controler.ChangePouActionName(words[1], old_name, new_name) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1633 |
self.RefreshEditorNames(self.Controler.ComputePouActionName(words[1], old_name), |
814 | 1634 |
self.Controler.ComputePouActionName(words[1], new_name)) |
1635 |
self.RefreshPageTitles() |
|
1636 |
elif item_infos["type"] == ITEM_CONFIGURATION: |
|
1637 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectConfigNames() if name != old_name]: |
|
1638 |
message = _("\"%s\" config already exists!")%new_name |
|
1639 |
abort = True |
|
1640 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]: |
|
1641 |
messageDialog = wx.MessageDialog(self, _("There is a POU named \"%s\". This could cause a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION) |
|
1642 |
if messageDialog.ShowModal() == wx.ID_NO: |
|
1643 |
abort = True |
|
1644 |
messageDialog.Destroy() |
|
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1167
diff
changeset
|
1645 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariableNames()]: |
814 | 1646 |
messageDialog = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION) |
1647 |
if messageDialog.ShowModal() == wx.ID_NO: |
|
1648 |
abort = True |
|
1649 |
messageDialog.Destroy() |
|
1650 |
if not abort: |
|
1651 |
self.Controler.ChangeConfigurationName(old_name, new_name) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1652 |
self.RefreshEditorNames(self.Controler.ComputeConfigurationName(old_name), |
814 | 1653 |
self.Controler.ComputeConfigurationName(new_name)) |
1654 |
self.RefreshPageTitles() |
|
1655 |
elif item_infos["type"] == ITEM_RESOURCE: |
|
1656 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectConfigNames()]: |
|
1657 |
message = _("\"%s\" config already exists!")%new_name |
|
1658 |
abort = True |
|
1659 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]: |
|
1660 |
messageDialog = wx.MessageDialog(self, _("There is a POU named \"%s\". This could cause a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION) |
|
1661 |
if messageDialog.ShowModal() == wx.ID_NO: |
|
1662 |
abort = True |
|
1663 |
messageDialog.Destroy() |
|
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1167
diff
changeset
|
1664 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariableNames()]: |
814 | 1665 |
messageDialog = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION) |
1666 |
if messageDialog.ShowModal() == wx.ID_NO: |
|
1667 |
abort = True |
|
1668 |
messageDialog.Destroy() |
|
1669 |
if not abort: |
|
1670 |
words = item_infos["tagname"].split("::") |
|
1671 |
self.Controler.ChangeConfigurationResourceName(words[1], old_name, new_name) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1672 |
self.RefreshEditorNames(self.Controler.ComputeConfigurationResourceName(words[1], old_name), |
814 | 1673 |
self.Controler.ComputeConfigurationResourceName(words[1], new_name)) |
1674 |
self.RefreshPageTitles() |
|
1675 |
if message or abort: |
|
1676 |
if message: |
|
1677 |
self.ShowErrorMessage(message) |
|
1678 |
event.Veto() |
|
1679 |
else: |
|
1680 |
wx.CallAfter(self.RefreshProjectTree) |
|
1681 |
self.RefreshEditor() |
|
1682 |
self._Refresh(TITLE, FILEMENU, EDITMENU) |
|
1683 |
event.Skip() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1684 |
|
814 | 1685 |
def OnProjectTreeItemActivated(self, event): |
1686 |
selected = event.GetItem() |
|
1687 |
name = self.ProjectTree.GetItemText(selected) |
|
1688 |
item_infos = self.ProjectTree.GetPyData(selected) |
|
1689 |
if item_infos["type"] == ITEM_PROJECT: |
|
1690 |
self.EditProjectSettings() |
|
1691 |
else: |
|
1692 |
if item_infos["type"] in [ITEM_DATATYPE, ITEM_POU, |
|
1693 |
ITEM_CONFIGURATION, ITEM_RESOURCE, |
|
1694 |
ITEM_TRANSITION, ITEM_ACTION]: |
|
1695 |
self.EditProjectElement(item_infos["type"], item_infos["tagname"]) |
|
1696 |
event.Skip() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1697 |
|
814 | 1698 |
def ProjectTreeItemSelect(self, select_item): |
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
1159
diff
changeset
|
1699 |
if select_item is not None and select_item.IsOk(): |
1112
ff3fcad17b47
Fixed bug when selecting item in ProjectTree on Linux
Laurent Bessard
parents:
1106
diff
changeset
|
1700 |
name = self.ProjectTree.GetItemText(select_item) |
ff3fcad17b47
Fixed bug when selecting item in ProjectTree on Linux
Laurent Bessard
parents:
1106
diff
changeset
|
1701 |
item_infos = self.ProjectTree.GetPyData(select_item) |
ff3fcad17b47
Fixed bug when selecting item in ProjectTree on Linux
Laurent Bessard
parents:
1106
diff
changeset
|
1702 |
if item_infos["type"] in [ITEM_DATATYPE, ITEM_POU, |
ff3fcad17b47
Fixed bug when selecting item in ProjectTree on Linux
Laurent Bessard
parents:
1106
diff
changeset
|
1703 |
ITEM_CONFIGURATION, ITEM_RESOURCE, |
ff3fcad17b47
Fixed bug when selecting item in ProjectTree on Linux
Laurent Bessard
parents:
1106
diff
changeset
|
1704 |
ITEM_TRANSITION, ITEM_ACTION]: |
ff3fcad17b47
Fixed bug when selecting item in ProjectTree on Linux
Laurent Bessard
parents:
1106
diff
changeset
|
1705 |
self.EditProjectElement(item_infos["type"], item_infos["tagname"], True) |
ff3fcad17b47
Fixed bug when selecting item in ProjectTree on Linux
Laurent Bessard
parents:
1106
diff
changeset
|
1706 |
self.PouInstanceVariablesPanel.SetPouType(item_infos["tagname"]) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1707 |
|
814 | 1708 |
def OnProjectTreeLeftUp(self, event): |
1709 |
if self.SelectedItem is not None: |
|
1710 |
self.ProjectTree.SelectItem(self.SelectedItem) |
|
1711 |
self.ProjectTreeItemSelect(self.SelectedItem) |
|
1240
ceaf9b4c0f86
Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents:
1233
diff
changeset
|
1712 |
self.ResetSelectedItem() |
814 | 1713 |
event.Skip() |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1714 |
|
1106
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1715 |
def OnProjectTreeMotion(self, event): |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1716 |
if not event.Dragging(): |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1717 |
pt = wx.Point(event.GetX(), event.GetY()) |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1718 |
item, flags = self.ProjectTree.HitTest(pt) |
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
1159
diff
changeset
|
1719 |
if item is not None and item.IsOk() and flags & wx.TREE_HITTEST_ONITEMLABEL: |
1106
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1720 |
item_infos = self.ProjectTree.GetPyData(item) |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1721 |
if item != self.LastToolTipItem and self.LastToolTipItem is not None: |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1722 |
self.ProjectTree.SetToolTip(None) |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1723 |
self.LastToolTipItem = None |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1724 |
if (self.LastToolTipItem != item and |
1106
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1725 |
item_infos["type"] in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]): |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1726 |
bodytype = self.Controler.GetEditedElementBodyType( |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1727 |
item_infos["tagname"]) |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1728 |
if item_infos["type"] == ITEM_POU: |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1729 |
block_type = { |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1730 |
"program": _("Program"), |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1731 |
"functionBlock": _("Function Block"), |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1732 |
"function": _("Function") |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1733 |
}[self.Controler.GetPouType(item_infos["name"])] |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1734 |
elif item_infos["type"] == ITEM_TRANSITION: |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1735 |
block_type = "Transition" |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1736 |
else: |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1737 |
block_type = "Action" |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1738 |
self.LastToolTipItem = item |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1739 |
wx.CallAfter(self.ProjectTree.SetToolTipString, |
1106
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1740 |
"%s : %s : %s" % ( |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1741 |
block_type, bodytype, item_infos["name"])) |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1742 |
elif self.LastToolTipItem is not None: |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1743 |
self.ProjectTree.SetToolTip(None) |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1744 |
self.LastToolTipItem = None |
843d181f73b4
Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents:
1105
diff
changeset
|
1745 |
event.Skip() |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1746 |
|
814 | 1747 |
def OnProjectTreeItemChanging(self, event): |
1748 |
if self.ProjectTree.GetPyData(event.GetItem())["type"] not in ITEMS_UNEDITABLE and self.SelectedItem is None: |
|
1749 |
self.SelectedItem = event.GetItem() |
|
1750 |
event.Veto() |
|
1751 |
else: |
|
1752 |
event.Skip() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1753 |
|
814 | 1754 |
def EditProjectElement(self, element, tagname, onlyopened = False): |
1755 |
openedidx = self.IsOpened(tagname) |
|
1756 |
if openedidx is not None: |
|
1757 |
old_selected = self.TabsOpened.GetSelection() |
|
1758 |
if old_selected != openedidx: |
|
1759 |
if old_selected >= 0: |
|
1760 |
self.TabsOpened.GetPage(old_selected).ResetBuffer() |
|
1761 |
self.TabsOpened.SetSelection(openedidx) |
|
1762 |
self._Refresh(FILEMENU, EDITMENU, EDITORTOOLBAR, PAGETITLES) |
|
1763 |
elif not onlyopened: |
|
870
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1764 |
if isinstance(element, EditorPanel): |
814 | 1765 |
new_window = element |
1766 |
self.AddPage(element, "") |
|
870
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1767 |
elif self.Controler.GetEditedElement(tagname) is not None: |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1768 |
new_window = None |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1769 |
if element == ITEM_CONFIGURATION: |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1770 |
new_window = ConfigurationEditor(self.TabsOpened, tagname, self, self.Controler) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1771 |
new_window.SetIcon(GetBitmap("CONFIGURATION")) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1772 |
self.AddPage(new_window, "") |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1773 |
elif element == ITEM_RESOURCE: |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1774 |
new_window = ResourceEditor(self.TabsOpened, tagname, self, self.Controler) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1775 |
new_window.SetIcon(GetBitmap("RESOURCE")) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1776 |
self.AddPage(new_window, "") |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1777 |
elif element in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]: |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1778 |
bodytype = self.Controler.GetEditedElementBodyType(tagname) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1779 |
if bodytype == "FBD": |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1780 |
new_window = Viewer(self.TabsOpened, tagname, self, self.Controler) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1781 |
new_window.RefreshScaling(False) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1782 |
elif bodytype == "LD": |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1783 |
new_window = LD_Viewer(self.TabsOpened, tagname, self, self.Controler) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1784 |
new_window.RefreshScaling(False) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1785 |
elif bodytype == "SFC": |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1786 |
new_window = SFC_Viewer(self.TabsOpened, tagname, self, self.Controler) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1787 |
new_window.RefreshScaling(False) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1788 |
else: |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1789 |
new_window = TextViewer(self.TabsOpened, tagname, self, self.Controler) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1790 |
new_window.SetTextSyntax(bodytype) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1791 |
if bodytype == "IL": |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1792 |
new_window.SetKeywords(IL_KEYWORDS) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1793 |
else: |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1794 |
new_window.SetKeywords(ST_KEYWORDS) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1795 |
if element == ITEM_POU: |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1796 |
pou_type = self.Controler.GetEditedElementType(tagname)[1].upper() |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1797 |
icon = GetBitmap(pou_type, bodytype) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1798 |
elif element == ITEM_TRANSITION: |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1799 |
icon = GetBitmap("TRANSITION", bodytype) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1800 |
elif element == ITEM_ACTION: |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1801 |
icon = GetBitmap("ACTION", bodytype) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1802 |
new_window.SetIcon(icon) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1803 |
self.AddPage(new_window, "") |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1804 |
elif element == ITEM_DATATYPE: |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1805 |
new_window = DataTypeEditor(self.TabsOpened, tagname, self, self.Controler) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1806 |
new_window.SetIcon(GetBitmap("DATATYPE")) |
61b32521442e
Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents:
849
diff
changeset
|
1807 |
self.AddPage(new_window, "") |
814 | 1808 |
if new_window is not None: |
1809 |
openedidx = self.IsOpened(tagname) |
|
1810 |
old_selected = self.TabsOpened.GetSelection() |
|
1811 |
if old_selected != openedidx: |
|
1812 |
if old_selected >= 0: |
|
1813 |
self.TabsOpened.GetPage(old_selected).ResetBuffer() |
|
1814 |
for i in xrange(self.TabsOpened.GetPageCount()): |
|
1815 |
window = self.TabsOpened.GetPage(i) |
|
1816 |
if window == new_window: |
|
1817 |
self.TabsOpened.SetSelection(i) |
|
1818 |
window.SetFocus() |
|
1819 |
self.RefreshPageTitles() |
|
1820 |
return new_window |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1821 |
|
814 | 1822 |
def OnProjectTreeRightUp(self, event): |
1240
ceaf9b4c0f86
Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents:
1233
diff
changeset
|
1823 |
item = event.GetItem() |
814 | 1824 |
self.ProjectTree.SelectItem(item) |
1825 |
self.ProjectTreeItemSelect(item) |
|
1826 |
name = self.ProjectTree.GetItemText(item) |
|
1827 |
item_infos = self.ProjectTree.GetPyData(item) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1828 |
|
814 | 1829 |
menu = None |
1830 |
if item_infos["type"] in ITEMS_UNEDITABLE + [ITEM_PROJECT]: |
|
1831 |
if item_infos["type"] == ITEM_PROJECT: |
|
1832 |
name = "Project" |
|
1833 |
else: |
|
1834 |
name = UNEDITABLE_NAMES_DICT[name] |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1835 |
|
814 | 1836 |
if name == "Data Types": |
1837 |
menu = wx.Menu(title='') |
|
1838 |
new_id = wx.NewId() |
|
1839 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add DataType")) |
|
1840 |
self.Bind(wx.EVT_MENU, self.OnAddDataTypeMenu, id=new_id) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1841 |
|
814 | 1842 |
elif name in ["Functions", "Function Blocks", "Programs", "Project"]: |
1843 |
menu = wx.Menu(title='') |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1844 |
|
814 | 1845 |
if name != "Project": |
1846 |
new_id = wx.NewId() |
|
1847 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add POU")) |
|
1848 |
self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction({"Functions" : "function", "Function Blocks" : "functionBlock", "Programs" : "program"}[name]), id=new_id) |
|
1849 |
||
1850 |
new_id = wx.NewId() |
|
1851 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Paste POU")) |
|
1852 |
self.Bind(wx.EVT_MENU, self.OnPastePou, id=new_id) |
|
1853 |
if self.GetCopyBuffer() is None: |
|
1854 |
menu.Enable(new_id, False) |
|
1855 |
||
1856 |
elif name == "Configurations": |
|
1857 |
menu = wx.Menu(title='') |
|
1858 |
new_id = wx.NewId() |
|
1859 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Configuration")) |
|
1860 |
self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu, id=new_id) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1861 |
|
814 | 1862 |
elif name == "Transitions": |
1863 |
menu = wx.Menu(title='') |
|
1864 |
new_id = wx.NewId() |
|
1865 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Transition")) |
|
1010
44c3cafef436
Fixed typo in IDEFrame OnProjectTreeRightUp method
Laurent Bessard
parents:
999
diff
changeset
|
1866 |
parent = self.ProjectTree.GetItemParent(item) |
44c3cafef436
Fixed typo in IDEFrame OnProjectTreeRightUp method
Laurent Bessard
parents:
999
diff
changeset
|
1867 |
parent_type = self.ProjectTree.GetPyData(parent)["type"] |
814 | 1868 |
while parent_type != ITEM_POU: |
1869 |
parent = self.ProjectTree.GetItemParent(parent) |
|
1870 |
parent_type = self.ProjectTree.GetPyData(parent)["type"] |
|
1871 |
self.Bind(wx.EVT_MENU, self.GenerateAddTransitionFunction(self.ProjectTree.GetItemText(parent)), id=new_id) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1872 |
|
814 | 1873 |
elif name == "Actions": |
1874 |
menu = wx.Menu(title='') |
|
1875 |
new_id = wx.NewId() |
|
1876 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Action")) |
|
1877 |
parent = self.ProjectTree.GetItemParent(item) |
|
1878 |
parent_type = self.ProjectTree.GetPyData(parent)["type"] |
|
1879 |
while parent_type != ITEM_POU: |
|
1880 |
parent = self.ProjectTree.GetItemParent(parent) |
|
1881 |
parent_type = self.ProjectTree.GetPyData(parent)["type"] |
|
1882 |
self.Bind(wx.EVT_MENU, self.GenerateAddActionFunction(self.ProjectTree.GetItemText(parent)), id=new_id) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1883 |
|
814 | 1884 |
elif name == "Resources": |
1885 |
menu = wx.Menu(title='') |
|
1886 |
new_id = wx.NewId() |
|
1887 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Resource")) |
|
1888 |
parent = self.ProjectTree.GetItemParent(item) |
|
1889 |
parent_type = self.ProjectTree.GetPyData(parent)["type"] |
|
1890 |
while parent_type not in [ITEM_CONFIGURATION, ITEM_PROJECT]: |
|
1891 |
parent = self.ProjectTree.GetItemParent(parent) |
|
1892 |
parent_type = self.ProjectTree.GetPyData(parent)["type"] |
|
1024
626de4ff4bdc
Fixed resource editing, removing definition of more than one resource and deletion of last resource defined
Laurent Bessard
parents:
1019
diff
changeset
|
1893 |
parent_name = None |
814 | 1894 |
if parent_type == ITEM_PROJECT: |
1024
626de4ff4bdc
Fixed resource editing, removing definition of more than one resource and deletion of last resource defined
Laurent Bessard
parents:
1019
diff
changeset
|
1895 |
config_names = self.Controler.GetProjectConfigNames() |
626de4ff4bdc
Fixed resource editing, removing definition of more than one resource and deletion of last resource defined
Laurent Bessard
parents:
1019
diff
changeset
|
1896 |
if len(config_names) > 0: |
626de4ff4bdc
Fixed resource editing, removing definition of more than one resource and deletion of last resource defined
Laurent Bessard
parents:
1019
diff
changeset
|
1897 |
parent_name = config_names[0] |
814 | 1898 |
else: |
1899 |
parent_name = self.ProjectTree.GetItemText(parent) |
|
1024
626de4ff4bdc
Fixed resource editing, removing definition of more than one resource and deletion of last resource defined
Laurent Bessard
parents:
1019
diff
changeset
|
1900 |
if parent_name is not None: |
626de4ff4bdc
Fixed resource editing, removing definition of more than one resource and deletion of last resource defined
Laurent Bessard
parents:
1019
diff
changeset
|
1901 |
self.Bind(wx.EVT_MENU, self.GenerateAddResourceFunction(parent_name), id=new_id) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1902 |
|
814 | 1903 |
else: |
1904 |
if item_infos["type"] == ITEM_POU: |
|
1905 |
menu = wx.Menu(title='') |
|
1906 |
if self.Controler.GetPouBodyType(name) == "SFC": |
|
1907 |
new_id = wx.NewId() |
|
1908 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Transition")) |
|
1909 |
self.Bind(wx.EVT_MENU, self.GenerateAddTransitionFunction(name), id=new_id) |
|
1910 |
new_id = wx.NewId() |
|
1911 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Action")) |
|
1912 |
self.Bind(wx.EVT_MENU, self.GenerateAddActionFunction(name), id=new_id) |
|
1913 |
menu.AppendSeparator() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1914 |
|
814 | 1915 |
new_id = wx.NewId() |
1916 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Copy POU")) |
|
1917 |
self.Bind(wx.EVT_MENU, self.OnCopyPou, id=new_id) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1918 |
|
814 | 1919 |
pou_type = self.Controler.GetPouType(name) |
1920 |
if pou_type in ["function", "functionBlock"]: |
|
1921 |
change_menu = wx.Menu(title='') |
|
1922 |
if pou_type == "function": |
|
1923 |
new_id = wx.NewId() |
|
1924 |
AppendMenu(change_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Function Block")) |
|
1925 |
self.Bind(wx.EVT_MENU, self.GenerateChangePouTypeFunction(name, "functionBlock"), id=new_id) |
|
1926 |
new_id = wx.NewId() |
|
1927 |
AppendMenu(change_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Program")) |
|
1928 |
self.Bind(wx.EVT_MENU, self.GenerateChangePouTypeFunction(name, "program"), id=new_id) |
|
1929 |
menu.AppendMenu(wx.NewId(), _("Change POU Type To"), change_menu) |
|
1930 |
new_id = wx.NewId() |
|
1931 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Rename")) |
|
1932 |
self.Bind(wx.EVT_MENU, self.OnRenamePouMenu, id=new_id) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1933 |
|
814 | 1934 |
elif item_infos["type"] == ITEM_CONFIGURATION: |
1935 |
menu = wx.Menu(title='') |
|
1936 |
new_id = wx.NewId() |
|
1937 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Resource")) |
|
1938 |
self.Bind(wx.EVT_MENU, self.GenerateAddResourceFunction(name), id=new_id) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1939 |
|
814 | 1940 |
elif item_infos["type"] in [ITEM_DATATYPE, ITEM_TRANSITION, ITEM_ACTION, ITEM_RESOURCE]: |
1941 |
menu = wx.Menu(title='') |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1942 |
|
814 | 1943 |
if menu is not None: |
1944 |
new_id = wx.NewId() |
|
1945 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Delete")) |
|
1946 |
self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=new_id) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1947 |
|
814 | 1948 |
if menu is not None: |
1480
79e54c5dead5
fix issue, then it wasn't possible to remove functional blocks from
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1408
diff
changeset
|
1949 |
self.FindFocus().PopupMenu(menu) |
814 | 1950 |
menu.Destroy() |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1951 |
|
1240
ceaf9b4c0f86
Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents:
1233
diff
changeset
|
1952 |
self.ResetSelectedItem() |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1953 |
|
814 | 1954 |
event.Skip() |
1955 |
||
1956 |
||
1957 |
#------------------------------------------------------------------------------- |
|
1958 |
# Instances Tree Management Functions |
|
1959 |
#------------------------------------------------------------------------------- |
|
1960 |
||
1961 |
def GetTreeImage(self, var_class): |
|
1962 |
return self.TreeImageDict[var_class] |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1963 |
|
814 | 1964 |
def RefreshPouInstanceVariablesPanel(self): |
1965 |
self.PouInstanceVariablesPanel.RefreshView() |
|
1966 |
||
1967 |
def OpenDebugViewer(self, instance_category, instance_path, instance_type): |
|
1968 |
openedidx = self.IsOpened(instance_path) |
|
930
4be515ac635e
Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents:
916
diff
changeset
|
1969 |
new_window = None |
814 | 1970 |
if openedidx is not None: |
1971 |
old_selected = self.TabsOpened.GetSelection() |
|
1972 |
if old_selected != openedidx: |
|
1973 |
if old_selected >= 0: |
|
1974 |
self.TabsOpened.GetPage(old_selected).ResetBuffer() |
|
1975 |
self.TabsOpened.SetSelection(openedidx) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1976 |
|
814 | 1977 |
elif instance_category in ITEMS_VARIABLE: |
887
d3c6c4ab8b28
Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents:
885
diff
changeset
|
1978 |
if self.Controler.IsNumType(instance_type, True): |
1364
e9e17d3b2849
Remove old debug panels and viewers not using matplotlib
Laurent Bessard
parents:
1362
diff
changeset
|
1979 |
self.AddDebugVariable(instance_path, True) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1980 |
|
814 | 1981 |
else: |
1982 |
bodytype = self.Controler.GetEditedElementBodyType(instance_type, True) |
|
1983 |
if bodytype == "FBD": |
|
1984 |
new_window = Viewer(self.TabsOpened, instance_type, self, self.Controler, True, instance_path) |
|
1985 |
new_window.RefreshScaling(False) |
|
1986 |
elif bodytype == "LD": |
|
1987 |
new_window = LD_Viewer(self.TabsOpened, instance_type, self, self.Controler, True, instance_path) |
|
1988 |
new_window.RefreshScaling(False) |
|
1989 |
elif bodytype == "SFC": |
|
1990 |
new_window = SFC_Viewer(self.TabsOpened, instance_type, self, self.Controler, True, instance_path) |
|
1991 |
new_window.RefreshScaling(False) |
|
1992 |
else: |
|
1993 |
new_window = TextViewer(self.TabsOpened, instance_type, self, self.Controler, True, instance_path) |
|
1994 |
new_window.SetTextSyntax(bodytype) |
|
1995 |
if bodytype == "IL": |
|
1996 |
new_window.SetKeywords(IL_KEYWORDS) |
|
1997 |
else: |
|
1998 |
new_window.SetKeywords(ST_KEYWORDS) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
1999 |
|
814 | 2000 |
if new_window is not None: |
2001 |
if instance_category in [ITEM_FUNCTIONBLOCK, ITEM_PROGRAM]: |
|
2002 |
pou_type = self.Controler.GetEditedElementType(instance_type, True)[1].upper() |
|
2003 |
icon = GetBitmap(pou_type, bodytype) |
|
2004 |
elif instance_category == ITEM_TRANSITION: |
|
2005 |
icon = GetBitmap("TRANSITION", bodytype) |
|
2006 |
elif instance_category == ITEM_ACTION: |
|
2007 |
icon = GetBitmap("ACTION", bodytype) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2008 |
|
885
fc91d3718b74
Fix bug multiple graph viewer tab displaying values of the same variable can be opened
Laurent Bessard
parents:
870
diff
changeset
|
2009 |
if new_window is not None: |
fc91d3718b74
Fix bug multiple graph viewer tab displaying values of the same variable can be opened
Laurent Bessard
parents:
870
diff
changeset
|
2010 |
new_window.SetIcon(icon) |
fc91d3718b74
Fix bug multiple graph viewer tab displaying values of the same variable can be opened
Laurent Bessard
parents:
870
diff
changeset
|
2011 |
self.AddPage(new_window, "") |
fc91d3718b74
Fix bug multiple graph viewer tab displaying values of the same variable can be opened
Laurent Bessard
parents:
870
diff
changeset
|
2012 |
new_window.RefreshView() |
fc91d3718b74
Fix bug multiple graph viewer tab displaying values of the same variable can be opened
Laurent Bessard
parents:
870
diff
changeset
|
2013 |
new_window.SetFocus() |
fc91d3718b74
Fix bug multiple graph viewer tab displaying values of the same variable can be opened
Laurent Bessard
parents:
870
diff
changeset
|
2014 |
self.RefreshPageTitles() |
814 | 2015 |
return new_window |
2016 |
||
2017 |
def ResetGraphicViewers(self): |
|
887
d3c6c4ab8b28
Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents:
885
diff
changeset
|
2018 |
if self.EnableDebug: |
d3c6c4ab8b28
Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents:
885
diff
changeset
|
2019 |
self.DebugVariablePanel.ResetGraphicsValues() |
814 | 2020 |
|
2021 |
def CloseObsoleteDebugTabs(self): |
|
2022 |
if self.EnableDebug: |
|
2023 |
idxs = range(self.TabsOpened.GetPageCount()) |
|
2024 |
idxs.reverse() |
|
2025 |
for idx in idxs: |
|
2026 |
editor = self.TabsOpened.GetPage(idx) |
|
1364
e9e17d3b2849
Remove old debug panels and viewers not using matplotlib
Laurent Bessard
parents:
1362
diff
changeset
|
2027 |
if isinstance(editor, Viewer) and editor.IsDebugging(): |
814 | 2028 |
instance_infos = self.Controler.GetInstanceInfos(editor.GetInstancePath(), self.EnableDebug) |
2029 |
if instance_infos is None: |
|
2030 |
self.TabsOpened.DeletePage(idx) |
|
2031 |
else: |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1171
diff
changeset
|
2032 |
editor.SubscribeAllDataConsumers() |
897
3cd39bc7dbad
Added support for defining extension file editor as DebugViewer
Laurent Bessard
parents:
887
diff
changeset
|
2033 |
elif editor.IsDebugging(): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1171
diff
changeset
|
2034 |
editor.SubscribeAllDataConsumers() |
1207 | 2035 |
self.DebugVariablePanel.SubscribeAllDataConsumers() |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2036 |
|
1214
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1207
diff
changeset
|
2037 |
def AddDebugVariable(self, iec_path, force=False, graph=False): |
814 | 2038 |
if self.EnableDebug: |
1214
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1207
diff
changeset
|
2039 |
self.DebugVariablePanel.InsertValue(iec_path, force=force, graph=graph) |
814 | 2040 |
self.EnsureTabVisible(self.DebugVariablePanel) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2041 |
|
814 | 2042 |
#------------------------------------------------------------------------------- |
2043 |
# Library Panel Management Function |
|
2044 |
#------------------------------------------------------------------------------- |
|
2045 |
||
2046 |
def RefreshLibraryPanel(self): |
|
2047 |
self.LibraryPanel.RefreshTree() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2048 |
|
814 | 2049 |
#------------------------------------------------------------------------------- |
2050 |
# ToolBars Management Functions |
|
2051 |
#------------------------------------------------------------------------------- |
|
2052 |
||
2053 |
def AddToMenuToolBar(self, items): |
|
2054 |
MenuToolBar = self.Panes["MenuToolBar"] |
|
2055 |
if MenuToolBar.GetToolsCount() > 0: |
|
2056 |
MenuToolBar.AddSeparator() |
|
2057 |
for toolbar_item in items: |
|
2058 |
if toolbar_item is None: |
|
2059 |
MenuToolBar.AddSeparator() |
|
2060 |
else: |
|
2061 |
id, bitmap, help, callback = toolbar_item |
|
2062 |
MenuToolBar.AddSimpleTool(id=id, shortHelpString=help, bitmap=GetBitmap(bitmap)) |
|
2063 |
if callback is not None: |
|
2064 |
self.Bind(wx.EVT_TOOL, callback, id=id) |
|
2065 |
MenuToolBar.Realize() |
|
2066 |
self.AUIManager.GetPane("MenuToolBar").BestSize(MenuToolBar.GetBestSize()) |
|
2067 |
||
2068 |
def ResetEditorToolBar(self): |
|
2069 |
EditorToolBar = self.Panes["EditorToolBar"] |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2070 |
|
814 | 2071 |
for item in self.CurrentEditorToolBar: |
2072 |
if wx.VERSION >= (2, 6, 0): |
|
2073 |
self.Unbind(wx.EVT_MENU, id=item) |
|
2074 |
else: |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2075 |
self.Disconnect(id=item, eventType=wx.wxEVT_COMMAND_MENU_SELECTED) |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2076 |
|
814 | 2077 |
if EditorToolBar: |
2078 |
EditorToolBar.DeleteTool(item) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2079 |
|
814 | 2080 |
if EditorToolBar: |
2081 |
EditorToolBar.Realize() |
|
2082 |
self.AUIManager.GetPane("EditorToolBar").BestSize(EditorToolBar.GetBestSize()) |
|
2083 |
self.AUIManager.GetPane("EditorToolBar").Hide() |
|
2084 |
self.AUIManager.Update() |
|
2085 |
||
2086 |
def RefreshEditorToolBar(self): |
|
2087 |
selected = self.TabsOpened.GetSelection() |
|
2088 |
menu = None |
|
2089 |
if selected != -1: |
|
2090 |
window = self.TabsOpened.GetPage(selected) |
|
1364
e9e17d3b2849
Remove old debug panels and viewers not using matplotlib
Laurent Bessard
parents:
1362
diff
changeset
|
2091 |
if isinstance(window, (Viewer, TextViewer)): |
814 | 2092 |
if not window.IsDebugging(): |
2093 |
menu = self.Controler.GetEditedElementBodyType(window.GetTagName()) |
|
2094 |
else: |
|
2095 |
menu = "debug" |
|
2096 |
if menu is not None and menu != self.CurrentMenu: |
|
2097 |
self.ResetEditorToolBar() |
|
2098 |
self.CurrentMenu = menu |
|
2099 |
self.CurrentEditorToolBar = [] |
|
2100 |
EditorToolBar = self.Panes["EditorToolBar"] |
|
2101 |
if EditorToolBar: |
|
2102 |
for radio, modes, id, method, picture, help in EditorToolBarItems[menu]: |
|
2103 |
if modes & self.DrawingMode: |
|
2104 |
if radio or self.DrawingMode == FREEDRAWING_MODE: |
|
2105 |
EditorToolBar.AddRadioTool(id, GetBitmap(picture), wx.NullBitmap, help) |
|
2106 |
else: |
|
2107 |
EditorToolBar.AddSimpleTool(id, GetBitmap(picture), help) |
|
2108 |
self.Bind(wx.EVT_MENU, getattr(self, method), id=id) |
|
2109 |
self.CurrentEditorToolBar.append(id) |
|
2110 |
EditorToolBar.Realize() |
|
2111 |
self.AUIManager.GetPane("EditorToolBar").BestSize(EditorToolBar.GetBestSize()) |
|
2112 |
self.AUIManager.GetPane("EditorToolBar").Show() |
|
2113 |
self.AUIManager.Update() |
|
2114 |
elif menu is None: |
|
2115 |
self.ResetEditorToolBar() |
|
2116 |
self.CurrentMenu = menu |
|
2117 |
self.ResetCurrentMode() |
|
2118 |
||
2119 |
||
2120 |
#------------------------------------------------------------------------------- |
|
2121 |
# EditorToolBar Items Functions |
|
2122 |
#------------------------------------------------------------------------------- |
|
2123 |
||
2124 |
def ResetCurrentMode(self): |
|
2125 |
selected = self.TabsOpened.GetSelection() |
|
2126 |
if selected != -1: |
|
2127 |
window = self.TabsOpened.GetPage(selected) |
|
2128 |
window.SetMode(MODE_SELECTION) |
|
2129 |
EditorToolBar = self.Panes["EditorToolBar"] |
|
2130 |
if EditorToolBar: |
|
2131 |
EditorToolBar.ToggleTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION, False) |
|
2132 |
EditorToolBar.ToggleTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION, True) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2133 |
|
814 | 2134 |
def ResetToolToggle(self, id): |
2135 |
tool = self.Panes["EditorToolBar"].FindById(id) |
|
2136 |
tool.SetToggle(False) |
|
2137 |
||
2138 |
def OnSelectionTool(self, event): |
|
2139 |
selected = self.TabsOpened.GetSelection() |
|
2140 |
if selected != -1: |
|
2141 |
self.TabsOpened.GetPage(selected).SetMode(MODE_SELECTION) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2142 |
|
814 | 2143 |
def OnMotionTool(self, event): |
2144 |
selected = self.TabsOpened.GetSelection() |
|
2145 |
if selected != -1: |
|
2146 |
self.TabsOpened.GetPage(selected).SetMode(MODE_MOTION) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2147 |
|
814 | 2148 |
def OnCommentTool(self, event): |
2149 |
self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCOMMENT) |
|
2150 |
selected = self.TabsOpened.GetSelection() |
|
2151 |
if selected != -1: |
|
2152 |
self.TabsOpened.GetPage(selected).SetMode(MODE_COMMENT) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2153 |
|
814 | 2154 |
def OnVariableTool(self, event): |
2155 |
self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARVARIABLE) |
|
2156 |
selected = self.TabsOpened.GetSelection() |
|
2157 |
if selected != -1: |
|
2158 |
self.TabsOpened.GetPage(selected).SetMode(MODE_VARIABLE) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2159 |
|
814 | 2160 |
def OnBlockTool(self, event): |
2161 |
self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARBLOCK) |
|
2162 |
selected = self.TabsOpened.GetSelection() |
|
2163 |
if selected != -1: |
|
2164 |
self.TabsOpened.GetPage(selected).SetMode(MODE_BLOCK) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2165 |
|
814 | 2166 |
def OnConnectionTool(self, event): |
2167 |
self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCONNECTION) |
|
2168 |
selected = self.TabsOpened.GetSelection() |
|
2169 |
if selected != -1: |
|
2170 |
self.TabsOpened.GetPage(selected).SetMode(MODE_CONNECTION) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2171 |
|
814 | 2172 |
def OnPowerRailTool(self, event): |
2173 |
self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL) |
|
2174 |
selected = self.TabsOpened.GetSelection() |
|
2175 |
if selected != -1: |
|
2176 |
self.TabsOpened.GetPage(selected).SetMode(MODE_POWERRAIL) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2177 |
|
814 | 2178 |
def OnRungTool(self, event): |
2179 |
selected = self.TabsOpened.GetSelection() |
|
2180 |
if selected != -1: |
|
2181 |
self.TabsOpened.GetPage(selected).AddLadderRung() |
|
2182 |
event.Skip() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2183 |
|
814 | 2184 |
def OnCoilTool(self, event): |
2185 |
self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCOIL) |
|
2186 |
selected = self.TabsOpened.GetSelection() |
|
2187 |
if selected != -1: |
|
2188 |
self.TabsOpened.GetPage(selected).SetMode(MODE_COIL) |
|
2189 |
event.Skip() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2190 |
|
814 | 2191 |
def OnContactTool(self, event): |
2192 |
if self.DrawingMode == FREEDRAWING_MODE: |
|
2193 |
self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCONTACT) |
|
2194 |
selected = self.TabsOpened.GetSelection() |
|
2195 |
if selected != -1: |
|
2196 |
if self.DrawingMode == FREEDRAWING_MODE: |
|
2197 |
self.TabsOpened.GetPage(selected).SetMode(MODE_CONTACT) |
|
2198 |
else: |
|
2199 |
self.TabsOpened.GetPage(selected).AddLadderContact() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2200 |
|
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2201 |
def OnBranchTool(self, event): |
814 | 2202 |
selected = self.TabsOpened.GetSelection() |
2203 |
if selected != -1: |
|
2204 |
self.TabsOpened.GetPage(selected).AddLadderBranch() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2205 |
|
814 | 2206 |
def OnInitialStepTool(self, event): |
2207 |
self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP) |
|
2208 |
selected = self.TabsOpened.GetSelection() |
|
2209 |
if selected != -1: |
|
2210 |
self.TabsOpened.GetPage(selected).SetMode(MODE_INITIALSTEP) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2211 |
|
814 | 2212 |
def OnStepTool(self, event): |
2213 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
2214 |
self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARSTEP) |
|
2215 |
selected = self.TabsOpened.GetSelection() |
|
2216 |
if selected != -1: |
|
2217 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
2218 |
self.TabsOpened.GetPage(selected).SetMode(MODE_STEP) |
|
2219 |
else: |
|
2220 |
self.TabsOpened.GetPage(selected).AddStep() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2221 |
|
814 | 2222 |
def OnActionBlockTool(self, event): |
2223 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
2224 |
self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK) |
|
2225 |
selected = self.TabsOpened.GetSelection() |
|
2226 |
if selected != -1: |
|
2227 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
2228 |
self.TabsOpened.GetPage(selected).SetMode(MODE_ACTION) |
|
2229 |
else: |
|
2230 |
self.TabsOpened.GetPage(selected).AddStepAction() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2231 |
|
814 | 2232 |
def OnTransitionTool(self, event): |
2233 |
self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARTRANSITION) |
|
2234 |
selected = self.TabsOpened.GetSelection() |
|
2235 |
if selected != -1: |
|
2236 |
self.TabsOpened.GetPage(selected).SetMode(MODE_TRANSITION) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2237 |
|
814 | 2238 |
def OnDivergenceTool(self, event): |
2239 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
2240 |
self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE) |
|
2241 |
selected = self.TabsOpened.GetSelection() |
|
2242 |
if selected != -1: |
|
2243 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
2244 |
self.TabsOpened.GetPage(selected).SetMode(MODE_DIVERGENCE) |
|
2245 |
else: |
|
2246 |
self.TabsOpened.GetPage(selected).AddDivergence() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2247 |
|
814 | 2248 |
def OnJumpTool(self, event): |
2249 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
2250 |
self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARJUMP) |
|
2251 |
selected = self.TabsOpened.GetSelection() |
|
2252 |
if selected != -1: |
|
2253 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
2254 |
self.TabsOpened.GetPage(selected).SetMode(MODE_JUMP) |
|
2255 |
else: |
|
2256 |
self.TabsOpened.GetPage(selected).AddJump() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2257 |
|
814 | 2258 |
|
2259 |
#------------------------------------------------------------------------------- |
|
2260 |
# Add Project Elements Functions |
|
2261 |
#------------------------------------------------------------------------------- |
|
2262 |
||
2263 |
def OnAddDataTypeMenu(self, event): |
|
2264 |
tagname = self.Controler.ProjectAddDataType() |
|
2265 |
if tagname is not None: |
|
2266 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE) |
|
2267 |
self.EditProjectElement(ITEM_DATATYPE, tagname) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2268 |
|
814 | 2269 |
def GenerateAddPouFunction(self, pou_type): |
2270 |
def OnAddPouMenu(event): |
|
2271 |
dialog = PouDialog(self, pou_type) |
|
2272 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
|
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1167
diff
changeset
|
2273 |
dialog.SetPouElementNames(self.Controler.GetProjectPouVariableNames()) |
814 | 2274 |
dialog.SetValues({"pouName": self.Controler.GenerateNewName(None, None, "%s%%d" % pou_type)}) |
2275 |
if dialog.ShowModal() == wx.ID_OK: |
|
2276 |
values = dialog.GetValues() |
|
2277 |
tagname = self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"]) |
|
2278 |
if tagname is not None: |
|
2279 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, LIBRARYTREE) |
|
2280 |
self.EditProjectElement(ITEM_POU, tagname) |
|
2281 |
dialog.Destroy() |
|
2282 |
return OnAddPouMenu |
|
2283 |
||
2284 |
def GenerateAddTransitionFunction(self, pou_name): |
|
2285 |
def OnAddTransitionMenu(event): |
|
2286 |
dialog = PouTransitionDialog(self) |
|
2287 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
|
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1167
diff
changeset
|
2288 |
dialog.SetPouElementNames(self.Controler.GetProjectPouVariableNames(pou_name)) |
814 | 2289 |
dialog.SetValues({"transitionName": self.Controler.GenerateNewName(None, None, "transition%d")}) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2290 |
if dialog.ShowModal() == wx.ID_OK: |
814 | 2291 |
values = dialog.GetValues() |
2292 |
tagname = self.Controler.ProjectAddPouTransition(pou_name, values["transitionName"], values["language"]) |
|
2293 |
if tagname is not None: |
|
2294 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE) |
|
2295 |
self.EditProjectElement(ITEM_TRANSITION, tagname) |
|
2296 |
dialog.Destroy() |
|
2297 |
return OnAddTransitionMenu |
|
2298 |
||
2299 |
def GenerateAddActionFunction(self, pou_name): |
|
2300 |
def OnAddActionMenu(event): |
|
2301 |
dialog = PouActionDialog(self) |
|
2302 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
|
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1167
diff
changeset
|
2303 |
dialog.SetPouElementNames(self.Controler.GetProjectPouVariableNames(pou_name)) |
814 | 2304 |
dialog.SetValues({"actionName": self.Controler.GenerateNewName(None, None, "action%d")}) |
2305 |
if dialog.ShowModal() == wx.ID_OK: |
|
2306 |
values = dialog.GetValues() |
|
2307 |
tagname = self.Controler.ProjectAddPouAction(pou_name, values["actionName"], values["language"]) |
|
2308 |
if tagname is not None: |
|
2309 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE) |
|
2310 |
self.EditProjectElement(ITEM_ACTION, tagname) |
|
2311 |
dialog.Destroy() |
|
2312 |
return OnAddActionMenu |
|
2313 |
||
2314 |
def OnAddConfigurationMenu(self, event): |
|
2315 |
tagname = self.Controler.ProjectAddConfiguration() |
|
2316 |
if tagname is not None: |
|
2317 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL) |
|
2318 |
self.EditProjectElement(ITEM_CONFIGURATION, tagname) |
|
2319 |
||
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2320 |
def AddResourceMenu(self, event): |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2321 |
config_names = self.Controler.GetProjectConfigNames() |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2322 |
if len(config_names) > 0: |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2323 |
tagname = self.Controler.ProjectAddConfigurationResource(config_names[0]) |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2324 |
if tagname is not None: |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2325 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL) |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2326 |
self.EditProjectElement(ITEM_RESOURCE, tagname) |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2327 |
|
814 | 2328 |
def GenerateAddResourceFunction(self, config_name): |
2329 |
def OnAddResourceMenu(event): |
|
2330 |
tagname = self.Controler.ProjectAddConfigurationResource(config_name) |
|
2331 |
if tagname is not None: |
|
2332 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL) |
|
2333 |
self.EditProjectElement(ITEM_RESOURCE, tagname) |
|
2334 |
return OnAddResourceMenu |
|
2335 |
||
2336 |
def GenerateChangePouTypeFunction(self, name, new_type): |
|
2337 |
def OnChangePouTypeMenu(event): |
|
2338 |
selected = self.ProjectTree.GetSelection() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2339 |
if self.ProjectTree.GetPyData(selected)["type"] == ITEM_POU: |
814 | 2340 |
self.Controler.ProjectChangePouType(name, new_type) |
2341 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, LIBRARYTREE) |
|
2342 |
return OnChangePouTypeMenu |
|
2343 |
||
2344 |
def OnCopyPou(self, event): |
|
2345 |
selected = self.ProjectTree.GetSelection() |
|
2346 |
pou_name = self.ProjectTree.GetItemText(selected) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2347 |
|
814 | 2348 |
pou_xml = self.Controler.GetPouXml(pou_name) |
2349 |
if pou_xml is not None: |
|
2350 |
self.SetCopyBuffer(pou_xml) |
|
2351 |
self._Refresh(EDITMENU) |
|
2352 |
||
2353 |
def OnPastePou(self, event): |
|
2354 |
selected = self.ProjectTree.GetSelection() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2355 |
|
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2356 |
if self.ProjectTree.GetPyData(selected)["type"] != ITEM_PROJECT: |
814 | 2357 |
pou_type = self.ProjectTree.GetItemText(selected) |
2358 |
pou_type = UNEDITABLE_NAMES_DICT[pou_type] # one of 'Functions', 'Function Blocks' or 'Programs' |
|
2359 |
pou_type = {'Functions': 'function', 'Function Blocks': 'functionBlock', 'Programs': 'program'}[pou_type] |
|
2360 |
else: |
|
2361 |
pou_type = None |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2362 |
|
814 | 2363 |
pou_xml = self.GetCopyBuffer() |
2364 |
||
2365 |
result = self.Controler.PastePou(pou_type, pou_xml) |
|
2366 |
||
2367 |
if not isinstance(result, TupleType): |
|
1129
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2368 |
self.ShowErrorMessage(result) |
814 | 2369 |
else: |
2370 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, LIBRARYTREE) |
|
2371 |
self.EditProjectElement(ITEM_POU, result[0]) |
|
2372 |
||
2373 |
#------------------------------------------------------------------------------- |
|
2374 |
# Remove Project Elements Functions |
|
2375 |
#------------------------------------------------------------------------------- |
|
2376 |
||
1129
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2377 |
def CheckElementIsUsedBeforeDeletion(self, check_function, title, name): |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2378 |
if not check_function(name): |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2379 |
return True |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2380 |
|
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2381 |
dialog = wx.MessageDialog(self, |
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2382 |
_("\"%s\" is used by one or more POUs. Do you wish to continue?") % name, |
1129
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2383 |
title, wx.YES_NO|wx.ICON_QUESTION) |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2384 |
answer = dialog.ShowModal() |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2385 |
dialog.Destroy() |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2386 |
return answer == wx.ID_YES |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2387 |
|
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2388 |
def CheckDataTypeIsUsedBeforeDeletion(self, name): |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2389 |
return self.CheckElementIsUsedBeforeDeletion( |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2390 |
self.Controler.DataTypeIsUsed, |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2391 |
_("Remove Datatype"), name) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2392 |
|
1129
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2393 |
def CheckPouIsUsedBeforeDeletion(self, name): |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2394 |
return self.CheckElementIsUsedBeforeDeletion( |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2395 |
self.Controler.PouIsUsed, |
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2396 |
_("Remove Pou"), name) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2397 |
|
814 | 2398 |
def OnRemoveDataTypeMenu(self, event): |
2399 |
selected = self.ProjectTree.GetSelection() |
|
2400 |
if self.ProjectTree.GetPyData(selected)["type"] == ITEM_DATATYPE: |
|
2401 |
name = self.ProjectTree.GetItemText(selected) |
|
1129
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2402 |
if self.CheckDataTypeIsUsedBeforeDeletion(name): |
814 | 2403 |
self.Controler.ProjectRemoveDataType(name) |
2404 |
tagname = self.Controler.ComputeDataTypeName(name) |
|
2405 |
idx = self.IsOpened(tagname) |
|
2406 |
if idx is not None: |
|
2407 |
self.TabsOpened.DeletePage(idx) |
|
2408 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2409 |
|
814 | 2410 |
def OnRenamePouMenu(self, event): |
2411 |
selected = self.ProjectTree.GetSelection() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2412 |
if self.ProjectTree.GetPyData(selected)["type"] == ITEM_POU: |
814 | 2413 |
wx.CallAfter(self.ProjectTree.EditLabel, selected) |
2414 |
||
2415 |
def OnRemovePouMenu(self, event): |
|
2416 |
selected = self.ProjectTree.GetSelection() |
|
2417 |
if self.ProjectTree.GetPyData(selected)["type"] == ITEM_POU: |
|
2418 |
name = self.ProjectTree.GetItemText(selected) |
|
1129
189b49723f9f
Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents:
1112
diff
changeset
|
2419 |
if self.CheckPouIsUsedBeforeDeletion(name): |
814 | 2420 |
self.Controler.ProjectRemovePou(name) |
2421 |
tagname = self.Controler.ComputePouName(name) |
|
2422 |
idx = self.IsOpened(tagname) |
|
2423 |
if idx is not None: |
|
2424 |
self.TabsOpened.DeletePage(idx) |
|
2425 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
|
2426 |
||
2427 |
def OnRemoveTransitionMenu(self, event): |
|
2428 |
selected = self.ProjectTree.GetSelection() |
|
2429 |
item_infos = self.ProjectTree.GetPyData(selected) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2430 |
if item_infos["type"] == ITEM_TRANSITION: |
814 | 2431 |
transition = self.ProjectTree.GetItemText(selected) |
2432 |
pou_name = item_infos["tagname"].split("::")[1] |
|
2433 |
self.Controler.ProjectRemovePouTransition(pou_name, transition) |
|
2434 |
tagname = self.Controler.ComputePouTransitionName(pou_name, transition) |
|
2435 |
idx = self.IsOpened(tagname) |
|
2436 |
if idx is not None: |
|
2437 |
self.TabsOpened.DeletePage(idx) |
|
2438 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE) |
|
2439 |
||
2440 |
def OnRemoveActionMenu(self, event): |
|
2441 |
selected = self.ProjectTree.GetSelection() |
|
2442 |
item_infos = self.ProjectTree.GetPyData(selected) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2443 |
if item_infos["type"] == ITEM_ACTION: |
814 | 2444 |
action = self.ProjectTree.GetItemText(selected) |
2445 |
pou_name = item_infos["tagname"].split("::")[1] |
|
2446 |
self.Controler.ProjectRemovePouAction(pou_name, action) |
|
2447 |
tagname = self.Controler.ComputePouActionName(pou_name, action) |
|
2448 |
idx = self.IsOpened(tagname) |
|
2449 |
if idx is not None: |
|
2450 |
self.TabsOpened.DeletePage(idx) |
|
2451 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE) |
|
2452 |
||
2453 |
def OnRemoveConfigurationMenu(self, event): |
|
2454 |
selected = self.ProjectTree.GetSelection() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2455 |
if self.ProjectTree.GetPyData(selected)["type"] == ITEM_CONFIGURATION: |
814 | 2456 |
name = self.ProjectTree.GetItemText(selected) |
2457 |
self.Controler.ProjectRemoveConfiguration(name) |
|
2458 |
tagname = self.Controler.ComputeConfigurationName(name) |
|
2459 |
idx = self.IsOpened(tagname) |
|
2460 |
if idx is not None: |
|
2461 |
self.TabsOpened.DeletePage(idx) |
|
2462 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL) |
|
2463 |
||
2464 |
def OnRemoveResourceMenu(self, event): |
|
2465 |
selected = self.ProjectTree.GetSelection() |
|
2466 |
item_infos = self.ProjectTree.GetPyData(selected) |
|
2467 |
if item_infos["type"] == ITEM_RESOURCE: |
|
2468 |
resource = self.ProjectTree.GetItemText(selected) |
|
2469 |
config_name = item_infos["tagname"].split("::")[1] |
|
2470 |
self.Controler.ProjectRemoveConfigurationResource(config_name, resource) |
|
2471 |
tagname = self.Controler.ComputeConfigurationResourceName(config_name, selected) |
|
2472 |
idx = self.IsOpened(tagname) |
|
2473 |
if idx is not None: |
|
2474 |
self.TabsOpened.DeletePage(idx) |
|
2475 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL) |
|
2476 |
||
2477 |
#------------------------------------------------------------------------------- |
|
2478 |
# Highlights showing functions |
|
2479 |
#------------------------------------------------------------------------------- |
|
2480 |
||
2481 |
def ShowHighlight(self, infos, start, end, highlight_type): |
|
2482 |
self.SelectProjectTreeItem(infos[0]) |
|
2483 |
if infos[1] == "name": |
|
2484 |
self.Highlights[infos[0]] = highlight_type |
|
2485 |
self.RefreshProjectTree() |
|
2486 |
self.ProjectTree.Unselect() |
|
2487 |
else: |
|
2488 |
self.EditProjectElement(self.Controler.GetElementType(infos[0]), infos[0]) |
|
2489 |
selected = self.TabsOpened.GetSelection() |
|
2490 |
if selected != -1: |
|
2491 |
viewer = self.TabsOpened.GetPage(selected) |
|
2492 |
viewer.AddHighlight(infos[1:], start, end, highlight_type) |
|
2493 |
||
2494 |
def ShowError(self, infos, start, end): |
|
2495 |
self.ShowHighlight(infos, start, end, ERROR_HIGHLIGHT) |
|
2496 |
||
2497 |
def ShowSearchResult(self, infos, start, end): |
|
2498 |
self.ShowHighlight(infos, start, end, SEARCH_RESULT_HIGHLIGHT) |
|
2499 |
||
2500 |
def ClearHighlights(self, highlight_type=None): |
|
2501 |
if highlight_type is None: |
|
2502 |
self.Highlights = {} |
|
2503 |
else: |
|
2504 |
self.Highlights = dict([(name, highlight) for name, highlight in self.Highlights.iteritems() if highlight != highlight_type]) |
|
2505 |
self.RefreshProjectTree() |
|
2506 |
for i in xrange(self.TabsOpened.GetPageCount()): |
|
2507 |
viewer = self.TabsOpened.GetPage(i) |
|
2508 |
viewer.ClearHighlights(highlight_type) |
|
2509 |
||
2510 |
def ClearErrors(self): |
|
2511 |
self.ClearHighlights(ERROR_HIGHLIGHT) |
|
2512 |
||
2513 |
def ClearSearchResults(self): |
|
2514 |
self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT) |
|
838 | 2515 |
|
2516 |
#------------------------------------------------------------------------------- |
|
2517 |
# Viewer Printout |
|
2518 |
#------------------------------------------------------------------------------- |
|
2519 |
||
2520 |
UPPER_DIV = lambda x, y: (x / y) + {True : 0, False : 1}[(x % y) == 0] |
|
2521 |
||
2522 |
class GraphicPrintout(wx.Printout): |
|
2523 |
def __init__(self, viewer, page_size, margins, preview = False): |
|
2524 |
wx.Printout.__init__(self) |
|
2525 |
self.Viewer = viewer |
|
2526 |
self.PageSize = page_size |
|
2527 |
if self.PageSize[0] == 0 or self.PageSize[1] == 0: |
|
2528 |
self.PageSize = (1050, 1485) |
|
2529 |
self.Preview = preview |
|
2530 |
self.Margins = margins |
|
2531 |
self.FontSize = 5 |
|
2532 |
self.TextMargin = 3 |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2533 |
|
838 | 2534 |
maxx, maxy = viewer.GetMaxSize() |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2535 |
self.PageGrid = (UPPER_DIV(maxx, self.PageSize[0]), |
838 | 2536 |
UPPER_DIV(maxy, self.PageSize[1])) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2537 |
|
838 | 2538 |
def GetPageNumber(self): |
2539 |
return self.PageGrid[0] * self.PageGrid[1] |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2540 |
|
838 | 2541 |
def HasPage(self, page): |
2542 |
return page <= self.GetPageNumber() |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2543 |
|
838 | 2544 |
def GetPageInfo(self): |
2545 |
page_number = self.GetPageNumber() |
|
2546 |
return (1, page_number, 1, page_number) |
|
2547 |
||
2548 |
def OnBeginDocument(self, startPage, endPage): |
|
2549 |
dc = self.GetDC() |
|
2550 |
if not self.Preview and isinstance(dc, wx.PostScriptDC): |
|
2551 |
dc.SetResolution(720) |
|
2552 |
super(GraphicPrintout, self).OnBeginDocument(startPage, endPage) |
|
2553 |
||
2554 |
def OnPrintPage(self, page): |
|
2555 |
dc = self.GetDC() |
|
2556 |
dc.SetUserScale(1.0, 1.0) |
|
2557 |
dc.SetDeviceOrigin(0, 0) |
|
2558 |
dc.printing = not self.Preview |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2559 |
|
838 | 2560 |
# Get the size of the DC in pixels |
2561 |
ppiPrinterX, ppiPrinterY = self.GetPPIPrinter() |
|
2562 |
ppiScreenX, ppiScreenY = self.GetPPIScreen() |
|
2563 |
pw, ph = self.GetPageSizePixels() |
|
2564 |
dw, dh = dc.GetSizeTuple() |
|
2565 |
Xscale = (float(dw) * float(ppiPrinterX)) / (float(pw) * 25.4) |
|
2566 |
Yscale = (float(dh) * float(ppiPrinterY)) / (float(ph) * 25.4) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2567 |
|
838 | 2568 |
fontsize = self.FontSize * Yscale |
2569 |
text_margin = self.TextMargin * Yscale |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2570 |
|
838 | 2571 |
margin_left = self.Margins[0].x * Xscale |
2572 |
margin_top = self.Margins[0].y * Yscale |
|
2573 |
area_width = dw - self.Margins[1].x * Xscale - margin_left |
|
2574 |
area_height = dh - self.Margins[1].y * Yscale - margin_top |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2575 |
|
838 | 2576 |
dc.SetPen(MiterPen(wx.BLACK)) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2577 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
838 | 2578 |
dc.DrawRectangle(margin_left, margin_top, area_width, area_height) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2579 |
|
838 | 2580 |
dc.SetFont(wx.Font(fontsize, wx.DEFAULT, wx.NORMAL, wx.NORMAL)) |
2581 |
dc.SetTextForeground(wx.BLACK) |
|
2582 |
block_name = " - ".join(self.Viewer.GetTagName().split("::")[1:]) |
|
2583 |
text_width, text_height = dc.GetTextExtent(block_name) |
|
2584 |
dc.DrawText(block_name, margin_left, margin_top - text_height - self.TextMargin) |
|
2585 |
dc.DrawText(_("Page: %d") % page, margin_left, margin_top + area_height + self.TextMargin) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2586 |
|
838 | 2587 |
# Calculate the position on the DC for centering the graphic |
2588 |
posX = area_width * ((page - 1) % self.PageGrid[0]) |
|
2589 |
posY = area_height * ((page - 1) / self.PageGrid[0]) |
|
2590 |
||
2591 |
scaleX = float(area_width) / float(self.PageSize[0]) |
|
2592 |
scaleY = float(area_height) / float(self.PageSize[1]) |
|
2593 |
scale = min(scaleX, scaleY) |
|
2594 |
||
2595 |
# Set the scale and origin |
|
2596 |
dc.SetDeviceOrigin(-posX + margin_left, -posY + margin_top) |
|
2597 |
dc.SetClippingRegion(posX, posY, self.PageSize[0] * scale, self.PageSize[1] * scale) |
|
2598 |
dc.SetUserScale(scale, scale) |
|
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2599 |
|
838 | 2600 |
#------------------------------------------- |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2601 |
|
838 | 2602 |
self.Viewer.DoDrawing(dc, True) |
1408
eb2aa27602b7
Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents:
1401
diff
changeset
|
2603 |
|
838 | 2604 |
return True |
2605 |