diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-02 09:58:13 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-02 09:58:13 +0000 |
commit | 6277a66deb30559a8ea991175c274e0fd899e48e (patch) | |
tree | 0f1f15f96c362749e2646ae14a23e9d4a0a5e3e4 /ext/tk | |
parent | 08719ea2380b179ef98a10cd5e871be7a44fff43 (diff) | |
download | ruby-6277a66deb30559a8ea991175c274e0fd899e48e.tar.gz |
* (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
Diffstat (limited to 'ext/tk')
-rw-r--r-- | ext/tk/MANIFEST | 8 | ||||
-rw-r--r-- | ext/tk/lib/tk.rb | 4 | ||||
-rw-r--r-- | ext/tk/sample/demos-en/labelframe.rb | 93 | ||||
-rw-r--r-- | ext/tk/sample/demos-en/paned1.rb | 45 | ||||
-rw-r--r-- | ext/tk/sample/demos-en/paned2.rb | 92 | ||||
-rw-r--r-- | ext/tk/sample/demos-en/spin.rb | 64 | ||||
-rw-r--r-- | ext/tk/sample/demos-en/widget | 18 | ||||
-rw-r--r-- | ext/tk/sample/demos-jp/labelframe.rb | 98 | ||||
-rw-r--r-- | ext/tk/sample/demos-jp/paned1.rb | 48 | ||||
-rw-r--r-- | ext/tk/sample/demos-jp/paned2.rb | 96 | ||||
-rw-r--r-- | ext/tk/sample/demos-jp/spin.rb | 68 | ||||
-rw-r--r-- | ext/tk/sample/demos-jp/widget | 22 |
12 files changed, 650 insertions, 6 deletions
diff --git a/ext/tk/MANIFEST b/ext/tk/MANIFEST index f858fd8e80..edcc7dafc2 100644 --- a/ext/tk/MANIFEST +++ b/ext/tk/MANIFEST @@ -84,10 +84,13 @@ sample/demos-en/images/teapot.ppm sample/demos-en/items.rb sample/demos-en/ixset sample/demos-en/label.rb +sample/demos-en/labelframe.rb sample/demos-en/menu.rb sample/demos-en/menubu.rb sample/demos-en/msgbox.rb sample/demos-en/patch_1.1c1 +sample/demos-en/paned1.rb +sample/demos-en/paned2.rb sample/demos-en/plot.rb sample/demos-en/puzzle.rb sample/demos-en/radio.rb @@ -97,6 +100,7 @@ sample/demos-en/rolodex-j sample/demos-en/ruler.rb sample/demos-en/sayings.rb sample/demos-en/search.rb +sample/demos-en/spin.rb sample/demos-en/square sample/demos-en/states.rb sample/demos-en/style.rb @@ -153,10 +157,13 @@ sample/demos-jp/images/teapot.ppm sample/demos-jp/items.rb sample/demos-jp/ixset sample/demos-jp/label.rb +sample/demos-jp/labelframe.rb sample/demos-jp/menu.rb sample/demos-jp/menu8x.rb sample/demos-jp/menubu.rb sample/demos-jp/msgbox.rb +sample/demos-jp/paned1.rb +sample/demos-jp/paned2.rb sample/demos-jp/plot.rb sample/demos-jp/puzzle.rb sample/demos-jp/radio.rb @@ -166,6 +173,7 @@ sample/demos-jp/rolodex-j sample/demos-jp/ruler.rb sample/demos-jp/sayings.rb sample/demos-jp/search.rb +sample/demos-jp/spin.rb sample/demos-jp/square sample/demos-jp/states.rb sample/demos-jp/style.rb diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 6f3de4e417..a2d2bf898f 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -4271,6 +4271,9 @@ class TkFrame<TkWindow end class TkLabelFrame<TkFrame + TkCommandNames = ['labelframe'.freeze].freeze + WidgetClassName = 'Labelframe'.freeze + WidgetClassNames[WidgetClassName] = self def create_self(keys) if keys and keys != None tk_call 'labelframe', @path, *hash_kv(keys) @@ -4279,6 +4282,7 @@ class TkLabelFrame<TkFrame end end end +TkLabelframe = TkLabelFrame class TkPanedWindow<TkWindow TkCommandNames = ['panedwindow'.freeze].freeze diff --git a/ext/tk/sample/demos-en/labelframe.rb b/ext/tk/sample/demos-en/labelframe.rb new file mode 100644 index 0000000000..8636a4a9b9 --- /dev/null +++ b/ext/tk/sample/demos-en/labelframe.rb @@ -0,0 +1,93 @@ +# 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=><<EOL).pack(:side=>:top) +Labelframes are used to group related widgets together. \ +The label may be either plain text or another widget. \ +If your Tk library linked to Ruby doesn't include a 'labelframe' widget, \ +this demo doesn't work. Please use later version of Tk \ +which supports a 'labelframe' widget. +EOL + +# The bottom buttons +TkFrame.new($labelframe_demo){|f| + pack(:side=>:bottom, :fill=>:x, :pady=>'2m') + + TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ + $labelframe_demo.destroy + $labelframe_demo = nil + }).pack(:side=>:left, :expand=>true) + + TkButton.new(f, :text=>'See Code', :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=>'Value', + :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=>"Use this option.", :padx=>0) {|cb| + command proc{lfEnableButtons(f)} + f.labelwidget(cb) + } + grid(:row=>0, :column=>1, :pady=>'2m', :padx=>'2m') + + %w(Option1 Option2 Option3).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-en/paned1.rb b/ext/tk/sample/demos-en/paned1.rb new file mode 100644 index 0000000000..8c25de0ef3 --- /dev/null +++ b/ext/tk/sample/demos-en/paned1.rb @@ -0,0 +1,45 @@ +# 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=><<EOL).pack(:side=>:top) +The sash between the two coloured windows below can be used to divide the area between them. Use the left mouse button to resize without redrawing by just moving the sash, and use the middle mouse button to resize opaquely (always redrawing the windows in each position.) +If your Tk library linked to Ruby doesn't include a 'panedwindow', this demo doesn't work. Please use later version of Tk which supports a 'panedwindow'. +EOL + +# The bottom buttons +TkFrame.new($paned1_demo){|f| + pack(:side=>:bottom, :fill=>:x, :pady=>'2m') + + TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ + $paned1_demo.destroy + $paned1_demo = nil + }).pack(:side=>:left, :expand=>true) + + TkButton.new(f, :text=>'See Code', :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-en/paned2.rb b/ext/tk/sample/demos-en/paned2.rb new file mode 100644 index 0000000000..c8c5abb470 --- /dev/null +++ b/ext/tk/sample/demos-en/paned2.rb @@ -0,0 +1,92 @@ +# 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=><<EOL).pack(:side=>:top) +The sash between the two scrolled windows below can be used to divide the area between them. Use the left mouse button to resize without redrawing by just moving the sash, and use the middle mouse button to resize opaquely (always redrawing the windows in each position.) +If your Tk library linked to Ruby doesn't include a 'panedwindow', this demo doesn't work. Please use later version of Tk which supports a 'panedwindow'. +EOL + +# The bottom buttons +TkFrame.new($paned2_demo){|f| + pack(:side=>:bottom, :fill=>:x, :pady=>'2m') + + TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ + $paned2_demo.destroy + $paned2_demo = nil + }).pack(:side=>:left, :expand=>true) + + TkButton.new(f, :text=>'See Code', :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 + 'List of Ruby/Tk Widgets', + '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', "This is just a normal text widget") + 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-en/spin.rb b/ext/tk/sample/demos-en/spin.rb new file mode 100644 index 0000000000..882772ad4d --- /dev/null +++ b/ext/tk/sample/demos-en/spin.rb @@ -0,0 +1,64 @@ +# 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=><<EOL).pack(:side=>:top) +Three different spin-boxes are displayed below. \ +You can add characters by pointing, clicking and typing. \ +The normal Motif editing characters are supported, along with \ +many Emacs bindings. For example, Backspace and Control-h \ +delete the character to the left of the insertion cursor and \ +Delete and Control-d delete the chararacter to the right of the \ +insertion cursor. For values that are too large to fit in the \ +window all at once, you can scan through the value by dragging \ +with mouse button2 pressed. Note that the first spin-box will \ +only permit you to type in integers, and the third selects from \ +a list of Australian cities. +If your Tk library linked to Ruby doesn't include a 'spinbox' widget, \ +this demo doesn't work. Please use later version of Tk \ +which supports a 'spinbox' widget. +EOL + +TkFrame.new($spin_demo){|f| + pack(:side=>:bottom, :fill=>:x, :pady=>'2m') + + TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ + $spin_demo.destroy + $spin_demo = nil + }).pack(:side=>:left, :expand=>true) + + TkButton.new(f, :text=>'See Code', :width=>15, :command=>proc{ + showCode 'spin' + }).pack(:side=>:left, :expand=>true) +} + +australianCities = [ + 'Canberra', 'Sydney', 'Melbourne', 'Perth', 'Adelaide', + 'Brisbane', 'Hobart', 'Darwin', 'Alice Springs' +] + +[ + # Current version of Ruby/Tk (current is 1.8.0) is not enough + # to support 'validate' option and related options. This problem + # will be improved in the next or future version. + 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-en/widget b/ext/tk/sample/demos-en/widget index 96a24447e1..9381401db2 100644 --- a/ext/tk/sample/demos-en/widget +++ b/ext/tk/sample/demos-en/widget @@ -206,6 +206,8 @@ txt.insert('end', "7. Two labels displaying images.\n", tag_demo, "demo-image1") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "8. A simple user interface for viewing images.\n", tag_demo, "demo-image2") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "9. Labelled frames (if supported)\n", tag_demo, "demo-labelframe") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") txt.insert('end', "Listboxes\n", tag_title) @@ -218,13 +220,15 @@ txt.insert('end', "3. A collection of famous sayings.\n", tag_demo, "demo-saying txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") -txt.insert('end', "Entries\n", tag_title) +txt.insert('end', "Entries and Spin-boxes\n", tag_title) txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. Without scrollbars.\n", tag_demo, "demo-entry1") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "2. With scrollbars.\n", tag_demo, "demo-entry2") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "3. Simple Rolodex-like form.\n", tag_demo, "demo-form") +txt.insert('end', "3. Spin-boxes. (if supported)\n", tag_demo, "demo-spin") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "4. Simple Rolodex-like form.\n", tag_demo, "demo-form") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") @@ -268,6 +272,14 @@ txt.insert('end', "2. Horizontal scale.\n", tag_demo.id, "demo-hscale") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") +txt.insert('end', "Paned Windows\n", tag_title) +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "1. Horizontal paned window. (if supported)\n", tag_demo.id, "demo-paned1") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "2. Vertical paned window. (if supported)\n", tag_demo.id, "demo-paned2") +txt.insert('end', " \n ", tag_demospace) + +txt.insert('end', "\n") txt.insert('end', "Menus\n", tag_title) txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. Menus and cascades.\n", tag_demo, "demo-menu") @@ -490,7 +502,7 @@ end # def aboutBox Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo', - 'message'=>"Ruby/Tk widget demonstration Ver.1.0.2\n\n( based on Tk 8.1 Copyright (c) 1996-1997 Sun Microsystems, Inc. )\n\nRunning Version :: Ruby#{VERSION}/Tk#{$tk_version}") + 'message'=>"Ruby/Tk widget demonstration Ver.1.3.0-en\n\n( based on Tk 8.1 Copyright (c) 1996-1997 Sun Microsystems, Inc. )\n\nRunning Version :: Ruby#{VERSION}/Tk#{$tk_version}") end ################################ 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=><<EOL).pack(:side=>: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=><<EOL).pack(:side=>: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=><<EOL).pack(:side=>: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=><<EOL).pack(:side=>: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. 格言集\n", tag_demo, "demo-sayings") 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") @@ -294,6 +300,16 @@ 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) txt.insert('end', " \n ", tag_demospace) @@ -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 ################################ |