X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a8d55739f87d26e5cec7ed0566b8f7c9c44a9fa5..db679b8c836e69c111cdc31e62cf92cebe4f938f:/wxPython/misc/widgetLayoutTest.py?ds=inline diff --git a/wxPython/misc/widgetLayoutTest.py b/wxPython/misc/widgetLayoutTest.py index e9f61c6bbb..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): @@ -17,14 +21,21 @@ class LayoutTestFrame(wx.Frame): p = wx.Panel(self) # Create control widgets - self.testHistory = wx.ListBox(p, -1, size=(150, 250)) + self.testHistory = wx.ListBox(p, -1, size=(150, 300)) self.moduleName = wx.TextCtrl(p, -1, "wx") self.className = wx.TextCtrl(p, -1, "") self.parameters = wx.TextCtrl(p, -1, "") + self.postCreate = wx.TextCtrl(p, -1, "", size=(1,75), + style=wx.TE_MULTILINE|wx.TE_DONTWRAP) self.expression = wx.TextCtrl(p, -1, "", style=wx.TE_READONLY) - self.docstring = wx.TextCtrl(p, -1, "", size=(1,125), + self.docstring = wx.TextCtrl(p, -1, "", size=(1,75), style=wx.TE_READONLY|wx.TE_MULTILINE|wx.TE_DONTWRAP) - + + self.expression.SetBackgroundColour( + 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") @@ -38,14 +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.SetSizeHints((20,20)) - #self.testPanel.SetDefaultBackgroundColour("dark red") + 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) @@ -64,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) @@ -72,27 +86,31 @@ 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)) ctlsSizer.Add(wx.StaticText(p, -1, "Module name:"), 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL) - ctlsSizer.Add(self.moduleName, 0, wx.EXPAND) - ctlsSizer.Add(wx.StaticText(p, -1, "Class name:"), - 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL) - ctlsSizer.Add(self.className, 0, wx.EXPAND) + 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|wx.RIGHT, 10) + mcSizer.Add(self.className, 1, 0) + ctlsSizer.Add(mcSizer, 0, wx.EXPAND) + ctlsSizer.Add(wx.StaticText(p, -1, "Parameters:"), 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL) ctlsSizer.Add(self.parameters, 0, wx.EXPAND) - ctlsSizer.Add(wx.StaticText(p, -1, "Expression:"), + ctlsSizer.Add(wx.StaticText(p, -1, "Create Expr:"), 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL) ctlsSizer.Add(self.expression, 0, wx.EXPAND) + ctlsSizer.Add(wx.StaticText(p, -1, "Post create:"), 0, wx.ALIGN_RIGHT) + 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) - topSizer.Add(ctlsSizer, 1) - + 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) @@ -109,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): """ @@ -136,11 +156,11 @@ 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 - while len(item) < 3: + while len(item) < 4: item.append('') # add it to the listbox @@ -166,8 +186,9 @@ class LayoutTestFrame(wx.Frame): moduleName = self.moduleName.GetValue() className = self.className.GetValue() parameters = self.parameters.GetValue() + postCreate = self.postCreate.GetValue() - item = [str(moduleName), str(className), str(parameters)] + item = [str(moduleName), str(className), str(parameters), str(postCreate)] self.history.append(item) self.testHistory.Append(item[0] + '.' + item[1]) @@ -181,6 +202,7 @@ class LayoutTestFrame(wx.Frame): del self.history[idx] self.testHistory.Delete(idx) self.needSaved = True + self.OnClear(None) def OnReplaceHistory(self, evt): @@ -189,20 +211,25 @@ class LayoutTestFrame(wx.Frame): moduleName = self.moduleName.GetValue() className = self.className.GetValue() parameters = self.parameters.GetValue() + postCreate = self.postCreate.GetValue() - item = [str(moduleName), str(className), str(parameters)] + item = [str(moduleName), str(className), str(parameters), str(postCreate)] self.history[idx] = item self.testHistory.SetString(idx, item[0] + '.' + item[1]) self.needSaved = True 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): @@ -210,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): @@ -218,17 +252,19 @@ class LayoutTestFrame(wx.Frame): moduleName = self.moduleName.GetValue() className = self.className.GetValue() parameters = self.parameters.GetValue() - - expr = "%s.%s(self.testPanel, %s)" % (moduleName, className, parameters) + + 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) @@ -240,12 +276,17 @@ class LayoutTestFrame(wx.Frame): def OnCreateWidget(self, evt): if self.testWidget is not None: 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() + 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): @@ -263,7 +304,21 @@ class LayoutTestFrame(wx.Frame): import traceback traceback.print_exc() return - + + # Is there postCreate code? + if postCreate: + ns = {} + ns.update(globals()) + ns.update(locals()) + try: + exec postCreate in ns + except Exception, e: + wx.MessageBox("Got a '%s' Exception!" % e.__class__.__name__, "Error") + import traceback + 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) @@ -274,25 +329,25 @@ class LayoutTestFrame(wx.Frame): # make the destroy button be default now self.destroyBtn.SetDefault() + self.infoPane.Update(w, testPanel) def OnDestroyWidget(self, evt): self.testWidget.Destroy() self.testWidget = None self.testPanel.SetSizer(None, True) + self.testPanel.Refresh() + + # ensure the panel shrinks again now that it has no sizer + self.testPanel.SetMinSize((20,20)) self.bottomSizer.Layout() + self.testPanel.SetMinSize(wx.DefaultSize) # make the create button be default now self.createBtn.SetDefault() -## tp = self.testPanel -## print tp.GetSizer() -## print 'size', tp.GetSize() -## print 'minsize', tp.GetMinSize() -## print 'bestsize', tp.GetBestSize() -## print 'abstsize', tp.GetAdjustedBestSize() - - + self.infoPane.Clear() + def OnClear(self, evt): self.moduleName.SetValue("") @@ -300,8 +355,164 @@ class LayoutTestFrame(wx.Frame): self.parameters.SetValue("") 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=False) frame = LayoutTestFrame()