But then I wanted to change the font size, so I added the self.SetFont() call, which also works as expected; all child items are now using this font.
BUT, the window size from the col1sizer.Fit() resizes the size of the content with the default font. That is to say the window size does not change to fit the new font size -- it's exactly the size it was when the SetFont() call wasn't there. So if I use a smaller font size, the window is too big, and if I use a larger font size, the window is too small.
I added the InvalidateBestSize() in an effort to fix this, but it had no effect.
Without SetFont(): With SetFont(): Full code below:
Code: Select all
#!/usr/bin/env python
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self._defaultBorder = wx.EXPAND | wx.TOP | wx.BOTTOM | wx.LEFT | wx.RIGHT, 7
font = wx.Font(5, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
self.SetFont(font)
col1Sizer = wx.BoxSizer(wx.VERTICAL)
self.basicConfig(col1Sizer)
#self.highProtectConfig()
#self.SetAutoLayout(True)
self.SetSizer(col1Sizer)
self.InvalidateBestSize()
col1Sizer.Fit(self)
def basicConfig(self, sizer):
panel = wx.Panel(self)
sb = wx.StaticBox(panel, label='Basic Configuration')
sbs = wx.StaticBoxSizer(sb, wx.VERTICAL)
fgs = wx.FlexGridSizer(11, gap=(3,3))
sbs.Add(fgs, 0, wx.EXPAND | wx.ALL, border=5)
panel.SetSizer(sbs)
sizer.Add(panel, 1, *self._defaultBorder)
rflags = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT
lflags = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
def gen(fn, unit1, unit2 = None, unit3 = 'S', spacing=10):
unit2 = unit2 or unit1
items = (
(wx.StaticText(sb, label = fn.upper()), 0, rflags),
(wx.TextCtrl(sb, name = fn), 0, lflags),
(wx.StaticText(sb, label = unit1), 0, rflags),
(spacing, 1),
(wx.StaticText(sb, label = 'Release'), 0, rflags),
(wx.TextCtrl(sb, name = fn + '_rel'), 0, lflags),
(wx.StaticText(sb, label = unit2), 0, lflags),
(spacing, 1),
(wx.StaticText(sb, label = 'Delay'), 0, rflags),
(wx.TextCtrl(sb, name = fn + '_delay'), 0, lflags),
(wx.StaticText(sb, label = unit3), 0, lflags),
)
return items
fgs.AddMany(gen('covp', 'mV'))
fgs.AddMany(gen('cuvp', 'mV'))
fgs.AddMany(gen('povp', 'mV'))
fgs.AddMany(gen('puvp', 'mV'))
fgs.AddMany(gen('chgot', 'C'))
fgs.AddMany(gen('chgut', 'C'))
fgs.AddMany(gen('dsgot', 'C'))
fgs.AddMany(gen('dsgut', 'C'))
fgs.AddMany(gen('chgoc', 'mA', 'S'))
fgs.AddMany(gen('dsgoc', 'mA', 'S'))
sbs.Fit(panel)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'A Static box', )
frame.Show()
return True
if __name__ == "__main__":
app = MyApp()
app.MainLoop()