]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/SashWindow.py
   4 #--------------------------------------------------------------------------- 
   6 class TestSashWindow(wx
.Panel
): 
   8     def __init__(self
, parent
, log
): 
   9         wx
.Panel
.__init
__(self
, parent
, -1) 
  14         # Create some layout windows 
  15         # A window like a toolbar 
  16         topwin 
= wx
.SashLayoutWindow( 
  17             self
, -1, wx
.DefaultPosition
, (200, 30),  
  21         topwin
.SetDefaultSize((1000, 30)) 
  22         topwin
.SetOrientation(wx
.LAYOUT_HORIZONTAL
) 
  23         topwin
.SetAlignment(wx
.LAYOUT_TOP
) 
  24         topwin
.SetBackgroundColour(wx
.Colour(255, 0, 0)) 
  25         topwin
.SetSashVisible(wx
.SASH_BOTTOM
, True) 
  27         self
.topWindow 
= topwin
 
  28         winids
.append(topwin
.GetId()) 
  30         # A window like a statusbar 
  31         bottomwin 
= wx
.SashLayoutWindow( 
  32                 self
, -1, wx
.DefaultPosition
, (200, 30),  
  36         bottomwin
.SetDefaultSize((1000, 30)) 
  37         bottomwin
.SetOrientation(wx
.LAYOUT_HORIZONTAL
) 
  38         bottomwin
.SetAlignment(wx
.LAYOUT_BOTTOM
) 
  39         bottomwin
.SetBackgroundColour(wx
.Colour(0, 0, 255)) 
  40         bottomwin
.SetSashVisible(wx
.SASH_TOP
, True) 
  42         self
.bottomWindow 
= bottomwin
 
  43         winids
.append(bottomwin
.GetId()) 
  45         # A window to the left of the client window 
  46         leftwin1 
=  wx
.SashLayoutWindow( 
  47                 self
, -1, wx
.DefaultPosition
, (200, 30),  
  51         leftwin1
.SetDefaultSize((120, 1000)) 
  52         leftwin1
.SetOrientation(wx
.LAYOUT_VERTICAL
) 
  53         leftwin1
.SetAlignment(wx
.LAYOUT_LEFT
) 
  54         leftwin1
.SetBackgroundColour(wx
.Colour(0, 255, 0)) 
  55         leftwin1
.SetSashVisible(wx
.SASH_RIGHT
, True) 
  56         leftwin1
.SetExtraBorderSize(10) 
  57         textWindow 
= wx
.TextCtrl( 
  58                         leftwin1
, -1, "", wx
.DefaultPosition
, wx
.DefaultSize
,  
  59                         wx
.TE_MULTILINE|wx
.SUNKEN_BORDER
 
  62         textWindow
.SetValue("A sub window") 
  64         self
.leftWindow1 
= leftwin1
 
  65         winids
.append(leftwin1
.GetId()) 
  68         # Another window to the left of the client window 
  69         leftwin2 
= wx
.SashLayoutWindow( 
  70                 self
, -1, wx
.DefaultPosition
, (200, 30),  
  74         leftwin2
.SetDefaultSize((120, 1000)) 
  75         leftwin2
.SetOrientation(wx
.LAYOUT_VERTICAL
) 
  76         leftwin2
.SetAlignment(wx
.LAYOUT_LEFT
) 
  77         leftwin2
.SetBackgroundColour(wx
.Colour(0, 255, 255)) 
  78         leftwin2
.SetSashVisible(wx
.SASH_RIGHT
, True) 
  80         self
.leftWindow2 
= leftwin2
 
  81         winids
.append(leftwin2
.GetId()) 
  83         # will occupy the space not used by the Layout Algorithm 
  84         self
.remainingSpace 
= wx
.Panel(self
, -1, style
=wx
.SUNKEN_BORDER
) 
  87             wx
.EVT_SASH_DRAGGED_RANGE
, self
.OnSashDrag
, 
  88             id=min(winids
), id2
=max(winids
) 
  91         self
.Bind(wx
.EVT_SIZE
, self
.OnSize
) 
  94     def OnSashDrag(self
, event
): 
  95         if event
.GetDragStatus() == wx
.SASH_STATUS_OUT_OF_RANGE
: 
  96             self
.log
.write('drag is out of range') 
  99         eobj 
= event
.GetEventObject() 
 101         if eobj 
is self
.topWindow
: 
 102             self
.log
.write('topwin received drag event') 
 103             self
.topWindow
.SetDefaultSize((1000, event
.GetDragRect().height
)) 
 105         elif eobj 
is self
.leftWindow1
: 
 106             self
.log
.write('leftwin1 received drag event') 
 107             self
.leftWindow1
.SetDefaultSize((event
.GetDragRect().width
, 1000)) 
 110         elif eobj 
is self
.leftWindow2
: 
 111             self
.log
.write('leftwin2 received drag event') 
 112             self
.leftWindow2
.SetDefaultSize((event
.GetDragRect().width
, 1000)) 
 114         elif eobj 
is self
.bottomWindow
: 
 115             self
.log
.write('bottomwin received drag event') 
 116             self
.bottomWindow
.SetDefaultSize((1000, event
.GetDragRect().height
)) 
 118         wx
.LayoutAlgorithm().LayoutWindow(self
, self
.remainingSpace
) 
 119         self
.remainingSpace
.Refresh() 
 121     def OnSize(self
, event
): 
 122         wx
.LayoutAlgorithm().LayoutWindow(self
, self
.remainingSpace
) 
 124 #--------------------------------------------------------------------------- 
 126 def runTest(frame
, nb
, log
): 
 127     win 
= TestSashWindow(nb
, log
) 
 130 #--------------------------------------------------------------------------- 
 134 wx.SashLayoutWindow responds to OnCalculateLayout events generated by  
 135 wxLayoutAlgorithm. It allows the application to use simple accessors to  
 136 specify how the window should be laid out, rather than having to respond  
 137 to events. The fact that the class derives from wx.SashWindow allows sashes  
 138 to be used if required, to allow the windows to be user-resizable. 
 140 The documentation for wx.LayoutAlgorithm explains the purpose of this class  
 146 if __name__ 
== '__main__': 
 149     run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])