]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/misc/widgetLayoutTest.py
use ResetClipping() instead of simply setting m_clipping to false; added call to...
[wxWidgets.git] / wxPython / misc / widgetLayoutTest.py
index 02a8a33695b7237c9114ab76606dd01d65963418..22706ac42fa1cc1468bb02598ec27d3f5cc4ed33 100644 (file)
@@ -17,14 +17,21 @@ class LayoutTestFrame(wx.Frame):
         p = wx.Panel(self)
 
         # Create control widgets
         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.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.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)
                                       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")
 
         addBtn = wx.Button(p, -1, "Add")
         remBtn = wx.Button(p, -1, "Remove")
@@ -45,6 +52,7 @@ class LayoutTestFrame(wx.Frame):
         self.testPanel.SetDefaultBackgroundColour((205, 183, 181)) # mistyrose3
         self.testWidget = None
 
         self.testPanel.SetDefaultBackgroundColour((205, 183, 181)) # mistyrose3
         self.testWidget = None
 
+        self.infoPane = InfoPane(p)
 
         # setup event bindings
         self.Bind(wx.EVT_TEXT, self.OnUpdate, self.moduleName)
 
         # setup event bindings
         self.Bind(wx.EVT_TEXT, self.OnUpdate, self.moduleName)
@@ -63,7 +71,7 @@ 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)
         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)
-        
+
 
         # setup the layout
         mainSizer = wx.BoxSizer(wx.VERTICAL)
 
         # setup the layout
         mainSizer = wx.BoxSizer(wx.VERTICAL)
@@ -71,27 +79,31 @@ class LayoutTestFrame(wx.Frame):
         ctlsSizer = wx.FlexGridSizer(2, 2, 5, 5)
         ctlsSizer.AddGrowableCol(1)
         btnSizer =  wx.BoxSizer(wx.HORIZONTAL)
         ctlsSizer = wx.FlexGridSizer(2, 2, 5, 5)
         ctlsSizer.AddGrowableCol(1)
         btnSizer =  wx.BoxSizer(wx.HORIZONTAL)
-        
+
         topSizer.Add(self.testHistory, 0, wx.RIGHT, 30)
 
         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(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, 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, "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)
                       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)
         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)
         btnSizer.Add((5,5))
         btnSizer.Add(addBtn, 0, wx.RIGHT, 5)
         btnSizer.Add(remBtn, 0, wx.RIGHT, 5)
@@ -108,19 +120,21 @@ class LayoutTestFrame(wx.Frame):
         ##mainSizer.Add(wx.StaticLine(p, -1), 0, wx.EXPAND)
         mainSizer.Add(bottomPanel, 1, wx.EXPAND)
 
         ##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)
         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()
 
 
         p.SetSizerAndFit(mainSizer)
         self.Fit()
 
         self.PopulateHistory()
 
 
-       
+
 
     def PopulateHistory(self):
         """
 
     def PopulateHistory(self):
         """
@@ -135,11 +149,11 @@ class LayoutTestFrame(wx.Frame):
             self.history = []
 
         self.testHistory.Clear()
             self.history = []
 
         self.testHistory.Clear()
-        
+
         for idx in range(len(self.history)):
             item = self.history[idx]
             # check if it is too short
         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
                 item.append('')
 
             # add it to the listbox
@@ -165,8 +179,9 @@ class LayoutTestFrame(wx.Frame):
         moduleName = self.moduleName.GetValue()
         className  = self.className.GetValue()
         parameters = self.parameters.GetValue()
         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])
 
         self.history.append(item)
         self.testHistory.Append(item[0] + '.' + item[1])
 
@@ -180,6 +195,7 @@ class LayoutTestFrame(wx.Frame):
             del self.history[idx]
             self.testHistory.Delete(idx)
         self.needSaved = True
             del self.history[idx]
             self.testHistory.Delete(idx)
         self.needSaved = True
+        self.OnClear(None)
 
 
     def OnReplaceHistory(self, evt):
 
 
     def OnReplaceHistory(self, evt):
@@ -188,8 +204,9 @@ class LayoutTestFrame(wx.Frame):
             moduleName = self.moduleName.GetValue()
             className  = self.className.GetValue()
             parameters = self.parameters.GetValue()
             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
             self.history[idx] = item
             self.testHistory.SetString(idx, item[0] + '.' + item[1])
         self.needSaved = True
@@ -202,6 +219,7 @@ class LayoutTestFrame(wx.Frame):
             self.moduleName.SetValue(item[0])
             self.className.SetValue(item[1])
             self.parameters.SetValue(item[2])
             self.moduleName.SetValue(item[0])
             self.className.SetValue(item[1])
             self.parameters.SetValue(item[2])
+            self.postCreate.SetValue(item[3])
 
 
     def OnHistoryActivate(self, evt):
 
 
     def OnHistoryActivate(self, evt):
@@ -209,7 +227,7 @@ class LayoutTestFrame(wx.Frame):
         if btn is not None:
             e = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, btn.GetId())
             btn.Command(e)
         if btn is not None:
             e = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, btn.GetId())
             btn.Command(e)
-            
+
 
 
     def OnUpdate(self, evt):
 
 
     def OnUpdate(self, evt):
@@ -217,8 +235,8 @@ class LayoutTestFrame(wx.Frame):
         moduleName = self.moduleName.GetValue()
         className  = self.className.GetValue()
         parameters = self.parameters.GetValue()
         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 = ""
         self.expression.SetValue(expr)
 
         docstring = ""
@@ -227,7 +245,7 @@ class LayoutTestFrame(wx.Frame):
         except:
             pass
         self.docstring.SetValue(docstring)
         except:
             pass
         self.docstring.SetValue(docstring)
-        
+
 
     def OnEnableDestroy(self, evt):
         evt.Enable(self.testWidget is not None)
 
     def OnEnableDestroy(self, evt):
         evt.Enable(self.testWidget is not None)
@@ -239,12 +257,15 @@ class LayoutTestFrame(wx.Frame):
     def OnCreateWidget(self, evt):
         if self.testWidget is not None:
             return
     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()
         # 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()
 
         # make sure the module is imported already
         if not sys.modules.has_key(moduleName):
 
         # make sure the module is imported already
         if not sys.modules.has_key(moduleName):
@@ -263,6 +284,20 @@ class LayoutTestFrame(wx.Frame):
             traceback.print_exc()
             return
 
             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)
         # Put the widget in a sizer and the sizer in the testPanel
         sizer = wx.BoxSizer(wx.VERTICAL)
         sizer.Add(w, 0, wx.ALL, 5)
@@ -273,35 +308,40 @@ class LayoutTestFrame(wx.Frame):
         # make the destroy button be default now
         self.destroyBtn.SetDefault()
 
         # make the destroy button be default now
         self.destroyBtn.SetDefault()
 
-
-        if True:
+        self.infoPane.Update(w, testPanel)
+        
+        if False:
             print 'w size', w.GetSize()
             print 'w minsize', w.GetMinSize()
             print 'w bestsize', w.GetBestSize()
             print 'w abstsize', w.GetAdjustedBestSize()
             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()
             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()
-            
-        
+
+
 
     def OnDestroyWidget(self, evt):
         self.testWidget.Destroy()
         self.testWidget = None
         self.testPanel.SetSizer(None, True)
 
     def OnDestroyWidget(self, evt):
         self.testWidget.Destroy()
         self.testWidget = None
         self.testPanel.SetSizer(None, True)
+        self.testPanel.Refresh()
 
         # ensure the panel shrinks again
 
         # ensure the panel shrinks again
-        self.testPanel.SetSizeHints((20,20)) 
+        self.testPanel.SetSizeHints((20,20))
         self.bottomSizer.Layout()
         self.testPanel.SetSizeHints(wx.DefaultSize)
         self.bottomSizer.Layout()
         self.testPanel.SetSizeHints(wx.DefaultSize)
-        
+
         # make the create button be default now
         self.createBtn.SetDefault()
 
         # make the create button be default now
         self.createBtn.SetDefault()
 
+        self.infoPane.Clear()
+        
+
 
     def OnClear(self, evt):
         self.moduleName.SetValue("")
 
     def OnClear(self, evt):
         self.moduleName.SetValue("")
@@ -309,10 +349,160 @@ class LayoutTestFrame(wx.Frame):
         self.parameters.SetValue("")
         self.expression.SetValue("")
         self.docstring.SetValue("")
         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)
+
+        # 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)
+
+        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()) )
+        
+
+    def Clear(self):
+        self._size.SetValue("")
+        self._minsize.SetValue("")
+        self._bestsize.SetValue("")
+        self._adjbstsize.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.SetSizeHints((20,20))
+        self._bgtxt = wx.TextCtrl(self, -1, "", style=wx.TE_READONLY)
+        self._bgclr = wx.Panel(self, style=wx.SIMPLE_BORDER)
+        self._bgclr.SetSizeHints((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)
+        
+
+app = wx.PySimpleApp(redirect=True)
 frame = LayoutTestFrame()
 app.SetTopWindow(frame)
 frame.Show()
 frame = LayoutTestFrame()
 app.SetTopWindow(frame)
 frame.Show()