]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/misc/widgetLayoutTest.py
removed a debugging print
[wxWidgets.git] / wxPython / misc / widgetLayoutTest.py
index e9f61c6bbb8980fae720ec66311f013540044cbd..c9d30ebc0fb8416f829af09c9d841345fdb04208 100644 (file)
@@ -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")
@@ -42,10 +53,10 @@ class LayoutTestFrame(wx.Frame):
         bottomPanel.SetDefaultBackgroundColour("light blue")
 
         self.testPanel = wx.Panel(bottomPanel, name="testPanel")
-        self.testPanel.SetSizeHints((20,20))
-        #self.testPanel.SetDefaultBackgroundColour("dark red")
+        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)
@@ -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,8 +252,8 @@ 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 = ""
@@ -228,7 +262,7 @@ class LayoutTestFrame(wx.Frame):
         except:
             pass
         self.docstring.SetValue(docstring)
-        
+
 
     def OnEnableDestroy(self, evt):
         evt.Enable(self.testWidget is not None)
@@ -240,12 +274,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 +302,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 +327,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
+        self.testPanel.SetSizeHints((20,20))
         self.bottomSizer.Layout()
+        self.testPanel.SetSizeHints(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 +353,161 @@ 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)
 
+        # 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) )
+
+##         f = win.GetFont()
+##         print f.GetNativeFontInfo().ToString()
+        
+
+    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()