]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxDynamicSashWindow.py
   2 from wxPython
.wx 
import * 
   3 from wxPython
.gizmos 
import * 
   4 from wxPython
.stc 
import * 
   6 #---------------------------------------------------------------------- 
   7 # This is an example of the complex view that manages its own scrollbars 
   8 # as described in the overview below. 
  10 class TestView(wxStyledTextCtrl
): 
  11     def __init__(self
, parent
, ID
, log
): 
  12         wxStyledTextCtrl
.__init
__(self
, parent
, ID
, style
=wxNO_BORDER
) 
  13         self
.dyn_sash 
= parent
 
  15         self
.SetupScrollBars() 
  16         self
.SetMarginWidth(1,0) 
  17         self
.StyleSetFont(wxSTC_STYLE_DEFAULT
, 
  18                           wxFont(10, wxMODERN
, wxNORMAL
, wxNORMAL
)) 
  19         EVT_DYNAMIC_SASH_SPLIT(self
, -1, self
.OnSplit
) 
  20         EVT_DYNAMIC_SASH_UNIFY(self
, -1, self
.OnUnify
) 
  21         #self.SetScrollWidth(500) 
  23     def SetupScrollBars(self
): 
  24         # hook the scrollbars provided by the wxDynamicSashWindow 
  26         v_bar 
= self
.dyn_sash
.GetVScrollBar(self
) 
  27         h_bar 
= self
.dyn_sash
.GetHScrollBar(self
) 
  28         EVT_SCROLL(v_bar
, self
.OnSBScroll
) 
  29         EVT_SCROLL(h_bar
, self
.OnSBScroll
) 
  30         EVT_SET_FOCUS(v_bar
, self
.OnSBFocus
) 
  31         EVT_SET_FOCUS(h_bar
, self
.OnSBFocus
) 
  33         # And set the wxStyledText to use these scrollbars instead 
  34         # of its built-in ones. 
  35         self
.SetVScrollBar(v_bar
) 
  36         self
.SetHScrollBar(h_bar
) 
  40         self
.log
.write("TestView.__del__\n") 
  42     def OnSplit(self
, evt
): 
  43         self
.log
.write("TestView.OnSplit\n"); 
  44         newview 
= TestView(self
.dyn_sash
, -1, self
.log
) 
  45         newview
.SetDocPointer(self
.GetDocPointer())     # use the same document 
  46         self
.SetupScrollBars() 
  49     def OnUnify(self
, evt
): 
  50         self
.log
.write("TestView.OnUnify\n"); 
  51         self
.SetupScrollBars() 
  54     def OnSBScroll(self
, evt
): 
  55         # redirect the scroll events from the dyn_sash's scrollbars to the STC 
  56         self
.GetEventHandler().ProcessEvent(evt
) 
  58     def OnSBFocus(self
, evt
): 
  59         # when the scrollbar gets the focus move it back to the STC 
  64 You can drag the little tabs above the vertical scrollbar, or to the 
  65 left of the horizontal scrollbar to split this view, and you can 
  66 continue splitting the new views as much as you like.  Try it and see. 
  68 In this case the views also share the same document so changes in one 
  69 are instantly seen in the others.  This is a feature of the 
  70 wxStyledTextCtrl that is used for the view class in this sample. 
  73 #---------------------------------------------------------------------- 
  74 # This one is simpler, but doesn't do anything with the scrollbars 
  75 # except the default wxDynamicSashWindow behaviour 
  77 class SimpleView(wxPanel
): 
  78     def __init__(self
, parent
, ID
, log
): 
  79         wxPanel
.__init
__(self
, parent
, ID
) 
  80         self
.dyn_sash 
= parent
 
  82         self
.SetBackgroundColour("LIGHT BLUE") 
  83         EVT_DYNAMIC_SASH_SPLIT(self
, -1, self
.OnSplit
) 
  85     def OnSplit(self
, evt
): 
  86         v 
= SimpleView(self
.dyn_sash
, -1, self
.log
) 
  89 #---------------------------------------------------------------------- 
  91 def runTest(frame
, nb
, log
): 
  93         win 
= wxDynamicSashWindow(nb
, -1, style 
= 0 
  95                                   #| wxDS_MANAGE_SCROLLBARS 
  98         win
.SetFont(wxFont(10, wxMODERN
, wxNORMAL
, wxNORMAL
)) 
  99         view 
= TestView(win
, -1, log
) 
 100         view
.SetText(sampleText
) 
 102         win 
= wxDynamicSashWindow(nb
, -1) 
 103         view 
= SimpleView(win
, -1, log
) 
 106 #---------------------------------------------------------------------- 
 110 <h2>wxDynamicSashWindow</h2> 
 112 wxDynamicSashWindow widgets manages the way other widgets are viewed. 
 113 When a wxDynamicSashWindow is first shown, it will contain one child 
 114 view, a viewport for that child, and a pair of scrollbars to allow the 
 115 user to navigate the child view area.  Next to each scrollbar is a small 
 116 tab.  By clicking on either tab and dragging to the appropriate spot, a 
 117 user can split the view area into two smaller views separated by a 
 118 draggable sash.  Later, when the user wishes to reunify the two subviews, 
 119 the user simply drags the sash to the side of the window. 
 120 wxDynamicSashWindow will automatically reparent the appropriate child 
 121 view back up the window hierarchy, and the wxDynamicSashWindow will have 
 122 only one child view once again. 
 124 As an application developer, you will simply create a wxDynamicSashWindow 
 125 using either the Create() function or the more complex constructor 
 126 provided below, and then create a view window whose parent is the 
 127 wxDynamicSashWindow.  The child should respond to 
 128 wxDynamicSashSplitEvents -- perhaps with an OnSplit() event handler -- by 
 129 constructing a new view window whose parent is also the 
 130 wxDynamicSashWindow.  That's it!  Now your users can dynamically split 
 131 and reunify the view you provided. 
 133 If you wish to handle the scrollbar events for your view, rather than 
 134 allowing wxDynamicSashWindow to do it for you, things are a bit more 
 135 complex.  (You might want to handle scrollbar events yourself, if, 
 136 for instance, you wish to scroll a subwindow of the view you add to 
 137 your wxDynamicSashWindow object, rather than scrolling the whole view.) 
 138 In this case, you will need to construct your wxDynamicSashWindow without 
 139 the wxDS_MANAGE_SCROLLBARS style and  you will need to use the 
 140 GetHScrollBar() and GetVScrollBar() methods to retrieve the scrollbar 
 141 controls and call SetEventHanler() on them to redirect the scrolling 
 142 events whenever your window is reparented by wxDyanmicSashWindow. 
 143 You will need to set the scrollbars' event handler at three times: 
 146 <li>  When your view is created 
 147 <li>  When your view receives a wxDynamicSashSplitEvent 
 148 <li>  When your view receives a wxDynamicSashUnifyEvent