Home | Trees | Indices | Help |
|
---|
|
1 # Copyright 2006 James Tauber and contributors 2 # Copyright (C) 2009 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 SimplePanel import SimplePanel 21 from RootPanel import RootPanel 22 from pyjamas.ui import MouseListener 23 from pyjamas.ui import KeyboardListener 24206 207 Factory.registerClass('pyjamas.ui.PopupPanel', PopupPanel) 20827 28 self.popupListeners = [] 29 self.showing = False 30 self.autoHide = autoHide 31 self.modal = modal 32 33 self.glass = glass 34 if self.glass: 35 self.glass = DOM.createDiv() 36 if not 'GlassStyleName' in kwargs: 37 kwargs['GlassStyleName'] = "gwt-PopupPanelGlass" 38 39 if rootpanel is None: 40 rootpanel = RootPanel() 41 42 self.rootpanel = rootpanel 43 44 if kwargs.has_key('Element'): 45 element = kwargs.pop('Element') 46 else: 47 element = self.createElement() 48 DOM.setStyleAttribute(element, "position", "absolute") 49 50 SimplePanel.__init__(self, element, **kwargs)5153 self.popupListeners.append(listener)54 57 60 61 # PopupImpl.createElement 6466 if not self.showing: 67 return 68 self.showing = False 69 70 if self.glass: 71 self.hideGlass() 72 73 DOM.removeEventPreview(self) 74 75 self.rootpanel.remove(self) 76 self.onHideImpl(self.getElement()) 77 for listener in self.popupListeners: 78 if hasattr(listener, 'onPopupClosed'): listener.onPopupClosed(self, autoClosed) 79 else: listener(self, autoClosed)80 8385 target = DOM.eventGetTarget(event) 86 return target and DOM.isOrHasChild(self.getElement(), target)8789 type = DOM.eventGetType(event) 90 if type == "keydown": 91 return ( self.onKeyDownPreview( 92 DOM.eventGetKeyCode(event), 93 KeyboardListener.getKeyboardModifiers(event) 94 ) 95 and (not self.modal or self._event_targets_popup(event)) 96 ) 97 elif type == "keyup": 98 return ( self.onKeyUpPreview( 99 DOM.eventGetKeyCode(event), 100 KeyboardListener.getKeyboardModifiers(event) 101 ) 102 and (not self.modal or self._event_targets_popup(event)) 103 ) 104 elif type == "keypress": 105 return ( self.onKeyPressPreview( 106 DOM.eventGetKeyCode(event), 107 KeyboardListener.getKeyboardModifiers(event) 108 ) 109 and (not self.modal or self._event_targets_popup(event)) 110 ) 111 elif ( type == "mousedown" 112 or type == "blur" 113 ): 114 if DOM.getCaptureElement() is not None: 115 return True 116 if self.autoHide and not self._event_targets_popup(event): 117 self.hide(True) 118 return True 119 elif ( type == "mouseup" 120 or type == "click" 121 or type == "mousemove" 122 or type == "dblclick" 123 ): 124 if DOM.getCaptureElement() is not None: 125 return True 126 return not self.modal or self._event_targets_popup(event)127 130 133 136 137 # PopupImpl.onHide 140 141 # PopupImpl.onShow 144146 self.popupListeners.remove(listener)147149 if left < 0: 150 left = 0 151 if top < 0: 152 top = 0 153 154 # Account for the difference between absolute position and the 155 # body's positioning context. 156 left -= DOM.getBodyOffsetLeft() 157 top -= DOM.getBodyOffsetTop() 158 159 element = self.getElement() 160 DOM.setStyleAttribute(element, "left", "%dpx" % left) 161 DOM.setStyleAttribute(element, "top", "%dpx" % top)162 166168 top = Window.getScrollTop() 169 left = Window.getScrollLeft() 170 height = Window.getClientHeight() 171 width = Window.getClientWidth() 172 173 DOM.setStyleAttribute(self.glass, "position", "absolute") 174 DOM.setStyleAttribute(self.glass, "left", "%s" % left if left == 0 else "%spx" % left) 175 DOM.setStyleAttribute(self.glass, "top", "%s" % top if top == 0 else "%spx" % top) 176 DOM.setStyleAttribute(self.glass, "height", "%spx" % (top + height)) 177 DOM.setStyleAttribute(self.glass, "width", "%spx" % (left + width))178180 Window.enableScrolling(False) 181 self.setGlassPosition() 182 doc().body.appendChild(self.glass) 183 Window.addWindowResizeListener(self)184186 Window.removeWindowResizeListener(self) 187 doc().body.removeChild(self.glass) 188 Window.enableScrolling(True)189191 self.setGlassPosition()192194 if self.showing: 195 return 196 197 self.showing = True 198 199 if self.glass: 200 self.showGlass() 201 202 DOM.addEventPreview(self) 203 204 self.rootpanel.add(self) 205 self.onShowImpl(self.getElement())
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Jun 16 12:42:34 2010 | http://epydoc.sourceforge.net |