* lib/tkextlib/blt/component.rb: bug fix on treatment of

component objects.
* sample/tkextlib/blt/graph6.rb: a new sample script.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2005-04-01 03:48:26 +00:00
parent 4b7cc65b81
commit a8123f8f7e
3 changed files with 2387 additions and 79 deletions

View File

@ -1,3 +1,10 @@
2005-04-01 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* lib/tkextlib/blt/component.rb: bug fix on treatment of
component objects.
* sample/tkextlib/blt/graph6.rb: a new sample script.
2005-03-31 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> 2005-03-31 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* sample/tkextlib/iwidgets/sample/hierarchy.rb: show basename * sample/tkextlib/iwidgets/sample/hierarchy.rb: show basename

View File

@ -58,8 +58,9 @@ module Tk::BLT
def __item_config_cmd(id) def __item_config_cmd(id)
if id.kind_of?(Array) if id.kind_of?(Array)
# id := [ type, name ] # id := [ type, name, ... ]
[self.path, id[0], 'configure', id[1]] type, *names = id
[self.path, type, 'configure'].concat(names)
else else
[self.path, id, 'configure'] [self.path, id, 'configure']
end end
@ -75,29 +76,36 @@ module Tk::BLT
private :__item_pathname private :__item_pathname
def axis_cget(id, option) def axis_cget(id, option)
ret = itemcget(['axis', id], option) ret = itemcget(['axis', tagid(id)], option)
end end
def axis_configure(id, slot, value=None) def axis_configure(*args)
slot = args.pop
if slot.kind_of?(Hash) if slot.kind_of?(Hash)
value = None
slot = _symbolkey2str(slot) slot = _symbolkey2str(slot)
if cmd = slot.delete('command') if cmd = slot.delete('command')
slot['command'] = proc{|w, tick| slot['command'] = proc{|w, tick|
cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) cmd.call(TkComm.window(w), TkComm.num_or_str(tick))
} }
end end
elsif slot == :command || slot == 'command' else
cmd = value value = slot
value = proc{|w, tick| slot = args.pop
cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) if slot == :command || slot == 'command'
} cmd = value
value = proc{|w, tick|
cmd.call(TkComm.window(w), TkComm.num_or_str(tick))
}
end
end end
itemconfigure(['axis', id], slot, value) id_list = args.flatten.collect!{|id| tagid(id)}.unshift('axis')
itemconfigure(id_list, slot, value)
end end
def axis_configinfo(id, slot=nil) def axis_configinfo(id, slot=nil)
itemconfiginfo(['axis', id], slot) itemconfiginfo(['axis', tagid(id)], slot)
end end
def current_axis_configinfo(id, slot=nil) def current_axis_configinfo(id, slot=nil)
current_itemconfiginfo(['axis', id], slot) current_itemconfiginfo(['axis', tagid(id)], slot)
end end
def crosshairs_cget(option) def crosshairs_cget(option)
@ -114,42 +122,66 @@ module Tk::BLT
end end
def element_cget(id, option) def element_cget(id, option)
itemcget(['element', id], option) itemcget(['element', tagid(id)], option)
end end
def element_configure(id, slot, value=None) def element_configure(*args)
itemconfigure(['element', id], slot, value) slot = args.pop
if slot.kind_of?(Hash)
value = None
else
value = slot
slot = args.pop
end
id_list = args.flatten.collect!{|id| tagid(id)}.unshift('element')
itemconfigure(id_list, slot, value)
end end
def element_configinfo(id, slot=nil) def element_configinfo(id, slot=nil)
itemconfiginfo(['element', id], slot) itemconfiginfo(['element', tagid(id)], slot)
end end
def current_element_configinfo(id, slot=nil) def current_element_configinfo(id, slot=nil)
current_itemconfiginfo(['element', id], slot) current_itemconfiginfo(['element', tagid(id)], slot)
end end
def bar_cget(id, option) def bar_cget(id, option)
itemcget(['bar', id], option) itemcget(['bar', tagid(id)], option)
end end
def bar_configure(id, slot, value=None) def bar_configure(*args)
itemconfigure(['bar', id], slot, value) slot = args.pop
if slot.kind_of?(Hash)
value = None
else
value = slot
slot = args.pop
end
id_list = args.flatten.collect!{|id| tagid(id)}.unshift('bar')
itemconfigure(id_list, slot, value)
end end
def bar_configinfo(id, slot=nil) def bar_configinfo(id, slot=nil)
itemconfiginfo(['bar', id], slot) itemconfiginfo(['bar', tagid(id)], slot)
end end
def current_bar_configinfo(id, slot=nil) def current_bar_configinfo(id, slot=nil)
current_itemconfiginfo(['bar', id], slot) current_itemconfiginfo(['bar', tagid(id)], slot)
end end
def line_cget(id, option) def line_cget(id, option)
itemcget(['line', id], option) itemcget(['line', tagid(id)], option)
end end
def line_configure(id, slot, value=None) def line_configure(*args)
itemconfigure(['line', id], slot, value) slot = args.pop
if slot.kind_of?(Hash)
value = None
else
value = slot
slot = args.pop
end
id_list = args.flatten.collect!{|id| tagid(id)}.unshift('line')
itemconfigure(id_list, slot, value)
end end
def line_configinfo(id, slot=nil) def line_configinfo(id, slot=nil)
itemconfiginfo(['line', id], slot) itemconfiginfo(['line', tagid(id)], slot)
end end
def current_line_configinfo(id, slot=nil) def current_line_configinfo(id, slot=nil)
current_itemconfiginfo(['line', id], slot) current_itemconfiginfo(['line', tagid(id)], slot)
end end
def gridline_cget(option) def gridline_cget(option)
@ -179,16 +211,24 @@ module Tk::BLT
end end
def pen_cget(id, option) def pen_cget(id, option)
itemcget(['pen', id], option) itemcget(['pen', tagid(id)], option)
end end
def pen_configure(id, slot, value=None) def pen_configure(*args)
itemconfigure(['pen', id], slot, value) slot = args.pop
if slot.kind_of?(Hash)
value = None
else
value = slot
slot = args.pop
end
id_list = args.flatten.collect!{|id| tagid(id)}.unshift('pen')
itemconfigure(id_list, slot, value)
end end
def pen_configinfo(id, slot=nil) def pen_configinfo(id, slot=nil)
itemconfiginfo(['pen', id], slot) itemconfiginfo(['pen', tagid(id)], slot)
end end
def current_pen_configinfo(id, slot=nil) def current_pen_configinfo(id, slot=nil)
current_itemconfiginfo(['pen', id], slot) current_itemconfiginfo(['pen', tagid(id)], slot)
end end
def postscript_cget(option) def postscript_cget(option)
@ -205,16 +245,24 @@ module Tk::BLT
end end
def marker_cget(id, option) def marker_cget(id, option)
itemcget(['marker', id], option) itemcget(['marker', tagid(id)], option)
end end
def marker_configure(id, slot, value=None) def marker_configure(*args)
itemconfigure(['marker', id], slot, value) slot = args.pop
if slot.kind_of?(Hash)
value = None
else
value = slot
slot = args.pop
end
id_list = args.flatten.collect!{|id| tagid(id)}.unshift('marker')
itemconfigure(id_list, slot, value)
end end
def marker_configinfo(id, slot=nil) def marker_configinfo(id, slot=nil)
itemconfiginfo(['marker', id], slot) itemconfiginfo(['marker', tagid(id)], slot)
end end
def current_marker_configinfo(id, slot=nil) def current_marker_configinfo(id, slot=nil)
current_itemconfiginfo(['marker', id], slot) current_itemconfiginfo(['marker', tagid(id)], slot)
end end
alias __itemcget itemcget alias __itemcget itemcget
@ -223,7 +271,7 @@ module Tk::BLT
private :__itemcget, :__itemconfiginfo, :__current_itemconfiginfo private :__itemcget, :__itemconfiginfo, :__current_itemconfiginfo
def itemcget(tagOrId, option) def itemcget(tagOrId, option)
ret = __itemcget(tagOrId, option) ret = __itemcget(tagid(tagOrId), option)
if option == 'bindtags' || option == :bindtags if option == 'bindtags' || option == :bindtags
ret.collect{|tag| TkBindTag.id2obj(tag)} ret.collect{|tag| TkBindTag.id2obj(tag)}
else else
@ -231,7 +279,7 @@ module Tk::BLT
end end
end end
def itemconfiginfo(tagOrId, slot = nil) def itemconfiginfo(tagOrId, slot = nil)
ret = __itemconfiginfo(tagOrId, slot) ret = __itemconfiginfo(tagid(tagOrId), slot)
if TkComm::GET_CONFIGINFO_AS_ARRAY if TkComm::GET_CONFIGINFO_AS_ARRAY
if slot if slot
@ -240,9 +288,10 @@ module Tk::BLT
ret[-1] = ret[-1].collect{|tag| TkBindTag.id2obj(tag)} ret[-1] = ret[-1].collect{|tag| TkBindTag.id2obj(tag)}
end end
else else
inf = ret.assoc('bindtags') if (inf = ret.assoc('bindtags'))
inf[-2] = inf[-2].collect{|tag| TkBindTag.id2obj(tag)} inf[-2] = inf[-2].collect{|tag| TkBindTag.id2obj(tag)}
inf[-1] = inf[-1].collect{|tag| TkBindTag.id2obj(tag)} inf[-1] = inf[-1].collect{|tag| TkBindTag.id2obj(tag)}
end
end end
else # ! TkComm::GET_CONFIGINFO_AS_ARRAY else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
@ -256,7 +305,7 @@ module Tk::BLT
ret ret
end end
def current_itemconfiginfo(tagOrId, slot = nil) def current_itemconfiginfo(tagOrId, slot = nil)
ret = __current_itemconfiginfo(tagOrId, slot) ret = __current_itemconfiginfo(tagid(tagOrId), slot)
if (val = ret['bindtags']) if (val = ret['bindtags'])
ret['bindtags'] = val.collect{|tag| TkBindTag.id2obj(tag)} ret['bindtags'] = val.collect{|tag| TkBindTag.id2obj(tag)}
@ -1110,7 +1159,7 @@ module Tk::BLT
def axis_create(id=nil, keys={}) def axis_create(id=nil, keys={})
# tk_send('axis', 'create', tagid(id), keys) # tk_send('axis', 'create', tagid(id), keys)
Tk::BLT::PlotComponent::Axis.new(self, id, keys) Tk::BLT::PlotComponent::Axis.new(self, tagid(id), keys)
end end
def axis_delete(*ids) def axis_delete(*ids)
tk_send('axis', 'delete', *(ids.collect{|id| tagid(id)})) tk_send('axis', 'delete', *(ids.collect{|id| tagid(id)}))
@ -1123,7 +1172,8 @@ module Tk::BLT
list(tk_send('axis', 'limits', tagid(id))) list(tk_send('axis', 'limits', tagid(id)))
end end
def axis_names(*pats) def axis_names(*pats)
simplelist(tk_send('axis', 'names', *pats)).collect{|axis| simplelist(tk_send('axis', 'names',
*(pats.collect{|pat| tagid(pat)}))).collect{|axis|
Tk::BLT::PlotComponent::Axis.id2obj(self, axis) Tk::BLT::PlotComponent::Axis.id2obj(self, axis)
} }
end end
@ -1164,19 +1214,27 @@ module Tk::BLT
def element_create(id=nil, keys={}) def element_create(id=nil, keys={})
# tk_send('element', 'create', tagid(id), keys) # tk_send('element', 'create', tagid(id), keys)
Tk::BLT::PlotComponent::Element.new(self, id, keys) Tk::BLT::PlotComponent::Element.new(self, tagid(id), keys)
end end
def element_activate(id, *indices) def element_activate(*args)
tk_send('element', 'activate', tagid(id), *indices) if args.empty?
self list(tk_send('element', 'activate')).collect{|elem|
Tk::BLT::PlotComponent::Element.id2obj(self, elem)
}
else
# id, *indices
id = args.shift
tk_send('element', 'activate', tagid(id), *args)
end
end end
def element_closest(x, y, var, *args) def element_closest(x, y, var, *args)
if args[-1].kind_of?(Hash) if args[-1].kind_of?(Hash)
keys = args.pop keys = args.pop
bool(tk_send('element', 'activate', x, y, var, bool(tk_send('element', 'closest', x, y, var,
*(hash_kv(keys).concat(args)))) *(hash_kv(keys).concat(args.collect{|id| tagid(id)}))))
else else
bool(tk_send('element', 'activate', x, y, var, *args)) bool(tk_send('element', 'closest', x, y, var,
*(args.collect{|id| tagid(id)})))
end end
end end
def element_deactivate(*ids) def element_deactivate(*ids)
@ -1191,7 +1249,8 @@ module Tk::BLT
bool(tk_send('element', 'exists', tagid(id))) bool(tk_send('element', 'exists', tagid(id)))
end end
def element_names(*pats) def element_names(*pats)
simplelist(tk_send('element', 'names', *pats)).collect{|elem| simplelist(tk_send('element', 'names',
*(pats.collect{|pat| tagid(pat)}))).collect{|elem|
Tk::BLT::PlotComponent::Element.id2obj(self, elem) Tk::BLT::PlotComponent::Element.id2obj(self, elem)
} }
end end
@ -1199,7 +1258,7 @@ module Tk::BLT
if names.empty? if names.empty?
simplelist(tk_send('element', 'show')) simplelist(tk_send('element', 'show'))
else else
tk_send('element', 'show', *names) tk_send('element', 'show', *(names.collect{|n| tagid(n)}))
self self
end end
end end
@ -1211,20 +1270,28 @@ module Tk::BLT
def bar_create(id=nil, keys={}) def bar_create(id=nil, keys={})
# tk_send('bar', 'create', tagid(id), keys) # tk_send('bar', 'create', tagid(id), keys)
Tk::BLT::PlotComponent::Bar.new(self, id, keys) Tk::BLT::PlotComponent::Bar.new(self, tagid(id), keys)
end end
alias bar bar_create alias bar bar_create
def bar_activate(id, *indices) def bar_activate(*args)
tk_send('bar', 'activate', tagid(id), *indices) if args.empty?
self list(tk_send('bar', 'activate')).collect{|elem|
Tk::BLT::PlotComponent::Element.id2obj(self, elem)
}
else
# id, *indices
id = args.shift
tk_send('bar', 'activate', tagid(id), *args)
end
end end
def bar_closest(x, y, var, *args) def bar_closest(x, y, var, *args)
if args[-1].kind_of?(Hash) if args[-1].kind_of?(Hash)
keys = args.pop keys = args.pop
bool(tk_send('bar', 'activate', x, y, var, bool(tk_send('bar', 'closest', x, y, var,
*(hash_kv(keys).concat(args)))) *(hash_kv(keys).concat(args.collect{|id| tagid(id)}))))
else else
bool(tk_send('bar', 'activate', x, y, var, *args)) bool(tk_send('bar', 'closest', x, y, var,
*(args.collect{|id| tagid(id)})))
end end
end end
def bar_deactivate(*ids) def bar_deactivate(*ids)
@ -1239,7 +1306,8 @@ module Tk::BLT
bool(tk_send('bar', 'exists', tagid(id))) bool(tk_send('bar', 'exists', tagid(id)))
end end
def bar_names(*pats) def bar_names(*pats)
simplelist(tk_send('bar', 'names', *pats)).collect{|elem| simplelist(tk_send('bar', 'names',
*(pats.collect{|pat| tagid(pat)}))).collect{|elem|
Tk::BLT::PlotComponent::Element.id2obj(self, elem) Tk::BLT::PlotComponent::Element.id2obj(self, elem)
} }
end end
@ -1247,7 +1315,7 @@ module Tk::BLT
if names.empty? if names.empty?
simplelist(tk_send('bar', 'show')) simplelist(tk_send('bar', 'show'))
else else
tk_send('bar', 'show', *names) tk_send('bar', 'show', *(names.collect{|n| tagid(n)}))
self self
end end
end end
@ -1259,20 +1327,28 @@ module Tk::BLT
def line_create(id=nil, keys={}) def line_create(id=nil, keys={})
# tk_send('line', 'create', tagid(id), keys) # tk_send('line', 'create', tagid(id), keys)
Tk::BLT::PlotComponent::Line.new(self, id, keys) Tk::BLT::PlotComponent::Line.new(self, tagid(id), keys)
end end
alias bar line_create alias bar line_create
def line_activate(id, *indices) def line_activate(*args)
tk_send('line', 'activate', tagid(id), *indices) if args.empty?
self list(tk_send('line', 'activate')).collect{|elem|
Tk::BLT::PlotComponent::Element.id2obj(self, elem)
}
else
# id, *indices
id = args.shift
tk_send('line', 'activate', tagid(id), *args)
end
end end
def line_closest(x, y, var, *args) def line_closest(x, y, var, *args)
if args[-1].kind_of?(Hash) if args[-1].kind_of?(Hash)
keys = args.pop keys = args.pop
bool(tk_send('line', 'activate', x, y, var, bool(tk_send('line', 'closest', x, y, var,
*(hash_kv(keys).concat(args)))) *(hash_kv(keys).concat(args.collect{|id| tagid(id)}))))
else else
bool(tk_send('line', 'activate', x, y, var, *args)) bool(tk_send('line', 'closest', x, y, var,
*(args.collect{|id| tagid(id)})))
end end
end end
def line_deactivate(*ids) def line_deactivate(*ids)
@ -1287,7 +1363,8 @@ module Tk::BLT
bool(tk_send('line', 'exists', tagid(id))) bool(tk_send('line', 'exists', tagid(id)))
end end
def line_names(*pats) def line_names(*pats)
simplelist(tk_send('line', 'names', *pats)).collect{|elem| simplelist(tk_send('line', 'names',
*(pats.collect{|pat| tagid(pat)}))).collect{|elem|
Tk::BLT::PlotComponent::Element.id2obj(self, elem) Tk::BLT::PlotComponent::Element.id2obj(self, elem)
} }
end end
@ -1295,7 +1372,7 @@ module Tk::BLT
if names.empty? if names.empty?
simplelist(tk_send('line', 'show')) simplelist(tk_send('line', 'show'))
else else
tk_send('line', 'show', *names) tk_send('line', 'show', *(names.collect{|n| tagid(n)}))
self self
end end
end end
@ -1321,12 +1398,16 @@ module Tk::BLT
################### ###################
def legend_activate(*pats) def legend_activate(*pats)
tk_send('legend', 'activate', *pats) list(tk_send('legend', 'activate',
self *(pats.collect{|pat| tagid(pat)}))).collect{|elem|
Tk::BLT::PlotComponent::Element.id2obj(self, elem)
}
end end
def legend_deactivate(*pats) def legend_deactivate(*pats)
tk_send('legend', 'deactivate', *pats) list(tk_send('legend', 'deactivate',
self *(pats.collect{|pat| tagid(pat)}))).collect{|elem|
Tk::BLT::PlotComponent::Element.id2obj(self, elem)
}
end end
def legend_get(pos, y=nil) def legend_get(pos, y=nil)
if y if y
@ -1343,14 +1424,15 @@ module Tk::BLT
def pen_create(id=nil, keys={}) def pen_create(id=nil, keys={})
# tk_send('pen', 'create', tagid(id), keys) # tk_send('pen', 'create', tagid(id), keys)
Tk::BLT::PlotComponent::Pen.new(self, id, keys) Tk::BLT::PlotComponent::Pen.new(self, tagid(id), keys)
end end
def pen_delete(*ids) def pen_delete(*ids)
tk_send('pen', 'delete', *(ids.collect{|id| tagid(id)})) tk_send('pen', 'delete', *(ids.collect{|id| tagid(id)}))
self self
end end
def pen_names(*pats) def pen_names(*pats)
simplelist(tk_send('pen', 'names', *pats)).collect{|pen| simplelist(tk_send('pen', 'names',
*(pats.collect{|pat| tagid(pat)}))).collect{|pen|
Tk::BLT::PlotComponent::Pen.id2obj(self, pen) Tk::BLT::PlotComponent::Pen.id2obj(self, pen)
} }
end end
@ -1419,7 +1501,8 @@ module Tk::BLT
bool(tk_send('marker', 'exists', tagid(id))) bool(tk_send('marker', 'exists', tagid(id)))
end end
def marker_names(*pats) def marker_names(*pats)
simplelist(tk_send('marker', 'names', *pats)).collect{|id| simplelist(tk_send('marker', 'names',
*(pats.collect{|pat| tagid(pat)}))).collect{|id|
Tk::BLT::PlotComponent::Marker.id2obj(self, id) Tk::BLT::PlotComponent::Marker.id2obj(self, id)
} }
end end

File diff suppressed because it is too large Load Diff