Package muntjac :: Package event :: Module field_events
[hide private]
[frames] | no frames]

Source Code for Module muntjac.event.field_events

  1  # Copyright (C) 2012 Vaadin Ltd.  
  2  # Copyright (C) 2012 Richard Lincoln 
  3  #  
  4  # Licensed under the Apache License, Version 2.0 (the "License");  
  5  # you may not use this file except in compliance with the License.  
  6  # You may obtain a copy of the License at  
  7  #  
  8  #     http://www.apache.org/licenses/LICENSE-2.0  
  9  #  
 10  # Unless required by applicable law or agreed to in writing, software  
 11  # distributed under the License is distributed on an "AS IS" BASIS,  
 12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
 13  # See the License for the specific language governing permissions and  
 14  # limitations under the License. 
 15   
 16  """Interface for adding and removing C{FocusEvent} listeners.""" 
 17   
 18  from muntjac.terminal.gwt.client.event_id import EventId 
 19  from muntjac.event.component_event_listener import IComponentEventListener 
 20  from muntjac.ui.component import Event as ComponentEvent 
 21   
 22   
23 -class IFocusNotifier(object):
24 """The interface for adding and removing C{FocusEvent} listeners. 25 By implementing this interface a class explicitly announces that it will 26 generate a C{FocusEvent} when it receives keyboard focus. 27 28 @see: L{IFocusListener} 29 @see: L{FocusEvent} 30 """ 31
32 - def addListener(self, listener, iface=None):
33 """Adds a C{IFocusListener} to the Component which gets fired 34 when a C{Field} receives keyboard focus. 35 36 @see: L{IFocusListener} 37 """ 38 raise NotImplementedError
39 40
41 - def addCallback(self, callback, eventType=None, *args):
42 raise NotImplementedError
43 44
45 - def removeListener(self, listener, iface=None):
46 """Removes a C{IFocusListener} from the Component. 47 48 @see: L{IFocusListener} 49 """ 50 raise NotImplementedError
51 52
53 - def removeCallback(self, callback, eventType=None):
54 raise NotImplementedError
55 56
57 -class IBlurNotifier(object):
58 """The interface for adding and removing C{BlurEvent} listeners. 59 By implementing this interface a class explicitly announces that it will 60 generate a C{BlurEvent} when it loses keyboard focus. 61 62 @see: L{IBlurListener} 63 @see: L{BlurEvent} 64 """ 65
66 - def addListener(self, listener, iface=None):
67 """Adds a C{IBlurListener} to the Component which gets fired 68 when a C{Field} loses keyboard focus. 69 70 @see: L{IBlurListener} 71 """ 72 raise NotImplementedError
73 74
75 - def addCallback(self, callback, eventType=None, *args):
76 raise NotImplementedError
77 78
79 - def removeListener(self, listener, iface=None):
80 """Removes a C{IBlurListener} from the Component. 81 82 @see: L{IBlurListener} 83 """ 84 raise NotImplementedError
85 86
87 - def removeCallback(self, callback, eventType=None):
88 raise NotImplementedError
89 90
91 -class FocusEvent(ComponentEvent):
92 """C{FocusEvent} class for holding additional event information. 93 Fired when a C{Field} receives keyboard focus. 94 """ 95 # Identifier for event that can be used in L{EventRouter} 96 EVENT_ID = EventId.FOCUS 97
98 - def __init__(self, source):
99 super(FocusEvent, self).__init__(source)
100 101
102 -class IFocusListener(IComponentEventListener):
103 """C{IFocusListener} interface for listening for C{FocusEvent} fired by 104 a C{Field}. 105 106 @see: FocusEvent 107 """ 108
109 - def focus(self, event):
110 """Component has been focused 111 112 @param event: 113 Component focus event. 114 """ 115 raise NotImplementedError
116 117 focusMethod = focus
118 119
120 -class BlurEvent(ComponentEvent):
121 """C{BlurEvent} class for holding additional event information. 122 Fired when a C{Field} loses keyboard focus. 123 """ 124 125 # Identifier for event that can be used in L{EventRouter} 126 EVENT_ID = EventId.BLUR 127
128 - def __init__(self, source):
129 super(BlurEvent, self).__init__(source)
130 131
132 -class IBlurListener(IComponentEventListener):
133 """C{IBlurListener} interface for listening for C{BlurEvent} fired by 134 a C{Field}. 135 136 @see: BlurEvent 137 """ 138
139 - def blur(self, event):
140 """Component has been blurred 141 142 @param event: 143 Component blur event. 144 """ 145 raise NotImplementedError
146 147 blurMethod = blur
148 149
150 -class TextChangeEvent(ComponentEvent):
151 """TextChangeEvents are fired when the user is editing the text content of 152 a field. Most commonly text change events are triggered by typing text with 153 keyboard, but e.g. pasting content from clip board to a text field also 154 triggers an event. 155 156 TextChangeEvents differ from L{ValueChangeEvent}s so that they are 157 triggered repeatedly while the end user is filling the field. 158 ValueChangeEvents are not fired until the user for example hits enter or 159 focuses another field. Also note the difference that TextChangeEvents are 160 only fired if the change is triggered from the user, while 161 ValueChangeEvents are also fired if the field value is set by the 162 application code. 163 164 The L{ITextChangeNotifier}s implementation may decide when exactly 165 TextChangeEvents are fired. TextChangeEvents are not necessary fire for 166 example on each key press, but buffered with a small delay. The 167 L{TextField} component supports different modes for triggering 168 TextChangeEvents. 169 170 @see: L{ITextChangeListener} 171 @see: L{ITextChangeNotifier} 172 @see: TextField.setTextChangeEventMode 173 """ 174
175 - def __init__(self, source):
176 super(TextChangeEvent, self).__init__(source)
177 178
179 - def getText(self):
180 """@return: the text content of the field after the 181 L{TextChangeEvent} 182 """ 183 pass
184 185
186 - def getCursorPosition(self):
187 """@return: the cursor position during after the 188 L{TextChangeEvent}""" 189 pass
190 191
192 -class ITextChangeListener(IComponentEventListener):
193 """A listener for L{TextChangeEvent}s. 194 """ 195 196 EVENT_ID = 'ie' 197
198 - def textChange(self, event):
199 """This method is called repeatedly while the text is edited by a 200 user. 201 202 @param event: 203 the event providing details of the text change 204 """ 205 raise NotImplementedError
206 207 208 EVENT_METHOD = ITextChangeListener.textChange 209 210
211 -class ITextChangeNotifier(object):
212 """An interface implemented by a L{Field} supporting 213 L{TextChangeEvent}s. An example a L{TextField} supports 214 L{ITextChangeListener}s. 215 """ 216
217 - def addListener(self, listener, iface=None):
218 raise NotImplementedError
219 220
221 - def addCallback(self, callback, eventType=None, *args):
222 raise NotImplementedError
223 224
225 - def removeListener(self, listener, iface=None):
226 raise NotImplementedError
227 228
229 - def removeCallback(self, callback, eventType=None):
230 raise NotImplementedError
231