wxPython - 2 x foldpanelbar with tree...

w.p. ptaku2 at tlen.pl
Mon Feb 26 09:50:11 EST 2007


Hello!
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...
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()




More information about the Python-list mailing list