Problems with Sizers

Hello,

I have troubbles in this code when I try to resize the form, all the
widgets dont move.

Any idea?

Thansk in advance!

···

-----------------------------------------------------------------------------
# -*- coding: utf8 -*-#
#Boa:Dialog:frmPostales

import wx
#import modGlobals
#from Conectar import Conectar
#import errores

def create(parent):
    return frmPostales(parent)

[wxID_FRMPOSTALES, wxID_FRMPOSTALESBTNCANCELAR, wxID_FRMPOSTALESBTNOK,
wxID_FRMPOSTALESCBODISTRI, wxID_FRMPOSTALESCBODPTO,
wxID_FRMPOSTALESCBOPAIS,
wxID_FRMPOSTALESCBOPROV, wxID_FRMPOSTALESLBLCOD,
wxID_FRMPOSTALESLBLDISTRO,
wxID_FRMPOSTALESLBLDPTO, wxID_FRMPOSTALESLBLPAIS,
wxID_FRMPOSTALESLBLPOSTAL,
wxID_FRMPOSTALESLBLPROV,
] = [wx.NewId() for _init_ctrls in range(13)]

class frmPostales(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_FRMPOSTALES,
name=u'frmPostales',
              parent=prnt, pos=wx.Point(579, 295), size=wx.Size(254,
197),
              style=wx.DEFAULT_FRAME_STYLE, title=u'C\xf3digos
Postales')
        self.SetClientSize(wx.Size(254, 197))

        self.btnOk = wx.Button(id=wxID_FRMPOSTALESBTNOK,
label=u'Aceptar',
              name=u'btnOk', parent=self, pos=wx.Point(28, 148),
              size=wx.Size(85, 34), style=0)
        self.btnOk.SetToolTipString(u'Aceptar')
        self.btnOk.Bind(wx.EVT_BUTTON, self.OnBtnOkButton,
              id=wxID_FRMPOSTALESBTNOK)

        self.btnCancelar = wx.Button(id=wxID_FRMPOSTALESBTNCANCELAR,
              label=u'Cancelar', name=u'btnCancelar', parent=self,
              pos=wx.Point(133, 148), size=wx.Size(85, 34), style=0)
        self.btnCancelar.SetToolTipString(u'Salir')
        self.btnCancelar.Bind(wx.EVT_BUTTON, self.OnBtnCancelarButton,
              id=wxID_FRMPOSTALESBTNCANCELAR)

        self.lblPais = wx.StaticText(id=wxID_FRMPOSTALESLBLPAIS,
              label=u'Pa\xeds', name=u'lblPais', parent=self,
pos=wx.Point(18,
              18), size=wx.Size(20, 12), style=0)

        self.cboPais = wx.ComboBox(choices=[],
id=wxID_FRMPOSTALESCBOPAIS,
              name=u'cboPais', parent=self, pos=wx.Point(123, 18),
              size=wx.Size(117, 27), style=0, value=u'')
        self.cboPais.SetLabel(u'')
        self.cboPais.SetToolTipString(u'Pais')
        self.cboPais.Bind(wx.EVT_COMBOBOX, self.OnCboPaisCombobox,
              id=wxID_FRMPOSTALESCBOPAIS)

        self.lblDpto = wx.StaticText(id=wxID_FRMPOSTALESLBLDPTO,
              label=u'Departamento', name=u'lblDpto', parent=self,
              pos=wx.Point(18, 45), size=wx.Size(70, 12), style=0)

        self.cboDpto = wx.ComboBox(choices=[],
id=wxID_FRMPOSTALESCBODPTO,
              name=u'cboDpto', parent=self, pos=wx.Point(123, 45),
              size=wx.Size(117, 27), style=0, value=u'')
        self.cboDpto.SetLabel(u'')
        self.cboDpto.SetToolTipString(u'Departamentos')
        self.cboDpto.Bind(wx.EVT_COMBOBOX, self.OnCboDptoCombobox,
              id=wxID_FRMPOSTALESCBODPTO)

        self.lblProv = wx.StaticText(id=wxID_FRMPOSTALESLBLPROV,
              label=u'Provincia', name=u'lblProv', parent=self,
pos=wx.Point(18,
              72), size=wx.Size(45, 12), style=0)

        self.cboProv = wx.ComboBox(choices=[],
id=wxID_FRMPOSTALESCBOPROV,
              name=u'cboProv', parent=self, pos=wx.Point(123, 72),
              size=wx.Size(117, 27), style=0, value=u'')
        self.cboProv.SetLabel(u'')
        self.cboProv.SetToolTipString(u'Provincias')
        self.cboProv.Bind(wx.EVT_COMBOBOX, self.OnCboProvCombobox,
              id=wxID_FRMPOSTALESCBOPROV)

        self.lblDistro = wx.StaticText(id=wxID_FRMPOSTALESLBLDISTRO,
              label=u'Distrito', name=u'lblDistro', parent=self,
              pos=wx.Point(18, 99), size=wx.Size(36, 12), style=0)

        self.cboDistri = wx.ComboBox(choices=[],
id=wxID_FRMPOSTALESCBODISTRI,
              name=u'cboDistri', parent=self, pos=wx.Point(123, 99),
              size=wx.Size(117, 27), style=0, value=u'')
        self.cboDistri.SetLabel(u'')
        self.cboDistri.SetToolTipString(u'Distritos')
        self.cboDistri.Bind(wx.EVT_COMBOBOX, self.OnCboDistriCombobox,
              id=wxID_FRMPOSTALESCBODISTRI)

        self.lblCod = wx.StaticText(id=wxID_FRMPOSTALESLBLCOD,
              label=u'C\xf3digo Postal:', name=u'lblCod', parent=self,
              pos=wx.Point(18, 126), size=wx.Size(70, 12), style=0)

        self.lblPostal = wx.StaticText(id=wxID_FRMPOSTALESLBLPOSTAL,
label=u'',
              name=u'lblPostal', parent=self, pos=wx.Point(123, 126),
              size=wx.Size(117, 12), style=0)
        self.lblPostal.SetToolTipString(u'Ubigeo')

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        self.CargarSizers(parent)
        
        #Instancia la Clase
# self.oPostal=Postal()
        
        #Establece el encoding segun el OS
        # TODO: Revizar este codigo de encoding!!!!
        if wx.Platform=="__WXMSW__":
            self.encode='iso-8859-1'
        elif wx.Platform=="__WXGTK__":
            self.encode='utf8'
        
  # self.CargarComboPais()
  
#-------------------------------------------------------------------------------
    def CargarSizers(self,parent):
        """ Funcion q cargara los sizers del form."""
        
        panel=wx.Panel(self)
        
        #Se declara el Sizer principal
        mSizer=wx.BoxSizer(wx.HORIZONTAL)
        
        #Agregar sizer de ctrls
        ctrlSizer=wx.FlexGridSizer(rows=6,cols=2,hgap=5,vgap=5)
        ctrlSizer.AddGrowableCol(1)
        
        #Se agregan los controles
        ctrlSizer.Add(self.lblPais,0,wx.ALIGN_RIGHT|
wx.ALIGN_CENTER_VERTICAL)
        ctrlSizer.Add(self.cboPais,0,wx.EXPAND)
        ctrlSizer.Add(self.lblDpto,0,wx.ALIGN_RIGHT|
wx.ALIGN_CENTER_VERTICAL)
        ctrlSizer.Add(self.cboDpto,0,wx.EXPAND)
        ctrlSizer.Add(self.lblProv,0,wx.ALIGN_RIGHT|
wx.ALIGN_CENTER_VERTICAL)
        ctrlSizer.Add(self.cboProv,0,wx.EXPAND)
        ctrlSizer.Add(self.lblDistro,0,wx.ALIGN_RIGHT|
wx.ALIGN_CENTER_VERTICAL)
        ctrlSizer.Add(self.cboDistri,0,wx.EXPAND)
        ctrlSizer.Add(self.lblCod,0,wx.ALIGN_RIGHT|
wx.ALIGN_CENTER_VERTICAL)
        ctrlSizer.Add(self.lblPostal,0,wx.EXPAND)
        ctrlSizer.Add(self.btnOk, 1)
        ctrlSizer.Add(self.btnCancelar,1)
        
        #Agregar este sizer al Principal
        mSizer.Add(ctrlSizer,0,wx.EXPAND|wx.ALL,10)
        
        panel.SetSizer(mSizer)
        
        mSizer.Fit(self)
        mSizer.SetSizeHints(self)
        
#-------------------------------------------------------------------------------
     
#-------------------------------------------------------------------------------
    def OnBtnOkButton(self, event):
        self.Close(True)

    def OnBtnCancelarButton(self, event):
        self.Close(True)
#-------------------------------------------------------------------------------

    def OnCboPaisCombobox(self, event):
        """Carga el combo Departamento."""
        """
        self.cboDpto.Clear()
        self.cboDistri.Clear()
        self.cboProv.Clear()
        
        cb = event.GetEventObject()
        #Obtengo el Key
        kPais = cb.GetClientData(cb.GetSelection())
        self.keyPais=kPais
        
        rs=self.oPostal.CargarDepa(kPais)
        i=0
        
        for it in rs:
            x=unicode(rs[i][1],self.encode)
            self.cboDpto.Append(x,rs[i][0])
            i+=1
        """
#-------------------------------------------------------------------------------

    def OnCboDptoCombobox(self, event):
        """Carga el combo Provincia."""
        """
        self.cboProv.Clear()
        
        cb=event.GetEventObject()
        #Obtengo el Key
        kDepa = cb.GetClientData(cb.GetSelection())
        self.keyDepa=kDepa
        
        rs=self.oPostal.CargarProv(kDepa)
        i=0
        
        for it in rs:
            x=unicode(rs[i][1],self.encode)
            self.cboProv.Append(x,rs[i][0])
            i+=1
            
        """
#-------------------------------------------------------------------------------

    def OnCboProvCombobox(self, event):
        """ Carga el combo Distritos."""
        """
        self.cboDistri.Clear()
        
        cb=event.GetEventObject()
        #Obtengo el Key
        kProv = cb.GetClientData(cb.GetSelection())
        self.keyProv=kProv
        
        rs=self.oPostal.CargarDist(self.keyDepa,kProv)
        i=0
        
        for it in rs:
            x=unicode(rs[i][1],self.encode)
            self.cboDistri.Append(x,rs[i][0])
            i+=1
            
        """

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

    def OnCboDistriCombobox(self, event):
        """
        cb=event.GetEventObject()
        #Obtengo el Key
        kDist = cb.GetClientData(cb.GetSelection())
        self.keyDist=kDist
        
        self.GeneraUbigeo()
        """
#-------------------------------------------------------------------------------

    def GeneraUbigeo(self):
        """Genera el codigo de Ubigeo obtenido."""
        """
        self.ubigeo=self.keyDepa+self.keyProv+self.keyDist
        
        modGlobals.UBIGEO=self.ubigeo
        
        #Pinta el codigo
        self.lblPostal.SetLabel(self.ubigeo)
        
        return self.ubigeo
      """
#-------------------------------------------------------------------------------

--
Mario Lacunza <mlacunza@gmail.com>

Hello,

I have troubbles in this code when I try to resize the form, all the
widgets dont move.

Any idea?

Thansk in advance!

   [...]

    def CargarSizers(self,parent):
        """ Funcion q cargara los sizers del form."""

        panel=wx.Panel(self)

   [...]

        panel.SetSizer(mSizer)

I believe your problem revolves around this panel you are creating in
this function here. You're trying to use the panel as a background or
at least size things based on it, but all the controls that you want
on top of the _panel_ are parented to the _frame_, and I've never been
able to get things to work right when the parenting is off.

You could just drop the panel and use self.SetSizer, but that may note
give you the dialogue-y background you want.

What I would try, is making the panel up before all your other
controls and changing the various controls to be parent=pnlBack or
whatever.

I don't have time to test things right now though. By the way, you may
in the future want to send your code as an attachment so the email
formatting dosn't do strange things to it, and stick a little generic
wx.App that calls your frame and a little "if __name__ == 'main':"
section to run the App, so people can see what's going on immediatly
:).

···

On 8/16/06, Mario Lacunza <mlacunza@gmail.com> wrote:

Hi Mario,

Mario Lacunza wrote:

Hello,

I have troubbles in this code when I try to resize the form, all the
widgets dont move.

Any idea?

I attached a changed version.

- commented your sizer code and used Boa to add sizers, this way when you use the Boa designer you can see what the sizers are doing.
- you are using a wx.Dialog, so you don't need an other panel, the controls can be parented to the dialog directly.
- used Boa menu option "Edit / Add simple app", so one can run the dialog
- used three sizers, a dialog sizer to get your 10 pixels around all controls, a control sizer for the controls and one for the buttons. The button sizer so the right button does not size with the right controls.

Werner

dialog.py (11.8 KB)

···

Thansk in advance!

Thanks a lot Werner!! Worka perfect!

I'll study your changes for learn more about Boa.

···

El jue, 17-08-2006 a las 11:22 +0200, Werner F. Bruhin escribió:

Hi Mario,

Mario Lacunza wrote:

>Hello,
>
>I have troubbles in this code when I try to resize the form, all the
>widgets dont move.
>
>Any idea?
>
>
I attached a changed version.

- commented your sizer code and used Boa to add sizers, this way when
you use the Boa designer you can see what the sizers are doing.
- you are using a wx.Dialog, so you don't need an other panel, the
controls can be parented to the dialog directly.
- used Boa menu option "Edit / Add simple app", so one can run the dialog
- used three sizers, a dialog sizer to get your 10 pixels around all
controls, a control sizer for the controls and one for the buttons. The
button sizer so the right button does not size with the right controls.

Werner

--
Mario Lacunza <mlacunza@gmail.com>