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