Problems with Sizers

M

Mario Lacunza

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[1],self.encode)
self.cboDpto.Append(x,rs[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[1],self.encode)
self.cboProv.Append(x,rs[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[1],self.encode)
self.cboDistri.Append(x,rs[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
"""
#-------------------------------------------------------------------------------
 
S

Sybren Stuvel

Mario Lacunza enlightened us with:
I have troubbles in this code when I try to resize the form, all the
widgets dont move.

That's because you're positioning them based on pixel positions.
Remove the pixel positions, and add the widgets to the sizer. Now you
only add a sizer, but don't add anything to it.

Sybren
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top