]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ScrolledPanel.py
34aa549a55605ed67e70634813fd9b07ddd05959
[wxWidgets.git] / wxPython / demo / ScrolledPanel.py
1
2 import wx
3 import wx.lib.scrolledpanel as scrolled
4
5 #----------------------------------------------------------------------
6
7 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"
8
9
10 class TestPanel(scrolled.ScrolledPanel):
11 def __init__(self, parent, log):
12 self.log = log
13 scrolled.ScrolledPanel.__init__(self, parent, -1)
14
15 vbox = wx.BoxSizer(wx.VERTICAL)
16 desc = wx.StaticText(self, -1,
17 "ScrolledPanel extends wx.ScrolledWindow, adding all "
18 "the necessary bits to set up scroll handling for you.\n\n"
19 "Here are three fixed size examples of its use. The "
20 "demo panel for this sample is also using it -- the \nwxStaticLine "
21 "below is intentionally made too long so a scrollbar will be "
22 "activated."
23 )
24 desc.SetForegroundColour("Blue")
25 vbox.Add(desc, 0, wx.ALIGN_LEFT|wx.ALL, 5)
26 vbox.Add(wx.StaticLine(self, -1, size=(1024,-1)), 0, wx.ALL, 5)
27 vbox.Add((20,20))
28
29 words = text.split()
30
31 panel1 = scrolled.ScrolledPanel(self, -1, size=(140, 300),
32 style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="panel1" )
33 fgs1 = wx.FlexGridSizer(cols=2, vgap=4, hgap=4)
34
35 for word in words:
36 label = wx.StaticText(panel1, -1, word+":")
37 if word == "three":
38 tc = wx.TextCtrl(panel1, -1, word, size=(150,-1))
39 else:
40 tc = wx.TextCtrl(panel1, -1, word, size=(50,-1))
41 fgs1.Add(label, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=10)
42 fgs1.Add(tc, flag=wx.RIGHT, border=10)
43
44 panel1.SetSizer( fgs1 )
45 panel1.SetAutoLayout(1)
46 panel1.SetupScrolling()
47
48 panel2 = scrolled.ScrolledPanel(self, -1, size=(350, 50),
49 style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="panel2")
50 panel3 = scrolled.ScrolledPanel(self, -1, size=(200,100),
51 style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="panel3")
52
53 fgs2 = wx.FlexGridSizer(cols=25, vgap=4, hgap=4)
54 fgs3 = wx.FlexGridSizer(cols=5, vgap=4, hgap=4)
55
56 for i in range(len(words)):
57 word = words[i]
58 if i % 5 != 4:
59 label2 = wx.StaticText(panel2, -1, word)
60 fgs2.Add(label2, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
61 label3 = wx.StaticText(panel3, -1, word)
62 fgs3.Add(label3, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
63 else:
64 tc2 = wx.TextCtrl(panel2, -1, word, size=(50,-1))
65 fgs2.Add(tc2, flag=wx.LEFT, border=5)
66 tc3 = wx.TextCtrl(panel3, -1, word )
67 fgs3.Add(tc3, flag=wx.LEFT, border=5)
68
69 panel2.SetSizer( fgs2 )
70 panel2.SetAutoLayout(1)
71 panel2.SetupScrolling(scroll_y = False)
72
73 panel3.SetSizer( fgs3 )
74 panel3.SetAutoLayout(1)
75 panel3.SetupScrolling()
76
77 hbox = wx.BoxSizer(wx.HORIZONTAL)
78 hbox.Add((20,20))
79 hbox.Add(panel1, 0)
80 hbox.Add((40, 10))
81
82 vbox2 = wx.BoxSizer(wx.VERTICAL)
83 vbox2.Add(panel2, 0)
84 vbox2.Add((20, 50))
85
86 vbox2.Add(panel3, 0)
87 vbox2.Add((20, 10))
88 hbox.Add(vbox2)
89
90 vbox.Add(hbox, 0)
91 self.SetSizer(vbox)
92 self.SetAutoLayout(1)
93 self.SetupScrolling()
94
95
96 #----------------------------------------------------------------------
97
98
99 def runTest(frame, nb, log):
100 win = TestPanel(nb, log)
101 return win
102
103 #----------------------------------------------------------------------
104
105
106
107 overview = """<html><body>
108 ScrolledPanel fills a "hole" in the implementation of wx.ScrolledWindow,
109 providing automatic scrollbar and scrolling behavior and the tab traversal
110 mangement that wx.ScrolledWindow lacks.
111 </body></html>
112 """
113
114
115 if __name__ == '__main__':
116 import sys,os
117 import run
118 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])