* ext/tk/lib/tk/menu.rb: improve usability of TkOptionMenubutton
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
941d135904
commit
d852a4e317
@ -1,3 +1,7 @@
|
|||||||
|
Tue Nov 23 08:09:50 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||||
|
|
||||||
|
* ext/tk/lib/tk/menu.rb: improve usability of TkOptionMenubutton
|
||||||
|
|
||||||
Tue Nov 23 02:00:21 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Tue Nov 23 02:00:21 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* file.c (rb_file_chown): [ruby-dev:24949]
|
* file.c (rb_file_chown): [ruby-dev:24949]
|
||||||
|
@ -402,33 +402,56 @@ class TkOptionMenubutton<TkMenubutton
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(parent=nil, var=nil, firstval=nil, *vals)
|
def initialize(*args)
|
||||||
if parent.kind_of? Hash
|
# args :: [parent,] [var,] [value[, ...],] [keys]
|
||||||
keys = _symbolkey2str(parent)
|
# parent --> TkWindow or nil
|
||||||
parent = keys['parent']
|
# var --> TkVariable or nil
|
||||||
var = keys['variable'] if keys['variable']
|
# keys --> Hash
|
||||||
firstval, *vals = keys['values']
|
# 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
|
end
|
||||||
if parent.kind_of? TkVariable
|
|
||||||
vals.unshift(firstval) if firstval
|
@variable = nil
|
||||||
firstval = var
|
if args[0].kind_of?(TkVariable) || args[0] == nil
|
||||||
var = parent
|
@variable = args.shift
|
||||||
parent = nil
|
else
|
||||||
|
@variable = keys.delete('variable')
|
||||||
end
|
end
|
||||||
var = TkVariable.new unless var
|
@variable = TkVariable.new unless @variable
|
||||||
fail 'variable option must be TkVariable' unless var.kind_of? TkVariable
|
|
||||||
@variable = var
|
(args = keys.delete('values') || []) if args.empty?
|
||||||
firstval = @variable.value unless firstval
|
if args.empty?
|
||||||
@variable.value = firstval
|
args << @variable.value
|
||||||
|
else
|
||||||
|
@variable.value = args[0]
|
||||||
|
end
|
||||||
|
|
||||||
install_win(if parent then parent.path end)
|
install_win(if parent then parent.path end)
|
||||||
@menu = OptionMenu.new(tk_call('tk_optionMenu', @path, @variable.id,
|
@menu = OptionMenu.new(tk_call('tk_optionMenu',
|
||||||
firstval, *vals))
|
@path, @variable.id, *args))
|
||||||
|
|
||||||
|
configure(keys) if keys
|
||||||
end
|
end
|
||||||
|
|
||||||
def value
|
def value
|
||||||
@variable.value
|
@variable.value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def value=(val)
|
||||||
|
@variable.value = val
|
||||||
|
end
|
||||||
|
|
||||||
def activate(index)
|
def activate(index)
|
||||||
@menu.activate(index)
|
@menu.activate(index)
|
||||||
self
|
self
|
||||||
|
Loading…
x
Reference in New Issue
Block a user