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