wxPython - FlatNotebook help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MrQ
    New Member
    • May 2007
    • 5

    wxPython - FlatNotebook help

    Hi, I'm having some problems with FlatNotebook.py and i hope you can help me. I'm sure that is very easy for an experinced user but i can't figured it out, i just start using wxpython.
    The problem is that i don't know how to put diferent king of widgets on every notebook page. For example when i select page1, I want ot see three checkboxes and one button and when i select page2 two buttons and ten radio buttons, all in different positions than the previous page. Considering I have the following sample code how can i do that:
    #code
    Code:
    import wx
    import FlatNotebook as FNB
    import random
    
    class MenuEventFrame(wx.Frame):
        
        def __init__(self, parent, id):
            wx.Frame.__init__(self, parent, id, 'Menus', size=(450, 200), pos=(500,400))
            self.panel=wx.Panel (self, -1)
            #self.panel.SetBackgroundColour ("white")
            menuBar = wx.MenuBar()
            menu1 = wx.Menu()
            menuItem = menu1.Append(-1, "&Exit...")
            menuBar.Append(menu1, "&File")
            self.SetMenuBar(menuBar)
            
            dd="Page1"
            dd1="Page2"
            dd2="Page3"
            
            caption = "test"
            
            stil = FNB.FNB_VC8 | FNB.FNB_DROPDOWN_TABS_LIST | FNB.FNB_TABS_BORDER_SIMPLE | FNB.FNB_BACKGROUND_GRADIENT
            self.book = FNB.FlatNotebook(self, wx.ID_ANY,  style=stil)
            self.book.SetTabAreaColour(wx.Color(0,153,204))
            self.book.AddPage(self.panel, dd, True, -1)
            self.book.AddPage(self.panel, dd1, True, -1)
            self.book.AddPage(self.panel, dd2, True, -1)
            self.book.SetSelection(1)
            
        
            
        def CreatePage(self, caption):
            p = wx.Panel(self.book)
            wx.StaticText(p, -1, caption, (20,20))
            wx.TextCtrl(p, -1, "", (20,40), (150,-1))
            p.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE))
            return p
        
    
    if __name__ == '__main__':
        app = wx.PySimpleApp()
        frame = MenuEventFrame(parent=None, id=-1)
        frame.Show()
        app.MainLoop()
    #end code

    In conclusion i want to show different widgets on different notebook pages and of course bind an event to every widget.
    Thank you.
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Thanks for the post (and you came SO close to getting the [ CODE ] tags right - instructions are on the right hand side in REPLY GUIDELINES when you reply).

    Instead of
    Code:
            self.book.AddPage(self.panel, dd, True, -1)
            self.book.AddPage(self.panel, dd1, True, -1)
            self.book.AddPage(self.panel, dd2, True, -1)
    You need to create more than on panel (with the widgets that you want on each page and then:
    Code:
            self.book.AddPage(self.panel1, dd, True, -1)
            self.book.AddPage(self.panel2, dd1, True, -1)
            self.book.AddPage(self.panel3, dd2, True, -1)
    Hope that helps!

    Comment

    • MrQ
      New Member
      • May 2007
      • 5

      #3
      Hope that helps!
      Yes, it helps, thank you very much, but now i'm having a more complex problem, I hope you can help me.
      Basically what i want to do is to add a splitter window inside an flat notebook page, then inside the splitter window, on left panel add a label notebook. the problem is neither splitter window nor labelbook is created.
      Here is sample code but it's obviously wrong because it's not working. Flatnotebook is created with all 4 pages but not the other ones. :
      Code:
      import wx
      import FlatNotebook as FNB
      import random
      import data
      import LabelBook as LB
      from Resources import *
      
      
      _pageTexts = ["Hello", "From", "wxPython", "LabelBook", "Demo"]
      _pageIcons = ["roll.png", "charge.png", "add.png", "decrypted.png", "news.png"]
      _pageColours = [wx.RED, wx.GREEN, wx.WHITE, wx.BLUE, "Pink"]
      
      class Panel(wx.Panel):
      
          def __init__(self, parent, colour, label):
      
              wx.Panel.__init__(self, parent, style=wx.BORDER_SUNKEN)
              self.SetBackgroundColour(colour)
      
              label = label + "Demo"
              static = wx.StaticText(self, -1, label, pos=(10, 10))     
              
      
      class MenuEventFrame(wx.Frame):
          
          def __init__(self, parent, id):
              wx.Frame.__init__(self, parent, id, 'Demo', size=(640, 480), pos=(500,400))
              
              self.panel=wx.Panel (self, -1)
              self.panel1=wx.Panel (self, -1)
              self.panel2=wx.Panel (self, -1)
              self.panel3=wx.Panel (self, -1)
              
              
              #splitter window
              self.splitter = wx.SplitterWindow(self.panel, -1, style=wx.SP_3D|wx.SP_BORDER|
                                                wx.SP_LIVE_UPDATE|wx.SP_3DSASH)
              sty = wx.BORDER_SUNKEN
              p1 = wx.Window(self.splitter, style=sty)
              p1.SetBackgroundColour("blue")
              wx.StaticText(p1, -1, "Panel One", (5,5))
              p2 = wx.Window(self.splitter, style=sty)
              p2.SetBackgroundColour("sky blue")
              wx.StaticText(p2, -1, "Panel Two", (5,5))
              self.splitter.SetMinimumPaneSize(20)
              self.splitter.SplitVertically(p1, p2, -100)
              self.splitter.SetMinimumPaneSize(120)
              
           
      
              #menu bar
              menuBar = wx.MenuBar()
              menu1 = wx.Menu()
              menuItem = menu1.Append(-1, "&Exit...")
              menuBar.Append(menu1, "&File")
              self.SetMenuBar(menuBar)
              self.Bind(wx.EVT_MENU, self.OnCloseMe, menuItem)
           
      
              #flat notebook
              stil = FNB.FNB_VC8 | FNB.FNB_DROPDOWN_TABS_LIST | FNB.FNB_TABS_BORDER_SIMPLE | FNB.FNB_BACKGROUND_GRADIENT
              self.book = FNB.FlatNotebook(self, wx.ID_ANY,pos=(100, 300),size=(100, 100),  style=stil)
              self.book.SetTabAreaColour(wx.Color(0,153,204))
              self.book.AddPage(self.panel, "Main Application", True, -1)
              self.book.AddPage(self.panel1, "Configuration", True, -1)
              self.book.AddPage(self.panel2, "Favorites", True, -1)
              self.book.AddPage(self.panel3, "Favorites", True, -1)
              
              
              self.book1 = LB.LabelBook(self.panel, -1, style=INB_GRADIENT_BACKGROUND)
              for indx, txts in enumerate(_pageTexts):
                  label = "This is panel number %d"%(indx+1)
                  self.book.AddPage(Panel(self.book1, _pageColours[indx], label),
                                    txts, True, indx)
          
                      
          def OnCloseMe(self, event):
              self.Close(True)
              
      
      if __name__ == '__main__':
          app = wx.PySimpleApp()
          frame = MenuEventFrame(parent=None, id=-1)
          frame.Show()
          app.MainLoop()
      I will be very grateful if you can help me with this because i'm kinda lost.

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        I don't know enough about splitter windows to get all the properties set just right.
        For that matter I never write the GUI part of my programs. Here is what I consider to be a well-factored wx.Frame definition might look like (as generated by Boa Constructor):
        Code:
        #Boa:Frame:Frame1
        
        import wx
        
        def create(parent):
            return Frame1(parent)
        
        [wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1NOTEBOOK1, wxID_FRAME1NOTEBOOK2, wxID_FRAME1PANEL1,
         wxID_FRAME1SPLITTERWINDOW1, wxID_FRAME1STATICTEXT1,
        ] = [wx.NewId() for _init_ctrls in range(7)]
        
        class Frame1(wx.Frame):
            def _init_coll_boxSizer1_Items(self, parent):
                # generated method, don't edit
        
                parent.AddWindow(self.panel1, 1, border=0, flag=wx.EXPAND)
        
            def _init_coll_boxSizer2_Items(self, parent):
                # generated method, don't edit
        
                parent.AddWindow(self.notebook1, 1, border=0, flag=wx.EXPAND)
        
            def _init_coll_notebook2_Pages(self, parent):
                # generated method, don't edit
        
                parent.AddPage(imageId=-1, page=self.staticText1, select=True, text='Pages0')
        
            def _init_coll_notebook1_Pages(self, parent):
                # generated method, don't edit
        
                parent.AddPage(imageId=-1, page=self.splitterWindow1, select=True, text='Pages0')
        
            def _init_sizers(self):
                # generated method, don't edit
                self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL)
        
                self.boxSizer2 = wx.BoxSizer(orient=wx.VERTICAL)
        
                self._init_coll_boxSizer1_Items(self.boxSizer1)
                self._init_coll_boxSizer2_Items(self.boxSizer2)
        
                self.SetSizer(self.boxSizer1)
                self.panel1.SetSizer(self.boxSizer2)
        
            def _init_ctrls(self, prnt):
                # generated method, don't edit
                wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(304, 151),
                        size=wx.Size(732, 517), style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
                self.SetClientSize(wx.Size(724, 490))
        
                self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self, pos=wx.Point(0, 0),
                        size=wx.Size(724, 490), style=wx.TAB_TRAVERSAL)
        
                self.notebook1 = wx.Notebook(id=wxID_FRAME1NOTEBOOK1, name='notebook1', parent=self.panel1,
                        pos=wx.Point(0, 0), size=wx.Size(724, 490), style=0)
        
                self.splitterWindow1 = wx.SplitterWindow(id=wxID_FRAME1SPLITTERWINDOW1,
                        name='splitterWindow1', parent=self.notebook1, pos=wx.Point(0, 0), size=wx.Size(716,
                        464), style=wx.SP_LIVE_UPDATE | wx.SP_3D)
                self.splitterWindow1.SetNeedUpdating(True)
        
                self.notebook2 = wx.Notebook(id=wxID_FRAME1NOTEBOOK2, name='notebook2',
                        parent=self.splitterWindow1, pos=wx.Point(0, 0), size=wx.Size(282, 464),
                        style=wx.NB_LEFT)
        
                self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label='button1', name='button1',
                        parent=self.splitterWindow1, pos=wx.Point(286, 0), size=wx.Size(430, 464), style=0)
                self.splitterWindow1.SplitVertically(self.notebook2, self.button1, 200)
        
                self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1, label='staticText1',
                        name='staticText1', parent=self.notebook2, pos=wx.Point(0, 0), size=wx.Size(254,
                        456), style=0)
        
                self._init_coll_notebook1_Pages(self.notebook1)
                self._init_coll_notebook2_Pages(self.notebook2)
        
                self._init_sizers()
        
            def __init__(self, parent):
                self._init_ctrls(parent)
        
        if __name__ == '__main__':
            app = wx.PySimpleApp()
            frame = create(parent=None)
            frame.Show()
            app.MainLoop()

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          If you are interested in trying the latest version of Boa Constructor, there are instruction for getting if from the CVS on SourceForge here.

          Comment

          Working...