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