Layout Constraints

trying to get layout contraints working, i want the wxTectCtrl to fit the size of the window. i tried copying stuff from the demo, but it doesnt work - i get the same effect as i would without.
reading up on layout techniques, layout constraints sounds to me like what i need. but i cant get it working :/.
if its relavent, im using python 2.2.2 and wxpython 2.3.3.1 - any help would be appreciated.

from wxPython.wx import *

class MyFrame(wxFrame):

    def __init__(self, parent, id, title):
        wxFrame.__init__(self, parent, id, title,
                         wxPoint(100, 100), wxSize(500, 400))

        EVT_CLOSE(self, self.OnCloseWindow)

        self.textWindow = wxTextCtrl(self.panel, -1, "", style=wxTE_MULTILINE)
        cons = wxLayoutConstraints()
        cons.top.SameAs(self.panel, wxTop)
        cons.right.SameAs(self.panel, wxRight)
        cons.width.PercentOf(self.panel, wxWidth, 100)
        cons.height.PercentOf(self.panel, wxHeight, 100)
        self.textWindow.SetConstraints(cons)

        self.panel = wxPanel(self, -1)

    def OnCloseWindow(self, event):
        self.Destroy()

class MyApp(wxApp):

    def OnInit(self):

        self.frame = MyFrame(None, -1, "TITLE")
        self.frame.Show(true)
        self.frame.size = (10, 10)
        self.SetTopWindow(self.frame)

        return true

app = MyApp(0)
app.MainLoop()

I think you need "self.SetAutoLayout(true)" in your __init__ method.
Regards,
Brendan Simon.

Amos Joshua wrote:

···

trying to get layout contraints working, i want the wxTectCtrl to fit the size of the window. i tried copying stuff from the demo, but it doesnt work - i get the same effect as i would without.
reading up on layout techniques, layout constraints sounds to me like what i need. but i cant get it working :/.
if its relavent, im using python 2.2.2 and wxpython 2.3.3.1 - any help would be appreciated.

from wxPython.wx import *

class MyFrame(wxFrame):

   def __init__(self, parent, id, title):
       wxFrame.__init__(self, parent, id, title,
                        wxPoint(100, 100), wxSize(500, 400))

       EVT_CLOSE(self, self.OnCloseWindow)

       self.textWindow = wxTextCtrl(self.panel, -1, "", style=wxTE_MULTILINE)
       cons = wxLayoutConstraints()
       cons.top.SameAs(self.panel, wxTop)
       cons.right.SameAs(self.panel, wxRight)
       cons.width.PercentOf(self.panel, wxWidth, 100)
       cons.height.PercentOf(self.panel, wxHeight, 100)
       self.textWindow.SetConstraints(cons)

       self.panel = wxPanel(self, -1)

   def OnCloseWindow(self, event):
       self.Destroy()

class MyApp(wxApp):

   def OnInit(self):

       self.frame = MyFrame(None, -1, "TITLE")
       self.frame.Show(true)
       self.frame.size = (10, 10)
       self.SetTopWindow(self.frame)

       return true

app = MyApp(0)
app.MainLoop()

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

I think you need "self.SetAutoLayout(true)" in your __init__ method.

That sounds like the right idea but...

> self.textWindow = wxTextCtrl(self.panel, -1, "",
> style=wxTE_MULTILINE)
> cons = wxLayoutConstraints()
> cons.top.SameAs(self.panel, wxTop)
> cons.right.SameAs(self.panel, wxRight)
> cons.width.PercentOf(self.panel, wxWidth, 100)
> cons.height.PercentOf(self.panel, wxHeight, 100)
> self.textWindow.SetConstraints(cons)
>
>
> self.panel = wxPanel(self, -1)

...can you really refer to an undeclared variable in the constraints declaration? Every time I did
that by mistake I get an error thrown at me.

David Gentle

David Gentle wrote:

I think you need "self.SetAutoLayout(true)" in your __init__ method.
   

That sounds like the right idea but...

      self.textWindow = wxTextCtrl(self.panel, -1, "",
style=wxTE_MULTILINE)
      cons = wxLayoutConstraints()
      cons.top.SameAs(self.panel, wxTop)
      cons.right.SameAs(self.panel, wxRight)
      cons.width.PercentOf(self.panel, wxWidth, 100)
      cons.height.PercentOf(self.panel, wxHeight, 100)
      self.textWindow.SetConstraints(cons)

      self.panel = wxPanel(self, -1)
     

...can you really refer to an undeclared variable in the constraints declaration? Every time I did
that by mistake I get an error thrown at me.

I don't understand. What is undeclared ???

Cheers,
Brendan Simon.

This seems to work:

I got rid of the reference to the panel (which wasn’t declared) and added " self.SetAutoLayout(true)".

It seems to work…

Chris.

from wxPython.wx import *

class MyFrame(wxFrame):

def init(self, parent, id, title):
wxFrame.init(self, parent, id, title,
wxPoint(100, 100), wxSize(500, 400))

EVT_CLOSE(self, self.OnCloseWindow)

self.textWindow = wxTextCtrl(self, -1, “”,
style=wxTE_MULTILINE)
self.SetAutoLayout(true)
cons = wxLayoutConstraints()
cons.top.SameAs(self, wxTop)
cons.right.SameAs(self, wxRight)
cons.width.PercentOf(self, wxWidth, 100)
cons.height.PercentOf(self, wxHeight, 100)
self.textWindow.SetConstraints(cons)

    self = wxPanel(self, -1)

def OnCloseWindow(self, event):
self.Destroy()

class MyApp(wxApp):

def OnInit(self):

self.frame = MyFrame(None, -1, “TITLE”)
self.frame.Show(true)
self.frame.size = (10, 10)
self.SetTopWindow(self.frame)

return true

app = MyApp(0)
app.MainLoop()

thank you all so much! this has had me stuck for the past three days.

btw - youre right, the declaration of 'panel' should come before declaring the constraints.
that happend because i didnt check the code before i sent it, i will next time.

>>> self.textWindow = wxTextCtrl(self.panel, -1, "",
>>>style=wxTE_MULTILINE)
>>> cons = wxLayoutConstraints()
>>> cons.top.SameAs(self.panel, wxTop)
>>> cons.right.SameAs(self.panel, wxRight)
>>> cons.width.PercentOf(self.panel, wxWidth, 100)
>>> cons.height.PercentOf(self.panel, wxHeight, 100)
>>> self.textWindow.SetConstraints(cons)
>>>
>>>
>>> self.panel = wxPanel(self, -1)
I don't understand. What is undeclared ???

self.panel is declared after it's referenced as parent by self.textWindow and used in the
constraints.
Of course it could be that I don't understand Python nearly as well as I think I do.

David Gentle