forked from bpbible/bpbible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auilayer.py
859 lines (654 loc) · 23.5 KB
/
auilayer.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
import re
import wx
from wx import aui
import guiconfig
import config
from gui import guiutil
from util.configmgr import config_manager
from util.observerlist import ObserverList
from module_popup import ModulePopup
from util.debug import dprint, WARNING
from util import osutils
import util.i18n
# the following three functions borrowed from wxAUI in dockart.cpp
# wxAuiBlendColour is used by wxAuiStepColour
def wxAuiBlendColour(fg, bg, alpha):
result = bg + (alpha * (fg - bg))
result = max(result, 0)
result = min(result, 255)
return result
# wxAuiStepColour() it a utility function that simply darkens
# or lightens a color, based on the specified percentage
# ialpha of 0 would be completely black, 100 completely white
# an ialpha of 100 returns the same colour
def wxAuiStepColour(c, ialpha):
if ialpha == 100:
return c
r, g, b = c.Red(), c.Green(), c.Blue()
# ialpha is 0..200 where 0 is completely black
# and 200 is completely white and 100 is the same
# convert that to normal alpha 0.0 - 1.0
ialpha = min(ialpha, 200);
ialpha = max(ialpha, 0);
alpha = (ialpha - 100.0)/100.0
if (ialpha > 100):
# blend with white
bg = 255.0;
alpha = 1.0 - alpha# // 0 = transparent fg; 1 = opaque fg
else:
# blend with black
bg = 0.0
alpha = 1.0 + alpha# // 0 = transparent fg; 1 = opaque fg
r = wxAuiBlendColour(r, bg, alpha)
g = wxAuiBlendColour(g, bg, alpha)
b = wxAuiBlendColour(b, bg, alpha)
return r, g, b
def wxAuiLightContrastColour(c):
amount = 120
# if the color is especially dark, then
# make the contrast even lighter
if c.Red() < 128 and c.Green() < 128 and c.Blue() < 128:
amount = 160
return wxAuiStepColour(c, amount)
class DockArt(wx.aui.PyAuiDockArt):
"""DockArt: tracks the sections which when right clicked, bring up a
toolbar popup"""
text_padding = 2
def __init__(self, parent):
self.aui_dock_art = wx.aui.AuiDefaultDockArt()
self.caption_drawn = ObserverList()
super(DockArt, self).__init__()
self.parent = parent
def DrawBackground(self, dc, window, orientation, rect):
# note the empty space that has been taken by spurious background
# this space will be able to be right-clicked in to bring up a list of
# toolbars
self.aui_dock_art.DrawBackground(dc, window, orientation, rect)
self.parent.rects.append(rect)
def DrawBorder(self, dc, rect, pane):
# note the empty space that has been taken by toolbars that aren't
# floating
# this space will be able to be right-clicked in to bring up a list of
# toolbars
self.aui_dock_art.DrawBorder(dc, pane.window, rect, pane)
if pane.IsToolbar() and not pane.IsFloating():
self.parent.rects.append(rect)
def setup_font(self, dc, active):
dc.TextForeground = self.GetColour([
aui.AUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR,
aui.AUI_DOCKART_ACTIVE_CAPTION_TEXT_COLOUR
][active])
dc.Font = self.GetFont(aui.AUI_DOCKART_CAPTION_FONT)
def DrawCaption(self, dc, window, text, rect, pane):
from install_manager.install_module import chop_text
active = bool(pane.state & pane.optionActive)
max_width = rect[2] - 5
button_size = self.GetMetric(aui.AUI_DOCKART_PANE_BUTTON_SIZE)
max_width -= button_size * (
pane.HasCloseButton() + pane.HasMaximizeButton()
)
caption_sizes[pane.name] = (
pane, wx.Rect(rect[0], rect[1], max_width, rect[3])
)
match = None
if pane.name in [title for p, title in self.parent.panes]:
self.regex = re.compile(r"\(([^)]+)\)")
# get the last match
for match in self.regex.finditer(text):
pass
if not match:
# use the default behaviour
return self.aui_dock_art.DrawCaption(dc, window, text, rect, pane)
# draw the background...
self.aui_dock_art.DrawCaption(dc, window, "", rect, pane)
# setup our font
self.setup_font(dc, active)
combo_text = match.group(1)
before_text = text[:match.start(1)]
after_text = text[match.end(1):]
chopped_text = chop_text(dc, before_text, max_size=max_width)
w, h = dc.GetTextExtent(chopped_text)
clipping_rect = wx.Rect(rect[0], rect[1], max_width, rect[3])
dc.SetClippingRegion(*clipping_rect)
dc.DrawText(chopped_text, rect[0] + 2, rect.y+(rect.height/2)-(h/2))
if before_text != chopped_text:
if pane.name in size_taken:
del size_taken[pane.name]
dc.DestroyClippingRegion()
return
c_w = w
c_h = h
w, h = dc.GetTextExtent(combo_text)
height = h + 2
backing_rect = wx.Rect(
rect[0] + c_w + self.text_padding, rect.y+rect.height/2-height/2,
w+self.text_padding+height, height
)
self.draw_combo(dc, window, backing_rect, combo_text,
pane, clipping_rect)
max_width -= backing_rect.width - 3
chopped_text = chop_text(dc, after_text, max_size=max_width)
w, h = dc.GetTextExtent(chopped_text)
dc.DrawText(chopped_text, backing_rect.right + 2,
rect.y+(rect.height/2)-(h/2))
w += rect[0] + 2
h = rect[1]
size_taken[pane.name] = pane, backing_rect, combo_text, clipping_rect
#self.caption_drawn(pane, max_width, *size_taken[pane.name])
dc.DestroyClippingRegion()
def draw_combo(self, dc, window, rect, text, pane, clipping_rect=None):
assert pane.IsShown(), "Trying to draw hidden combo!"
active = bool(pane.state & pane.optionActive)
self.setup_font(dc, active)
cc = self.GetColour([
aui.AUI_DOCKART_INACTIVE_CAPTION_COLOUR,
aui.AUI_DOCKART_ACTIVE_CAPTION_COLOUR,
][active])
dc.SetBrush(wx.Brush(wxAuiStepColour(cc, 120)))
dc.SetPen(wx.Pen(wxAuiStepColour(cc,
70 + (pane.name not in mouse_over) * 25))
)
w, h = dc.GetTextExtent(text)
dc.DrawRectangleRect(rect)
dc.DrawText(text, rect[0] + self.text_padding,
rect.y+(rect.height/2)-(h/2))
h = rect.height
drop_arrow_rect = (
rect[0] + w + self.text_padding,
rect.y+(rect.height/2)-(h/2), 15, 15
)
# clipping doesn't seem to be done here. So draw all or nothing
if clipping_rect and clipping_rect.ContainsRect(drop_arrow_rect):
# bug under gtk:
# window content doesn't fill maximized window when resizing if we
# set the foreground colour for the mainframe. So change the
# colour of our hidden text buffer instead and use it
if osutils.is_gtk():
window = guiconfig.mainfrm.buffer
fg_old = window.ForegroundColour
window.SetForegroundColour(dc.GetTextForeground())
wx.RendererNative.Get().DrawDropArrow(
window, dc, drop_arrow_rect, 0
)
window.SetForegroundColour(fg_old)
mouse_over = {}
size_taken = {}
caption_sizes = {}
class AuiLayer(object):
"""The AUI part of the main form"""
def setup(self):
self.aui_mgr = aui.AuiManager(
self,
aui.AUI_MGR_ALLOW_FLOATING|
aui.AUI_MGR_ALLOW_ACTIVE_PANE|
aui.AUI_MGR_NO_VENETIAN_BLINDS_FADE|
aui.AUI_MGR_TRANSPARENT_HINT)
self.on_close += self.aui_mgr.UnInit
self.aui_uses_provider = False
self.maximized_pane_direction = None
self.needs_showing_event = {}
self.on_render = ObserverList()
try:
self.dockart = DockArt(self)
self.aui_mgr.Bind(aui.EVT_AUI_RENDER, self.on_aui_render)
self.aui_mgr.SetArtProvider(self.dockart)
self.aui_uses_provider = True
except AttributeError:
# no constructor defined previous to wx 2.8.4.0, so can't override
pass
# now set the inactive caption colour
# wxAUI arguably should do this itself
# on high contrast black, you couldn't see the inactive captions at
# all
prov = self.aui_mgr.GetArtProvider()
# wxAUI darkens the gripper colour if it is too light. However, this
# looks ugly next to a toolbar.
prov.SetColour(wx.aui.AUI_DOCKART_GRIPPER_COLOUR,
wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DFACE))
if not config.use_system_inactive_caption_colour:
return
prov.SetMetric(aui.AUI_DOCKART_GRADIENT_TYPE,
aui.AUI_GRADIENT_HORIZONTAL)
inactive_caption_colour = wx.SystemSettings.GetColour(
wx.SYS_COLOUR_INACTIVECAPTION
)
inactive_caption_gradient_colour = wxAuiLightContrastColour(
inactive_caption_colour
)
inactive_caption_text_colour = wx.SystemSettings.GetColour(
wx.SYS_COLOUR_INACTIVECAPTIONTEXT
)
for setting, colour in (
(aui.AUI_DOCKART_INACTIVE_CAPTION_COLOUR, inactive_caption_colour),
(aui.AUI_DOCKART_INACTIVE_CAPTION_GRADIENT_COLOUR,
inactive_caption_gradient_colour),
(aui.AUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR,
inactive_caption_text_colour)
):
prov.SetColour(setting, colour)
def get_aui_items(self):
default_items = [
[self.version_tree, _("Books"), "Books", [], [["Left"],
["MinSize", [138, 50]],# self.version_tree.GetSize()],
["BestSize", [138, 50]],#self.version_tree.GetBestSize()]
]],
[self.bibletext.get_window(),
self.bibletext.title,
self.bibletext.id,
[["CloseButton", False]],
[["Centre"],
["Floatable", False]],
],
[self.commentarytext.get_window(),
self.commentarytext.title,
self.commentarytext.id,
[],
[["Right"],["Layer",2]]],
[self.dictionarytext.get_window(),
self.dictionarytext.title,
self.dictionarytext.id,
[],
[["Bottom"]]
],
[self.daily_devotional_frame.get_window(),
self.daily_devotional_frame.title,
self.daily_devotional_frame.id,
[],
[["Bottom"]]
],
[self.genbooktext.get_window(),
self.genbooktext.title,
self.genbooktext.id,
[],
[["Top"],
["Hide"]]
],
[self.harmony_frame.get_window(),
self.harmony_frame.title,
self.harmony_frame.id,
[],
[["Top"],
["Hide"]]
],
[self.preview_window.get_window(),
self.preview_window.title,
self.preview_window.id,
[],
[["Right"],
["Layer",2],
["Hide"]]],
[self.verse_compare.get_window(),
self.verse_compare.title,
self.verse_compare.id,
[], [
["Left"],
["Hide"]
]
],
[self.history_pane, _("History"), "History", [], [["Left"],
["Hide"]]
],
]
for item in self.searchers:
scrollsize = self.search_panel.BestSize
scrollsize2 = (630, 470)
#scrollsize[0] += 63
default_items.append([item, item.title, item.id, [], [
["Left"], ["Layer", 1],
["MinSize", scrollsize],
["BestSize", scrollsize2],
["FloatingSize", scrollsize2],
["Hide"],
["Float"],
["Dockable", False],
]])
return default_items
def set_aui_items_up(self):
if not guiconfig.use_one_toolbar:
self.ToolBar = None#self.main_toolbar
items = [
[self.version_tree, "Books",],
[self.bibletext.get_window(), "Bible", ["CloseButton", False]],
[self.commentarytext.get_window(), "Commentary",],
[self.dictionarytext.get_window(), "Dictionary"],
[self.daily_devotional_frame.get_window(), "Daily Devotional"],
[self.genbooktext.get_window(), "Other Books"],
[self.harmony_frame.get_window(), "Harmony"],
[self.verse_compare.get_window(), "Version Comparison"],
[self.history_pane, "History"],
[self.preview_window, "Preview",],
]
items.extend([item, item.title] for item in self.searchers)
panes = (
self.bibletext, self.commentarytext,
self.dictionarytext, self.genbooktext, self.verse_compare,
self.daily_devotional_frame, self.harmony_frame,
self.preview_window
)
self.panes = [(frame, frame.id) for frame in panes]
self.pane_titles = {}
for window, title, id, a1, a2 in self.get_aui_items():
self.pane_titles[title] = id
for item in self.toolbars:
self.pane_titles[_(item[1])] = item[1]
if util.i18n.langid in config_manager["BPBible"]["layout"]:
layout = config_manager["BPBible"]["layout"][util.i18n.langid]
self.create_items(self.get_aui_items(), use_startups=False)
if not guiconfig.use_one_toolbar:
self.create_toolbars(self.toolbars)
self.load_aui_perspective(layout["perspective"])
maximized = layout["maximized"]
if maximized:
pane = self.aui_mgr.GetPane(maximized)
assert pane.IsOk(), maximized
self.maximize_pane(pane)
else:
self.default_set_aui_items_up()
self.aui_mgr.Update()
def maximize_pane(self, pane):
self.fix_pane_direction(pane)
self.aui_mgr.MaximizePane(pane)
self.on_changed()
def get_pane_for_frame(self, frame):
for f, pane_name in self.panes:
if f == frame:
pane = self.aui_mgr.GetPane(pane_name)
assert pane.IsOk(), pane_name
return pane
def get_frame_for_pane(self, pane):
for f, pane_name in self.panes:
if pane.name == pane_name:
return f
def get_selected_frame(self):
for f, pane_name in self.panes:
pane = self.aui_mgr.GetPane(pane_name)
assert pane.IsOk(), pane_name
active = bool(pane.state & pane.optionActive)
if active:
return f
def create_items(self, items, use_startups=True):
for frame, title, name, always_items, startup_items in items:
defaults = "CaptionVisible MaximizeButton Movable Floatable " \
"MinimizeButton"
items = [[j] for j in defaults.split()]
items += always_items
if use_startups:
items +=startup_items
info = aui.AuiPaneInfo().BestSize((300, 300)) \
.Name(name).Caption(title).MinimizeButton(True).Layer(0)
for attr in items:
getattr(info, attr[0])(*attr[1:])
self.aui_mgr.AddPane(frame, info)
def create_toolbars(self, toolbars):
for item in toolbars:
defaults = "Top"
item = item[:]
item[2:] = [[j] for j in defaults.split()] + item[2:]
info = aui.AuiPaneInfo()\
.Name(item[1]).Caption(_(item[1])).Row(0).ToolbarPane().\
LeftDockable(False).RightDockable(False)
for attr in item[2:]:
getattr(info, attr[0])(*attr[1:])
self.aui_mgr.AddPane(item[0], info)
def bind_events(self):
self.aui_mgr.Bind(aui.EVT_AUI_PANE_CLOSE, self.on_pane_close)
self.aui_mgr.Bind(aui.EVT_AUI_PANE_RESTORE, self.on_pane_restore)
self.aui_mgr.Bind(aui.EVT_AUI_PANE_MAXIMIZE, self.on_pane_maximize)
self.aui_mgr.Bind(wx.EVT_MOTION, self.on_motion)
self.aui_mgr.Bind(wx.EVT_LEFT_DOWN, self.on_left_down)
self.aui_mgr.Bind(wx.EVT_LEFT_DCLICK, self.on_left_dclick)
self.aui_mgr.Bind(wx.EVT_LEAVE_WINDOW, self.on_leave_window)
def on_leave_window(self, event):
self.clear_over_list()
event.Skip()
def on_left_dclick(self, event):
maximized_pane = self.get_maximized_pane()
for name, (pane, rect) in caption_sizes.items():
if rect.Contains(event.Position) and self.pane_can_be_seen(pane):
if maximized_pane:
assert maximized_pane.name == name, "Wrong maximized pane"
self.restore_maximized_pane(pane)
else:
self.maximize_pane(pane)
self.aui_mgr.Update()
wx.CallAfter(self.update_all_aui_menu_items)
break
else:
event.Skip()
def on_left_down(self, event):
#TODO: don't popup on maximize button or close button click
if mouse_over:
self.popup(event)
else:
event.Skip()
def popup(self, event):
assert(len(mouse_over)) == 1, "Only one thing can have mouse over"
name, (pane, rect, title, clipping_rect) = mouse_over.items()[0]
if not self.pane_can_be_seen(pane):
event.Skip()
return
frames = [frame for frame, f_title in self.panes if f_title == name]
assert len(frames) == 1, "Wrong frame count: %s (%r)" % (name, frames)
frame = frames[0]
keytext = frame.reference
if not isinstance(keytext, basestring):
keytext = keytext.text
# find the intersection of the clipping rect and the actual rect
# this will be the actual rectangle the user can see.
r = wx.RectPP(
(
max(rect[0], clipping_rect[0]),
max(rect[1], clipping_rect[1]),
),
(
min(rect.Right, clipping_rect.Right),
min(rect.Bottom, clipping_rect.Bottom),
)
)
p = ModulePopup(self, event, r, frame.book, keytext)
# use the main frame to grab the mouse wheel events, as wxPopupWindow
# cannot have focus, nor any of its children
# This isn't needed under gtk, as the scroll wheel will automatically
# select the window underneath for scrolling
if osutils.is_msw():
self.SetFocus()
self.Bind(wx.EVT_MOUSEWHEEL, p.box.on_mouse_wheel)
def on_dismiss(chosen):
if not r.Contains(
self.ScreenToClient(wx.GetMousePosition())
):
self.clear_over_list()
if chosen is not None:
frame.book.SetModule(p.box.modules[chosen])
if osutils.is_msw():
self.Unbind(wx.EVT_MOUSEWHEEL)
wx.CallAfter(p.Destroy)
p.on_dismiss += on_dismiss
p.Popup()
def clear_over_list(self):
old_mouse_over = mouse_over.items()
mouse_over.clear()
for key, (pane, rect, title, clipping_rect) in old_mouse_over:
self.repaint_combo(key, rect, title, clipping_rect)
def pane_can_be_seen(self, pane):
maximized_pane = self.get_maximized_pane()
return (pane.IsShown() and not pane.IsFloating() and (
not maximized_pane or repr(maximized_pane) == repr(pane)))
def repaint_combo(self, key, rect, title, clipping_rect):
pane = self.aui_mgr.GetPane(key)
if not self.pane_can_be_seen(pane):
return False
dc = wx.ClientDC(self)
dc.SetClippingRegion(*clipping_rect)
self.dockart.draw_combo(dc, self, rect, title, pane, clipping_rect)
dc.DestroyClippingRegion()
return True
def on_motion(self, event):
self.clear_over_list()
pos = (event.X, event.Y)
for key, (pane, backing_rect,
title, clipping_rect) in size_taken.items():
if backing_rect.Contains(pos) and clipping_rect.Contains(pos):
mouse_over[key] = pane, backing_rect, title, clipping_rect
if self.repaint_combo(key, backing_rect, title, clipping_rect):
return
event.Skip()
def show_toolbar_popup(self, event):
if self.aui_uses_provider:
for item in self.rects:
if item.Contains(event.Position):
break
else:
return
event.EventObject.PopupMenu(self.toolbar_menu,
guiutil.get_mouse_pos(event.EventObject))
def get_maximized_pane(self):
for pane in self.aui_mgr.GetAllPanes():
if pane.IsMaximized():
return pane
@guiutil.frozen
def load_default_perspective(self, event):
maximized = self.get_maximized_pane()
if maximized:
self.restore_maximized_pane(maximized)
for item in self.aui_mgr.AllPanes:
self.aui_mgr.DetachPane(item.window)
self.default_set_aui_items_up()
self.aui_mgr.Update()
self.on_changed()
def load_aui_perspective(self, perspective):
aui_items = self.get_aui_items()
def get_caption(match):
n = match.group(2)
for frame, caption, name, dummy, dummy in aui_items:
if name == n:
break
else:
for item in self.toolbars:
if item[1] == n:
caption = _(item[1])
break
else:
dprint(WARNING, "Couldn't find caption by name", n)
return match.group(0)
return match.group(1) + caption + ";"
# strip out the captions and replace with the proper i18n'ed caption
perspective = re.sub("(name=([^;]*);caption=)[^;]*;",
get_caption, perspective)
self.aui_mgr.LoadPerspective(perspective)
# If a pane doesn't exist in this perspective, we need to set it up
# now
for frame, caption, name, always, setup in aui_items:
if re.search("name=%s;" % name, perspective):
continue
pane = self.aui_mgr.GetPane(name)
assert pane.IsOk()
for item in always + setup:
getattr(pane, item[0])(*item[1:])
wx.CallAfter(self.on_changed)
def on_changed(self):
for pane in self.aui_mgr.GetAllPanes():
if pane.IsShown():
if pane.name in self.aui_callbacks:
# only give an event if we need to - if we were already
# showing, this will have been set to false in
# update_all_aui_menu_items
if self.needs_showing_event.get(pane.name, True):
self.aui_callbacks[pane.name](True)
wx.CallAfter(self.update_all_aui_menu_items)
def show_panel(self, panel, toggle=True):
pane = self.aui_mgr.GetPane(panel)
maximized = self.get_maximized_pane()
if maximized and not pane.IsToolbar() and not pane.IsFloating():
self.restore_maximized_pane(maximized)
assert pane.IsOk(), panel
changed = not (toggle and not maximized and pane.IsShown())
if changed:
pane.Show(toggle)
self.aui_mgr.Update()
if panel in self.aui_callbacks:
self.aui_callbacks[panel](toggle)
if changed:
self.on_pane_changed(panel, toggle)
def restore_maximized_pane(self, pane):
self.restore_pane_direction(pane)
self.pane_restore_hack()
self.aui_mgr.RestoreMaximizedPane()
self.on_changed()
def on_pane_changed(self, pane_name, toggle):
wx.CallAfter(self.update_all_aui_menu_items)
for item in self.windows_menu.MenuItems:
if item.Label == pane_name:
item.Check(toggle)
def update_all_aui_menu_items(self):
menus = self.windows_menu, self.toolbar_menu
for menu in menus:
for item in reversed(menu.MenuItems):
if item.IsSeparator():
break
pane = self.aui_mgr.GetPane(self.pane_titles[item.Label])
assert pane.IsOk(), item.Label
item.Check(pane.IsShown())
self.needs_showing_event[pane.name] = not pane.IsShown()
def pane_restore_hack(self):
for item in reversed(self.windows_menu.MenuItems):
if item.IsSeparator():
break
pane = self.aui_mgr.GetPane(self.pane_titles[item.Label])
assert pane.IsOk(), item.Label
### HACK around http://trac.wxwidgets.org/ticket/11385
# set the saved hidden state to whether it was shown,
# otherwise it will show them regardless
if pane.IsFloating():
pane.SetFlag(pane.savedHiddenState, not pane.IsShown())
def on_pane_restore(self, event):
self.pane_restore_hack()
pane = event.GetPane()
self.restore_pane_direction(pane)
wx.CallAfter(self.on_changed)
def fix_pane_direction(self, pane):
self.maximized_pane_direction = pane.dock_direction
pane.Right()
def restore_pane_direction(self, pane):
if self.maximized_pane_direction:
pane.dock_direction = self.maximized_pane_direction
self.maximized_pane_direction = None
def on_pane_maximize(self, event):
# workaround maximization bug - move the pane to the right before
# maximizing, then back afterwards
pane = event.GetPane()
self.fix_pane_direction(pane)
wx.CallAfter(self.on_changed)
def on_pane_close(self, event):
self.event = event
self.on_pane_changed(event.pane.name, False)
def save_layout(self):
maximized = self.get_maximized_pane()
maximized_name = None
if maximized:
maximized_name = maximized.name
self.restore_maximized_pane(maximized)
data = dict(perspective=self.aui_mgr.SavePerspective(),
maximized=maximized_name)
return data
def on_aui_render(self, event):
self.rects = []
self.on_render()
event.Skip()
def set_pane_title(self, panename, text):
pane = self.aui_mgr.GetPane(panename)
assert pane.IsOk()
pane.Caption(text)
if pane.IsFloating():
parent = guiutil.toplevel_parent(pane.window)
assert parent, "Top level parent of window not found!!!"
parent.Title = text
self.aui_mgr.Update()
def is_pane_shown(self, panename):
pane = self.aui_mgr.GetPane(panename)
assert pane.IsOk()
return pane.IsShown()
def default_set_aui_items_up(self):
"""Code used to generate perspective"""
self.create_items(self.get_aui_items())
if not guiconfig.use_one_toolbar: self.create_toolbars(self.toolbars)