Sha256: 51c9fe1f772b78da0967a0622fb588cfdc68367946b1a755a593fe638e1fe4dc
Contents?: true
Size: 1.81 KB
Versions: 5
Compression:
Stored size: 1.81 KB
Contents
module Tk # Translation from Tcl: http://wiki.tcl.tk/1954 class Tooltip < Struct.new(:text, :tooltip) def bind_to(widget) widget.bind('<Any-Enter>' ){ Tk::After.ms(500){ show(widget) }} widget.bind('<Any-Leave>' ){ Tk::After.ms(500){ destroy }} widget.bind('<Any-KeyPress>'){ Tk::After.ms(500){ destroy }} widget.bind('<Any-Button>' ){ Tk::After.ms(500){ destroy }} end def destroy tooltip.destroy rescue NoMethodError, RuntimeError => ex end def show_on(widget) root = Tk.root root_pointerx, root_pointery = root.winfo_pointerx, root.winfo_pointery return unless Tk::Winfo.containing(root_pointerx, root_pointery) destroy scrh, scrw = widget.winfo_screenheight, widget.winfo_screenwidth self.tooltip = tooltip = Tk::Toplevel.new(widget, bd: true, bg: 'black') tooltip.wm_geometry = "+#{scrh}+#{scrw}" tooltip.wm_overrideredirect = true tooltip.attributes(topmost: true) if tooltip.tk_windowingsystem == :win32 label = Tk::Label.new(tooltip, bg: :lightyellow, fg: :black, text: text, justify: :left).pack width, height = label.winfo_reqwidth, label.winfo_reqheight position_x, position_y = root_pointerx, root_pointery + 25 root_screen_width = root.winfo_screenwidth if (position_x + width) > root_screen_width position_x -= ((position_x + width) - root_screen_width) end tooltip.wm_geometry = "#{width}x#{height}+#{position_x}+#{position_y}" tooltip.raise tooltip.bind('Any-Enter'){ destroy } tooltip.bind('Any-Leave'){ destroy } end end end if __FILE__ == $0 require 'ffi-tk' button = Tk::Button.new(text: 'hello').pack tooltip = Tk::Tooltip.new('Hello, World!') tooltip.bind_to(button) Tk.mainloop end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
ver-2010.08 | lib/ver/tooltip.rb |
ver-2010.02 | lib/ver/tooltip.rb |
ver-2009.12.14 | lib/ver/tooltip.rb |
ver-2009.11.29 | lib/ver/tooltip.rb |
ver-2009.11.28 | lib/ver/tooltip.rb |