[wxPython] wxCheckBox & wxStaticBox

Hi

I'm to implement a dialog of (more less) such struchture (a test
configuration):

···

+-----------------------------------------------------+

+- test 1 -----------------------------------+ |
> sub test 1.1 | |
> sub test 1.2 | |
> sub test 1.3 | |
+------------------------------------------------+ |
+- test 2 -----------------------------------+ |
> sub test 2.1 | |
> sub test 2.2 | |
> sub test 2.3 | |
+------------------------------------------------+ |
+- test 3 -----------------------------------+ |
> sub test 3.1 | |
> sub test 3.2 | |
> sub test 3.3 | |
+------------------------------------------------+ |
+----------+ +----------+ |
> OK | | Cancel | |
+----------+ +----------+ |

+-----------------------------------------------------+

Where all "" are wxCheckBoxes. If " test 1" is unchecked all its sub
tests are desabled, and if checked then enabeld. Thats esay ofcource.

But how do I group the checkboxex so nicely ? Do I have to put a wxCheckBox
and below it a wxStaticBox with the sub test checkboxes ? Or can can I mix
(somehow) wxCheckBox with wxStaticBox ?

And how do I tell a wxStaticBox which widgets to wrap around ?

Thanks for sugestions.

Przemek G.

I have been working on (playing with) nested panels and nested
sizers, including wxStaticBoxSizers, so trying to answer your
question seemed like a good way to test my approach. This is not
necessarily the most efficient way (for example, there is reason to
create a separate ButtonPanel as I did, except to demonstrate
nesting panels), but the code that follows produces a frame that is
similar to what you requested. BTW I don't think it is possible to
put a checkbox IN the border of the static box.

from wxPython.wx import *

class CheckBoxPanel(wxPanel):
    def __init__(self, parent, spacer=0, text=''):
        wxPanel.__init__(self, parent, -1)
        sizer = wxBoxSizer(wxHORIZONTAL)
        sizer.Add(spacer, 5, 0, wxEXPAND)
        sizer.Add(wxCheckBox(self, -1, text), 1, wxEXPAND|wxALL, 5)
        sizer.Fit(self) # set panel to minimum size
        self.SetAutoLayout(true) # tell frame to use sizer
        self.SetSizer(sizer) # actually set the sizer
        sizer.SetSizeHints(self) # set size hints, honor mininum

class ButtonPanel(wxPanel):
    def __init__(self, parent, id=-1):
        wxPanel.__init__(self, parent, id)
        sizer = wxBoxSizer(wxHORIZONTAL)
        sizer.Add(wxButton(self, -1, 'OK'), 1, wxEXPAND)
        sizer.Add(wxButton(self, -1, 'Cancel'), 1, wxEXPAND)
        sizer.Fit(self) # set panel to minimum size
        self.SetAutoLayout(true) # tell frame to use sizer
        self.SetSizer(sizer) # actually set the sizer
        sizer.SetSizeHints(self) # set size hints, honor mininum

class TestPanel(wxPanel):
    def __init__(self, parent, id=-1):
        wxPanel.__init__(self, parent, id)
        sizer = wxStaticBoxSizer(wxStaticBox(self, -1, 'Test',
                                 style=wxSUNKEN_BORDER),
wxVERTICAL)
        sizer.Add(CheckBoxPanel(self, 0, 'test'), 1, wxEXPAND)
        sizer.Add(CheckBoxPanel(self, 20, 'subtest'), 1, wxEXPAND)
        sizer.Add(CheckBoxPanel(self, 20, 'subtest'), 1, wxEXPAND)
        sizer.Add(CheckBoxPanel(self, 20, 'subtest'), 1, wxEXPAND)
        sizer.Fit(self) # set panel to minimum size
        self.SetAutoLayout(true) # tell frame to use sizer
        self.SetSizer(sizer) # actually set the sizer
        sizer.SetSizeHints(self) # set size hints, honor mininum

class MyPanel(wxPanel):
    def __init__(self, parent, id=-1):
        wxPanel.__init__(self, parent, id)
        sizer = wxBoxSizer(wxVERTICAL)
        sizer.Add(TestPanel(self), 3, wxEXPAND)
        sizer.Add(TestPanel(self), 3, wxEXPAND)
        sizer.Add(TestPanel(self), 3, wxEXPAND)
        sizer.Add(ButtonPanel(self), 1, wxEXPAND)
        sizer.Fit(self) # set panel to minimum size
        self.SetAutoLayout(true) # tell frame to use sizer
        self.SetSizer(sizer) # actually set the sizer
        sizer.SetSizeHints(self) # set size hints, honor mininum

class MyFrame(wxFrame):
    def __init__(self):
        wxFrame.__init__(self, None, -1, 'Test Suite')
        sizer = wxBoxSizer(wxHORIZONTAL)
        sizer.Add(MyPanel(self), 1, wxEXPAND)
        sizer.Fit(self) # set frame to minimum size
        self.SetAutoLayout(true) # tell frame to use sizer
        self.SetSizer(sizer) # actually set the sizer
        sizer.SetSizeHints(self) # set size hints, honor mininum
        sizer.Layout()

class testApp(wxApp):
    def OnInit(self):
        main = MyFrame()
        self.SetTopWindow(main)
        main.Show(true)
        return true

app = testApp(0)
app.MainLoop()

···

--- Przemys�aw G. Gawro�ski <P.Gawronski@obop.com.pl> wrote:

Hi

I'm to implement a dialog of (more less) such structure (a test
configuration):

<snip>

=====
Donnal Walter
Arkansas Children's Hospital

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage

But how do I group the checkboxex so nicely ? Do I have to put a

wxCheckBox

and below it a wxStaticBox with the sub test checkboxes ? Or can can I mix
(somehow) wxCheckBox with wxStaticBox ?

I can't think of an easy way of "mixing" them, besides creating a custom
control. Does the test1 checkbox have to be visually on top of the static
box, or can they just be stacked vertically?

And how do I tell a wxStaticBox which widgets to wrap around ?

wxStaticBoxSizer makes it easy. It works just like a wxBoxSizer but
arrainges a wxStaticBox around the border.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!