From 6277a66deb30559a8ea991175c274e0fd899e48e Mon Sep 17 00:00:00 2001 From: nagai Date: Sat, 2 Aug 2003 09:58:13 +0000 Subject: * (bug fix) forgot to entry a widget class name of 'labelframe' widget * add demo-scripts to the JP/EN widget demos git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/sample/demos-jp/labelframe.rb | 98 ++++++++++++++++++++++++++++++++++++ ext/tk/sample/demos-jp/paned1.rb | 48 ++++++++++++++++++ ext/tk/sample/demos-jp/paned2.rb | 96 +++++++++++++++++++++++++++++++++++ ext/tk/sample/demos-jp/spin.rb | 68 +++++++++++++++++++++++++ ext/tk/sample/demos-jp/widget | 22 ++++++-- 5 files changed, 329 insertions(+), 3 deletions(-) create mode 100644 ext/tk/sample/demos-jp/labelframe.rb create mode 100644 ext/tk/sample/demos-jp/paned1.rb create mode 100644 ext/tk/sample/demos-jp/paned2.rb create mode 100644 ext/tk/sample/demos-jp/spin.rb (limited to 'ext/tk/sample/demos-jp') diff --git a/ext/tk/sample/demos-jp/labelframe.rb b/ext/tk/sample/demos-jp/labelframe.rb new file mode 100644 index 0000000000..044fcd23ae --- /dev/null +++ b/ext/tk/sample/demos-jp/labelframe.rb @@ -0,0 +1,98 @@ +# labelframe.rb +# +# This demonstration script creates a toplevel window containing +# several labelframe widgets. +# +# based on "Id: labelframe.tcl,v 1.2 2001/10/30 11:21:50 dkf Exp" + + +if defined?($labelframe_demo) && $labelframe_demo + $labelframe_demo.destroy + $labelframe_demo = nil +end + +$labelframe_demo = TkToplevel.new {|w| + title("Labelframe Demonstration") + iconname("labelframe") + positionWindow(w) +} + +# Some information +TkLabel.new($labelframe_demo, + :font=>$font, :wraplength=>'4i', :justify=>:left, + :text=><:top) +TkLabelFrame ウィジェットは関連する widget +群をまとめて取り扱うために用いられます。ラ +ベルは通常の文字列でも何らかのウィジェット +でもかまいません。もしあなたが使っている +Ruby にリンクされている Tk ライブラリが +labelframe ウィジェットを実装していない +場合、このデモはうまく動かないはずです。 +その場合には labelframe ウィジェットが実装 +されているようなより新しいバージョンの Tk +を組み合わせて試すようにしてください。 +EOL + +# The bottom buttons +TkFrame.new($labelframe_demo){|f| + pack(:side=>:bottom, :fill=>:x, :pady=>'2m') + + TkButton.new(f, :text=>'了解', :width=>15, :command=>proc{ + $labelframe_demo.destroy + $labelframe_demo = nil + }).pack(:side=>:left, :expand=>true) + + TkButton.new(f, :text=>'コード参照', :width=>15, :command=>proc{ + showCode 'labelframe' + }).pack(:side=>:left, :expand=>true) +} + +# Demo area +w = TkFrame.new($labelframe_demo).pack(:side=>:bottom, :fill=>:both, + :expand=>true) + +# A group of radiobuttons in a labelframe +TkLabelFrame.new(w, :text=>'選択値', + :padx=>2, :pady=>2) {|f| + grid(:row=>0, :column=>0, :pady=>'2m', :padx=>'2m') + + v = TkVariable.new + (1..4).each{|i| + TkRadiobutton.new(f, :text=>"This is value #{i}", + :variable=>v, :value=>i) { + pack(:side=>:top, :fill=>:x, :pady=>2) + } + } +} + + +# Using a label window to control a group of options. +$lfdummy = TkVariable.new(0) + +def lfEnableButtons(w) + TkWinfo.children(w).each{|child| + next if child.path =~ /\.cb$/ + if $lfdummy == 1 + child.state(:normal) + else + child.state(:disabled) + end + } +end + +TkLabelFrame.new(w, :pady=>2, :padx=>2){|f| + TkCheckButton.new(f, :widgetname=>'cb', :variable=>$lfdummy, + :text=>"オプションを使用", :padx=>0) {|cb| + command proc{lfEnableButtons(f)} + f.labelwidget(cb) + } + grid(:row=>0, :column=>1, :pady=>'2m', :padx=>'2m') + + %w(オプション1 オプション2 オプション3).each{|str| + TkCheckbutton.new(f, :text=>str).pack(:side=>:top, :fill=>:x, :pady=>2) + } + + lfEnableButtons(f) +} + +TkGrid.columnconfigure(w, [0,1], :weight=>1) diff --git a/ext/tk/sample/demos-jp/paned1.rb b/ext/tk/sample/demos-jp/paned1.rb new file mode 100644 index 0000000000..99e6b6cddb --- /dev/null +++ b/ext/tk/sample/demos-jp/paned1.rb @@ -0,0 +1,48 @@ +# paned1.rb +# +# This demonstration script creates a toplevel window containing +# a paned window that separates two windows horizontally. +# +# based on "Id: paned1.tcl,v 1.1 2002/02/22 14:07:01 dkf Exp" + +if defined?($paned1_demo) && $paned1_demo + $paned1_demo.destroy + $paned1_demo = nil +end + +$paned1_demo = TkToplevel.new {|w| + title("Horizontal Paned Window Demonstration") + iconname("paned1") + positionWindow(w) +} + +TkLabel.new($paned1_demo, + :font=>$font, :wraplength=>'4i', :justify=>:left, + :text=><:top) +下の色付けされた二つのウィンドウの間の仕切り枠は、一つの領域をそれぞれのウィンドウのために分割するためのものです。左ボタンで仕切りを操作すると、分割サイズ変更の操作途中では再表示はなされず、確定させたときに表示が更新されます。マウスによる仕切りの操作に追随してサイズを変更した表示がなわれるようにしたい場合は、マウスの中央ボタンを使ってください。 +もしあなたが使っている Ruby にリンクされている Tk ライブラリが panedwindow を実装していない +場合、このデモはうまく動かないはずです。その場合には panedwindow が実装されているような +より新しいバージョンの Tk を組み合わせて試す +ようにしてください。 +EOL + +# The bottom buttons +TkFrame.new($paned1_demo){|f| + pack(:side=>:bottom, :fill=>:x, :pady=>'2m') + + TkButton.new(f, :text=>'了解', :width=>15, :command=>proc{ + $paned1_demo.destroy + $paned1_demo = nil + }).pack(:side=>:left, :expand=>true) + + TkButton.new(f, :text=>'コード参照', :width=>15, :command=>proc{ + showCode 'paned1' + }).pack(:side=>:left, :expand=>true) +} + +TkPanedwindow.new($paned1_demo){|f| + pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m') + + add(TkLabel.new(f, :text=>"This is the\nleft side", :bg=>'yellow'), + TkLabel.new(f, :text=>"This is the\nright side", :bg=>'cyan')) +} diff --git a/ext/tk/sample/demos-jp/paned2.rb b/ext/tk/sample/demos-jp/paned2.rb new file mode 100644 index 0000000000..9df88c4b97 --- /dev/null +++ b/ext/tk/sample/demos-jp/paned2.rb @@ -0,0 +1,96 @@ +# paned2.rb -- +# +# This demonstration script creates a toplevel window containing +# a paned window that separates two windows vertically. +# +# based on "Id: paned2.tcl,v 1.1 2002/02/22 14:07:01 dkf Exp" + +if defined?($paned2_demo) && $paned2_demo + $paned2_demo.destroy + $paned2_demo = nil +end + +$paned2_demo = TkToplevel.new {|w| + title("Vertical Paned Window Demonstration") + iconname("paned2") + positionWindow(w) +} + +TkLabel.new($paned2_demo, + :font=>$font, :wraplength=>'4i', :justify=>:left, + :text=><:top) +下のスクロールバー付きのウィジェットが置かれた二つのウィンドウの間の仕切り枠は、一つの領域をそれぞれのウィンドウのために分割するためのものです。左ボタンで仕切りを操作すると、分割サイズ変更の操作途中では再表示はなされず、確定させたときに表示が更新されます。マウスによる仕切りの操作に追随してサイズを変更した表示がなわれるようにしたい場合は、マウスの中央ボタンを使ってください。 +もしあなたが使っている Ruby にリンクされている Tk ライブラリが panedwindow を実装していない +場合、このデモはうまく動かないはずです。その場合には panedwindow が実装されているような +より新しいバージョンの Tk を組み合わせて試す +ようにしてください。 +EOL + +# The bottom buttons +TkFrame.new($paned2_demo){|f| + pack(:side=>:bottom, :fill=>:x, :pady=>'2m') + + TkButton.new(f, :text=>'了解', :width=>15, :command=>proc{ + $paned2_demo.destroy + $paned2_demo = nil + }).pack(:side=>:left, :expand=>true) + + TkButton.new(f, :text=>'コード参照', :width=>15, :command=>proc{ + showCode 'paned2' + }).pack(:side=>:left, :expand=>true) +} + +paneList = TkVariable.new # define as normal variable (not array) +paneList.value = [ # ruby's array --> tcl's list + 'Ruby/Tk のウィジェット一覧', + 'TkButton', + 'TkCanvas', + 'TkCheckbutton', + 'TkEntry', + 'TkFrame', + 'TkLabel', + 'TkLabelframe', + 'TkListbox', + 'TkMenu', + 'TkMenubutton', + 'TkMessage', + 'TkPanedwindow', + 'TkRadiobutton', + 'TkScale', + 'TkScrollbar', + 'TkSpinbox', + 'TkText', + 'TkToplevel' +] + +# Create the pane itself +TkPanedwindow.new($paned2_demo, :orient=>:vertical){|f| + pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m') + + add(TkFrame.new(f){|paned2_top| + TkListbox.new(paned2_top, :listvariable=>paneList) { + # Invert the first item to highlight it + itemconfigure(0, :background=>self.cget(:foreground), + :foreground=>self.cget(:background) ) + yscrollbar(TkScrollbar.new(paned2_top).pack(:side=>:right, + :fill=>:y)) + pack(:fill=>:both, :expand=>true) + } + }, + + TkFrame.new(f) {|paned2_bottom| + # The bottom window is a text widget with scrollbar + paned2_xscr = TkScrollbar.new(paned2_bottom) + paned2_yscr = TkScrollbar.new(paned2_bottom) + paned2_text = TkText.new(paned2_bottom, :width=>30, :wrap=>:non) { + insert('1.0', 'ここに配置されているのは、' + + 'ごく普通のテキストウィジェットです。') + xscrollbar(paned2_xscr) + yscrollbar(paned2_yscr) + } + Tk.grid(paned2_text, paned2_yscr, :sticky=>'nsew') + Tk.grid(paned2_xscr, :sticky=>'nsew') + TkGrid.columnconfigure(paned2_bottom, 0, :weight=>1) + TkGrid.rowconfigure(paned2_bottom, 0, :weight=>1) + } ) +} diff --git a/ext/tk/sample/demos-jp/spin.rb b/ext/tk/sample/demos-jp/spin.rb new file mode 100644 index 0000000000..909d2b4818 --- /dev/null +++ b/ext/tk/sample/demos-jp/spin.rb @@ -0,0 +1,68 @@ +# spin.rb -- +# +# This demonstration script creates several spinbox widgets. +# +# based on Tcl/Tk8.4.4 widget demos + +if defined?($spin_demo) && $spin_demo + $spin_demo.destroy + $spin_demo = nil +end + +$spin_demo = TkToplevel.new {|w| + title("Spinbox Demonstration") + iconname("spin") + positionWindow(w) +} + +TkLabel.new($spin_demo, + :font=>$font, :wraplength=>'5i', :justify=>:left, + :text=><:top) +下には3種類のスピンボックスが表示されています。\ +それぞれ、マウスで選択して文字を入力することができます。 +編集操作としては、Emacs 形式の多くに加えて、一般的な +Motif 形式のキー操作がサポートされています。たとえば、 +Backspace と Control-h とは入力カーソルの左側の文字を +削除し、Delete と Control-d とは右側の文字を削除します。 +入力枠の長さを越えるような長い文字列を入力した場合には、 +マウスのボタン2を押してドラッグすることで、入力文字列 +をスキャンすることが可能です。 +なお、最初のスピンボックスは、整数値とみなされるような +文字列しか入力が許されないことに注意してください。また、 +3番目のスピンボックスで選択候補に現れるのはオーストラ +リアの都市名のリストとなっています。 +もしあなたが使っている Ruby にリンクされている Tk ライ +ブラリが spinbox ウィジェットを実装していない場合、この +デモはうまく動かないはずです。その場合には spinbox ウィ +ジェットが実装されているようなより新しいバージョンの Tk +を組み合わせて試すようにしてください。 +EOL + +TkFrame.new($spin_demo){|f| + pack(:side=>:bottom, :fill=>:x, :pady=>'2m') + + TkButton.new(f, :text=>'了解', :width=>15, :command=>proc{ + $spin_demo.destroy + $spin_demo = nil + }).pack(:side=>:left, :expand=>true) + + TkButton.new(f, :text=>'コード参照', :width=>15, :command=>proc{ + showCode 'spin' + }).pack(:side=>:left, :expand=>true) +} + +australianCities = [ + 'Canberra', 'Sydney', 'Melbourne', 'Perth', 'Adelaide', + 'Brisbane', 'Hobart', 'Darwin', 'Alice Springs' +] + +[ + # 現状の Ruby/Tk (現在のバージョンは 1.8.0) では、validate オプションや + # それに関連するオプションへのサポートを十分に達成できていません。この + # 問題については、次または将来のバージョンで改善する予定です。 + TkSpinbox.new($spin_demo, :from=>1, :to=>10, :width=>10, :validate=>:key, + :validatecommand=>"string is integer %P"), + TkSpinbox.new($spin_demo, :from=>0, :to=>3, :increment=>0.5, + :format=>'%05.2f', :width=>10), + TkSpinbox.new($spin_demo, :values=>australianCities, :width=>10) +].each{|sbox| sbox.pack(:side=>:top, :pady=>5, :padx=>10)} diff --git a/ext/tk/sample/demos-jp/widget b/ext/tk/sample/demos-jp/widget index 5eb5d5f074..b13bd0573e 100644 --- a/ext/tk/sample/demos-jp/widget +++ b/ext/tk/sample/demos-jp/widget @@ -223,6 +223,9 @@ txt.insert('end', " \n ", tag_demospace) txt.insert('end', "8. 画像を見るための簡単なユーザインターフェース\n", tag_demo, "demo-image2") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "9. ラベル付きフレーム (Tkに実装されている場合に限る)\n", + tag_demo, "demo-labelframe") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") #txt.insert('end', "リストボックス\n", tag_middle) @@ -237,14 +240,17 @@ txt.insert('end', "3. txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") -#txt.insert('end', "エントリ\n", tag_middle) +#txt.insert('end', "エントリとスピンボックス\n", tag_middle) txt.insert('end', "エントリ\n", tag_kanji_title) txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. スクロールバーなし\n", tag_demo, "demo-entry1") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "2. スクロールバーあり\n", tag_demo, "demo-entry2") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "3. 簡単なフォーム\n", tag_demo, "demo-form") +txt.insert('end', "3. スピンボックス (Tkに実装されている場合に限る)\n", + tag_demo, "demo-spin") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "4. 簡単なフォーム\n", tag_demo, "demo-form") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") @@ -293,6 +299,16 @@ txt.insert('end', " \n ", tag_demospace) txt.insert('end', "2. 水平\n", tag_demo.id, "demo-hscale") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "\n") +txt.insert('end', "ペインドウィンドウ\n", tag_kanji_title) +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "1. 水平方向 (Tkに実装されている場合に限る)\n", + tag_demo.id, "demo-paned1") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "2. 垂直方向 (Tkに実装されている場合に限る)\n", + tag_demo.id, "demo-paned2") +txt.insert('end', " \n ", tag_demospace) + txt.insert('end', "\n") #txt.insert('end', "メニュー\n", tag_middle) txt.insert('end', "メニュー\n", tag_kanji_title) @@ -496,7 +512,7 @@ end # def aboutBox Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo', - 'message'=>"Ruby/Tk ウィジェットデモ Ver.1.2.2\n\n( based on Tk ウィジェットデモ :: Copyright (c) 1996-1997 Sun Microsystems, Inc. )\n\nRunning Version :: Ruby#{VERSION}/Tk#{$tk_version}#{(Tk::JAPANIZED_TK)? 'jp': ''}") + 'message'=>"Ruby/Tk ウィジェットデモ Ver.1.3.0-jp\n\n( based on Tk ウィジェットデモ :: Copyright (c) 1996-1997 Sun Microsystems, Inc. )\n\nRunning Version :: Ruby#{VERSION}/Tk#{$tk_version}#{(Tk::JAPANIZED_TK)? 'jp': ''}") end ################################ -- cgit v1.2.3