<s> from pyjamas . ui . PopupPanel import PopupPanel <EOL> from pyjamas import Factory <EOL> from pyjamas . ui . HTML import HTML <EOL> from pyjamas . ui . RootPanel import RootPanel <EOL> from pyjamas . Timer import Timer <EOL> from pyjamas import Window <EOL> from pyjamas import DOM <EOL> tooltip_hide_timer = None <EOL> class Tooltip ( PopupPanel ) : <EOL> def __init__ ( self , sender , offsetX , offsetY , contents , <EOL> show_delay , hide_delay , styleName , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> PopupPanel . __init__ ( self , True , ** kwargs ) <EOL> self . show_delay = show_delay <EOL> self . hide_delay = hide_delay <EOL> if isinstance ( contents , basestring ) : <EOL> contents = HTML ( contents ) <EOL> self . add ( contents ) <EOL> left = sender . getAbsoluteLeft ( ) + offsetX <EOL> top = sender . getAbsoluteTop ( ) + offsetY <EOL> self . setPopupPosition ( left , top ) <EOL> self . setStyleName ( styleName ) <EOL> if tooltip_hide_timer : <EOL> self . tooltip_show_timer = Timer ( <NUM_LIT:1> , self ) <EOL> else : <EOL> self . tooltip_show_timer = Timer ( self . show_delay , self ) <EOL> def onShowImpl ( self , popup ) : <EOL> width = self . getOffsetWidth ( ) <EOL> heigth = self . getOffsetHeight ( ) <EOL> w_width = Window . getClientWidth ( ) <EOL> w_heigth = Window . getClientHeight ( ) <EOL> if w_width > width and w_heigth > heigth : <EOL> offset_x = self . getAbsoluteLeft ( ) <EOL> offset_y = self . getAbsoluteTop ( ) <EOL> element = self . getElement ( ) <EOL> if ( offset_x + width ) > w_width : <EOL> offset_x = w_width - width <EOL> DOM . setStyleAttribute ( element , "<STR_LIT:left>" , "<STR_LIT>" % offset_x ) <EOL> if ( offset_y + heigth ) > w_heigth : <EOL> offset_y = w_heigth - heigth <EOL> DOM . setStyleAttribute ( element , "<STR_LIT>" , "<STR_LIT>" % offset_y ) <EOL> def show ( self ) : <EOL> global tooltip_hide_timer <EOL> tooltip_hide_timer = Timer ( self . hide_delay , self ) <EOL> PopupPanel . show ( self ) <EOL> def hide ( self , autoClosed = False ) : <EOL> self . tooltip_show_timer . cancel ( ) <EOL> PopupPanel . hide ( self , autoClosed ) <EOL> def onTimer ( self , timer ) : <EOL> global tooltip_hide_timer <EOL> if timer is tooltip_hide_timer : <EOL> tooltip_hide_timer = None <EOL> if timer is self . tooltip_show_timer : <EOL> self . show ( ) <EOL> else : <EOL> self . hide ( ) <EOL> class TooltipListener : <EOL> DEFAULT_TOOLTIP_STYLE = "<STR_LIT>" <EOL> DEFAULT_OFFSET_X = <NUM_LIT:10> <EOL> DEFAULT_OFFSET_Y = <NUM_LIT> <EOL> def __init__ ( self , text , show_delay = <NUM_LIT:1000> , hide_delay = <NUM_LIT> , styleName = "<STR_LIT>" ) : <EOL> if not styleName : <EOL> styleName = self . DEFAULT_TOOLTIP_STYLE <EOL> self . tooltip = None <EOL> self . text = text <EOL> self . styleName = styleName <EOL> self . show_delay = show_delay <EOL> self . hide_delay = hide_delay <EOL> self . offsetX = self . DEFAULT_OFFSET_X <EOL> self . offsetY = self . DEFAULT_OFFSET_Y <EOL> def onMouseEnter ( self , sender ) : <EOL> self . hide ( ) <EOL> self . tooltip = Tooltip ( sender , self . offsetX , self . offsetY , self . text , self . show_delay , self . hide_delay , self . styleName ) <EOL> def onMouseLeave ( self , sender ) : <EOL> self . hide ( ) <EOL> def onMouseMove ( self , sender , x , y ) : <EOL> pass <EOL> def onMouseDown ( self , sender , x , y ) : <EOL> pass <EOL> def onMouseUp ( self , sender , x , y ) : <EOL> pass <EOL> def getStyleName ( self ) : <EOL> return self . styleName <EOL> def setStyleName ( self , styleName ) : <EOL> self . styleName = styleName <EOL> def getOffsetX ( self ) : <EOL> return self . offsetX <EOL> def setOffsetX ( self , offsetX ) : <EOL> self . offsetX = offsetX <EOL> def getOffsetY ( self ) : <EOL> return self . offsetY <EOL> def setOffsetY ( self , offsetY ) : <EOL> self . offsetY = offsetY <EOL> def hide ( self ) : <EOL> if self . tooltip is not None : <EOL> self . tooltip . hide ( ) <EOL> Factory . registerClass ( '<STR_LIT>' , '<STR_LIT>' , Tooltip ) </s>
