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