diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-22 23:12:37 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-22 23:12:37 +0000 |
commit | 81c1375c98f9dfa25c834a856b49217ed1c6b32f (patch) | |
tree | 0800d6289432b190547dcbe0b5cfdf80d4cb1d9f /ext | |
parent | 4e979c77e536250d6327754efad695b5060a2d9d (diff) |
* ext/tk/lib/tk/menu.rb: improve usability of TkOptionMenubutton
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/tk/lib/tk/menu.rb | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/ext/tk/lib/tk/menu.rb b/ext/tk/lib/tk/menu.rb index 5014dea603..2ac6a0efe7 100644 --- a/ext/tk/lib/tk/menu.rb +++ b/ext/tk/lib/tk/menu.rb @@ -402,33 +402,56 @@ class TkOptionMenubutton<TkMenubutton end end - def initialize(parent=nil, var=nil, firstval=nil, *vals) - if parent.kind_of? Hash - keys = _symbolkey2str(parent) - parent = keys['parent'] - var = keys['variable'] if keys['variable'] - firstval, *vals = keys['values'] + def initialize(*args) + # args :: [parent,] [var,] [value[, ...],] [keys] + # parent --> TkWindow or nil + # var --> TkVariable or nil + # keys --> Hash + # keys[:parent] or keys['parent'] --> parent + # keys[:variable] or keys['variable'] --> var + # keys[:values] or keys['values'] --> value, ... + # other Hash keys are menubutton options + keys = {} + keys = args.pop if args[-1].kind_of?(Hash) + keys = _symbolkey2str(keys) + + parent = nil + if args[0].kind_of?(TkWindow) || args[0] == nil + parent = args.shift + else + parent = keys.delete('parent') + end + + @variable = nil + if args[0].kind_of?(TkVariable) || args[0] == nil + @variable = args.shift + else + @variable = keys.delete('variable') end - if parent.kind_of? TkVariable - vals.unshift(firstval) if firstval - firstval = var - var = parent - parent = nil + @variable = TkVariable.new unless @variable + + (args = keys.delete('values') || []) if args.empty? + if args.empty? + args << @variable.value + else + @variable.value = args[0] end - var = TkVariable.new unless var - fail 'variable option must be TkVariable' unless var.kind_of? TkVariable - @variable = var - firstval = @variable.value unless firstval - @variable.value = firstval + install_win(if parent then parent.path end) - @menu = OptionMenu.new(tk_call('tk_optionMenu', @path, @variable.id, - firstval, *vals)) + @menu = OptionMenu.new(tk_call('tk_optionMenu', + @path, @variable.id, *args)) + + configure(keys) if keys end def value @variable.value end + def value=(val) + @variable.value = val + end + def activate(index) @menu.activate(index) self |