[wxPython] wxBoxSizer - how to use it?

I have just found that adding button_panel.Layout() just after the
button_panel.SetSizer() fixes the problem. However, is there more simple
way to achive my goals?

···

----
Sincerely Yours, Victor V. Kryukov, UFG
phone: +7501 967 3727, ext. 4387
email: vkryukov@ufg.com

-----Original Message-----
From: Krjukov Victor
Sent: Wednesday, October 16, 2002 8:50 PM
To: wxpython-users@lists.wxwindows.org
Subject: [wxPython] wxBoxSizer - how to use it?

Greetings,

Can someone please explain me the right way to use sizers in the
following situation:

I want to have a Dialog (or Frame, that doesn't matter) with layout as
in wxBoxSizer example in the wxWindows doc

http://www.lpthe.jussieu.fr/~zeitlin/wxWindows/docs/wxwin475.h
tm#boxsize
rprogramming

except that OK button should be aligned to the left and Cancel button
should be aligned to the right.

To achieve this I inserted a spacer between this two buttons.

I've modified wxWindows doc's example in following way (see attached
script) and I am facing very strange behaviour.

When I first start my program, I see OK button aligned to the left-top
instead of left-center and see no Cancel button. After *any* resize,
Cancel button appears and buttons layouted in the way I want.

What is the reason for this strange behaviour? What is the correct way
to implement the layout I want?

I also think it would be a good improvement to have such
example in the
demo program.

Sincerely Yours, Victor.

I use wxWindows 2.3.3.1, python 2.2.2, Windows 2000 if this can help.

=======>
from wxPython.wx import *

class MyDialog(wxDialog):
    def __init__(self, parent, id, title):
        wxDialog.__init__(self, parent, id, title,
                          style = wxDEFAULT_DIALOG_STYLE |
wxRESIZE_BORDER)

        topsizer = wxBoxSizer(wxVERTICAL)
        topsizer.Add(
            wxTextCtrl(self, -1, "My text.", pos = wxDefaultPosition,
                       size = wxSize(100, 60), style =
wxTE_MULTILINE),
            1, wxEXPAND | wxALL, 10)

        button_panel = wxPanel(self, -1)
        button_sizer = wxBoxSizer(wxHORIZONTAL)
        button_sizer.Add(wxButton(button_panel, wxID_OK, "OK"), 0,
wxALL, 10)
        button_sizer.Add(0,0,1)
        button_sizer.Add(wxButton(button_panel, wxID_CANCEL,
"Cancel"),
0, wxALL, 10)

        button_sizer.Fit(button_panel)
        button_panel.SetAutoLayout(true)
        button_panel.SetSizer(button_sizer)

        topsizer.Add(button_panel, 0, wxALIGN_CENTER | wxEXPAND)

        self.SetSizer(topsizer)
        topsizer.SetSizeHints(self)

class MyApp(wxApp):
    def OnInit(self):
        dialog = MyDialog(None, -1, "My dialog.")
        self.SetTopWindow(dialog)
        dialog.ShowModal()
        dialog.Destroy()

        return true

if __name__ == '__main__':
    app = MyApp(0)
    app.MainLoop()
<=======

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

Krjukov Victor wrote:

I have just found that adding button_panel.Layout() just after the
button_panel.SetSizer() fixes the problem. However, is there more simple
way to achive my goals?

Well, first, I think you want to call topsizer.Fit instead of topsizer.SetSizeHints. Then, one way is to eliminate the button_panel, make the buttons children of the dialog, and add the button_sizer instead of the button_panel to the topsizer:

class MyDialog(wxDialog):
     def __init__(self, parent, id, title):
         wxDialog.__init__(self, parent, id, title,
                           style = wxDEFAULT_DIALOG_STYLE |
wxRESIZE_BORDER)

         topsizer = wxBoxSizer(wxVERTICAL)
         topsizer.Add(
             wxTextCtrl(self, -1, "My text.", pos = wxDefaultPosition,
                        size = wxSize(100, 60), style = wxTE_MULTILINE),
             1, wxEXPAND | wxALL, 10)

         button_sizer = wxBoxSizer(wxHORIZONTAL)
         button_sizer.Add(wxButton(self, wxID_OK, "OK"), 0, wxALL, 10)
         button_sizer.Add(0,0,1)
         button_sizer.Add(wxButton(self, wxID_CANCEL, "Cancel"), 0, wxALL, 10)

         topsizer.Add(button_sizer, 0, wxALIGN_CENTER | wxEXPAND)

         self.SetAutoLayout(true)
         self.SetSizer(topsizer)
         topsizer.Fit(self)

···

----
Sincerely Yours, Victor V. Kryukov, UFG
phone: +7501 967 3727, ext. 4387
email: vkryukov@ufg.com

-----Original Message-----
From: Krjukov Victor Sent: Wednesday, October 16, 2002 8:50 PM
To: wxpython-users@lists.wxwindows.org
Subject: [wxPython] wxBoxSizer - how to use it?

Greetings,

Can someone please explain me the right way to use sizers in the
following situation:

I want to have a Dialog (or Frame, that doesn't matter) with layout as
in wxBoxSizer example in the wxWindows doc

http://www.lpthe.jussieu.fr/~zeitlin/wxWindows/docs/wxwin475.h
tm#boxsize
rprogramming

except that OK button should be aligned to the left and Cancel button
should be aligned to the right.

To achieve this I inserted a spacer between this two buttons.

I've modified wxWindows doc's example in following way (see attached
script) and I am facing very strange behaviour.

When I first start my program, I see OK button aligned to the left-top
instead of left-center and see no Cancel button. After *any* resize,
Cancel button appears and buttons layouted in the way I want.

What is the reason for this strange behaviour? What is the correct way
to implement the layout I want?

I also think it would be a good improvement to have such example in the
demo program.

Sincerely Yours, Victor.

I use wxWindows 2.3.3.1, python 2.2.2, Windows 2000 if this can help.

=======>
from wxPython.wx import *

class MyDialog(wxDialog):
   def __init__(self, parent, id, title):
       wxDialog.__init__(self, parent, id, title,
                         style = wxDEFAULT_DIALOG_STYLE |
wxRESIZE_BORDER)

       topsizer = wxBoxSizer(wxVERTICAL)
       topsizer.Add(
           wxTextCtrl(self, -1, "My text.", pos = wxDefaultPosition,
                      size = wxSize(100, 60), style = wxTE_MULTILINE),
           1, wxEXPAND | wxALL, 10)

       button_panel = wxPanel(self, -1)
       button_sizer = wxBoxSizer(wxHORIZONTAL)
       button_sizer.Add(wxButton(button_panel, wxID_OK, "OK"), 0,
wxALL, 10)
       button_sizer.Add(0,0,1)
       button_sizer.Add(wxButton(button_panel, wxID_CANCEL, "Cancel"),
0, wxALL, 10)

       button_sizer.Fit(button_panel)
       button_panel.SetAutoLayout(true)
       button_panel.SetSizer(button_sizer)

       topsizer.Add(button_panel, 0, wxALIGN_CENTER | wxEXPAND)

       self.SetSizer(topsizer)
       topsizer.SetSizeHints(self)

class MyApp(wxApp):
   def OnInit(self):
       dialog = MyDialog(None, -1, "My dialog.")
       self.SetTopWindow(dialog)
       dialog.ShowModal()
       dialog.Destroy()

       return true

if __name__ == '__main__':
   app = MyApp(0)
   app.MainLoop()
<=======

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users