Package library :: Package pyjamas :: Package ui :: Module HyperlinkImage
[hide private]
[frames] | no frames]

Source Code for Module library.pyjamas.ui.HyperlinkImage

 1  # Date Time Example 
 2  # Copyright (C) 2009 Yit Choong (http://code.google.com/u/yitchoong/) 
 3  # Copyright (C) 2009 Luke Kenneth Casson Leighton <lkcl@lkcl.net> 
 4   
 5  from pyjamas.ui.Hyperlink import Hyperlink 
 6  from pyjamas import Factory 
 7  from pyjamas.ui.Image import Image 
 8  from pyjamas import DOM 
 9  from pyjamas.ui import Event 
10  from pyjamas.ui import MouseListener 
11   
12   
13 -class HyperlinkImage(Hyperlink):
14 - def __init__(self, img, **kwargs):
15 self.mouseListeners = [] 16 if not kwargs.has_key('StyleName'): 17 kwargs['StyleName'] = 'gwt-HyperlinkImage' 18 Hyperlink.__init__(self, **kwargs) 19 DOM.appendChild(DOM.getFirstChild(self.getElement()), img.getElement()) 20 img.unsinkEvents(Event.ONCLICK | Event.MOUSEEVENTS) 21 self.sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS)
22
23 - def addMouseListener(self, listener):
24 self.mouseListeners.append(listener)
25
26 - def removeMouseListener(self,listener):
27 self.mouseListeners.remove(listener)
28
29 - def onBrowserEvent(self, event):
30 type = DOM.eventGetType(event) 31 if type == 'mousedown' or type == 'mouseup' or type == 'mousemove' or type == 'mouseover' or type == 'mouseout': 32 MouseListener.fireMouseEvent(self.mouseListeners, self, event) 33 # stop event falling through esp. for drag on image 34 DOM.eventPreventDefault(event) 35 36 else: 37 Hyperlink.onBrowserEvent(self, event)
38 39 Factory.registerClass('pyjamas.ui.HyperlinkImage', 'HyperlinkImage', HyperlinkImage) 40