diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-07-01 09:38:48 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-07-01 09:38:48 +0000 |
commit | ffcedd79505ea2e99f859c7cea2fb2221c948d4c (patch) | |
tree | 02232516faf0e1959ecb5d5b7aca25a52f9f87ca /ext/tk/sample/tkextlib/vu/pie.rb | |
parent | 73cf1d02bac2dbdd5d7f673a33d81444a00c865e (diff) | |
download | ruby-ffcedd79505ea2e99f859c7cea2fb2221c948d4c.tar.gz |
* ext/tk/lib/tcltklib : bug fix
* ext/tk/lib/tk : bug fix and add Tcl/Tk extension support libraries
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6559 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample/tkextlib/vu/pie.rb')
-rw-r--r-- | ext/tk/sample/tkextlib/vu/pie.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/ext/tk/sample/tkextlib/vu/pie.rb b/ext/tk/sample/tkextlib/vu/pie.rb new file mode 100644 index 0000000000..a567f840a0 --- /dev/null +++ b/ext/tk/sample/tkextlib/vu/pie.rb @@ -0,0 +1,56 @@ +#!/usr/bin/env ruby + +require 'tk' +require 'tkextlib/vu/pie' + +pie = Tk::Vu::Pie.new(:label=>"My Revolving Budget"){ + itemconfigure('Welfare', :value=>3.004) + itemconfigure('Military', :value=>7.006) + itemconfigure('Transport', :value=>1.6, :explode=>15) + itemconfigure('Parks', :value=>0.9) + itemconfigure('Schools', :value=>2) + itemconfigure('Debt', :value=>4, :explode=>10) + + configure(:angle=>10, :origin=>90, :shadow=>10) +} + +spin = TkTimer.new(60, -1, proc{|obj| + pie.configure(:origin=>pie[:origin] + 1) +}) + +f = TkFrame.new +fast_btn = TkButton.new(f, :text=>"Spin Faster", :command=>proc{spin.start}) +slow_btn = TkButton.new(f, :text=>"Spin Slower", :command=>proc{spin.stop}) +quit_btn = TkButton.new(f, :text=>"Exit", :command=>proc{exit}) + +Tk.grid(pie, :sticky=>:news) +Tk.grid(f, :sticky=>:ew) + +Tk.pack(fast_btn, slow_btn, quit_btn, + :in=>f, :side=>:left, :fill=>:both, :expand=>true, :padx=>6, :pady=>4) + +Tk.root.grid_columnconfigure(0, :weight=>1) +Tk.root.grid_rowconfigure(0, :weight=>1) + +priv = { + :x=>0, :y=>0, :pie_in=>false, :angle=>pie[:angle], :origin=>pie[:origin] +} + +pie.bind('ButtonPress-1', proc{|w, x, y| + priv[:x] = x + priv[:y] = y + priv[:pie_in] = (w.winfo_width/1.8 > x) + priv[:angle] = w[:angle] + priv[:origin] = w[:origin] + }, '%W %x %y') + +pie.bind('B1-Motion', proc{|w, x, y| + if priv[:pie_in] + w.configure(:angle=>priv[:angle] + (priv[:y] - y)/3, + :origin=>(priv[:origin] + + ((w.winfo_height/2.2 > y)? -1: 1) * + (priv[:x] - x)/3) % 360) + end + }, '%W %x %y') + +Tk.mainloop |