X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/98c092854c6507f6fb007bf2c25c6dd002e0da61..6a52ea5cb81dcd07c286d34b80945534780fe05f:/wxPython/misc/widgetLayoutTest.py?ds=sidebyside diff --git a/wxPython/misc/widgetLayoutTest.py b/wxPython/misc/widgetLayoutTest.py index ebe741b6c2..bcb463e87c 100644 --- a/wxPython/misc/widgetLayoutTest.py +++ b/wxPython/misc/widgetLayoutTest.py @@ -9,6 +9,10 @@ import wx import sys import os +# stuff for debugging +print "wx.VERSION_STRING = ", wx.VERSION_STRING +print "pid:", os.getpid() +##raw_input("Press Enter...") class LayoutTestFrame(wx.Frame): def __init__(self): @@ -31,7 +35,7 @@ class LayoutTestFrame(wx.Frame): wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK)) self.docstring.SetBackgroundColour( wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK)) - + addBtn = wx.Button(p, -1, "Add") remBtn = wx.Button(p, -1, "Remove") @@ -45,13 +49,14 @@ class LayoutTestFrame(wx.Frame): self.destroyBtn = destroyBtn bottomPanel = wx.Panel(p, style=wx.SUNKEN_BORDER, name="bottomPanel") - bottomPanel.SetSizeHints((640,240)) - bottomPanel.SetDefaultBackgroundColour("light blue") + bottomPanel.SetMinSize((640,240)) + bottomPanel.SetOwnBackgroundColour("light blue") self.testPanel = wx.Panel(bottomPanel, name="testPanel") - self.testPanel.SetDefaultBackgroundColour((205, 183, 181)) # mistyrose3 + self.testPanel.SetOwnBackgroundColour((205, 183, 181)) # mistyrose3 self.testWidget = None + self.infoPane = InfoPane(p) # setup event bindings self.Bind(wx.EVT_TEXT, self.OnUpdate, self.moduleName) @@ -70,7 +75,10 @@ class LayoutTestFrame(wx.Frame): self.Bind(wx.EVT_BUTTON, self.OnReplaceHistory, repBtn) self.Bind(wx.EVT_LISTBOX, self.OnHistorySelect, self.testHistory) self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnHistoryActivate, self.testHistory) - + + if 'wxMac' in wx.PlatformInfo or 'wxGTK' in wx.PlatformInfo: + self.testHistory.Bind(wx.EVT_KEY_DOWN, self.OnHistoryKey) + # setup the layout mainSizer = wx.BoxSizer(wx.VERTICAL) @@ -78,18 +86,15 @@ class LayoutTestFrame(wx.Frame): ctlsSizer = wx.FlexGridSizer(2, 2, 5, 5) ctlsSizer.AddGrowableCol(1) btnSizer = wx.BoxSizer(wx.HORIZONTAL) - - topSizer.Add(self.testHistory, 0, wx.RIGHT, 30) - ctlsSizer.Add((1,25)) - ctlsSizer.Add((1,25)) + topSizer.Add(self.testHistory, 0, wx.RIGHT, 30) ctlsSizer.Add(wx.StaticText(p, -1, "Module name:"), 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL) mcSizer = wx.BoxSizer(wx.HORIZONTAL) mcSizer.Add(self.moduleName, 0, 0) mcSizer.Add(wx.StaticText(p, -1, "Class name:"), - 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL |wx.LEFT, 10) + 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL |wx.LEFT|wx.RIGHT, 10) mcSizer.Add(self.className, 1, 0) ctlsSizer.Add(mcSizer, 0, wx.EXPAND) @@ -103,9 +108,9 @@ class LayoutTestFrame(wx.Frame): ctlsSizer.Add(self.postCreate, 0, wx.EXPAND) ctlsSizer.Add(wx.StaticText(p, -1, "DocString:"), 0, wx.ALIGN_RIGHT) ctlsSizer.Add(self.docstring, 0, wx.EXPAND) - ctlsSizer.AddGrowableRow(5) + ctlsSizer.AddGrowableRow(4) topSizer.Add(ctlsSizer, 1, wx.EXPAND) - + btnSizer.Add((5,5)) btnSizer.Add(addBtn, 0, wx.RIGHT, 5) btnSizer.Add(remBtn, 0, wx.RIGHT, 5) @@ -122,19 +127,21 @@ class LayoutTestFrame(wx.Frame): ##mainSizer.Add(wx.StaticLine(p, -1), 0, wx.EXPAND) mainSizer.Add(bottomPanel, 1, wx.EXPAND) + mainSizer.Add(self.infoPane, 0, wx.EXPAND) + self.bottomSizer = sz = wx.BoxSizer(wx.VERTICAL) sz.Add((0,0), 1) sz.Add(self.testPanel, 0, wx.ALIGN_CENTER) sz.Add((0,0), 1) bottomPanel.SetSizer(sz) - + p.SetSizerAndFit(mainSizer) self.Fit() self.PopulateHistory() - + def PopulateHistory(self): """ @@ -149,7 +156,7 @@ class LayoutTestFrame(wx.Frame): self.history = [] self.testHistory.Clear() - + for idx in range(len(self.history)): item = self.history[idx] # check if it is too short @@ -196,7 +203,7 @@ class LayoutTestFrame(wx.Frame): self.testHistory.Delete(idx) self.needSaved = True self.OnClear(None) - + def OnReplaceHistory(self, evt): idx = self.testHistory.GetSelection() @@ -213,13 +220,16 @@ class LayoutTestFrame(wx.Frame): def OnHistorySelect(self, evt): - idx = self.testHistory.GetSelection() + #idx = self.testHistory.GetSelection() + idx = evt.GetInt() if idx != wx.NOT_FOUND: item = self.history[idx] self.moduleName.SetValue(item[0]) self.className.SetValue(item[1]) self.parameters.SetValue(item[2]) self.postCreate.SetValue(item[3]) + if 'wxMac' in wx.PlatformInfo: + self.OnUpdate(None) def OnHistoryActivate(self, evt): @@ -227,7 +237,14 @@ class LayoutTestFrame(wx.Frame): if btn is not None: e = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, btn.GetId()) btn.Command(e) - + + + def OnHistoryKey(self, evt): + key = evt.GetKeyCode() + if key == wx.WXK_RETURN: + self.OnHistoryActivate(None) + else: + evt.Skip() def OnUpdate(self, evt): @@ -235,17 +252,19 @@ class LayoutTestFrame(wx.Frame): moduleName = self.moduleName.GetValue() className = self.className.GetValue() parameters = self.parameters.GetValue() - + expr = "w = %s.%s( testPanel, %s )" % (moduleName, className, parameters) self.expression.SetValue(expr) - docstring = "" + docstring = None try: docstring = eval("%s.%s.__init__.__doc__" % (moduleName, className)) except: pass - self.docstring.SetValue(docstring) - + if docstring is not None: + self.docstring.SetValue(docstring) + else: + self.docstring.SetValue("") def OnEnableDestroy(self, evt): evt.Enable(self.testWidget is not None) @@ -259,13 +278,15 @@ class LayoutTestFrame(wx.Frame): return testPanel = self.testPanel - + # get the details from the form moduleName = self.moduleName.GetValue() className = self.className.GetValue() parameters = self.parameters.GetValue() expr = self.expression.GetValue()[4:] postCreate = self.postCreate.GetValue() + if 'wxMac' in wx.PlatformInfo: + postCreate = postCreate.replace('\r', '\n') # make sure the module is imported already if not sys.modules.has_key(moduleName): @@ -297,7 +318,7 @@ class LayoutTestFrame(wx.Frame): traceback.print_exc() w.Destroy() return - + # Put the widget in a sizer and the sizer in the testPanel sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(w, 0, wx.ALL, 5) @@ -308,19 +329,7 @@ class LayoutTestFrame(wx.Frame): # make the destroy button be default now self.destroyBtn.SetDefault() - if False: - print 'w size', w.GetSize() - print 'w minsize', w.GetMinSize() - print 'w bestsize', w.GetBestSize() - print 'w abstsize', w.GetAdjustedBestSize() - - tp = self.testPanel - #print tp.GetSizer() - print 'tp size', tp.GetSize() - print 'tp minsize', tp.GetMinSize() - print 'tp bestsize', tp.GetBestSize() - print 'tp abstsize', tp.GetAdjustedBestSize() - + self.infoPane.Update(w, testPanel) def OnDestroyWidget(self, evt): @@ -328,15 +337,17 @@ class LayoutTestFrame(wx.Frame): self.testWidget = None 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.infoPane.Clear() + def OnClear(self, evt): self.moduleName.SetValue("") @@ -345,10 +356,165 @@ class LayoutTestFrame(wx.Frame): self.expression.SetValue("") self.docstring.SetValue("") self.postCreate.SetValue("") + + + + + + +class InfoPane(wx.Panel): + """ + This class is used to display details of various properties of the + widget and the testPanel to aid with debugging. + """ + def __init__(self, parent): + wx.Panel.__init__(self, parent) + + # create subwidgets + self.wPane = SizeInfoPane(self, "Widget") + self.tpPane= SizeInfoPane(self, "testPanel") + self.cPane = ColourInfoPanel(self, "Widget colours") + + # Setup the layout + sizer = wx.BoxSizer(wx.HORIZONTAL) + sizer.Add(self.wPane, 0, wx.EXPAND|wx.ALL, 5) + sizer.Add(self.tpPane, 0, wx.EXPAND|wx.ALL, 5) + sizer.Add(self.cPane, 0, wx.EXPAND|wx.ALL, 5) + + self.SetSizer(sizer) + + def Update(self, w, tp): + self.wPane.Update(w) + self.tpPane.Update(tp) + self.cPane.Update(w) + + def Clear(self): + self.wPane.Clear() + self.tpPane.Clear() + self.cPane.Clear() + + + +class SizeInfoPane(wx.Panel): + """ + A component of the InfoPane that shows vaious window size attributes. + """ + def __init__(self, parent, label): + wx.Panel.__init__(self, parent) + + # create subwidgets + sb = wx.StaticBox(self, -1, label) + self._size = wx.TextCtrl(self, -1, "", style=wx.TE_READONLY) + 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) + fgs.AddGrowableCol(1) + + fgs.Add(wx.StaticText(self, -1, "Size:"), + 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL) + fgs.Add(self._size, 0, wx.EXPAND) + + fgs.Add(wx.StaticText(self, -1, "MinSize:"), + 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL) + fgs.Add(self._minsize, 0, wx.EXPAND) + + fgs.Add(wx.StaticText(self, -1, "BestSize:"), + 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL) + fgs.Add(self._bestsize, 0, wx.EXPAND) + + fgs.Add(wx.StaticText(self, -1, "AdjustedBestSize:"), + 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.SetSizer(sbs) + + def Update(self, win): + self._size.SetValue( str(win.GetSize()) ) + 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("") + + + +class ColourInfoPanel(wx.Panel): + """ + A component of the InfoPane that shows fg and bg colour attributes. + """ + def __init__(self, parent, label): + wx.Panel.__init__(self, parent) + + # create subwidgets + sb = wx.StaticBox(self, -1, label) + self._fgtxt = wx.TextCtrl(self, -1, "", style=wx.TE_READONLY) + self._fgclr = wx.Panel(self, style=wx.SIMPLE_BORDER) + self._fgclr.SetMinSize((20,20)) + self._bgtxt = wx.TextCtrl(self, -1, "", style=wx.TE_READONLY) + self._bgclr = wx.Panel(self, style=wx.SIMPLE_BORDER) + self._bgclr.SetMinSize((20,20)) + + # setup the layout + fgs = wx.FlexGridSizer(2, 3, 5, 5) + fgs.AddGrowableCol(1) + + fgs.Add(wx.StaticText(self, -1, "FG colour:"), + 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL) + fgs.Add(self._fgtxt, 0, wx.EXPAND) + fgs.Add(self._fgclr) + + fgs.Add(wx.StaticText(self, -1, "BG colour:"), + 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL) + fgs.Add(self._bgtxt, 0, wx.EXPAND) + fgs.Add(self._bgclr) + + sbs = wx.StaticBoxSizer(sb, wx.VERTICAL) + sbs.Add(fgs, 0, wx.EXPAND|wx.ALL, 4) + + self.SetSizer(sbs) + + + def Update(self, win): + def clr2hex(c, cp): + cp.SetBackgroundColour(c) + cp.Refresh() + return "#%02X%02X%02X" % c.Get() + + self._fgtxt.SetValue( clr2hex(win.GetForegroundColour(), self._fgclr) ) + self._bgtxt.SetValue( clr2hex(win.GetBackgroundColour(), self._bgclr) ) + + + def Clear(self): + self._fgtxt.SetValue("") + self._bgtxt.SetValue("") + self._fgclr.SetBackgroundColour(self.GetBackgroundColour()) + self._bgclr.SetBackgroundColour(self.GetBackgroundColour()) + self._fgclr.Refresh() + self._bgclr.Refresh() + + + -app = wx.PySimpleApp(redirect=True) +app = wx.PySimpleApp(redirect=False) frame = LayoutTestFrame() app.SetTopWindow(frame) frame.Show()