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