aboutsummaryrefslogtreecommitdiffstats
path: root/ext/tk/sample/demos-en
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-02 09:58:13 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-02 09:58:13 +0000
commit6277a66deb30559a8ea991175c274e0fd899e48e (patch)
tree0f1f15f96c362749e2646ae14a23e9d4a0a5e3e4 /ext/tk/sample/demos-en
parent08719ea2380b179ef98a10cd5e871be7a44fff43 (diff)
downloadruby-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/sample/demos-en')
-rw-r--r--ext/tk/sample/demos-en/labelframe.rb93
-rw-r--r--ext/tk/sample/demos-en/paned1.rb45
-rw-r--r--ext/tk/sample/demos-en/paned2.rb92
-rw-r--r--ext/tk/sample/demos-en/spin.rb64
-rw-r--r--ext/tk/sample/demos-en/widget18
5 files changed, 309 insertions, 3 deletions
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
################################