wxlayoutconstraints inside a wxDialog ?
Robert Amesz
sheershion at mailexpire.com
Fri Feb 22 13:56:56 EST 2002
Marcus Stojek wrote:
> I'm using wxPython and I'm trying to use
> layout constraints in a Dialog.
> why doesn't this work?
>
> --------------------------------
>
> d=CompoDlg(self)
> -----
> class CompoDlg(wxDialog):
> def __init__(self,parent):
> BORDERPIX=20
> ID_E11=wxNewId()
>
> win=wxDialog(parent, -1, "Title", wxDefaultPosition,
> wxSize(350, 200))
> win.SetAutoLayout(true)
>
> E11 = wxStaticText(win,-1,"E11:",wxDefaultPosition,
> wxDefaultSize)
> lc=wxLayoutConstraints()
> lc.top.SameAs(win,wxTop,BORDERPIX)
> lc.left.SameAs(win,wxLeft,BORDERPIX)
> lc.width.AsIs()
> lc.height.AsIs()
> E11.SetConstraints(lc)
> --------------------------------
There is one basic thing wrong with this code: you're not initializing
your class correctly. You should call the constructor of the base
class, but you're creating a new wxDialog instead. With that in mind,
the window which needs laying out is simply 'self', not 'win'. So,
after correcting, rearranging, and removing some unused and redundant
stuff, you might end up with something like this (warning, untested
code):
class CompoDlg(wxDialog):
def __init__(self,parent):
wxDialog.__init__(self, parent, -1, "Title", wxDefaultPosition,
wxSize(350, 200))
self.SetAutoLayout(true)
E11 = wxStaticText(self,-1,"E11:")
BORDERPIX=20
lc=wxLayoutConstraints()
lc.top.SameAs(self,wxTop,BORDERPIX)
lc.left.SameAs(self,wxLeft,BORDERPIX)
E11.SetConstraints(lc)
By the way, I assume you know that
d=CompoDlg(self)
will not, by itself, actually show the dialog? Do
result = d.ShowModal()
for that.
Having gone through all that, you might want to consider using sizers
instead of constraints. As far as development is concerned, constraints
are pretty much dead, or so I gather, and sizers are very much alive.
Furthermore, it has become the preferred layout method of the wxWindows
developers, so who am I to argue with them?
Robert Amesz
--
P.S. Take a look at the wxPython mailing list. It's somewhere on
http://lists.wxwindows.org
More information about the Python-list
mailing list