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

Source Code for Module muntjac.event.mouse_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  """Class for holding information about a mouse click event.""" 
 17   
 18  from muntjac.terminal.gwt.client.mouse_event_details import MouseEventDetails 
 19  from muntjac.event.component_event_listener import IComponentEventListener 
 20  from muntjac.ui.component import Event as ComponentEvent 
 21   
 22   
23 -class ClickEvent(ComponentEvent):
24 """Class for holding information about a mouse click event. A 25 L{ClickEvent} is fired when the user clicks on a C{Component}. 26 27 The information available for click events are terminal dependent. 28 Correct values for all event details cannot be guaranteed. 29 30 @author: Vaadin Ltd. 31 @author: Richard Lincoln 32 @see: L{ClickListener} 33 @version: 1.1.2 34 """ 35 36 BUTTON_LEFT = MouseEventDetails.BUTTON_LEFT 37 BUTTON_MIDDLE = MouseEventDetails.BUTTON_MIDDLE 38 BUTTON_RIGHT = MouseEventDetails.BUTTON_RIGHT 39
40 - def __init__(self, source, mouseEventDetails):
41 super(ClickEvent, self).__init__(source) 42 self._details = mouseEventDetails
43 44
45 - def getButton(self):
46 """Returns an identifier describing which mouse button the user pushed. 47 Compare with L{BUTTON_LEFT}, L{BUTTON_MIDDLE}, L{BUTTON_RIGHT} to 48 find out which button it is. 49 50 @return: one of L{BUTTON_LEFT}, L{BUTTON_MIDDLE}, L{BUTTON_RIGHT}. 51 """ 52 return self._details.getButton()
53 54
55 - def getClientX(self):
56 """Returns the mouse position (x coordinate) when the click took place. 57 The position is relative to the browser client area. 58 59 @return: The mouse cursor x position 60 """ 61 return self._details.getClientX()
62 63
64 - def getClientY(self):
65 """Returns the mouse position (y coordinate) when the click took place. 66 The position is relative to the browser client area. 67 68 @return: The mouse cursor y position 69 """ 70 return self._details.getClientY()
71 72
73 - def getRelativeX(self):
74 """Returns the relative mouse position (x coordinate) when the click 75 took place. The position is relative to the clicked component. 76 77 @return: The mouse cursor x position relative to the clicked layout 78 component or -1 if no x coordinate available 79 """ 80 return self._details.getRelativeX()
81 82
83 - def getRelativeY(self):
84 """Returns the relative mouse position (y coordinate) when the click 85 took place. The position is relative to the clicked component. 86 87 @return: The mouse cursor y position relative to the clicked layout 88 component or -1 if no y coordinate available 89 """ 90 return self._details.getRelativeY()
91 92
93 - def isDoubleClick(self):
94 """Checks if the event is a double click event. 95 96 @return: true if the event is a double click event, false otherwise 97 """ 98 return self._details.isDoubleClick()
99 100
101 - def isAltKey(self):
102 """Checks if the Alt key was down when the mouse event took place. 103 104 @return: true if Alt was down when the event occured, false otherwise 105 """ 106 return self._details.isAltKey()
107 108
109 - def isCtrlKey(self):
110 """Checks if the Ctrl key was down when the mouse event took place. 111 112 @return: true if Ctrl was pressed when the event occured, false 113 otherwise 114 """ 115 return self._details.isCtrlKey()
116 117
118 - def isMetaKey(self):
119 """Checks if the Meta key was down when the mouse event took place. 120 121 @return: true if Meta was pressed when the event occured, false 122 otherwise 123 """ 124 return self._details.isMetaKey()
125 126
127 - def isShiftKey(self):
128 """Checks if the Shift key was down when the mouse event took place. 129 130 @return: true if Shift was pressed when the event occured, false 131 otherwise 132 """ 133 return self._details.isShiftKey()
134 135
136 - def getButtonName(self):
137 """Returns a human readable string representing which button has been 138 pushed. This is meant for debug purposes only and the string returned 139 could change. Use L{getButton} to check which button was pressed. 140 141 @return: A string representation of which button was pushed. 142 """ 143 return self._details.getButtonName()
144 145
146 -class IClickListener(IComponentEventListener):
147 """Interface for listening for a L{ClickEvent} fired by a L{Component}. 148 149 @see: L{ClickEvent} 150 @author: Vaadin Ltd. 151 @author: Richard Lincoln 152 @version: 1.1.2 153 """ 154
155 - def click(self, event):
156 """Called when a L{Component} has been clicked. A reference to the 157 component is given by L{ClickEvent.getComponent}. 158 159 @param event: 160 An event containing information about the click. 161 """ 162 raise NotImplementedError
163 164 clickMethod = click
165 166
167 -class DoubleClickEvent(ComponentEvent):
168 """Class for holding additional event information for DoubleClick events. 169 Fired when the user double-clicks on a C{Component}. 170 171 @see: L{ClickEvent} 172 @author: Vaadin Ltd. 173 @author: Richard Lincoln 174 @version: 1.1.2 175 """ 176
177 - def __init__(self, source):
178 super(DoubleClickEvent, self).__init__(source)
179 180
181 -class IDoubleClickListener(IComponentEventListener):
182 """Interface for listening for a L{DoubleClickEvent} fired by a 183 L{Component}. 184 185 @see: L{DoubleClickEvent} 186 @author: Vaadin Ltd. 187 @author: Richard Lincoln 188 @version: 1.1.2 189 """ 190
191 - def doubleClick(self, event):
192 """Called when a L{Component} has been double clicked. A reference 193 to the component is given by L{DoubleClickEvent.getComponent}. 194 195 @param event: 196 An event containing information about the double click. 197 """ 198 raise NotImplementedError
199 200 doubleClickMethod = doubleClick
201