]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/DynamicSashWindow.py
1 # 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
7 import wx
.gizmos
as gizmos
10 #----------------------------------------------------------------------
11 # This is an example of the complex view that manages its own scrollbars
12 # as described in the overview below.
14 class TestView(stc
.StyledTextCtrl
):
15 def __init__(self
, parent
, ID
, log
):
16 stc
.StyledTextCtrl
.__init
__(self
, parent
, ID
, style
=wx
.NO_BORDER
)
17 self
.dyn_sash
= parent
19 self
.SetupScrollBars()
20 self
.SetMarginWidth(1,0)
22 self
.StyleSetFont(stc
.STC_STYLE_DEFAULT
,
23 wx
.Font(10, wx
.MODERN
, wx
.NORMAL
, wx
.NORMAL
))
25 self
.Bind(gizmos
.EVT_DYNAMIC_SASH_SPLIT
, self
.OnSplit
)
26 self
.Bind(gizmos
.EVT_DYNAMIC_SASH_UNIFY
, self
.OnUnify
)
27 #self.SetScrollWidth(500)
29 def SetupScrollBars(self
):
30 # hook the scrollbars provided by the wxDynamicSashWindow
32 v_bar
= self
.dyn_sash
.GetVScrollBar(self
)
33 h_bar
= self
.dyn_sash
.GetHScrollBar(self
)
34 v_bar
.Bind(wx
.EVT_SCROLL
, self
.OnSBScroll
)
35 h_bar
.Bind(wx
.EVT_SCROLL
, self
.OnSBScroll
)
36 v_bar
.Bind(wx
.EVT_SET_FOCUS
, self
.OnSBFocus
)
37 h_bar
.Bind(wx
.EVT_SET_FOCUS
, self
.OnSBFocus
)
39 # And set the wxStyledText to use these scrollbars instead
40 # of its built-in ones.
41 self
.SetVScrollBar(v_bar
)
42 self
.SetHScrollBar(h_bar
)
46 self
.log
.write("TestView.__del__\n")
48 def OnSplit(self
, evt
):
49 self
.log
.write("TestView.OnSplit\n");
50 newview
= TestView(self
.dyn_sash
, -1, self
.log
)
51 newview
.SetDocPointer(self
.GetDocPointer()) # use the same document
52 self
.SetupScrollBars()
55 def OnUnify(self
, evt
):
56 self
.log
.write("TestView.OnUnify\n");
57 self
.SetupScrollBars()
60 def OnSBScroll(self
, evt
):
61 # redirect the scroll events from the dyn_sash's scrollbars to the STC
62 self
.GetEventHandler().ProcessEvent(evt
)
64 def OnSBFocus(self
, evt
):
65 # when the scrollbar gets the focus move it back to the STC
70 You can drag the little tabs above the vertical scrollbar, or to the
71 left of the horizontal scrollbar to split this view, and you can
72 continue splitting the new views as much as you like. Try it and see.
74 In this case the views also share the same document so changes in one
75 are instantly seen in the others. This is a feature of the
76 StyledTextCtrl that is used for the view class in this sample.
79 #----------------------------------------------------------------------
80 # This one is simpler, but doesn't do anything with the scrollbars
81 # except the default wxDynamicSashWindow behaviour
83 class SimpleView(wx
.Panel
):
84 def __init__(self
, parent
, ID
, log
):
85 wx
.Panel
.__init
__(self
, parent
, ID
)
86 self
.dyn_sash
= parent
88 self
.SetBackgroundColour("LIGHT BLUE")
89 self
.Bind(gizmos
.EVT_DYNAMIC_SASH_SPLIT
, self
.OnSplit
)
91 def OnSplit(self
, evt
):
92 v
= SimpleView(self
.dyn_sash
, -1, self
.log
)
95 #----------------------------------------------------------------------
97 def runTest(frame
, nb
, log
):
98 if wx
.Platform
== "__WXMAC__":
99 wx
.MessageBox("This demo currently fails on the Mac. The problem is being looked into...", "Sorry")
103 win
= gizmos
.DynamicSashWindow(nb
, -1, style
= wx
.CLIP_CHILDREN
104 #| wxDS_MANAGE_SCROLLBARS
108 win
.SetFont(wx
.Font(10, wx
.MODERN
, wx
.NORMAL
, wx
.NORMAL
))
109 view
= TestView(win
, -1, log
)
110 view
.SetText(sampleText
)
112 win
= wx
.DynamicSashWindow(nb
, -1)
113 view
= SimpleView(win
, -1, log
)
116 #----------------------------------------------------------------------
120 <h2>DynamicSashWindow</h2>
122 wxDynamicSashWindow widgets manages the way other widgets are viewed.
123 When a wxDynamicSashWindow is first shown, it will contain one child
124 view, a viewport for that child, and a pair of scrollbars to allow the
125 user to navigate the child view area. Next to each scrollbar is a small
126 tab. By clicking on either tab and dragging to the appropriate spot, a
127 user can split the view area into two smaller views separated by a
128 draggable sash. Later, when the user wishes to reunify the two subviews,
129 the user simply drags the sash to the side of the window.
130 wxDynamicSashWindow will automatically reparent the appropriate child
131 view back up the window hierarchy, and the wxDynamicSashWindow will have
132 only one child view once again.
134 As an application developer, you will simply create a wxDynamicSashWindow
135 using either the Create() function or the more complex constructor
136 provided below, and then create a view window whose parent is the
137 wxDynamicSashWindow. The child should respond to
138 wxDynamicSashSplitEvents -- perhaps with an OnSplit() event handler -- by
139 constructing a new view window whose parent is also the
140 wxDynamicSashWindow. That's it! Now your users can dynamically split
141 and reunify the view you provided.
143 If you wish to handle the scrollbar events for your view, rather than
144 allowing wxDynamicSashWindow to do it for you, things are a bit more
145 complex. (You might want to handle scrollbar events yourself, if,
146 for instance, you wish to scroll a subwindow of the view you add to
147 your wxDynamicSashWindow object, rather than scrolling the whole view.)
148 In this case, you will need to construct your wxDynamicSashWindow without
149 the wxDS_MANAGE_SCROLLBARS style and you will need to use the
150 GetHScrollBar() and GetVScrollBar() methods to retrieve the scrollbar
151 controls and call SetEventHanler() on them to redirect the scrolling
152 events whenever your window is reparented by wxDyanmicSashWindow.
153 You will need to set the scrollbars' event handler at three times:
156 <li> When your view is created
157 <li> When your view receives a wxDynamicSashSplitEvent
158 <li> When your view receives a wxDynamicSashUnifyEvent
164 if __name__
== '__main__':
167 run
.main(['', os
.path
.basename(sys
.argv
[0])])