From 1125122df55683ec52e08f515fd875ef8feb2b56 Mon Sep 17 00:00:00 2001 From: nagai Date: Sun, 3 Aug 2003 22:07:47 +0000 Subject: * ready to use 'validatecommand' option of TkEntry/TkSpinbox widget git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4307 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/lib/tkentry.rb | 56 +++++++++++++++++++++++++++++------------- ext/tk/sample/demos-en/spin.rb | 7 +++--- ext/tk/sample/demos-jp/spin.rb | 7 +++--- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/ext/tk/lib/tkentry.rb b/ext/tk/lib/tkentry.rb index ab69e7655..fc52b9435 100644 --- a/ext/tk/lib/tkentry.rb +++ b/ext/tk/lib/tkentry.rb @@ -15,9 +15,19 @@ class TkEntry1, :to=>10, :width=>10, :validate=>:key, - :validatecommand=>"string is integer %P"), + :validatecommand=>[ + proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%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) diff --git a/ext/tk/sample/demos-jp/spin.rb b/ext/tk/sample/demos-jp/spin.rb index 909d2b481..4f6edc13c 100644 --- a/ext/tk/sample/demos-jp/spin.rb +++ b/ext/tk/sample/demos-jp/spin.rb @@ -57,11 +57,10 @@ australianCities = [ ] [ - # 現状の Ruby/Tk (現在のバージョンは 1.8.0) では、validate オプションや - # それに関連するオプションへのサポートを十分に達成できていません。この - # 問題については、次または将来のバージョンで改善する予定です。 TkSpinbox.new($spin_demo, :from=>1, :to=>10, :width=>10, :validate=>:key, - :validatecommand=>"string is integer %P"), + :validatecommand=>[ + proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%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) -- cgit