Class: Tk::Tooltip
- Inherits:
-
Struct
- Object
- Struct
- Tk::Tooltip
- Defined in:
- lib/ver/tooltip.rb
Overview
Translation from Tcl: wiki.tcl.tk/1954
Instance Attribute Summary collapse
-
#text ⇒ Object
Returns the value of attribute text.
-
#tooltip ⇒ Object
Returns the value of attribute tooltip.
Instance Method Summary collapse
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text
3 4 5 |
# File 'lib/ver/tooltip.rb', line 3 def text @text end |
#tooltip ⇒ Object
Returns the value of attribute tooltip
3 4 5 |
# File 'lib/ver/tooltip.rb', line 3 def tooltip @tooltip end |
Instance Method Details
#bind_to(widget) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/ver/tooltip.rb', line 4 def bind_to() .bind('<Any-Enter>' ){ Tk::After.ms(500){ show() }} .bind('<Any-Leave>' ){ Tk::After.ms(500){ destroy }} .bind('<Any-KeyPress>'){ Tk::After.ms(500){ destroy }} .bind('<Any-Button>' ){ Tk::After.ms(500){ destroy }} end |
#destroy ⇒ Object
11 12 13 14 |
# File 'lib/ver/tooltip.rb', line 11 def destroy tooltip.destroy rescue NoMethodError, RuntimeError => ex end |
#show_on(widget) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ver/tooltip.rb', line 16 def show_on() 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 = .winfo_screenheight, .winfo_screenwidth self.tooltip = tooltip = Tk::Toplevel.new(, 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 |