plese suggest good tutorial for sizers.

krishnakant Mane

- A quick and dirty solution as starting point for learning.
- I wrote it to brush up my knowledge on sizers.

Sizers gurus
- Comments and corrections are welcome.
- Is there some way to lock the frame size in one direction only? In that case,
the height. I have attempt several things like SizeHints without to much success.

Jean-Michel Fauth, Switzerland.

# -*- coding: iso-8859-1 -*-

···

#--------------------------------------------------------------------
# Name: dummy.py
# Purpose: On sizers...
# Author: Jean-Michel Fauth, Switzerland
# Copyright: (c) 2007 Jean-Michel Fauth
# Licence: ---
#--------------------------------------------------------------------
# os dev: w2k sp4
# py dev: Python 2.5
# wx dev: wxPython 2.8.0.1
# Revision: ... 2006
#--------------------------------------------------------------------

import wx

#--------------------------------------------------------------------

class MyPanel(wx.Panel):

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

         #vision problems? font size!
         self.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))

         lab1 = wx.StaticText(self, -1, 'hydrogen:', style=wx.ALIGN_RIGHT)
         lab2 = wx.StaticText(self, -1, 'tin :', style=wx.ALIGN_RIGHT)
         lab3 = wx.StaticText(self, -1, 'mendelevium :', style=wx.ALIGN_RIGHT)
         lab4 = wx.StaticText(self, -1, 'carbon :', style=wx.ALIGN_RIGHT)
         lab5 = wx.StaticText(self, -1, 'nitogen :', style=wx.ALIGN_RIGHT)
         lab6 = wx.StaticText(self, -1, 'argon :', style=wx.ALIGN_RIGHT)
         lab7 = wx.StaticText(self, -1, 'iron :', style=wx.ALIGN_RIGHT)
         lab8 = wx.StaticText(self, -1, 'gold :', style=wx.ALIGN_RIGHT)
         txt1 = wx.TextCtrl(self, -1, '')
         txt2 = wx.TextCtrl(self, -1, '')
         txt3 = wx.TextCtrl(self, -1, '')
         txt4 = wx.TextCtrl(self, -1, '')
         txt5 = wx.TextCtrl(self, -1, '')
         txt6 = wx.TextCtrl(self, -1, '')
         txt7 = wx.TextCtrl(self, -1, '')
         txt8 = wx.TextCtrl(self, -1, '')
         b1 = wx.Button(self, wx.NewId(), 'Use')
         b2 = wx.Button(self, wx.NewId(), 'the')
         b3 = wx.Button(self, wx.NewId(), 'wonderful')
         b4 = wx.Button(self, wx.NewId(), 'sizer')
         b5 = wx.Button(self, wx.NewId(), 'world')
         b6 = wx.Button(self, wx.NewId(), '&OK')

         b = 10
         sizer1 = wx.FlexGridSizer(4, 4, b, b)
         sizer1.AddMany([
             (lab1, 1, wx.EXPAND | wx.ALL),
             (txt1, 1, wx.EXPAND | wx.ALL),
             (lab2, 1, wx.EXPAND | wx.ALL),
             (txt2, 1, wx.EXPAND | wx.ALL),

             (lab3, 1, wx.EXPAND | wx.ALL),
             (txt3, 1, wx.EXPAND | wx.ALL),
             (lab4, 1, wx.EXPAND | wx.ALL),
             (txt4, 1, wx.EXPAND | wx.ALL),

             (lab5, 1, wx.EXPAND | wx.ALL),
             (txt5, 1, wx.EXPAND | wx.ALL),
             (lab6, 1, wx.EXPAND | wx.ALL),
             (txt6, 1, wx.EXPAND | wx.ALL),

             (lab7, 1, wx.EXPAND | wx.ALL),
             (txt7, 1, wx.EXPAND | wx.ALL),
             (lab8, 1, wx.EXPAND | wx.ALL),
             (txt8, 1, wx.EXPAND | wx.ALL),
             ])

         sizer1.AddGrowableCol(1)
         sizer1.AddGrowableCol(3)

         sizer2 = wx.BoxSizer(wx.HORIZONTAL)
         b = 5
         sizer2.Add(b1, 0, border=b)
         sizer2.Add(b2, 0, wx.LEFT, b)
         sizer2.Add(b3, 0, wx.LEFT, b)
         sizer2.Add(b4, 0, wx.LEFT, b)
         sizer2.Add(b5, 0, wx.LEFT, b)
         sizer2.Add(b6, 0, wx.LEFT, b)

         sizer3 = wx.BoxSizer(wx.VERTICAL)
         b = 10
         sizer3.Add(sizer1, 1, wx.GROW | wx.ALL, b)
         sizer3.Add(sizer2, 0, wx.ALIGN_CENTER | wx.ALL, b)
         #~ sizer3.SetMinSize((800, 200))

         self.SetSizer(sizer3)
         self.parent.SetClientSize(sizer3.GetMinSize())
         self.CentreOnParent()

#--------------------------------------------------------------------

class MyFrame(wx.Frame):

     def __init__(self, parent, id):
         wx.Frame.__init__(self, parent, id, 'SimpleApp', wx.DefaultPosition, wx.DefaultSize, wx.DEFAULT_FRAME_STYLE)

         self.panel = MyPanel(self, wx.ID_ANY)

#--------------------------------------------------------------------

app = wx.PySimpleApp()
frame = MyFrame(None, wx.ID_ANY)
frame.Show()
app.MainLoop()

#eof-----------------------------------------------------------------

jmf wrote:

krishnakant Mane

- A quick and dirty solution as starting point for learning.
- I wrote it to brush up my knowledge on sizers.

Sizers gurus
- Comments and corrections are welcome.
- Is there some way to lock the frame size in one direction only? In that case,
the height. I have attempt several things like SizeHints without to much success.

It sure looks like:

self.SetSizeHints( (-1, H), (-1, H) )

should work. Or is that what you tried?

-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

Andrea Gavana wrote:

If you want to specify a minimum height beyond which the frame
shouldn't shrink, you could add this to your __init__ method in the
MyFrame class:

mainSizer = wx.BoxSizer(wx.VERTICAL)
mainSizer.Add(self.panel, 1, wx.EXPAND)
self.SetSizer(mainSizer)
self.SetSizeHints(-1, 300)
mainSizer.Layout()
self.Fit()

HTH.

Andrea.

Can you comment on why you run Layout on the sizer rather than its container
(self)? Also, since you aren't setting a maxsize, isn't your call to
SetSizeHints equivalent to a call to SetMinSize?

···

--
Jeffrey Barish

Hi Jeffrey,

Andrea Gavana wrote:

> If you want to specify a minimum height beyond which the frame
> shouldn't shrink, you could add this to your __init__ method in the
> MyFrame class:
>
> mainSizer = wx.BoxSizer(wx.VERTICAL)
> mainSizer.Add(self.panel, 1, wx.EXPAND)
> self.SetSizer(mainSizer)
> self.SetSizeHints(-1, 300)
> mainSizer.Layout()
> self.Fit()
>
> HTH.
>
> Andrea.

Can you comment on why you run Layout on the sizer rather than its container
(self)?

As far as I know, running Layout() on the main sizer or calling
self.Layout() should be the same. Quoting the manual:

"
wxWindow::Layout
void Layout()

Invokes the constraint-based layout algorithm or the sizer-based
algorithm for this window
"
I.e., call the sizer Layout(), unless my understanding of english is
wrong (which it may be). In any case, I always call Layout() on sizers
instead of on the windows because from my philosophical point of view
is the sizer that layouts something and not the window. The window
itself does not hold any layout algorithm in itself, it's always the
sizer that does the job. So I give credit to sizers :smiley:
The only main difference I can see, is that if you are using layout
constraints instead of sizers, you can only use window.Layout()

Also, since you aren't setting a maxsize, isn't your call to
SetSizeHints equivalent to a call to SetMinSize?

It is, as far as I know. Actually, I use SetSizeHints it because I
like it more than SetMinSize :smiley:

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

···

On 1/8/07, Jeffrey Barish wrote: