1999-04-29 23:29:54 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
import wx
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestSashWindow(wx.Panel):
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
def __init__(self, parent, log):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
self.log = log
|
2005-02-18 15:25:05 -05:00
|
|
|
winids = []
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
# Create some layout windows
|
|
|
|
# A window like a toolbar
|
2005-02-18 15:25:05 -05:00
|
|
|
topwin = wx.SashLayoutWindow(
|
|
|
|
self, -1, wx.DefaultPosition, (200, 30),
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.NO_BORDER|wx.SW_3D
|
|
|
|
)
|
|
|
|
|
2005-02-18 15:25:05 -05:00
|
|
|
topwin.SetDefaultSize((1000, 30))
|
|
|
|
topwin.SetOrientation(wx.LAYOUT_HORIZONTAL)
|
|
|
|
topwin.SetAlignment(wx.LAYOUT_TOP)
|
|
|
|
topwin.SetBackgroundColour(wx.Colour(255, 0, 0))
|
|
|
|
topwin.SetSashVisible(wx.SASH_BOTTOM, True)
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2005-02-18 15:25:05 -05:00
|
|
|
self.topWindow = topwin
|
|
|
|
winids.append(topwin.GetId())
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
# A window like a statusbar
|
2005-02-18 15:25:05 -05:00
|
|
|
bottomwin = wx.SashLayoutWindow(
|
|
|
|
self, -1, wx.DefaultPosition, (200, 30),
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.NO_BORDER|wx.SW_3D
|
|
|
|
)
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2005-02-18 15:25:05 -05:00
|
|
|
bottomwin.SetDefaultSize((1000, 30))
|
|
|
|
bottomwin.SetOrientation(wx.LAYOUT_HORIZONTAL)
|
|
|
|
bottomwin.SetAlignment(wx.LAYOUT_BOTTOM)
|
|
|
|
bottomwin.SetBackgroundColour(wx.Colour(0, 0, 255))
|
|
|
|
bottomwin.SetSashVisible(wx.SASH_TOP, True)
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2005-02-18 15:25:05 -05:00
|
|
|
self.bottomWindow = bottomwin
|
|
|
|
winids.append(bottomwin.GetId())
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
# A window to the left of the client window
|
2005-02-18 15:25:05 -05:00
|
|
|
leftwin1 = wx.SashLayoutWindow(
|
|
|
|
self, -1, wx.DefaultPosition, (200, 30),
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.NO_BORDER|wx.SW_3D
|
|
|
|
)
|
|
|
|
|
2005-02-18 15:25:05 -05:00
|
|
|
leftwin1.SetDefaultSize((120, 1000))
|
|
|
|
leftwin1.SetOrientation(wx.LAYOUT_VERTICAL)
|
|
|
|
leftwin1.SetAlignment(wx.LAYOUT_LEFT)
|
|
|
|
leftwin1.SetBackgroundColour(wx.Colour(0, 255, 0))
|
|
|
|
leftwin1.SetSashVisible(wx.SASH_RIGHT, True)
|
|
|
|
leftwin1.SetExtraBorderSize(10)
|
2003-12-08 20:23:28 -05:00
|
|
|
textWindow = wx.TextCtrl(
|
2005-02-18 15:25:05 -05:00
|
|
|
leftwin1, -1, "", wx.DefaultPosition, wx.DefaultSize,
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.TE_MULTILINE|wx.SUNKEN_BORDER
|
|
|
|
)
|
|
|
|
|
2000-12-10 03:37:52 -05:00
|
|
|
textWindow.SetValue("A sub window")
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2005-02-18 15:25:05 -05:00
|
|
|
self.leftWindow1 = leftwin1
|
|
|
|
winids.append(leftwin1.GetId())
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Another window to the left of the client window
|
2005-02-18 15:25:05 -05:00
|
|
|
leftwin2 = wx.SashLayoutWindow(
|
|
|
|
self, -1, wx.DefaultPosition, (200, 30),
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.NO_BORDER|wx.SW_3D
|
|
|
|
)
|
|
|
|
|
2005-02-18 15:25:05 -05:00
|
|
|
leftwin2.SetDefaultSize((120, 1000))
|
|
|
|
leftwin2.SetOrientation(wx.LAYOUT_VERTICAL)
|
|
|
|
leftwin2.SetAlignment(wx.LAYOUT_LEFT)
|
|
|
|
leftwin2.SetBackgroundColour(wx.Colour(0, 255, 255))
|
|
|
|
leftwin2.SetSashVisible(wx.SASH_RIGHT, True)
|
|
|
|
|
|
|
|
self.leftWindow2 = leftwin2
|
|
|
|
winids.append(leftwin2.GetId())
|
|
|
|
|
|
|
|
# will occupy the space not used by the Layout Algorithm
|
|
|
|
self.remainingSpace = wx.Panel(self, -1, style=wx.SUNKEN_BORDER)
|
|
|
|
|
|
|
|
self.Bind(
|
|
|
|
wx.EVT_SASH_DRAGGED_RANGE, self.OnSashDrag,
|
|
|
|
id=min(winids), id2=max(winids)
|
|
|
|
)
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2005-02-18 15:25:05 -05:00
|
|
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
def OnSashDrag(self, event):
|
2003-12-08 20:23:28 -05:00
|
|
|
if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE:
|
2005-02-18 15:25:05 -05:00
|
|
|
self.log.write('drag is out of range')
|
1999-04-29 23:29:54 -04:00
|
|
|
return
|
|
|
|
|
2005-02-18 15:25:05 -05:00
|
|
|
eobj = event.GetEventObject()
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2005-02-18 15:25:05 -05:00
|
|
|
if eobj is self.topWindow:
|
|
|
|
self.log.write('topwin received drag event')
|
2003-12-08 20:23:28 -05:00
|
|
|
self.topWindow.SetDefaultSize((1000, event.GetDragRect().height))
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2005-02-18 15:25:05 -05:00
|
|
|
elif eobj is self.leftWindow1:
|
|
|
|
self.log.write('leftwin1 received drag event')
|
2003-12-08 20:23:28 -05:00
|
|
|
self.leftWindow1.SetDefaultSize((event.GetDragRect().width, 1000))
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
|
2005-02-18 15:25:05 -05:00
|
|
|
elif eobj is self.leftWindow2:
|
|
|
|
self.log.write('leftwin2 received drag event')
|
2003-12-08 20:23:28 -05:00
|
|
|
self.leftWindow2.SetDefaultSize((event.GetDragRect().width, 1000))
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2005-02-18 15:25:05 -05:00
|
|
|
elif eobj is self.bottomWindow:
|
|
|
|
self.log.write('bottomwin received drag event')
|
2003-12-08 20:23:28 -05:00
|
|
|
self.bottomWindow.SetDefaultSize((1000, event.GetDragRect().height))
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
|
2000-12-10 03:37:52 -05:00
|
|
|
self.remainingSpace.Refresh()
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
def OnSize(self, event):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestSashWindow(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
overview = """\
|
2004-01-12 22:17:17 -05:00
|
|
|
wx.SashLayoutWindow responds to OnCalculateLayout events generated by
|
2003-12-08 20:23:28 -05:00
|
|
|
wxLayoutAlgorithm. It allows the application to use simple accessors to
|
|
|
|
specify how the window should be laid out, rather than having to respond
|
2004-01-12 22:17:17 -05:00
|
|
|
to events. The fact that the class derives from wx.SashWindow allows sashes
|
2003-12-08 20:23:28 -05:00
|
|
|
to be used if required, to allow the windows to be user-resizable.
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2004-01-12 22:17:17 -05:00
|
|
|
The documentation for wx.LayoutAlgorithm explains the purpose of this class
|
2003-12-08 20:23:28 -05:00
|
|
|
in more detail.
|
1999-04-29 23:29:54 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
"""
|
1999-04-29 23:29:54 -04:00
|
|
|
|
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
2004-03-04 19:06:33 -05:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|