aboutsummaryrefslogtreecommitdiffstats
path: root/ext/tk/sample
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-21 08:57:35 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-21 08:57:35 +0000
commit59a07a0690ea964aa1f6d2f250a9ef176cac49ab (patch)
treeb75ba8b89ab8151fdcb14b9b358bb18c88afbc41 /ext/tk/sample
parentd66a188c4a1aa269be94c5707df3aeff185dd076 (diff)
downloadruby-59a07a0690ea964aa1f6d2f250a9ef176cac49ab.tar.gz
Ruby/Tk :: provisional support on Ruby-VM and Tcl/Tk8.5.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample')
-rw-r--r--ext/tk/sample/demos-en/bind.rb18
-rw-r--r--ext/tk/sample/demos-en/pendulum.rb35
-rw-r--r--ext/tk/sample/demos-jp/bind.rb18
-rw-r--r--ext/tk/sample/demos-jp/pendulum.rb35
-rw-r--r--ext/tk/sample/demos-jp/widget6
-rw-r--r--ext/tk/sample/tkextlib/vu/canvSticker2.rb12
6 files changed, 74 insertions, 50 deletions
diff --git a/ext/tk/sample/demos-en/bind.rb b/ext/tk/sample/demos-en/bind.rb
index aabe7f0849..6faeeaa30c 100644
--- a/ext/tk/sample/demos-en/bind.rb
+++ b/ext/tk/sample/demos-en/bind.rb
@@ -94,33 +94,27 @@ TkText.new($bind_demo){|t|
}
d1.bind('1',
proc{
- eval(`cat #{[$demo_dir,'items.rb'].join(File::Separator)}`,
- _null_binding)
+ eval_samplecode(`cat #{[$demo_dir,'items.rb'].join(File::Separator)\}`)
})
d2.bind('1',
proc{
- eval(`cat #{[$demo_dir,'plot.rb'].join(File::Separator)}`,
- _null_binding)
+ eval_samplecode(`cat #{[$demo_dir,'plot.rb'].join(File::Separator)\}`)
})
d3.bind('1',
proc{
- eval(`cat #{[$demo_dir,'ctext.rb'].join(File::Separator)}`,
- _null_binding)
+ eval_samplecode(`cat #{[$demo_dir,'ctext.rb'].join(File::Separator)\}`)
})
d4.bind('1',
proc{
- eval(`cat #{[$demo_dir,'arrow.rb'].join(File::Separator)}`,
- _null_binding)
+ eval_samplecode(`cat #{[$demo_dir,'arrow.rb'].join(File::Separator)\}`)
})
d5.bind('1',
proc{
- eval(`cat #{[$demo_dir,'ruler.rb'].join(File::Separator)}`,
- _null_binding)
+ eval_samplecode(`cat #{[$demo_dir,'ruler.rb'].join(File::Separator)\}`)
})
d6.bind('1',
proc{
- eval(`cat #{[$demo_dir,'cscroll.rb'].join(File::Separator)}`,
- _null_binding)
+ eval_samplecode(`cat #{[$demo_dir,'cscroll.rb'].join(File::Separator)\}`)
})
TkTextMarkInsert.new(t, '0.0')
diff --git a/ext/tk/sample/demos-en/pendulum.rb b/ext/tk/sample/demos-en/pendulum.rb
index 36bb44edec..a3498d67cf 100644
--- a/ext/tk/sample/demos-en/pendulum.rb
+++ b/ext/tk/sample/demos-en/pendulum.rb
@@ -49,9 +49,11 @@ TkFrame.new($pendulum_demo) {|frame|
class PendulumAnimationDemo
def initialize(frame)
# Create some structural widgets
- pane = TkPanedWindow.new(frame).pack(:fill=>:both, :expand=>true)
- pane.add(@lf1 = TkLabelFrame.new(pane, :text=>'Pendulum Simulation'))
- pane.add(@lf2 = TkLabelFrame.new(pane, :text=>'Phase Space'))
+ @pane = TkPanedWindow.new(frame).pack(:fill=>:both, :expand=>true)
+# @pane.add(@lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation'))
+# @pane.add(@lf2 = TkLabelFrame.new(@pane, :text=>'Phase Space'))
+ @lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation')
+ @lf2 = TkLabelFrame.new(@pane, :text=>'Phase Space')
# Create the canvas containing the graphical representation of the
# simulated system.
@@ -99,23 +101,24 @@ class PendulumAnimationDemo
@dTheta = 0.0
@length = 150
- # init display
- showPendulum
-
# animation loop
@timer = TkTimer.new(15){ repeat }
# binding
@c.bindtags_unshift(btag = TkBindTag.new)
btag.bind('Destroy'){ @timer.stop }
- btag.bind('1', proc{|x, y| @timer.stop; showPendulum(x, y)}, '%x %y')
- btag.bind('B1-Motion', proc{|x, y| showPendulum(x, y)}, '%x %y')
+ btag.bind('1', proc{|x, y| @timer.stop; showPendulum(x.to_i, y.to_i)},
+ '%x %y')
+ btag.bind('B1-Motion', proc{|x, y| showPendulum(x.to_i, y.to_i)}, '%x %y')
btag.bind('ButtonRelease-1',
- proc{|x, y| showPendulum(x, y); @timer.start }, '%x %y')
+ proc{|x, y| showPendulum(x.to_i, y.to_i); @timer.start },
+ '%x %y')
- btag.bind('Configure', proc{|w| @plate.coords(0, 25, w, 25)}, '%w')
+ btag.bind('Configure', proc{|w| @plate.coords(0, 25, w.to_i, 25)}, '%w')
@k.bind('Configure', proc{|h, w|
+ h = h.to_i
+ w = w.to_i
@psh = h/2;
@psw = w/2
@x_axis.coords(2, @psh, w-2, @psh)
@@ -124,6 +127,14 @@ class PendulumAnimationDemo
@label_dtheta.coords(w-6, @psh+4)
}, '%h %w')
+ # add
+ Tk.update
+ @pane.add(@lf1)
+ @pane.add(@lf2)
+
+ # init display
+ showPendulum
+
# animation start
@timer.start(500)
end
@@ -154,6 +165,10 @@ class PendulumAnimationDemo
# rate at which the angle is changing (the first derivative with
# respect to time.)
def showPhase
+ unless @psw && @psh
+ @psw = @k.width/2
+ @psh = @k.height/2
+ end
@points << @theta + @psw << -20*@dTheta + @psh
if @points.length > 100
@points = @points[-100..-1]
diff --git a/ext/tk/sample/demos-jp/bind.rb b/ext/tk/sample/demos-jp/bind.rb
index 779e395826..af4e04fe8d 100644
--- a/ext/tk/sample/demos-jp/bind.rb
+++ b/ext/tk/sample/demos-jp/bind.rb
@@ -92,33 +92,27 @@ TkText.new($bind_demo){|t|
}
d1.bind('1',
proc{
- eval(`cat #{[$demo_dir,'items.rb'].join(File::Separator)}`,
- _null_binding)
+ eval_samplecode(`cat #{[$demo_dir,'items.rb'].join(File::Separator)\}`)
})
d2.bind('1',
proc{
- eval(`cat #{[$demo_dir,'plot.rb'].join(File::Separator)}`,
- _null_binding)
+ eval_samplecode(`cat #{[$demo_dir,'plot.rb'].join(File::Separator)\}`)
})
d3.bind('1',
proc{
- eval(`cat #{[$demo_dir,'ctext.rb'].join(File::Separator)}`,
- _null_binding)
+ eval_samplecode(`cat #{[$demo_dir,'ctext.rb'].join(File::Separator)\}`)
})
d4.bind('1',
proc{
- eval(`cat #{[$demo_dir,'arrow.rb'].join(File::Separator)}`,
- _null_binding)
+ eval_samplecode(`cat #{[$demo_dir,'arrow.rb'].join(File::Separator)\}`)
})
d5.bind('1',
proc{
- eval(`cat #{[$demo_dir,'ruler.rb'].join(File::Separator)}`,
- _null_binding)
+ eval_samplecode(`cat #{[$demo_dir,'ruler.rb'].join(File::Separator)\}`)
})
d6.bind('1',
proc{
- eval(`cat #{[$demo_dir,'cscroll.rb'].join(File::Separator)}`,
- _null_binding)
+ eval_samplecode(`cat #{[$demo_dir,'cscroll.rb'].join(File::Separator)\}`)
})
TkTextMarkInsert.new(t, '0.0')
diff --git a/ext/tk/sample/demos-jp/pendulum.rb b/ext/tk/sample/demos-jp/pendulum.rb
index c245136d5c..e19b57a2d6 100644
--- a/ext/tk/sample/demos-jp/pendulum.rb
+++ b/ext/tk/sample/demos-jp/pendulum.rb
@@ -51,9 +51,11 @@ TkFrame.new($pendulum_demo) {|frame|
class PendulumAnimationDemo
def initialize(frame)
# Create some structural widgets
- pane = TkPanedWindow.new(frame).pack(:fill=>:both, :expand=>true)
- pane.add(@lf1 = TkLabelFrame.new(pane, :text=>'Pendulum Simulation'))
- pane.add(@lf2 = TkLabelFrame.new(pane, :text=>'Phase Space'))
+ @pane = TkPanedWindow.new(frame).pack(:fill=>:both, :expand=>true)
+# @pane.add(@lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation'))
+# @pane.add(@lf2 = TkLabelFrame.new(@pane, :text=>'Phase Space'))
+ @lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation')
+ @lf2 = TkLabelFrame.new(@pane, :text=>'Phase Space')
# Create the canvas containing the graphical representation of the
# simulated system.
@@ -101,23 +103,24 @@ class PendulumAnimationDemo
@dTheta = 0.0
@length = 150
- # init display
- showPendulum
-
# animation loop
@timer = TkTimer.new(15){ repeat }
# binding
@c.bindtags_unshift(btag = TkBindTag.new)
btag.bind('Destroy'){ @timer.stop }
- btag.bind('1', proc{|x, y| @timer.stop; showPendulum(x, y)}, '%x %y')
- btag.bind('B1-Motion', proc{|x, y| showPendulum(x, y)}, '%x %y')
+ btag.bind('1', proc{|x, y| @timer.stop; showPendulum(x.to_i, y.to_i)},
+ '%x %y')
+ btag.bind('B1-Motion', proc{|x, y| showPendulum(x.to_i, y.to_i)}, '%x %y')
btag.bind('ButtonRelease-1',
- proc{|x, y| showPendulum(x, y); @timer.start }, '%x %y')
+ proc{|x, y| showPendulum(x.to_i, y.to_i); @timer.start },
+ '%x %y')
- btag.bind('Configure', proc{|w| @plate.coords(0, 25, w, 25)}, '%w')
+ btag.bind('Configure', proc{|w| @plate.coords(0, 25, w.to_i, 25)}, '%w')
@k.bind('Configure', proc{|h, w|
+ h = h.to_i
+ w = w.to_i
@psh = h/2;
@psw = w/2
@x_axis.coords(2, @psh, w-2, @psh)
@@ -126,6 +129,14 @@ class PendulumAnimationDemo
@label_dtheta.coords(w-6, @psh+4)
}, '%h %w')
+ # add
+ Tk.update
+ @pane.add(@lf1)
+ @pane.add(@lf2)
+
+ # init display
+ showPendulum
+
# animation start
@timer.start(500)
end
@@ -156,6 +167,10 @@ class PendulumAnimationDemo
# rate at which the angle is changing (the first derivative with
# respect to time.)
def showPhase
+ unless @psw && @psh
+ @psw = @k.width/2
+ @psh = @k.height/2
+ end
@points << @theta + @psw << -20*@dTheta + @psh
if @points.length > 100
@points = @points[-100..-1]
diff --git a/ext/tk/sample/demos-jp/widget b/ext/tk/sample/demos-jp/widget
index b369bfba96..7982a6651e 100644
--- a/ext/tk/sample/demos-jp/widget
+++ b/ext/tk/sample/demos-jp/widget
@@ -2,7 +2,11 @@
# -*- coding: euc-jp -*-
# ´Á»ú¥³¡¼¥ÉÀßÄê ( tk.rb ¤Î¥í¡¼¥É»þ¤Î encoding ¿äÄê/ÀßÄê¤Ë»È¤ï¤ì¤ë )
-$KCODE = 'euc'
+if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!!!!
+ $KCODE = 'euc'
+else
+ $TK_ENCODING = 'EUC-JP'
+end
# tk ´Ø·¸¥é¥¤¥Ö¥é¥ê¤ÎÆɤ߹þ¤ß
require 'tk'
diff --git a/ext/tk/sample/tkextlib/vu/canvSticker2.rb b/ext/tk/sample/tkextlib/vu/canvSticker2.rb
index f54e748660..34daf9ae3b 100644
--- a/ext/tk/sample/tkextlib/vu/canvSticker2.rb
+++ b/ext/tk/sample/tkextlib/vu/canvSticker2.rb
@@ -20,14 +20,16 @@ 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, 180, 180], "Sticker äöüß@²³¼½¾", :center ]
+#txt_conf = [ [210, 210], "Text äöüß@²³¼½¾", :center ]
sti_conf = [ [10, 10, 350, 350],
- Tk::UTF8_String("Sticker äöüß@²³¼½¾"), :center ]
+ Tk::UTF8_String('Sticker \u00E4\u00F6\u00FC\u00DF\u0040\u00B2\u00B3\u00BC\u00BD\\u00BE')
+ :center ]
txt_conf = [ [250, 250],
- Tk::UTF8_String("Text äöüß@²³¼½¾"), :center ]
+ Tk::UTF8_String('Text \u00E4\u00F6\u00FC\u00DF\u0040\u00B2\u00B3\u00BC\u00BD\\u00BE')
+ :center ]
-p sti_conf
+#p sti_conf
fnt = TkFont.new('Helvetica 24 bold')