--- /dev/null
+
+import wx
+
+
+class TestNotebook(wx.Notebook):
+ def __init__(self, parent, ID=-1):
+ wx.Notebook.__init__(self, parent, ID)
+
+ # page 1
+ # just a panel with a small fixed size
+ p = wx.Panel(self, size=(50,50))
+ self.AddPage(p, "page 1")
+
+ # page 2
+ # a medium sized panel with manually layed out controls
+ p = wx.Panel(self)
+ b = wx.Button(p, -1, "a button", (20,20))
+ b = wx.Button(p, -1, "another button", (80,80))
+ b = wx.Button(p, -1, "and yet another button", (140,140))
+ b.Bind(wx.EVT_BUTTON, self.ShowBestSizes)
+ self.AddPage(p, "page 2")
+
+ # page 3
+ # a larger panel with lots of controls in a sizer.
+ text = "one two buckle my shoe three four shut the door "\
+ "five six pick up sticks seven eight lay them straight "\
+ "nine ten big fat hen"
+ p = wx.Panel(self)
+ fgs = wx.FlexGridSizer(cols=4, vgap=5, hgap=5)
+ for word in text.split():
+ label = wx.StaticText(p, -1, word+":")
+ tc = wx.TextCtrl(p, -1, "", size=(120,-1))
+ fgs.Add(label, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=10)
+ fgs.Add(tc, flag=wx.RIGHT, border=10)
+ box = wx.BoxSizer()
+ box.Add(fgs, 1, wx.EXPAND|wx.ALL, 10)
+ p.SetSizer(box)
+ self.AddPage(p, "page 3")
+
+
+ # show the best size of each page
+ def ShowBestSizes(self, evt):
+ for num in range(self.GetPageCount()):
+ page = self.GetPage(num)
+ print page.GetBestSize()
+
+
+if __name__ == '__main__':
+ app = wx.PySimpleApp()
+ f = wx.Frame(None, -1, "Notebook Test")
+ nb = TestNotebook(f)
+ s = wx.BoxSizer()
+ s.Add(nb) # notebook is added directly to the sizer
+ f.SetSizer(s)
+ s.Fit(f) # sizer calculates layout to set frame size
+ f.Show()
+ app.MainLoop()
+
['wx', 'Button', '-1, "normal"', ''],
['wx', 'Button', '-1, "with a longer, longer label"', ''],
['wx', 'Button', '-1, "default"', 'w.SetDefault()'],
+['wx', 'Button', '-1, "larger font"', 'w.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL))\n\n\n'],
['wx', 'CheckBox', '-1, "checkbox"', ''],
['wx', 'CheckBox', '-1, "checkbox with longer label"', ''],
['wx', 'CheckListBox', '-1, size=(100,-1), choices="one two three four five six seven eight".split()', ''],
['wx.calendar', 'CalendarCtrl', '-1', ''],
['wx.calendar', 'CalendarCtrl', '-1, style=wx.calendar.CAL_SEQUENTIAL_MONTH_SELECTION', ''],
['wx.lib.stattext', 'GenStaticText', '-1, "New font"', 'f = wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD)\nw.SetFont(f)\n'],
-['wx', 'Button', '-1, "larger font"', 'w.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL))\n##w.SetMinSize(wx.DefaultSize)\n'],
]
self.destroyBtn = destroyBtn
bottomPanel = wx.Panel(p, style=wx.SUNKEN_BORDER, name="bottomPanel")
- bottomPanel.SetSizeHints((640,240))
+ bottomPanel.SetMinSize((640,240))
bottomPanel.SetDefaultBackgroundColour("light blue")
self.testPanel = wx.Panel(bottomPanel, name="testPanel")
self.testPanel.SetSizer(None, True)
self.testPanel.Refresh()
- # ensure the panel shrinks again
- self.testPanel.SetSizeHints((20,20))
+ # ensure the panel shrinks again now that it has no sizer
+ self.testPanel.SetMinSize((20,20))
self.bottomSizer.Layout()
- self.testPanel.SetSizeHints(wx.DefaultSize)
+ self.testPanel.SetMinSize(wx.DefaultSize)
# make the create button be default now
self.createBtn.SetDefault()
self._minsize = wx.TextCtrl(self, -1, "", style=wx.TE_READONLY)
self._bestsize = wx.TextCtrl(self, -1, "", style=wx.TE_READONLY)
self._adjbstsize = wx.TextCtrl(self, -1, "", style=wx.TE_READONLY)
+ self._bestfit = wx.TextCtrl(self, -1, "", style=wx.TE_READONLY)
# setup the layout
fgs = wx.FlexGridSizer(2, 2, 5, 5)
0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
fgs.Add(self._adjbstsize, 0, wx.EXPAND)
+ fgs.Add(wx.StaticText(self, -1, "BestFittingSize:"),
+ 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
+ fgs.Add(self._bestfit, 0, wx.EXPAND)
+
sbs = wx.StaticBoxSizer(sb, wx.VERTICAL)
sbs.Add(fgs, 0, wx.EXPAND|wx.ALL, 4)
self._minsize.SetValue( str(win.GetMinSize()) )
self._bestsize.SetValue( str(win.GetBestSize()) )
self._adjbstsize.SetValue( str(win.GetAdjustedBestSize()) )
-
+ self._bestfit.SetValue( str(win.GetBestFittingSize()) )
def Clear(self):
self._size.SetValue("")
self._minsize.SetValue("")
self._bestsize.SetValue("")
self._adjbstsize.SetValue("")
+ self._bestfit.SetValue("")