1#!/usr/bin/env ruby 2 3require 'tk' 4require 'tkextlib/vu/pie' 5 6pie = Tk::Vu::Pie.new(:label=>"My Revolving Budget"){ 7 itemconfigure('Welfare', :value=>3.004) 8 itemconfigure('Military', :value=>7.006) 9 itemconfigure('Transport', :value=>1.6, :explode=>15) 10 itemconfigure('Parks', :value=>0.9) 11 itemconfigure('Schools', :value=>2) 12 itemconfigure('Debt', :value=>4, :explode=>10) 13 14 configure(:angle=>10, :origin=>90, :shadow=>10) 15} 16 17spin = TkTimer.new(60, -1, proc{|obj| 18 pie.configure(:origin=>pie[:origin] + 1) 19}) 20 21f = TkFrame.new 22fast_btn = TkButton.new(f, :text=>"Spin Faster", :command=>proc{spin.start}) 23slow_btn = TkButton.new(f, :text=>"Spin Slower", :command=>proc{spin.stop}) 24quit_btn = TkButton.new(f, :text=>"Exit", :command=>proc{exit}) 25 26Tk.grid(pie, :sticky=>:news) 27Tk.grid(f, :sticky=>:ew) 28 29Tk.pack(fast_btn, slow_btn, quit_btn, 30 :in=>f, :side=>:left, :fill=>:both, :expand=>true, :padx=>6, :pady=>4) 31 32Tk.root.grid_columnconfigure(0, :weight=>1) 33Tk.root.grid_rowconfigure(0, :weight=>1) 34 35priv = { 36 :x=>0, :y=>0, :pie_in=>false, :angle=>pie[:angle], :origin=>pie[:origin] 37} 38 39pie.bind('ButtonPress-1', proc{|w, x, y| 40 priv[:x] = x 41 priv[:y] = y 42 priv[:pie_in] = (w.winfo_width/1.8 > x) 43 priv[:angle] = w[:angle] 44 priv[:origin] = w[:origin] 45 }, '%W %x %y') 46 47pie.bind('B1-Motion', proc{|w, x, y| 48 if priv[:pie_in] 49 w.configure(:angle=>priv[:angle] + (priv[:y] - y)/3, 50 :origin=>(priv[:origin] + 51 ((w.winfo_height/2.2 > y)? -1: 1) * 52 (priv[:x] - x)/3) % 360) 53 end 54 }, '%W %x %y') 55 56Tk.mainloop 57