[wxPython] Sizers - Again

My current problem with sizers is this:

A Scrolled Window has a wxBoxSizer
Each item in the wxBoxSizer is an object of a widget class derived from wxPanel.
The wxPanel widget class also contains a sizer, which is placed within the sizer of the wxBoxSizer of the scrolled window.
All the widgets are created dynamically, triggered by buttons, one to create the wxPanel, a second one to extend it with additional items in its sizer. Initially the wxPanel is created with vertical size 70, and is later extended by adding new items to the sizer.
\
The problem is that the added items in the wxPanel's boxSizer do not seem to be affecting the size calculation of the ScrolledWindow's sizer's size.

I can observe the wxPanel Box sizer being extened in height by 10 each time I add to the wxPanel's sizer. That works ok. But when I add an entirely new panel, the scrolled Window's sizer still has the original calculated dimensions for the wxpanel with vertical size 70. This means that the added items in the panels are being obscured by new panels.

After adding a panel the window looks like this:

10
20
30
40
50
60
70

After adding items to the panel, the length gets longer

···

---
10
20
...
60
70
80
---
But when I add a new panel, I see:

---
10
20
...
60
70
---
10
20
...
60
70
---
         
How do I get the sizer in the Scrolled Window to recognize that the size of the first item in its sizer has changed.

-Pat

Here's a demo, illiustrating the problem.

from wxPython.wx import *

import UserList
import string
import time

def menuItem( app, menu, label, command, help):
    id=wxNewId()
    menu.Append(id, label, help )
    EVT_MENU( app, id, command)
def menuSeparator(app, menu):
    menu.AppendSeparator()
class UiMenus:
    def __init__(self,parent,controller):
        c=controller
        parent.mainmenu = wxMenuBar()
        file = wxMenu()
        menuItem(parent, file, '&Exit', c.fileExit, '')
        parent.mainmenu.Append (file, '&File')
        parent.SetMenuBar (parent.mainmenu) # Attach the menu bar to window.

class UiToolBars:
    def __init__(self,app,controller):
        c=controller
        tb = app.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER)
        id = wxNewId()
        tb.AddControl(wxButton(
            tb, id, 'New Panel', wxPoint(0,0),wxSize(80,20 )))
        EVT_BUTTON(app, id, c.toolNewPanel)
        id = wxNewId()
        tb.AddControl(wxButton(
            tb, id, 'New Addon', wxPoint(0,20),wxSize(80,20)))
        EVT_BUTTON(app, id, c.toolNewPanelAddon)
        
        tb.Realize()
        
class UiStatusBar:
    def __init__(self,parent):
        self.parent=parent
        sb = parent.CreateStatusBar(2)
        parent.SetStatusText("This is the statusbar",0)
        sb.SetStatusWidths([-1, 150])
        self.timer = wxPyTimer(self.Notify)
        self.timer.Start(1000)
        self.Notify()
    def Notify(self):
        t = time.localtime(time.time())
        st = time.strftime(" %d-%b-%Y %I:%M:%S", t)
        self.parent.SetStatusText(st, 1)

    def __del__(self):
        self.timer.Stop()
        del self.timer

class Addon:
    def __init__(self):
        self.data=''

class Item:
    def __init__(self):
        self.description = ''
        self.sessionsList=[]

    def update ( self, description, completed, activateDate, status):
        self.description = description
        self.completed = completed
        self.activateDate = activateDate
        self.activationStatus = status
        
    def addAddon( self, session):
        self.sessionsList.add(session)

class Data:
    def __init__(self):
        self.ItemList=ItemList()
class Tools:
    def __init__(self,data):
        self.data=data
        self.ui=None
    def setUi(self, ui):
        self.ui = ui

    def fileExit(self, event):
        print "FileExit Not implemented"
        print self
        print event
        
    def toolNewPanel(self, event):
      #print self.toolNewPanel
        newItem=Item()
        self.ui.content.addItem(newItem)
        
    def toolNewPanelAddon(self, event):
      #print self.toolNewPanelAddon
        newPanelAddon=None
        self.ui.content.addAddon(newPanelAddon)

class Addon:
    def __init__(self,parentWindow,parentSizer,item=None):
        self.sizer= wxBoxSizer(wxHORIZONTAL)

        self.description = wxTextCtrl(parentWindow, -1,
                                        'detail description',
                                        wxPoint(-1,-1), wxSize(150,20),
                                        0, wxDefaultValidator)

        self.sizer.Add(self.description,0)
        parentSizer.Add(self.sizer)

class AddonList:
    
    def __init__(self,parent,parentSizer,item=None):
        self.parentWindow=parent
        self.sessionList = []
        self.sizer = wxBoxSizer(wxVERTICAL)
        parentSizer.Add(self.sizer)

class ItemFrame(wxPanel):
    def __init__(self,parent,id=-1,item=None):
        wxPanel.__init__(self, parent, id, wxPoint(-1,-1), wxSize(800,60),
                         wxSUNKEN_BORDER)
        self.sizer = wxBoxSizer(wxVERTICAL)
        self.description = wxTextCtrl(self, -1, 'description',
                                      wxPoint(-1,-1), wxSize(450,60),
                                      0, wxDefaultValidator)
        id=wxNewId()

        self.sizer.Add(self.description,0)
        self.addonList = AddonList(self,self.sizer,item)

        self.SetAutoLayout(1)
        self.sizer.Layout()

class UiContent(wxScrolledWindow):
    def __init__(self,app,id,data=None):
        wxScrolledWindow.__init__(self,app, -1)
        self.parent=app
        self.panels = []
        self.sizer = wxBoxSizer(wxVERTICAL)
        self.SetSizer(self.sizer)
        self.SetAutoLayout(1)
        self.Show(true)
        self.SetScrollbars(5,5,50,0)
        self.currentItem=None
        self.n=0

    def addItem(self,item=None):
        id=wxNewId()

        self.currentItem = f =ItemFrame(self,id,item)
        self.n=self.n+1
        self.sizer.Add(f,0, wxEXPAND)
        self.panels.append(f)

        self.SetClientSize(self.parent.GetClientSize())
        self.setScrollbars

    def addAddon(self,addon=None):
        id=wxNewId()
        s=Addon(self.currentItem,
                  self.currentItem.addonList.sizer,
                  addon)

        self.currentItem.SetClientSize(self.currentItem.sizer.CalcMin())
        self.currentItem.sizer.Layout()
        #self.sizer.Layout() Adding this makes the new addon invisible
        self.setScrollbars()
    def setScrollbars(self):
        self.SetScrollbars(5,5,20,self.n*39)
        
class Ui(wxFrame):
    def __init__(self, parent, id, title):
        wxFrame.__init__(self, parent, -1, title, size = (500, 600),
                         style=wxDEFAULT_FRAME_STYLE)
    def start(self, data, controller):
        self.menus = UiMenus(self,controller)
        self.ToolBars = UiToolBars(self,controller)
        self.statusBar = UiStatusBar(self)
        self.content = UiContent(self,data)
        self.Show(true)

class SizersDemo(wxApp):
    def OnInit(self):
        self.data = None
        self.controller=Tools(self.data)
        self.ui = Ui(None, -1, "SizersDemo")
        self.controller.setUi(self.ui)
        self.ui.start(self.data, self.controller)
        self.SetTopWindow(self.ui)
        return true

if __name__ == "__main__":
    sizersDemo = SizersDemo(0)
    sizersDemo.MainLoop()

The problem is that the added items in the wxPanel's boxSizer
do not seem to be affecting the size calculation of the
ScrolledWindow's sizer's size.

Because you need to tell the sizer that you changed the item's size...

I made the following changes in your sample code:

1. In ItemFrame.__init__ add self.SetSizer(self.sizer) so the panel will
actually use the sizer you are making for it.

2. In UiContent.addItem add self.Layout to the end so that it will run the
layout algorithm again.

3. In UiContent.addAddon I couldn't follow all you were doing with the Addon
class and addonList and so on. I get the feeling that you are creating more
sizers than you need... I replaced the method with the following and it
does what I think you were attempting to do in just a few lines:

        panel = self.currentItem
        psizer = panel.GetSizer()
        desc = wxTextCtrl(panel, -1, 'detail description',
                          size=(150,20))
        psizer.Add(desc)
        psizer.Fit(panel)
        self.sizer.SetItemMinSize(panel, panel.GetSize().width,
                                  panel.GetSize().height)
        self.Layout()

···

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

ok all that makes it work as expected. The key seems to be the SetItemMinSize

You call SetItemMinSize with the current items panel width and height. What exactly is being set there? The width and height of the current panel vary up and down depending on the number of detail items. Is it the individual item in the sizer associated with the panel reference that is being set?

The extra sizer for description is to be expanded with widgets for the other attributes of the detail item. This example is a minimalized cut down of a work in progress. I removed a bit too much detail and it obscured why that third level sizer is present. Also the names Item and "addon" aren't too good. A better name for addOn would be ItemDetails.

I'll do some more cleanup and expand the ItemDetails to more than one widget. Do you think this would make a good example for the wxPython Demos?

-Pat

> The problem is that the added items in the wxPanel's boxSizer
> do not seem to be affecting the size calculation of the
> ScrolledWindow's sizer's size.

Because you need to tell the sizer that you changed the item's size...

I made the following changes in your sample code:

1. In ItemFrame.__init__ add self.SetSizer(self.sizer) so the panel will
actually use the sizer you are making for it.

2. In UiContent.addItem add self.Layout to the end so that it will run the
layout algorithm again.

When I tried # 1 and #2 individually they seemed to have no effect, so I removed them. These are apparently still needed to make the change in #3 actually work so I put them back in.

3. In UiContent.addAddon I couldn't follow all you were doing with the Addon
class and addonList and so on. I get the feeling that you are creating more
sizers than you need...

I replaced the method with the following and it
does what I think you were attempting to do in just a few lines:

        panel = self.currentItem
        psizer = panel.GetSizer()
        desc = wxTextCtrl(panel, -1, 'detail description',
                          size=(150,20))
        psizer.Add(desc)
        psizer.Fit(panel)
        self.sizer.SetItemMinSize(panel, panel.GetSize().width,
                                  panel.GetSize().height)
        self.Layout()

This seems like a pretty good example now of the kind of thing I'm attempting. Still to work out is the scrolling behavior for the ScrolledWindow.

···

On Mon, 4 Mar 2002 09:53:46 -0800 "Robin Dunn" <robin@alldunn.com> wrote:

ok all that makes it work as expected. The key seems to be
the SetItemMinSize

Yes.

You call SetItemMinSize with the current items panel width
and height. What exactly is being set there?

Take a look at the previous line. It is resetting the size of the panel
based on the new contents of it's sizer. Then the new size of the panel is
given to the main window's sizer as the new minimum (or default) size.

···

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

The problem I have had learning to use sizers is that there's not a lot of information about what the sizer objects properties are, and how the methods of the sizer classes work together to produce a desired result.

Through the examples in the documentation and the example we're discussing here, things are becoming clearer, but I still don't fully understand which methods affect the size of the sizer itself, or which the size of the individual elements of the sizer. Its not yet clear exactly what needs to get set and when although your corrections to my example have helped greatly.

Having some information about the internal properties stored in the sizer and which methods read and set these properties in the wxWindows manual might make things clearer. I think its at least necessary to label the relevant properties conceptually and refer to them by these labels in the method descriptions. The current descripton of the wxSizer class only hints at the properties involved.

For example, sizers probably at least have a size for the sizer itself and a size and a position for each element added to the sizer. Can the description of the sizer classes be improved by listing these groups of properties? Can the way various types of sizers treat these properties be described and compared? Can the description of how the methods work be written in terms of the specific groups of properties read or written by the method?

-Pat

···

On Mon, 4 Mar 2002 17:45:29 -0800 "Robin Dunn" <robin@alldunn.com> wrote:

> ok all that makes it work as expected. The key seems to be
> the SetItemMinSize

Yes.

>
> You call SetItemMinSize with the current items panel width
> and height. What exactly is being set there?

Take a look at the previous line. It is resetting the size of the panel
based on the new contents of it's sizer. Then the new size of the panel is
given to the main window's sizer as the new minimum (or default) size.

Patrick Callahan wrote:

Having some information about the internal properties stored in the sizer and which methods read and set these properties in the wxWindows manual might make things clearer. I think its at least necessary to label the relevant properties conceptually and refer to them by these labels in the method descriptions. The current descripton of the wxSizer class only hints at the properties involved.

Robin has recently added some stuff to the Wiki. Take a look there, and
if it doesn't have the information you are looking for, perhaps you
could add it.

I understand that you are still struggling with your understanding, but
if you put something there, creating a good outline, and leaving holes
and questions when you don't know something, you can then post a message
here about it, and we'll go in and try to fill it in.

We all want good docs, but it's a lot of work to write them!

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (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

So I added the demo program I'm working on to the wiki. You can find it under

http://wiki.wxpython.org/index.cgi/CompleteApplication
or
http://wiki.wxpython.org/index.cgi/DemoA_2epy

The demo is incomplete. You are welcome to modify it by suggesting changes or putting diffs at the bottom. If you want to actively help with developing this demo, e-mail me.

-Pat Callahan

···

On Wed, 06 Mar 2002 10:00:20 -0800 Chris Barker <Chris.Barker@noaa.gov> wrote:

Patrick Callahan wrote:

> Having some information about the internal properties stored in the sizer and which methods read and set these properties in the wxWindows manual might make things clearer. I think its at least necessary to label the relevant properties conceptually and refer to them by these labels in the method descriptions. The current descripton of the wxSizer class only hints at the properties involved.

Robin has recently added some stuff to the Wiki. Take a look there, and
if it doesn't have the information you are looking for, perhaps you
could add it.

I understand that you are still struggling with your understanding, but
if you put something there, creating a good outline, and leaving holes
and questions when you don't know something, you can then post a message
here about it, and we'll go in and try to fill it in.

We all want good docs, but it's a lot of work to write them!

-Chris

Patrick Callahan wrote:

So I added the demo program I'm working on to the wiki. You can find it under

http://wiki.wxpython.org/index.cgi/CompleteApplication
or
http://wiki.wxpython.org/index.cgi/DemoA_2epy

The demo is incomplete. You are welcome to modify it by suggesting changes or putting diffs at the bottom. If you want to actively help with developing this demo, e-mail me.

Good idea, but I have no idea what the demo application does, perhaps we
should develop something useful, if small. I Also think that a
sizers-only demo of some sort would be a good idea.

Anyway, I have a small application that I wrote for converting units (ft
to meters, etc). It uses sizers, has anned for persistant storage etc.
Perhaps it would be a good basis for your demo. I'd like to add a way to
interactively add new units, which would allow it to demonsrate
additional features. I've enclosed it if you're interested.

-Chris

Converter.py (9.34 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (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

Hi,

After recently moving away from tkinter to use wxPython ... I have found
that the only thing really letting this package down is lack of
documentation.

Would anyone be interested in helping to write/ contributing to a wxWindows
open source book ?

regards

Ben Catanzariti

Oops ...correction ... previous_message.replace('wxWindows', 'wxPython')

Ben

···

----- Original Message -----
From: "Ben" <benc@rehame.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Friday, March 08, 2002 12:39 PM
Subject: [wxPython] wxWindows Book

Hi,

After recently moving away from tkinter to use wxPython ... I have found
that the only thing really letting this package down is lack of
documentation.

Would anyone be interested in helping to write/ contributing to a

wxWindows

open source book ?

regards

Ben Catanzariti

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

Just a reminder that PythonCard (in cvs) and the release (0.6.4) coming out
in a few days uses direct subclasses of wxPython controls. This is relevant
to this thread because the PythonCard samples that use sizers may be
beneficial as sizer examples even if you're wanting to use wxPython without
PythonCard. The relevant samples are: doodle, findfiles, hopalong,
radioclient, resourceEditor, samples, simpleBrowser, textRouter, and turtle

Most of the samples use wxBoxSizer. The findfiles sample and positionSize
window of the resourceEditor use wxFlexGridSizer. The Message Watcher window
in debug.py also uses a wxBoxSizer.

ka

···

-----Original Message-----
From: wxpython-users-admin@lists.wxwindows.org
[mailto:wxpython-users-admin@lists.wxwindows.org]On Behalf Of Patrick
Callahan
Sent: Thursday, March 07, 2002 4:16 PM
To: wxpython-users@lists.wxwindows.org
Subject: Re: [wxPython] Sizers - Again

On Wed, 06 Mar 2002 10:00:20 -0800 > Chris Barker <Chris.Barker@noaa.gov> wrote:

> Patrick Callahan wrote:
>
> > Having some information about the internal properties stored
in the sizer and which methods read and set these properties in
the wxWindows manual might make things clearer. I think its at
least necessary to label the relevant properties conceptually and
refer to them by these labels in the method descriptions. The
current descripton of the wxSizer class only hints at the
properties involved.
>
> Robin has recently added some stuff to the Wiki. Take a look there, and
> if it doesn't have the information you are looking for, perhaps you
> could add it.
>
> I understand that you are still struggling with your understanding, but
> if you put something there, creating a good outline, and leaving holes
> and questions when you don't know something, you can then post a message
> here about it, and we'll go in and try to fill it in.
>
> We all want good docs, but it's a lot of work to write them!
>
> -Chris
>
>
So I added the demo program I'm working on to the wiki. You can
find it under

http://wiki.wxpython.org/index.cgi/CompleteApplication
or
http://wiki.wxpython.org/index.cgi/DemoA_2epy

The demo is incomplete. You are welcome to modify it by
suggesting changes or putting diffs at the bottom. If you want
to actively help with developing this demo, e-mail me.

-Pat Callahan

We should also be co-ordinating this effort with Robin Dunn. No sense having multiple sets of demos.

What do you think Robin?

Patrick Callahan wrote:

> So I added the demo program I'm working on to the wiki. You can find it under
>
> http://wiki.wxpython.org/index.cgi/CompleteApplication
> or
> http://wiki.wxpython.org/index.cgi/DemoA_2epy
>
> The demo is incomplete. You are welcome to modify it by suggesting changes or putting diffs at the bottom. If you want to actively help with developing this demo, e-mail me.

Good idea, but I have no idea what the demo application does, perhaps we
should develop something useful, if small. I Also think that a
sizers-only demo of some sort would be a good idea.

DemoA.py does absolutely nothing useful. The data structure exists only to demonstrate the use of sizers within sizers that dynamically expand in a scrolled window. The scrolling feature is not yet working.

The data structure in DemoA.py is deliberately simple and abstract but it is analogous to many common data structures such as
Invoice and Line Item
Overview and Point by Point Descriptions
Account and Transaction

The behavior of the application is meant to mirror the features an application in one of these problem domains would have without the clutter of being an actual application. The finished demo would be a good starting point for a variety of applications with a similar data model.

The wording of the description of the demo needs improvement. Perhaps the name of the "data objects" needs to be changed to something that makes describing the demo easier. Right now the demo is just a hack of a partially completed app.

Anyway, I have a small application that I wrote for converting units (ft
to meters, etc). It uses sizers, has anned for persistant storage etc.
Perhaps it would be a good basis for your demo. I'd like to add a way to
interactively add new units, which would allow it to demonsrate
additional features. I've enclosed it if you're interested.

-Chris

There's no reason we can't have multiple demo applications.

I think an app should be considered if it is:

o fairly small but robust. (your app certainly fits the bill here)
o usable as a template for new apps with minimal modification needed to remove and replace the application domain specific code.

To turn it into a true demo, we'd need to add explanations of some or all of the wxPython features used in the program.

I also think we should store the sources in some already existing controlled repository of sources such as sourceforge or the vault of parnassus. Having the source directly on the wiki is an invitation to the malicious to insert something nasty. I've put it there for the moment for discussion purposes and will add a warning not to run the code from there without reading EVERY line. For the moment its probably ok because not too many know its there yet.

···

On Thu, 07 Mar 2002 17:31:02 -0800 Chris Barker <Chris.Barker@noaa.gov> wrote:

Hi there,

I have looked through the mailing list and the wxPython demo for examples of
key events .... but can not seem to find anything on how key events are used
...
... in particular I want to create shortcut keys for an application ie.
trl - Q fires function 'x' ... would anyone be able to point me in the
right direction

thanks in advance

Ben Catnazariti

···

----- Original Message -----
From: "Ben" <benc@rehame.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Friday, March 08, 2002 12:44 PM
Subject: Re: [wxPython] wxWindows Book

Oops ...correction ... previous_message.replace('wxWindows', 'wxPython')

Ben

----- Original Message -----
From: "Ben" <benc@rehame.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Friday, March 08, 2002 12:39 PM
Subject: [wxPython] wxWindows Book

> Hi,
>
>
> After recently moving away from tkinter to use wxPython ... I have found
> that the only thing really letting this package down is lack of
> documentation.
>
> Would anyone be interested in helping to write/ contributing to a
wxWindows
> open source book ?
>
> regards
>
> Ben Catanzariti
>
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@lists.wxwindows.org
> http://lists.wxwindows.org/mailman/listinfo/wxpython-users
>

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

After recently moving away from tkinter to use wxPython ... I have found
that the only thing really letting this package down is lack of
documentation.

Would anyone be interested in helping to write/ contributing to a

wxWindows

open source book ?

Why not just add more content to the wxPyWiki? The cookbook seciton is a
bit unorganized at the moment, but there is a lot there that would make good
book fodder. OTOH, you could always add a new link on the Front page to a
set of more organized, book-like content.

http://wiki.wxpython.org/index.cgi/FrontPage

There is also the wxPython-docs mail list.

http://lists.wxwindows.org/mailman/listinfo/wxpython-docs

···

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

We should also be co-ordinating this effort with Robin Dunn. No
sense having multiple sets of demos.

What do you think Robin?

The purpose of the wxPyWiki is to provide documentation, examples, how-to's,
etc. for helping people learn, understand and use wxPython. Anything that
falls within those guidelines is fair game.

···

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

I have looked through the mailing list and the wxPython demo for examples

of

key events .... but can not seem to find anything on how key events are

used

...
... in particular I want to create shortcut keys for an application ie.
trl - Q fires function 'x' ... would anyone be able to point me in the
right direction

Take a look at wxAcceratorTable. There has been a bug reported lately that
it doesn't work on wxGTK unless the accelerators are also defined in the
menu strings. See th demo for an example of this.

···

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

Hi there,

I would be happy to help contribute to the wxPython documentation if that is
OK? ... to try and help other newcomers to become comfortable with the wx*
library.

As Gary is already working on a wxPython book ...( put me down for a signed
copy Gary :slight_smile: ... I will not try to duplicate his efforts

thanks

Ben

···

----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Saturday, March 09, 2002 5:44 AM
Subject: Re: [wxPython] wxWindows Book

> After recently moving away from tkinter to use wxPython ... I have found
> that the only thing really letting this package down is lack of
> documentation.
>
> Would anyone be interested in helping to write/ contributing to a
wxWindows
> open source book ?

Why not just add more content to the wxPyWiki? The cookbook seciton is a
bit unorganized at the moment, but there is a lot there that would make

good

book fodder. OTOH, you could always add a new link on the Front page to a
set of more organized, book-like content.

http://wiki.wxpython.org/index.cgi/FrontPage

There is also the wxPython-docs mail list.

http://lists.wxwindows.org/mailman/listinfo/wxpython-docs

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

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

I have followed this thread with great interest, as I use sizers
exclusively (and extensively). Thanks, Robin, for the Wiki on Using
Sizers: very helpful. Here is a problem, however, that is not
addressed by the Wiki, nor has it been discussed in this thread as
I understand it.

Although Point 3 of the Wiki states that "Often sizer.Fit(frame) is
NOT what you want," this often IS exactly what I want, especially
when I am using a dialog. Here is the behavior that I am seeking. I
want to define a number of panels, each of which can be used in
several different settings. For example, a given panel might be
placed in a wxDialog, or on a page in a wxNotebook, or along side
another panel in a wxFrame. When that panel is used alone in a
Frame or Dialog, the Frame (or Dialog) should start out with the
panel and its child windows in the "packed" or minimum state. It
should then be possible to resize the frame to make it larger, but
not make it smaller. The code below demonstrates this desired
behavior.

The issue I want to bring up here is that I discovered the need for
the following line of code:

        self.SetSize(sizer.GetMinSize())

only by trial and error, and I do not understand why it is
necessary. Can someone illumine me? Thanks.

···

--- Robin Dunn <robin@alldunn.com> wrote:

> The problem is that the added items in the wxPanel's boxSizer
> do not seem to be affecting the size calculation of the
> ScrolledWindow's sizer's size.

Because you need to tell the sizer that you changed the item's
size...

I made the following changes in your sample code:
<snip>
3. In UiContent.addAddon I couldn't follow all you were doing
with the Addon class and addonList and so on. I get the feeling
that you are creating more sizers than you need... I replaced
the method with the following and it does what I think you were
attempting to do in just a few lines:

        panel = self.currentItem
        psizer = panel.GetSizer()
        desc = wxTextCtrl(panel, -1, 'detail description',
                          size=(150,20))
        psizer.Add(desc)
        psizer.Fit(panel)
        self.sizer.SetItemMinSize(panel, panel.GetSize().width,
                                  panel.GetSize().height)
        self.Layout()

###############################################################
# wxPython 2.3.2 with Python 2.2 on Win2000 Pro

from wxPython.wx import *

class MyPanelA(wxPanel):
    def __init__(self, parent, id):
        wxPanel.__init__(self, parent, id)
        panel1 = MyPanelB(self, -1)
        panel2 = MyPanelB(self, -1)
        sizer = wxBoxSizer(wxVERTICAL)
        sizer.Add(panel1, 1, wxEXPAND)
        sizer.Add(panel2, 1, wxEXPAND)
        self.SetAutoLayout(true) # needed (as expected)
        self.SetSizer(sizer) # needed (as expected)
        self.SetSize(sizer.GetMinSize()) # needed (surprising!)
## self.Layout() # not helpful

class MyPanelB(wxPanel):
    def __init__(self, parent, id):
        wxPanel.__init__(self, parent, id)
        tc1 = wxTextCtrl(self, -1)
        bn1 = wxButton(self, -1, 'in panel')
        sizer = wxBoxSizer(wxHORIZONTAL)
        sizer.Add(tc1, 1, wxEXPAND)
        sizer.Add(bn1, 1, wxEXPAND)
        self.SetAutoLayout(true) # needed (as expected)
        self.SetSizer(sizer) # needed (as expected)
        self.SetSize(sizer.GetMinSize()) # needed (surprising!)
## self.Layout() # not helpful

class MyFrame(wxFrame):
    def __init__(self, parent, id):
        wxFrame.__init__(self, parent, id, title='MyFrame')
        panel1 = MyPanelA(self, -1)
        sizer = wxBoxSizer(wxHORIZONTAL)
        sizer.Add(panel1, 1, wxEXPAND)
        self.SetAutoLayout(true) # needed (as expected)
        self.SetSizer(sizer) # needed (as expected)
        sizer.Fit(self) # needed (as expected)
        sizer.SetSizeHints(self) # needed (as expected)
## self.Layout() # not helpful

class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame(None, -1)
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

if __name__ == '__main__':

    app = MyApp(0)
    app.MainLoop()

=====
Donnal Walter
Arkansas Children's Hospital

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage

The issue I want to bring up here is that I discovered the need for
the following line of code:

        self.SetSize(sizer.GetMinSize())

only by trial and error, and I do not understand why it is
necessary. Can someone illumine me? Thanks.

When creating windows inside sizers you must tell for sizer what the min size is - sizer.Fit call is required and for min/max window size is - SetSizeHints.

When window is running and you add something to sizer other calls are required - sizeritem.SetInitSize, sizer.Layout, window.SetClientSize

Patch inside code

mak

###############################################################
# wxPython 2.3.2 with Python 2.2 on Win2000 Pro

from wxPython.wx import *

class MyPanelA(wxPanel):
    def __init__(self, parent, id):
        wxPanel.__init__(self, parent, id)
        panel1 = MyPanelB(self, -1)
        panel2 = MyPanelB(self, -1)
        sizer = wxBoxSizer(wxVERTICAL)
        sizer.Add(panel1, 1, wxEXPAND)
        sizer.Add(panel2, 1, wxEXPAND)
        self.SetAutoLayout(true) # needed (as expected)
        self.SetSizer(sizer) # needed (as expected)

          sizer.Fit(self)

           sizer.SetSizeHints(self)

# self.SetSize(sizer.GetMinSize()) # needed (surprising!)

···

## self.Layout() # not helpful