[wxPython] Notebook and multiple sizers

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Notebook and multiple sizers

Daniel Glassey-6
I'm trying to put a notebook that is in a sizer on a panel with a
toolbar inside another sizer that is on the mainframe.

The pages that I add to the notebook don't display, but if I just have
the notebook in the main sizer it is ok.

Demonstration code is below.

Daniel


--
from wxPython.wx import *
#from pySword.pySword import *
from wxPython.html import *
from wxPython.lib.sizers import *

## Create a new pFrame class, derived from the wxPython Frame.
class SwordFrame(wxFrame):

        def __init__(self, parent, id, title):
                # First, call the base class' __init__ method to create the pFrame
                wxFrame.__init__(self, parent, id, title,
                        wxPoint(100, 100), wxSize(640, 240))

                self.MakeNoteBooks()
                self.MakeSizers()

        def MakeNoteBooks(self):
                mID = NewId()
                self.m_pSearchNote = ModuleNote(self, mID, 0, "Test2")

                mID = NewId()
                self.m_pSelectNote = ModuleNote(self, mID, 0, "Test")


                mID = NewId()
             self.m_pDictNote = ModulePanel(self, mID, "Dict")


        def MakeSizers(self):
                box1 = wxBoxSizer(wxVERTICAL)
                box1.Add(self.m_pSelectNote, 1)
                box1.Add(self.m_pSearchNote, 1)
                self.sizer = wxBoxSizer(wxHORIZONTAL)
                self.sizer.Add(box1, 1)
                self.sizer.Add(self.m_pDictNote, 2)
                #self.sizer.Add(self.Splitter, 2)
                #self.Splitter.SplitHorizontally(self.m_pTextNote, self.m_pDictNote, 240)
                self.sizer.FitWindow(self)

        def OnSize(self, event):
                self.m_pDictNote.Note.ResizeChildren()
                size = self.GetClientSize()
                self.sizer.Layout(size)

class ModuleNote(wxNotebook):

        def __init__(self, parent, id, nstyle, initmodule):
                wxNotebook.__init__(self, parent, id, style=nstyle)
                mID = NewId()
                self.AddModule(initmodule)

        def AddModule(self, module):
            print "Adding module ", module
            mID = NewId()
            newwin2 = wxHtmlWindow(self, mID)
            self.AddPage(newwin2, module, TRUE)
            self.CurWin = newwin2
            self.CurWin.SetPage("<H3>Test</H3>")              
            print "pos2=", newwin2.GetPositionTuple()
            print "size2=", newwin2.GetSizeTuple()
           
class ModulePanel(wxPanel):

        def __init__(self, parent, id, module):
                # First, call the base class' __init__ method to create the pFrame
                wxPanel.__init__(self, parent, id)
                mID = NewId()
                self.Note = ModuleNote(self, mID, wxNO_BORDER|wxTB_FLAT, module)
                self.InitTools()
                self.MakeSizer()
                self.SetAutoLayout(true)
               
        def InitTools(self):
                mID = NewId()
                self.ToolBar = wxToolBar(self, mID)

                mID = NewId()
                self.ToolBar.AddTool(mID, wxNoRefBitmap('bitmaps/forward.bmp',   wxBITMAP_TYPE_BMP),wxNullBitmap, false, 5, -1, "Add another")
                EVT_TOOL(self, mID, self.OnTBClick)
                self.ToolBar.Realize()

        def MakeSizer(self):
                self.sizer = wxBoxSizer(wxVERTICAL)
                self.sizer.Add(self.ToolBar, 0)
                self.sizer.Add(self.Note, 0)

        def OnSize(self, event):
                self.Note.ResizeChildren()
                size = self.GetClientSize()
                self.sizer.Layout(size)

        def OnTBClick(self, event):
            self.Note.AddModule("Another")

class MyApp(wxApp):

        def OnInit(self):
                pFrame = SwordFrame(NULL, -1, "wxSword-Python")

                pFrame.SetAutoLayout(true)
                pFrame.Show(true)
                self.SetTopWindow(pFrame)
                return true

app = MyApp(0)     # Create an instance of the application class
app.MainLoop()     # Tell it to start processing events


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Notebook and multiple sizers

Robin Dunn
> I'm trying to put a notebook that is in a sizer on a panel with a
> toolbar inside another sizer that is on the mainframe.
>
> The pages that I add to the notebook don't display, but if I just have
> the notebook in the main sizer it is ok.
>
> Demonstration code is below.
>


In ModulePanel.MakeSizer change

        self.sizer.Add(self.Note, 0)

to

        self.sizer.Add(self.Note, 1)

in order for the notebook to grow to fill remaining space.  (The page is
actually there on the notebook, but it has no space to display itself in.)
Also you need to add the following to ModulePanel.OnTBClick after adding the
new pages:

        self.Note.ResizeChildren()

This gets around a refresh bug for newly added pages, it forces a resize
event on the children so then they ask the notebook how big they should be.


--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!





_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users