Layout witout resize don't work ?

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 change.
If resize the window with the mouse, the label is moved to the proper position.

Making test if i do:

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

It work, but the window is resized twice. I can avoid the flicker with Freeze and Thaw, but, is there another method to do it?

I attach a sample.

Thanks.

Test_ShowLabel.py (2.33 KB)

···

--
*****************************************
Oswaldo Hernández
oswaldo (@) soft-com (.) es
*****************************************

Try self.FitInside() instead. I think that works.

Gre7g

···

--- Oswaldo Hernández <listas@soft-com.es> wrote:

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()

____________________________________________________________________________________
Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food & Drink Q&A.
http://answers.yahoo.com/dir/?link=list&sid=396545367

Gre7g Luterman escribió:

···

--- Oswaldo Hernández <listas@soft-com.es> wrote:

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()

Try self.FitInside() instead. I think that works.

No, no works. Until the Frame is resized with the mouse, the label is showed in wrong position.

Thanks.

--
*****************************************
Oswaldo Hernández
oswaldo (@) soft-com (.) es
*****************************************

Yeah, I'm having the same sort of problem now that I'm
dynamically adding items to my sizer.

I've got a wxPanel that contains a wxFlexGridSizer
which in turn contains a variety of controls. When I
insert items into my sizer, I call:

self.SetSizerAndFit(self.Grid)

which gets the display *MOSTLY* correct. However,
some of my rows have been marked "growable" by calling
AddGrowableRow. When the SetSizerAndFit is initially
called, these growable rows are not "grown". Instead,
they are at their minimum height until you begin to
resize the window.

Does anyone know a way that I can force the sizer to
recalculate? I've tried a variety of things, but none
of them seem to work.

Gre7g

···

--- Oswaldo Hernández <listas@soft-com.es> wrote:

No, no works. Until the Frame is resized with the
mouse, the label is showed in wrong position.

      ____________________________________________________________________________________
Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/

Oops. Nevermind. Layout() is working now. I had
another error in my code.

Gre7g

···

--- Gre7g Luterman <hafeliel@yahoo.com> wrote:

Yeah, I'm having the same sort of problem now that
I'm
dynamically adding items to my sizer.

I've got a wxPanel that contains a wxFlexGridSizer
which in turn contains a variety of controls. When
I
insert items into my sizer, I call:

self.SetSizerAndFit(self.Grid)

which gets the display *MOSTLY* correct. However,
some of my rows have been marked "growable" by
calling
AddGrowableRow. When the SetSizerAndFit is
initially
called, these growable rows are not "grown".
Instead,
they are at their minimum height until you begin to
resize the window.

Does anyone know a way that I can force the sizer to
recalculate? I've tried a variety of things, but
none
of them seem to work.

Gre7g

____________________________________________________________________________________
Sick sense of humor? Visit Yahoo! TV's
Comedy with an Edge to see what's on, when.
http://tv.yahoo.com/collections/222

Oswaldo Hernández wrote:

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 change.
If resize the window with the mouse, the label is moved to the proper position.

When you call self.Layout that results in a call to the frame's sizer's Layout method. Since the only thing in that sizer is the main panel, and since the panel is not changing size, then the layout process stops there. On the other hand when you change the size of the frame then the size of the panel changes too and so its sizer's Layout is called and since it contains the label then it is positioned where you want it to be.

So to solve your problem don't call the frame's Layout, but he panel's. You you can also do it by asking the label for the sizer that contains it and then call Layout there, so:

  self.panel.Layout()

or:

  self.label_msg.GetContainingSizer().Layout()

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn escribió:

Oswaldo Hernández wrote:

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 change.
If resize the window with the mouse, the label is moved to the proper position.

When you call self.Layout that results in a call to the frame's sizer's Layout method. Since the only thing in that sizer is the main panel, and since the panel is not changing size, then the layout process stops there. On the other hand when you change the size of the frame then the size of the panel changes too and so its sizer's Layout is called and since it contains the label then it is positioned where you want it to be.

So to solve your problem don't call the frame's Layout, but he panel's. You you can also do it by asking the label for the sizer that contains it and then call Layout there, so:

    self.panel.Layout()

or:

    self.label_msg.GetContainingSizer().Layout()

Anohter lesson about sizers :slight_smile:

Thanks Robin.

···

--
*****************************************
Oswaldo Hernández
oswaldo (@) soft-com (.) es
*****************************************