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