diff options
author | (no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-07-01 09:38:53 +0000 |
---|---|---|
committer | (no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-07-01 09:38:53 +0000 |
commit | 867524eff51c1679f63b9c61fdacc44f8cb85d11 (patch) | |
tree | b8fcdf67f2058b43c0a7cf704bcd7e0a782eff7c /ext/tk/sample/tkextlib/vu | |
parent | 3c4ad5062d65fbe491dfc1df680a540feacadcda (diff) | |
download | ruby-867524eff51c1679f63b9c61fdacc44f8cb85d11.tar.gz ruby-867524eff51c1679f63b9c61fdacc44f8cb85d11.tar.xz ruby-867524eff51c1679f63b9c61fdacc44f8cb85d11.zip |
This commit was manufactured by cvs2svn to create branch 'ruby_1_8'.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@6560 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample/tkextlib/vu')
-rw-r--r-- | ext/tk/sample/tkextlib/vu/README.txt | 50 | ||||
-rw-r--r-- | ext/tk/sample/tkextlib/vu/canvItems.rb | 90 | ||||
-rw-r--r-- | ext/tk/sample/tkextlib/vu/canvSticker.rb | 82 | ||||
-rw-r--r-- | ext/tk/sample/tkextlib/vu/canvSticker2.rb | 99 | ||||
-rw-r--r-- | ext/tk/sample/tkextlib/vu/dial.rb | 113 | ||||
-rw-r--r-- | ext/tk/sample/tkextlib/vu/m128_000.xbm | 174 | ||||
-rw-r--r-- | ext/tk/sample/tkextlib/vu/oscilloscope.rb | 68 | ||||
-rw-r--r-- | ext/tk/sample/tkextlib/vu/pie.rb | 56 | ||||
-rw-r--r-- | ext/tk/sample/tkextlib/vu/vu.rb | 67 |
9 files changed, 799 insertions, 0 deletions
diff --git a/ext/tk/sample/tkextlib/vu/README.txt b/ext/tk/sample/tkextlib/vu/README.txt new file mode 100644 index 000000000..ce5f371fa --- /dev/null +++ b/ext/tk/sample/tkextlib/vu/README.txt @@ -0,0 +1,50 @@ + + >>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + >>> The following text is the original 'README.txt' of <<< + >>> vu extension demos. <<< + >>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +## +## DESCRIPTION OF DEMOS +## + +canvItems.tcl + old demo of all canvas chart items, useful to find memory leaks. + <1> prints out the additional memory usage (charts.so + script) + +canvSticker.tcl + Heribert Dahms original "demo.tcl" + <p> creates DEMO.ps + +canvSticker2.tcl + compares "sticker" and "text"; press <1>, <2> or <1> ... + <p> creates DEMO.ps + +dial.tcl + demo of variations of the dial widget. + +load.tcl + Just a utility file, not a real demo. + +m128_000.xbm + XBM pic used by sticker and canvItems demos + +oscilloscope.tcl + the heart of a Realtime Oscilloscope,where the PC´s joystick + port gives 4 digtal inputs and 4 analog 8 bit values with an + resolution of ~1 millisecond (!!!) running Realtime Linux. + <p> creates DEMO.ps + +pie.tcl + The magic 3D spinning pie chart! + +vu.tcl + demo fo Vu widgets + +canvLabel.tcl + 'label' is a canvas item just like 'text', but with -angle + rotation of the string. This is not built in by default, as + it requires the internal Tk headers. + press <1>, <2> or <1> ... + <p> creates DEMO.ps + diff --git a/ext/tk/sample/tkextlib/vu/canvItems.rb b/ext/tk/sample/tkextlib/vu/canvItems.rb new file mode 100644 index 000000000..c3e563058 --- /dev/null +++ b/ext/tk/sample/tkextlib/vu/canvItems.rb @@ -0,0 +1,90 @@ +#!/usr/bin/env ruby + +require 'tk' +require 'tkextlib/vu/charts' + +####################################### + +xbm = File.join(File.dirname(File.expand_path(__FILE__)), 'm128_000.xbm') + +sval = [ 11, 22, 33, 44, 55, 66, 77, 88, 99 ] + +l0 = TkLabel.new(:width=>128, :height=>128, + :bitmap=>"@#{xbm}", :relief=>:groove).pack(:side=>:left) + +c0 = TkCanvas.new(:width=>80, :height=>80, + :insertwidth=>0, :highlightthickness=>0, + :selectborderwidth=>0, :borderwidth=>2, + :relief=>:ridge).place(:in=>l0, :relx=>0.5, :rely=>0.5, + :anchor=>:c) + +st = Tk::Vu::TkcStripchart.new(c0, 3, 3, 80, 80, + :background=>"#b7c0d7", :fill=>'slategray3', + :jumpscroll=>1, :outline=>'black', + :scaleline=>'blue', :stripline=>'red', + :selected=>1, :values=>sval) + +TkcText.create(c0, 40, 40, + :text=>Tk::TCL_PATCHLEVEL, :fill=>'cyan', :tags=>'text') + + +l1 = TkLabel.new(:width=>128, :height=>128, + :bitmap=>"@#{xbm}", :relief=>:groove).pack(:side=>:left) + +c1 = TkCanvas.new(:width=>80, :height=>80, + :insertwidth=>0, :highlightthickness=>0, + :selectborderwidth=>0, :borderwidth=>2, + :relief=>:ridge).place(:in=>l1, :relx=>0.5, :rely=>0.5, + :anchor=>:c) + +bar1 = Tk::Vu::TkcBarchart.new(c1, 3, 3, 80, 80, + :background=>"#b7c0d7", :scalevalue=>10.0, + :autocolor=>true, :selected=>1, + :outline=>'black', :barline=>'yellow', + :scalelinestyle=>0) + +bar2 = Tk::Vu::TkcBarchart.new(c1, 53, 3, 80, 80, + :background=>"#b7c0d7", :scalevalue=>10.0, + :autocolor=>true, :selected=>1, + :outline=>'black', :fill=>"#b7c0d7", + :barline=>'red', :scalelinestyle=>22) + + +l2 = TkLabel.new(:width=>128, :height=>128, + :bitmap=>"@#{xbm}", :relief=>:groove).pack(:side=>:left) + +c2 = TkCanvas.new(:width=>80, :height=>80, + :insertwidth=>0, :highlightthickness=>0, + :selectborderwidth=>0, :borderwidth=>2, + :relief=>:ridge).place(:in=>l2, :relx=>0.5, :rely=>0.5, + :anchor=>:c) + +begin + stick = Tk::Vu::TkcSticker.new(c2, 3, 3, 80, 80, + :text=>"Tcl/Tk", :space=>0, :color=>'red', + :outline=>'red', :font=>'Helvetica 14 bold', + :fill=>'', :stipple=>'', :bar=>'blue', + :orient=>:vertical, :anchor=>:s, + :relheight=>1.0, :relwidth=>0.15, + :relx=>0.1, :rely=>0.0) +rescue + stick = nil + TkcText.new(c2, 40, 10, :text=>"No Sticker Item") +end + +c_do = proc{ + st[:values] = rand() * 100 + + bar1[:values] = rand() * 10 + bar2[:values] = rand() * 10 + + stick[:rely] = rand() * 100 * 0.01 if stick +} + +c0.bind('1', c_do) + +TkTimer.new(100, -1, c_do).start + +Tk.root.bind('q', proc{exit}) + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/vu/canvSticker.rb b/ext/tk/sample/tkextlib/vu/canvSticker.rb new file mode 100644 index 000000000..431ca56fd --- /dev/null +++ b/ext/tk/sample/tkextlib/vu/canvSticker.rb @@ -0,0 +1,82 @@ +#!/usr/bin/env ruby + +require 'tk' +require 'tkextlib/vu/charts' + +####################################### + +Tk.root.geometry('+30+30') + +delay = 2000 + +c = TkCanvas.new.pack + +begin + st = Tk::Vu::TkcSticker.new(c, 0, 0, 10, 10) +rescue + Tk.messageBox(:type=>'ok', :title=>"No sticker Item", + :message=>"This build of vu does not include the sticker item") + exit +end +#st.delete + +steps = [] + +steps << proc{ + # I used a 75dpi screen for testing, but others should make no difference! + puts 'You\'ll see a small upright rectangle with "He" inside.' + st = Tk::Vu::TkcSticker.new(c, '6m', '10m', '13m', '27m', :text=>'Hello') +} + +steps << proc{ + puts 'You\'ll see the whole "Hello" drawn rotated 90 degrees.' + st[:orient] = :vertical +} + +steps << proc{ + puts 'The rectangle shrinks and the text is clipped to "Hell"' + #st.coords('6m', '10m', '13m', '20m') + st.coords('6m', '10m', '13m', '17m') +} + +steps << proc{ + puts 'Now you\'ll read "ello"' + st[:lefttrunc] = true +} + +steps << proc{ + puts 'Enlarging the rectangle shows the complete "Hello" again' + st.scale(0, 0, 3, 3) +} + +steps << proc{ + puts 'This time the text is repeated: "Hello", approx. 5mm space, "Hello"' + st[:space] = '5m' +} + +steps << proc{ + puts 'A vertical bar appears in the lower right region and text jumps to the left.' + st.configure(:anchor=>:n, :relw=>0.3, :relh=>0.7, + :relx=>0.6, :rely=>0.3, :bar=>'red') +} + +steps << proc{ + puts 'Paint the backgound.' + st[:fill] = 'yellow' +} + +steps << proc{ + puts "Let's test stippling." + st[:stipple] = 'gray25' +} + +steps << proc{ + puts 'Finally a large outline forces a single "Hello" and shrinks the bar.' + st[:width] = '6m' +} + +Tk.root.bind('q', proc{exit}) + +TkTimer.new(delay, 1, *steps).start + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/vu/canvSticker2.rb b/ext/tk/sample/tkextlib/vu/canvSticker2.rb new file mode 100644 index 000000000..1e6b59a18 --- /dev/null +++ b/ext/tk/sample/tkextlib/vu/canvSticker2.rb @@ -0,0 +1,99 @@ +#!/usr/bin/env ruby + +require 'tk' +require 'tkextlib/vu/charts' + +####################################### + +c = TkCanvas.new.pack + +begin + st = Tk::Vu::TkcSticker.new(c, 0, 0, 10, 10) +rescue + Tk.messageBox(:type=>'ok', :title=>"No sticker Item", + :message=>"This build of vu does not include the sticker item") + exit +end + +c.destroy + +#--- +#--- set STRING {{x0 y0 x1 y1} {...text...} {resize point: center} + +#sti_conf = [ [10, 10, 180, 180], "Sticker äöüß@²³¼½¾", :center ] +#txt_conf = [ [210, 210], "Text äöüß@²³¼½¾", :center ] +sti_conf = [ [10, 10, 350, 350], + Tk::UTF8_String("Sticker äöüß@²³¼½¾"), :center ] +txt_conf = [ [250, 250], + Tk::UTF8_String("Text äöüß@²³¼½¾"), :center ] + +p sti_conf + +fnt = TkFont.new('Helvetica 24 bold') + +#---GUI +c = TkCanvas.new(:width=>500, :height=>500, :bg=>'aquamarine3').pack + +#---CRRW Use the technique of eval the coord ... +sti = Tk::Vu::TkcSticker.new(c, sti_conf[0]){ + anchor sti_conf[2] + bar 'black' + color 'red' + fill '' + font fnt + lefttrunc 0 + outline '' + relheight 0.0 + relwidth 0.0 + relx 0.0 + rely 0.0 + space 0 + stipple '' + tags 'sti' + text sti_conf[1] + width 0 + orient :vertical + minwidth 0 + minheight 0 + maxwidth 32767 + maxheight 32767 +} + +txt = TkcText.new(c, txt_conf[0]){ + activefill '' + activestipple '' + anchor txt_conf[2] + disabledfill '' + disabledstipple '' + fill 'blue' + font fnt + justify :left + offset '0,0' + state '' + stipple '' + tags ['tex'] + text txt_conf[1] + width 0 +} + +#---BINDINGS +c.bind('2', proc{ + sti[:orient] = :horizontal + txt[:width] = 0 # horizontal + }) + +c.bind('3', proc{ + sti[:orient] = :vertical + txt[:width] = 1 # top down + }) + +Tk.root.bind('p', proc{ + c.postscript(:file=>'DEMO.ps') + puts "DEMO.ps printed" + }) + +Tk.root.bind('q', proc{exit}) + +##################### + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/vu/dial.rb b/ext/tk/sample/tkextlib/vu/dial.rb new file mode 100644 index 000000000..d2ae0990c --- /dev/null +++ b/ext/tk/sample/tkextlib/vu/dial.rb @@ -0,0 +1,113 @@ +#!/usr/bin/env ruby + +require 'tk' +require 'tkextlib/vu/dial' + +####################################### + +v_volume = TkVariable.new +v_speed = TkVariable.new +v_dir = TkVariable.new +v_rot = TkVariable.new +v_linked = TkVariable.new +v_needle = TkVariable.new + +volume = Tk::Vu::Dial.new(:label=>"Volume", :from=>-0.1, :to=>0.1, + :resolution=>0.001, :minortickinterval=>0.01, + :tickinterval=>0.1, :beginangle=>-20, + :endangle=>260, :variable=>v_volume) + +speed = Tk::Vu::Dial.new(:label=>"Speed", :from=>2000, :to=>100, + :resolution=>10, :tickinterval=>100, + :minortickinterval=>0, :variable=>v_speed, + :showtags=>:label, :showvalue=>false) + +speed.set_tag_constrain(100, 'Fast', 2000, 'Slow') + +fwd = Tk::Vu::Dial.new(:from=>-10.0, :to=>-20.0, :resolution=>0.1, + :tickinterval=>5.0, :minortickinterval=>1.0, + :variable=>v_dir) + +rev = Tk::Vu::Dial.new(:from=>-20.0, :to=>-10.0, :resolution=>0.1, + :tickinterval=>5.0, :minortickinterval=>1.0, + :variable=>v_dir) + +small = Tk::Vu::Dial.new(:font=>"Helvetica -10", :from=>0, :to=>10, + :resolution=>0.05, :tickinterval=>2, + :minortickinterval=>0.5, :radius=>20, + :dialcolor=>'red2', :activebackground=>'red', + :variable=>v_rot) + +large = Tk::Vu::Dial.new(:font=>"Helvetica -8", :from=>0, :to=>10, + :resolution=>0.05, :tickinterval=>1, + :minortickinterval=>0.25, :radius=>40, + :dialcolor=>'red2', :activebackground=>'red', + :variable=>v_rot) + +turn = Tk::Vu::Dial.new(:needlecolor=>'red', :label=>"Linked", + :variable=>v_linked) + +scale = TkScale.new(:label=>"Linked", :variable=>v_linked) + +d1 = Tk::Vu::Dial.new(:resolution=>0.0001, :from=>-0.1, :to=>0.1, + :showvalue=>true, :minortickinterval=>0.01, + :tickinterval=>0.1, :radius=>30, :label=>"Dial", + :beginangle=>-20, :endangle=>260, :variable=>v_needle, + :relief=>:raised) + +d2 = Tk::Vu::Dial.new(:resolution=>0.01, :from=>-0.1, :to=>0.1, + :showvalue=>true, :minortickinterval=>0.01, + :tickinterval=>0.1, :radius=>30, :label=>"Dial 2", + :beginangle=>-20, :endangle=>260, :variable=>v_needle, + :dialrelief=>:flat, :needlecolor=>'red', + :needletype=>:triangle, :relief=>:sunken) + +d3 = Tk::Vu::Dial.new(:resolution=>0.001, :from=>-0.1, :to=>0.1, + :showvalue=>true, :minortickinterval=>0.01, + :tickinterval=>0.1, :radius=>30, :label=>"Dial 3", + :beginangle=>-20, :endangle=>260, :variable=>v_needle, + :dialrelief=>:flat, :needlecolor=>'blue', + :needletype=>:arc, :relief=>:ridge) + +f_btns = TkFrame.new +f_sep = TkFrame.new(:height=>2, :relief=>:sunken, :bd=>1) + + +v_volume.value = -0.1 +v_speed.value = 500 + +update = TkTimer.new(proc{v_speed.numeric}, -1, proc{ + if v_volume == volume[:to] + v_volume.numeric = volume[:from] + else + v_volume.numeric += volume[:resolution] + end + }) + +b_start = TkButton.new(:text=>"Start", :command=>proc{update.start}) +b_stop = TkButton.new(:text=>"Stop", :command=>proc{update.stop}) +b_exit = TkButton.new(:text=>"Exit", :command=>proc{exit}) + +Tk.grid(b_start, :in=>f_btns, :sticky=>:ew, :padx=>4, :pady=>4) +Tk.grid(b_stop, :in=>f_btns, :sticky=>:ew, :padx=>4, :pady=>4) +f_btns.grid_columnconfigure(0, :weight=>1) + +Tk.grid(f_btns, speed, volume, :sticky=>:news) +Tk.grid(f_sep, '-', '-', :sticky=>:news) +Tk.grid(fwd, rev, d1, :sticky=>:news) +Tk.grid(small, large, d2, :sticky=>:news) +Tk.grid(turn, scale, d3, :sticky=>:news) + +Tk.grid(b_exit, '-', '-', :sticky=>:ew, :padx=>4, :pady=>4) + +Tk.root.grid_columnconfigure(0, :weight=>1) +Tk.root.grid_columnconfigure(1, :weight=>1) +Tk.root.grid_columnconfigure(2, :weight=>1) + +Tk.root.grid_rowconfigure(0, :weight=>1) +Tk.root.grid_rowconfigure(2, :weight=>1) +Tk.root.grid_rowconfigure(3, :weight=>1) +Tk.root.grid_rowconfigure(4, :weight=>1) + + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/vu/m128_000.xbm b/ext/tk/sample/tkextlib/vu/m128_000.xbm new file mode 100644 index 000000000..455e3c5e0 --- /dev/null +++ b/ext/tk/sample/tkextlib/vu/m128_000.xbm @@ -0,0 +1,174 @@ +#define m128_000_width 128 +#define m128_000_height 128 +static unsigned char m128_000_bits[] = { + 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf0, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, + 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x03, 0xfc, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, +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0x3d, 0xbf, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x3f, 0x7f, 0x55, 0x55, 0x55, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x3f, + 0xfc, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xea, 0x0f, 0xfc, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xd5, 0x0f, 0xf0, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, + 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x03, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xc0, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; diff --git a/ext/tk/sample/tkextlib/vu/oscilloscope.rb b/ext/tk/sample/tkextlib/vu/oscilloscope.rb new file mode 100644 index 000000000..43254c9b2 --- /dev/null +++ b/ext/tk/sample/tkextlib/vu/oscilloscope.rb @@ -0,0 +1,68 @@ +#!/usr/bin/env ruby + +require 'tk' +require 'tkextlib/vu/charts' + +#---USAGE +info = "...the heart of a Realtime Oscilloscope, where the PCIs +joystick port gives 4 digtal inputs and 4 analog 8 bit +values with an resolution of ~1 millisecond (!!!) +running Realtime Linux. +<p> creates DEMO.ps +<B1-Motion> see what happens" +puts info + +#---GEOMETRY +geo_fr = [10, 10, 210, 180] +geo_ch0 = [10, 10, 210, 90] +geo_ch1 = [10, 90, 210, 180] +geo_t1 = [15, 88] + +#---GUI +c = TkCanvas.new(:width=>220, :height=>190).pack(:fill=>:both, :expand=>true) + +#---background +TkcRectangle.new(c, geo_fr, :width=>4, :fill=>'aquamarine3', + :tags=>['osc', 'frbg']) + +#---channel 0 +ch0 = Tk::Vu::TkcStripchart.new(c, geo_ch0, + :fill=>'', :jumpscroll=>false, + :outline=>'', :scaleline=>'', + :stripline=>'cyan', :tags=>['osc', 'ch0']) + +#---channel 1 +ch1 = Tk::Vu::TkcStripchart.new(c, geo_ch1, + :fill=>'', :jumpscroll=>0, + :outline=>'', :scaleline=>'', + :stripline=>'red', :tags=>['osc', 'ch1']) + +#---frame +TkcRectangle.new(c, geo_fr, :width=>4, :tags=>['osc', 'frfg']) + +#---position +txt1 = TkcText.new(c, geo_t1, :text=>"B1-Motion: X:%X\tY:%Y", + :anchor=>:nw, :tags=>['osc', 'txt1']) + +#---BINDINGS +c.bind('B1-Motion', proc{|x, y, xx, yy| + ch0[:values] = x + ch1[:values] = y + txt1[:text] = "B1-Motion: X:#{xx}\tY:#{yy}" + }, '%x %y %X %Y') + +Tk.root.bind('v', proc{ + puts ch0[:values].join(' ') + puts ch0[:values].size + }) + +Tk.root.bind('p', proc{ + c.postscript(:file=>'DEMO.ps') + puts "DEMO.ps printed" + }) + +Tk.root.bind('q', proc{exit}) + +##################### + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/vu/pie.rb b/ext/tk/sample/tkextlib/vu/pie.rb new file mode 100644 index 000000000..a567f840a --- /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 diff --git a/ext/tk/sample/tkextlib/vu/vu.rb b/ext/tk/sample/tkextlib/vu/vu.rb new file mode 100644 index 000000000..df9a7f38a --- /dev/null +++ b/ext/tk/sample/tkextlib/vu/vu.rb @@ -0,0 +1,67 @@ +#!/usr/bin/env ruby + +require 'tk' +require 'tkextlib/vu' + +####################################### + +puts "Show off barchart and dial widgets" + +speed = TkVariable.new(0) + +dial = Tk::Vu::Dial.new(:resolution=>0.001, :from=>-0.1, :to=>0.1, + :showvalue=>true, :minortickinterval=>0.01, + :tickinterval=>0.1, :radius=>50, :label=>"Dial", + :beginangle=>-20, :endangle=>260, :dialcolor=>'red3', + :active=>'red2', :variable=>speed) + +bar = Tk::Vu::Bargraph.new(:from=>0, :to=>100, :relief=>:groove, + :border=>2, :label=>"Bar Chart") + +####################################### + +green = 25 +blue = 50 +purple = 75 +current = 50 + +def rand_bool + +end + +update = TkTimer.new(200, -1, proc{ + if (rand() - 0.5 + speed.numeric * 3) > 0 + current += 1 + else + current -= 1 + end + bar.set(current) + if current < green + current = 100 if current <= 0 + bar[:barcolor] = 'green' + elsif current < blue + bar[:barcolor] = 'blue' + elsif current < purple + bar[:barcolor] = 'purple' + else + bar[:barcolor] = 'red' + current = 0 if current >= 100 + end + }) + +####################################### + +gobar = TkButton.new(:text=>"Start", :command=>proc{update.start}) +nobar = TkButton.new(:text=>"Stop", :command=>proc{update.stop}) +quit = TkButton.new(:text=>"Exit", :command=>proc{exit}) + +Tk.grid('x', gobar, :sticky=>:ew, :padx=>4, :pady=>4) +Tk.grid(dial, bar, :sticky=>:news) +Tk.grid('x', nobar, :sticky=>:ew, :padx=>4, :pady=>4) +Tk.grid(quit, '-', '-', :sticky=>:ew, :padx=>4, :pady=>4) +Tk.root.grid_columnconfigure(2, :weight=>1) +Tk.root.grid_rowconfigure(1, :weight=>1) + +####################################### + +Tk.mainloop |