sized_controls and StaticBox/StaticBoxSizer

sized_controls doesn't seem to have provision for StaticBoxSizer.

I tried this:

         sbPane = sc.SizedPanel(self.pane, -1)
         sb = wx.StaticBox(sbPane, -1)
         sbSizer = wx.StaticBoxSizer(sb)
         sbPane.SetSizer(sbSizer)
         sbCtrlsPane = sc.SizedPanel(sbPane, -1)
         sbCtrlsPane.SetSizerType('grid', {'cols': 2,})
         st1 = wx.StaticText(sbCtrlsPane, -1, 'static text ctrl')
         tc1 = wx.TextCtrl(sbCtrlsPane, -1, 'something')

self.pane is a sc.SizedPanel and it looks as I like BUT it crashes when I close the dialog which contains all of this. As the crash doesn't give any traceback I am guessing that the SetSizer call is may be stepping on someone.

If I change sbPane to be a wx.Panel instead of a sized one then I don't see any crash but I manually need to handle the sizing of it, which means I loose the HIG spacing.

What is the correct way of using StaticBoxSizer with sized_controls so that everything still respects the HIG's?

Werner

Hi Werner,

sized_controls doesn't seem to have provision for StaticBoxSizer.

I tried this:

       sbPane = sc.SizedPanel(self.pane, -1)
       sb = wx.StaticBox(sbPane, -1)
       sbSizer = wx.StaticBoxSizer(sb)
       sbPane.SetSizer(sbSizer)
       sbCtrlsPane = sc.SizedPanel(sbPane, -1)
       sbCtrlsPane.SetSizerType('grid', {'cols': 2,})
       st1 = wx.StaticText(sbCtrlsPane, -1, 'static text ctrl')
       tc1 = wx.TextCtrl(sbCtrlsPane, -1, 'something')

self.pane is a sc.SizedPanel and it looks as I like BUT it crashes when I close the dialog which contains all of this. As the crash doesn't give any traceback I am guessing that the SetSizer call is may be stepping on someone.

If I change sbPane to be a wx.Panel instead of a sized one then I don't see any crash but I manually need to handle the sizing of it, which means I loose the HIG spacing.

What is the correct way of using StaticBoxSizer with sized_controls so that everything still respects the HIG's?

The basic problem is that sized_controls assumes a natural parent / child hierarchy controls and automatically adds all controls to the parent's sizer, including wx.StaticBox and its siblings. See this thread, particularly the last message, for a workaround:

http://groups.google.com/group/wxpython-users/browse_thread/thread/b7bb7195f17e04b8/323419e1a9d58e62?lnk=gst&q=SizedControls#323419e1a9d58e62

In 2.9, I believe you can now actually make wx.StaticBox a parent and have its internal controls as children, which, if it works as it should, would make the workaround unnecessary.

Regards,

Kevin

···

On Sep 13, 2011, at 6:45 AM, werner wrote:

Werner

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Hi Kevin,

Hi Werner,

sized_controls doesn't seem to have provision for StaticBoxSizer.

I tried this:

        sbPane = sc.SizedPanel(self.pane, -1)
        sb = wx.StaticBox(sbPane, -1)
        sbSizer = wx.StaticBoxSizer(sb)
        sbPane.SetSizer(sbSizer)
        sbCtrlsPane = sc.SizedPanel(sbPane, -1)
        sbCtrlsPane.SetSizerType('grid', {'cols': 2,})
        st1 = wx.StaticText(sbCtrlsPane, -1, 'static text ctrl')
        tc1 = wx.TextCtrl(sbCtrlsPane, -1, 'something')

self.pane is a sc.SizedPanel and it looks as I like BUT it crashes when I close the dialog which contains all of this. As the crash doesn't give any traceback I am guessing that the SetSizer call is may be stepping on someone.

If I change sbPane to be a wx.Panel instead of a sized one then I don't see any crash but I manually need to handle the sizing of it, which means I loose the HIG spacing.

What is the correct way of using StaticBoxSizer with sized_controls so that everything still respects the HIG's?

The basic problem is that sized_controls assumes a natural parent / child hierarchy controls and automatically adds all controls to the parent's sizer, including wx.StaticBox and its siblings. See this thread, particularly the last message, for a workaround:

http://groups.google.com/group/wxpython-users/browse_thread/thread/b7bb7195f17e04b8/323419e1a9d58e62?lnk=gst&q=SizedControls#323419e1a9d58e62

In 2.9, I believe you can now actually make wx.StaticBox a parent and have its internal controls as children, which, if it works as it should, would make the workaround unnecessary.

Since I sent the email I came up with another work around.

- create a SizedStaticBoxPanel

class SizedStaticBoxPanel(wx.Panel):
     def __init__(self, *args, **kwargs):
         wx.Panel.__init__(self, *args, **kwargs)

         self.sBox = wx.StaticBox(self, -1, "Static box")
         bsizer = wx.StaticBoxSizer(self.sBox, wx.VERTICAL)

         if wx.VERSION < (2,9):
             self.mainPanel = SizedPanel(self, -1)
         else:
             self.mainPanel = SizedPanel(self.sBox, -1)

         bsizer.Add(self.mainPanel, 1, wx.EXPAND)

         self.SetSizer(bsizer)

     def GetContentsPane(self):
         return self.mainPanel

     def GetStaticBox(self):
         return self.sBox

Which I then basically use in the same way as a SizedPanel, e.g. my code shown above then becomes this:

         sbBox = sc.SizedStaticBoxPanel(self.pane, wx.ID_ANY)
         sbBox.SetSizerProps(expand=True, proportion=1)
         sbBox.GetStaticBox().SetLabel("my static box")
         sbPane = sbBox.GetContentsPane()
         sbPane.SetSizerType('grid', {'cols': 2,})

         st1 = wx.StaticText(sbPane, wx.ID_ANY, 'static text ctrl')
         tc1 = wx.TextCtrl(sbPane, wx.ID_ANY, 'something')
         tc1.SetSizerProps(expand=True, proportion=0)

I guess should expand it to support the "orient" parameter in some way.

Maybe one or the other idea or a merge of all this could make it into wxPython 2.9?

Werner

···

On 09/13/2011 05:24 PM, Kevin Ollivier wrote:

On Sep 13, 2011, at 6:45 AM, werner wrote:

Hi Kevin,

Hi Kevin,

Hi Werner,

sized_controls doesn't seem to have provision for StaticBoxSizer.

I tried this:

        sbPane = sc.SizedPanel(self.pane, -1)
        sb = wx.StaticBox(sbPane, -1)
        sbSizer = wx.StaticBoxSizer(sb)
        sbPane.SetSizer(sbSizer)
        sbCtrlsPane = sc.SizedPanel(sbPane, -1)
        sbCtrlsPane.SetSizerType('grid', {'cols': 2,})
        st1 = wx.StaticText(sbCtrlsPane, -1, 'static text ctrl')
        tc1 = wx.TextCtrl(sbCtrlsPane, -1, 'something')

self.pane is a sc.SizedPanel and it looks as I like BUT it crashes when I close the dialog which contains all of this. As the crash doesn't give any traceback I am guessing that the SetSizer call is may be stepping on someone.

If I change sbPane to be a wx.Panel instead of a sized one then I don't see any crash but I manually need to handle the sizing of it, which means I loose the HIG spacing.

What is the correct way of using StaticBoxSizer with sized_controls so that everything still respects the HIG's?

The basic problem is that sized_controls assumes a natural parent / child hierarchy controls and automatically adds all controls to the parent's sizer, including wx.StaticBox and its siblings. See this thread, particularly the last message, for a workaround:

http://groups.google.com/group/wxpython-users/browse_thread/thread/b7bb7195f17e04b8/323419e1a9d58e62?lnk=gst&q=SizedControls#323419e1a9d58e62

In 2.9, I believe you can now actually make wx.StaticBox a parent and have its internal controls as children, which, if it works as it should, would make the workaround unnecessary.

Since I sent the email I came up with another work around.

- create a SizedStaticBoxPanel

class SizedStaticBoxPanel(wx.Panel):
    def __init__(self, *args, **kwargs):
        wx.Panel.__init__(self, *args, **kwargs)

        self.sBox = wx.StaticBox(self, -1, "Static box")
        bsizer = wx.StaticBoxSizer(self.sBox, wx.VERTICAL)

        if wx.VERSION < (2,9):
            self.mainPanel = SizedPanel(self, -1)
        else:
            self.mainPanel = SizedPanel(self.sBox, -1)

        bsizer.Add(self.mainPanel, 1, wx.EXPAND)

        self.SetSizer(bsizer)

    def GetContentsPane(self):
        return self.mainPanel

    def GetStaticBox(self):
        return self.sBox

Which I then basically use in the same way as a SizedPanel, e.g. my code shown above then becomes this:

        sbBox = sc.SizedStaticBoxPanel(self.pane, wx.ID_ANY)
        sbBox.SetSizerProps(expand=True, proportion=1)
        sbBox.GetStaticBox().SetLabel("my static box")
        sbPane = sbBox.GetContentsPane()
        sbPane.SetSizerType('grid', {'cols': 2,})

        st1 = wx.StaticText(sbPane, wx.ID_ANY, 'static text ctrl')
        tc1 = wx.TextCtrl(sbPane, wx.ID_ANY, 'something')
        tc1.SetSizerProps(expand=True, proportion=0)

I guess should expand it to support the "orient" parameter in some way.

Maybe one or the other idea or a merge of all this could make it into wxPython 2.9?

A clean up of my work around which supports changing of orientation, only tested (and not extensively) with wxPython 2.9.

class SizedStaticBoxPanel(wx.Panel):
     def __init__(self, *args, **kwargs):
         wx.Panel.__init__(self, *args, **kwargs)

         self._sBox = wx.StaticBox(self, -1, "Static box")
         self._bSizer = wx.StaticBoxSizer(self._sBox, wx.VERTICAL)

         if wx.VERSION < (2,9):
             self.mainPanel = SizedPanel(self, -1)
         else:
             self.mainPanel = SizedPanel(self._sBox, -1)

         self._bSizer.Add(self.mainPanel, 1, wx.EXPAND)

         self.SetSizer(self._bSizer)

     def GetContentsPane(self):
         return self.mainPanel

     def SetStaticBoxLabel(self, label):
         self._sBox.SetLabel(label)

     def SetStaticBoxSizer(self, orient=wx.VERTICAL):
         """Set the orientation of the StaticBoxSizer"""
         self._bSizer.Detach(self._sBox)
         self._bSizer.Detach(self.mainPanel)

         self._bSizer = wx.StaticBoxSizer(self._sBox, orient)
         self._bSizer.Add(self.mainPanel, 1, wx.EXPAND)
         self.SetSizer(self._bSizer)

Or would the preferred approach be Brendan's approach.

Werner

···

On 09/13/2011 07:44 PM, werner wrote:

On 09/13/2011 05:24 PM, Kevin Ollivier wrote:

On Sep 13, 2011, at 6:45 AM, werner wrote:

Hi Werner,

Hi Kevin,

Hi Kevin,

Hi Werner,

sized_controls doesn't seem to have provision for StaticBoxSizer.

I tried this:

       sbPane = sc.SizedPanel(self.pane, -1)
       sb = wx.StaticBox(sbPane, -1)
       sbSizer = wx.StaticBoxSizer(sb)
       sbPane.SetSizer(sbSizer)
       sbCtrlsPane = sc.SizedPanel(sbPane, -1)
       sbCtrlsPane.SetSizerType('grid', {'cols': 2,})
       st1 = wx.StaticText(sbCtrlsPane, -1, 'static text ctrl')
       tc1 = wx.TextCtrl(sbCtrlsPane, -1, 'something')

self.pane is a sc.SizedPanel and it looks as I like BUT it crashes when I close the dialog which contains all of this. As the crash doesn't give any traceback I am guessing that the SetSizer call is may be stepping on someone.

If I change sbPane to be a wx.Panel instead of a sized one then I don't see any crash but I manually need to handle the sizing of it, which means I loose the HIG spacing.

What is the correct way of using StaticBoxSizer with sized_controls so that everything still respects the HIG's?

The basic problem is that sized_controls assumes a natural parent / child hierarchy controls and automatically adds all controls to the parent's sizer, including wx.StaticBox and its siblings. See this thread, particularly the last message, for a workaround:

http://groups.google.com/group/wxpython-users/browse_thread/thread/b7bb7195f17e04b8/323419e1a9d58e62?lnk=gst&q=SizedControls#323419e1a9d58e62

In 2.9, I believe you can now actually make wx.StaticBox a parent and have its internal controls as children, which, if it works as it should, would make the workaround unnecessary.

Since I sent the email I came up with another work around.

- create a SizedStaticBoxPanel

class SizedStaticBoxPanel(wx.Panel):
   def __init__(self, *args, **kwargs):
       wx.Panel.__init__(self, *args, **kwargs)

       self.sBox = wx.StaticBox(self, -1, "Static box")
       bsizer = wx.StaticBoxSizer(self.sBox, wx.VERTICAL)

       if wx.VERSION < (2,9):
           self.mainPanel = SizedPanel(self, -1)
       else:
           self.mainPanel = SizedPanel(self.sBox, -1)

       bsizer.Add(self.mainPanel, 1, wx.EXPAND)

       self.SetSizer(bsizer)

   def GetContentsPane(self):
       return self.mainPanel

   def GetStaticBox(self):
       return self.sBox

Which I then basically use in the same way as a SizedPanel, e.g. my code shown above then becomes this:

       sbBox = sc.SizedStaticBoxPanel(self.pane, wx.ID_ANY)
       sbBox.SetSizerProps(expand=True, proportion=1)
       sbBox.GetStaticBox().SetLabel("my static box")
       sbPane = sbBox.GetContentsPane()
       sbPane.SetSizerType('grid', {'cols': 2,})

       st1 = wx.StaticText(sbPane, wx.ID_ANY, 'static text ctrl')
       tc1 = wx.TextCtrl(sbPane, wx.ID_ANY, 'something')
       tc1.SetSizerProps(expand=True, proportion=0)

I guess should expand it to support the "orient" parameter in some way.

Maybe one or the other idea or a merge of all this could make it into wxPython 2.9?

A clean up of my work around which supports changing of orientation, only tested (and not extensively) with wxPython 2.9.

class SizedStaticBoxPanel(wx.Panel):
   def __init__(self, *args, **kwargs):
       wx.Panel.__init__(self, *args, **kwargs)

       self._sBox = wx.StaticBox(self, -1, "Static box")
       self._bSizer = wx.StaticBoxSizer(self._sBox, wx.VERTICAL)

       if wx.VERSION < (2,9):
           self.mainPanel = SizedPanel(self, -1)
       else:
           self.mainPanel = SizedPanel(self._sBox, -1)

       self._bSizer.Add(self.mainPanel, 1, wx.EXPAND)

       self.SetSizer(self._bSizer)

   def GetContentsPane(self):
       return self.mainPanel

   def SetStaticBoxLabel(self, label):
       self._sBox.SetLabel(label)

   def SetStaticBoxSizer(self, orient=wx.VERTICAL):
       """Set the orientation of the StaticBoxSizer"""
       self._bSizer.Detach(self._sBox)
       self._bSizer.Detach(self.mainPanel)

       self._bSizer = wx.StaticBoxSizer(self._sBox, orient)
       self._bSizer.Add(self.mainPanel, 1, wx.EXPAND)
       self.SetSizer(self._bSizer)

Or would the preferred approach be Brendan's approach.

I'll have to check into this more closely later, but why does 2.9 even need wx.StaticBoxSizer? Its whole reason for existence is to deal with the fact that wx.StaticBox cannot have children, which is no longer the case. Since the solution would only go into the 2.9 series, I don't want to design the implementation around hacks needed for 2.8.

I do think we will still need a SizedStaticBox, which would basically contain the same code that goes into SizedPanel, but we can't do that with 2.9 as-is because we cannot override wx.StaticBox's virtual methods like we can with wx.Panel. Project Phoenix will remove that limitation though (along with address a host of similar issues).

Thanks,

Kevin

···

On Sep 14, 2011, at 12:28 AM, werner wrote:

On 09/13/2011 07:44 PM, werner wrote:

On 09/13/2011 05:24 PM, Kevin Ollivier wrote:

On Sep 13, 2011, at 6:45 AM, werner wrote:

Werner

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

...

I'll have to check into this more closely later, but why does 2.9 even need wx.StaticBoxSizer? Its whole reason for existence is to deal with the fact that wx.StaticBox cannot have children, which is no longer the case. Since the solution would only go into the 2.9 series, I don't want to design the implementation around hacks needed for 2.8.

I do think we will still need a SizedStaticBox, which would basically contain the same code that goes into SizedPanel, but we can't do that with 2.9 as-is because we cannot override wx.StaticBox's virtual methods like we can with wx.Panel. Project Phoenix will remove that limitation though (along with address a host of similar issues).

Thanks for the clarification, I'll just keep using my solution in the mean time.

Werner

···

On 09/14/2011 06:29 PM, Kevin Ollivier wrote: