sizers wx carga inicial en formulario

damufo damufo en gmail.com
Mar Feb 17 22:18:44 CET 2009



Oswaldo Hernández escribiu:
> damufo escribió:
>> Hola:
> ...
>> Tengo un formulario dentro del cual un panel con botones y sizers.
>> El caso es que al cargar el formulario solo se ve un botón, pero si 
>> redimensiono el formulario, resulta que aparece todo como debería, ya 
>> se ven los 6 botones y en su sitio.
>> Pienso que tengo que indicarle de alguna manera que al arrancar cargue 
>> la presentación pero no sé como.
>> He probado con
>> self.SetAutoLayout(True)
>> y
>> self.panel1.SetAutoLayout(True)
>> pero no he tenido exito.
>>
>> Este es el código(acepto todo tipo de sugerencias en cuanto a la 
>> redacción del código):
>>
>> import wx
>>
>> class Frame3(wx.Frame):
>>    def _init_ctrls(self, prnt):
>>        wx.Frame.__init__(self, id=-1, name='', parent=prnt,
>>              pos=wx.Point(519, 306), size=wx.Size(846, 508),
>>              style=wx.DEFAULT_FRAME_STYLE, title='Frame3')
>>        self.SetClientSize(wx.Size(838, 464))
>>
>>        self.panel1 = wx.Panel(id=-1, name='panel1', parent=self,
>>              pos=wx.Point(0, 0), size=wx.Size(838, 464), style=0)
>>
>>        # Create the Box and sizer for the outline
>> ##        box = wx.StaticBox(self, -1, "This is a wx.StaticBox")
>>        self.panel1.box = wx.StaticBox(parent=self.panel1, id=-1, 
>> label="This is a wx.StaticBox")
>>        self.panel1.bsizer = wx.StaticBoxSizer(self.panel1.box, 
>> wx.VERTICAL)
>>
>>        # Create the sizer and place my controls within it
>>        self.panel1.gbs = wx.GridBagSizer(5, 5)
>>
>>        self.panel1.a_btn = wx.Button(self.panel1, -1, "Button 1", 
>> (-1,-1), (250,100))
>>        self.panel1.b_btn = wx.Button(self.panel1, -1, "Button 2", 
>> (-1,-1), (250,100))
>>        self.panel1.c_btn = wx.Button(self.panel1, -1, "Button 3", 
>> (-1,-1), (150,-1))
>>        self.panel1.d_btn = wx.Button(self.panel1, -1, "Button 4", 
>> (-1,-1), (150,-1))
>>        self.panel1.e_btn = wx.Button(self.panel1, -1, "Button 5", 
>> (-1,-1), (150,-1))
>>        self.panel1.f_btn = wx.Button(self.panel1, -1, "Button 6", 
>> (-1,-1), (150,-1))
>>
>>        self.panel1.gbs.Add( self.panel1.a_btn, (0,0), (1,1), 
>> flag=wx.EXPAND )
>>        self.panel1.gbs.Add( self.panel1.b_btn, (2,0), (1,1), 
>> flag=wx.EXPAND )
>>        self.panel1.gbs.Add( self.panel1.c_btn, (2,1), (1,1), 
>> flag=wx.EXPAND )
>>        self.panel1.gbs.Add( self.panel1.d_btn, (3,0), (1,1), 
>> flag=wx.EXPAND )
>>        self.panel1.gbs.Add( self.panel1.e_btn, (3,1), (1,1), 
>> flag=wx.EXPAND )
>>        self.panel1.gbs.Add( self.panel1.f_btn, (5,0), (1,1), 
>> flag=wx.EXPAND )
>>
>>        self.panel1.gbs.AddGrowableRow(0)
>>        self.panel1.gbs.AddGrowableRow(2)
>>        self.panel1.gbs.AddGrowableRow(3)
>>        self.panel1.gbs.AddGrowableRow(5)
>>        self.panel1.gbs.AddGrowableCol(0)
>>
>>        # Place the Controls within the Static Box Sizer
>>        ##       self.bsizer.Add(self.gbs, 0, wx.TOP|wx.LEFT, 10)
>>        self.panel1.bsizer.Add(self.panel1.gbs, 1, 
>> wx.TOP|wx.LEFT|wx.EXPAND, 0)
>>
>>        # Place the Static Box Sizer within the Border frame
>>        # Creating a border that my box static box will sit inside
>>        self.panel1.border = wx.BoxSizer()
>>        self.panel1.border.Add(self.panel1.bsizer, 1000, 
>> wx.EXPAND|wx.ALL, 10)
>>        self.panel1.SetSizer(self.panel1.border)
>> ##        self.panel1.SetAutoLayout(True)
>> ##        self.SetAutoLayout(True)
> 
> #Prueba a poner aqui:
>     self.panel1.border.SetSizeHints(self.panel1)
>         self.Fit()
>         self.Layout()
> 
>>
>>    def __init__(self, parent):
>>        self._init_ctrls(parent)
>>        self.parent = parent
>>        self.Center()
>>
> 
Ha funcionado perfecto!
con el self.Fit() ha sido suficiente.
Una vez más, muchas gracias Oswaldo.
------------ próxima parte ------------
_______________________________________________
Lista de correo Python-es 
http://listas.aditel.org/listinfo/python-es
FAQ: http://listas.aditel.org/faqpyes


Más información sobre la lista de distribución Python-es