Layout en wxPython

Carlos López Pérez clp en opencanarias.com
Mar Jul 22 10:42:02 CEST 2003


The class Layoutf(wxLayoutConstraints) presents a simplification
of the wxLayoutConstraints syntax. The name Layoutf is choosen
because of the similarity with C's printf function.

Quick Example:

    lc = Layoutf('t=t#1;l=r10#2;r!100;h%h50#1', (self, self.panel))

is equivalent to

    lc = wxLayoutContraints()
    lc.top.SameAs(self, wxTop)
    lc.left.SameAs(self.panel, wxRight, 10)
    lc.right.Absolute(100)
    lc.height.PercentOf(self, wxHeight, 50)

Usage:

    You can give a constraint string to the Layoutf constructor,
or use the 'pack' method. The following are equivalent:

    lc = Layoutf('t=t#1;l=r#2;r!100;h%h50#1', (self, self.panel))

and

    lc = Layoutf()
    lc.pack('t=t#1;l=r#2;r!100;h%h50#1', (self, self.panel))

    Besides 'pack' there's also 'debug_pack' which does not set
constraints, but prints traditional wxLayoutConstraint calls to
stdout.

    The calls to the Layoutf constructor and pack methods have
the following argument list:

    (constraint_string, objects_tuple)

Constraint String syntax:

    Constraint directives are separated by semi-colons. You
generally (always?) need four directives to completely describe a
subwindow's location.

    A single directive has either of the following forms:

    1. <own attribute><compare operation>[numerical argument]
    for example r!100 -> lc.right.Absolute(100) )
    and w* -> lc.width.AsIs()

    2. <own attribute><compare operation>[numerical argument]
       #<compare object nr.>
    for example t_10#2 (lc.top.Below(<second obj>, 10)

    3. <own attribute><compare operation><compare attribute>
       [numerical argument]#<compare object nr.>
    for example w%h50#2 ( lc.width.PercentOf(<second obj>,
    wxHeight, 50) and t=b#1 ( lc.top.SameAs(<first obj>,
    wxBottom) )

    Which one you need is defined by the <compare operation>
type. The following take type 1 (no object to compare with):

    '!': 'Absolute', '?': 'Unconstrained', '*': 'AsIs'

These take type 2 (need to be compared with another object)

    '<': 'LeftOf', '>': 'RightOf', '^': 'Above', '_': 'Below'

These take type 3 (need to be compared to another object
attribute)

    '=': 'SameAs', '%': 'PercentOf'

For all types, the <own attribute> letter can be any of

    't': 'top', 'l': 'left', 'b': 'bottom',
    'r': 'right', 'h': 'height', 'w': 'width',
    'x': 'centreX', 'y': 'centreY'

If the operation takes an (optional) numerical argument, place it
in [numerical argument].  For type 3 directives, the <compare
attribute> letter can be any of

    't': 'wxTop', 'l': 'wxLeft', 'b': 'wxBottom'
    'r': 'wxRight', 'h': 'wxHeight', 'w': 'wxWidth',
    'x': 'wxCentreX', 'y': 'wxCentreY'

Note that these are the same letters as used for <own attribute>,
so you'll only need to remember one set. Finally, the object
whose attribute is refered to, is specified by #<compare object
nr>, where <compare object nr> is the 1-based (stupid, I know,
but I've gotten used to it) index of the object in the
objects_tuple argument.

Bugs:

Not entirely happy about the logic in the order of arguments
after the <compare operation> character.

Not all wxLayoutConstraint methods are included in the
syntax. However, the type 3 directives are generally the most
used. Further excuse: wxWindows layout constraints are at the
time of this writing not documented.
  ----- Original Message ----- 
  From: Gema Núñez Blázquez 
  To: ListaPython-es 
  Sent: Tuesday, July 22, 2003 9:24 AM
  Subject: [Python-es] Layout en wxPython


  Hola necesito ayuda sobre un tema que es el siguiente:

  Tengo un MiniFrame donde muestro una caja de texto y un botón que está dentro de un panel. Lo que quiero es que cuando el usuario cambie de tamaño la ventana los controles cambien de forma proporcional al nuevo tamaño para eso quiero utilizar Layout.

  El caso es que cuando pongo la siguiente linea:

  self.control.SetConstraints(Layoutf('X=X#1;Y=Y#1;h*;w%w50#1', (panel,)))

  me muestra el panel y el boton pero no la caja de texto. Además que son esos caracteres ('X=X#1;Y=Y#1;h*;w%w50#1') que hay que meter al crear el Layoutf?.

  Si alguient puede darme algunas notas sobre los Layout y como puedo solucionarlo se lo agradecería

  El código de mi ventana es la siguiente:

  La caja de texto está declarada como self.control porque necesito acceder desde fuera para poder ir insertando texto.

  import sys, os

  from wxPython.wx import *

  from wxPython.lib.layoutf import Layoutf

  class main_window(wxMiniFrame):

  def __init__(self, parent, id, title):

  wxMiniFrame.__init__(self, parent, id, title, pos=wxDefaultPosition, #size:ancho, alto

  style=wxDEFAULT_FRAME_STYLE|wxTINY_CAPTION_HORIZ)#|wxNO_FULL_REPAINT_ON_RESIZE) 

  panel = wxPanel(self, -1)

  panel.SetAutoLayout(true)

  panel.SetBackgroundColour(wxBLUE)

  panel.SetConstraints(Layoutf('t=t10#1;l=l10#1;b=b10#1;r%r50#1',(self,)))

  self.control = wxTextCtrl(panel, -1, style=wxTE_MULTILINE|wxTE_RICH2,size=(495, 450))#size(ancho,alto)

  self.control.SetConstraints(Layoutf('X=X#1;Y=Y#1;h*;w%w50#1', (panel,)))

  btnSalir = wxButton(panel, 1, "Cerrar", wxPoint(215, 450))#el 10 es el identificador

  btnSalir.SetBackgroundColour(wxBLUE)

  btnSalir.SetForegroundColour(wxWHITE)

  #btnSalir.SetDefault()

  EVT_BUTTON(self, 1, self.OnCloseMe)

  EVT_CLOSE(self, self.OnCloseWindow)

  self.Show(true)

  def OnCloseMe(self, event):

  self.Close(true)

  def OnCloseWindow(self, event):

  self.Destroy()

  class App(wxApp):

  def OnInit(self):

  self.frame = main_window(None, -1, "Proceso")

  self.frame.SetSize(wxSize(500, 500))

  self.frame.Centre(wxBOTH)

  self.SetTopWindow(self.frame)

  return true

  app = App(0)

  app.MainLoop()

  Gracias



------------------------------------------------------------------------------
  Yahoo! Messenger
  Nueva versión: Super Webcam, voz, caritas animadas, y más ¡Gratis!


------------------------------------------------------------------------------


  _______________________________________________
  Python-es mailing list
  Python-es en aditel.org
  http://listas.aditel.org/listinfo/python-es


  __________ NOD32 1.465 (20030721) Information __________

  This message was checked by NOD32 Antivirus System.
  http://www.nod32.com

------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://mail.python.org/pipermail/python-es/attachments/20030722/d967bb27/attachment.html>
------------ próxima parte ------------
_______________________________________________
Python-es mailing list
Python-es en aditel.org
http://listas.aditel.org/listinfo/python-es


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