2 from wxPython
.wx
import *
4 #----------------------------------------------------------------------
6 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"
9 class ScrolledPanel(wxScrolledWindow
):
10 def __init__(self
, parent
, log
):
12 wxScrolledWindow
.__init
__(self
, parent
, -1,
13 style
= wxTAB_TRAVERSAL
)
15 box
= wxBoxSizer(wxVERTICAL
)
16 box
.Add(wxStaticText(self
, -1,
17 "This sample shows how to make a scrollable data entry \n"
18 "form by using a wxSizer in a wxScrolledWindow."),
20 box
.Add(wxStaticLine(self
, -1), 0, wxEXPAND|wxALL
, 5)
22 fgs
= wxFlexGridSizer(cols
=2, vgap
=4, hgap
=4)
29 for word
in text
.split():
30 label
= wxStaticText(self
, -1, word
+":")
31 tc
= wxTextCtrl(self
, -1, word
)
32 fgs
.Add(label
, flag
=wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL
)
33 fgs
.Add(tc
, flag
=wxEXPAND
)
36 box
.Add(10, 40) # some more empty space at the bottom
40 # The following is all that is needed to integrate the sizer and the
41 # scrolled window. In this case we will only support vertical scrolling.
42 self
.EnableScrolling(false
, true
)
43 self
.SetScrollRate(0, 20)
44 box
.SetVirtualSizeHints(self
)
46 EVT_CHILD_FOCUS(self
, self
.OnChildFocus
)
49 def OnChildFocus(self
, evt
):
50 # If the child window that gets the focus is not visible,
51 # this handler will try to scroll enough to see it. If you
52 # need to handle horizontal auto-scrolling too then this will
55 child
= evt
.GetWindow()
57 sppu_y
= self
.GetScrollPixelsPerUnit()[1]
58 vs_y
= self
.GetViewStart()[1]
59 cpos
= child
.GetPosition()
62 # is it above the top?
64 new_vs
= cpos
.y
/ sppu_y
65 self
.Scroll(-1, new_vs
)
67 # is it below the bottom ?
68 if cpos
.y
+ csz
.height
> self
.GetClientSize().height
:
69 diff
= (cpos
.y
+ csz
.height
- self
.GetClientSize().height
) / sppu_y
70 self
.Scroll(-1, vs_y
+ diff
+ 1)
73 #----------------------------------------------------------------------
76 def runTest(frame
, nb
, log
):
77 win
= ScrolledPanel(nb
, log
)
80 #----------------------------------------------------------------------
84 overview
= """<html><body>
85 This sample shows how to make a scrollable data entry form by
86 using a wxSizer in a wxScrolledWindow.
92 if __name__
== '__main__':
95 run
.main(['', os
.path
.basename(sys
.argv
[0])])