]>
Commit | Line | Data |
---|---|---|
8fa876ca RD |
1 | # 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
2 | # | |
3 | # o Updated for wx namespace | |
4 | # | |
ebf4302c | 5 | |
8fa876ca RD |
6 | import wx |
7 | import wx.gizmos as gizmos | |
8 | import wx.stc as stc | |
ebf4302c RD |
9 | |
10 | #---------------------------------------------------------------------- | |
11 | # This is an example of the complex view that manages its own scrollbars | |
12 | # as described in the overview below. | |
13 | ||
8fa876ca | 14 | class TestView(stc.StyledTextCtrl): |
ebf4302c | 15 | def __init__(self, parent, ID, log): |
8fa876ca | 16 | stc.StyledTextCtrl.__init__(self, parent, ID, style=wx.NO_BORDER) |
ebf4302c RD |
17 | self.dyn_sash = parent |
18 | self.log = log | |
6e8a778a | 19 | self.SetupScrollBars() |
ebf4302c | 20 | self.SetMarginWidth(1,0) |
8fa876ca RD |
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) | |
a834585d | 27 | #self.SetScrollWidth(500) |
ebf4302c RD |
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) | |
8fa876ca RD |
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) | |
ebf4302c RD |
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 | ||
69 | sampleText="""\ | |
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. | |
73 | ||
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 | |
8fa876ca | 76 | StyledTextCtrl that is used for the view class in this sample. |
ebf4302c RD |
77 | """ |
78 | ||
79 | #---------------------------------------------------------------------- | |
80 | # This one is simpler, but doesn't do anything with the scrollbars | |
81 | # except the default wxDynamicSashWindow behaviour | |
82 | ||
8fa876ca | 83 | class SimpleView(wx.Panel): |
ebf4302c | 84 | def __init__(self, parent, ID, log): |
8fa876ca | 85 | wx.Panel.__init__(self, parent, ID) |
ebf4302c RD |
86 | self.dyn_sash = parent |
87 | self.log = log | |
88 | self.SetBackgroundColour("LIGHT BLUE") | |
8fa876ca | 89 | self.Bind(gizmos.EVT_DYNAMIC_SASH_SPLIT, self.OnSplit) |
ebf4302c RD |
90 | |
91 | def OnSplit(self, evt): | |
92 | v = SimpleView(self.dyn_sash, -1, self.log) | |
93 | ||
94 | ||
95 | #---------------------------------------------------------------------- | |
96 | ||
97 | def runTest(frame, nb, log): | |
8fa876ca RD |
98 | if wx.Platform == "__WXMAC__": |
99 | wx.MessageBox("This demo currently fails on the Mac. The problem is being looked into...", "Sorry") | |
1e4a197e RD |
100 | return |
101 | ||
ebf4302c | 102 | if 1: |
8fa876ca | 103 | win = gizmos.DynamicSashWindow(nb, -1, style = wx.CLIP_CHILDREN |
ebf4302c RD |
104 | #| wxDS_MANAGE_SCROLLBARS |
105 | #| wxDS_DRAG_CORNER | |
106 | ) | |
8fa876ca RD |
107 | |
108 | win.SetFont(wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL)) | |
ebf4302c RD |
109 | view = TestView(win, -1, log) |
110 | view.SetText(sampleText) | |
111 | else: | |
8fa876ca | 112 | win = wx.DynamicSashWindow(nb, -1) |
ebf4302c RD |
113 | view = SimpleView(win, -1, log) |
114 | return win | |
115 | ||
116 | #---------------------------------------------------------------------- | |
117 | ||
118 | overview = """\ | |
119 | <html><body> | |
8fa876ca | 120 | <h2>DynamicSashWindow</h2> |
ebf4302c RD |
121 | <p> |
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. | |
133 | <p> | |
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. | |
142 | <p> | |
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: | |
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 | """ | |
1e4a197e RD |
162 | |
163 | ||
164 | if __name__ == '__main__': | |
165 | import sys,os | |
166 | import run | |
167 | run.main(['', os.path.basename(sys.argv[0])]) | |
168 |