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 import pyjd 17 from pyjamas import DOM 18 from pyjamas import Window 19 from pyjamas import Factory 20 from __pyjamas__ import JS, doc 21 from pyjamas.ui.SimplePanel import SimplePanel 22 from pyjamas.ui.Widget import Widget 23 from pyjamas.ui.MouseListener import MouseHandler 24 from pyjamas.ui.RootPanel import RootPanel 25 26 mousecapturer = None 27 2830 global mousecapturer 31 if mousecapturer is None: 32 mousecapturer = GlassWidget(**kwargs) 33 # if mousecapturer has been overloaded with something 34 # other than a GlassWidget (as in IE override) 35 # just return None 36 elif not isinstance(mousecapturer, GlassWidget): 37 return None 38 return mousecapturer39 4042 global mousecapturer 43 mc = getMouseCapturer(**kwargs) 44 mc.mousetarget = mousetarget 45 if isinstance(mousetarget, MouseHandler): 46 mc.mousehandler = True 47 mc.show()48 49 53 54198 199 200 Factory.registerClass('pyjamas.ui.GlassWidget', 'GlassWidget', GlassWidget) 20157 58 self.glassListeners = [] 59 self.showing = False 60 self.mousehandler = False 61 62 if not 'StyleName' in kwargs: 63 kwargs['StyleName'] = "gwt-GlassWidget" 64 65 if 'Element' in kwargs: 66 element = kwargs.pop('Element') 67 else: 68 element = DOM.createDiv() 69 70 self.setElement(element) 71 Widget.__init__(self, **kwargs) 72 MouseHandler.__init__(self) 73 self.setzIndex(1000000) 74 self.addMouseListener(self)7577 self.glassListeners.append(listener)7880 self.showing = False 81 82 self.hideGlass() 83 84 DOM.removeEventPreview(self) 85 86 RootPanel().remove(self) 87 self.onHideImpl(self.getElement()) 88 DOM.releaseCapture(self.getElement()) 89 for listener in self.glassListeners: 90 if hasattr(listener, 'onGlassHide'): 91 listener.onGlassHide(self, autoClosed) 92 else: 93 listener(self, autoClosed)9496 target = DOM.eventGetTarget(event) 97 return target and DOM.isOrHasChild(self.getElement(), target)98100 etype = DOM.eventGetType(event) 101 if etype == "mousedown" or etype == "blur": 102 if DOM.getCaptureElement() is not None: 103 return True 104 elif etype == "mouseup" or etype == "click" or \ 105 etype == "mousemove" or etype == "dblclick": 106 if DOM.getCaptureElement() is not None: 107 return True 108 return self._event_targets_popup(event)109 112 115117 self.glassListeners.remove(listener)118120 top = Window.getScrollTop() 121 left = Window.getScrollLeft() 122 height = Window.getClientHeight() 123 width = Window.getClientWidth() 124 el = self.getElement() 125 DOM.setStyleAttribute(el, "position", "absolute") 126 DOM.setStyleAttribute(el, "left", 127 "%s" % left if left == 0 else "%spx" % left) 128 DOM.setStyleAttribute(el, "top", 129 "%s" % top if top == 0 else "%spx" % top) 130 DOM.setStyleAttribute(el, "height", "%spx" % (top + height)) 131 DOM.setStyleAttribute(el, "width", "%spx" % (left + width)) 132 # under pyjd glasswidget cannot be transparent, 133 # otherwise it drops the mousecapture, so we have 134 # to give it a 1% opaque background color 135 if pyjd.is_desktop: 136 # pyjd uses IE style opacity 137 DOM.setStyleAttribute(el, "filter", "alpha(opacity=1)") 138 # this is the Moz form of transparency 139 DOM.setStyleAttribute(el, "background", "rgba(255,255,255,0.1)")140142 self.setGlassPosition() 143 doc().body.appendChild(self.getElement()) 144 Window.addWindowResizeListener(self)145 149151 self.setGlassPosition()152154 if self.showing: 155 return 156 157 self.showing = True 158 159 self.showGlass() 160 161 DOM.addEventPreview(self) 162 163 RootPanel().add(self) 164 self.onShowImpl(self.getElement()) 165 DOM.setCapture(self.getElement())166168 x += self.getAbsoluteLeft() - self.mousetarget.getAbsoluteLeft() 169 y += self.getAbsoluteTop() - self.mousetarget.getAbsoluteTop() 170 return x, y171173 x, y = self.adjustMousePos(x, y) 174 if self.mousehandler: 175 self.mousetarget.onBrowserEvent(DOM.eventGetCurrentEvent()) 176 else: 177 self.mousetarget.onMouseDown(sender, x, y)178180 self.mousetarget.onMouseGlassEnter(sender)181183 self.mousetarget.onMouseGlassLeave(sender)184186 x, y = self.adjustMousePos(x, y) 187 if self.mousehandler: 188 self.mousetarget.onBrowserEvent(DOM.eventGetCurrentEvent()) 189 else: 190 self.mousetarget.onMouseMove(sender, x, y)191193 x, y = self.adjustMousePos(x, y) 194 if self.mousehandler: 195 self.mousetarget.onBrowserEvent(DOM.eventGetCurrentEvent()) 196 else: 197 self.mousetarget.onMouseUp(sender, x, y)
Home | Trees | Indices | Help |
|
---|
http://epydoc.sourceforge.net |