M
matt
I noticed that TkComposite had a bug in it by refering to the default
slot for delegation as DEFALUT in configure. I also noticed that
TkComposite isn't in the tk.rb in cvs...
Anyway, here's the version of configure that I hacked together to fix
the above mentioned problem, and another function which is useful
def method_configure(*methodnames)
@methodnames += methodnames.map {|m| m.to_s}
end
def configure(slot, value=None)
if slot.kind_of? Hash then
slot.each{|slot,value| configure slot, value}
elsif (meth = @methodnames.find {|m| m == slot.to_s}) then
self.send(meth.intern, value)
elsif @delegates and [slot, 'DEFAULT'].any? {|slot_key|
@delegates.has_key?(slot_key)} then
last = nil
@delegates[@delegates.has_key?(slot) ? slot : 'DEFAULT'].each
{|i| last = i.configure(slot, value)}
last
else
super
end
end
@methodnames is initialized to [] inside initialize. This way, you
can just do the following:
# inside some class using TkComposite
method_configurescrollbars, :width, :
# and whenever you configure a la
# TkMoo.new(parent, 'scrollbars'=>'x', ...)
# it will call your scrollbars function and do all that needs to be
done.
slot for delegation as DEFALUT in configure. I also noticed that
TkComposite isn't in the tk.rb in cvs...
Anyway, here's the version of configure that I hacked together to fix
the above mentioned problem, and another function which is useful
def method_configure(*methodnames)
@methodnames += methodnames.map {|m| m.to_s}
end
def configure(slot, value=None)
if slot.kind_of? Hash then
slot.each{|slot,value| configure slot, value}
elsif (meth = @methodnames.find {|m| m == slot.to_s}) then
self.send(meth.intern, value)
elsif @delegates and [slot, 'DEFAULT'].any? {|slot_key|
@delegates.has_key?(slot_key)} then
last = nil
@delegates[@delegates.has_key?(slot) ? slot : 'DEFAULT'].each
{|i| last = i.configure(slot, value)}
last
else
super
end
end
@methodnames is initialized to [] inside initialize. This way, you
can just do the following:
# inside some class using TkComposite
method_configurescrollbars, :width, :
# and whenever you configure a la
# TkMoo.new(parent, 'scrollbars'=>'x', ...)
# it will call your scrollbars function and do all that needs to be
done.