~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to ext/tk/sample/tkextlib/vu/dial_demo.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
 
 
3
require 'tk'
 
4
require 'tkextlib/vu/dial'
 
5
 
 
6
#######################################
 
7
 
 
8
v_volume = TkVariable.new
 
9
v_speed  = TkVariable.new
 
10
v_dir    = TkVariable.new
 
11
v_rot    = TkVariable.new
 
12
v_linked = TkVariable.new
 
13
v_needle = TkVariable.new
 
14
 
 
15
volume = Tk::Vu::Dial.new(:label=>"Volume", :from=>-0.1, :to=>0.1, 
 
16
                          :resolution=>0.001, :minortickinterval=>0.01, 
 
17
                          :tickinterval=>0.1, :beginangle=>-20, 
 
18
                          :endangle=>260, :variable=>v_volume)
 
19
 
 
20
speed = Tk::Vu::Dial.new(:label=>"Speed", :from=>2000, :to=>100, 
 
21
                         :resolution=>10, :tickinterval=>100, 
 
22
                         :minortickinterval=>0, :variable=>v_speed, 
 
23
                         :showtags=>:label, :showvalue=>false)
 
24
 
 
25
speed.set_tag_constrain(100, 'Fast', 2000, 'Slow')
 
26
 
 
27
fwd  = Tk::Vu::Dial.new(:from=>-10.0, :to=>-20.0, :resolution=>0.1, 
 
28
                        :tickinterval=>5.0, :minortickinterval=>1.0, 
 
29
                        :variable=>v_dir)
 
30
 
 
31
rev  = Tk::Vu::Dial.new(:from=>-20.0, :to=>-10.0, :resolution=>0.1, 
 
32
                        :tickinterval=>5.0, :minortickinterval=>1.0, 
 
33
                        :variable=>v_dir)
 
34
 
 
35
small = Tk::Vu::Dial.new(:font=>"Helvetica -10", :from=>0, :to=>10, 
 
36
                         :resolution=>0.05, :tickinterval=>2,
 
37
                         :minortickinterval=>0.5, :radius=>20, 
 
38
                         :dialcolor=>'red2', :activebackground=>'red', 
 
39
                         :variable=>v_rot)
 
40
 
 
41
large = Tk::Vu::Dial.new(:font=>"Helvetica -8", :from=>0, :to=>10, 
 
42
                         :resolution=>0.05, :tickinterval=>1,
 
43
                         :minortickinterval=>0.25, :radius=>40, 
 
44
                         :dialcolor=>'red2', :activebackground=>'red', 
 
45
                         :variable=>v_rot)
 
46
 
 
47
turn = Tk::Vu::Dial.new(:needlecolor=>'red', :label=>"Linked", 
 
48
                        :variable=>v_linked)
 
49
 
 
50
scale = TkScale.new(:label=>"Linked", :variable=>v_linked)
 
51
 
 
52
d1 = Tk::Vu::Dial.new(:resolution=>0.0001, :from=>-0.1, :to=>0.1, 
 
53
                      :showvalue=>true, :minortickinterval=>0.01, 
 
54
                      :tickinterval=>0.1, :radius=>30, :label=>"Dial", 
 
55
                      :beginangle=>-20, :endangle=>260, :variable=>v_needle, 
 
56
                      :relief=>:raised)
 
57
 
 
58
d2 = Tk::Vu::Dial.new(:resolution=>0.01, :from=>-0.1, :to=>0.1, 
 
59
                      :showvalue=>true, :minortickinterval=>0.01, 
 
60
                      :tickinterval=>0.1, :radius=>30, :label=>"Dial 2", 
 
61
                      :beginangle=>-20, :endangle=>260, :variable=>v_needle, 
 
62
                      :dialrelief=>:flat, :needlecolor=>'red', 
 
63
                      :needletype=>:triangle, :relief=>:sunken)
 
64
 
 
65
d3 = Tk::Vu::Dial.new(:resolution=>0.001, :from=>-0.1, :to=>0.1, 
 
66
                      :showvalue=>true, :minortickinterval=>0.01, 
 
67
                      :tickinterval=>0.1, :radius=>30, :label=>"Dial 3", 
 
68
                      :beginangle=>-20, :endangle=>260, :variable=>v_needle, 
 
69
                      :dialrelief=>:flat, :needlecolor=>'blue', 
 
70
                      :needletype=>:arc, :relief=>:ridge)
 
71
 
 
72
f_btns = TkFrame.new
 
73
f_sep  = TkFrame.new(:height=>2, :relief=>:sunken, :bd=>1)
 
74
 
 
75
 
 
76
v_volume.value = -0.1
 
77
v_speed.value = 500
 
78
 
 
79
update = TkTimer.new(proc{v_speed.numeric}, -1, proc{
 
80
                       if v_volume == volume[:to]
 
81
                         v_volume.numeric = volume[:from]
 
82
                       else
 
83
                         v_volume.numeric += volume[:resolution]
 
84
                       end
 
85
                     })
 
86
 
 
87
b_start = TkButton.new(:text=>"Start", :command=>proc{update.start})
 
88
b_stop  = TkButton.new(:text=>"Stop",  :command=>proc{update.stop})
 
89
b_exit  = TkButton.new(:text=>"Exit",  :command=>proc{exit})
 
90
 
 
91
Tk.grid(b_start, :in=>f_btns, :sticky=>:ew, :padx=>4, :pady=>4)
 
92
Tk.grid(b_stop,  :in=>f_btns, :sticky=>:ew, :padx=>4, :pady=>4)
 
93
f_btns.grid_columnconfigure(0, :weight=>1)
 
94
 
 
95
Tk.grid(f_btns, speed, volume, :sticky=>:news)
 
96
Tk.grid(f_sep,  '-',   '-',    :sticky=>:news)
 
97
Tk.grid(fwd,    rev,   d1,     :sticky=>:news)
 
98
Tk.grid(small,  large, d2,     :sticky=>:news)
 
99
Tk.grid(turn,   scale, d3,     :sticky=>:news)
 
100
 
 
101
Tk.grid(b_exit, '-',   '-',    :sticky=>:ew, :padx=>4, :pady=>4)
 
102
 
 
103
Tk.root.grid_columnconfigure(0, :weight=>1)
 
104
Tk.root.grid_columnconfigure(1, :weight=>1)
 
105
Tk.root.grid_columnconfigure(2, :weight=>1)
 
106
 
 
107
Tk.root.grid_rowconfigure(0, :weight=>1)
 
108
Tk.root.grid_rowconfigure(2, :weight=>1)
 
109
Tk.root.grid_rowconfigure(3, :weight=>1)
 
110
Tk.root.grid_rowconfigure(4, :weight=>1)
 
111
 
 
112
 
 
113
Tk.mainloop