2000-12-10 03:37:52 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
import wx
|
|
|
|
|
2004-01-02 20:14:17 -05:00
|
|
|
import ScrolledWindow
|
2000-12-10 03:37:52 -05:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
2003-12-08 20:23:28 -05:00
|
|
|
# There are better ways to do IDs, but this demo requires that the window
|
|
|
|
# IDs be in a specific range. There are better ways to do that, too, but
|
|
|
|
# this will do for purposes of this demo.
|
2000-12-10 03:37:52 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
ID_Menu_New = 5004
|
|
|
|
ID_Menu_Exit = 5005
|
2000-12-10 03:37:52 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
ID_WINDOW_TOP = 5000
|
|
|
|
ID_WINDOW_LEFT1 = 5001
|
|
|
|
ID_WINDOW_LEFT2 = 5002
|
|
|
|
ID_WINDOW_BOTTOM = 5003
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyParentFrame(wx.MDIParentFrame):
|
2000-12-10 03:37:52 -05:00
|
|
|
def __init__(self):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.MDIParentFrame.__init__(
|
|
|
|
self, None, -1, "MDI Parent", size=(600,400),
|
|
|
|
style = wx.DEFAULT_FRAME_STYLE | wx.HSCROLL | wx.VSCROLL
|
|
|
|
)
|
2000-12-10 03:37:52 -05:00
|
|
|
|
|
|
|
self.winCount = 0
|
2003-12-08 20:23:28 -05:00
|
|
|
menu = wx.Menu()
|
|
|
|
menu.Append(ID_Menu_New, "&New Window")
|
2000-12-10 03:37:52 -05:00
|
|
|
menu.AppendSeparator()
|
2003-12-08 20:23:28 -05:00
|
|
|
menu.Append(ID_Menu_Exit, "E&xit")
|
2000-12-10 03:37:52 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
menubar = wx.MenuBar()
|
2000-12-10 03:37:52 -05:00
|
|
|
menubar.Append(menu, "&File")
|
|
|
|
self.SetMenuBar(menubar)
|
|
|
|
|
|
|
|
#self.CreateStatusBar()
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(wx.EVT_MENU, self.OnNewWindow, id=ID_Menu_New)
|
|
|
|
self.Bind(wx.EVT_MENU, self.OnExit, id=ID_Menu_Exit)
|
2000-12-10 03:37:52 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(
|
|
|
|
wx.EVT_SASH_DRAGGED_RANGE, self.OnSashDrag, id=ID_WINDOW_TOP,
|
|
|
|
id2=ID_WINDOW_BOTTOM
|
|
|
|
)
|
2000-12-10 03:37:52 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
2000-12-10 03:37:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
# Create some layout windows
|
|
|
|
# A window like a toolbar
|
2003-12-08 20:23:28 -05:00
|
|
|
win = wx.SashLayoutWindow(self, ID_WINDOW_TOP, style=wx.NO_BORDER|wx.SW_3D)
|
2000-12-10 03:37:52 -05:00
|
|
|
win.SetDefaultSize((1000, 30))
|
2003-12-08 20:23:28 -05:00
|
|
|
win.SetOrientation(wx.LAYOUT_HORIZONTAL)
|
|
|
|
win.SetAlignment(wx.LAYOUT_TOP)
|
|
|
|
win.SetBackgroundColour(wx.Colour(255, 0, 0))
|
|
|
|
win.SetSashVisible(wx.SASH_BOTTOM, True)
|
2000-12-10 03:37:52 -05:00
|
|
|
|
|
|
|
self.topWindow = win
|
|
|
|
|
|
|
|
|
|
|
|
# A window like a statusbar
|
2003-12-08 20:23:28 -05:00
|
|
|
win = wx.SashLayoutWindow(self, ID_WINDOW_BOTTOM, style=wx.NO_BORDER|wx.SW_3D)
|
2000-12-10 03:37:52 -05:00
|
|
|
win.SetDefaultSize((1000, 30))
|
2003-12-08 20:23:28 -05:00
|
|
|
win.SetOrientation(wx.LAYOUT_HORIZONTAL)
|
|
|
|
win.SetAlignment(wx.LAYOUT_BOTTOM)
|
|
|
|
win.SetBackgroundColour(wx.Colour(0, 0, 255))
|
|
|
|
win.SetSashVisible(wx.SASH_TOP, True)
|
2000-12-10 03:37:52 -05:00
|
|
|
|
|
|
|
self.bottomWindow = win
|
|
|
|
|
|
|
|
|
|
|
|
# A window to the left of the client window
|
2003-12-08 20:23:28 -05:00
|
|
|
win = wx.SashLayoutWindow(self, ID_WINDOW_LEFT1, style=wx.NO_BORDER|wx.SW_3D)
|
2000-12-10 03:37:52 -05:00
|
|
|
win.SetDefaultSize((120, 1000))
|
2003-12-08 20:23:28 -05:00
|
|
|
win.SetOrientation(wx.LAYOUT_VERTICAL)
|
|
|
|
win.SetAlignment(wx.LAYOUT_LEFT)
|
|
|
|
win.SetBackgroundColour(wx.Colour(0, 255, 0))
|
|
|
|
win.SetSashVisible(wx.SASH_RIGHT, True)
|
2000-12-10 03:37:52 -05:00
|
|
|
win.SetExtraBorderSize(10)
|
2003-12-08 20:23:28 -05:00
|
|
|
textWindow = wx.TextCtrl(win, -1, "", style=wx.TE_MULTILINE|wx.SUNKEN_BORDER)
|
2000-12-10 03:37:52 -05:00
|
|
|
textWindow.SetValue("A sub window")
|
|
|
|
|
|
|
|
self.leftWindow1 = win
|
|
|
|
|
|
|
|
|
|
|
|
# Another window to the left of the client window
|
2003-12-08 20:23:28 -05:00
|
|
|
win = wx.SashLayoutWindow(self, ID_WINDOW_LEFT2, style=wx.NO_BORDER|wx.SW_3D)
|
2000-12-10 03:37:52 -05:00
|
|
|
win.SetDefaultSize((120, 1000))
|
2003-12-08 20:23:28 -05:00
|
|
|
win.SetOrientation(wx.LAYOUT_VERTICAL)
|
|
|
|
win.SetAlignment(wx.LAYOUT_LEFT)
|
|
|
|
win.SetBackgroundColour(wx.Colour(0, 255, 255))
|
|
|
|
win.SetSashVisible(wx.SASH_RIGHT, True)
|
2000-12-10 03:37:52 -05:00
|
|
|
|
|
|
|
self.leftWindow2 = win
|
|
|
|
|
|
|
|
|
|
|
|
def OnSashDrag(self, event):
|
2003-12-08 20:23:28 -05:00
|
|
|
if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE:
|
2000-12-10 03:37:52 -05:00
|
|
|
return
|
|
|
|
|
|
|
|
eID = event.GetId()
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
if eID == ID_WINDOW_TOP:
|
|
|
|
self.topWindow.SetDefaultSize((1000, event.GetDragRect().height))
|
2000-12-10 03:37:52 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
elif eID == ID_WINDOW_LEFT1:
|
|
|
|
self.leftWindow1.SetDefaultSize((event.GetDragRect().width, 1000))
|
2000-12-10 03:37:52 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
elif eID == ID_WINDOW_LEFT2:
|
|
|
|
self.leftWindow2.SetDefaultSize((event.GetDragRect().width, 1000))
|
2000-12-10 03:37:52 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
elif eID == ID_WINDOW_BOTTOM:
|
|
|
|
self.bottomWindow.SetDefaultSize((1000, event.GetDragRect().height))
|
2000-12-10 03:37:52 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.LayoutAlgorithm().LayoutMDIFrame(self)
|
2000-12-10 03:37:52 -05:00
|
|
|
self.GetClientWindow().Refresh()
|
|
|
|
|
|
|
|
|
|
|
|
def OnSize(self, event):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.LayoutAlgorithm().LayoutMDIFrame(self)
|
2000-12-10 03:37:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
def OnExit(self, evt):
|
2003-03-25 01:35:27 -05:00
|
|
|
self.Close(True)
|
2000-12-10 03:37:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
def OnNewWindow(self, evt):
|
|
|
|
self.winCount = self.winCount + 1
|
2003-12-08 20:23:28 -05:00
|
|
|
win = wx.MDIChildFrame(self, -1, "Child Window: %d" % self.winCount)
|
2004-01-02 20:14:17 -05:00
|
|
|
canvas = ScrolledWindow.MyCanvas(win)
|
2003-03-25 01:35:27 -05:00
|
|
|
win.Show(True)
|
2000-12-10 03:37:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2002-04-18 01:43:08 -04:00
|
|
|
if __name__ == '__main__':
|
2003-12-08 20:23:28 -05:00
|
|
|
class MyApp(wx.App):
|
2002-04-18 01:43:08 -04:00
|
|
|
def OnInit(self):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.InitAllImageHandlers()
|
2002-04-18 01:43:08 -04:00
|
|
|
frame = MyParentFrame()
|
2003-03-25 01:35:27 -05:00
|
|
|
frame.Show(True)
|
2002-04-18 01:43:08 -04:00
|
|
|
self.SetTopWindow(frame)
|
2003-03-25 01:35:27 -05:00
|
|
|
return True
|
2000-12-10 03:37:52 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
app = MyApp(False)
|
2002-04-18 01:43:08 -04:00
|
|
|
app.MainLoop()
|
2000-12-10 03:37:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
|