]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ScrolledPanel.py
Added scripts to make Tex2RTF distribution on Unix
[wxWidgets.git] / wxPython / demo / ScrolledPanel.py
1
2 from wxPython.wx import *
3
4 #----------------------------------------------------------------------
5
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"
7
8
9 class ScrolledPanel(wxScrolledWindow):
10 def __init__(self, parent, log):
11 self.log = log
12 wxScrolledWindow.__init__(self, parent, -1,
13 style = wxTAB_TRAVERSAL)
14
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."),
19 0, wxCENTER|wxALL, 5)
20 box.Add(wxStaticLine(self, -1), 0, wxEXPAND|wxALL, 5)
21
22 fgs = wxFlexGridSizer(cols=2, vgap=4, hgap=4)
23 fgs.AddGrowableCol(1)
24
25 # Add some spacers
26 fgs.Add(75, 10)
27 fgs.Add(150, 10)
28
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)
34
35 box.Add(fgs, 1)
36 box.Add(10, 40) # some more empty space at the bottom
37 self.SetSizer(box)
38
39
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)
45
46 EVT_CHILD_FOCUS(self, self.OnChildFocus)
47
48
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
53 # need adapted.
54 evt.Skip()
55 child = evt.GetWindow()
56
57 sppu_y = self.GetScrollPixelsPerUnit()[1]
58 vs_y = self.GetViewStart()[1]
59 cpos = child.GetPosition()
60 csz = child.GetSize()
61
62 # is it above the top?
63 if cpos.y < 0:
64 new_vs = cpos.y / sppu_y
65 self.Scroll(-1, new_vs)
66
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)
71
72
73 #----------------------------------------------------------------------
74
75
76 def runTest(frame, nb, log):
77 win = ScrolledPanel(nb, log)
78 return win
79
80 #----------------------------------------------------------------------
81
82
83
84 overview = """<html><body>
85 This sample shows how to make a scrollable data entry form by
86 using a wxSizer in a wxScrolledWindow.
87 </body></html>
88 """
89
90
91
92 if __name__ == '__main__':
93 import sys,os
94 import run
95 run.main(['', os.path.basename(sys.argv[0])])
96