Ah. I was mainly just looking at the layout of the widgets compared to each other, and not the overall picture.
Okay, I’ve taken a closer look and here’s what I’ve found.
-
It’s the row_sizer that is pushing out the width.
-
Some items in that sizer are added with proportion=1, so the unexpected extra width is likely because the proportional widths will be based on the largest item managed by the sizer.
-
I notice you use wx.ALL or other side flags (TOP, BOTTOM, LEFT, RIGHT) without giving a margin value, making the use of those flags meaningless. Not part of the problem but maybe it indicates some misunderstanding about how they work.
-
The row_sizer is added to the main_sizer without wx.EXPAND, so it will not be automatically expanded to the width of the other items in the main_sizer. I changed the wx.ALL on that line to wx.EXPAND.
-
The stretch spacer inside the btn_sizer is superfluous, because the stretch spacer next to it in the parent sizer will take care of pushing the buttons to the right. Also, the btn_sizer should be added to the row_sizer with proportion=0 because it only needs to be as wide as the buttons, not steal space from the row_sizer, or cause it to be wider than needed.
Here are the changes I made to your sample code:
--- SystemConfigDlg.py.orig 2020-05-18 10:16:16.000000000 -0700
+++ SystemConfigDlg.py 2020-05-18 10:40:52.000000000 -0700
@@ -2,11 +2,11 @@
import wx.grid
-class SystemConfigDlg(wx.Dialog):
+class SystemConfigDlg(wx.Panel):
def __init__(self, parent):
- super().__init__(parent, wx.ID_ANY, 'System Defaults', size=(640,320))
-
+ #super().__init__(parent, wx.ID_ANY, 'System Defaults') #, size=(640,320))
+ super().__init__(parent)
self.__InitUI()
@@ -31,7 +31,7 @@
# add the reviewer controls
row_sizer = wx.BoxSizer()
self.__add_reviewer_controls(panel, row_sizer)
- main_sizer.Add(row_sizer, 0, wx.ALL)
+ main_sizer.Add(row_sizer, 0, wx.EXPAND)
panel.SetSizer(main_sizer)
@@ -39,6 +39,7 @@
self.SetSizer(top_sizer)
self.Fit()
+
def __add_adjustment_grid(self, panel, row_sizer):
col_sizer = wx.BoxSizer(wx.VERTICAL)
lbl = wx.StaticText(panel, label='Adjustments')
@@ -161,10 +162,27 @@
# add the apply/cancel buttons
btn_sizer = wx.BoxSizer()
- btn_sizer.AddStretchSpacer(1)
+ ##btn_sizer.AddStretchSpacer(1)
self.btn_sysconf_cancel = wx.Button(panel, wx.ID_CANCEL, label='Cancel')
btn_sizer.Add(self.btn_sysconf_cancel, 1, wx.ALIGN_BOTTOM)
self.btn_sysconf_apply = wx.Button(panel, wx.ID_APPLY, label='Apply')
btn_sizer.Add(self.btn_sysconf_apply, 1, wx.ALIGN_BOTTOM)
- row_sizer.Add(btn_sizer, 1, wx.ALL | wx.BOTTOM | wx.EXPAND)
+ row_sizer.Add(btn_sizer, 0, wx.EXPAND)
+
+
+
+app = wx.App()
+frame = wx.Frame(None, title="layout tester")
+panel = SystemConfigDlg(frame)
+frame.Sizer = wx.BoxSizer()
+frame.Sizer.Add(panel, 1, wx.EXPAND)
+frame.Fit()
+frame.Show()
+import wx.lib.inspection
+wx.lib.inspection.InspectionTool().Show()
+
+#dlg = SystemConfigDlg(None)
+#dlg.ShowModal()
+
+app.MainLoop()