sizing

Jack Andrews effbiae at gmail.com
Sun Jan 7 00:39:24 PST 2007


hi again,

having real problems with sizer-ing my dialog.  to reproduce my
problem, run the attached script and choose File->Open.  My dialog
isn't laid out as i'd like.  can't see the new toolbook control (it's
only showing a part of it...).

help much appreciated,



jack
-------------- next part --------------
import wx,wx.grid,wx.html,wx.aui,pyodbc,sys,time,wx.wizard
wg=3Dwx.grid;wiz=3Dwx.wizard;wp=3Dwiz.PyWizardPage
en=3Denumerate;ga=3Dgetattr;sa=3Dsetattr
import images
colourList =3D [ "Aquamarine", "Grey", "Blue", "Blue Violet", "Brown", "Cad=
et Blue",
               "Coral", "Wheat", ]
class ColoredPanel(wx.Window):
    def __init__(self, parent, color):
        wx.Window.__init__(self, parent, -1, style =3D wx.SIMPLE_BORDER)
        self.SetBackgroundColour(color)
        if wx.Platform =3D=3D '__WXGTK__':
            self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
def getNextImageID(count):
    imID =3D 0
    while True:
        yield imID
        imID +=3D 1
        if imID =3D=3D count:
            imID =3D 0
class TestTB(wx.Toolbook):
    def __init__(self,parent,id):
        wx.Toolbook.__init__(self, parent, id, style=3Dwx.BK_DEFAULT )
        # make an image list using the LBXX images
        il =3D wx.ImageList(32, 32)
        for x in range(12):
            f =3D getattr(images, 'getLB%02dBitmap' % (x+1))
            bmp =3D f()
            il.Add(bmp)
        self.AssignImageList(il)
        imageIdGenerator =3D getNextImageID(il.GetImageCount())
        =

        # Now make a bunch of panels for the list book
        first =3D True
        for colour in colourList:
            win =3D self.makeColorPanel(colour)
            self.AddPage(win, colour, imageId=3DimageIdGenerator.next())
            if first:
                st =3D wx.StaticText(win.win, -1,
                          "You can put nearly any type of window here,\n"
                          "and the toolbar can be on either side of the Too=
lbook",
                          wx.Point(10, 10))
                first =3D False

        self.Bind(wx.EVT_TOOLBOOK_PAGE_CHANGED, self.OnPageChanged)
        self.Bind(wx.EVT_TOOLBOOK_PAGE_CHANGING, self.OnPageChanging)


    def makeColorPanel(self, color):
        p =3D wx.Panel(self, -1)
        win =3D ColoredPanel(p, color)
        p.win =3D win
        def OnCPSize(evt, win=3Dwin):
            win.SetPosition((0,0))
            win.SetSize(evt.GetSize())
        p.Bind(wx.EVT_SIZE, OnCPSize)
        return p


    def OnPageChanged(self, event):
        old =3D event.GetOldSelection()
        new =3D event.GetSelection()
        sel =3D self.GetSelection()
        event.Skip()

    def OnPageChanging(self, event):
        old =3D event.GetOldSelection()
        new =3D event.GetSelection()
        sel =3D self.GetSelection()
        event.Skip()
class TestDialog(wx.Dialog):
    def __init__(self,parent):
        wx.Dialog.__init__(self,parent,-1,'title')
        self.ta=3Dwx.StaticText(self,-1,'static text')
        self.tb=3DTestTB(self,-1)
        sizer=3Dwx.BoxSizer(wx.VERTICAL)
        szf=3Dwx.EXPAND
        sizer.Add(self.ta,0,wx.EXPAND,1)
        sizer.Add(self.tb,1,wx.EXPAND,1)
        self.SetSizerAndFit(sizer)

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self,None,-1,"test")
        mb =3D wx.MenuBar()
        m=3Dwx.Menu()
        id1=3Dwx.NewId();id2=3Dwx.NewId()
        m.Append(id1,'&Open')
        m.Append(id2,'&Close')        =

        mb.Append(m,'File')
        self.Bind(wx.EVT_MENU,self.OnOpen,id=3Did1)
        self.Bind(wx.EVT_MENU,self.OnClose,id=3Did2)
        self.SetMenuBar(mb)
        self.SetMinSize(wx.Size(40,60))
    def OnOpen(self,e):
        dlg =3D TestDialog(self)
        dlg.CenterOnScreen()
        # this does not return until the dialog is closed.
        val =3D dlg.ShowModal()
        dlg.Destroy()
    def OnClose(self,e):self.Destroy();e.Skip()
class App(wx.App):
    def OnInit(self):
        frame =3D MyFrame()
        frame.Show(1)
        self.SetTopWindow(frame)
        return 1

if __name__ =3D=3D '__main__':
    app=3DApp()
    app.MainLoop()


More information about the wxpython-users mailing list