Class: TkBalloonHelp

Inherits:
TkLabel
  • Object
show all
Defined in:
sample/tkballoonhelp.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, keys = {}) ⇒ TkBalloonHelp

Returns a new instance of TkBalloonHelp.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'sample/tkballoonhelp.rb', line 36

def initialize(parent=nil, keys={})
  @parent = parent || Tk.root

  @frame = TkToplevel.new(@parent)
  @frame.withdraw
  @frame.overrideredirect(true)
  @frame.transient(TkWinfo.toplevel(@parent))
  @epath = @frame.path

  if keys
    keys = _symbolkey2str(keys)
  else
    keys = {}
  end

  @command = keys.delete('command')

  @interval = keys.delete('interval'){1000}
  _balloon_binding(@interval)

  @label = TkLabel.new(@frame, 'background'=>'bisque').pack
  @label.configure(_symbolkey2str(keys)) unless keys.empty?
  @path = @label
end

Class Method Details

.interval(val) ⇒ Object



17
18
19
# File 'sample/tkballoonhelp.rb', line 17

def @timer.interval(val)
  @sleep_time = val
end

Instance Method Details

#command(cmd = Proc.new) ⇒ Object



73
74
75
76
# File 'sample/tkballoonhelp.rb', line 73

def command(cmd = Proc.new)
  @command = cmd
  self
end

#destroyObject



110
111
112
# File 'sample/tkballoonhelp.rb', line 110

def destroy
  @frame.destroy
end

#epathObject



61
62
63
# File 'sample/tkballoonhelp.rb', line 61

def epath
  @epath
end

#eraseObject



105
106
107
108
# File 'sample/tkballoonhelp.rb', line 105

def erase
  @parent.cursor(@org_cursor) 
  @frame.withdraw
end

#interval(val) ⇒ Object



65
66
67
68
69
70
71
# File 'sample/tkballoonhelp.rb', line 65

def interval(val)
  if val
    @timer.interval(val)
  else
    @interval
  end
end

#showObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'sample/tkballoonhelp.rb', line 78

def show
  x = TkWinfo.pointerx(@parent)
  y = TkWinfo.pointery(@parent)
  @frame.geometry("+#{x+1}+#{y+1}")

  if @command
    case @command.arity
    when 0
      @command.call
    when 2
      @command.call(x - TkWinfo.rootx(@parent), y - TkWinfo.rooty(@parent))
    when 3
      @command.call(x - TkWinfo.rootx(@parent), y - TkWinfo.rooty(@parent), 
                    self)
    else
      @command.call(x - TkWinfo.rootx(@parent), y - TkWinfo.rooty(@parent), 
                    self, @parent)
    end
  end

  @frame.deiconify
  @frame.raise

  @org_cursor = @parent['cursor']
  @parent.cursor('crosshair') 
end