diff options
author | Yukihiro Matsumoto <matz@ruby-lang.org> | 1995-12-21 00:56:57 +0900 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2019-08-17 22:09:32 +0900 |
commit | fca49a8a69a0f6bb4feae74c6cd0e93d7fac8b36 (patch) | |
tree | 590a6d2ffcfa31212c1595e34a01d9cda56ba308 /lib | |
parent | 8bf1c909dc31fd4bcdc1488cda9fe89a62bc2830 (diff) |
version 0.95v0_95
https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.95.tar.gz
Thu Dec 21 00:56:57 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.95 - fj.sourcesに
* eval.c (rb_eval): rescueのロジックをrb_rescue()に一元化.
Wed Dec 20 19:30:58 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* Makefile.in: 不要なコンパイルの回避(より完全に).
* class.c (singleton_class_new): `single'->`singleton'
Tue Dec 19 07:14:33 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* io.c (closed?): IOがcloseされているかどうかを知る述語.
* parse.y (primary): 特異メソッドの引数のlex_stateが不適切.
* lib/tk.rb: tcl->rubyの変換関数の用意.
* ext/extmk.rb.in (install): installの2重コンパイルの回避.
* array.c (range_beg_len): range指定の不適切なエラーを訂正.
* string.c (str_aref): range指定のバグを削除.
* lib/tk.rb (tk_split_list): Tclのリストに対応.
Mon Dec 18 09:58:12 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.94
* dln.c (dln_load): HP対応(未確認)
* eval.c (Init_Proc): BlockをProcに改名.
Sat Dec 16 13:46:14 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* eval.c (rb_eval): retryでイテレータの再実行ができるように.
Fri Dec 15 17:14:30 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* eval.c: proc:lambdaの親しみやすい別名
Thu Dec 14 17:21:55 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* eval.c (dyna_var_asgn): イテレータブロック内で最初に初期化された
ローカル変数の有効範囲をそのブロック内に限定.これでlambdaと呼べ
ないことはない.
Wed Dec 13 02:30:58 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* gc.c: autoloadのマークミス.
* lib/tk.rb: wishからの複数行の戻り値に対応
* lib/tkcomposite.rb: 複合widget
* variable.c (rb_class2path): ICLASSに対応してなかった.
* eval.c (ruby_run): exit(0)のバグ
Sat Dec 9 01:21:24 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* ext/marshal/marshal.c (dumps|load): 文字列に対する入出力を可能に
した(ただし実はファイル経由なのだ).
Fri Dec 8 18:29:11 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* ext/marshal/marshal.c: シンボルを一度だけ初期化する.
Thu Dec 7 07:58:50 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* parse.y (yylex): 第1引数の正規表現の認識にエラーがあった.同時に
状態数を減らした.
* string.c (str_sub): 置換でスキップ幅が大きすぎた.
Wed Dec 6 15:14:23 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* string.c (str_sub_method): sub/gsub(!なし)は置換が行なわれなかっ
た時,置換前の文字列を返す.
Tue Dec 5 00:55:15 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* parse.y (yylex): 括弧を省略した時の引数展開の`*'に対応.
* eval.c (ruby_run): EXITハンドラ内での例外に対応.
* bignum.c (big_cmp): BignumとFixnumの比較で落ちる.
Mon Dec 4 14:21:18 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* parse.y (call_op): コンパイル時の定数式の展開をやめた.労多くし
て益少ないと判断したので.
Thu Nov 30 01:35:15 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* lib/tk.rb: {Radio,Check}Buttonのvariableの実装.
* eval.c (rb_yield_0): Block.callがネストした時のバグ.
* io.c (f_select): 常に配列3つをふくむ配列を返すように
* lib/tk.rb: fileeventをruby側で実装.
Wed Nov 29 17:53:23 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* variable.c (rb_ivar_get): selfを常に指定するように.
Tue Nov 14 00:07:29 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* lib/tk.rb: Tk4.0対応
Mon Nov 13 16:23:32 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.93
Thu Nov 9 23:26:01 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* gc.c (gc_mark): モジュールのMixinのマーク忘れ.
* parse.y (f_arglist): メソッド定義の引数を括弧で括らなくても良い
ようにした.
Wed Nov 8 00:17:51 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* eval.c (rb_yield_0): 未初期化のローカル変数があった.
* eval.c (rb_eval): pendig signalのチェックをeval実行後に行うよう
にした.でないとシグナルの発生と検出が遠く離れてしまう事がある.
* parse.y: class文のsuperclass部を定数から式に拡張した.
* lib/tk.rb: Tkのほぼ全ウィンドウクラスに対応.キャンバスとテキス
ト上のオブジェクトが残っている.
Tue Nov 7 08:18:37 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* signal.c (trap): ブロックを指定できるように.
Mon Nov 6 16:44:00 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* eval.c (f_caller): 呼出元の情報を得る.
* ext/tkutil/tkutil.c: wishのstderr出力を監視することで,エラー処
理を行う.
* ext/tkutil/tkutil.c: wishとの通信部をCで記述.
Sat Nov 4 01:12:59 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* sample/ruby-mode.el (ruby-calculate-indent): インデントの計算を
もう少しスマートにした(正規表現のチェック,継続行のチェック).
* eval.c (rb_call): 無限再帰を避けるため,関数のネストレベルの制限
を行なう.
* lib/tk.rb: Tkインターフェース.まだ不完全だが.
* eval.c (rb_yield_0): 空のBlockのバグ.
* sample/ruby-mode.el (ruby-calculate-indent): 行末の演算子による
行継続に対応.
Fri Nov 3 12:56:21 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* eval.c (rb_call): 本体が空の関数の実行にバグ.
* parse.y (var_extend): 文字列の末尾の変数展開のバグ.
* variable.c (rb_gvar_set): traceの評価時にに変数値を与えるように.
* eval.c (f_require): ruby scriptのrequireにbug.
* variable.c (rb_const_get): モジュールのinclude対策.
Thu Oct 19 13:56:06 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* dln.c (dln_load): HP対応でのtypo.
Wed Oct 18 17:39:39 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.92
* object.c (krn_type): オブジェクトの動的な型を返すメソッド.
Tue Oct 17 00:48:18 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* ruby.c (proc_options): -X オプション.chdirだけを行う.
* re.c (reg_search): 漢字コードを途中で変更できるように.コンパイ
ル時のコードが変更された時にはマッチの直前に正規表現の再コンパイ
ルを行う.定数KCODEから変数$KCODEへ.
* parse.y: ()のなかにcompexprを許す.
* re.c (reg_search): メモリリークを直した.
Fri Oct 13 13:19:19 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* string.c (str_sub): 文字列置換にバグ.
* string.c (str_strip_bang): 文字列の後ろの長さの調整が行われてい
なかった.
* re.c (reg_search): $&, $1...のはローカルに束縛するようになった.
呼び出したメソッドでのマッチは現スコープの$&などの値に影響しない.
マッチの情報をスコープ外で得たいときには$~を使って束縛情報を持ち
出す必要がある.
Thu Oct 12 00:33:33 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* re.c (reg_search): String:split, String:indexでは$&, $1...が変化
しないようにした.
* io.c (rb_str_setter): setterの仕様が変更になっていた.
* variable.c (f_trace_var): 第2引数を省略してイテレータとして呼べ
るように.
Wed Oct 11 11:50:59 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.91
* variable.c (var_setter): 引数が間違っていた.致命的バグ.
* io.c (pipe_open): $stderrの値が変更されている時にはそちらを
子プロセスのstderrに設定する.
Mon Oct 9 13:06:33 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* object.c (mod_to_s): モジュール内のモジュールは`::'を使った表現
で表示されるように.
* variable.c (rb_gvar_set): 代入によるループが発生しないように,
trace内での代入ではtraceを評価しない.
* struct.c (struct_equal): structのequal判定にクラスの一致を含めた.
Sat Oct 7 00:18:32 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* eval.c (rb_eval): defined?の機能を拡張(yieldのチェック,superの
存在など).
Fri Oct 6 12:06:47 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.90
* st.c (st_foreach): 要素を削除した時に要素数が変化していなかった.
* hash.c (hash_values): バグ修正.keysを返していた….
* parse.y (call_op): defined? の引数では定数の畳み込みを行わない
(チェックする前にコンパイルエラーになっては困る).
* スコープ生成の一部見直し.
Thu Oct 5 00:29:43 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* 関数とクラスの命名規則を変更した.関数名,変数名の全面書き換え.
* gc.c (looks_pointerp): ヒープチェックの高速化.
* struct.c (Fstruct_aset): 構造体に対する`[]='.
(struct_set): 構造体メンバに対する代入.
Wed Oct 4 09:54:07 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.89
* eval.c (Frequire): ダイナミックロードのエラーチェックを厳しく.
* struct.c: structの構造を完全に書き換えた.以前は順序付きの
id->valueの連想配列であったが,今度は構造体毎に新しいクラスを生
成するようにした.
* parse.y: `::'の意味をAssocの生成からクラス(モジュール)内の定数ア
クセスへ変更.
* assoc.c: なくす.
Tue Oct 3 13:31:08 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* variable.c (Ftrace_var): trace_var, 大域変数への書き込みhookを設
定する.
* variable.c: global_entryの構成を書き換えた.これでtrace_varを実
装できる.
* file.c (Ffile_stat): "&"で直前のfstatの結果も参照できるように.
Fri Sep 29 14:15:13 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.88
* dln.c (dln_load): AIXとHPに対応したコードを入れた(動作は未確認).
* ext/extmk.rb.in: 必要に応じて,定数EXTLIBを定義するように.
* dln.c (dln_load): dln独立に書き換える.将来の拡張用.
(load_1): dln_a_outにおいてソースコードでライブラリを明示的にロー
ドする必要がないように変更した.
Thu Sep 28 13:31:37 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* sample/ruby-mode.el: もっとましなhilit19対応(正規表現).
Wed Sep 27 04:12:44 1995 Takahasi Mamoru <taka@soum.co.jp>
* sample/test.rb: echoで-nを使わないように(SysV対策).
* ext/extmk.rb.in: sub -> sub!
Tue Sep 26 19:12:42 1995 Yasuo OHBA <jammy@csg.mes.co.jp>
* dln.c (dln_find_1): `.', `..'から始まるパスに対応した.
Mon Sep 25 12:33:03 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.87
Sat Sep 23 10:00:18 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* eval.c (Fmod_modfunc): メソッドをprivateにし,同時に特異メソッド
も定義するメソッド.パッケージ的使い方のモジュール用.
Fri Sep 22 11:02:44 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* lib/find.rb: findを提供するライブラリ
* variable.c (rb_define_variable): hookの設定を分離.
(add_hook): 1変数に対して複数のhookを設定できるように.
Thu Sep 21 00:22:11 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* string.c (Fstr_frozen): 文字列が更新不可かどうかをチェックする述
語メソッド.
* hash.c (Fhash_aset): keyが文字列の時,キーの内容が変化しないよう
に,dupしてfreezeする.
Wed Sep 20 16:12:44 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.86
* ext/extmk.rb.in (have_header): キャッシュにバグ.
* ext/extmk.rb.in (have_library): 引数の順序が変わった.
Thu Sep 14 18:00:59 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* object.c (obj_is_instance_of): is_member_ofから名称変更.
Wed Sep 13 15:44:35 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* string.c (Fstr_tr_bang): 範囲外の文字に対する変換バグ.
Tue Sep 12 14:27:58 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* file.c (Sfile_expand_path): expand_file_name -> expand_pathに名
称変更.
* enum.c (Fenum_member): includes? -> member? に名称変更.
* string.c (Fstr_each_byte): StringはByteArrayであるという基本に戻っ
て,eachの定義をeach_byteに変更した.今までのeachはeach_lineでア
クセスできる.
Mon Sep 11 18:31:17 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* file.c (cache_stat): ファイル名として"&"を指定すると直前の
stat(2)の結果を再利用するように.
Fri Sep 8 14:18:51 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* ruby.texi: `!', `?'に対応してアップデート.
* parse.y: defined -> defined?
* file.c: FileOpの一文字メソッドをなくす.一文字テストはtestメソッ
ドにまかせる.
* parse.y (yylex): 変数名の後ろに`?'も許す.述語メソッドの後ろに
`?'を追加する.
Thu Sep 7 20:01:33 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* string.c: 文字列の中身を更新するメソッドの名前の終りに`!'を付加.
`!'の無いバージョンも用意した.
* parse.y: 変数名の後ろに`!'を許す.
Wed Sep 6 14:12:19 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.85
* string.c (Fstr_dup): 文字列の複製を作る
(Fstr_freeze): 文字列の更新不可属性を設定できるように.
(Fsub/Fgsub): $_の内容をdupしてから置換を行うように.
* ruby.h (CLONESETUP): flagsの状態もコピー
Tue Sep 5 01:27:50 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* sample/test.rb: 失敗の検出を厳しく.
Fri Aug 25 14:31:02 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* process.c (Ffork): イテレータとしても動作するように.
* version 0.84
* signal.c (sig_beg): ハンドラが設定されている時には再設定しない.
* ext/extmk.rb.in (create_makefile): shared objectのリンクの際に
`-l'オプションを指定するように.
* signal.c (trap): `EXIT'で終了処理を行う設定が出来る.
Wed Aug 16 00:13:22 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* signal.c (sig_beg): デフォルトではbegin節の中でだけSIGINTを捕捉
するように変更.
* io.c (io_ctl): fcntlを持たないシステムにも対応.
* 各ディレクトリに分散していたMANIFESTをまとめた.拡張モジュール毎
には必要.
* string.c (Sstr_new,str_sub,Fstr_crypt): 引数を自動的に文字列に変
換するように.
Sat Aug 12 00:44:02 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* string.c (Fstr_crypt): PD cryptを用意した.
Fri Aug 11 14:37:03 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* assoc.c (Fassoc_clone): assocもcloneできるように.
* io.c: マクロREAD_DATA_PENDINGの定義を変更(Linux対応)
* io.c (io_fptr_finalize): ftprの開放時の処理を指定できるように.
Wed Aug 9 16:52:41 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* eval.c (rb_provided): 複数のfeatureをロードすると無限ループに落
ちるという単純な(しかし凶悪な)ミス.
* ext/extmk.rb.in (install): dlopen対応を行った.今までdlnにしか十
分に対応していなかった.
Tue Aug 8 14:17:06 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.83
Mon Aug 7 12:47:41 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* parse.y: resque -> rescue.恥ずかしいがtypoを残しておくわけには
いかないよなあ.なんで今まで気がつかなかったのか….
Thu Aug 3 18:18:05 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* missing/nt.c: NT移植用の関数群をまとめた.
* variable.c (rb_const_get): また例外を発生するようにした.defined
がある以上例外を発生させない理由がないので(例外が発生した方がタ
イプミスの検出などの点で有利).
* variable.c (Fautoload): autoloadを実装.今度は使えるか.
Mon Jul 31 15:44:21 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* parse.y (arg_ambiguous): 第1引数のあいまいさを警告(-vオプション
で有効).
* eval.c (rb_eval): `-v'オプションをつけて`def'が呼ばれると不必要
なエラーメッセージが出た.
* parse.y (yylex): メソッドの第1引数の判定をもうちょっと賢くした.
Fri Jul 28 19:04:43 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* parse.y (yylex): `+/-/['の直前に空白が来るかどうかで動作を変更し
た(混乱のもとか?)
Wed Jul 26 09:21:23 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.82a
* sprintf.c (Fsprintf): `%s'で'\0'を含む文字列に対応.
* pack.c (Fpck_pack): packの要素確保のバグ.
* eval.c (Floop): 無限ループのイテレータ.
* io.c (next_argv): 存在しないファイル名が指定された時のエラー処理
が行われていなかった.
Mon Jul 24 17:37:34 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.82
* ext/extmk.rb.in (install): 拡張モジュールをstatic linkする場合は
そのモジュールが既にrequireされたのと同じようにfeatureを設定する.
これで拡張モジュールの機能が必要な時には(static linkされているか
どうかにかかわらず)requireすればよくなる.
* eval.c (Frequire): `$"'に格納する文字列をフルパスでなくフィーチャ
名とする.rubyスクリプトをロードした時には`.rb',オブジェクトを
ロードした時には`.o'をフィーチャ名に付加する.lispのrequireと
provideの働きに(少し)近い.
Thu Jul 20 12:50:05 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* Makefile.in (test): make testができるように.
* struct.c (struct_new): typo.
* eval.c (rb_eval): `defined'を追加.メソッド/変数/定数の定義状態
を知る事が出来る.
Wed Jul 19 18:04:01 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.81
Mon Jul 17 14:53:51 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* variable.c (rb_const_get): 未初期化のCONSTANTの値をnilにした.し
かし,今後また例外に戻す可能性はある.要はoptionalなクラス/モジュー
ルが存在するかチェックしたいだけなんだな.
* st.c (int): grow_factorを固定にした(大嶋さんのマシンに対応).
Fri Jul 14 00:48:40 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* ext/extmk.rb.in: キャッシュのバグを修正.
* parse.y (var_extend): #{$数字}に対応した.
* dln.c (dln_load_1): `Init_FILENAME'だけを有効に.`init_*'は今後
実行しない.
* ext/etc/etc.c : Etcモジュールを拡張モジュールとして分離.実はNT
対応への布石だったりするかもしれない.
Tue Jul 11 17:12:48 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* gcc -Wallで出たwarningを元にソースを変更.
* signal.c (trap): typo.
Fri Jul 7 10:08:51 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.80
* ruby.texi: texinfo documentを提供.specとruby.1は無くなった.
* signal.c (Ftrap): 割込み禁止中の例外発生に対応.
* eval.c (Flambda): Blockオブジェクトを返す.Block.newと同義.
Thu Jul 6 00:35:03 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* signal.c (Ftrap): SIG_DFLの処理を変更.SIGINTへのデフォルトハン
ドラを用意(例外を発生する).
* file.c (Sfile_expand_fname): パス名を絶対パスに展開するメソッド.
(Sfile_basename): basenameを得るメソッド.拡張子も外せる.
(Sfile_dirname): basenameの反対.
* eval.c (rb_call): argument評価中の例外発生に対応.
* file.c (Ftest): `M', `A', `C'を追加.
Tue Jul 4 12:36:33 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* file.c (Ftest): ファイルテスト用メソッド.
* ruby.c (proc_options): `-r'オプションを追加.
* parse.y (f_args): デフォルト引数を追加.
* eval.c (rb_call): 該当する引数が無い時,rest引数の値をnilに.
* numeric.c (num_equal): 数値以外との比較で例外が発生していた.
FALSEを返すように.
* eval.c (masign): 多重代入のrest部の動作がおかしかった.
Sat Jun 17 01:03:16 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* parse.y (gettable): 未初期化のローカル変数の参照(独立した識別子)
は正式にメソッド呼び出しとした.
* parse.y (read_escape): tokenbufを使わないように修正.それにとも
ない,`\C-x',`\M-x'などのエスケープ表現を復活.これでドキュメン
トと実際の処理系が一致した.
Thu Jun 15 15:42:00 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* re.c (re_regcomp): cacheのチェックを改善.
Mon Jun 12 18:50:51 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* version 0.79
Sat Jun 10 00:25:01 1995 Yukihiro Matsumoto <matz@caelum.co.jp>
* re.c (re_regcomp): cache判定に`$='の値も反映させた.
* sample/test.rb: test suite作成.
Fri Jun 9 15:58:34 1995 Yukihiro Matsumoto <matz@ix-02>
* re.c (re_regcomp): cacheの判定が間違っていた.
Fri Jun 9 00:01:35 1995 Yukihiro Matsumoto (matz@dyna)
* eval.c (rb_yield): block構造体に初期化していないメンバ(iter)があっ
たのでイテレータのネストが正しく動作しなかった.
Thu Jun 8 00:59:03 1995 Yukihiro Matsumoto (matz@dyna)
* re.c (=~): String以外との比較がFALSEを返すように(例外を発生して
いた).
* extmk.rb.in: 判定した値をファイルにキャッシュするようにした.
* assoc.c (to_a): to_aメソッドが再定義されていなかった.
* eval.c (rb_eval): 初期化されていないローカル変数へのアクセスを引
数の無いメソッド呼び出しと解釈する.ただし,(現状では)メソッドが
定義されていない場合,エラーにせず変数未初期化のwaringを出して
nilを返している.「ruby -pe print」などが実行できるという意味で
はありがたいこの仕様は,しかし今後の検討が必要である.-- メソッ
ド呼び出しとするのを止めるか(以前の仕様),いつもメソッド呼び出し
とする(未定義ならばエラー)か,今の仕様で行くか.
* eval.c (rb_eval): 初期化されていないローカル変数へのアクセスで
(evalなどで)初期化された事が分かった時には以後初期化されたローカ
ル変数とみなす.
Wed Jun 7 11:58:12 1995 Yukihiro Matsumoto <matz@ix-02>
* eval.c (rb_fail): 例外処理後も`$!'をクリアしないように.
(rb_fail): `$!'変数に最後に改行を追加しない.
* io.c (Fprint): privateメソッドに変更.引数を取らない時の動作を変
更(`$_'を出力する).
(Fio_print): 出力先指定のprintメソッド.
(Fio_printf): 出力先指定のprintfメソッド.
* parse.y: not演算子の追加.優先順位の低い`!'演算子.
Mon Jun 5 19:00:55 1995 Yukihiro Matsumoto <matz@ix-02>
* version 0.78
Fri Jun 2 17:52:03 1995 Yukihiro Matsumoto <matz@ix-02>
* ruby.c (proc_options): -Iオプションで`$:'への追加される順番を修
正した.
Fri Jun 2 00:36:34 1995 Yukihiro Matsumoto (matz@dyna)
* parse.y: while修飾子の動作を通常のwhileと同じにした.ただし,
begin式へのwhile修飾子だけはdo..while型のループとなる.
Wed May 31 18:36:30 1995 Yukihiro Matsumoto <matz@ix-02>
* version 0.77
Mon May 29 18:39:37 1995 Yukihiro Matsumoto <matz@ix-02>
* ext/extmk.rb.in (install): 拡張モジュールもインストールできるよ
うに.
Fri May 26 14:43:01 1995 Yukihiro Matsumoto <matz@ix-02>
* process.c (Fsystem): 戻り値をサブプロセスの失敗/成功を表す真偽値
にした.終了ステータスは`$?'で得る.
Tue May 23 10:58:11 1995 Yukihiro Matsumoto <matz@ix-02>
* string.c (Fstr_upto): 無限ループに陥らないように.
* parse.y (cond): `||'などの右辺に制御式が書けるように,条件式がか
ならずしも値を持たなくても良いようにした.
* ext/marshal/marshal.c: オブジェクトの読み書きをメソッドの再定義
でコントロールできるように.インスタンスが`_dump_to'というメソッ
ドを定義している時はそちらを使うように.
* ext/extmk.rb.in: static linkも設定できるような仕様にした.
ext/Setupというファイルにディレクトリ名を記述するとそのディレク
トリに存在するモジュールはstatic linkされる(はず).
* eval.c (rb_eval): `..'を文法に組み込み,`..'と`...'の動作をperl
に合わせた.
Sat May 20 01:22:48 1995 Yukihiro Matsumoto (matz@dyna)
* io.c (select): timeout時と割込み時の動作の明確化.
Co-authored-by: Takahasi Mamoru <taka@soum.co.jp>
Co-authored-by: Yasuo OHBA <jammy@csg.mes.co.jp>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base64.rb | 55 | ||||
-rw-r--r-- | lib/find.rb | 38 | ||||
-rw-r--r-- | lib/getopts.rb | 117 | ||||
-rw-r--r-- | lib/mailread.rb | 45 | ||||
-rw-r--r-- | lib/parsearg.rb | 69 | ||||
-rw-r--r-- | lib/parsedate.rb | 42 | ||||
-rw-r--r-- | lib/tk.rb | 1215 | ||||
-rw-r--r-- | lib/tkcanvas.rb | 318 | ||||
-rw-r--r-- | lib/tkclass.rb | 36 | ||||
-rw-r--r-- | lib/tkentry.rb | 74 | ||||
-rw-r--r-- | lib/tktext.rb | 160 |
11 files changed, 2169 insertions, 0 deletions
diff --git a/lib/base64.rb b/lib/base64.rb new file mode 100644 index 0000000000..a6bf1adf92 --- /dev/null +++ b/lib/base64.rb @@ -0,0 +1,55 @@ +def decode64(str) + e = -1; + c = "," + string='' + for line in str.split("\n") + line.sub!(/=+$/, '') + line.tr! 'A-Za-z0-9+/', "\000-\377" + line.each_byte { |ch| + n +=1 + e +=1 + if e==0 + c = ch << 2 + elsif e==1 + c |= ch >>4 + string += [c].pack('c') + c = ch << 4 + elsif e == 2 + c |= ch >> 2 + string += [c].pack('c'); + c = ch << 6 + elsif e==3 + c |= ch + string += [c].pack('c') + e = -1 + end + } + end + return string +end + +def j2e(str) + while str =~ /\033\$B([^\033]*)\033\(B/ + s = $1 + pre, post = $`, $' + s.gsub!(/./) { |ch| + (ch[0]|0x80).chr + } + str = pre + s + post + end +# str.gsub!(/\033\$B([^\033]*)\033\(B/) { +# $1.gsub!(/./) { |ch| +# (ch[0]|0x80).chr +# } +# } + str +end + +def decode_b(str) + str.gsub!(/=\?ISO-2022-JP\?B\?([!->@-~]+)\?=/) { + decode64($1) + } + str.gsub!(/\n/, ' ') + str.gsub!(/\0/, '') + j2e(str) +end diff --git a/lib/find.rb b/lib/find.rb new file mode 100644 index 0000000000..340461c653 --- /dev/null +++ b/lib/find.rb @@ -0,0 +1,38 @@ +# Usage: +# require "find.rb" +# +# Find.find('/foo','/bar') {|f| ...} +# or +# include Find +# find('/foo','/bar') {|f| ...} +# + +module Find + extend Find + + def findpath(path, ary) + ary.push(path) + d = Dir.open(path) + for f in d + continue if f =~ /^\.\.?$/ + f = path + "/" + f + if File.directory? f + findpath(f, ary) + else + ary.push(f) + end + end + end + private :findpath + + def find(*path) + ary = [] + for p in path + findpath(p, ary) + for f in ary + yield f + end + end + end + module_function :find +end diff --git a/lib/getopts.rb b/lib/getopts.rb new file mode 100644 index 0000000000..37fd3dc69d --- /dev/null +++ b/lib/getopts.rb @@ -0,0 +1,117 @@ +# +# getopts.rb - get options +# $Release Version: $ +# $Revision: 1.2 $ +# $Date: 1994/02/15 05:17:15 $ +# by Yasuo OHBA(STAFS Development Room) +# +# -- +# IvV̉͂, $OPT_?? ɒlZbg܂. +# ŵȂIvVw肳ꂽ nil Ԃ܂. +# Iꍇ, ZbgꂽIvV̐Ԃ܂. +# +# getopts(single_opts, *opts) +# +# ex. sample [options] filename +# options ... +# -f -x --version --geometry 100x200 -d unix:0.0 +# +# getopts("fx", "version", "geometry:", "d:") +# +# : +# -f -x (= -fx) ̗lȈꕶ̃IvV̎w܂. +# ňȂƂ nil ̎w肪Kvł. +# ȍ~: +# Ol[̃IvV, ̔IvV̎w܂. +# --version , --geometry 300x400 , -d host:0.0 ł. +# w ":" KtĂ. +# +# IvV̎w肪ꍇ, ϐ $OPT_?? non-nil , ̃I +# vV̈Zbg܂. +# -f -> $OPT_f = TRUE +# --geometry 300x400 -> $OPT_geometry = 300x400 +# +# - -- , ȍ~, SăIvV̉͂܂. +# + +$RCS_ID="$Header: /var/ohba/RCS/getopts.rb,v 1.2 1994/02/15 05:17:15 ohba Exp ohba $" + +def getopts(single_opts, *opts) + if (opts) + single_colon = "" + long_opts = [] + sc = 0 + for option in opts + if (option.length <= 2) + single_colon[sc, 0] = option[0, 1] + sc += 1 + else + long_opts.push(option) + end + end + end + + opts = {} + count = 0 + while ($ARGV.length != 0) + compare = nil + case $ARGV[0] + when /^--?$/ + $ARGV.shift + break + when /^--.*/ + compare = $ARGV[0][2, ($ARGV[0].length - 2)] + if (long_opts != "") + for option in long_opts + if (option[(option.length - 1), 1] == ":" && + option[0, (option.length - 1)] == compare) + if ($ARGV.length <= 1) + return nil + end + eval("$OPT_" + compare + " = " + '$ARGV[1]') + opts[compare] = TRUE + $ARGV.shift + count += 1 + break + elsif (option == compare) + eval("$OPT_" + compare + " = TRUE") + opts[compare] = TRUE + count += 1 + break + end + end + end + when /^-.*/ + for index in 1..($ARGV[0].length - 1) + compare = $ARGV[0][index, 1] + if (single_opts && compare =~ "[" + single_opts + "]") + eval("$OPT_" + compare + " = TRUE") + opts[compare] = TRUE + count += 1 + elsif (single_colon != "" && compare =~ "[" + single_colon + "]") + if ($ARGV[0][index..-1].length > 1) + eval("$OPT_" + compare + " = " + '$ARGV[0][(index + 1)..-1]') + opts[compare] = TRUE + count += 1 + elsif ($ARGV.length <= 1) + return nil + else + eval("$OPT_" + compare + " = " + '$ARGV[1]') + opts[compare] = TRUE + $ARGV.shift + count = count + 1 + end + break + end + end + else + break + end + + $ARGV.shift + if (!opts.includes(compare)) + return nil + end + end + return count +end diff --git a/lib/mailread.rb b/lib/mailread.rb new file mode 100644 index 0000000000..4b04445beb --- /dev/null +++ b/lib/mailread.rb @@ -0,0 +1,45 @@ +class Mail + + def Mail.new(f) + if !f.is_kind_of?(IO) + f = open(f, "r") + me = super + f.close + else + me = super + end + return me + end + + def initialize(f) + @header = {} + @body = [] + while f.gets() + $_.chop! + continue if /^From / # skip From-line + break if /^$/ # end of header + if /^(\S+):\s*(.*)/ + @header[attr = $1.capitalize] = $2 + elsif attr + sub(/^\s*/, '') + @header[attr] += "\n" + $_ + end + end + + return if ! $_ + + while f.gets() + break if /^From / + @body.push($_) + end + end + + def header + return @header + end + + def body + return @body + end + +end diff --git a/lib/parsearg.rb b/lib/parsearg.rb new file mode 100644 index 0000000000..e7e2b7a7f3 --- /dev/null +++ b/lib/parsearg.rb @@ -0,0 +1,69 @@ +# +# parseargs.rb - parse arguments +# $Release Version: $ +# $Revision: 1.3 $ +# $Date: 1994/02/15 05:16:21 $ +# by Yasuo OHBA(STAFS Development Room) +# +# -- +# ̉͂, $OPT_?? ɒlZbg܂. +# Iꍇ, ZbgꂽIvV̐Ԃ܂. +# +# parseArgs(argc, single_opts, *opts) +# +# ex. sample [options] filename +# options ... +# -f -x --version --geometry 100x200 -d unix:0.0 +# +# parseArgs(1, nil, "fx", "version", "geometry:", "d:") +# +# : +# IvVȊO̍Œ̐ +# : +# IvV̕KvcKKvȂ %TRUE łȂ %FALSE. +# O: +# -f -x (= -fx) ̗lȈꕶ̃IvV̎w܂. +# ňȂƂ nil ̎w肪Kvł. +# lȍ~: +# Ol[̃IvV, ̔IvV̎w܂. +# --version , --geometry 300x400 , -d host:0.0 ł. +# w ":" KtĂ. +# +# IvV̎w肪ꍇ, ϐ $OPT_?? non-nil , ̃I +# vV̈Zbg܂. +# -f -> $OPT_f = %TRUE +# --geometry 300x400 -> $OPT_geometry = 300x400 +# +# usage gꍇ, $USAGE usage() w肵܂. +# def usage() +# c +# end +# $USAGE = 'usage' +# usage , --help w肳ꂽ, Ԉwɕ\܂. +# +# - -- , ȍ~, SăIvV̉͂܂. +# + +$RCS_ID="$Header: /var/ohba/RCS/parseargs.rb,v 1.3 1994/02/15 05:16:21 ohba Exp ohba $" + +load("getopts.rb") + +def printUsageAndExit() + if $USAGE + apply($USAGE) + end + exit() +end + +def parseArgs(argc, nopt, single_opts, *opts) + if ((noOptions = getopts(single_opts, *opts)) == nil) + printUsageAndExit() + end + if (nopt && noOptions == 0) + printUsageAndExit() + end + if ($ARGV.length < argc) + printUsageAndExit() + end + return noOptions +end diff --git a/lib/parsedate.rb b/lib/parsedate.rb new file mode 100644 index 0000000000..3f4612ebe5 --- /dev/null +++ b/lib/parsedate.rb @@ -0,0 +1,42 @@ +module ParseDate + MONTHS = { + 'jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4, + 'may' => 5, 'jun' => 6, 'jul' => 7, 'aug' => 8, + 'sep' => 9, 'oct' =>10, 'nov' =>11, 'dec' =>12 } + MONTHPAT = MONTHS.keys.join('|') + DAYPAT = 'mon|tue|wed|thu|fri|sat|sun' + + def parsedate(date) + if date.sub!(/(#{DAYPAT})/i, ' ') + dayofweek = $1 + end + if date.sub!(/\s+(\d+:\d+(:\d+)?)/, ' ') + time = $1 + end + if date =~ /19(\d\d)/ + year = $1 + end + if date.sub!(/\s*(\d+)\s+(#{MONTHPAT})\S*\s+/i, ' ') + dayofmonth = $1 + monthname = $2 + elsif date.sub!(/\s*(#{MONTHPAT})\S*\s+(\d+)\s+/i, ' ') + monthname = $1 + dayofmonth = $2 + elsif date.sub!(/\s*(#{MONTHPAT})\S*\s+(\d+)\D+/i, ' ') + monthname = $1 + dayofmonth = $2 + elsif date.sub!(/\s*(\d\d?)\/(\d\d?)/, ' ') + month = $1 + dayofmonth = $2 + end + if monthname + month = MONTHS[monthname.downcase] + end + if ! year && date =~ /\d\d/ + year = $& + end + return year, month, dayofmonth + end + + module_function :parsedate +end diff --git a/lib/tk.rb b/lib/tk.rb new file mode 100644 index 0000000000..9c61269881 --- /dev/null +++ b/lib/tk.rb @@ -0,0 +1,1215 @@ +# +# tk.rb - Tk interface for ruby +# $Date: 1995/11/03 08:17:15 $ +# by Yukihiro Matsumoto <matz@caelum.co.jp> + +require "tkutil" + +trap "PIPE", proc{exit 0} +trap "EXIT", proc{Tk.tk_exit} + +module Tk + include TkUtil + extend Tk + + $0 =~ /\/(.*$)/ + + PORT = open(format("|%s -n %s", WISH_PATH, $1), "w+"); + def tk_write(*args) + printf PORT, *args; + PORT.print "\n" + PORT.flush + end + tk_write '\ +wm withdraw . +proc rb_out args { + puts [format %%s $args] + flush stdout +} +proc tkerror args { exit } +proc keepalive {} { rb_out alive; after 120000 keepalive} +after 120000 keepalive' + + READABLE = [] + READ_CMD = {} + + def file_readable(port, cmd) + READABLE.push port + READ_CMD[port] = cmd + end + + WRITABLE = [] + WRITE_CMD = {} + def file_writable + WRITABLE.push port + WRITE_CMD[port] = cmd + end + module_function :file_readable, :file_writable + + file_readable PORT, proc { + exit if not PORT.gets + Tk.dispatch($_.chop!) + } + + def tk_exit + PORT.print "exit\n" + PORT.close + end + + def error_at + n = 1 + while c = caller(n) + break if c !~ /tk\.rb:/ + n+=1 + end + c + end + + def tk_tcl2ruby(val) + case val + when /^-?\d+$/ + val.to_i + when /^\./ + $tk_window_list[val] + when /^rb_out (c\d+)/ + $tk_cmdtbl[$1] + when / / + val.split.collect{|elt| + tk_tcl2ruby(elt) + } + when /^-?\d+\.\d*$/ + val.to_f + else + val + end + end + + def tk_split_list(str) + idx = str.index('{') + return tk_tcl2ruby(str) if not idx + + list = tk_tcl2ruby(str[0,idx]) + str = str[idx+1..-1] + i = -1 + brace = 1 + str.each_byte {|c| + i += 1 + brace += 1 if c == ?{ + brace -= 1 if c == ?} + break if brace == 0 + } + if str[0, i] == ' ' + list.push ' ' + else + list.push tk_split_list(str[0, i]) + end + list += tk_split_list(str[i+1..-1]) + list + end + private :tk_tcl2ruby, :tk_split_list + + def bool(val) + case bool + when "1", 1, 'yes', 'true' + TRUE + else + FALSE + end + end + def number(val) + case val + when /^-?\d+$/ + val.to_i + when /^-?\d+\.\d*$/ + val.to_f + else + val + end + end + def string(val) + if val == "{}" + '' + elsif val[0] == ?{ + val[1..-2] + else + val + end + end + def list(val) + tk_split_list(val) + end + def window(val) + $tk_window_list[val] + end + def procedure(val) + if val =~ /^rb_out (c\d+)/ + $tk_cmdtbl[$1] + else + nil + end + end + private :bool, :number, :string, :list, :window, :procedure + + # mark for non-given arguments + None = Object.new + def None.to_s + 'None' + end + + $tk_event_queue = [] + def tk_call(*args) + args = args.collect{|s| + continue if s == None + if s == FALSE + s = "0" + elsif s == TRUE + s = "1" + elsif s.is_kind_of?(TkObject) + s = s.path + else + s = s.to_s + s.gsub!(/[{}]/, '\\\\\0') + end + "{#{s}}" + } + str = args.join(" ") + tk_write 'if [catch {%s} var] {puts "!$var"} {puts "=$var@@"};flush stdout', str + while PORT.gets + $_.chop! + if /^=(.*)@@$/ + val = $1 + break + elsif /^=/ + val = $' + "\n" + while TRUE + PORT.gets + fail 'wish closed' if not $_ + if ~/@@$/ + val += $' + return val + else + val += $_ + end + end + elsif /^!/ + $@ = error_at + msg = $' + if msg =~ /unknown option "-(.*)"/ + fail format("undefined method `%s' for %s(%s)'", $1, self, self.type) + else + fail format("%s - %s", self.type, msg) + end + end + $tk_event_queue.push $_ + end + + while ev = $tk_event_queue.shift + Tk.dispatch ev + end + fail 'wish closed' if not $_ +# tk_split_list(val) + val + end + + def hash_kv(keys) + conf = [] + if keys + for k, v in keys + conf.push("-#{k}") + v = install_cmd(v) if v.type == Proc + conf.push(v) + end + end + conf + end + private :tk_call, :error_at, :hash_kv + + $tk_cmdid = "c00000" + def install_cmd(cmd) + return '' if cmd == '' # uninstall cmd + id = $tk_cmdid + $tk_cmdid = $tk_cmdid.next + $tk_cmdtbl[id] = cmd + @cmdtbl = [] if not @cmdtbl + @cmdtbl.push id + return format('rb_out %s', id) + end + def uninstall_cmd(id) + $tk_cmdtbl[id] = nil + end + private :install_cmd, :uninstall_cmd + + $tk_window_list = {} + class Event + def initialize(seq,b,f,h,k,s,t,w,x,y,aa,ee,kk,nn,ww,tt,xx,yy) + @serial = seq + @num = b + @focus = (f == 1) + @height = h + @keycode = k + @state = s + @time = t + @width = w + @x = x + @y = y + @char = aa + @send_event = (ee == 1) + @keysym = kk + @keysym_num = nn + @type = tt + @widget = ww + @x_root = xx + @y_root = yy + end + attr :serial + attr :num + attr :focus + attr :height + attr :keycode + attr :state + attr :time + attr :width + attr :x + attr :y + attr :char + attr :send_event + attr :keysym + attr :keysym_num + attr :type + attr :widget + attr :x_root + attr :y_root + end + + def install_bind(cmd) + id = install_cmd(proc{|args| + TkUtil.eval_cmd cmd, Event.new(*args) + }) + id + " %# %b %f %h %k %s %t %w %x %y %A %E %K %N %W %T %X %Y" + end + + def _bind(path, context, cmd) + begin + id = install_bind(cmd) + tk_call 'bind', path, "<#{context}>", id + rescue + $tk_cmdtbl[id] = nil + fail + end + end + private :install_bind, :_bind + + def bind_all(context, cmd=Proc.new) + _bind 'all', context, cmd + end + + $tk_cmdtbl = {} + + def after(ms, cmd=Proc.new) + myid = $tk_cmdid + tk_call 'after', ms, + install_cmd(proc{ + TkUtil.eval_cmd cmd + uninstall_cmd myid + }) + end + + def update(idle=nil) + if idle + tk_call 'update', 'idletasks' + else + tk_call 'update' + end + end + + def dispatch(line) + if line =~ /^c\d+/ + cmd = $& + fail "no command `#{cmd}'" if not $tk_cmdtbl[cmd] + args = tk_split_list($') + TkUtil.eval_cmd $tk_cmdtbl[cmd], *args + elsif line =~ /^alive$/ + # keep alive, do nothing + else + fail "malformed line <#{line}>" + end + end + + def mainloop + begin + tk_write 'after idle {wm deiconify .}' + while TRUE + rf, wf = select(READABLE, WRITABLE) + for f in rf + READ_CMD[f].call(f) if READ_CMD[f] + if f.closed? + READABLE.delete f + READ_CMD[f] = nil + end + end + for f in wf + WRITE_CMD[f].call(f) if WRITE_CMD[f] + if f.closed? + WRITABLE.delete f + WRITE_CMD[f] = nil + end + end + end + rescue + exit if $! =~ /^Interrupt/ + fail + ensure + tk_exit + end + end + + def root + $tk_root + end + + module_function :after, :update, :dispatch, :mainloop, :root + + module Scrollable + def xscrollcommand(cmd) + configure_cmd 'xscrollcommand', cmd + end + def yscrollcommand(cmd) + configure_cmd 'yscrollcommand', cmd + end + end + + module Wm + def aspect(*args) + w = window(tk_call('wm', 'grid', path, *args)) + w.split.collect{|s|s.to_i} if args.length == 0 + end + def client(name=None) + tk_call 'wm', 'client', path, name + end + def colormapwindows(*args) + list(tk_call('wm', 'colormapwindows', path, *args)) + end + def wm_command(value=None) + string(tk_call('wm', 'command', path, value)) + end + def deiconify + tk_call 'wm', 'deiconify', path + end + def focusmodel(*args) + tk_call 'wm', 'focusmodel', path, *args + end + def frame + tk_call 'wm', 'frame', path + end + def geometry(*args) + list(tk_call('wm', 'geometry', path, *args)) + end + def grid(*args) + w = tk_call('wm', 'grid', path, *args) + list(w) if args.size == 0 + end + def group(*args) + tk_call 'wm', 'path', path, *args + end + def iconbitmap(*args) + tk_call 'wm', 'bitmap', path, *args + end + def iconify + tk_call 'wm', 'iconify' + end + def iconmask(*args) + tk_call 'wm', 'iconmask', path, *args + end + def iconname(*args) + tk_call 'wm', 'iconname', path, *args + end + def iconposition(*args) + w = tk_call('wm', 'iconposition', path, *args) + list(w) if args.size == 0 + end + def iconwindow(*args) + tk_call 'wm', 'iconwindow', path, *args + end + def maxsize(*args) + w = tk_call('wm', 'maxsize', path, *args) + list(w) if not args.size == 0 + end + def minsize(*args) + w = tk_call('wm', 'minsize', path, *args) + list(w) if args.size == 0 + end + def overrideredirect(bool=None) + if bool == None + bool(tk_call('wm', 'overrideredirect', path)) + else + tk_call 'wm', 'overrideredirect', path, bool + end + end + def positionfrom(*args) + tk_call 'wm', 'positionfrom', path, *args + end + def protocol(name, func=None) + func = install_cmd(func) if not func == None + tk_call 'wm', 'command', path, name, func + end + def resizable(*args) + w = tk_call('wm', 'resizable', path, *args) + if args.length == 0 + list(w).collect{|e| bool(e)} + end + end + def sizefrom(*args) + list(tk_call('wm', 'sizefrom', path, *args)) + end + def state + tk_call 'wm', 'state', path + end + def title(*args) + tk_call 'wm', 'title', path, *args + end + def transient(*args) + tk_call 'wm', 'transient', path, *args + end + def withdraw + tk_call 'wm', 'withdraw', path + end + end +end + +module TkSelection + include Tk + extend Tk + def clear(win=Tk.root) + tk_call 'selection', 'clear', win.path + end + def get(type=None) + tk_call 'selection', 'get', type + end + def TkSelection.handle(win, func, type=None, format=None) + id = install_cmd(func) + tk_call 'selection', 'handle', win.path, id, type, format + end + def handle(func, type=None, format=None) + TkSelection.handle self, func, type, format + end + def TkSelection.own(win, func=None) + id = install_cmd(func) + tk_call 'selection', 'own', win.path, id + end + def own(func=None) + TkSelection.own self, func + end + + module_function :clear, :get +end + +module TkWinfo + include Tk + extend Tk + def TkWinfo.atom(name) + tk_call 'winfo', name + end + def winfo_atom(name) + TkWinfo.atom name + end + def TkWinfo.atomname(id) + tk_call 'winfo', id + end + def winfo_atomname(id) + TkWinfo.atomname id + end + def TkWinfo.cells(window) + number(tk_call('winfo', window.path)) + end + def winfo_cells + TkWinfo.cells self + end + def TkWinfo.children(window) + c = tk_call('winfo', 'children', window.path) + list(c) + end + def winfo_children + TkWinfo.children self + end + def TkWinfo.classname(window) + tk_call 'winfo', 'class', window.path + end + def winfo_classname + TkWinfo.classname self + end + def TkWinfo.containing(rootX, rootY) + path = tk_call('winfo', 'class', window.path) + window(path) + end + def winfo_containing(x, y) + TkWinfo.containing x, y + end + def TkWinfo.depth(window) + number(tk_call('winfo', 'depth', window.path)) + end + def winfo_depth(window) + TkWinfo.depth self + end + def TkWinfo.exists(window) + bool(tk_call('winfo', 'exists', window.path)) + end + def winfo_exists(window) + TkWinfo.exists self + end + def TkWinfo.fpixels(window, number) + number(tk_call('winfo', 'fpixels', window.path, number)) + end + def winfo_fpixels(window, number) + TkWinfo.fpixels self + end + def TkWinfo.geometry(window) + list(tk_call('winfo', 'geometry', window.path)) + end + def winfo_geometry(window) + TkWinfo.geometry self + end + def TkWinfo.height(window) + number(tk_call('winfo', 'height', window.path)) + end + def winfo_height(window) + TkWinfo.height self + end + def TkWinfo.id(window) + number(tk_call('winfo', 'id', window.path)) + end + def winfo_id(window) + TkWinfo.id self + end + def TkWinfo.ismapped(window) + bool(tk_call('winfo', 'ismapped', window.path)) + end + def winfo_ismapped(window) + TkWinfo.ismapped self + end + def TkWinfo.parent(window) + window(tk_call('winfo', 'parent', window.path)) + end + def winfo_parent(window) + TkWinfo.parent self + end + def TkWinfo.widget(id) + window(tk_call('winfo', 'pathname', id)) + end + def winfo_widget(id) + TkWinfo.widget id + end + def TkWinfo.pixels(window, number) + number(tk_call('winfo', 'pixels', window.path, number)) + end + def winfo_pixels(window, number) + TkWinfo.pixels self, number + end + def TkWinfo.reqheight(window) + number(tk_call('winfo', 'reqheight', window.path)) + end + def winfo_reqheight(window) + TkWinfo.reqheight self + end + def TkWinfo.reqwidth(window) + number(tk_call('winfo', 'reqwidth', window.path)) + end + def winfo_reqwidth(window) + TkWinfo.reqwidth self + end + def TkWinfo.rgb(window, color) + list(tk_call('winfo', 'rgb', window.path, color)) + end + def winfo_rgb(window, color) + TkWinfo.rgb self, color + end + def TkWinfo.rootx(window) + number(tk_call('winfo', 'rootx', window.path)) + end + def winfo_rootx(window) + TkWinfo.rootx self + end + def TkWinfo.rooty(window) + number(tk_call('winfo', 'rooty', window.path)) + end + def winfo_rooty(window) + TkWinfo.rooty self + end + def TkWinfo.screen(window) + tk_call 'winfo', 'screen', window.path + end + def winfo_screen(window) + TkWinfo.screen self + end + def TkWinfo.screencells(window) + number(tk_call('winfo', 'screencells', window.path)) + end + def winfo_screencells(window) + TkWinfo.screencells self + end + def TkWinfo.screendepth(window) + number(tk_call('winfo', 'screendepth', window.path)) + end + def winfo_screendepth(window) + TkWinfo.screendepth self + end + def TkWinfo.screenheight (window) + number(tk_call('winfo', 'screenheight', window.path)) + end + def winfo_screenheight(window) + TkWinfo.screenheight self + end + def TkWinfo.screenmmheight(window) + number(tk_call('winfo', 'screenmmheight', window.path)) + end + def winfo_screenmmheight(window) + TkWinfo.screenmmheight self + end + def TkWinfo.screenmmwidth(window) + number(tk_call('winfo', 'screenmmwidth', window.path)) + end + def winfo_screenmmwidth(window) + TkWinfo.screenmmwidth self + end + def TkWinfo.screenvisual(window) + tk_call 'winfo', 'screenvisual', window.path + end + def winfo_screenvisual(window) + TkWinfo.screenvisual self + end + def TkWinfo.screenwidth(window) + number(tk_call('winfo', 'screenwidth', window.path)) + end + def winfo_screenwidth(window) + TkWinfo.screenwidth self + end + def TkWinfo.toplevel(window) + window(tk_call('winfo', 'toplevel', window.path)) + end + def winfo_toplevel(window) + TkWinfo.toplevel self + end + def TkWinfo.visual(window) + tk_call 'winfo', 'visual', window.path + end + def winfo_visual(window) + TkWinfo.visual self + end + def TkWinfo.vrootheigh(window) + number(tk_call('winfo', 'vrootheight', window.path)) + end + def winfo_vrootheight(window) + TkWinfo.vrootheight self + end + def TkWinfo.vrootwidth(window) + number(tk_call('winfo', 'vrootwidth', window.path)) + end + def winfo_vrootwidth(window) + TkWinfo.vrootwidth self + end + def TkWinfo.vrootx(window) + number(tk_call('winfo', 'vrootx', window.path)) + end + def winfo_vrootx(window) + TkWinfo.vrootx self + end + def TkWinfo.vrooty(window) + number(tk_call('winfo', 'vrooty', window.path)) + end + def winfo_vrooty(window) + TkWinfo.vrooty self + end + def TkWinfo.width(window) + number(tk_call('winfo', 'width', window.path)) + end + def winfo_width(window) + TkWinfo.width self + end + def TkWinfo.x(window) + number(tk_call('winfo', 'x', window.path)) + end + def winfo_x(window) + TkWinfo.x self + end + def TkWinfo.y(window) + number(tk_call('winfo', 'y', window.path)) + end + def winfo_y(window) + TkWinfo.y self + end +end + +module TkPack + include Tk + extend Tk + def configure(win, *args) + if args[-1].is_kind_of(Hash) + keys = args.pop + end + wins = [win.epath] + for i in args + wins.push i.epath + end + tk_call "pack", 'configure', *(wins+hash_kv(keys)) + end + + def forget(*args) + tk_call 'pack', 'forget' *args + end + + def propagate(master, bool=None) + bool(tk_call('pack', 'propagate', mastaer.epath, bool)) + end + module_function :configure, :forget, :propagate +end + +module TkOption + include Tk + extend Tk + def add pat, value, pri=None + tk_call 'option', 'add', pat, value, pri + end + def clear + tk_call 'option', 'clear' + end + def get win, classname, name + tk_call 'option', 'get', classname, name + end + def readfile file, pri=None + tk_call 'option', 'readfile', file, pri + end + module_function :add, :clear, :get, :readfile +end + +class TkObject:TkKernel + include Tk + + def path + return @path + end + + def epath + return @path + end + + def tk_send(cmd, *rest) + tk_call path, cmd, *rest + end + private :tk_send + + def method_missing(id, *args) + if (args.length == 1) + configure id.id2name, args[0] + else + $@ = error_at + super + end + end + + def []=(id, val) + configure id, val + end + + def configure(slot, value) + if value == FALSE + value = "0" + elsif value.type == Proc + value = install_cmd(value) + end + tk_call path, 'configure', "-#{slot}", value + end + + def configure_cmd(slot, value) + configure slot, install_cmd(value) + end + + def bind(context, cmd=Proc.new) + _bind path, context, cmd + end +end + +class TkWindow:TkObject + $tk_window_id = "w00000" + def initialize(parent=nil, keys=nil) + id = $tk_window_id + $tk_window_id = $tk_window_id.next + if !parent or parent == Tk.root + @path = format(".%s", id); + else + @path = format("%s.%s", parent.path, id) + end + $tk_window_list[@path] = self + create_self + if keys + tk_call @path, 'configure', *hash_kv(keys) + end + end + + def create_self + end + private :create_self + + def pack(keys = nil) + tk_call 'pack', epath, *hash_kv(keys) + self + end + + def unpack(keys = nil) + tk_call 'pack', 'forget', epath + self + end + + def focus + tk_call 'focus', path + self + end + + def grab(*args) + if !args or args.length == 0 + tk_call 'grab', 'set', path + elsif args.length == 1 + case args[0] + when 'global' + tk_call 'grab', 'set', '-global', path + else + val = tk_call('grab', arg[0], path) + end + case args[0] + when 'current' + return window(val) + when 'status' + return val + end + else + fail 'wrong # of args' + end + end + + def lower(below=None) + tk_call 'lower', path, below + self + end + def raise(above=None) + tk_call 'raise', path, above + self + end + + def command(cmd) + configure_cmd 'command', cmd + end + + def colormodel model=None + tk_call 'tk', 'colormodel', path, model + self + end + + def destroy + tk_call 'destroy', path + if @cmdtbl + for id in @cmdtbl + uninstall_cmd id + end + end + $tk_window_list[path] = nil + end +end + +class TkRoot:TkWindow + include Wm + def TkRoot.new + return $tk_root if $tk_root + super + end + def path + "." + end + $tk_root = TkRoot.new + $tk_window_list['.'] = $tk_root +end + +class TkToplevel:TkWindow + include Wm + def initialize(parent=nil, screen=nil, classname=nil) + @screen = screen if screen + @classname = classname if classname + super + end + + def create_self + s = [] + s.push "-screen #@screen" if @screen + s.push "-class #@classname" if @classname + tk_call 'toplevel', path, *s + end +end + +class TkFrame:TkWindow + def create_self + tk_call 'frame', @path + end +end + +class TkLabel:TkWindow + def create_self + tk_call 'label', @path + end + def textvariable(v) + vn = @path + v.id2name + vset = format("global {%s}; set {%s}", vn, vn) + tk_call vset, eval(v.id2name).inspect + trace_var v, proc{|val| + tk_call vset, val.inspect + } + configure 'textvariable', vn + end +end + +class TkButton:TkLabel + def create_self + tk_call 'button', @path + end + def invoke + tk_send 'invoke' + end + def flash + tk_send 'flash' + end +end + +class TkRadioButton:TkButton + def create_self + tk_call 'radiobutton', @path + end + def deselect + tk_send 'deselect' + end + def select + tk_send 'select' + end + def variable(v) + vn = v.id2name; vn =~ /^./ + vn = 'btns_selected_' + $' + trace_var v, proc{|val| + tk_call 'set', vn, val + } + @var_id = install_cmd(proc{|name1,| + val = tk_call('set', name1) + eval(format("%s = '%s'", v.id2name, val)) + }) + tk_call 'trace variable', vn, 'w', @var_id + configure 'variable', vn + end + def destroy + tk_call 'trace vdelete', vn, 'w', @var_id + super + end +end + +class TkCheckButton:TkRadioButton + def create_self + tk_call 'checkbutton', @path + end + def toggle + tk_send 'toggle' + end +end + +class TkMessage:TkLabel + def create_self + tk_call 'message', @path + end +end + +class TkScale:TkWindow + def create_self + tk_call 'scale', path + end + + def get + number(tk_send('get')) + end + + def set(val) + tk_send "set", val + end + + def value + get + end + + def value= (val) + set val + end +end + +class TkScrollbar:TkWindow + def create_self + tk_call 'scrollbar', path + end + + def get + ary1 = tk_send('get', path).split + ary2 = [] + for i in ary1 + push number(i) + end + ary2 + end + + def set(first, last) + tk_send "set", first, last + end +end + +# abstract class for Text and Listbox +class TkTextWin:TkWindow + def bbox(index) + tk_send 'bbox', index + end + def delete(first, last=None) + tk_send 'delete', first, last + end + def get(*index) + tk_send 'get', *index + end + def insert(index, *rest) + tk_send 'insert', index, *rest + end + def index(index) + tk_send 'index', index + end + def insert(index, chars, *args) + tk_send 'insert', index, chars, *args + end + def scan_mark(x, y) + tk_send 'scan', 'mark', x, y + end + def scan_dragto(x, y) + tk_send 'scan', 'dragto', x, y + end + def see(index) + tk_send 'see', index + end +end + +class TkListbox:TkTextWin + def create_self + tk_call 'listbox', path + end + + def nearest(y) + tk_send 'nearest', y + end + def selection_anchor(index) + tk_send 'selection', 'anchor', index + end + def selection_clear(first, last=None) + tk_send 'selection', 'clear', first, last + end + def selection_includes + bool(tk_send('selection', 'includes')) + end + def selection_set(first, last=None) + tk_send 'selection', 'set', first, last + end + def xview(cmd, index, *more) + tk_send 'xview', cmd, index, *more + end + def yview(cmd, index, *more) + tk_send 'yview', cmd, index, *more + end +end + +class TkMenu:TkWindow + def create_self + tk_call 'menu', path + end + def activate(index) + tk_send 'activate', index + end + def add(type, keys=nil) + tk_send 'add', type, *kv_hash(keys) + end + def index(index) + tk_send 'index', index + end + def invoke + tk_send 'invoke' + end + def insert(index, type, keys=nil) + tk_send 'add', index, type, *kv_hash(keys) + end + def post(x, y) + tk_send 'post', x, y + end + def postcascade(index) + tk_send 'postcascade', index + end + def postcommand(cmd) + configure_cmd 'postcommand', cmd + end + def menutype(index) + tk_send 'type', index + end + def unpost + tk_send 'unpost' + end + def yposition(index) + number(tk_send('yposition', index)) + end +end + +class TkMenubutton:TkLabel + def create_self + tk_call 'menubutton', path + end +end + +module TkComposite + def initialize(parent=nil, *args) + @frame = TkFrame.new(parent) + @path = @epath = @frame.path + initialize_composite(*args) + end + + def epath + @epath + end + + def initialize_composite(*args) end + private :initialize_composite + + def delegate(option, *wins) + @delegates = {} if not @delegates + @delegates['DEFAULT'] = @frame + if option.is_kind_of? String + @delegates[option] = wins + else + for i in option + @delegates[i] = wins + end + end + end + + def configure(slot, value) + if @delegates and @delegates[slot] + for i in @delegates[slot] + if not i + i = @delegates['DEFALUT'] + redo + else + last = i.configure(slot, value) + end + end + last + else + super + end + end +end + +autoload :TkCanvas, 'tkcanvas' +autoload :TkImage, 'tkcanvas' +autoload :TkBitmapImage, 'tkcanvas' +autoload :TkPhotoImage, 'tkcanvas' +autoload :TkEntry, 'tkentry' +autoload :TkText, 'tktext' diff --git a/lib/tkcanvas.rb b/lib/tkcanvas.rb new file mode 100644 index 0000000000..33b28e3eff --- /dev/null +++ b/lib/tkcanvas.rb @@ -0,0 +1,318 @@ +# +# tkcanvas.rb - Tk canvas classes +# $Date: 1995/11/11 11:17:15 $ +# by Yukihiro Matsumoto <matz@caelum.co.jp> + +require "tk" + +class TkCanvas:TkWindow + def create_self + tk_call 'canvas', path + end + def tagid(tag) + if tag.is_kind_of?(TkcItem) + tag.id + else + tag + end + end + private :tagid + def addtag(tag, *args) + tk_send 'addtag', tagid(tag), *args + end + def addtag_above(tagOrId) + addtag('above', tagOrId) + end + def addtag_all + addtag('all') + end + def addtag_below(tagOrId) + addtag('below', tagOrId) + end + def addtag_closest(x, y, halo=None, start=None) + addtag('closest', x, y, halo, start) + end + def addtag_enclosed(x1, y1, x2, y2) + addtag('enclosed', x1, y1, x2, y2) + end + def addtag_overlapping(x1, y1, x2, y2) + addtag('overlapping', x1, y1, x2, y2) + end + def addtag_withtag(tagOrId) + addtag('withtag', tagOrId) + end + def bbox(tag) + list(tk_send('bbox', tagid(tag))) + end + def itembind(tag, seq, cmd=Proc.new) + id = install_cmd(cmd) + tk_send 'bind', tagid(tag), "<#{seq}>", id + @cmdtbl.push id + end + def canvasx(x, *args) + tk_send 'canvasx', x, *args + end + def canvasy(y, *args) + tk_send 'canvasy', y, *args + end + def coords(tag, *args) + tk_send 'coords', tagid(tag), *args + end + def dchars(tag, first, last=None) + tk_send 'dchars', tagid(tag), first, last + end + def delete(*args) + tk_send 'delete', *args + end + alias remove delete + def dtag(tag, tag_to_del=None) + tk_send 'dtag', tagid(tag), tag_to_del + end + def find(*args) + tk_send 'find', *args + end + def itemfocus(tag) + tk_send 'find', tagid(tag) + end + def gettags(tag) + tk_send 'gettags', tagid(tag) + end + def icursor(tag, index) + tk_send 'icursor', tagid(tag), index + end + def index(tag) + tk_send 'index', tagid(tag), index + end + def lower(tag, below=None) + tk_send 'lower', tagid(tag), below + end + def move(tag, x, y) + tk_send 'move', tagid(tag), x, y + end + def postscript(keys=None) + tk_call "pack", *hash_kv(keys) + end + def raise(tag, above=None) + tk_send 'raise', tagid(tag), above + end + def scale(tag, x, y, xs, ys) + tk_send 'scale', tagid(tag), x, y, xs, ys + end + def scan_mark(x, y) + tk_send 'scan', 'mark', x, y + end + def scan_dragto(x, y) + tk_send 'scan', 'dragto', x, y + end + def select(*args) + tk_send 'select', *args + end + def xview(index) + tk_send 'xview', index + end + def yview(index) + tk_send 'yview', index + end +end + +class TkcItem:TkObject + def initialize(parent, *args) + if not parent.is_kind_of?(TkCanvas) + fail format("%s need to be TkCanvas", parent.inspect) + end + @c = parent + @path = parent.path + if args[-1].type == Hash + keys = args.pop + end + @id = create_self(*args) + if keys + tk_call @path, 'itemconfigure', *hash_kv(keys) + end + end + def create_self(*args) end + private :create_self + def id + return @id + end + + def configure(slot, value) + tk_call path, 'itemconfigure', id, "-#{slot}", value + end + + def addtag(tag) + @c.addtag(tag, 'withtag', @id) + end + def bbox + @c.bbox(@id) + end + def bind(seq, cmd=Proc.new) + @c.itembind @id, seq, cmd + end + def coords(*args) + @c.coords @id, *args + end + def dchars(first, last=None) + @c.dchars @id, first, last + end + def dtag(ttd) + @c.dtag @id, ttd + end + def focus + @c.focus @id + end + def gettags + @c.gettags @id + end + def icursor + @c.icursor @id + end + def index + @c.index @id + end + def insert(beforethis, string) + @c.insert @id, beforethis, string + end + def lower(belowthis=None) + @c.lower @id, belowthis + end + def move(xamount, yamount) + @c.move @id, xamount, yamount + end + def raise(abovethis=None) + @c.raise @id, abovethis + end + def scale(xorigin, yorigin, xscale, yscale) + @c.scale @id, xorigin, yorigin, xscale, yscale + end + def type + @c.type @id + end + def destroy + tk_call path, 'delete', @id + end +end + +class TkcArc:TkcItem + def create_self(*args) + tk_call(@path, 'create', 'arc', *args) + end +end +class TkcBitmap:TkcItem + def create_self(*args) + tk_call(@path, 'create', 'bitmap', *args) + end +end +class TkcImage:TkcItem + def create_self(*args) + tk_call(@path, 'create', 'image', *args) + end +end +class TkcLine:TkcItem + def create_self(*args) + tk_call(@path, 'create', 'line', *args) + end +end +class TkcOval:TkcItem + def create_self(*args) + tk_call(@path, 'create', 'oval', *args) + end +end +class TkcPolygon:TkcItem + def create_self(*args) + tk_call(@path, 'create', 'polygon', *args) + end +end +class TkcText:TkcItem + def create_self(*args) + tk_call(@path, 'create', 'text', *args) + end +end +class TkcWindow:TkcItem + def create_self(*args) + tk_call(@path, 'create', 'window', *args) + end +end +class TkcGroup:TkcItem + $tk_group_id = 'tkg00000' + def create_self(*args) + @id = $tk_group_id + $tk_group_id = $tk_group_id.next + end + + def add(*tags) + for i in tags + i.addtag @id + end + end + def add(*tags) + for i in tags + i.addtag @id + end + end + def delete(*tags) + for i in tags + i.delete @id + end + end + def list + @c.find 'withtag', @id + end + alias remove delete +end + + +class TkImage:TkObject + include Tk + + $tk_image_id = 'i00000' + def initialize(keys=nil) + @path = $tk_image_id + $tk_image_id = $tk_image_id.next + tk_call 'image', @type, @path, *hash_kv(keys) + end + + def height + number(tk_call('image', 'height', @path)) + end + def type + tk_call('image', 'type', @path) + end + def width + number(tk_call('image', 'height', @path)) + end + + def TkImage.names + tk_call('image', 'names', @path).split + end + def TkImage.types + tk_call('image', 'types', @path).split + end +end + +class TkBitmapImage:TkImage + def initialize(*args) + @type = 'bitmap' + super + end +end + +class TkPhotoImage:TkImage + def initialize(*args) + @type = 'bitmap' + super + end + + def blank + tk_send 'blank' + end + def cget + tk_send 'cget' + end + def get(x, y) + tk_send 'get', x, y + end + def put(data, to=None) + tk_send 'put', data, to + end +end diff --git a/lib/tkclass.rb b/lib/tkclass.rb new file mode 100644 index 0000000000..10ecc80b20 --- /dev/null +++ b/lib/tkclass.rb @@ -0,0 +1,36 @@ +# +# tkclass.rb - Tk classes +# $Date: 1995/11/11 19:17:15 $ +# by Yukihiro Matsumoto <matz@caelum.co.jp> + +require "tk" + +TopLevel = TkToplevel +Frame = TkFrame +Label = TkLabel +Button = TkButton +Radiobutton = TkRadioButton +Checkbutton = TkCheckButton +Message = TkMessage +Entry = TkEntry +Text = TkText +Scale = TkScale +Scrollbar = TkScrollbar +Listbox = TkListbox +Menu = TkMenu +Menubutton = TkMenubutton +Canvas = TkCanvas +Arc = TkcArc +Bitmap = TkcBitmap +Line = TkcLine +Oval = TkcOval +Polygon = TkcPolygon +TextItem = TkcText +WindowItem = TkcWindow +Selection = TkSelection +Winfo = TkWinfo +Pack = TkPack + +def Mainloop + Tk.mainloop +end diff --git a/lib/tkentry.rb b/lib/tkentry.rb new file mode 100644 index 0000000000..dbd848d0ca --- /dev/null +++ b/lib/tkentry.rb @@ -0,0 +1,74 @@ +# +# tkentry.rb - Tk entry classes +# $Date: 1995/12/07 15:01:10 $ +# by Yukihiro Matsumoto <matz@caelum.co.jp> + +require 'tk.rb' + +class TkEntry:TkLabel + def create_self + tk_call 'entry', @path + end + def scrollcommand(cmd) + configure 'scrollcommand', cmd + end + + def delete(s, e=None) + if e + tk_send 'delete', s + else + tk_send 'delete', s, e + end + end + + def cursor + tk_send 'index', 'insert' + end + def cursor=(index) + tk_send 'icursor', index + end + def index(index) + tk_send 'index', index + end + def insert(text, pos=None) + if pos + tk_send 'icursor', pos + end + tk_send 'insert', 'insert', text + end + def mark(pos) + tk_send 'scan', 'mark', pos + end + def dragto(pos) + tk_send 'scan', 'dragto', pos + end + def select_adjust(index) + tk_send 'select', 'adjust', index + end + def select_clear + tk_send 'select', 'clear', 'end' + end + def select_from(index) + tk_send 'select', 'from', index + end + def select_present() + tk_send('select', 'present') == 1 + end + def select_range(s, e) + tk_send 'select', 'range', s, e + end + def select_to(index) + tk_send 'select', 'to', index + end + def xview(*index) + tk_send 'xview', *index + end + + def value + tk_send 'get' + end + def value= (val) + tk_send 'delete', 0, 'end' + tk_send 'insert', 0, val + end +end diff --git a/lib/tktext.rb b/lib/tktext.rb new file mode 100644 index 0000000000..e7a2be950f --- /dev/null +++ b/lib/tktext.rb @@ -0,0 +1,160 @@ +# +# tktext.rb - Tk text classes +# $Date: 1995/12/07 08:37:10 $ +# by Yukihiro Matsumoto <matz@caelum.co.jp> + +require 'tk.rb' + +class TkText:TkTextWin + include Scrollable + def create_self + tk_call 'text', @path + @tags = {} + end + def index(index) + tk_send 'index', index + end + def value + tk_send 'get', "1.0", "end" + end + def value= (val) + tk_send 'delete', "1.0", 'end' + tk_send 'insert', "1.0", val + end + def _addcmd(cmd) + @cmdtbl.push id + end + def _addtag(cmd) + @cmdtbl.push id + end + private :_addcmd, :_addtag + def tag_names + tk_send('tag', 'names').collect{|elt| + if not @tags[elt] + elt + else + @tags[elt] + end + } + end + def window_names + tk_send('window', 'names').collect{|elt| + if not @tags[elt] + elt + else + @tags[elt] + end + } + end + + def destroy + for t in @tags + t.destroy + end + super + end + + def backspace + self.delete 'insert' + end + + def compare(idx1, op, idx2) + bool(tk_send('compare', idx1, op, idx2)) + end + + def debug + bool(tk_send('debug')) + end + def debug=(boolean) + tk_send 'debug', boolean + end + + def yview(*what) + tk_send 'yview', *what + end + def yview_pickplace(*what) + tk_send 'yview', '-pickplace', *what + end +end + +class TkTextTag:TkObject + $tk_text_tag = 'tag0000' + def initialize(parent) + if not parent.is_kind_of?(TkText) + fail format("%s need to be TkText", parent.inspect) + end + @t = parent + @path = parent.path + @id = $tk_text_tag + $tk_text_tag = $tk_text_tag.next + @t._addtag id, self + end + def id + return @id + end + + def add(*index) + tk_call path, 'tag', 'add', @id, *index + end + + def configure(slot, value) + tk_call path, 'tag', 'configure', id, "-#{slot}", value + end + + def bind(seq, cmd=Proc.new) + id = install_cmd(cmd) + tk_call path, 'tag', 'bind', tag, "<#{seq}>", id + @t._addcmd cmd + end + + def lower(below=None) + tk_call path, 'tag', 'lower', below + end + + def destroy + tk_call path, 'tag', 'delete', @id + end +end + +class TkTextMark:TkObject + $tk_text_mark = 'mark0000' + def initialize(parent, index) + if not parent.is_kind_of?(TkText) + fail format("%s need to be TkText", parent.inspect) + end + @t = parent + @path = parent.path + @id = $tk_text_mark + $tk_text_mark = $tk_text_mark.next + tk_call @t, 'set', @id, index + @t._addtag id, self + end + def id + return @id + end + + def set(where) + tk_call path, 'mark', 'unset', @id, where + end + + def unset + tk_call path, 'mark', 'unset', @id + end + alias destroy unset +end + +class TkTextWindow:TkObject + def initialize(parent, index, *args) + if not parent.is_kind_of?(TkText) + fail format("%s need to be TkText", parent.inspect) + end + @t = parent + @path = parent.path + @index = index + tk_call @path, 'window', 'create', index, *args + end + + def configure(slot, value) + tk_call path, 'window', 'configure', @index, "-#{slot}", value + end +end |