diff options
Diffstat (limited to 'ext/tk/sample/demos-jp')
-rw-r--r-- | ext/tk/sample/demos-jp/bind.rb | 18 | ||||
-rw-r--r-- | ext/tk/sample/demos-jp/pendulum.rb | 35 | ||||
-rw-r--r-- | ext/tk/sample/demos-jp/widget | 6 |
3 files changed, 36 insertions, 23 deletions
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' |