aboutsummaryrefslogtreecommitdiffstats
path: root/ext/tk/sample
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-03-10 10:13:30 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-03-10 10:13:30 +0000
commitd2a9e77748684e786af9525e258aee98c8ff2a8d (patch)
treec981003f0983f34978882802c6b8db378df5ab93 /ext/tk/sample
parent7935361d36fdfd372002c276baede34bb39f89a2 (diff)
downloadruby-d2a9e77748684e786af9525e258aee98c8ff2a8d.tar.gz
* ext/tk/tcltklib.c (lib_eventloop_ensure): mis-delete a timer handler
when exit from a recursive called eventloop * ext/tk/lib/tk/timer.rb: new TkRTTimer class, which can works for a realtime operation * ext/tk/sample/tkrttimer.rb: sample of TkRTTimer class * ext/tk/lib/tk/textmark.rb: move TkTextMark#+ and TkTextMark#- to TkText::IndexModMethods * ext/tk/lib/tk/text.rb: improve TkTextMark#+ and TkTextMark#-, and add them to TkText::IndexModMethods module * ext/tk/sample/tktextio.rb: add test part of "seek by text index modifiers" git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample')
-rw-r--r--ext/tk/sample/demos-en/widget12
-rw-r--r--ext/tk/sample/demos-jp/widget12
-rw-r--r--ext/tk/sample/tkrttimer.rb68
-rw-r--r--ext/tk/sample/tktextio.rb18
4 files changed, 98 insertions, 12 deletions
diff --git a/ext/tk/sample/demos-en/widget b/ext/tk/sample/demos-en/widget
index b8073a05da..43880e6d23 100644
--- a/ext/tk/sample/demos-en/widget
+++ b/ext/tk/sample/demos-en/widget
@@ -517,10 +517,10 @@ end
# txt - Name of text widget
# index - The index of the character that the user clicked on.
-def invoke (txt, index)
- tag = txt.tag_names(index).find{|t| t.kind_of?(String) && t =~ /^demo-/}
+def invoke (txt, idx)
+ tag = txt.tag_names(idx).find{|t| t.kind_of?(String) && t =~ /^demo-/}
return unless tag
- cursor = txt.cget('cursor')
+ current_cursor = txt.cget('cursor')
txt.cursor('watch')
Tk.update
# eval `cat #{tag[5..-1]}.rb`
@@ -528,9 +528,9 @@ def invoke (txt, index)
eval IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join
Tk.update
# txt.cursor('xterm')
- txt.cursor(cursor)
+ txt.cursor(current_cursor)
- $tag_visited.add("#{index} linestart +1 chars", "#{index} lineend +1 chars")
+ $tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars")
end
# showStatus --
@@ -791,7 +791,7 @@ end
#
def aboutBox
Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo',
- 'message'=>"Ruby/Tk widget demonstration Ver.1.5.2-en\n\n" +
+ 'message'=>"Ruby/Tk widget demonstration Ver.1.5.3-en\n\n" +
"based on demos of Tk8.1 -- 8.5 " +
"( Copyright:: " +
"(c) 1996-1997 Sun Microsystems, Inc. / " +
diff --git a/ext/tk/sample/demos-jp/widget b/ext/tk/sample/demos-jp/widget
index 59d6309d56..7c559d2a09 100644
--- a/ext/tk/sample/demos-jp/widget
+++ b/ext/tk/sample/demos-jp/widget
@@ -552,10 +552,10 @@ else # ver >= 8.4
end
# テキスト上での click に対する動作
-def invoke (txt, index)
- tag = txt.tag_names(index).find{|t| t.kind_of?(String) && t =~ /^demo-/}
+def invoke (txt, idx)
+ tag = txt.tag_names(idx).find{|t| t.kind_of?(String) && t =~ /^demo-/}
return unless tag
- cursor = txt.cget('cursor')
+ current_cursor = txt.cget('cursor')
txt.cursor('watch')
Tk.update
# eval `cat #{tag[5..-1]}.rb`
@@ -563,9 +563,9 @@ def invoke (txt, index)
eval IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join
Tk.update
# txt.cursor('xterm')
- txt.cursor(cursor)
+ txt.cursor(current_cursor)
- $tag_visited.add("#{index} linestart +1 chars", "#{index} lineend +1 chars")
+ $tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars")
end
# 状態表示
@@ -819,7 +819,7 @@ end
#
def aboutBox
Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo',
- 'message'=>"Ruby/Tk ウィジェットデモ Ver.1.5.2-jp\n\n" +
+ 'message'=>"Ruby/Tk ウィジェットデモ Ver.1.5.3-jp\n\n" +
"based on demos of Tk8.1 -- 8.5 " +
"( Copyright:: " +
"(c) 1996-1997 Sun Microsystems, Inc. / " +
diff --git a/ext/tk/sample/tkrttimer.rb b/ext/tk/sample/tkrttimer.rb
new file mode 100644
index 0000000000..531f4a8d5a
--- /dev/null
+++ b/ext/tk/sample/tkrttimer.rb
@@ -0,0 +1,68 @@
+#!/usr/bin/env ruby
+# This script is a re-implementation of tktimer.rb with TkTimer(TkAfter) class.
+
+require "tk"
+
+root = TkRoot.new(:title=>'realtime timer sample')
+
+f1 = TkFrame.new(:borderwidth=>2, :relief=>:ridge)
+f1.pack(:side=>:bottom, :fill=>:both)
+TkLabel.new(f1, :text=>'use TkTimer (TkAfter) class').pack(:anchor=>:center)
+label1 = TkLabel.new(:parent=>f1, :relief=>:raised,
+ :width=>10).pack(:fill=>:both)
+
+f2 = TkFrame.new(:borderwidth=>2, :relief=>:ridge)
+f2.pack(:side=>:bottom, :fill=>:both)
+TkLabel.new(f2, :text=>'use TkRTTimer class').pack
+label2 = TkLabel.new(:parent=>f2, :relief=>:raised,
+ :width=>10).pack(:fill=>:both)
+
+TkLabel.new(:text=>'Interval setting of each timer is 10 ms.',
+ :padx=>10, :pady=>5).pack
+
+# define the procedure repeated by the TkTimer object
+tick = proc{|aobj| #<== TkTimer object
+ cnt = aobj.return_value + 1 # return_value keeps a result of the last proc
+ label = aobj.current_args[0]
+ label.text format("%d.%02d", *(cnt.divmod(100)))
+ cnt #==> return value is kept by TkTimer object
+ # (so, can be send to the next repeat-proc)
+}
+
+timer1 = TkTimer.new(10, -1, [tick, label1]) # 10 ms interval
+timer2 = TkRTTimer.new(10, -1, [tick, label2]) # 10 ms interval
+
+timer1.start(0, proc{ label1.text('0.00'); 0 })
+timer2.start(0, proc{ label2.text('0.00'); 0 })
+
+b_start = TkButton.new(:text=>'Start', :state=>:disabled) {
+ pack(:side=>:left, :fill=>:both, :expand=>true)
+}
+
+b_stop = TkButton.new(:text=>'Stop', :state=>:normal) {
+ pack('side'=>'left', 'fill'=>'both', 'expand'=>'yes')
+}
+
+b_start.command {
+ timer1.continue
+ timer2.continue
+ b_stop.state(:normal)
+ b_start.state(:disabled)
+}
+
+b_stop.command {
+ timer1.stop
+ timer2.stop
+ b_start.state(:normal)
+ b_stop.state(:disabled)
+}
+
+TkButton.new(:text=>'Reset', :state=>:normal) {
+ command { timer1.reset; timer2.reset }
+ pack(:side=>:right, :fill=>:both, :expand=>:yes)
+}
+
+ev_quit = TkVirtualEvent.new('Control-c', 'Control-q')
+Tk.root.bind(ev_quit, proc{Tk.exit}).focus
+
+Tk.mainloop
diff --git a/ext/tk/sample/tktextio.rb b/ext/tk/sample/tktextio.rb
index fecedf6ee1..cb59c2d9d6 100644
--- a/ext/tk/sample/tktextio.rb
+++ b/ext/tk/sample/tktextio.rb
@@ -581,5 +581,23 @@ if __FILE__ == $0
STDOUT.print("\n================================================\n\n")
+ STDOUT.print("\n========= reverse order (seek by lines) ========\n\n")
+
+ tio.seek(-1, IO::SEEK_END)
+ begin
+ begin
+ tio.seek(:linestart, IO::SEEK_CUR)
+ rescue
+ # maybe use old version of tk/textmark.rb
+ tio.seek('0 char linestart', IO::SEEK_CUR)
+ end
+ STDOUT.print(gets)
+ tio.seek('-1 char linestart -1 char', IO::SEEK_CUR)
+ end while(tio.pos > 0)
+
+ STDOUT.print("\n================================================\n\n")
+
+ tio.seek(0, IO::SEEK_END)
+
Tk.mainloop
end