标签:eth mon format following turn ble title inf a star
choice_editor = wx.grid.GridCellChoiceEditor(choices_list, True)
grid.SetCellEditor(row, col, choice_editor)
A common question is how to dynamically update the list in a GridCellChoiceEditor. The problem comes from not having direct access to the underlying ComboBox widget in the grid editor. Fortunately the grid editor throws an event that allows us to get to the underlying ComboBox.
In addition to dynamic updates to the choice list, having access to the underlying ComboBox allows us to use application data and the choice index.
The following example shows a method of doing this.
1 #-----------------------------------------------------------------------------
2 # Name: GridCombo.py
3 # Purpose: Dynamic list updating with a wx.grid.GridCellChoiceEditor
4 #
5 # Author: Thomas M Wetherbee
6 #
7 # Created: 2009/04/27
8 # RCS-ID: $Id: GridCombo.py $
9 # Copyright: (c) 2009
10 # Licence: Distributed under the terms of the GNU General Public License
11 #-----------------------------------------------------------------------------
12 #!/usr/bin/env python
13
14
15 ‘‘‘
16 Dynamic list updating with a wx.grid.GridCellChoiceEditor.
17
18 This example shows how to dynamically update the choices in a
19 GridCellChoiceEditor. This simple example creates a two column
20 grid where the top row in each column is a wx.grid.GridCellChoiceEditor.
21 The choices listed in the editor are created on the fly, and may change
22 with each selection. Text entered into the GridCellChoiceEditor cell
23 is appended as an additional choice.
24
25 In addition to appending new choices, this example also shows how to get
26 the selection index and client data from the choice.
27
28 Cell editor interactions are printed for every step.
29
30 This example is deliberately simple, lacking sizers and other useful but
31 confusing niceties.
32
33 Theory:
34
35 The GridCellChoiceEditor uses an underlying ComboBox to do the editing.
36 This underlying ComboBox is created when the cell editor is created. Normally
37 the ComboBox is completely hidden, but in this example we retrieve a reference
38 to the ComboBox and use it to load choices and retrieve index and client data.
39
40 The example starts with a GridCellChoiceEditor attached to the two top cells of
41 the grid. When the GridCellChoiceEditor is invoked for the first time, two
42 choice items are added to the choice list along with their associated user
43 data. The items are (‘spam‘, 42) and (‘eggs‘, 69), where spam is the text to
44 display and 42 is the associated client data. In this example ‘spam‘ has an
45 index of 0 while eggs, being the second item of the list, has an index of 1.
46
47 Note that the index and user data are not required. The demonstrated method
48 works fine without either, but sometimes it is useful to know the index of a
49 selection, especially when the user is allowed to create choices. For example,
50