mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
![]() * tkafter.rb: Add self to 1st argument of interval- and loop-proc TkAfter#current_interval returns an interval (sleep) time value TkAfter#current_args returns an array of arguments TkAfter#return_value returns a return value of last loop-proc e.g. TkAfter.new( proc{|obj| 500 - obj.current_interval}, 10, [proc{|obj| p obj.current_args}, 'proc', 1], proc{|obj| p obj.current_args; ['return', 2]}, [proc{|obj| p obj.return_value p ['proc', obj.current_args[0].call(obj.return_value[1], obj.current_args[1])]}, proc{|*args| args[0] + args[1]}, 1], proc{p ['proc', 4]} ).start(100) * tk*.rb: Allow to use Symbols for parameters. Allow new notation of constructor (also allow old notation). e.g. TkFrame.new('classname'=>'User'){|base| pack f = TkFrame.new(base, :classname=>'ButtonFrame').pack TkButton.new( :parent => f, :text => 'Quit', :command => proc{exit} ).pack( :fill => :x, :pady => 2 ) } * tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item constructor (for new notation of constructor). e.g. c = TkCanvas.new.pack l = TkcLine.new(c, :coords=>[[0,0], [100,100]]) * tcltklib.c: New 'mainloop' and 'mainloop_watchdog'. The priority of their event-loop can be controlled. They accept an optional argument. If it false, they don't exit although the root widget is destroyed. This function is sometimes useful, if it is used with 'restart'. 'mainloop' can't treat Thread#join/value in a callback routine. (e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) ) 'mainloop_watchdog' can treat them, but watchdog thread is always running (so, a little heavier than 'mainloop'). If the purpose of using Thread#join/value is to do something under some safe-level, please use Proc object. (e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE}) * tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'. * tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter. 'app-name' specifies the name and the resource class of the application. If 'app-name' is specified to 'xxx', the application class on the resource database is set to 'Xxx' and the application name is changed by the same rule of Tk.appname method. 'use' specifies the main window for embedding the root widget instead of generating a new window. * tk.rb: Add new parameter 'widgetname' to the widget constructor to support effective use of Resource Database. For example, the resource 'Xxx*quit.text: QUIT' can set the text of the button generated by the following code. e.g. Tk.restart('Xxx') TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack Tk.mainloop * tk.rb: TkOption::get always returns a tainted string. Add TkOption::new_proc_class. It generates a class to import procedures defined on the resource database. For example, there is a following resource file. ----< resource-test >------------ *CMD.foo: {|*args| p [$SAFE, :foo, args]} *CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]} *Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)} --------------------------------- The following code is a sample of use of the resource file. e.g. require 'tk' TkOption.readfile 'resource-test' p TkOption.new_proc_class(:CMD, [:foo], 1) p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD) TkButton.new(:text=>'test').pack Tk.mainloop git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e |
||
---|---|---|
.. | ||
demo | ||
lib | ||
sample | ||
.cvsignore | ||
depend | ||
extconf.rb | ||
MANIFEST | ||
MANUAL.euc | ||
README.euc | ||
stubs.c | ||
tcltklib.c |
(tof) tcltk ライブラリ tcltklib ライブラリ Sep. 19, 1997 Y. Shigehiro 以下, 「tcl/tk」という表記は, tclsh や wish を実現している, 一般でいう ところの tcl/tk を指します. 「tcltk ライブラリ」, 「tcltklib ライブラ リ」という表記は, 本パッケージに含まれる ruby 用のライブラリを指します. [ファイルについて] README.euc : このファイル(注意, 特徴, インストールの方法). MANUAL.euc : マニュアル. lib/, ext/ : ライブラリの実体. sample/ : マニュアル代わりのサンプルプログラム. sample/sample0.rb : tcltklib ライブラリのテスト. sample/sample1.rb : tcltk ライブラリのテスト. tcl/tk (wish) でできそうなことを一通り書いてみました. sample/sample2.rb : tcltk ライブラリのサンプル. maeda shugo (shugo@po.aianet.ne.jp) 氏による (`rb.tk' で書かれていた) ruby のサンプルプログラム http://www.aianet.or.jp/~shugo/ruby/othello.rb.gz を tcltk ライブラリを使うように, 機械的に変更してみました. demo/ : 100 本の線を 100 回描くデモプログラム. 最初に空ループの時間を測定し, 続いて実際に線を引く時間を測定します. tcl/tk は(再)描画のときに backing store を使わずに律義に 10000 本(?) 線を引くので, (再)描画を始めると, マシンがかなり重くなります. demo/lines0.tcl : wish 用のスクリプト. demo/lines1.rb : `tk.rb' 用のスクリプト. demo/lines2.rb : tcltk ライブラリ用のスクリプト. [注意] コンパイル/実行には, tcl/tk の C ライブラリが必要です. このライブラリは, ruby-1.0-970701, ruby-1.0-970911, ruby-1.0-970919 FreeBSD 2.2.2-RELEASE およびそのパッケージ jp-tcl-7.6.tgz, jp-tk-4.2.tgz で作成/動作確認しました. 他の環境では動作するかどうかわかりません. TclTkLib.mainloop を実行中に Control-C が効かないのは不便なので, ruby のソースを参考に, #include "sig.h" して trap_immediate を操作していま すが, ruby の README.EXT にも書いてないのに, こんなことをして良いのか どうかわかりません. -d オプションでデバッグ情報を表示させるために, ruby のソースを参考に, debug という大域変数を参照していますが, ruby の README.EXT にも書いて ないのに, こんなことをして良いのかどうかわかりません. extconf.rb は書きましたが, (いろいろな意味で)これで良いのか良く分かり ません. [特徴] ruby から tcl/tk ライブラリを利用できます. tcl/tk インタプリタのスクリプトは, 機械的に tcltk ライブラリ用の ruby スクリプトに変換できます. (`tk.rb' との違い) 1. tcl/tk インタプリタのスクリプトが, どのように, tcltk ライブラリ用の ruby スクリプトに変換されるかが理解できれば, マニュアル類が無いに等 しい `tk.rb' とは異なり tcl/tk のマニュアルやオンラインドキュメントを用いて 効率良くプログラミングを行うことができます. 記述方法がわからない, コマンドに与えるパラメータがわからない... - Canvas.new { ... } と, なぜイテレータブロックを書けるの?? - Canvas の bbox は数値のリストを返すのに, xview は文字列を返すの?? と, いちいち, ライブラリのソースを追いかける必要はありません. 2. 個々の機能(オプション)を個別処理によりサポートしており, そのためサ ポートしていない機能は使うことができない(本当は使えないこともないの ですが) `tk.rb' とは異なり, tcl/tk インタプリタで可能なことは ほとんど ruby からも実行できます. 現在, ruby から実行できないことが確認され ているのは, bind コマンドでスクリプトを追加する構文 「bind tag sequence +script」 ^ のみです. - `. configure -width' をしようとして, `Tk.root.height()' と書い たのに, `undefined method `height'' と怒られてしまった. tk.rb を 読んでみて, ガーン. できないのか... ということはありません. 3. wish プロセスを起動しプロセス間通信で wish を利用する `tk.rb' とは 異なり, tcl/tk の C ライブラリをリンクし より高速に (といっても, 思った程は速くないですが) 処理を行います. 4. `tk.rb' ほど, 高水準なインターフェースを備えていないため, tcl/tk イ ンタプリタの生成等 何から何まで自分で記述 しなければなりません(その代わり, tcl/tk ライブラリの仕様通り, tcl/tk インタプリタを複数生成することもできますが). インターフェースは(おそらく) ruby の思想に沿ったものではありません. また, スクリプトの記述は ダサダサ です. スクリプトは, 一見, 読みづらいものとなります. が, 書く人にとっ ては, それほど煩わしいものではないと思います. [インストールの方法] 0. ruby のソースファイル(ruby-1.0-なんたら.tgz)を展開しておきます. 1. ruby-1.0-なんたら/ext に ext/tcltklib をコピーします. cp -r ext/tcltklib ???/ruby-1.0-なんたら/ext/ 2. ruby のインストール法に従い make 等をします. 3. ruby のライブラリ置場に lib/* をコピーします. cp lib/* /usr/local/lib/ruby/ (eof)