Home | Trees | Indices | Help |
|
---|
|
1 # Tooltip component for Pyjamas 2 # Ported by Willie Gollino from Tooltip component for GWT - Originally by Alexei Sokolov http://gwt.components.googlepages.com/ 3 # Copyright (C) 2009 Luke Kenneth Casson Leighton <lkcl@lkcl.net> 4 5 from pyjamas.ui.PopupPanel import PopupPanel 6 from pyjamas import Factory 7 from pyjamas.ui.HTML import HTML 8 from pyjamas.ui.RootPanel import RootPanel 9 from pyjamas.Timer import Timer 10 from pyjamas import Window 11 from pyjamas import DOM 12 13 tooltip_hide_timer = None 1477 7816 - def __init__(self, sender, offsetX, offsetY, contents, 17 show_delay, hide_delay, styleName, **kwargs):18 """ contents may be a text string or it may be a widget 19 """ 20 PopupPanel.__init__(self, True, **kwargs) 21 self.show_delay = show_delay 22 self.hide_delay = hide_delay 23 24 if isinstance(contents, basestring): 25 contents = HTML(contents) 26 self.add(contents) 27 28 left = sender.getAbsoluteLeft() + offsetX 29 top = sender.getAbsoluteTop() + offsetY 30 31 self.setPopupPosition(left, top) 32 self.setStyleName(styleName) 33 34 if tooltip_hide_timer: 35 self.tooltip_show_timer = Timer(1, self) 36 else: 37 self.tooltip_show_timer = Timer(self.show_delay, self)3840 width = self.getOffsetWidth() 41 heigth = self.getOffsetHeight() 42 w_width = Window.getClientWidth() 43 w_heigth = Window.getClientHeight() 44 if w_width > width and w_heigth > heigth: 45 offset_x = self.getAbsoluteLeft() 46 offset_y = self.getAbsoluteTop() 47 element = self.getElement() 48 if (offset_x + width) > w_width: 49 offset_x = w_width - width 50 DOM.setStyleAttribute(element, "left", "%dpx" % offset_x) 51 if (offset_y + heigth) > w_heigth: 52 offset_y = w_heigth - heigth 53 DOM.setStyleAttribute(element, "top", "%dpx" % offset_y)5456 global tooltip_hide_timer 57 58 # activate fast tooltips 59 tooltip_hide_timer = Timer(self.hide_delay, self) 60 PopupPanel.show(self)61 6567 global tooltip_hide_timer 68 69 # deactivate fast tooltips on last timer 70 if timer is tooltip_hide_timer: 71 tooltip_hide_timer = None 72 73 if timer is self.tooltip_show_timer: 74 self.show() 75 else: 76 self.hide()80 DEFAULT_TOOLTIP_STYLE = "TooltipPopup" 81 DEFAULT_OFFSET_X = 10 82 DEFAULT_OFFSET_Y = 35 83133 134 Factory.registerClass('pyjamas.ui.Tooltip', 'Tooltip', Tooltip) 13585 if not styleName: 86 styleName = self.DEFAULT_TOOLTIP_STYLE 87 88 self.tooltip = None 89 self.text = text 90 self.styleName = styleName 91 self.show_delay = show_delay 92 self.hide_delay = hide_delay 93 self.offsetX = self.DEFAULT_OFFSET_X 94 self.offsetY = self.DEFAULT_OFFSET_Y9597 self.hide() 98 self.tooltip = Tooltip(sender, self.offsetX, self.offsetY, self.text, self.show_delay, self.hide_delay, self.styleName)99101 self.hide()102 105 108 111 114 117 120 123 126 129
Home | Trees | Indices | Help |
|
---|
http://epydoc.sourceforge.net |