forked from wxWidgets/Phoenix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDynamicSashWindow.py
177 lines (142 loc) · 6.58 KB
/
DynamicSashWindow.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
#!/usr/bin/env python
import wx
import wx.lib.gizmos as gizmos # Formerly wx.gizmos in Classic
import wx.stc as stc
#----------------------------------------------------------------------
# This is an example of the complex view that manages its own scrollbars
# as described in the overview below.
class TestView(stc.StyledTextCtrl):
def __init__(self, parent, ID, log):
#super(TestView, self).__init__() # Test 2-phase
#self.Create(parent, ID, style=wx.NO_BORDER)
super(TestView, self).__init__(parent, ID, style=wx.NO_BORDER) # or 1-phase
self.dyn_sash = parent
self.log = log
self.SetupScrollBars()
self.SetMarginWidth(1,0)
self.StyleSetFont(stc.STC_STYLE_DEFAULT,
wx.Font(12, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.Bind(gizmos.EVT_DYNAMIC_SASH_SPLIT, self.OnSplit)
self.Bind(gizmos.EVT_DYNAMIC_SASH_UNIFY, self.OnUnify)
#self.SetScrollWidth(500)
def SetupScrollBars(self):
# hook the scrollbars provided by the wxDynamicSashWindow
# to this view
v_bar = self.dyn_sash.GetVScrollBar(self)
h_bar = self.dyn_sash.GetHScrollBar(self)
v_bar.Bind(wx.EVT_SCROLL, self.OnSBScroll)
h_bar.Bind(wx.EVT_SCROLL, self.OnSBScroll)
v_bar.Bind(wx.EVT_SET_FOCUS, self.OnSBFocus)
h_bar.Bind(wx.EVT_SET_FOCUS, self.OnSBFocus)
# And set the wxStyledText to use these scrollbars instead
# of its built-in ones.
self.SetVScrollBar(v_bar)
self.SetHScrollBar(h_bar)
def OnSplit(self, evt):
self.log.write("TestView.OnSplit\n")
newview = TestView(self.dyn_sash, -1, self.log)
newview.SetDocPointer(self.GetDocPointer()) # use the same document
self.SetupScrollBars()
def OnUnify(self, evt):
self.log.write("TestView.OnUnify\n")
self.SetupScrollBars()
def OnSBScroll(self, evt):
# redirect the scroll events from the dyn_sash's scrollbars to the STC
self.GetEventHandler().ProcessEvent(evt)
def OnSBFocus(self, evt):
# when the scrollbar gets the focus move it back to the STC
self.SetFocus()
sampleText="""\
You can drag the little tabs above the vertical scrollbar, or to the
left of the horizontal scrollbar to split this view, and you can
continue splitting the new views as much as you like. Try it and see.
In this case the views also share the same document so changes in one
are instantly seen in the others. This is a feature of the
StyledTextCtrl that is used for the view class in this sample.
"""
#----------------------------------------------------------------------
# This one is simpler, but doesn't do anything with the scrollbars
# except the default wxDynamicSashWindow behaviour
class SimpleView(wx.Panel):
count = 0
def __init__(self, parent, ID, log):
#wx.Panel.__init__(self) # 2-phase create
#self.Create(parent, ID)
super(SimpleView, self).__init__(parent, ID) # 1-phase
self.dyn_sash = parent
self.log = log
self.SetBackgroundColour("LIGHT BLUE")
self.Bind(gizmos.EVT_DYNAMIC_SASH_SPLIT, self.OnSplit)
self.Bind(gizmos.EVT_DYNAMIC_SASH_UNIFY, self.OnUnify)
SimpleView.count += 1
st = wx.StaticText(self, label=str(SimpleView.count), pos=(15,15))
font = st.GetFont()
st.SetFont(font.Bold().Scaled(2.0))
def OnSplit(self, evt):
self.log.write("SimpleView.OnSplit\n")
newview = SimpleView(self.dyn_sash, -1, self.log)
# It's automatically added to the proper place in the sash window
def OnUnify(self, evt):
self.log.write("SimpleView.OnUnify\n")
#----------------------------------------------------------------------
def runTest(frame, nb, log):
if True:
win = gizmos.DynamicSashWindow(nb, -1, style=0
#| gizmos.DS_MANAGE_SCROLLBARS
| gizmos.DS_DRAG_CORNER
)
view = TestView(win, -1, log)
view.SetText(sampleText)
else:
win = gizmos.DynamicSashWindow(nb, -1)
view = SimpleView(win, -1, log)
return win
#----------------------------------------------------------------------
overview = """\
<html><body>
<h2>DynamicSashWindow</h2>
<p>
wxDynamicSashWindow widgets manages the way other widgets are viewed.
When a wxDynamicSashWindow is first shown, it will contain one child
view, a viewport for that child, and a pair of scrollbars to allow the
user to navigate the child view area. Next to each scrollbar is a small
tab. By clicking on either tab and dragging to the appropriate spot, a
user can split the view area into two smaller views separated by a
draggable sash. Later, when the user wishes to reunify the two subviews,
the user simply drags the sash to the side of the window.
wxDynamicSashWindow will automatically reparent the appropriate child
view back up the window hierarchy, and the wxDynamicSashWindow will have
only one child view once again.
<p>
As an application developer, you will simply create a wxDynamicSashWindow
using either the Create() function or the more complex constructor
provided below, and then create a view window whose parent is the
wxDynamicSashWindow. The child should respond to
wxDynamicSashSplitEvents -- perhaps with an OnSplit() event handler -- by
constructing a new view window whose parent is also the
wxDynamicSashWindow. That's it! Now your users can dynamically split
and reunify the view you provided.
<p>
If you wish to handle the scrollbar events for your view, rather than
allowing wxDynamicSashWindow to do it for you, things are a bit more
complex. (You might want to handle scrollbar events yourself, if,
for instance, you wish to scroll a subwindow of the view you add to
your wxDynamicSashWindow object, rather than scrolling the whole view.)
In this case, you will need to construct your wxDynamicSashWindow without
the wxDS_MANAGE_SCROLLBARS style and you will need to use the
GetHScrollBar() and GetVScrollBar() methods to retrieve the scrollbar
controls and call SetEventHanler() on them to redirect the scrolling
events whenever your window is reparented by wxDyanmicSashWindow.
You will need to set the scrollbars' event handler at three times:
<p>
<ul>
<li> When your view is created
<li> When your view receives a wxDynamicSashSplitEvent
<li> When your view receives a wxDynamicSashUnifyEvent
</ul>
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])