diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-15 23:23:39 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-15 23:23:39 +0000 |
commit | 6175ca03be6d0d51359f9017123708987d0f5eb7 (patch) | |
tree | ecfcf6e79a21b1d25c3f6f42dd68ea0a14add89c /ruby_1_8_5/ext/tk/lib/tk/scale.rb | |
parent | 80a56b248b2e9cfc95622aed98750df05a19f667 (diff) |
add tag v1_8_5_91v1_8_5_91
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_8_5_91@13046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_1_8_5/ext/tk/lib/tk/scale.rb')
-rw-r--r-- | ruby_1_8_5/ext/tk/lib/tk/scale.rb | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/ruby_1_8_5/ext/tk/lib/tk/scale.rb b/ruby_1_8_5/ext/tk/lib/tk/scale.rb new file mode 100644 index 0000000000..0b703aa055 --- /dev/null +++ b/ruby_1_8_5/ext/tk/lib/tk/scale.rb @@ -0,0 +1,86 @@ +# +# tk/scale.rb : treat scale widget +# +require 'tk' + +class TkScale<TkWindow + TkCommandNames = ['scale'.freeze].freeze + WidgetClassName = 'Scale'.freeze + WidgetClassNames[WidgetClassName] = self + + def create_self(keys) + if keys and keys != None + if keys.key?('command') && ! keys['command'].kind_of?(String) + cmd = keys.delete('command') + keys['command'] = proc{|val| cmd.call(val.to_f)} + end + #tk_call_without_enc('scale', @path, *hash_kv(keys, true)) + tk_call_without_enc(self.class::TkCommandNames[0], @path, + *hash_kv(keys, true)) + else + #tk_call_without_enc('scale', @path) + tk_call_without_enc(self.class::TkCommandNames[0], @path) + end + end + private :create_self + + def __strval_optkeys + super() << 'label' + end + private :__strval_optkeys + + def _wrap_command_arg(cmd) + proc{|val| + if val.kind_of?(String) + cmd.call(number(val)) + else + cmd.call(val) + end + } + end + private :_wrap_command_arg + + def configure_cmd(slot, value) + configure(slot=>value) + end + + def configure(slot, value=None) + if (slot == 'command' || slot == :command) + configure('command'=>value) + elsif slot.kind_of?(Hash) && + (slot.key?('command') || slot.key?(:command)) + slot = _symbolkey2str(slot) + slot['command'] = _wrap_command_arg(slot.delete('command')) + end + super(slot, value) + end + + def command(cmd=Proc.new) + configure('command'=>cmd) + end + + def get(x=None, y=None) + number(tk_send_without_enc('get', x, y)) + end + + def coords(val=None) + tk_split_list(tk_send_without_enc('coords', val)) + end + + def identify(x, y) + tk_send_without_enc('identify', x, y) + end + + def set(val) + tk_send_without_enc('set', val) + end + + def value + get + end + + def value= (val) + set(val) + val + end +end |