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