Setting Application Window Size

I'm modifying an application I wrote a few years ago for a similar
purpose. When the application is invoked the window is now too small for all
widgets on the opening notebook tab to be visible. I've not found where I
can define the initial window size.

   In the main module is the application frame and the tabbed notebook. There
is no explicit size defined in either class, nor in the call to the app at
the end. The class for each tab has the sizers set up like this:

     topLevelBox = wx.BoxSizer(wx.VERTICAL) # main container
     outerBox = wx.BoxSizer(wx.VERTICAL) # base container
     hbox1 = wx.BoxSizer(wx.HORIZONTAL) # first row container
     hbox2 = wx.BoxSizer(wx.HORIZONTAL) # second row container
     hbox3 = wx.BoxSizer(wx.HORIZONTAL) # third row container
     hbox4 = wx.BoxSizer(wx.HORIZONTAL) # fourth row container
     hbox5 = wx.BoxSizer(wx.HORIZONTAL) # fifth row container
     hbox6 = wx.BoxSizer(wx.HORIZONTAL) # sixth row container
     buttonBox = wx.BoxSizer(wx.HORIZONTAL) # button container

and just above those I have:

     self.SetClientSize(wx.Size(1600, 600))

     self.Fit()

   The wx.Size for the original application was (800, 600), but doubling the
x dimension does not make the initial window twice as wide.

   What have I missed so I can make the window wider when the application is
invoked?

TIA,

Rich

The self.Fit() will resize self such that it fits around its children or meets the minimum needs of its sizer if it has one. If you want to for the use of (1600,600) then get rid of the Fit(). OTOH, if you want the frame to be large enough to show everything, but not larger, then make sure the frame has a sizer and just use Fit.

···

On 12/8/11 2:11 PM, Rich Shepard wrote:

I'm modifying an application I wrote a few years ago for a similar
purpose. When the application is invoked the window is now too small for
all
widgets on the opening notebook tab to be visible. I've not found where I
can define the initial window size.

In the main module is the application frame and the tabbed notebook. There
is no explicit size defined in either class, nor in the call to the app at
the end. The class for each tab has the sizers set up like this:

topLevelBox = wx.BoxSizer(wx.VERTICAL) # main container
outerBox = wx.BoxSizer(wx.VERTICAL) # base container
hbox1 = wx.BoxSizer(wx.HORIZONTAL) # first row container
hbox2 = wx.BoxSizer(wx.HORIZONTAL) # second row container
hbox3 = wx.BoxSizer(wx.HORIZONTAL) # third row container
hbox4 = wx.BoxSizer(wx.HORIZONTAL) # fourth row container
hbox5 = wx.BoxSizer(wx.HORIZONTAL) # fifth row container
hbox6 = wx.BoxSizer(wx.HORIZONTAL) # sixth row container
buttonBox = wx.BoxSizer(wx.HORIZONTAL) # button container

and just above those I have:

self.SetClientSize(wx.Size(1600, 600))

self.Fit()

The wx.Size for the original application was (800, 600), but doubling the
x dimension does not make the initial window twice as wide.

What have I missed so I can make the window wider when the application is
invoked?

--
Robin Dunn
Software Craftsman

The self.Fit() will resize self such that it fits around its children or
meets the minimum needs of its sizer if it has one.

Robin,

   I thought this would expand the window size to show all widgets, but it
isn't working that way. That's why I asked for insights.

If you want to for the use of (1600,600) then get rid of the Fit().

   I don't care what the size is as long as the page displays all widgets on
each notebook tab, and the tabs should all be the same size.

OTOH, if you want the frame to be large enough to show everything, but not
larger, then make sure the frame has a sizer and just use Fit.

   I'm having difficulties adding size to the frame. It's constructed this
way:

   def __init__(self, *args, **kwds):
     kwds["style"] = wx.DEFAULT_FRAME_STYLE|wx.FULL_REPAINT_ON_RESIZE|wx.TAB_TRAVERSAL
     wx.Frame.__init__(self, *args, **kwds)

and adding size = () to the __init__ after the keywords doesn't work.

   If this is not the appropriate way to add a sizer to the frame, please
teach me how to do this.

Regards,

Rich

···

On Thu, 8 Dec 2011, Robin Dunn wrote:

Based on your earlier message I'll assume that the only thing that is a direct child of the frame is the notebook. In that case you can just do something like this:

   def __init__(self, *args, **kwds):
     kwds["style"] = wx.DEFAULT_FRAME_STYLE|wx.FULL_REPAINT_ON_RESIZE|wx.TAB_TRAVERSAL
     wx.Frame.__init__(self, *args, **kwds)

     notebook = ...
     notebook.AddPage(...

     sizer = wx.BoxSizer()
     sizer.Add(notebook, 1, wx.EXPAND)
     self.SetSizer(sizer)
     self.Fit()

···

On 12/8/11 3:55 PM, Rich Shepard wrote:

On Thu, 8 Dec 2011, Robin Dunn wrote:

The self.Fit() will resize self such that it fits around its children or
meets the minimum needs of its sizer if it has one.

Robin,

I thought this would expand the window size to show all widgets, but it
isn't working that way. That's why I asked for insights.

If you want to for the use of (1600,600) then get rid of the Fit().

I don't care what the size is as long as the page displays all widgets on
each notebook tab, and the tabs should all be the same size.

OTOH, if you want the frame to be large enough to show everything, but
not
larger, then make sure the frame has a sizer and just use Fit.

I'm having difficulties adding size to the frame. It's constructed this
way:

def __init__(self, *args, **kwds):
kwds["style"] =
wx.DEFAULT_FRAME_STYLE|wx.FULL_REPAINT_ON_RESIZE|wx.TAB_TRAVERSAL
wx.Frame.__init__(self, *args, **kwds)

and adding size = () to the __init__ after the keywords doesn't work.

If this is not the appropriate way to add a sizer to the frame, please
teach me how to do this.

--
Robin Dunn
Software Craftsman

That's correct: the notebook is the only direct child of the frame. The
class is defined thusly:

class WqNotebook(wx.Notebook):

   def __init__(self, *args, **kwds):
     wx.Notebook.__init__(self, *args, **kwds)

     self.pane_1 = modBiota(self, wx.ID_ANY)
     self.pane_2 = modChem(self, wx.ID_ANY)
     self.pane_3 = modBact(self, wx.ID_ANY

     self.AddPage(self.pane_1, "Biota")
     self.AddPage(self.pane_2, "Chemistry")
     self.AddPage(self.pane_3, "Bacteria")

# End of Notebook class

   I'll add the sizer and Fit() to that class.

Thanks,

Rich

···

On Thu, 8 Dec 2011, Robin Dunn wrote:

Based on your earlier message I'll assume that the only thing that is a
direct child of the frame is the notebook. In that case you can just do
something like this:

def __init__(self, *args, **kwds):
   kwds["style"] = wx.DEFAULT_FRAME_STYLE|wx.FULL_REPAINT_ON_RESIZE|wx.TAB_TRAVERSAL
   wx.Frame.__init__(self, *args, **kwds)

   notebook = ...
   notebook.AddPage(...

   sizer = wx.BoxSizer()
   sizer.Add(notebook, 1, wx.EXPAND)
   self.SetSizer(sizer)
   self.Fit()

I apologize for my denseness; it's been a long time since I did any
serious python coding. My trials to implement the above have produced only
errors, and despite looking at the on-line docs I'm not seeing my error(s).

   The notebook class and beginning of the frame class:

class WqNotebook(wx.Notebook):
   def __init__(self, *args, **kwds):
     wx.Notebook.__init__(self, *args, **kwds)

     self.pane_1 = modBiota(self, wx.ID_ANY)
     self.pane_2 = modChem(self, wx.ID_ANY)
     sself.pane_3 = modBact(self, wx.ID_ANY

     self.AddPage(self.pane_1, "Biota")
     self.AddPage(self.pane_2, "Chemistry")
     self.AddPage(self.pane_3, "Bacteria")
# End of Notebook class

class OneFrame(wx.Frame):
   def __init__(self, *args, **kwds):
     kwds["style"] =
wx.DEFAULT_FRAME_STYLE|wx.FULL_REPAINT_ON_RESIZE|wx.TAB_TRAVERSAL
     wx.Frame.__init__(self, *args, **kwds)

     self.mainNB = WqNotebook(self, wx.ID_ANY, style=0)

     sizer = wx.BoxSizer()
     sizer.Add(self.mainNB, 1, wx.EXPAND)
     self.SetSizer(sizer)
     self.Fit()
   ...

   Please show me what I've not done correctly.

Rich

···

On Thu, 8 Dec 2011, Robin Dunn wrote:

Based on your earlier message I'll assume that the only thing that is a
direct child of the frame is the notebook. In that case you can just do
something like this:

def __init__(self, *args, **kwds):
   kwds["style"] = wx.DEFAULT_FRAME_STYLE|wx.FULL_REPAINT_ON_RESIZE|wx.TAB_TRAVERSAL
   wx.Frame.__init__(self, *args, **kwds)

   notebook = ...
   notebook.AddPage(...

   sizer = wx.BoxSizer()
   sizer.Add(notebook, 1, wx.EXPAND)
   self.SetSizer(sizer)
   self.Fit()

Found the solution: I have a settings method which sets the size of the
frame. Changing the wx.Size in that method does the trick.

Mea culpa!

Rich

···

On Fri, 9 Dec 2011, Rich Shepard wrote:

I apologize for my denseness; it's been a long time since I did any
serious python coding. My trials to implement the above have produced only
errors, and despite looking at the on-line docs I'm not seeing my
error(s).