-
Notifications
You must be signed in to change notification settings - Fork 7
/
IDEFrame.py
executable file
·2669 lines (2342 loc) · 124 KB
/
IDEFrame.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of Beremiz, a Integrated Development Environment for
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
#
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
#
# See COPYING file for copyrights details.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from __future__ import absolute_import
import sys
import cPickle
from types import TupleType
import base64
import wx
import wx.grid
import wx.aui
from editors.EditorPanel import EditorPanel
from editors.SFCViewer import SFC_Viewer
from editors.LDViewer import LD_Viewer
from editors.TextViewer import TextViewer
from editors.Viewer import Viewer, ZOOM_FACTORS
from editors.ResourceEditor import ConfigurationEditor, ResourceEditor
from editors.DataTypeEditor import DataTypeEditor
from PLCControler import *
from controls import CustomTree, LibraryPanel, PouInstanceVariablesPanel, SearchResultPanel
from controls.DebugVariablePanel import DebugVariablePanel
from dialogs import ProjectDialog, PouDialog, PouTransitionDialog, PouActionDialog, FindInPouDialog, SearchInProjectDialog
from util.BitmapLibrary import GetBitmap
from plcopen.types_enums import *
# Define PLCOpenEditor controls id
[
ID_PLCOPENEDITOR, ID_PLCOPENEDITORLEFTNOTEBOOK,
ID_PLCOPENEDITORBOTTOMNOTEBOOK, ID_PLCOPENEDITORRIGHTNOTEBOOK,
ID_PLCOPENEDITORPROJECTTREE, ID_PLCOPENEDITORMAINSPLITTER,
ID_PLCOPENEDITORSECONDSPLITTER, ID_PLCOPENEDITORTHIRDSPLITTER,
ID_PLCOPENEDITORLIBRARYPANEL, ID_PLCOPENEDITORLIBRARYSEARCHCTRL,
ID_PLCOPENEDITORLIBRARYTREE, ID_PLCOPENEDITORLIBRARYCOMMENT,
ID_PLCOPENEDITORTABSOPENED, ID_PLCOPENEDITORTABSOPENED,
ID_PLCOPENEDITOREDITORMENUTOOLBAR, ID_PLCOPENEDITOREDITORTOOLBAR,
ID_PLCOPENEDITORPROJECTPANEL,
] = [wx.NewId() for _init_ctrls in range(17)]
# Define PLCOpenEditor EditMenu extra items id
[
ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, ID_PLCOPENEDITOREDITMENUADDDATATYPE,
ID_PLCOPENEDITOREDITMENUADDFUNCTION, ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK,
ID_PLCOPENEDITOREDITMENUADDPROGRAM, ID_PLCOPENEDITOREDITMENUADDCONFIGURATION,
ID_PLCOPENEDITOREDITMENUFINDNEXT, ID_PLCOPENEDITOREDITMENUFINDPREVIOUS,
ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, ID_PLCOPENEDITOREDITMENUADDRESOURCE
] = [wx.NewId() for _init_coll_EditMenu_Items in range(10)]
# Define PLCOpenEditor DisplayMenu extra items id
[
ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE,
ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE,
ID_PLCOPENEDITORDISPLAYMENUFULLSCREEN,
] = [wx.NewId() for _init_coll_DisplayMenu_Items in range(3)]
# -------------------------------------------------------------------------------
# EditorToolBar definitions
# -------------------------------------------------------------------------------
# Define PLCOpenEditor Toolbar items id
[
ID_PLCOPENEDITOREDITORTOOLBARSELECTION, ID_PLCOPENEDITOREDITORTOOLBARCOMMENT,
ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, ID_PLCOPENEDITOREDITORTOOLBARBLOCK,
ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, ID_PLCOPENEDITOREDITORTOOLBARWIRE,
ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, ID_PLCOPENEDITOREDITORTOOLBARRUNG,
ID_PLCOPENEDITOREDITORTOOLBARCOIL, ID_PLCOPENEDITOREDITORTOOLBARCONTACT,
ID_PLCOPENEDITOREDITORTOOLBARBRANCH, ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP,
ID_PLCOPENEDITOREDITORTOOLBARSTEP, ID_PLCOPENEDITOREDITORTOOLBARTRANSITION,
ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE,
ID_PLCOPENEDITOREDITORTOOLBARJUMP, ID_PLCOPENEDITOREDITORTOOLBARMOTION,
] = [wx.NewId() for _init_coll_DefaultEditorToolBar_Items in range(18)]
# Define behaviour of each Toolbar item according to current POU body type
# Informations meaning are in this order:
# - Item is toggled
# - PLCOpenEditor mode where item is displayed (could be more then one)
# - Item id
# - Item callback function name
# - Item icon filename
# - Item tooltip text
EditorToolBarItems = {
"FBD": [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
"move", _("Move the view")),
(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
"add_comment", _("Create a new comment")),
(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
"add_variable", _("Create a new variable")),
(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
"add_block", _("Create a new block")),
(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool",
"add_connection", _("Create a new connection"))],
"LD": [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
"move", _("Move the view")),
(True, FREEDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
"add_comment", _("Create a new comment")),
(True, FREEDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool",
"add_powerrail", _("Create a new power rail")),
(False, DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARRUNG, "OnRungTool",
"add_rung", _("Create a new rung")),
(True, FREEDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARCOIL, "OnCoilTool",
"add_coil", _("Create a new coil")),
(False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool",
"add_contact", _("Create a new contact")),
(False, DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARBRANCH, "OnBranchTool",
"add_branch", _("Create a new branch")),
(True, FREEDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
"add_variable", _("Create a new variable")),
(False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
"add_block", _("Create a new block")),
(True, FREEDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool",
"add_connection", _("Create a new connection"))],
"SFC": [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
"move", _("Move the view")),
(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
"add_comment", _("Create a new comment")),
(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP, "OnInitialStepTool",
"add_initial_step", _("Create a new initial step")),
(False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARSTEP, "OnStepTool",
"add_step", _("Create a new step")),
(True, FREEDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARTRANSITION, "OnTransitionTool",
"add_transition", _("Create a new transition")),
(False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, "OnActionBlockTool",
"add_action", _("Create a new action block")),
(False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE, "OnDivergenceTool",
"add_divergence", _("Create a new divergence")),
(False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARJUMP, "OnJumpTool",
"add_jump", _("Create a new jump")),
(True, FREEDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
"add_variable", _("Create a new variable")),
(True, FREEDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
"add_block", _("Create a new block")),
(True, FREEDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool",
"add_connection", _("Create a new connection")),
(True, FREEDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool",
"add_powerrail", _("Create a new power rail")),
(True, FREEDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool",
"add_contact", _("Create a new contact"))],
"ST": [],
"IL": [],
"debug": [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
"move", _("Move the view"))],
}
# -------------------------------------------------------------------------------
# Helper Functions
# -------------------------------------------------------------------------------
def EncodeFileSystemPath(path, use_base64=True):
path = path.encode(sys.getfilesystemencoding())
if use_base64:
return base64.encodestring(path)
return path
def DecodeFileSystemPath(path, is_base64=True):
if is_base64:
path = base64.decodestring(path)
return unicode(path, sys.getfilesystemencoding())
def AppendMenu(parent, help, id, kind, text):
parent.Append(help=help, id=id, kind=kind, text=text)
[
TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE,
POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES
] = range(10)
def GetShortcutKeyCallbackFunction(viewer_function):
def ShortcutKeyFunction(self, event):
control = self.FindFocus()
if control is not None and control.GetName() in ["Viewer", "TextViewer"]:
getattr(control.ParentWindow, viewer_function)()
elif isinstance(control, wx.stc.StyledTextCtrl):
getattr(control, viewer_function)()
elif isinstance(control, wx.TextCtrl):
control.ProcessEvent(event)
return ShortcutKeyFunction
def GetDeleteElementFunction(remove_function, parent_type=None, check_function=None):
def DeleteElementFunction(self, selected):
name = self.ProjectTree.GetItemText(selected)
if check_function is None or check_function(name):
if parent_type is not None:
item_infos = self.ProjectTree.GetPyData(selected)
parent_name = item_infos["tagname"].split("::")[1]
remove_function(self.Controler, parent_name, name)
else:
remove_function(self.Controler, name)
return DeleteElementFunction
if wx.Platform == '__WXMSW__':
TAB_BORDER = 6
NOTEBOOK_BORDER = 6
else:
TAB_BORDER = 7
NOTEBOOK_BORDER = 2
def SimplifyTabLayout(tabs, rect):
for tab in tabs:
if tab["pos"][0] == rect.x:
others = [t for t in tabs if t != tab]
others.sort(lambda x, y: cmp(x["pos"][0], y["pos"][0]))
for other in others:
if other["pos"][1] == tab["pos"][1] and \
other["size"][1] == tab["size"][1] and \
other["pos"][0] == tab["pos"][0] + tab["size"][0] + TAB_BORDER:
tab["size"] = (tab["size"][0] + other["size"][0] + TAB_BORDER, tab["size"][1])
tab["pages"].extend(other["pages"])
tabs.remove(other)
if tab["size"][0] == rect.width:
return True
elif tab["pos"][1] == rect.y:
others = [t for t in tabs if t != tab]
others.sort(lambda x, y: cmp(x["pos"][1], y["pos"][1]))
for other in others:
if other["pos"][0] == tab["pos"][0] and \
other["size"][0] == tab["size"][0] and \
other["pos"][1] == tab["pos"][1] + tab["size"][1] + TAB_BORDER:
tab["size"] = (tab["size"][0], tab["size"][1] + other["size"][1] + TAB_BORDER)
tab["pages"].extend(other["pages"])
tabs.remove(other)
if tab["size"][1] == rect.height:
return True
return False
def ComputeTabsLayout(tabs, rect):
if len(tabs) == 0:
return tabs
if len(tabs) == 1:
return tabs[0]
split = None
split_id = None
for idx, tab in enumerate(tabs):
if len(tab["pages"]) == 0:
raise ValueError("Not possible")
if tab["size"][0] == rect.width:
if tab["pos"][1] == rect.y:
split = (wx.TOP, float(tab["size"][1]) / float(rect.height))
split_rect = wx.Rect(rect.x, rect.y + tab["size"][1] + TAB_BORDER,
rect.width, rect.height - tab["size"][1] - TAB_BORDER)
elif tab["pos"][1] == rect.height + 1 - tab["size"][1]:
split = (wx.BOTTOM, 1.0 - float(tab["size"][1]) / float(rect.height))
split_rect = wx.Rect(rect.x, rect.y,
rect.width, rect.height - tab["size"][1] - TAB_BORDER)
split_id = idx
break
elif tab["size"][1] == rect.height:
if tab["pos"][0] == rect.x:
split = (wx.LEFT, float(tab["size"][0]) / float(rect.width))
split_rect = wx.Rect(rect.x + tab["size"][0] + TAB_BORDER, rect.y,
rect.width - tab["size"][0] - TAB_BORDER, rect.height)
elif tab["pos"][0] == rect.width + 1 - tab["size"][0]:
split = (wx.RIGHT, 1.0 - float(tab["size"][0]) / float(rect.width))
split_rect = wx.Rect(rect.x, rect.y,
rect.width - tab["size"][0] - TAB_BORDER, rect.height)
split_id = idx
break
if split is not None:
split_tab = tabs.pop(split_id)
return {"split": split,
"tab": split_tab,
"others": ComputeTabsLayout(tabs, split_rect)}
else:
if SimplifyTabLayout(tabs, rect):
return ComputeTabsLayout(tabs, rect)
return tabs
UNEDITABLE_NAMES_DICT = dict([(_(n), n) for n in UNEDITABLE_NAMES])
class IDEFrame(wx.Frame):
"""IDEFrame Base Class"""
def _init_coll_MenuBar_Menus(self, parent):
parent.Append(menu=self.FileMenu, title=_(u'&File'))
parent.Append(menu=self.EditMenu, title=_(u'&Edit'))
parent.Append(menu=self.DisplayMenu, title=_(u'&Display'))
parent.Append(menu=self.HelpMenu, title=_(u'&Help'))
def _init_coll_FileMenu_Items(self, parent):
pass
def _init_coll_AddMenu_Items(self, parent, add_config=True):
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDDATATYPE,
kind=wx.ITEM_NORMAL, text=_(u'&Data Type'))
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDFUNCTION,
kind=wx.ITEM_NORMAL, text=_(u'&Function'))
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK,
kind=wx.ITEM_NORMAL, text=_(u'Function &Block'))
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDPROGRAM,
kind=wx.ITEM_NORMAL, text=_(u'&Program'))
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDRESOURCE,
kind=wx.ITEM_NORMAL, text=_(u'&Resource'))
if add_config:
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION,
kind=wx.ITEM_NORMAL, text=_(u'&Configuration'))
def _init_coll_EditMenu_Items(self, parent):
AppendMenu(parent, help='', id=wx.ID_UNDO,
kind=wx.ITEM_NORMAL, text=_(u'Undo') + '\tCTRL+Z')
AppendMenu(parent, help='', id=wx.ID_REDO,
kind=wx.ITEM_NORMAL, text=_(u'Redo') + '\tCTRL+Y')
parent.AppendSeparator()
AppendMenu(parent, help='', id=wx.ID_CUT,
kind=wx.ITEM_NORMAL, text=_(u'Cut') + '\tCTRL+X')
AppendMenu(parent, help='', id=wx.ID_COPY,
kind=wx.ITEM_NORMAL, text=_(u'Copy') + '\tCTRL+C')
AppendMenu(parent, help='', id=wx.ID_PASTE,
kind=wx.ITEM_NORMAL, text=_(u'Paste') + '\tCTRL+V')
parent.AppendSeparator()
AppendMenu(parent, help='', id=wx.ID_FIND,
kind=wx.ITEM_NORMAL, text=_(u'Find') + '\tCTRL+F')
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUFINDNEXT,
kind=wx.ITEM_NORMAL, text=_(u'Find Next') + '\tCTRL+K')
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUFINDPREVIOUS,
kind=wx.ITEM_NORMAL, text=_(u'Find Previous') + '\tCTRL+SHIFT+K')
parent.AppendSeparator()
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT,
kind=wx.ITEM_NORMAL, text=_(u'Search in Project') + '\tCTRL+SHIFT+F')
parent.AppendSeparator()
add_menu = wx.Menu(title='')
self._init_coll_AddMenu_Items(add_menu)
parent.AppendMenu(wx.ID_ADD, _(u"&Add Element"), add_menu)
AppendMenu(parent, help='', id=wx.ID_SELECTALL,
kind=wx.ITEM_NORMAL, text=_(u'Select All') + '\tCTRL+A')
AppendMenu(parent, help='', id=wx.ID_DELETE,
kind=wx.ITEM_NORMAL, text=_(u'&Delete'))
self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO)
self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO)
# self.Bind(wx.EVT_MENU, self.OnEnableUndoRedoMenu, id=ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO)
self.Bind(wx.EVT_MENU, self.OnCutMenu, id=wx.ID_CUT)
self.Bind(wx.EVT_MENU, self.OnCopyMenu, id=wx.ID_COPY)
self.Bind(wx.EVT_MENU, self.OnPasteMenu, id=wx.ID_PASTE)
self.Bind(wx.EVT_MENU, self.OnFindMenu, id=wx.ID_FIND)
self.Bind(wx.EVT_MENU, self.OnFindNextMenu,
id=ID_PLCOPENEDITOREDITMENUFINDNEXT)
self.Bind(wx.EVT_MENU, self.OnFindPreviousMenu,
id=ID_PLCOPENEDITOREDITMENUFINDPREVIOUS)
self.Bind(wx.EVT_MENU, self.OnSearchInProjectMenu,
id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT)
self.Bind(wx.EVT_MENU, self.OnAddDataTypeMenu,
id=ID_PLCOPENEDITOREDITMENUADDDATATYPE)
self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("function"),
id=ID_PLCOPENEDITOREDITMENUADDFUNCTION)
self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("functionBlock"),
id=ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK)
self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("program"),
id=ID_PLCOPENEDITOREDITMENUADDPROGRAM)
self.Bind(wx.EVT_MENU, self.AddResourceMenu,
id=ID_PLCOPENEDITOREDITMENUADDRESOURCE)
self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu,
id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION)
self.Bind(wx.EVT_MENU, self.OnSelectAllMenu, id=wx.ID_SELECTALL)
self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=wx.ID_DELETE)
self.AddToMenuToolBar([(wx.ID_UNDO, "undo", _(u'Undo'), None),
(wx.ID_REDO, "redo", _(u'Redo'), None),
None,
(wx.ID_CUT, "cut", _(u'Cut'), None),
(wx.ID_COPY, "copy", _(u'Copy'), None),
(wx.ID_PASTE, "paste", _(u'Paste'), None),
None,
(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, "find", _(u'Search in Project'), None),
(ID_PLCOPENEDITORDISPLAYMENUFULLSCREEN, "fullscreen", _(u'Toggle fullscreen mode'), None)])
def _init_coll_DisplayMenu_Items(self, parent):
AppendMenu(parent, help='', id=wx.ID_REFRESH,
kind=wx.ITEM_NORMAL, text=_(u'Refresh') + '\tCTRL+R')
if self.EnableDebug:
AppendMenu(parent, help='', id=wx.ID_CLEAR,
kind=wx.ITEM_NORMAL, text=_(u'Clear Errors') + '\tCTRL+K')
parent.AppendSeparator()
zoommenu = wx.Menu(title='')
parent.AppendMenu(wx.ID_ZOOM_FIT, _("Zoom"), zoommenu)
for idx, value in enumerate(ZOOM_FACTORS):
new_id = wx.NewId()
AppendMenu(zoommenu, help='', id=new_id,
kind=wx.ITEM_RADIO, text=str(int(round(value * 100))) + "%")
self.Bind(wx.EVT_MENU, self.GenerateZoomFunction(idx), id=new_id)
parent.AppendSeparator()
AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE,
kind=wx.ITEM_NORMAL, text=_(u'Switch perspective') + '\tF12')
self.Bind(wx.EVT_MENU, self.SwitchPerspective, id=ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE)
AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENUFULLSCREEN,
kind=wx.ITEM_NORMAL, text=_(u'Full screen') + '\tShift-F12')
self.Bind(wx.EVT_MENU, self.SwitchFullScrMode, id=ID_PLCOPENEDITORDISPLAYMENUFULLSCREEN)
AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE,
kind=wx.ITEM_NORMAL, text=_(u'Reset Perspective'))
self.Bind(wx.EVT_MENU, self.OnResetPerspective, id=ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE)
self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH)
if self.EnableDebug:
self.Bind(wx.EVT_MENU, self.OnClearErrorsMenu, id=wx.ID_CLEAR)
def _init_coll_HelpMenu_Items(self, parent):
pass
def _init_utils(self):
self.MenuBar = wx.MenuBar()
self.FileMenu = wx.Menu(title='')
self.EditMenu = wx.Menu(title='')
self.DisplayMenu = wx.Menu(title='')
self.HelpMenu = wx.Menu(title='')
self._init_coll_MenuBar_Menus(self.MenuBar)
self._init_coll_FileMenu_Items(self.FileMenu)
self._init_coll_EditMenu_Items(self.EditMenu)
self._init_coll_DisplayMenu_Items(self.DisplayMenu)
self._init_coll_HelpMenu_Items(self.HelpMenu)
def _init_icon(self, parent):
if self.icon:
self.SetIcon(self.icon)
elif parent and parent.icon:
self.SetIcon(parent.icon)
def _init_ctrls(self, prnt):
self._init_icon(prnt)
self.SetClientSize(wx.Size(1000, 600))
self.Bind(wx.EVT_ACTIVATE, self.OnActivated)
self.TabsImageList = wx.ImageList(31, 16)
self.TabsImageListIndexes = {}
# -----------------------------------------------------------------------
# Creating main structure
# -----------------------------------------------------------------------
self.AUIManager = wx.aui.AuiManager(self)
self.AUIManager.SetDockSizeConstraint(0.5, 0.5)
self.Panes = {}
self.LeftNoteBook = wx.aui.AuiNotebook(
self, ID_PLCOPENEDITORLEFTNOTEBOOK,
style=(wx.aui.AUI_NB_TOP |
wx.aui.AUI_NB_TAB_SPLIT |
wx.aui.AUI_NB_TAB_MOVE |
wx.aui.AUI_NB_SCROLL_BUTTONS |
wx.aui.AUI_NB_TAB_EXTERNAL_MOVE))
self.LeftNoteBook.Bind(wx.aui.EVT_AUINOTEBOOK_ALLOW_DND,
self.OnAllowNotebookDnD)
self.AUIManager.AddPane(
self.LeftNoteBook,
wx.aui.AuiPaneInfo().Name("ProjectPane").Left().Layer(1).
BestSize(wx.Size(300, 500)).CloseButton(False))
self.BottomNoteBook = wx.aui.AuiNotebook(
self, ID_PLCOPENEDITORBOTTOMNOTEBOOK,
style=(wx.aui.AUI_NB_TOP |
wx.aui.AUI_NB_TAB_SPLIT |
wx.aui.AUI_NB_TAB_MOVE |
wx.aui.AUI_NB_SCROLL_BUTTONS |
wx.aui.AUI_NB_TAB_EXTERNAL_MOVE))
self.BottomNoteBook.Bind(wx.aui.EVT_AUINOTEBOOK_ALLOW_DND,
self.OnAllowNotebookDnD)
self.AUIManager.AddPane(
self.BottomNoteBook,
wx.aui.AuiPaneInfo().Name("ResultPane").Bottom().Layer(0).
BestSize(wx.Size(800, 300)).CloseButton(False))
self.RightNoteBook = wx.aui.AuiNotebook(
self, ID_PLCOPENEDITORRIGHTNOTEBOOK,
style=(wx.aui.AUI_NB_TOP |
wx.aui.AUI_NB_TAB_SPLIT |
wx.aui.AUI_NB_TAB_MOVE |
wx.aui.AUI_NB_SCROLL_BUTTONS |
wx.aui.AUI_NB_TAB_EXTERNAL_MOVE))
self.RightNoteBook.Bind(wx.aui.EVT_AUINOTEBOOK_ALLOW_DND,
self.OnAllowNotebookDnD)
self.AUIManager.AddPane(
self.RightNoteBook,
wx.aui.AuiPaneInfo().Name("LibraryPane").Right().Layer(0).
BestSize(wx.Size(250, 400)).CloseButton(False))
self.TabsOpened = wx.aui.AuiNotebook(
self, ID_PLCOPENEDITORTABSOPENED,
style=(wx.aui.AUI_NB_DEFAULT_STYLE |
wx.aui.AUI_NB_WINDOWLIST_BUTTON))
self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGING,
self.OnPouSelectedChanging)
self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,
self.OnPouSelectedChanged)
self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE,
self.OnPageClose)
self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_END_DRAG,
self.OnPageDragged)
self.AUIManager.AddPane(self.TabsOpened,
wx.aui.AuiPaneInfo().CentrePane().Name("TabsPane"))
# -----------------------------------------------------------------------
# Creating PLCopen Project Types Tree
# -----------------------------------------------------------------------
self.MainTabs = {}
self.ProjectPanel = wx.SplitterWindow(
id=ID_PLCOPENEDITORPROJECTPANEL,
name='ProjectPanel', parent=self.LeftNoteBook, point=wx.Point(0, 0),
size=wx.Size(0, 0), style=wx.SP_3D)
self.ProjectTree = CustomTree(id=ID_PLCOPENEDITORPROJECTTREE,
name='ProjectTree',
parent=self.ProjectPanel,
pos=wx.Point(0, 0), size=wx.Size(0, 0),
style=wx.SUNKEN_BORDER,
agwStyle=(wx.TR_HAS_BUTTONS |
wx.TR_SINGLE |
wx.TR_EDIT_LABELS))
self.ProjectTree.SetBackgroundBitmap(GetBitmap("custom_tree_background"),
wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM)
add_menu = wx.Menu()
self._init_coll_AddMenu_Items(add_menu)
self.ProjectTree.SetAddMenu(add_menu)
self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnProjectTreeRightUp,
id=ID_PLCOPENEDITORPROJECTTREE)
self.ProjectTree.Bind(wx.EVT_LEFT_UP, self.OnProjectTreeLeftUp)
self.Bind(wx.EVT_TREE_SEL_CHANGING, self.OnProjectTreeItemChanging,
id=ID_PLCOPENEDITORPROJECTTREE)
self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnProjectTreeBeginDrag,
id=ID_PLCOPENEDITORPROJECTTREE)
self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit,
id=ID_PLCOPENEDITORPROJECTTREE)
self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnProjectTreeItemEndEdit,
id=ID_PLCOPENEDITORPROJECTTREE)
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnProjectTreeItemActivated,
id=ID_PLCOPENEDITORPROJECTTREE)
self.ProjectTree.Bind(wx.EVT_MOTION, self.OnProjectTreeMotion)
# -----------------------------------------------------------------------
# Creating PLCopen Project POU Instance Variables Panel
# -----------------------------------------------------------------------
self.PouInstanceVariablesPanel = PouInstanceVariablesPanel(self.ProjectPanel, self, self.Controler, self.EnableDebug)
self.MainTabs["ProjectPanel"] = (self.ProjectPanel, _("Project"))
self.LeftNoteBook.AddPage(*self.MainTabs["ProjectPanel"])
self.ProjectPanel.SplitHorizontally(self.ProjectTree, self.PouInstanceVariablesPanel, 300)
# -----------------------------------------------------------------------
# Creating Tool Bar
# -----------------------------------------------------------------------
MenuToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORMENUTOOLBAR,
wx.DefaultPosition, wx.DefaultSize,
wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
MenuToolBar.SetToolBitmapSize(wx.Size(25, 25))
MenuToolBar.Realize()
self.Panes["MenuToolBar"] = MenuToolBar
self.AUIManager.AddPane(MenuToolBar, wx.aui.AuiPaneInfo().
Name("MenuToolBar").Caption(_("Menu ToolBar")).
ToolbarPane().Top().
LeftDockable(False).RightDockable(False))
EditorToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORTOOLBAR,
wx.DefaultPosition, wx.DefaultSize,
wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
EditorToolBar.SetToolBitmapSize(wx.Size(25, 25))
EditorToolBar.AddRadioTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION,
GetBitmap("select"),
wx.NullBitmap,
_("Select an object"))
EditorToolBar.Realize()
self.Panes["EditorToolBar"] = EditorToolBar
self.AUIManager.AddPane(EditorToolBar, wx.aui.AuiPaneInfo().
Name("EditorToolBar").Caption(_("Editor ToolBar")).
ToolbarPane().Top().Position(1).
LeftDockable(False).RightDockable(False))
self.Bind(wx.EVT_MENU, self.OnSelectionTool,
id=ID_PLCOPENEDITOREDITORTOOLBARSELECTION)
# -----------------------------------------------------------------------
# Creating Search Panel
# -----------------------------------------------------------------------
self.SearchResultPanel = SearchResultPanel(self.BottomNoteBook, self)
self.MainTabs["SearchResultPanel"] = (self.SearchResultPanel, _("Search"))
self.BottomNoteBook.AddPage(*self.MainTabs["SearchResultPanel"])
# -----------------------------------------------------------------------
# Creating Library Panel
# -----------------------------------------------------------------------
self.LibraryPanel = LibraryPanel(self, True)
self.MainTabs["LibraryPanel"] = (self.LibraryPanel, _("Library"))
self.RightNoteBook.AddPage(*self.MainTabs["LibraryPanel"])
self._init_utils()
self.SetMenuBar(self.MenuBar)
if self.EnableDebug:
self.DebugVariablePanel = DebugVariablePanel(self.RightNoteBook, self.Controler, self)
self.MainTabs["DebugVariablePanel"] = (self.DebugVariablePanel, _("Debugger"))
self.RightNoteBook.AddPage(*self.MainTabs["DebugVariablePanel"])
self.AUIManager.Update()
def __init__(self, parent, enable_debug=False):
wx.Frame.__init__(self, id=ID_PLCOPENEDITOR, name='IDEFrame',
parent=parent, pos=wx.DefaultPosition,
size=wx.Size(1000, 600),
style=wx.DEFAULT_FRAME_STYLE)
self.Controler = None
self.Config = wx.ConfigBase.Get()
self.EnableDebug = enable_debug
self._init_ctrls(parent)
# Define Tree item icon list
self.TreeImageList = wx.ImageList(16, 16)
self.TreeImageDict = {}
# Icons for languages
for language in LANGUAGES:
self.TreeImageDict[language] = self.TreeImageList.Add(GetBitmap(language))
# Icons for other items
for imgname, itemtype in [
# editables
("PROJECT", ITEM_PROJECT),
# ("POU", ITEM_POU),
# ("VARIABLE", ITEM_VARIABLE),
("TRANSITION", ITEM_TRANSITION),
("ACTION", ITEM_ACTION),
("CONFIGURATION", ITEM_CONFIGURATION),
("RESOURCE", ITEM_RESOURCE),
("DATATYPE", ITEM_DATATYPE),
# uneditables
("DATATYPES", ITEM_DATATYPES),
("FUNCTION", ITEM_FUNCTION),
("FUNCTIONBLOCK", ITEM_FUNCTIONBLOCK),
("PROGRAM", ITEM_PROGRAM),
("VAR_LOCAL", ITEM_VAR_LOCAL),
("VAR_LOCAL", ITEM_VAR_GLOBAL),
("VAR_LOCAL", ITEM_VAR_EXTERNAL),
("VAR_LOCAL", ITEM_VAR_TEMP),
("VAR_INPUT", ITEM_VAR_INPUT),
("VAR_OUTPUT", ITEM_VAR_OUTPUT),
("VAR_INOUT", ITEM_VAR_INOUT),
("TRANSITIONS", ITEM_TRANSITIONS),
("ACTIONS", ITEM_ACTIONS),
("CONFIGURATIONS", ITEM_CONFIGURATIONS),
("RESOURCES", ITEM_RESOURCES),
("PROPERTIES", ITEM_PROPERTIES)]:
self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(imgname))
# Assign icon list to TreeCtrls
self.ProjectTree.SetImageList(self.TreeImageList)
self.PouInstanceVariablesPanel.SetTreeImageList(self.TreeImageList)
self.CurrentEditorToolBar = []
self.CurrentMenu = None
self.SelectedItem = None
self.LastToolTipItem = None
self.SearchParams = None
self.Highlights = {}
self.DrawingMode = FREEDRAWING_MODE
# self.DrawingMode = DRIVENDRAWING_MODE
self.AuiTabCtrl = []
# Save default perspective
notebooks = {}
for notebook, entry_name in [(self.LeftNoteBook, "leftnotebook"),
(self.BottomNoteBook, "bottomnotebook"),
(self.RightNoteBook, "rightnotebook")]:
notebooks[entry_name] = self.SaveTabLayout(notebook)
self.DefaultPerspective = {
"perspective": self.AUIManager.SavePerspective(),
"notebooks": notebooks,
}
# Initialize Printing configuring elements
self.PrintData = wx.PrintData()
self.PrintData.SetPaperId(wx.PAPER_A4)
self.PrintData.SetPrintMode(wx.PRINT_MODE_PRINTER)
self.PageSetupData = wx.PageSetupDialogData(self.PrintData)
self.PageSetupData.SetMarginTopLeft(wx.Point(10, 15))
self.PageSetupData.SetMarginBottomRight(wx.Point(10, 20))
self.SetRefreshFunctions()
self.SetDeleteFunctions()
wx.CallAfter(self.InitFindDialog)
def __del__(self):
self.FindDialog.Destroy()
def InitFindDialog(self):
self.FindDialog = FindInPouDialog(self)
self.FindDialog.Hide()
def Show(self):
wx.Frame.Show(self)
wx.CallAfter(self.RestoreLastState)
def OnActivated(self, event):
if event.GetActive():
wx.CallAfter(self._Refresh, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
event.Skip()
def SelectTab(self, tab):
for notebook in [self.LeftNoteBook, self.BottomNoteBook, self.RightNoteBook]:
idx = notebook.GetPageIndex(tab)
if idx != wx.NOT_FOUND and idx != notebook.GetSelection():
notebook.SetSelection(idx)
return
# -------------------------------------------------------------------------------
# Saving and restoring frame organization functions
# -------------------------------------------------------------------------------
def GetTabInfos(self, tab):
for page_name, (page_ref, _page_title) in self.MainTabs.iteritems():
if page_ref == tab:
return ("main", page_name)
return None
def SaveTabLayout(self, notebook):
tabs = []
for child in notebook.GetChildren():
if isinstance(child, wx.aui.AuiTabCtrl):
if child.GetPageCount() > 0:
pos = child.GetPosition()
tab = {"pos": (pos.x, pos.y), "pages": []}
tab_size = child.GetSize()
for page_idx in xrange(child.GetPageCount()):
page = child.GetWindowFromIdx(page_idx)
if "size" not in tab:
tab["size"] = (tab_size[0], tab_size[1] + page.GetSize()[1])
tab_infos = self.GetTabInfos(page)
if tab_infos is not None:
tab["pages"].append((tab_infos, page_idx == child.GetActivePage()))
tabs.append(tab)
tabs.sort(lambda x, y: cmp(x["pos"], y["pos"]))
size = notebook.GetSize()
return ComputeTabsLayout(tabs, wx.Rect(1, 1, size[0] - NOTEBOOK_BORDER, size[1] - NOTEBOOK_BORDER))
def LoadTab(self, notebook, page_infos):
if page_infos[0] == "main":
infos = self.MainTabs.get(page_infos[1])
if infos is not None:
page_ref, page_title = infos
notebook.AddPage(page_ref, page_title)
return notebook.GetPageIndex(page_ref)
elif page_infos[0] == "editor":
tagname = page_infos[1]
page_ref = self.EditProjectElement(GetElementType(tagname), tagname)
if page_ref is not None:
page_ref.RefreshView()
return notebook.GetPageIndex(page_ref)
elif page_infos[0] == "debug":
instance_path = page_infos[1]
instance_infos = self.Controler.GetInstanceInfos(instance_path, self.EnableDebug)
if instance_infos is not None:
return notebook.GetPageIndex(self.OpenDebugViewer(instance_infos["class"], instance_path, instance_infos["type"]))
return None
def LoadTabLayout(self, notebook, tabs, mode="all", first_index=None):
if isinstance(tabs, ListType):
if len(tabs) == 0:
return
raise ValueError("Not supported")
if "split" in tabs:
self.LoadTabLayout(notebook, tabs["others"])
split_dir, _split_ratio = tabs["split"]
first_index = self.LoadTabLayout(notebook, tabs["tab"], mode="first")
notebook.Split(first_index, split_dir)
self.LoadTabLayout(notebook, tabs["tab"], mode="others", first_index=first_index)
elif mode == "first":
return self.LoadTab(notebook, tabs["pages"][0][0])
else:
selected = first_index
if mode == "others":
add_tabs = tabs["pages"][1:]
else:
add_tabs = tabs["pages"]
for page_infos, page_selected in add_tabs:
page_idx = self.LoadTab(notebook, page_infos)
if page_selected:
selected = page_idx
if selected is not None:
wx.CallAfter(notebook.SetSelection, selected)
def ResetPerspective(self):
if self.DefaultPerspective is not None:
self.AUIManager.LoadPerspective(self.DefaultPerspective["perspective"])
for notebook in [self.LeftNoteBook, self.BottomNoteBook, self.RightNoteBook]:
for dummy in xrange(notebook.GetPageCount()):
notebook.RemovePage(0)
notebooks = self.DefaultPerspective["notebooks"]
for notebook, entry_name in [(self.LeftNoteBook, "leftnotebook"),
(self.BottomNoteBook, "bottomnotebook"),
(self.RightNoteBook, "rightnotebook")]:
self.LoadTabLayout(notebook, notebooks.get(entry_name))
self._Refresh(EDITORTOOLBAR)
def RestoreLastState(self):
frame_size = None
if self.Config.HasEntry("framesize"):
frame_size = cPickle.loads(str(self.Config.Read("framesize")))
if frame_size is None:
self.Maximize()
else:
self.SetClientSize(frame_size)
def SaveLastState(self):
if not self.IsMaximized():
self.Config.Write("framesize", cPickle.dumps(self.GetClientSize()))
elif self.Config.HasEntry("framesize"):
self.Config.DeleteEntry("framesize")
self.Config.Flush()
# -------------------------------------------------------------------------------
# General Functions
# -------------------------------------------------------------------------------
def SetRefreshFunctions(self):
self.RefreshFunctions = {
TITLE: self.RefreshTitle,
EDITORTOOLBAR: self.RefreshEditorToolBar,
FILEMENU: self.RefreshFileMenu,
EDITMENU: self.RefreshEditMenu,
DISPLAYMENU: self.RefreshDisplayMenu,
PROJECTTREE: self.RefreshProjectTree,
POUINSTANCEVARIABLESPANEL: self.RefreshPouInstanceVariablesPanel,
LIBRARYTREE: self.RefreshLibraryPanel,
SCALING: self.RefreshScaling,
PAGETITLES: self.RefreshPageTitles}
def _Refresh(self, *elements):
"""Call Editor refresh functions.
:param elements: List of elements to refresh.
"""
try:
for element in elements:
self.RefreshFunctions[element]()
except wx.PyDeadObjectError:
# ignore exceptions caused by refresh while quitting
pass
def OnPageClose(self, event):
"""Callback function when AUINotebook Page closed with CloseButton
:param event: AUINotebook Event.
"""
selected = self.TabsOpened.GetSelection()
if selected > -1:
window = self.TabsOpened.GetPage(selected)
if window.CheckSaveBeforeClosing():
# Refresh all window elements that have changed
wx.CallAfter(self._Refresh, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
wx.CallAfter(self.RefreshTabCtrlEvent)
wx.CallAfter(self.CloseFindInPouDialog)
event.Skip()
else:
event.Veto()
def GetCopyBuffer(self, primary_selection=False):
data = None
if primary_selection and wx.Platform == '__WXMSW__':
return data
else:
wx.TheClipboard.UsePrimarySelection(primary_selection)
if not wx.TheClipboard.IsOpened():
dataobj = wx.TextDataObject()
if wx.TheClipboard.Open():
success = False
try:
success = wx.TheClipboard.GetData(dataobj)
except wx._core.PyAssertionError:
pass
wx.TheClipboard.Close()
if success:
data = dataobj.GetText()
return data
def SetCopyBuffer(self, text, primary_selection=False):
if primary_selection and wx.Platform == '__WXMSW__':
return
else:
wx.TheClipboard.UsePrimarySelection(primary_selection)
if not wx.TheClipboard.IsOpened():
data = wx.TextDataObject()
data.SetText(text)
if wx.TheClipboard.Open():
wx.TheClipboard.SetData(data)
wx.TheClipboard.Flush()
wx.TheClipboard.Close()
wx.CallAfter(self.RefreshEditMenu)
def GetDrawingMode(self):
return self.DrawingMode
def RefreshScaling(self):
for i in xrange(self.TabsOpened.GetPageCount()):
editor = self.TabsOpened.GetPage(i)
editor.RefreshScaling()
def EditProjectSettings(self):
old_values = self.Controler.GetProjectProperties()
dialog = ProjectDialog(self)
dialog.SetValues(old_values)
if dialog.ShowModal() == wx.ID_OK:
new_values = dialog.GetValues()
new_values["creationDateTime"] = old_values["creationDateTime"]
if new_values != old_values:
self.Controler.SetProjectProperties(None, new_values)
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU,
PROJECTTREE, POUINSTANCEVARIABLESPANEL, SCALING)
dialog.Destroy()
# -------------------------------------------------------------------------------
# Notebook Unified Functions
# -------------------------------------------------------------------------------
def AddPage(self, window, text):