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/sample/demos-en/spin.rb | |
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/sample/demos-en/spin.rb')
-rw-r--r-- | ext/tk/sample/demos-en/spin.rb | 64 |
1 files changed, 64 insertions, 0 deletions
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)} |