]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | import wx | |
3 | ||
4 | #--------------------------------------------------------------------------- | |
5 | ||
6 | class TestChoice(wx.Panel): | |
7 | def __init__(self, parent, log): | |
8 | self.log = log | |
9 | wx.Panel.__init__(self, parent, -1) | |
10 | ||
11 | sampleList = ['zero', 'one', 'two', 'three', 'four', 'five', | |
12 | 'six', 'seven', 'eight'] | |
13 | ||
14 | wx.StaticText(self, -1, "This example uses the wxChoice control.", (15, 10)) | |
15 | wx.StaticText(self, -1, "Select one:", (15, 50), (75, 20)) | |
16 | self.ch = wx.Choice(self, -1, (80, 50), choices = sampleList) | |
17 | self.Bind(wx.EVT_CHOICE, self.EvtChoice, self.ch) | |
18 | ||
19 | ||
20 | def EvtChoice(self, event): | |
21 | self.log.WriteText('EvtChoice: %s\n' % event.GetString()) | |
22 | self.ch.Append("A new item") | |
23 | ||
24 | if event.GetString() == 'one': | |
25 | self.log.WriteText('Well done!\n') | |
26 | ||
27 | ||
28 | #--------------------------------------------------------------------------- | |
29 | ||
30 | def runTest(frame, nb, log): | |
31 | win = TestChoice(nb, log) | |
32 | return win | |
33 | ||
34 | #--------------------------------------------------------------------------- | |
35 | ||
36 | overview = """ | |
37 | A Choice control is used to select one of a list of strings. Unlike a listbox, | |
38 | only the current selection is visible until the user pulls down the menu of | |
39 | choices. | |
40 | ||
41 | This demo illustrates how to set up the Choice control and how to extract the | |
42 | selected choice once it is selected. | |
43 | ||
44 | Note that the syntax of the constructor is different than the C++ implementation. | |
45 | The number of choices and the choice array are consilidated into one python | |
46 | <code>list</code>. | |
47 | """ | |
48 | ||
49 | ||
50 | if __name__ == '__main__': | |
51 | import sys,os | |
52 | import run | |
53 | run.main(['', os.path.basename(sys.argv[0])]) | |
54 |