From 5df75faf3f8e14516235d6f4e912a97a2f082948 Mon Sep 17 00:00:00 2001 From: nagai Date: Thu, 12 Jan 2006 02:56:11 +0000 Subject: * ext/tk/sample/tkballoonhelp.rb: [bug fix] couldn't add to a widget which is constructed with TkComposite module. [new feature] support 'command' option which is called just before popping up the balloon help. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@9825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/sample/tkballoonhelp.rb | 99 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-) (limited to 'ext/tk') diff --git a/ext/tk/sample/tkballoonhelp.rb b/ext/tk/sample/tkballoonhelp.rb index d66bc35a8..c2c95f771 100644 --- a/ext/tk/sample/tkballoonhelp.rb +++ b/ext/tk/sample/tkballoonhelp.rb @@ -24,13 +24,17 @@ class TkBalloonHelp200, 'font'=>'courier', 'background'=>'gray', 'foreground'=>'red') } + + sb = TkScrollbox.new.pack(:fill=>:x) + sb.insert(:end, *%w(aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm)) +=begin + # CASE1 : command takes no arguemnt + bh = TkBalloonHelp.new(sb, :interval=>500, + :relief=>:ridge, :background=>'white', + :command=>proc{ + y = TkWinfo.pointery(sb) - TkWinfo.rooty(sb) + bh.text "current index == #{sb.nearest(y)}" + }) +=end +=begin + # CASE2 : command takes 2 arguemnts + bh = TkBalloonHelp.new(sb, :interval=>500, + :relief=>:ridge, :background=>'white', + :command=>proc{|x, y| + bh.text "current index == #{sb.nearest(y)}" + }) +=end +=begin + # CASE3 : command takes 3 arguemnts + TkBalloonHelp.new(sb, :interval=>500, + :relief=>:ridge, :background=>'white', + :command=>proc{|x, y, bhelp| + bhelp.text "current index == #{sb.nearest(y)}" + }) +=end +=begin + # CASE4a : command is a Proc object and takes 4 arguemnts + cmd = proc{|x, y, bhelp, parent| + bhelp.text "current index == #{parent.nearest(y)}" + } + + TkBalloonHelp.new(sb, :interval=>500, + :relief=>:ridge, :background=>'white', + :command=>cmd) + + sb2 = TkScrollbox.new.pack(:fill=>:x) + sb2.insert(:end, *%w(AAA BBB CCC DDD EEE FFF GGG HHH III JJJ KKK LLL MMM)) + TkBalloonHelp.new(sb2, :interval=>500, + :padx=>5, :relief=>:raised, + :background=>'gray25', :foreground=>'white', + :command=>cmd) +=end +#=begin + # CASE4b : command is a Method object and takes 4 arguemnts + def set_msg(x, y, bhelp, parent) + bhelp.text "current index == #{parent.nearest(y)}" + end + cmd = self.method(:set_msg) + + TkBalloonHelp.new(sb, :interval=>500, + :relief=>:ridge, :background=>'white', + :command=>cmd) + + sb2 = TkScrollbox.new.pack(:fill=>:x) + sb2.insert(:end, *%w(AAA BBB CCC DDD EEE FFF GGG HHH III JJJ KKK LLL MMM)) + TkBalloonHelp.new(sb2, :interval=>500, + :padx=>5, :relief=>:raised, + :background=>'gray25', :foreground=>'white', + :command=>cmd) +#=end + Tk.mainloop end -- cgit