+
+#---------------------------------------------------------------------------
+
+class CustomStatusBar(wxStatusBar):
+ def __init__(self, parent):
+ wxStatusBar.__init__(self, parent, -1)
+ self.SetFieldsCount(3)
+
+ self.SetStatusText("A Custom StatusBar...", 0)
+
+ self.cb = wxCheckBox(self, 1001, "toggle clock")
+ EVT_CHECKBOX(self, 1001, self.OnToggleClock)
+ self.cb.SetValue(true)
+
+ # figure out how tall to make it.
+ dc = wxClientDC(self)
+ dc.SetFont(self.GetFont())
+ (w,h, d,e) = dc.GetTextExtent('X')
+ h = int(h * 1.8)
+ self.SetSize(wxSize(100, h))
+
+ # start our timer
+ self.timer = wxPyTimer(self.Notify)
+ self.timer.Start(1000)
+ self.Notify()
+
+
+ # Time-out handler
+ def Notify(self):
+ t = time.localtime(time.time())
+ st = time.strftime("%d-%b-%Y %I:%M:%S", t)
+ self.SetStatusText(st, 2)
+
+ # the checkbox was clicked
+ def OnToggleClock(self, event):
+ if self.cb.GetValue():
+ self.timer.Start(1000)
+ self.Notify()
+ else:
+ self.timer.Stop()
+
+ # reposition the checkbox
+ def OnSize(self, event):
+ rect = self.GetFieldRect(1)
+ print "%s, %s" % (rect.x, rect.y)
+ self.cb.SetPosition(wxPoint(rect.x+2, rect.y+2))
+ self.cb.SetSize(wxSize(rect.width-4, rect.height-4))
+
+
+
+class TestCustomStatusBar(wxFrame):
+ def __init__(self, parent):
+ wxFrame.__init__(self, parent, -1, 'Test Custom StatusBar',
+ wxDefaultPosition, wxSize(500, 300))
+ wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
+
+ self.sb = CustomStatusBar(self)
+ self.SetStatusBar(self.sb)
+
+ def OnCloseWindow(self, event):
+ self.sb.timer.Stop()
+ self.Destroy()
+
+
+#---------------------------------------------------------------------------
+
+class TestToolBar(wxFrame):
+ def __init__(self, parent, log):
+ wxFrame.__init__(self, parent, -1, 'Test ToolBar',
+ wxDefaultPosition, wxSize(500, 300))
+ self.log = log
+
+ wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
+
+ tb = self.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER)
+ #tb = wxToolBar(self, -1, wxDefaultPosition, wxDefaultSize,
+ # wxTB_HORIZONTAL | wxNO_BORDER | wxTB_FLAT)
+ #self.SetToolBar(tb)
+
+ self.CreateStatusBar()
+
+ tb.AddTool(10, wxNoRefBitmap('bitmaps/new.bmp', wxBITMAP_TYPE_BMP),
+ wxNullBitmap, false, -1, -1, "New", "Long help for 'New'")
+ EVT_TOOL(self, 10, self.OnToolClick)
+ EVT_TOOL_RCLICKED(self, 10, self.OnToolRClick)
+
+ tb.AddTool(20, wxNoRefBitmap('bitmaps/open.bmp', wxBITMAP_TYPE_BMP),
+ wxNullBitmap, false, -1, -1, "Open")
+ EVT_TOOL(self, 20, self.OnToolClick)
+ EVT_TOOL_RCLICKED(self, 20, self.OnToolRClick)
+
+ tb.AddSeparator()
+ tb.AddTool(30, wxNoRefBitmap('bitmaps/copy.bmp', wxBITMAP_TYPE_BMP),
+ wxNullBitmap, false, -1, -1, "Copy")
+ EVT_TOOL(self, 30, self.OnToolClick)
+ EVT_TOOL_RCLICKED(self, 30, self.OnToolRClick)
+
+ tb.AddTool(40, wxNoRefBitmap('bitmaps/paste.bmp', wxBITMAP_TYPE_BMP),
+ wxNullBitmap, false, -1, -1, "Paste")
+ EVT_TOOL(self, 40, self.OnToolClick)
+ EVT_TOOL_RCLICKED(self, 40, self.OnToolRClick)
+
+ tb.AddSeparator()
+
+ tb.AddTool(50, wxNoRefBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
+ wxNullBitmap, true, -1, -1, "Toggle this")
+ EVT_TOOL(self, 50, self.OnToolClick)
+ EVT_TOOL_RCLICKED(self, 50, self.OnToolRClick)
+
+ tb.AddTool(60, wxNoRefBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
+ wxNoRefBitmap('bitmaps/tog2.bmp', wxBITMAP_TYPE_BMP),
+ true, -1, -1, "Toggle with 2 bitmaps")
+ EVT_TOOL(self, 60, self.OnToolClick)
+ EVT_TOOL_RCLICKED(self, 60, self.OnToolRClick)
+
+ tb.Realize()
+
+
+ def OnCloseWindow(self, event):
+ self.Destroy()
+
+ def OnToolClick(self, event):
+ self.log.WriteText("tool %s clicked\n" % event.GetId())
+
+ def OnToolRClick(self, event):
+ self.log.WriteText("tool %s right-clicked\n" % event.GetId())
+
+
+#---------------------------------------------------------------------------
+
+class TestTreeCtrlPanel(wxPanel):
+ def __init__(self, parent, log):
+ wxPanel.__init__(self, parent, -1)
+
+ self.log = log
+ tID = 1101
+
+ self.tree = wxTreeCtrl(self, tID)
+ root = self.tree.AddRoot("The Root Item")
+ for x in range(10):
+ child = self.tree.AppendItem(root, "Item %d" % x)
+ for y in range(5):
+ last = self.tree.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
+
+ self.tree.Expand(root)
+ EVT_TREE_ITEM_EXPANDED (self, tID, self.OnItemExpanded)
+ EVT_TREE_ITEM_COLLAPSED (self, tID, self.OnItemCollapsed)
+ EVT_TREE_SEL_CHANGED (self, tID, self.OnSelChanged)
+
+
+ def OnSize(self, event):
+ w,h = self.GetClientSizeTuple()
+ self.tree.SetDimensions(0, 0, w, h)
+
+
+ def OnItemExpanded(self, event):
+ item = event.GetItem()
+ self.log.WriteText("OnItemExpanded: %s\n" % self.tree.GetItemText(item))
+
+ def OnItemCollapsed(self, event):
+ item = event.GetItem()
+ self.log.WriteText("OnItemCollapsed: %s\n" % self.tree.GetItemText(item))
+
+ def OnSelChanged(self, event):
+ item = event.GetItem()
+ self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(item))
+
+
+
+
+class TestTreeCtrl(wxFrame):
+ def __init__(self, parent, log):
+ wxFrame.__init__(self, parent, -1, 'Test TreeCtrl',
+ wxDefaultPosition, wxSize(250, 300))
+
+ p = TestTreeCtrlPanel(self, log)
+
+
+#---------------------------------------------------------------------------
+
+class TestSashWindow(wxMDIParentFrame):
+ NEW_WINDOW = 5000
+ TOGGLE_WINDOW = 5001
+ QUIT = 5002
+ ID_WINDOW_TOP = 5100
+ ID_WINDOW_LEFT1 = 5101
+ ID_WINDOW_LEFT2 = 5102
+ ID_WINDOW_BOTTOM = 5103
+
+
+ def __init__(self, parent, log):
+ wxMDIParentFrame.__init__(self, parent, -1, 'Test Sash Window',
+ wxDefaultPosition, wxSize(250, 300))
+
+ self.log = log
+ menu = wxMenu()
+ menu.Append(self.NEW_WINDOW, "&New Window")
+ menu.Append(self.TOGGLE_WINDOW, "&Toggle window")
+ menu.Append(self.QUIT, "E&xit")
+
+ menubar = wxMenuBar()
+ menubar.Append(menu, "&File")
+
+ self.SetMenuBar(menubar)
+ self.CreateStatusBar()
+
+ EVT_MENU(self, self.NEW_WINDOW, self.OnNewWindow)
+ EVT_MENU(self, self.TOGGLE_WINDOW, self.OnToggleWindow)
+ EVT_MENU(self, self.QUIT, self.OnQuit)
+
+ EVT_SASH_DRAGGED_RANGE(self, self.ID_WINDOW_TOP,
+ self.ID_WINDOW_BOTTOM, self.OnSashDrag)
+
+
+ # Create some layout windows
+ # A window like a toolbar
+ win = wxSashLayoutWindow(self, self.ID_WINDOW_TOP, wxDefaultPosition,
+ wxSize(200, 30), wxNO_BORDER|wxSW_3D)
+ win.SetDefaultSize(wxSize(1000, 30))
+ win.SetOrientation(wxLAYOUT_HORIZONTAL)
+ win.SetAlignment(wxLAYOUT_TOP)
+ win.SetBackgroundColour(wxColour(255, 0, 0))
+ win.SetSashVisible(wxSASH_BOTTOM, true)
+
+ self.topWindow = win
+
+
+ # A window like a statusbar
+ win = wxSashLayoutWindow(self, self.ID_WINDOW_BOTTOM,
+ wxDefaultPosition, wxSize(200, 30),
+ wxNO_BORDER|wxSW_3D)
+ win.SetDefaultSize(wxSize(1000, 30))
+ win.SetOrientation(wxLAYOUT_HORIZONTAL)
+ win.SetAlignment(wxLAYOUT_BOTTOM)
+ win.SetBackgroundColour(wxColour(0, 0, 255))
+ win.SetSashVisible(wxSASH_TOP, true)
+
+ self.bottomWindow = win
+
+
+ # A window to the left of the client window
+ win = wxSashLayoutWindow(self, self.ID_WINDOW_LEFT1,
+ wxDefaultPosition, wxSize(200, 30),
+ wxNO_BORDER|wxSW_3D)
+ win.SetDefaultSize(wxSize(120, 1000))
+ win.SetOrientation(wxLAYOUT_VERTICAL)
+ win.SetAlignment(wxLAYOUT_LEFT)
+ win.SetBackgroundColour(wxColour(0, 255, 0))
+ win.SetSashVisible(wxSASH_RIGHT, TRUE)
+ win.SetExtraBorderSize(10)
+
+ textWindow = wxTextCtrl(win, -1, "", wxDefaultPosition, wxDefaultSize,
+ wxTE_MULTILINE|wxSUNKEN_BORDER)
+ textWindow.SetValue("A help window")
+
+ self.leftWindow1 = win
+
+
+ # Another window to the left of the client window
+ win = wxSashLayoutWindow(self, self.ID_WINDOW_LEFT2,
+ wxDefaultPosition, wxSize(200, 30),
+ wxNO_BORDER|wxSW_3D)
+ win.SetDefaultSize(wxSize(120, 1000))
+ win.SetOrientation(wxLAYOUT_VERTICAL)
+ win.SetAlignment(wxLAYOUT_LEFT)
+ win.SetBackgroundColour(wxColour(0, 255, 255))
+ win.SetSashVisible(wxSASH_RIGHT, TRUE)
+
+ self.leftWindow2 = win
+
+
+ def OnNewWindow(self, event):
+ pass
+
+ def OnToggleWindow(self, event):
+ pass
+
+ def OnQuit(self, event):
+ self.Close(true)
+
+ def OnSashDrag(self, event):
+ if event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE:
+ return
+
+ eID = event.GetId()
+ if eID == self.ID_WINDOW_TOP:
+ self.topWindow.SetDefaultSize(wxSize(1000, event.GetDragRect().height))
+
+ elif eID == self.ID_WINDOW_LEFT1:
+ self.leftWindow1.SetDefaultSize(wxSize(event.GetDragRect().width, 1000))
+
+
+ elif eID == self.ID_WINDOW_LEFT2:
+ self.leftWindow2.SetDefaultSize(wxSize(event.GetDragRect().width, 1000))
+
+ elif eID == self.ID_WINDOW_BOTTOM:
+ self.bottomWindow.SetDefaultSize(wxSize(1000, event.GetDragRect().height))
+
+ wxLayoutAlgorithm().LayoutMDIFrame(self)
+
+ # Leaves bits of itself behind sometimes
+ self.GetClientWindow().Refresh()
+
+
+ def OnSize(self, event):
+ wxLayoutAlgorithm().LayoutMDIFrame(self)
+
+#---------------------------------------------------------------------------
+#---------------------------------------------------------------------------