]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ScrolledPanel.py
Fixed "different linkage" compile error
[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|wxHSCROLL|wxVSCROLL)
14
15
16 box = wxBoxSizer(wxVERTICAL)
17 box.Add(wxStaticText(self, -1,
18 "This sample shows how to make a scrollable data entry \n"
19 "form by using a wxSizer in a wxScrolledWindow."),
20 0, wxCENTER|wxALL, 5)
21 box.Add(wxStaticLine(self, -1), 0, wxEXPAND|wxALL, 5)
22
23 fgs = wxFlexGridSizer(cols=2, vgap=4, hgap=4)
24 fgs.AddGrowableCol(1)
25
26 # Add some spacers
27 fgs.Add(75, 10)
28 fgs.Add(150, 10)
29
30 for word in text.split():
31 label = wxStaticText(self, -1, word+":")
32 tc = wxTextCtrl(self, -1, word)
33 fgs.Add(label, flag=wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL)
34 fgs.Add(tc, flag=wxEXPAND)
35
36 box.Add(fgs, 1)
37 box.Add(10, 40) # some more empty space at the bottom
38 self.SetSizer(box)
39
40
41 # The following is all that is needed to integrate the sizer and the
42 # scrolled window. In this case we will only support vertical scrolling.
43 self.EnableScrolling(false, true)
44 self.SetScrollRate(0, 20)
45 box.SetVirtualSizeHints(self)
46
47 EVT_CHILD_FOCUS(self, self.OnChildFocus)
48
49
50 def OnChildFocus(self, evt):
51 # If the child window that gets the focus is not visible,
52 # this handler will try to scroll enough to see it. If you
53 # need to handle horizontal auto-scrolling too then this will
54 # need adapted.
55 evt.Skip()
56 child = evt.GetWindow()
57
58 sppu_y = self.GetScrollPixelsPerUnit()[1]
59 vs_y = self.GetViewStart()[1]
60 cpos = child.GetPosition()
61 csz = child.GetSize()
62
63 # is it above the top?
64 if cpos.y < 0:
65 new_vs = cpos.y / sppu_y
66 self.Scroll(-1, new_vs)
67
68 # is it below the bottom ?
69 if cpos.y + csz.height > self.GetClientSize().height:
70 diff = (cpos.y + csz.height - self.GetClientSize().height) / sppu_y
71 self.Scroll(-1, vs_y + diff + 1)
72
73
74 #----------------------------------------------------------------------
75
76 ## class ScrollToHandler(wxEvtHandler):
77 ## """This class helps to scroll the panel
78
79 #----------------------------------------------------------------------
80
81 def runTest(frame, nb, log):
82 win = ScrolledPanel(nb, log)
83 return win
84
85 #----------------------------------------------------------------------
86
87
88
89 overview = """<html><body>
90 This sample shows how to make a scrollable data entry form by
91 using a wxSizer in a wxScrolledWindow.
92 </body></html>
93 """
94
95
96
97 if __name__ == '__main__':
98 import sys,os
99 import run
100 run.main(['', os.path.basename(sys.argv[0])])
101