I have some trouble with my GUI. I have left panel with foldpanelbar,
but i need one item but not collapsed - simple button. I split my left
panel into two foldpanelbars with one button between.
But a have trouble... Panels are to small, tree is too short..
Sorry for english
Simple code:
路路路
#------------------------------------------------------------------------------------------------------
import sys
import wx
import wx.html as html
import wx.lib.foldpanelbar as fpb
import os
import sys
ID_New = wx.NewId()
ID_Exit = wx.NewId()
#------------------------------------------------------------------------------
class MyMDIChildFrame(wx.MDIChildFrame):
#------------------------------------------------------------------------------
聽聽聽聽def __init__(self,parent,id,name=""):
聽聽聽聽聽聽wx.MDIChildFrame.__init__(self,parent, id, name)
聽聽聽聽聽聽self.InitGUI()
#--------------------------------------------------------------------------
聽聽聽聽def InitGUI(self):
#--------------------------------------------------------------------------
聽聽聽聽聽聽self.mainSplitter = wx.SplitterWindow(self, -1,
style=wx.SP_NOBORDER)
聽聽聽聽聽聽self.infoViewer = html.HtmlWindow(self.mainSplitter, -1,
style=wx.NO_FULL_REPAINT_ON_RESIZE)
聽聽聽聽聽聽#self.infoViewer.LoadPage("http://wxwidgets.org/manuals/2.5.4/
wx_wxbutton.html")
聽聽聽聽聽聽self.infoViewer.SetPage("Here is some <b>formatted</b>
<i><u>text</u></i> loaded from a <font color=\"red\">string</font>.")
聽聽聽聽聽聽self.leftPanel = wx.Panel(self.mainSplitter)
聽聽聽聽聽聽self.CreateFoldPanel()
聽聽聽聽聽聽self.mainSplitter.Initialize(self.infoViewer)
聽聽聽聽聽聽self.mainSplitter.SplitVertically(self.leftPanel,
self.infoViewer, 180)
#--------------------------------------------------------------------------
聽聽聽聽def CreateFoldPanel(self):
#--------------------------------------------------------------------------
聽聽聽聽聽聽# foldpanel #1
聽聽聽聽聽聽self.foldPanel1 = fpb.FoldPanelBar(self.leftPanel, -1,
wx.DefaultPosition, wx.Size(-1,-1), fpb.FPB_DEFAULT_STYLE,
fpb.FPB_SINGLE_FOLD)
聽聽聽聽聽聽self.bs = wx.BoxSizer(wx.VERTICAL)
聽聽聽聽聽聽self.leftPanel.SetSizer(self.bs)
聽聽聽聽聽聽self.leftPanel.SetBackgroundColour(wx.BLACK)
聽聽聽聽聽聽item = self.foldPanel1.AddFoldPanel("Documents",
collapsed=False)
聽聽聽聽聽聽item.SetBackgroundColour(wx.RED)
聽聽聽聽聽聽button1 = wx.Button(item, wx.ID_ANY, "In")
聽聽聽聽聽聽button2 = wx.Button(item, wx.ID_ANY, "Out")
聽聽聽聽聽聽self.foldPanel1.AddFoldPanelWindow(item, button1)
聽聽聽聽聽聽self.foldPanel1.AddFoldPanelWindow(item, button2)
聽聽聽聽聽聽item = self.foldPanel1.AddFoldPanel("Projects", collapsed=False)
聽聽聽聽聽聽item.SetBackgroundColour(wx.BLUE)
聽聽聽聽聽聽button1 = wx.Button(item, wx.ID_ANY, "Name")
聽聽聽聽聽聽button2 = wx.Button(item, wx.ID_ANY, "Type")
聽聽聽聽聽聽button3 = wx.Button(item, wx.ID_ANY, "Data")
聽聽聽聽聽聽self.foldPanel1.AddFoldPanelWindow(item, button1)
聽聽聽聽聽聽self.foldPanel1.AddFoldPanelWindow(item, button2)
聽聽聽聽聽聽self.foldPanel1.AddFoldPanelWindow(item, button3)
聽聽聽聽聽聽item = self.foldPanel1.AddFoldPanel("Contacts", collapsed=False)
聽聽聽聽聽聽item.SetBackgroundColour(wx.CYAN)
聽聽聽聽聽聽button1 = wx.Button(item, wx.ID_ANY, "Name")
聽聽聽聽聽聽button2 = wx.Button(item, wx.ID_ANY, "Mail")
聽聽聽聽聽聽button3 = wx.Button(item, wx.ID_ANY, "City")
聽聽聽聽聽聽self.foldPanel1.AddFoldPanelWindow(item, button1)
聽聽聽聽聽聽self.foldPanel1.AddFoldPanelWindow(item, button2)
聽聽聽聽聽聽self.foldPanel1.AddFoldPanelWindow(item, button3)
聽聽聽聽聽聽self.bs.Add(self.foldPanel1, 0, wx.EXPAND)
聽聽聽聽聽聽# button
聽聽聽聽聽聽button1 = wx.Button(self.leftPanel, wx.ID_ANY, "Calendar")
聽聽聽聽聽聽self.bs.Add(button1, 0, wx.ALL|wx.EXPAND, 4)
聽聽聽聽聽聽# foldpanel #2
聽聽聽聽聽聽self.foldPanel2 = fpb.FoldPanelBar(self.leftPanel, -1,
wx.DefaultPosition, wx.Size(-1,-1), fpb.FPB_DEFAULT_STYLE,
fpb.FPB_SINGLE_FOLD)
聽聽聽聽聽聽item = self.foldPanel2.AddFoldPanel("Treenote", collapsed=True)
聽聽聽聽聽聽item.SetBackgroundColour(wx.GREEN)
聽聽聽聽聽聽self.tree = wx.TreeCtrl(item, wx.ID_ANY, wx.DefaultPosition,
wx.DefaultSize,wx.TR_HAS_BUTTONS| wx.TR_EDIT_LABELS|
wx.TR_HIDE_ROOT)#| wx.TR_MULTIPLE#| wx.TR_HIDE_ROOT)
聽聽聽聽聽聽self.foldPanel2.AddFoldPanelWindow(item, self.tree)
聽聽聽聽聽聽self.LoadTree()
聽聽聽聽聽聽self.bs.Add(self.foldPanel2, 0, wx.EXPAND)
聽聽聽聽聽聽self.foldPanel1.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
聽聽聽聽聽聽self.foldPanel2.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
聽聽聽聽聽聽self.bs.Fit(self)
聽聽聽聽聽聽self.bs.Layout()
聽聽聽聽聽聽self.foldPanel1.Layout()
聽聽聽聽聽聽self.foldPanel2.Layout()
#--------------------------------------------------------------------------
聽聽聽聽def OnPressCaption(self, event):
#--------------------------------------------------------------------------
聽聽聽聽聽聽self.bs.Layout()
聽聽聽聽聽聽event.Skip()
#--------------------------------------------------------------------------
聽聽聽聽def LoadTree(self):
#--------------------------------------------------------------------------
聽聽聽聽聽聽self.root = self.tree.AddRoot("The Root Item")
聽聽聽聽聽聽for x in range(15):
聽聽聽聽聽聽聽聽child = self.tree.AppendItem(self.root, "Test item %d" % x)
聽聽聽聽聽聽聽聽for y in range(5):
聽聽聽聽聽聽聽聽聽聽last = self.tree.AppendItem(child, "test item %d-%s" % (x,
chr(ord("a")+y)))
聽聽聽聽聽聽聽聽聽聽for z in range(5):
聽聽聽聽聽聽聽聽聽聽聽聽item = self.tree.AppendItem(last, "test item %d-%s-%d" %
(x, chr(ord("a")+y), z))
#------------------------------------------------------------------------------
class MyParentFrame(wx.MDIParentFrame):
#------------------------------------------------------------------------------
#--------------------------------------------------------------------------
聽聽聽聽def __init__(self):
#--------------------------------------------------------------------------
聽聽聽聽聽聽wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent",
size=(800,600))
聽聽聽聽聽聽self.winCount = 0
聽聽聽聽聽聽menu = wx.Menu()
聽聽聽聽聽聽menu.Append(ID_New, "&New Window")
聽聽聽聽聽聽menu.AppendSeparator()
聽聽聽聽聽聽menu.Append(ID_Exit, "E&xit")
聽聽聽聽聽聽menubar = wx.MenuBar()
聽聽聽聽聽聽menubar.Append(menu, "&File")
聽聽聽聽聽聽self.SetMenuBar(menubar)
聽聽聽聽聽聽self.CreateStatusBar()
聽聽聽聽聽聽self.my_canvas = None
聽聽聽聽聽聽self.Bind(wx.EVT_MENU, self.OnNewWindow, id=ID_New)
聽聽聽聽聽聽self.CreateNewWindow()
#--------------------------------------------------------------------------
聽聽聽聽def OnNewWindow(self, evt):
#--------------------------------------------------------------------------
聽聽聽聽聽聽self.CreateNewWindow()
#--------------------------------------------------------------------------
聽聽聽聽def CreateNewWindow(self):
#--------------------------------------------------------------------------
聽聽聽聽聽聽self.winCount = self.winCount + 1
聽聽聽聽聽聽win = MyMDIChildFrame(self, -1, "Child Window: %d" %
self.winCount)
聽聽聽聽聽聽win.Maximize()
if __name__ == '__main__':
聽聽聽聽class MyApp(wx.App):
聽聽聽聽聽聽聽聽def OnInit(self):
聽聽聽聽聽聽聽聽聽聽聽聽wx.InitAllImageHandlers()
聽聽聽聽聽聽聽聽聽聽聽聽frame = MyParentFrame()
聽聽聽聽聽聽聽聽聽聽聽聽frame.Show(True)
聽聽聽聽聽聽聽聽聽聽聽聽self.SetTopWindow(frame)
聽聽聽聽聽聽聽聽聽聽聽聽return True
聽聽聽聽app = MyApp(False)
聽聽聽聽app.MainLoop()