Class: Tk::RbWidget::BalloonHelp

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

Constant Summary collapse

DEFAULT_FOREGROUND =
'black'
DEFAULT_BACKGROUND =
'white'
DEFAULT_INTERVAL =
750

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of BalloonHelp.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'sample/tkballoonhelp.rb', line 46

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'){DEFAULT_INTERVAL}
  _balloon_binding(@interval)

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

Class Method Details

.interval(val) ⇒ Object



27
28
29
# File 'sample/tkballoonhelp.rb', line 27

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

Instance Method Details

#command(cmd = Proc.new) ⇒ Object



86
87
88
89
# File 'sample/tkballoonhelp.rb', line 86

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

#destroyObject



135
136
137
# File 'sample/tkballoonhelp.rb', line 135

def destroy
  @frame.destroy
end

#epathObject



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

def epath
  @epath
end

#eraseObject



126
127
128
129
130
131
132
133
# File 'sample/tkballoonhelp.rb', line 126

def erase
  begin
    @parent.configure('cursor', @org_cursor)
  rescue
    @parent.cursor(@org_cursor)
  end
  @frame.withdraw
end

#interval(val) ⇒ Object



78
79
80
81
82
83
84
# File 'sample/tkballoonhelp.rb', line 78

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

#showObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'sample/tkballoonhelp.rb', line 91

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

  begin
    @org_cursor = @parent.cget('cursor')
  rescue
    @org_cursor = @parent['cursor']
  end
  begin
    @parent.configure('cursor', 'crosshair')
  rescue
    @parent.cursor('crosshair')
  end
end