1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from muntjac.ui.abstract_select import AbstractSelect
17 from muntjac.data.container import IContainer
18
19 from muntjac.event.field_events import \
20 BlurEvent, IBlurListener, IBlurNotifier, FocusEvent, \
21 IFocusListener, IFocusNotifier
22
23 from muntjac.terminal.gwt.client.ui.v_option_group import VOptionGroup
24
25
26 -class OptionGroup(AbstractSelect, IBlurNotifier, IFocusNotifier):
27 """Configures select to be used as an option group."""
28
29 CLIENT_WIDGET = None
30
32 self._disabledItemIds = set()
33
34 self._htmlContentAllowed = False
35
36 args = args
37 nargs = len(args)
38 if nargs == 0:
39 super(OptionGroup, self).__init__()
40 elif nargs == 1:
41 caption, = args
42 super(OptionGroup, self).__init__(caption)
43 elif nargs == 2:
44 if isinstance(args[1], IContainer):
45 caption, dataSource = args
46 super(OptionGroup, self).__init__(caption, dataSource)
47 else:
48 caption, options = args
49 super(OptionGroup, self).__init__(caption, options)
50 else:
51 raise ValueError, 'too many arguments'
52
53
54 - def paintContent(self, target):
59
60
65
66
75
76
78 if (isinstance(listener, IBlurListener) and
79 (iface is None or issubclass(iface, IBlurListener))):
80 self.registerListener(BlurEvent.EVENT_ID, BlurEvent,
81 listener, IBlurListener.blurMethod)
82
83 if (isinstance(listener, IFocusListener) and
84 (iface is None or issubclass(iface, IFocusListener))):
85 self.registerListener(FocusEvent.EVENT_ID, FocusEvent,
86 listener, IFocusListener.focusMethod)
87
88 super(OptionGroup, self).addListener(listener, iface)
89
90
91 - def addCallback(self, callback, eventType=None, *args):
92 if eventType is None:
93 eventType = callback._eventType
94
95 if issubclass(eventType, BlurEvent):
96 self.registerCallback(BlurEvent, callback,
97 BlurEvent.EVENT_ID, *args)
98
99 elif issubclass(eventType, FocusEvent):
100 self.registerCallback(FocusEvent, callback,
101 FocusEvent.EVENT_ID, *args)
102 else:
103 super(OptionGroup, self).addCallback(callback, eventType, *args)
104
105
107 if (isinstance(listener, IBlurListener) and
108 (iface is None or issubclass(iface, IBlurListener))):
109 self.withdrawListener(BlurEvent.EVENT_ID, BlurEvent, listener)
110
111 if (isinstance(listener, IFocusListener) and
112 (iface is None or issubclass(iface, IFocusListener))):
113 self.withdrawListener(FocusEvent.EVENT_ID, FocusEvent, listener)
114
115 super(OptionGroup, self).removeListener(listener, iface)
116
117
130
131
132 - def setValue(self, newValue, repaintIsNotNeeded=None):
133 if repaintIsNotNeeded is not None and repaintIsNotNeeded is True:
134
135
136
137
138 if self.isMultiSelect():
139 currentValueSet = self.getValue()
140 newValueSet = newValue
141 for itemId in currentValueSet:
142 if (not self.isItemEnabled(itemId)
143 and not (itemId in newValueSet)):
144 self.requestRepaint()
145 return
146
147 for itemId in newValueSet:
148 if (not self.isItemEnabled(itemId)
149 and not (itemId in currentValueSet)):
150 self.requestRepaint()
151 return
152 else:
153 if newValue is None:
154 newValue = self.getNullSelectionItemId()
155
156 if not self.isItemEnabled(newValue):
157 self.requestRepaint()
158 return
159
160 super(OptionGroup, self).setValue(newValue, repaintIsNotNeeded)
161
162
164 """Sets an item disabled or enabled. In the multiselect mode, a disabled
165 item cannot be selected or deselected by the user. In the single
166 selection mode, a disable item cannot be selected.
167
168 However, programmatical selection or deselection of an disable item is
169 possible. By default, items are enabled.
170
171 @param itemId:
172 the id of the item to be disabled or enabled
173 @param enabled:
174 if true the item is enabled, otherwise the item is disabled
175 """
176 if itemId is not None:
177
178 if enabled:
179 self._disabledItemIds.remove(itemId)
180 else:
181 self._disabledItemIds.add(itemId)
182
183 self.requestRepaint()
184
185
187 """Returns true if the item is enabled.
188
189 @param itemId:
190 the id of the item to be checked
191 @return: true if the item is enabled, false otherwise
192 @see: L{setItemEnabled}
193 """
194 if itemId is not None:
195 return not (itemId in self._disabledItemIds)
196
197 return True
198
199
200 - def setHtmlContentAllowed(self, htmlContentAllowed):
201 """Sets whether html is allowed in the item captions. If set to true,
202 the captions are passed to the browser as html and the developer is
203 responsible for ensuring no harmful html is used. If set to false, the
204 content is passed to the browser as plain text.
205
206 @param htmlContentAllowed:
207 true if the captions are used as html, false if used as plain
208 text
209 """
210 self._htmlContentAllowed = htmlContentAllowed
211 self.requestRepaint()
212
213
215 """Checks whether captions are interpreted as html or plain text.
216
217 @return: true if the captions are used as html, false if used as plain
218 text
219 @see: L{setHtmlContentAllowed}
220 """
221 return self._htmlContentAllowed
222