diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-11-20 07:31:55 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-11-20 07:31:55 +0000 |
commit | 39563af99459820ada08e30e379c84b4560c3fe9 (patch) | |
tree | 5844d64e2d5e0b5a7b9dfc259037778db84b12aa /ext/tk/lib/tkentry.rb | |
parent | 8f54a9b4704e5416290a5670519ae7bc869de0e8 (diff) | |
download | ruby-39563af99459820ada08e30e379c84b4560c3fe9.tar.gz |
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1049 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tkentry.rb')
-rw-r--r-- | ext/tk/lib/tkentry.rb | 105 |
1 files changed, 100 insertions, 5 deletions
diff --git a/ext/tk/lib/tkentry.rb b/ext/tk/lib/tkentry.rb index 5207d9b895..6c050d7cf1 100644 --- a/ext/tk/lib/tkentry.rb +++ b/ext/tk/lib/tkentry.rb @@ -18,6 +18,10 @@ class TkEntry<TkLabel tk_call 'entry', @path end + def bbox(index) + tk_send 'bbox', index + end + def delete(s, e=None) tk_send 'delete', s, e end @@ -59,14 +63,77 @@ class TkEntry<TkLabel tk_send 'selection', 'to', index end - def validate - if tk_send('validate') == '0' - false - else - true + def validate(mode = nil) + if mode + configure 'validate', mode + else + if tk_send('validate') == '0' + false + else + true + end end end + class ValidateCmd + include TkComm + + class ValidateArgs + def initialize(d,i,s,v,pp,ss,vv,ww) + @action = d + @index = i + @current = s + @type = v + @value = pp + @string = ss + @triggered = vv + @widget = ww + end + attr :action + attr :index + attr :current + attr :type + attr :value + attr :string + attr :triggered + attr :widget + end + + def initialize(cmd = Proc.new, args=nil) + if args + @id = install_cmd(proc{|*arg| + TkUtil.eval_cmd cmd, *arg + }) + " " + args + else + @id = install_cmd(proc{|arg| + TkUtil.eval_cmd cmd, ValidateArgs.new(*arg) + }) + ' %d %i %s %v %P %S %V %W' + end + end + + def to_eval + @id + end + end + + def validatecommand(cmd = ValidateCmd.new, args = nil) + if cmd.kind_of?(ValidateCmd) + configure('validatecommand', cmd) + else + configure('validatecommand', ValidateCmd.new(cmd, args)) + end + end + alias vcmd validatecommand + + def invalidcommand(cmd = ValidateCmd.new, args = nil) + if cmd.kind_of?(ValidateCmd) + configure('invalidcommand', cmd) + else + configure('invalidcommand', ValidateCmd.new(cmd, args)) + end + end + alias invcmd invalidcommand + def value tk_send 'get' end @@ -75,3 +142,31 @@ class TkEntry<TkLabel tk_send 'insert', 0, val end end + +class TkSpinbox<TkEntry + WidgetClassName = 'Spinbox'.freeze + WidgetClassNames[WidgetClassName] = self + def self.to_eval + WidgetClassName + end + + def create_self + tk_call 'spinbox', @path + end + + def identify(x, y) + tk_send 'identify', x, y + end + + def spinup + tk_send 'invoke', 'spinup' + end + + def spindown + tk_send 'invoke', 'spindown' + end + + def set(str) + tk_send 'set', str + end +end |