Home | Trees | Indices | Help |
|
---|
|
1 # Copyright 2006 James Tauber and contributors 2 # Copyright (C) 2009, 2010 Luke Kenneth Casson Leighton <lkcl@lkcl.net> 3 # Copyright (C) 2010 Serge Tarkovski <serge.tarkovski@gmail.com> 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 from pyjamas import DOM 17 from pyjamas import Window 18 from pyjamas import Factory 19 from __pyjamas__ import JS, doc 20 from pyjamas.ui.SimplePanel import SimplePanel 21 from pyjamas.ui.RootPanel import RootPanel 22 from pyjamas.ui import MouseListener 23 from pyjamas.ui import KeyboardListener27 28 _props = [("modal", "Modal", "Modal", None), 29 ] 30285 286 Factory.registerClass('pyjamas.ui.PopupPanel', 'PopupPanel', PopupPanel) 28733 34 self.popupListeners = [] 35 self.showing = False 36 self.autoHide = autoHide 37 kwargs['Modal'] = kwargs.get('Modal', modal) 38 39 if rootpanel is None: 40 rootpanel = RootPanel() 41 self.rootpanel = rootpanel 42 43 self.glass = glass 44 if self.glass: 45 self.glass = DOM.createDiv() 46 if not 'GlassStyleName' in kwargs: 47 kwargs['GlassStyleName'] = "gwt-PopupPanelGlass" 48 49 if kwargs.has_key('Element'): 50 element = kwargs.pop('Element') 51 else: 52 element = self.createElement() 53 DOM.setStyleAttribute(element, "position", "absolute") 54 55 SimplePanel.__init__(self, element, **kwargs) 56 57 if glass: 58 self.setGlassEnabled(True) 59 if 'GlassStyleName' in kwargs: 60 self.setGlassStyleName(kwargs.pop('GlassStyleName'))61 62 63 64 @classmethod 6769 self.popupListeners.append(listener)70 73 76 77 # PopupImpl.createElement 8082 if not self.showing: 83 return 84 self.showing = False 85 86 if self.glass: 87 self.hideGlass() 88 89 DOM.removeEventPreview(self) 90 91 self.rootpanel.remove(self) 92 self.onHideImpl(self.getElement()) 93 for listener in self.popupListeners: 94 if hasattr(listener, 'onPopupClosed'): 95 listener.onPopupClosed(self, autoClosed) 96 else: 97 listener(self, autoClosed)98 101103 return self.isModal()104 109111 target = DOM.eventGetTarget(event) 112 return target and DOM.isOrHasChild(self.getElement(), target)113115 etype = DOM.eventGetType(event) 116 if etype == "keydown": 117 return ( self.onKeyDownPreview( 118 DOM.eventGetKeyCode(event), 119 KeyboardListener.getKeyboardModifiers(event) 120 ) 121 and (not self.modal or self._event_targets_popup(event)) 122 ) 123 elif etype == "keyup": 124 return ( self.onKeyUpPreview( 125 DOM.eventGetKeyCode(event), 126 KeyboardListener.getKeyboardModifiers(event) 127 ) 128 and (not self.modal or self._event_targets_popup(event)) 129 ) 130 elif etype == "keypress": 131 return ( self.onKeyPressPreview( 132 DOM.eventGetKeyCode(event), 133 KeyboardListener.getKeyboardModifiers(event) 134 ) 135 and (not self.modal or self._event_targets_popup(event)) 136 ) 137 elif ( etype == "mousedown" 138 or etype == "blur" 139 ): 140 if DOM.getCaptureElement() is not None: 141 return True 142 if self.autoHide and not self._event_targets_popup(event): 143 self.hide(True) 144 return True 145 elif ( etype == "mouseup" 146 or etype == "click" 147 or etype == "mousemove" 148 or type == "dblclick" 149 ): 150 if DOM.getCaptureElement() is not None: 151 return True 152 return not self.modal or self._event_targets_popup(event)153 156 159 162 163 # PopupImpl.onHide 166 167 # PopupImpl.onShow 170172 self.popupListeners.remove(listener)173175 if isinstance(left, basestring): 176 if left.endswith('%'): 177 left = int(left[:-1]) 178 left = int(left * Window.getClientWidth() / 100) 179 elif left.lower().endswith('px'): 180 left = int(left[:-2]) 181 if isinstance(top, basestring): 182 if top.lower().endswith('%'): 183 top = int(top[:-1]) 184 top = int(top * Window.getClientHeight() / 100) 185 elif top.endswith('px'): 186 top = int(top[:-2]) 187 188 left = max(left, 0) 189 top = max(top, 0) 190 191 # Account for the difference between absolute position and the 192 # body's positioning context. 193 left -= DOM.getBodyOffsetLeft() 194 top -= DOM.getBodyOffsetTop() 195 196 element = self.getElement() 197 DOM.setStyleAttribute(element, "left", "%dpx" % left) 198 DOM.setStyleAttribute(element, "top", "%dpx" % top)199 202204 if enabled: 205 if self.glass is None: 206 self.glass = DOM.createDiv() 207 self.setGlassStyleName() 208 elif self.glass is not None: 209 self.hideGlass()210 213 217 221223 top = Window.getScrollTop() 224 left = Window.getScrollLeft() 225 height = Window.getClientHeight() 226 width = Window.getClientWidth() 227 228 DOM.setStyleAttribute(self.glass, "position", "absolute") 229 DOM.setStyleAttribute(self.glass, "left", "%s" % \ 230 left if left == 0 else "%spx" % left) 231 DOM.setStyleAttribute(self.glass, "top", "%s" % \ 232 top if top == 0 else "%spx" % top) 233 DOM.setStyleAttribute(self.glass, "height", "%spx" % (top + height)) 234 DOM.setStyleAttribute(self.glass, "width", "%spx" % (left + width))235237 Window.enableScrolling(False) 238 self.setGlassPosition() 239 doc().body.appendChild(self.glass) 240 Window.addWindowResizeListener(self)241243 Window.removeWindowResizeListener(self) 244 doc().body.removeChild(self.glass) 245 Window.enableScrolling(True)246248 self.setGlassPosition()249251 self_width = self.getOffsetWidth() 252 self_height = self.getOffsetHeight() 253 254 height = Window.getClientHeight() 255 width = Window.getClientWidth() 256 257 center_x = int(width) / 2 258 center_y = int(height) / 2 259 260 self_top = center_y - (int(self_height) / 2) 261 self_left = center_x - (int(self_width) / 2) 262 263 self.setPopupPosition(self_left, self_top)264 268270 self.setWidget(widget)271273 if self.showing: 274 return 275 276 self.showing = True 277 278 if self.glass: 279 self.showGlass() 280 281 DOM.addEventPreview(self) 282 283 self.rootpanel.add(self) 284 self.onShowImpl(self.getElement())
Home | Trees | Indices | Help |
|
---|
http://epydoc.sourceforge.net |