]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/wxDynamicSashWindow.py
reSWIGged
[wxWidgets.git] / wxPython / demo / wxDynamicSashWindow.py
... / ...
CommitLineData
1# 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Updated for wx namespace
4#
5
6import wx
7import wx.gizmos as gizmos
8import wx.stc as stc
9
10#----------------------------------------------------------------------
11# This is an example of the complex view that manages its own scrollbars
12# as described in the overview below.
13
14class 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
18 self.log = log
19 self.SetupScrollBars()
20 self.SetMarginWidth(1,0)
21
22 self.StyleSetFont(stc.STC_STYLE_DEFAULT,
23 wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL))
24
25 self.Bind(gizmos.EVT_DYNAMIC_SASH_SPLIT, self.OnSplit)
26 self.Bind(gizmos.EVT_DYNAMIC_SASH_UNIFY, self.OnUnify)
27 #self.SetScrollWidth(500)
28
29 def SetupScrollBars(self):
30 # hook the scrollbars provided by the wxDynamicSashWindow
31 # to this view
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)
38
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)
43
44
45 def __del__(self):
46 self.log.write("TestView.__del__\n")
47
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()
53
54
55 def OnUnify(self, evt):
56 self.log.write("TestView.OnUnify\n");
57 self.SetupScrollBars()
58
59
60 def OnSBScroll(self, evt):
61 # redirect the scroll events from the dyn_sash's scrollbars to the STC
62 self.GetEventHandler().ProcessEvent(evt)
63
64 def OnSBFocus(self, evt):
65 # when the scrollbar gets the focus move it back to the STC
66 self.SetFocus()
67
68
69sampleText="""\
70You can drag the little tabs above the vertical scrollbar, or to the
71left of the horizontal scrollbar to split this view, and you can
72continue splitting the new views as much as you like. Try it and see.
73
74In this case the views also share the same document so changes in one
75are instantly seen in the others. This is a feature of the
76StyledTextCtrl that is used for the view class in this sample.
77"""
78
79#----------------------------------------------------------------------
80# This one is simpler, but doesn't do anything with the scrollbars
81# except the default wxDynamicSashWindow behaviour
82
83class SimpleView(wx.Panel):
84 def __init__(self, parent, ID, log):
85 wx.Panel.__init__(self, parent, ID)
86 self.dyn_sash = parent
87 self.log = log
88 self.SetBackgroundColour("LIGHT BLUE")
89 self.Bind(gizmos.EVT_DYNAMIC_SASH_SPLIT, self.OnSplit)
90
91 def OnSplit(self, evt):
92 v = SimpleView(self.dyn_sash, -1, self.log)
93
94
95#----------------------------------------------------------------------
96
97def 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")
100 return
101
102 if 1:
103 win = gizmos.DynamicSashWindow(nb, -1, style = wx.CLIP_CHILDREN
104 #| wxDS_MANAGE_SCROLLBARS
105 #| wxDS_DRAG_CORNER
106 )
107
108 win.SetFont(wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL))
109 view = TestView(win, -1, log)
110 view.SetText(sampleText)
111 else:
112 win = wx.DynamicSashWindow(nb, -1)
113 view = SimpleView(win, -1, log)
114 return win
115
116#----------------------------------------------------------------------
117
118overview = """\
119<html><body>
120<h2>DynamicSashWindow</h2>
121<p>
122wxDynamicSashWindow widgets manages the way other widgets are viewed.
123When a wxDynamicSashWindow is first shown, it will contain one child
124view, a viewport for that child, and a pair of scrollbars to allow the
125user to navigate the child view area. Next to each scrollbar is a small
126tab. By clicking on either tab and dragging to the appropriate spot, a
127user can split the view area into two smaller views separated by a
128draggable sash. Later, when the user wishes to reunify the two subviews,
129the user simply drags the sash to the side of the window.
130wxDynamicSashWindow will automatically reparent the appropriate child
131view back up the window hierarchy, and the wxDynamicSashWindow will have
132only one child view once again.
133<p>
134As an application developer, you will simply create a wxDynamicSashWindow
135using either the Create() function or the more complex constructor
136provided below, and then create a view window whose parent is the
137wxDynamicSashWindow. The child should respond to
138wxDynamicSashSplitEvents -- perhaps with an OnSplit() event handler -- by
139constructing a new view window whose parent is also the
140wxDynamicSashWindow. That's it! Now your users can dynamically split
141and reunify the view you provided.
142<p>
143If you wish to handle the scrollbar events for your view, rather than
144allowing wxDynamicSashWindow to do it for you, things are a bit more
145complex. (You might want to handle scrollbar events yourself, if,
146for instance, you wish to scroll a subwindow of the view you add to
147your wxDynamicSashWindow object, rather than scrolling the whole view.)
148In this case, you will need to construct your wxDynamicSashWindow without
149the wxDS_MANAGE_SCROLLBARS style and you will need to use the
150GetHScrollBar() and GetVScrollBar() methods to retrieve the scrollbar
151controls and call SetEventHanler() on them to redirect the scrolling
152events whenever your window is reparented by wxDyanmicSashWindow.
153You will need to set the scrollbars' event handler at three times:
154<p>
155<ul>
156<li> When your view is created
157<li> When your view receives a wxDynamicSashSplitEvent
158<li> When your view receives a wxDynamicSashUnifyEvent
159</ul>
160</body></html>
161"""
162
163
164if __name__ == '__main__':
165 import sys,os
166 import run
167 run.main(['', os.path.basename(sys.argv[0])])
168