]> git.saurik.com Git - wxWidgets.git/commitdiff
Added demo of using a sizer in a wxScrolledWindow
authorRobin Dunn <robin@alldunn.com>
Wed, 26 Jun 2002 20:08:30 +0000 (20:08 +0000)
committerRobin Dunn <robin@alldunn.com>
Wed, 26 Jun 2002 20:08:30 +0000 (20:08 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15965 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

wxPython/CHANGES.txt
wxPython/demo/Main.py
wxPython/demo/ScrolledPanel.py [new file with mode: 0644]
wxPython/demo/run.py
wxPython/demo/wxHtmlWindow.py
wxPython/demo/wxScrolledWindow.py

index 235dbaef83f637f9aa2fbd308246d196540ba6d4..022ca009772903ae55dbc3083b01b83f9babd757 100644 (file)
@@ -124,13 +124,16 @@ DoGetBestSize and AcceptsFocus.
 Added wxArtProvider.
 
 Added wxCallAfter which is a helper function that registers a function
-(or any callable Python object) to be called one time the next time
-there are no pending events.  This is useful for when you need to do
+(or any callable Python object) to be called once the next time there
+are no pending events.  This is useful for when you need to do
 something but it can't be done during the current event handler.  The
 implementation is very simple, see wxPython/wx.py.
 
 Fixed a boatload of reference leaks.
 
+Added a demo of using a sizer in a wxScrolledWindow, in effect
+creating a ScrolledPanel.
+
 
 
 
index 82b0a9b9f5dcebbc0fd7d2eaa996e8f951a5502b..e9beb449ad2e049d77b40e5854a93daa266223c3 100644 (file)
@@ -31,6 +31,7 @@ _treeList = [
         'wxGenericDirCtrl',
         'wxImageFromStream',
         'wxArtProvider',
+        'ScrolledPanel',
         ]),
 
     # managed windows == things with a caption you can close
@@ -127,6 +128,7 @@ _treeList = [
         'LayoutAnchors',
         'Layoutf',
         'RowColSizer',
+        'ScrolledPanel',
         'Sizers',
         'wxLayoutConstraints',
         'XML_Resource',
@@ -356,10 +358,13 @@ class wxPythonDemo(wxFrame):
         # But instead of the above we want to show how to use our own wxLog class
         wxLog_SetActiveTarget(MyLog(self.log))
 
-
+        # for serious debugging
+        #wxLog_SetActiveTarget(wxLogStderr())
+        #wxLog_SetTraceMask(wxTraceMessages)
 
         self.Show(true)
 
+
         # add the windows to the splitter and split it.
         splitter2.SplitHorizontally(self.nb, self.log)
         splitter.SplitVertically(self.tree, splitter2)
diff --git a/wxPython/demo/ScrolledPanel.py b/wxPython/demo/ScrolledPanel.py
new file mode 100644 (file)
index 0000000..e4a0bb5
--- /dev/null
@@ -0,0 +1,101 @@
+
+from wxPython.wx import *
+
+#----------------------------------------------------------------------
+
+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"
+
+
+class ScrolledPanel(wxScrolledWindow):
+    def __init__(self, parent, log):
+        self.log = log
+        wxScrolledWindow.__init__(self, parent, -1,
+                                  style = wxTAB_TRAVERSAL|wxHSCROLL|wxVSCROLL)
+
+
+        box = wxBoxSizer(wxVERTICAL)
+        box.Add(wxStaticText(self, -1,
+                             "This sample shows how to make a scrollable data entry \n"
+                             "form by using a wxSizer in a wxScrolledWindow."),
+                0, wxCENTER|wxALL, 5)
+        box.Add(wxStaticLine(self, -1), 0, wxEXPAND|wxALL, 5)
+
+        fgs = wxFlexGridSizer(cols=2, vgap=4, hgap=4)
+        fgs.AddGrowableCol(1)
+
+        # Add some spacers
+        fgs.Add(75, 10)
+        fgs.Add(150, 10)
+
+        for word in text.split():
+            label = wxStaticText(self, -1, word+":")
+            tc = wxTextCtrl(self, -1, word)
+            fgs.Add(label, flag=wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL)
+            fgs.Add(tc, flag=wxEXPAND)
+
+        box.Add(fgs, 1)
+        box.Add(10, 40)  # some more empty space at the bottom
+        self.SetSizer(box)
+
+
+        # The following is all that is needed to integrate the sizer and the
+        # scrolled window.  In this case we will only support vertical scrolling.
+        self.EnableScrolling(false, true)
+        self.SetScrollRate(0, 20)
+        box.SetVirtualSizeHints(self)
+
+        EVT_CHILD_FOCUS(self, self.OnChildFocus)
+
+
+    def OnChildFocus(self, evt):
+        # If the child window that gets the focus is not visible,
+        # this handler will try to scroll enough to see it.  If you
+        # need to handle horizontal auto-scrolling too then this will
+        # need adapted.
+        evt.Skip()
+        child = evt.GetWindow()
+
+        sppu_y = self.GetScrollPixelsPerUnit()[1]
+        vs_y   = self.GetViewStart()[1]
+        cpos = child.GetPosition()
+        csz  = child.GetSize()
+
+        # is it above the top?
+        if cpos.y < 0:
+            new_vs = cpos.y / sppu_y
+            self.Scroll(-1, new_vs)
+
+        # is it below the bottom ?
+        if cpos.y + csz.height > self.GetClientSize().height:
+            diff = (cpos.y + csz.height - self.GetClientSize().height) / sppu_y
+            self.Scroll(-1, vs_y + diff + 1)
+
+
+#----------------------------------------------------------------------
+
+## class ScrollToHandler(wxEvtHandler):
+##     """This class helps to scroll the panel
+
+#----------------------------------------------------------------------
+
+def runTest(frame, nb, log):
+    win = ScrolledPanel(nb, log)
+    return win
+
+#----------------------------------------------------------------------
+
+
+
+overview = """<html><body>
+This sample shows how to make a scrollable data entry form by
+using a wxSizer in a wxScrolledWindow.
+</body></html>
+"""
+
+
+
+if __name__ == '__main__':
+    import sys,os
+    import run
+    run.main(['', os.path.basename(sys.argv[0])])
+
index d2eac71dae9a031adfe9a80e5be2b2aed6abc1e7..f82ecbbea552cbc9af428afd6a7dca97994f8012 100755 (executable)
@@ -72,6 +72,8 @@ class RunDemoApp(wxApp):
 
         self.SetTopWindow(frame)
         self.frame = frame
+        #wxLog_SetActiveTarget(wxLogStderr())
+        #wxLog_SetTraceMask(wxTraceMessages)
         return true
 
 
index 2c865f7416fda5f50b019239f59150153732755a..5692a76b0b5caf916ffe79b80a14002a73de8866 100644 (file)
@@ -158,6 +158,7 @@ class TestHtmlPanel(wxPanel):
 
 def runTest(frame, nb, log):
     win = TestHtmlPanel(nb, frame, log)
+    print wxWindow_FindFocus()
     return win
 
 
index 31a388a11e34877d25e18f4443b297251930127f..3c815ada18a2d831d0a16aa800e84310a0581249 100644 (file)
@@ -211,13 +211,14 @@ def runTest(frame, nb, log):
 
 
 
+overview = """\
+"""
 
 
 
 
+if __name__ == '__main__':
+    import sys,os
+    import run
+    run.main(['', os.path.basename(sys.argv[0])])
 
-
-
-
-overview = """\
-"""