diff options
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 |