Layout witout resize don't work ?

Oswaldo Hernández listas at soft-com.es
Fri Jun 29 09:27:07 PDT 2007


Hello all,

On a Frame I want show/hide a label. To do it, i create a label on __init__=
, put on the ziser and =

hide it.

When i need show the label i do:
self.label.Show()
self.Layout()

But the label is showed in top/left corner.
I suppose that the layout do not the work because the window size do not ch=
ange.
If resize the window with the mouse, the label is moved to the proper posit=
ion.

Making test if i do:

self.label.Show()
s =3D self.GetSize()
self.GetSizer().SetSizeHints(self)
self.SetSize(s)

It work, but the window is resized twice. I can avoid the flicker with Free=
ze and Thaw, but, is =

there another method to do it?

I attach a sample.

Thanks.

-- =

*****************************************
Oswaldo Hern=E1ndez
oswaldo (@) soft-com (.) es
*****************************************
-------------- next part --------------
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import wx
       =

    =


class mFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        kwds["style"] =3D wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        =

        sizer_frame =3D wx.BoxSizer(wx.HORIZONTAL)
        self.SetSizer(sizer_frame)
        =

        self.panel =3D wx.Panel(self, -1)
        sizer_frame.Add(self.panel, 1, wx.EXPAND, 0)        =

        =

        sizer_panel =3D wx.BoxSizer(wx.VERTICAL)
        self.panel.SetSizer(sizer_panel)
        =

        self.textb =3D wx.TextCtrl(self.panel, -1, "", style=3Dwx.TE_PROCES=
S_ENTER )        =

        sizer_panel.Add(self.textb, 0, wx.EXPAND)
        =

        # message label
        self.label_msg =3D wx.StaticText(self.panel, -1, "Message")
        self.label_msg.SetBackgroundColour(wx.ColourRGB(0xCC66FF))        =

        sizer_panel.Add(self.label_msg, 0, wx.EXPAND)
        self.label_msg.Show(False)
        =

#        sizer_cabecera.Add(self.label_1, 0, wx.ALL|wx.ALIGN_CENTER_VERTICA=
L, 3)
#        sizer_cabecera.Add(self.fil_valor, 1, wx.ALL|wx.EXPAND, 3)

        self.lista =3D wx.ListCtrl(self.panel, -1)                =

        sizer_panel.Add(self.lista, 2, wx.EXPAND)
        =

        self.btn =3D wx.Button(self.panel, -1, "Show and Layout")
        sizer_panel.Add(self.btn,0)
        =

        self.btn2 =3D wx.Button(self.panel, -1, "Show and Resize")
        sizer_panel.Add(self.btn2,0)

        # init Layout
        sizer_frame.SetSizeHints(self)
        sizer_frame.Fit(self)
        self.SetAutoLayout(True)
        self.Layout()
        =

        # set the initial size
        self.SetSize((500, 350))

        self.btn.Bind(wx.EVT_BUTTON, self.OnBtnLayout)
        self.btn2.Bind(wx.EVT_BUTTON, self.OnBtnResize)
        =

    def OnBtnLayout(self, evt):
        self.label_msg.Show(not self.label_msg.IsShown())      =

        self.Layout()
        evt.Skip()  =

        =

    def OnBtnResize(self, evt):
        #self.Freeze()
        self.label_msg.Show(not self.label_msg.IsShown())        =

        s =3D self.GetSize()
        self.GetSizer().SetSizeHints(self)
        self.SetSize(s)
        #self.Thaw()
        evt.Skip()
        =

        =

if __name__ =3D=3D "__main__":
    app =3D wx.PySimpleApp(0)
    wx.InitAllImageHandlers()

    frame_1 =3D mFrame(None, -1, "")
    app.SetTopWindow(frame_1)
    frame_1.Show()

    app.MainLoop()



More information about the wxpython-users mailing list