1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """Defines a filtering drop-down single-select."""
17
18 from muntjac.ui.select import Select
19 from muntjac.data.container import IContainer
20
21 from muntjac.terminal.gwt.client.ui.v_filter_select import VFilterSelect
22
23
25 """A filtering dropdown single-select. Suitable for newItemsAllowed, but
26 it's turned of by default to avoid mistakes. Items are filtered based on
27 user input, and loaded dynamically ("lazy-loading") from the server. You
28 can turn on newItemsAllowed and change filtering mode (and also turn it
29 off), but you can not turn on multi-select mode.
30 """
31
32 CLIENT_WIDGET = None
33
35 self._inputPrompt = None
36
37
38
39
40 self._textInputAllowed = True
41
42 nargs = len(args)
43 if nargs == 0:
44 super(ComboBox, self).__init__()
45 self.setMultiSelect(False)
46 self.setNewItemsAllowed(False)
47 elif nargs == 1:
48 caption, = args
49 super(ComboBox, self).__init__(caption)
50 self.setMultiSelect(False)
51 self.setNewItemsAllowed(False)
52 elif nargs == 2:
53 if isinstance(args[1], IContainer):
54 caption, dataSource = args
55 super(ComboBox, self).__init__(caption, dataSource)
56 self.setMultiSelect(False)
57 self.setNewItemsAllowed(False)
58 else:
59 caption, options = args
60 super(ComboBox, self).__init__(caption, options)
61 self.setMultiSelect(False)
62 self.setNewItemsAllowed(False)
63 else:
64 raise ValueError, 'too many arguments'
65
66
72
73
81
82
92
93
94 - def paintContent(self, target):
95 if self._inputPrompt is not None:
96 target.addAttribute('prompt', self._inputPrompt)
97
98 super(ComboBox, self).paintContent(target)
99
100 if not self._textInputAllowed:
101 target.addAttribute(VFilterSelect.ATTR_NO_TEXT_INPUT, True)
102
103
105 """Sets whether it is possible to input text into the field or whether
106 the field area of the component is just used to show what is selected.
107 By disabling text input, the comboBox will work in the same way as a
108 L{NativeSelect}
109
110 @see L{isTextInputAllowed}
111
112 @param textInputAllowed:
113 true to allow entering text, false to just show the current
114 selection
115 """
116 self._textInputAllowed = textInputAllowed
117 self.requestRepaint()
118
119
121 """Returns true if the user can enter text into the field to either
122 filter the selections or enter a new value if :{isNewItemsAllowed}
123 returns true. If text input is disabled, the comboBox will work in the
124 same way as a L{NativeSelect}.
125 """
126 return self._textInputAllowed
127