11
def initialize(parent=nil, *args)
16
if parent.kind_of? Hash
17
keys = _symbolkey2str(parent)
18
parent = keys.delete('parent')
19
@frame = TkFrame.new(parent)
20
@path = @epath = @frame.path
21
initialize_composite(keys)
23
@frame = TkFrame.new(parent)
24
@path = @epath = @frame.path
25
initialize_composite(*args)
30
def _choice_classname_of_baseframe
33
klass = WidgetClassNames[self.class::WidgetClassName]
36
# WidgetClassName is a known class
37
if klass <= TkFrame || klass < TkComposite
38
# klass is valid for the base frame
39
if self.class <= klass
41
base_class_name = self.class.name
42
if base_class_name == ''
43
# anonymous class -> use ancestor's name
44
base_class_name = klass.name
47
# not subclass -> use WidgetClassName
48
base_class_name = klass.name
52
# klass is invalid for the base frame
53
if self.class < TkFrame || self.class.superclass < TkComposite
54
# my class name is valid for the base frame -> use my classname
55
base_class_name = self.class.name
56
if base_class_name == ''
57
# anonymous class -> use TkFrame
61
# no idea for the base frame -> use TkFrame
66
elsif self.class::WidgetClassName && ! self.class::WidgetClassName.empty?
67
# unknown WidgetClassName is defined -> use it for the base frame
68
base_class_name = self.class::WidgetClassName
71
# no valid WidgetClassName
72
if self.class < TkFrame || self.class.superclass < TkComposite
73
# my class name is valid for the base frame -> use my classname
74
base_class_name = self.class.name
75
if base_class_name == ''
76
# anonymous class -> use TkFrame
80
# no idea for the base frame -> use TkFrame
87
private :_choice_classname_of_baseframe
89
# def initialize(parent=nil, *args)
95
if args[-1].kind_of?(Hash)
96
keys = _symbolkey2str(args.pop)
101
parent = keys.delete('parent') if keys.has_key?('parent')
103
if keys.key?('classname')
104
keys['class'] = keys.delete('classname')
106
if (base_class_name = (keys.delete('class')).to_s).empty?
107
base_class_name = _choice_classname_of_baseframe
111
@frame = TkFrame.new(parent, :class=>base_class_name)
113
@frame = TkFrame.new(parent)
115
@path = @epath = @frame.path
117
args.push(keys) unless keys.empty?
118
initialize_composite(*args)
121
def database_classname
122
@frame.database_classname
126
@frame.database_class
133
def initialize_composite(*args) end
134
private :initialize_composite
136
def option_methods(*opts)
137
opts.each{|m_set, m_cget, m_info|
139
m_cget = m_set if !m_cget && self.method(m_set).arity == -1
140
m_cget = m_cget.to_s if m_cget
141
m_info = m_info.to_s if m_info
142
@option_methods[m_set] = {
143
:set => m_set, :cget => m_cget, :info => m_info
148
def delegate_alias(alias_opt, option, *wins)
150
fail ArgumentError, "target widgets are not given"
152
if alias_opt != option && (alias_opt == 'DEFAULT' || option == 'DEFAULT')
153
fail ArgumentError, "cannot alias 'DEFAULT' option"
155
alias_opt = alias_opt.to_s
157
if @delegates[alias_opt].kind_of?(Array)
158
if (elem = @delegates[alias_opt].assoc(option))
159
wins.each{|w| elem[1].push(w)}
161
@delegates[alias_opt] << [option, wins]
164
@delegates[alias_opt] = [ [option, wins] ]
168
def delegate(option, *wins)
169
delegate_alias(option, option, *wins)
175
if @option_methods.include?(slot)
176
if @option_methods[slot][:cget]
177
return self.__send__(@option_methods[slot][:cget])
179
if @option_setting[slot]
180
return @option_setting[slot]
187
tbl = @delegates[slot]
188
tbl = @delegates['DEFAULT'] unless tbl
193
opt = slot if opt == 'DEFAULT'
195
return wins[-1].cget(opt)
204
def configure(slot, value=None)
205
if slot.kind_of? Hash
206
slot.each{|slot,value| configure slot, value}
212
if @option_methods.include?(slot)
213
unless @option_methods[slot][:cget]
214
if value.kind_of?(Symbol)
215
@option_setting[slot] = value.to_s
217
@option_setting[slot] = value
220
return self.__send__(@option_methods[slot][:set], value)
223
tbl = @delegates[slot]
224
tbl = @delegates['DEFAULT'] unless tbl
230
opt = slot if opt == 'DEFAULT'
231
wins.each{|w| last = w.configure(opt, value)}
241
def configinfo(slot = nil)
242
if TkComm::GET_CONFIGINFO_AS_ARRAY
245
if @option_methods.include?(slot)
246
if @option_methods[slot][:info]
247
return self.__send__(@option_methods[slot][:info])
249
return [slot, '', '', '', self.cget(slot)]
253
tbl = @delegates[slot]
254
tbl = @delegates['DEFAULT'] unless tbl
260
if slot == opt || opt == 'DEFAULT'
261
return wins[-1].configinfo(slot)
263
info = wins[-1].configinfo(opt)
269
return [slot, '', '', '', wins[-1].cget(opt)]
278
info_list = super(slot)
280
tbl = @delegates['DEFAULT']
284
wins[-1].configinfo.each{|info|
286
info_list.delete_if{|i| i[0] == slot} << info
291
@delegates.each{|slot, tbl|
292
next if slot == 'DEFAULT'
295
next unless wins && wins[-1]
297
info_list.delete_if{|i| i[0] == slot} <<
298
wins[-1].configinfo(slot)
300
info = wins[-1].configinfo(opt)
302
info_list.delete_if{|i| i[0] == slot} << info
306
info_list.delete_if{|i| i[0] == slot} <<
307
[slot, '', '', '', wins[-1].cget(opt)]
311
@option_methods.each{|slot, m|
313
info = self.__send__(m[:info])
315
info = [slot, '', '', '', self.cget(slot)]
317
info_list.delete_if{|i| i[0] == slot} << info
323
else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
326
if @option_methods.include?(slot)
327
if @option_methods[slot][:info]
328
return self.__send__(@option_methods[slot][:info])
330
return {slot => ['', '', '', self.cget(slot)]}
334
tbl = @delegates[slot]
335
tbl = @delegates['DEFAULT'] unless tbl
341
if slot == opt || opt == 'DEFAULT'
342
return wins[-1].configinfo(slot)
344
return {slot => wins[-1].configinfo(opt)[opt]}
348
return {slot => ['', '', '', wins[-1].cget(opt)]}
357
info_list = super(slot)
359
tbl = @delegates['DEFAULT']
362
info_list.update(wins[-1].configinfo) if wins && wins[-1]
365
@delegates.each{|slot, tbl|
366
next if slot == 'DEFAULT'
369
next unless wins && wins[-1]
371
info_list.update(wins[-1].configinfo(slot))
373
info_list.update({slot => wins[-1].configinfo(opt)[opt]})
377
info_list.update({slot => ['', '', '', wins[-1].cget(opt)]})
381
@option_methods.each{|slot, m|
383
info = self.__send__(m[:info])
385
info = {slot => ['', '', '', self.cget(slot)]}
387
info_list.update(info)