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