[wxPython] wxlayoutconstraints

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] wxlayoutconstraints

Andrew Swan-2
hi there - i am having trouble with wxLayoutConstraints. in the example below,
i set up a splitter window, with a tree on the left hand side, and a panel on
the right hand side. when i click one of the tree items, i want a scrolled
window to appear in the right hand panel, taking up the top half of said panel.
however, when i activate it, the scrolled window is tiny, and is in the top left
corner of the panel (default size and location i suppose). it only does what its
supposed to do (ie, fills half the panel) when i resize the window (or shift
the splitter bar). any clues as to what i'm doing wrong? i'm a novice at this
having recently started using python and wx after years of perl and tk.

the same thing happens in linux and nt. also, have noticed that in the demo
program, it happens with the htmlwindow demo on linux, but not on windows(!).
on linux, i can't see the html window until i do some resizing.

by the way, you have done a good job mr dunn et al. keep up the good work.
anyway, here's my little example:

#!/usr/bin/python

from wxPython.wx import *

class wxTest(wxFrame):
    def __init__(self,parent,id,title):
        wxFrame.__init__(self,parent,-1,title,size=(725,550))

        splitter = wxSplitterWindow(self,-1)
        self.right = wxPanel(splitter,-1)
        self.right.SetBackgroundColour(wxGREEN)
        self.right.SetAutoLayout(true)

        tID = wxNewId()
        self.tree = wxTreeCtrl(splitter,tID)
        root = self.tree.AddRoot('Parent')
        child1 = self.tree.AppendItem(root,'Child')
        self.tree.Expand(root)

        EVT_TREE_SEL_CHANGED(self.tree,tID,self.treefunc)
       
        splitter.SplitVertically(self.tree,self.right)
        splitter.SetSashPosition(150)

    def treefunc(self, event):
       
        item = event.GetItem()
        itemText = self.tree.GetItemText(item)
       
        if itemText == 'Child':
           
            sw = wxScrolledWindow(self.right,-1,wxPoint(0,0),wxDefaultSize)

            sw.SetBackgroundColour(wxBLUE)
            sw.SetScrollbars(20, 20, 50, -1)
           
            lc = wxLayoutConstraints()
            lc.top.SameAs(self.right, wxTop, 0)
            lc.left.SameAs(self.right, wxLeft, 0)
            lc.right.SameAs(self.right, wxRight, 0)
            lc.bottom.PercentOf(self.right, wxBottom, 50)
            sw.SetConstraints(lc)
   
class MyApp(wxApp):
    def OnInit(self):
        frame = wxTest(NULL,-1,"Test")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

app = MyApp(0)
app.MainLoop()

--
Andrew Swan
CSIRO Animal Production
Pastoral Research Laboratory
Armidale  2350  AUSTRALIA
ph.  +61 (0)2 67761377
fax  +61 (0)2 67761333
email: [hidden email]

_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] wxlayoutconstraints

Robin Dunn
> hi there - i am having trouble with wxLayoutConstraints. in the example
below,
> i set up a splitter window, with a tree on the left hand side, and a panel
on
> the right hand side. when i click one of the tree items, i want a scrolled
> window to appear in the right hand panel, taking up the top half of said
panel.
> however, when i activate it, the scrolled window is tiny, and is in the top
left
> corner of the panel (default size and location i suppose). it only does
what its
> supposed to do (ie, fills half the panel) when i resize the window (or
shift
> the splitter bar). any clues as to what i'm doing wrong?

As you've discovered, AutoLayout happens during size events.  Since you are
adding a window to an already existing and sized splitter, there will be no
size event automatically from the system, so the new window doesn't get
layout'ed and just uses it's default size.  (If the window had been added to
the splitter when the splitter was created, then there would have been one or
more size events when thesplitter was shown and

You should be able to fix this by adding a call to self.right.Layout() at the
end of your treefunc method.  This will run the layout algorithm immediately
instead of waiting for the next size event to happen.


> the same thing happens in linux and nt. also, have noticed that in the demo
> program, it happens with the htmlwindow demo on linux, but not on
windows(!).
> on linux, i can't see the html window until i do some resizing.

Hmm...  Guess I havn't looked at the HtmlWindow on GTK for a while...

>
> by the way, you have done a good job mr dunn et al. keep up the good work.

Thanks!

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] wxlayoutconstraints

Robin Dunn
> layout'ed and just uses it's default size.  (If the window had been added
to
> the splitter when the splitter was created, then there would have been one
or
> more size events when thesplitter was shown and
>

I'm a bit absent-minded today and didn't finish my sentence.  Just add
"correct layout would have happened.)" to the above.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users