views:

285

answers:

1

Ok, so I'm learning about sizers in wxPython and I was wondering if it was possible to do something like:

==============================================
|WINDOW TITLE                          _ [] X|
|============================================|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxNOTEBOOKxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
|________                         ___________|
|IMAGE   |                       |LoginForm  |
|________|                       |___________|
==============================================

NOTE:Yeah, I literally got this from http://stackoverflow.com/questions/1892110/wxpython-picking-the-right-sizer-to-use-in-an-application

With NOTEBOOK expanded to left and bottom, IMAGE to align to left and bottom and loginform align to right and bottom and I managed to do almost everything but now I have a problem..

The problem is that I can't align Loginform and Image separately (im using Box Sizers), and I would like to.

EDIT: So everyone can see what I mean: "Oh and what I was referring to, was basically that if I changed the align, it would affect both LoginForm and Image.. For example if I set the align to RIGHT, both image and loginform would have been aligned to the right because of: sizer.Add(sizer4,0, wx.ALIGN_RIGHT | wx.RIGHT, 10). Hope you guys can understand this time"

This is the code I'm using that is causing the problem at the moment, any help is appreciated. NOTE:The code might be (HUGELY) sloppy as I'm still learning box sizers. Heres a test code:

import wx
class Sizerframe(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'sizertestframe',size=(790, 524))
        p = wx.Panel(self)
        nb = wx.Notebook(p, size = (750, 332))
        button = wx.Button(p, -1, "loginform1rest", size=(94,23))
        button1 = wx.Button(p, -1, "Login", size=(94,23))
        button2 = wx.Button(p, -1, "Cancel", size=(94,23))
        imagebutton = wx.Button(p, -1, "imagebutton", size=(94,23))



        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer1 = wx.BoxSizer(wx.HORIZONTAL)
        sizer1.Add(nb,1, wx.EXPAND)
        sizer.Add(sizer1,1, wx.LEFT | wx.RIGHT | wx.EXPAND, 10)
        sizer.Add((-1, 25))
        sizer2 = wx.BoxSizer(wx.VERTICAL)
        sizer2.Add(button, 0)
        sizer3 = wx.BoxSizer(wx.HORIZONTAL)
        sizer3.Add(button1, 0)
        sizer3.Add(button2,0, wx.LEFT, 5)
        sizer2.Add(sizer3, 0)

        sizer4 = wx.BoxSizer(wx.HORIZONTAL)
        sizer4.Add(imagebutton, 1, wx.LEFT | wx.BOTTOM)
        sizer4.Add(sizer2,0, wx.RIGHT | wx.BOTTOM , 5)
        sizer.Add(sizer4,0, wx.ALIGN_RIGHT | wx.RIGHT, 10)
        p.SetSizer(sizer)

def main():
    app = wx.App()
    frame = Sizerframe()
    frame.Show()
    app.MainLoop()
if __name__ == '__main__':
    main()
+1  A: 

How about something like this?

container = wx.BoxSizer(wx.VERTICAL)
container.Add(self.nb, 1, wx.EXPAND)

login = wx.BoxSizer(wx.VERTICAL)
login.Add(self.userLabel)
login.Add(self.userText)

# ... clip, rest of login form additions here

bottom = wx.BoxSizer(wx.HORIZONTAL)
bottom.Add(image)
bottom.Add((0, 0), 1, wx.EXPAND)
bottom.Add(login)

container.Add(bottom, 1, wx.EXPAND)

Basically, the bottom.Add((0, 0), 1, wx.EXPAND) will act as a spacer that'll take up all the space between the image and the login form. I didn't really understand what you meant by "The problem is that I can't align Loginform and Image separately (im using Box Sizers), and I would like to". I mostly just followed the illustration in trying to create a layout. I hope this helps.

synic
Thanks for your response, ill analyze it tomorrow as I'm off to bed, I also added a test code in case you want mess with it, thanks alot for your response nonetheless
Francisco Aleixo
No problem. You can make most layouts with different combinations of nested BoxSizers.
synic
Oh and what I was referring to, was basically that if I changed the align, it would affect both LoginForm and Image.. For example if I set the align to RIGHT, both image and loginform would have been aligned to the right because of:sizer.Add(sizer4,0, wx.ALIGN_RIGHT | wx.RIGHT, 10).Hope you can understand this time.
Francisco Aleixo
Oh, yeah, you shouldn't have to worry about that with the "spacer" I added there.
synic
Instead of that manually-built spacer, you should consider using `bottom.AddStretchSpacer()`.
Philippe Beaudoin
Hah, awesome. How did I miss that one?
synic
Hey, I'm sorry if I'm being ignorant at the moment and I should change something, but at the moment, with that piece of code, again, everything works right but now I can't align (loginform isn't aligned) to right/bottom as I pretended to, instead its only aligned to bottom. Sorry if I'm missing something but I'm still learning and I really want to get this right ;). Still, you helped alot in understanding this, thanks.
Francisco Aleixo
Could you post a screenshot? I guess I still don't understand what you mean by aligned. Aligned to what?
synic
http://img121.imageshack.us/i/problemtv.jpg/Sorry if this isn't the way to post links here in SO.NOTE: The login form was in the corner with the default size, but in that pic, the form is resized
Francisco Aleixo
Hrmm, I almost want you to post your code again. That `bottom.AddStretchSpacer()` should take up all the space between the image on the left and the login form on the right.
synic
I've been searching how the "AddStretchSpacer" works but didn't find anything relevant (or didn't search properly). Adding only bottom.AddStretchSpacer() doesn't do anything so I was wondering how does it work?
Francisco Aleixo
It just adds an empty space that expands. So, if you only add it, and no controls after it, you won't see anything.
synic
But just by adding AddStretchSpacer() without any control it adds an empty space that expands? Because it didn't do anything to me, didn't even add a space nor expanded.
Francisco Aleixo
Pastebin your code at pastie.org, or edit your post and paste it
synic
http://pastie.org/915807
Francisco Aleixo
Yeah, change: `bottom.Add(login, wx.LEFT, 15)` to `bottom.Add(login)`, or `bottom.Add(login, border=15)` if you still want that border.
synic
Just did that, and still the same, can't align that loginform to the corner.. And still the AddStretchSpacer() doesn't do any space at all, atleast that I can see of... The only way I see I can do a space is with your way in your original answer.
Francisco Aleixo
Oh, and change `container.Add(bottom)` to `container.Add(bottom, 1, ex.EXPAND)` - sorry about that.
synic
Thank you so much you just solved the problem!By the way, when I did that it just added a big space at the bottom, do you know the reason? Thank you again!http://img412.imageshack.us/img412/7240/giantm.jpg
Francisco Aleixo
Whoops, try this: `container.Add(bottom, 0, wx.EXPAND)`
synic
Oh man, thank you so much! I appreciate your help ALOT!
Francisco Aleixo