MiniFrame and sizers

Do sizers work the same way for miniframes as for wx.Frame?

I'm trying to follow one of the examples from the Learn Sizers
tutorial by ean-Michel Fauth, Switzerland, unfortunately my results
are different.

1. When I stretch the frame in my code, the widgets do not stretch.
    Stretching the frame in the LearnSizers code- the widgets stretch
& shrink accordingly.

2. When I call self.SetSizer(), all of my widgets are scrunched to the
upper left, and mostly invisible. The frame is still visible though.
This does not happen in the Learn Sizers program, which is how I based
my program.

# this code is from Learn Sizers: with_STaticBoxSizers.py

class MyPanel1(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        wred = ColWin(self, wx.ID_ANY, wx.RED)
        wblue = ColWin(self, wx.ID_ANY, wx.BLUE)
        wgreen = ColWin(self, wx.ID_ANY, wx.GREEN)

        b = 10 #inside the staticbox
        vsbsizer1 = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY,
'StaticboxSizer with a caption'), wx.VERTICAL)
        vsbsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
        vsbsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
        vsbsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
        self.SetSizer(vsbsizer1)

# the code above is from Learn Sizers

# This is a small piece of my code

        favoriteBox = wx.StaticBox(self._panel,wx.ID_ANY, "Favorite ",
pos=(10,10), size=sizeTup, style=wx.SB_RAISED )
        favoriteSizer = wx.StaticBoxSizer(favoriteBox , wx.VERTICAL)

        xStart = groupBox_X + 15
        yStart = groupBox_Y + 25

        self._lblFavorite = wx.StaticText(self._panel, wx.ID_ANY,
"Address", (xStart+21,yStart) )
        self._tbFavorite = wx.TextCtrl(self._panel, wx.ID_ANY, pos=
(xStart,yStart+17), size=(80,20))
        self._tbFavorite.SetFont(wx.Font(9, wx.FONTFAMILY_MODERN,
wx.NORMAL, wx.NORMAL))

        border = 10
        favoriteSizer.Add(self._lblFavorite, 1, wx.EXPAND | wx.ALL,
border)
        favoriteSizer.Add(self._tbFavorite,1, wx.EXPAND | wx.ALL,
border)
# self.Sizer(favoriteSizer) # messes up the display

Does the miniFrame change how sizers respond?

First:

http://wiki.wxpython.org/MakingSampleApps

but, from a bit of your code, I may see an issue or two:

cappy2112 wrote:

Do sizers work the same way for miniframes as for wx.Frame?

no, but wx.Frame has the property that if it has only one child, it will expand that child to fit -- miniFrames may not do that, so if you're putting a MuPanel1 on a wx.miniframe, it way not expand automatically. You can use a sizer to do it, though.

also:

# This is a small piece of my code

        favoriteBox = wx.StaticBox(self._panel,wx.ID_ANY, "Favorite ",
pos=(10,10), size=sizeTup, style=wx.SB_RAISED )
        favoriteSizer = wx.StaticBoxSizer(favoriteBox , wx.VERTICAL)

so the parent of the StaticBox is self._panel

# self.Sizer(favoriteSizer) # messes up the display

and you are now setting the Siser on self.

HTH,

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

MakingSampleApps - wxPyWiki

Ok- will separate this window from my main code, then submit.

no, but wx.Frame has the property that if it has only one child, it will
expand that child to fit -- miniFrames may not do that, so if you're
putting a MuPanel1 on a wx.miniframe, it way not expand automatically.

You can use a sizer to do it, though.

I have a panel on the miniframe, and several widgets on the panel.
Would you elaborate?

so the parent of the StaticBox is self._panel

Yes

> # self.Sizer(favoriteSizer) # messes up the display

and you are now setting the Siser on self.

The example from LearnSizers does the same thing- but works correctly.
I don't see how self.Sizer(favoriteSizer) is a problem though.

Hi,

I'm using Windows XP (64-bit) with Python 2.5.2 (32-bit) and wx version 2.8.10.1, but I've downloaded AGW/aui from SVN for the most up to date version.

I'm trying to create an AUI GUI with an AuiNotebook in one pane that contains a page with AUI panes inside that page and that can only be "managed" and re-arranged inside that page. So far, I've managed to create a widget just to that point, but when I try to resize the panes inside the AuiNotebook page, they don't behave properly.

I've attached an example program called aui_in_auinotebook.py. I've tried to keep it simple. In the main AUI I've got two panes, Center is a TextCtrl and the Left one is an AuiNotebook. There are two pages in the AuiNotebook that are simple TextCtrls. You may need to resize the panes to see them.

If you click on File->NewNotebookPage, a third page is created with three panes in it. That is shown in the attached JPG. If you resize or otherwise grab one of these panes, then they start showing odd behaviour.

All that I can think of is that I am not passing the right thing to my second instantiation of the AuiManager. But, maybe these two widgets actually don't mix.

My endpoint is to create a scientific application that can load multiple data sets. Each data set will have a page in the AuiNotebook where the data is plotted in one pane and other info displayed in other panes. By using an AUI in AuiNotebook panes, I'd be able to load two data sets and then split them apart side by side in the AuiNotebook to compare data.

Any thoughts would be appreciated.

thanks,

Brian.

aui_in_auinotebook.py (3.26 KB)

aui_in_auinotebook.jpg

First:

MakingSampleApps - wxPyWiki

Ok- I'm now using a small, stand alone version which looks exactly
like my frame & has the same problem (the widgets don't stretch when
the frame does).

But I'm using wx.Frame instead of the miniFrame because of your
suggestion.

However, using the Web interface for this list, I cannot attach any
files, so I'll have to wait until the digest arrives, then reply to
that subject.

cappy2112 wrote:

However, using the Web interface for this list, I cannot attach any
files,

  so I'll have to wait until the digest arrives, then reply to

that subject.

you should be able to simply send an email to:

wxpython-users@googlegroups.com

it won't be the same thread, but that's not too big a deal.

You could also cut&paste the code straight into the note, though that does tend to mangle it -- darn that google for not supporting attachments!

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

you should be able to simply send an email to:

wxpython-users@googlegroups.com

Yes, but I'd rather follow the thread. It helps me in the future when
I can go back and read about my goofs, and
if threaded correctly it may help others.

You could also cut&paste the code straight into the note, though that
does tend to mangle it -- darn that google for not supporting attachments!

I'm trying to follow your advice below about attaching vs pasting.
http://wiki.wxpython.org/MakingSampleApps

Hi,

MakingSampleApps - wxPyWiki

Ok- will separate this window from my main code, then submit.

no, but wx.Frame has the property that if it has only one child, it will
expand that child to fit -- miniFrames may not do that, so if you're
putting a MuPanel1 on a wx.miniframe, it way not expand automatically.

You can use a sizer to do it, though.

I have a panel on the miniframe, and several widgets on the panel.
Would you elaborate?

A wx.Frame will automatically expand its first child to fill the window space by automatically putting it in a sizer, other top level windows do not do this so you need to do it yourself by putting your panel in a sizer.

so the parent of the StaticBox is self._panel

Yes

# self.Sizer(favoriteSizer) # messes up the display

and you are now setting the Siser on self.

The example from LearnSizers does the same thing- but works correctly.
I don't see how self.Sizer(favoriteSizer) is a problem though.

The favoriteSizer is a sizer for windows that belong to the panel which is a child of self (MiniFrame). Its an issue of hierarchy, the frames sizer should size its children not its grandchildren. The difference in the other example is that the sizer is sizing the children of the frame and not the frames panel.

minframe.py (994 Bytes)

···

On Jan 4, 2010, at 4:05 PM, cappy2112 wrote:

cappy2112 wrote:

you should be able to simply send an email to:

wxpython-users@googlegroups.com

Yes, but I'd rather follow the thread.

I think you'll break the thread if you reply to a digest anyway.

You could also cut&paste the code straight into the note, though that
does tend to mangle it -- darn that google for not supporting attachments!

I'm trying to follow your advice below about attaching vs pasting.
MakingSampleApps - wxPyWiki

Not mine, but yes, that is good advise, but if you can't you can't.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

It doesn't actually use a sizer to do it, but the effect is pretty much the same.

···

On 1/4/10 3:57 PM, Cody Precord wrote:

A wx.Frame will automatically expand its first child to fill the
window space by automatically putting it in a sizer,

--
Robin Dunn
Software Craftsman

Looks like your on_new method is creating text controls with a parent
of "self" (i.e. the Main class) instead of the wx.Panel that you've
just created.

In the on_new method, if you change the CreateTextCtrl calls to use
self.ctrl instead of self, your demo app works. So, instead of:

        self.ctrl._mgr.AddPane(CreateTextCtrl(self) ...

use:

        self.ctrl._mgr.AddPane(CreateTextCtrl(self.ctrl) ...

Rob

···

On Mon, Jan 4, 2010 at 2:05 PM, Brian J. Soher <bsoher@briansoher.com> wrote:

I'm trying to create an AUI GUI with an AuiNotebook in one pane that
contains a page with AUI panes inside that page and that can only be
"managed" and re-arranged inside that page.

Yep. That did it, both in my example and the (messy) original code. Thanks for the help! Happy 2010.

Brian.

···

At 09:33 PM 1/4/2010, you wrote:

On Mon, Jan 4, 2010 at 2:05 PM, Brian J. Soher <bsoher@briansoher.com> wrote:
> I'm trying to create an AUI GUI with an AuiNotebook in one pane that
> contains a page with AUI panes inside that page and that can only be
> "managed" and re-arranged inside that page.

Looks like your on_new method is creating text controls with a parent
of "self" (i.e. the Main class) instead of the wx.Panel that you've
just created.

In the on_new method, if you change the CreateTextCtrl calls to use
self.ctrl instead of self, your demo app works. So, instead of:

        self.ctrl._mgr.AddPane(CreateTextCtrl(self) ...

use:

        self.ctrl._mgr.AddPane(CreateTextCtrl(self.ctrl) ...

Rob

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

The favoriteSizer is a sizer for windows that belong to the panel
which is a child of self (MiniFrame). Its an issue of hierarchy, the
frames sizer should size its children not its grandchildren. The
difference in the other example is that the sizer is sizing the
children of the frame and not the frames panel.

minframe.py
< 1KViewDownload

Thanks Cody-
I'm looking at your code now- comparing it to mine.

Do sizers work the same way for miniframes as for wx.Frame?

I'm trying to follow one of the examples from the Learn Sizers
tutorial by ean-Michel Fauth, Switzerland, unfortunately my results
are different.

1. When I stretch the frame in my code, the widgets do not stretch.
Stretching the frame in the LearnSizers code- the widgets stretch
& shrink accordingly.

2. When I call self.SetSizer(), all of my widgets are scrunched to the
upper left, and mostly invisible. The frame is still visible though.
This does not happen in the Learn Sizers program, which is how I based
my program.

# this code is from Learn Sizers: with_STaticBoxSizers.py

...

Does the miniFrame change how sizers respond?

LearnSizer8 (and probably previous releases)

If you derive MyFrame (module baseframe.py), the top level frame
of all the demos, from a wx.MiniFrame instead of a wx.Frame you
will see the sizers are working correctly.

However this is a proof of concept. Using MiniFrames as
top level frames is not correct.

Jean-Michel Fauth, Switzerland

···

On 4 jan, 21:36, cappy2112 <cappy2...@gmail.com> wrote:

OK, after all the suggestions, and Cody's miniframe.py, I've finally
got my main program TLW -resizing normally.
I think the main issue was that I did not add self._panel to the final
sizer.

The only issue is the proportions & spacing between the widgets is
off, but I can probably work these out.

After having a few apps using sizers under my belt, they are still not
second-nature to me and seem to present as many difficulties as the
first program I wrote which used sizers :wink:

Thanks to all who replied

I find that sketching out my sizers with the appropriate widgets helps
me to conceptually see how it should all lay out. This is especially
true with complex layouts which require nested sizers.

Of course, the Widget Inspection Tool is handy too for showing sizer
borders and figuring out what's wrong with an application's setup.

···

On Jan 5, 1:06 pm, cappy2112 <cappy2...@gmail.com> wrote:

OK, after all the suggestions, and Cody's miniframe.py, I've finally
got my main program TLW -resizing normally.
I think the main issue was that I did not add self._panel to the final
sizer.

The only issue is the proportions & spacing between the widgets is
off, but I can probably work these out.

After having a few apps using sizers under my belt, they are still not
second-nature to me and seem to present as many difficulties as the
first program I wrote which used sizers :wink:

Thanks to all who replied

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

PyCon 2010 Atlanta Feb 19-21 http://us.pycon.org/

I find that sketching out my sizers with the appropriate widgets helps
me to conceptually see how it should all lay out.

This was once suggested to me before, and I did have a scratch pad
with some drawings on it.
However- it seems like one needs to understand sizers first, before
this approach is useful.
I was struggling with "should I put two widgets in a vertical sizer,
and then in a horizontal sizer", and vice-versa,
not too mention which sizer(s) to use.

I tried following WIA, and the examples/tutorials online but ended up
going astray :wink:

I even used the smallest program that I wrote which used sizers for a
guideline, and was actually pretty easy to figure out at
the time I wrote it.

Of course, the Widget Inspection Tool is handy too for showing sizer
borders and figuring out what's wrong with an application's setup.

I started by adding this Mixin- but couldn't make it work this time.
The method names and sequence of calls are too confusing..
I've used this a few programs ago too. :wink:

I think I described my process poorly. I actually sketch my
application and then draw boxes around various controls to simulate
sizers. I know how it's supposed to look without sizers, after all.

If I have a series of widgets running vertically or horizontally, then
I know they should go in that type of boxsizer. If I have widgets laid
out in a grid shape, then I know that a gridsizer (or a set of nested
box sizers) is the way to go.

Next, I create the sizers I need and add the widgets according to my
sketch. If it looks odd on some or all the lines, I adjust the border
widths, add or remove the EXPAND flag, mess with proportion, etc.

This is something else I should probably write a tutorial about...but
if I do, I don't know when I'll get to it.

···

On Jan 5, 1:45 pm, cappy2112 <cappy2...@gmail.com> wrote:

> I find that sketching out my sizers with the appropriate widgets helps
> me to conceptually see how it should all lay out.

This was once suggested to me before, and I did have a scratch pad
with some drawings on it.
However- it seems like one needs to understand sizers first, before
this approach is useful.
I was struggling with "should I put two widgets in a vertical sizer,
and then in a horizontal sizer", and vice-versa,
not too mention which sizer(s) to use.

I tried following WIA, and the examples/tutorials online but ended up
going astray :wink:

I even used the smallest program that I wrote which used sizers for a
guideline, and was actually pretty easy to figure out at
the time I wrote it.

> Of course, the Widget Inspection Tool is handy too for showing sizer
> borders and figuring out what's wrong with an application's setup.

I started by adding this Mixin- but couldn't make it work this time.
The method names and sequence of calls are too confusing..
I've used this a few programs ago too. :wink:

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

PyCon 2010 Atlanta Feb 19-21 http://us.pycon.org/

I think I described my process poorly. I actually sketch my
application and then draw boxes around various controls to simulate
sizers. I know how it's supposed to look without sizers, after all.

Not really- I followed you ok, but I left out some details.

I actually started using PythonCard's UI tool- to flesh out the widget
position, but not generate the code.
This was for the main GUI.

When my customer asked for a floating window to display data without
scrolling, I figured I would do it without sizers, so I could get it
done. When I realized the customer may want to stretch/shrink the
floating window, my blood went cold because I knew I *should* use
sizers for that window.

I did try sketching those 4 widgets, using dotted lines 4 sizers, and
had the same problem as when I go to the store to buy beer....
"Too many choices' :wink:

I always try to use BoxSizers, just to eliminate the others from the
choices.
I still see the widgets inside of BoxSizers in a grid layout in my
mind, but that's probably not right.

I'm sure I'll get this stuff under my belt, someday ..

I tend to use BoxSizers most of the time too. I think it's more
flexible that way, but it can also get down right confusing too. You
can get it, but it takes longer than it probably should.

···

On Jan 5, 2:25 pm, cappy2112 <cappy2...@gmail.com> wrote:

> I think I described my process poorly. I actually sketch my
> application and then draw boxes around various controls to simulate
> sizers. I know how it's supposed to look without sizers, after all.

Not really- I followed you ok, but I left out some details.

I actually started using PythonCard's UI tool- to flesh out the widget
position, but not generate the code.
This was for the main GUI.

When my customer asked for a floating window to display data without
scrolling, I figured I would do it without sizers, so I could get it
done. When I realized the customer may want to stretch/shrink the
floating window, my blood went cold because I knew I *should* use
sizers for that window.

I did try sketching those 4 widgets, using dotted lines 4 sizers, and
had the same problem as when I go to the store to buy beer....
"Too many choices' :wink:

I always try to use BoxSizers, just to eliminate the others from the
choices.
I still see the widgets inside of BoxSizers in a grid layout in my
mind, but that's probably not right.

I'm sure I'll get this stuff under my belt, someday ..

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

PyCon 2010 Atlanta Feb 19-21 http://us.pycon.org/