* ext/tk/lib/tk.rb (TkWindow.initialize): accept 'without_creating'

option without 'widgetname' option to allow creating a widget object
  which is used as an argument of Tcl/Tk's widget allocation commands.
* ext/tk/lib/tk/image.rb (TkImage.initialize): accept 'imagename'
  option to create a image object by the given name.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2005-04-01 17:22:02 +00:00
parent 011527f455
commit 4f8df7dcc4
8 changed files with 230 additions and 114 deletions

View File

@ -1,3 +1,12 @@
Sat Apr 2 02:19:11 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb (TkWindow.initialize): accept 'without_creating'
option without 'widgetname' option to allow creating a widget object
which is used as an argument of Tcl/Tk's widget allocation commands.
* ext/tk/lib/tk/image.rb (TkImage.initialize): accept 'imagename'
option to create a image object by the given name.
Thu Mar 31 23:52:48 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp> Thu Mar 31 23:52:48 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/tk/sample/tkextlib/treectrl/demo.rb: should use Hash#index. * ext/tk/sample/tkextlib/treectrl/demo.rb: should use Hash#index.

View File

@ -1,3 +1,13 @@
2005-04-02 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* lib/tkextlib/blt/component.rb: add TreeCtrl#legend_window_create().
* sample/tkextlib/blt/graph6.rb: use legend_window_create().
* lib/tkextlib/blt/tree.rb: forget to call tagid().
* lib/tkextlib/blt/treeview.rb: ditto.
2005-04-01 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> 2005-04-01 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* sample/tkextlib/treectrl/demo.rb: bridge the gap of * sample/tkextlib/treectrl/demo.rb: bridge the gap of

View File

@ -3425,19 +3425,19 @@ class TkWindow<TkObject
widgetname = keys.delete('widgetname') widgetname = keys.delete('widgetname')
install_win(if parent then parent.path end, widgetname) install_win(if parent then parent.path end, widgetname)
without_creating = keys.delete('without_creating') without_creating = keys.delete('without_creating')
if without_creating && !widgetname # if without_creating && !widgetname
fail ArgumentError, # fail ArgumentError,
"if set 'without_creating' to true, need to define 'widgetname'" # "if set 'without_creating' to true, need to define 'widgetname'"
end # end
elsif keys elsif keys
keys = _symbolkey2str(keys) keys = _symbolkey2str(keys)
widgetname = keys.delete('widgetname') widgetname = keys.delete('widgetname')
install_win(if parent then parent.path end, widgetname) install_win(if parent then parent.path end, widgetname)
without_creating = keys.delete('without_creating') without_creating = keys.delete('without_creating')
if without_creating && !widgetname # if without_creating && !widgetname
fail ArgumentError, # fail ArgumentError,
"if set 'without_creating' to true, need to define 'widgetname'" # "if set 'without_creating' to true, need to define 'widgetname'"
end # end
else else
install_win(if parent then parent.path end) install_win(if parent then parent.path end)
end end

View File

@ -15,9 +15,16 @@ class TkImage<TkObject
TkCore::INTERP.init_ip_env{ Tk_IMGTBL.clear } TkCore::INTERP.init_ip_env{ Tk_IMGTBL.clear }
def initialize(keys=nil) def initialize(keys=nil)
# @path = Tk_Image_ID.join('') @path = nil
@path = Tk_Image_ID.join(TkCore::INTERP._ip_id_) if keys.kind_of?(Hash)
Tk_Image_ID[1].succ! keys = _symbolkey2str(keys)
@path = keys.delete('imagename')
end
unless @path
# @path = Tk_Image_ID.join('')
@path = Tk_Image_ID.join(TkCore::INTERP._ip_id_)
Tk_Image_ID[1].succ!
end
tk_call_without_enc('image', 'create', @type, @path, *hash_kv(keys, true)) tk_call_without_enc('image', 'create', @type, @path, *hash_kv(keys, true))
Tk_IMGTBL[@path] = self Tk_IMGTBL[@path] = self
end end

View File

@ -350,6 +350,7 @@ module Tk::BLT
@axis = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze @axis = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
OBJ_ID[1].succ! OBJ_ID[1].succ!
end end
@path = @id
@parent = @chart = chart @parent = @chart = chart
@cpath = @chart.path @cpath = @chart.path
Axis::OBJ_TBL[@cpath][@axis] = self Axis::OBJ_TBL[@cpath][@axis] = self
@ -442,14 +443,15 @@ module Tk::BLT
@cpath = @chart.path @cpath = @chart.path
Crosshairs::OBJ_TBL[@cpath] = self Crosshairs::OBJ_TBL[@cpath] = self
@chart.crosshair_configure(keys) unless keys.empty? @chart.crosshair_configure(keys) unless keys.empty?
@path = @id = 'crosshairs'
end end
def id def id
'crosshairs' @id
end end
def to_eval def to_eval
'crosshairs' @id
end end
def cget(option) def cget(option)
@ -531,6 +533,7 @@ module Tk::BLT
@element = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze @element = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
OBJ_ID[1].succ! OBJ_ID[1].succ!
end end
@path = @id
@parent = @chart = chart @parent = @chart = chart
@cpath = @chart.path @cpath = @chart.path
@typename = self.class::ElementTypeName @typename = self.class::ElementTypeName
@ -570,7 +573,6 @@ module Tk::BLT
def activate(*args) def activate(*args)
@chart.element_activate(@id, *args) @chart.element_activate(@id, *args)
self
end end
def closest(x, y, var, keys={}) def closest(x, y, var, keys={})
@ -625,14 +627,15 @@ module Tk::BLT
@cpath = @chart.path @cpath = @chart.path
GridLine::OBJ_TBL[@cpath] = self GridLine::OBJ_TBL[@cpath] = self
@chart.gridline_configure(keys) unless keys.empty? @chart.gridline_configure(keys) unless keys.empty?
@path = @id = 'grid'
end end
def id def id
'grid' @id
end end
def to_eval def to_eval
'grid' @id
end end
def cget(option) def cget(option)
@ -678,14 +681,15 @@ module Tk::BLT
@cpath = @chart.path @cpath = @chart.path
Crosshairs::OBJ_TBL[@cpath] = self Crosshairs::OBJ_TBL[@cpath] = self
@chart.crosshair_configure(keys) unless keys.empty? @chart.crosshair_configure(keys) unless keys.empty?
@path = @id = 'legend'
end end
def id def id
'legend' @id
end end
def to_eval def to_eval
'legend' @id
end end
def cget(option) def cget(option)
@ -704,12 +708,10 @@ module Tk::BLT
def activate(*args) def activate(*args)
@chart.legend_activate(*args) @chart.legend_activate(*args)
self
end end
def deactivate(*args) def deactivate(*args)
@chart.legend_deactivate(*args) @chart.legend_deactivate(*args)
self
end end
def get(pos, y=nil) def get(pos, y=nil)
@ -750,6 +752,7 @@ module Tk::BLT
@pen = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze @pen = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
OBJ_ID[1].succ! OBJ_ID[1].succ!
end end
@path = @id
@parent = @chart = chart @parent = @chart = chart
@cpath = @chart.path @cpath = @chart.path
Pen::OBJ_TBL[@cpath][@pen] = self Pen::OBJ_TBL[@cpath][@pen] = self
@ -807,14 +810,15 @@ module Tk::BLT
@cpath = @chart.path @cpath = @chart.path
Postscript::OBJ_TBL[@cpath] = self Postscript::OBJ_TBL[@cpath] = self
@chart.postscript_configure(keys) unless keys.empty? @chart.postscript_configure(keys) unless keys.empty?
@path = @id = 'postscript'
end end
def id def id
'postscript' @id
end end
def to_eval def to_eval
'postscript' @id
end end
def cget(option) def cget(option)
@ -925,25 +929,25 @@ module Tk::BLT
obj = self.allocate obj = self.allocate
obj.instance_eval{ obj.instance_eval{
@parent = @chart = chart @parent = @chart = chart
@path = chart.path @cpath = chart.path
@id = id @id = id
unless Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path] unless Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath]
Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path] = {} Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] = {}
end end
Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path][@id] = self Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath][@id] = self
} }
obj obj
end end
def initialize(parent, *args) def initialize(parent, *args)
@parent = @chart = parent @parent = @chart = parent
@path = parent.path @cpath = parent.path
@id = create_self(*args) # an integer number as 'item id' @path = @id = create_self(*args) # an integer number as 'item id'
unless Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path] unless Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath]
Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path] = {} Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] = {}
end end
Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path][@id] = self Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath][@id] = self
end end
def create_self(*args) def create_self(*args)
self.class.create(@chart, *args) # return an integer as 'item id' self.class.create(@chart, *args) # return an integer as 'item id'
@ -1397,6 +1401,34 @@ module Tk::BLT
################### ###################
def legend_window_create(parent=nil, keys=nil)
if parent.kind_of?(Hash)
keys = _symbolkey2str(parent)
parent = keys.delete('parent')
widgetname = keys.delete('widgetname')
keys.delete('without_creating')
elsif keys
keys = _symbolkey2str(keys)
widgetname = keys.delete('widgetname')
keys.delete('without_creating')
end
legend = self.class.new(parent, :without_creating=>true,
:widgetname=>widgetname)
class << legend
def __destroy_hook__
TkCore::INTERP.tk_windows.delete(@path)
end
end
if keys
self.legend_configure(keys.update('position'=>legend))
else
self.legend_configure('position'=>legend)
end
legend
end
def legend_activate(*pats) def legend_activate(*pats)
list(tk_send('legend', 'activate', list(tk_send('legend', 'activate',
*(pats.collect{|pat| tagid(pat)}))).collect{|elem| *(pats.collect{|pat| tagid(pat)}))).collect{|elem|

View File

@ -12,7 +12,7 @@ module Tk::BLT
################################### ###################################
class Node < TkObject class Node < TkObject
TreeNodeID_TBL = TkCore::INTERP.create_table TreeNodeID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{ TreeNodeID_TBL.clear } TkCore::INTERP.init_ip_env{ TreeNodeID_TBL.clear }
@ -271,6 +271,10 @@ module Tk::BLT
TreeTagID_TBL[@tpath][@id] = self TreeTagID_TBL[@tpath][@id] = self
end end
def id
@id
end
def add(*nodes) def add(*nodes)
tk_call(@tpath, 'tag', 'add', @id, *nodes) tk_call(@tpath, 'tag', 'add', @id, *nodes)
self self
@ -368,6 +372,10 @@ module Tk::BLT
@path = @id = tk_call(@tpath, 'notify', 'create', *args) @path = @id = tk_call(@tpath, 'notify', 'create', *args)
end end
def id
@id
end
def delete() def delete()
tk_call(@tpath, 'notify', 'delete', @id) tk_call(@tpath, 'notify', 'delete', @id)
NotifyID_TBL[tpath].delete(@id) NotifyID_TBL[tpath].delete(@id)
@ -445,6 +453,10 @@ module Tk::BLT
}) })
end end
def id
@id
end
def delete() def delete()
tk_call(@tpath, 'trace', 'delete', @id) tk_call(@tpath, 'trace', 'delete', @id)
TraceID_TBL[tpath].delete(@id) TraceID_TBL[tpath].delete(@id)
@ -524,6 +536,17 @@ module Tk::BLT
Tk::BLT::Tree::Trace::TraceID_TBL.delete(@path) Tk::BLT::Tree::Trace::TraceID_TBL.delete(@path)
end end
def tagid(tag)
if tag.kind_of?(Tk::BLT::Tree::Node) ||
tag.kind_of?(Tk::BLT::Tree::Tag) ||
tag.kind_of?(Tk::BLT::Tree::Notify) ||
tag.kind_of?(Tk::BLT::Tree::Trace)
tag.id
else
tag # maybe an Array of configure paramters
end
end
def destroy() def destroy()
tk_call('::blt::tree', 'destroy', @id) tk_call('::blt::tree', 'destroy', @id)
self self
@ -531,11 +554,11 @@ module Tk::BLT
def ancestor(node1, node2) def ancestor(node1, node2)
Tk::BLT::Tree::Node.id2obj(self, tk_call('::blt::tree', 'ancestor', Tk::BLT::Tree::Node.id2obj(self, tk_call('::blt::tree', 'ancestor',
node1, node2)) tagid(node1), tagid(node2)))
end end
def apply(node, keys={}) def apply(node, keys={})
tk_call('::blt::tree', 'apply', node, __conv_keyonly_opts(keys)) tk_call('::blt::tree', 'apply', tagid(node), __conv_keyonly_opts(keys))
self self
end end
@ -545,30 +568,30 @@ module Tk::BLT
end end
def children(node) def children(node)
simplelist(tk_call('::blt::tree', 'children', node)).collect{|n| simplelist(tk_call('::blt::tree', 'children', tagid(node))).collect{|n|
Tk::BLT::Tree::Node.id2obj(self, n) Tk::BLT::Tree::Node.id2obj(self, n)
} }
end end
def copy(src, parent, keys={}) def copy(src, parent, keys={})
id = tk_call('::blt::tree', 'copy', src, parent, id = tk_call('::blt::tree', 'copy', tagid(src), tagid(parent),
__conv_keyonly_opts(keys)) __conv_keyonly_opts(keys))
Tk::BLT::Tree::Node.new(self, nil, 'node'=>id) Tk::BLT::Tree::Node.new(self, nil, 'node'=>id)
end end
def copy_to(src, dest_tree, parent, keys={}) def copy_to(src, dest_tree, parent, keys={})
return copy(src, parent, keys={}) unless dest_tree return copy(src, parent, keys={}) unless dest_tree
id = tk_call('::blt::tree', 'copy', src, dest_tree, parent, id = tk_call('::blt::tree', 'copy', tagid(src), dest_tree,
__conv_keyonly_opts(keys)) tagid(parent), __conv_keyonly_opts(keys))
Tk::BLT::Tree::Node.new(dest_tree, nil, 'node'=>id) Tk::BLT::Tree::Node.new(dest_tree, nil, 'node'=>id)
end end
def degree(node) def degree(node)
number(tk_call('::blt::tree', 'degree', node)) number(tk_call('::blt::tree', 'degree', tagid(node)))
end end
def delete(*nodes) def delete(*nodes)
tk_call('::blt::tree', 'delete', *nodes) tk_call('::blt::tree', 'delete', *(nodes.collect{|node| tagid(node)}))
nodes.each{|node| nodes.each{|node|
if node.kind_of?(Tk::BLT::Tree::Node) if node.kind_of?(Tk::BLT::Tree::Node)
Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.id) Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.id)
@ -580,78 +603,82 @@ module Tk::BLT
end end
def depth(node) def depth(node)
number(tk_call('::blt::tree', 'depth', node)) number(tk_call('::blt::tree', 'depth', tagid(node)))
end end
def dump(node) def dump(node)
simplelist(tk_call('::blt::tree', 'dump', node)).collect{|n| simplelist(tk_call('::blt::tree', 'dump', tagid(node))).collect{|n|
simplelist(n) simplelist(n)
} }
end end
def dump_to_file(node, file) def dump_to_file(node, file)
tk_call('::blt::tree', 'dumpfile', node, file) tk_call('::blt::tree', 'dumpfile', tagid(node), file)
self self
end end
def exist?(node, key=None) def exist?(node, key=None)
bool(tk_call('::blt::tree', 'exists', node, key)) bool(tk_call('::blt::tree', 'exists', tagid(node), key))
end end
def find(node, keys={}) def find(node, keys={})
simplelist(tk_call('::blt::tree', 'find', node, simplelist(tk_call('::blt::tree', 'find', tagid(node),
__conv_keyonly_opts(keys))).collect{|n| __conv_keyonly_opts(keys))).collect{|n|
Tk::BLT::Tree::Node.id2obj(self, n) Tk::BLT::Tree::Node.id2obj(self, n)
} }
end end
def find_child(node, label) def find_child(node, label)
ret = tk_call('::blt::tree', 'findchild', node, label) ret = tk_call('::blt::tree', 'findchild', tagid(node), label)
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret) (ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end end
def first_child(node) def first_child(node)
ret = tk_call('::blt::tree', 'firstchild', node) ret = tk_call('::blt::tree', 'firstchild', tagid(node))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret) (ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end end
def get(node) def get(node)
Hash[*simplelist(tk_call('::blt::tree', 'get', node))] Hash[*simplelist(tk_call('::blt::tree', 'get', tagid(node)))]
end end
def get_value(node, key, default_val=None) def get_value(node, key, default_val=None)
tk_call('::blt::tree', 'get', node, key, default_val) tk_call('::blt::tree', 'get', tagid(node), key, default_val)
end end
def index(node) def index(node)
Tk::BLT::Tree::Node.id2obj(self, tk_call('::blt::tree', 'index', node)) Tk::BLT::Tree::Node.id2obj(self,
tk_call('::blt::tree', 'index', tagid(node)))
end end
def insert(parent, keys={}) def insert(parent, keys={})
id = tk_call('::blt::tree', 'insert', parent, keys) id = tk_call('::blt::tree', 'insert', tagid(parent), keys)
Tk::BLT::Tree::Node.new(self, nil, 'node'=>id) Tk::BLT::Tree::Node.new(self, nil, 'node'=>id)
end end
def ancestor?(node1, node2) def ancestor?(node1, node2)
bool(tk_call('::blt::tree', 'is', 'ancestor', node1, node2)) bool(tk_call('::blt::tree', 'is', 'ancestor',
tagid(node1), tagid(node2)))
end end
def before?(node1, node2) def before?(node1, node2)
bool(tk_call('::blt::tree', 'is', 'before', node1, node2)) bool(tk_call('::blt::tree', 'is', 'before',
tagid(node1), tagid(node2)))
end end
def leaf?(node) def leaf?(node)
bool(tk_call('::blt::tree', 'is', 'leaf', node)) bool(tk_call('::blt::tree', 'is', 'leaf', tagid(node)))
end end
def link?(node) def link?(node)
bool(tk_call('::blt::tree', 'is', 'link', node)) bool(tk_call('::blt::tree', 'is', 'link', tagid(node)))
end end
def root?(node) def root?(node)
bool(tk_call('::blt::tree', 'is', 'root', node)) bool(tk_call('::blt::tree', 'is', 'root', tagid(node)))
end end
def keys(node, *nodes) def keys(node, *nodes)
if nodes.empty? if nodes.empty?
simplelist(tk_call('blt::tree', 'keys', node)) simplelist(tk_call('blt::tree', 'keys', tagid(node)))
else else
simplelist(tk_call('blt::tree', 'keys', node, *nodes)).collect{|lst| simplelist(tk_call('blt::tree', 'keys', tagid(node),
*(nodes.collect{|n| tagid(n)}))).collect{|lst|
simplelist(lst) simplelist(lst)
} }
end end
@ -659,36 +686,36 @@ module Tk::BLT
def label(node, text=nil) def label(node, text=nil)
if text if text
tk_call('::blt::tree', 'label', node, text) tk_call('::blt::tree', 'label', tagid(node), text)
text text
else else
tk_call('::blt::tree', 'label', node) tk_call('::blt::tree', 'label', tagid(node))
end end
end end
def last_child(node) def last_child(node)
ret = tk_call('::blt::tree', 'lastchild', node) ret = tk_call('::blt::tree', 'lastchild', tagid(node))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret) (ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end end
def link(parent, node, keys={}) def link(parent, node, keys={})
ret = tk_call('::blt::tree', 'link', parent, node, ret = tk_call('::blt::tree', 'link', tagid(parent), tagid(node),
__conv_keyonly_opts(keys)) __conv_keyonly_opts(keys))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret) (ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end end
def move(node, dest, keys={}) def move(node, dest, keys={})
tk_call('::blt::tree', 'move', node, dest, keys) tk_call('::blt::tree', 'move', tagid(node), tagid(dest), keys)
self self
end end
def next(node) def next(node)
ret = tk_call('::blt::tree', 'next', node) ret = tk_call('::blt::tree', 'next', tagid(node))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret) (ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end end
def next_sibling(node) def next_sibling(node)
ret = tk_call('::blt::tree', 'nextsibling', node) ret = tk_call('::blt::tree', 'nextsibling', tagid(node))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret) (ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end end
@ -707,7 +734,7 @@ module Tk::BLT
end end
def notify_info(id) def notify_info(id)
lst = simplelist(tk_call(@path, 'notify', 'info', id)) lst = simplelist(tk_call(@path, 'notify', 'info', tagid(id)))
lst[0] = Tk::BLT::Tree::Notify.id2obj(self, lst[0]) lst[0] = Tk::BLT::Tree::Notify.id2obj(self, lst[0])
lst[1] = simplelist(lst[1]).collect{|flag| flag[1..-1]} lst[1] = simplelist(lst[1]).collect{|flag| flag[1..-1]}
lst[2] = tk_tcl2ruby(lst[2]) lst[2] = tk_tcl2ruby(lst[2])
@ -721,30 +748,30 @@ module Tk::BLT
end end
def parent(node) def parent(node)
ret = tk_call('::blt::tree', 'parent', node) ret = tk_call('::blt::tree', 'parent', tagid(node))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret) (ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end end
def fullpath(node) def fullpath(node)
tk_call('::blt::tree', 'path', node) tk_call('::blt::tree', 'path', tagid(node))
end end
def position(node) def position(node)
number(tk_call('::blt::tree', 'position', node)) number(tk_call('::blt::tree', 'position', tagid(node)))
end end
def previous(node) def previous(node)
ret = tk_call('::blt::tree', 'previous', node) ret = tk_call('::blt::tree', 'previous', tagid(node))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret) (ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end end
def prev_sibling(node) def prev_sibling(node)
ret = tk_call('::blt::tree', 'prevsibling', node) ret = tk_call('::blt::tree', 'prevsibling', tagid(node))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret) (ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end end
def restore(node, str, keys={}) def restore(node, str, keys={})
tk_call('::blt::tree', 'restore', node, str, tk_call('::blt::tree', 'restore', tagid(node), str,
__conv_keyonly_opts(keys)) __conv_keyonly_opts(keys))
self self
end end
@ -752,12 +779,12 @@ module Tk::BLT
keys = __conv_keyonly_opts(keys) keys = __conv_keyonly_opts(keys)
keys.delete('overwrite') keys.delete('overwrite')
keys.delete(:overwrite) keys.delete(:overwrite)
tk_call('::blt::tree', 'restore', node, str, '-overwrite', keys) tk_call('::blt::tree', 'restore', tagid(node), str, '-overwrite', keys)
self self
end end
def restore_from_file(node, file, keys={}) def restore_from_file(node, file, keys={})
tk_call('::blt::tree', 'restorefile', node, file, tk_call('::blt::tree', 'restorefile', tagid(node), file,
__conv_keyonly_opts(keys)) __conv_keyonly_opts(keys))
self self
end end
@ -765,12 +792,14 @@ module Tk::BLT
keys = __conv_keyonly_opts(keys) keys = __conv_keyonly_opts(keys)
keys.delete('overwrite') keys.delete('overwrite')
keys.delete(:overwrite) keys.delete(:overwrite)
tk_call('::blt::tree', 'restorefile', node, file, '-overwrite', keys) tk_call('::blt::tree', 'restorefile', tagid(node), file,
'-overwrite', keys)
self self
end end
def root(node=None) def root(node=None)
Tk::BLT::Tree::Node.id2obj(self, tk_call('::blt::tree', 'root', node)) Tk::BLT::Tree::Node.id2obj(self, tk_call('::blt::tree', 'root',
tagid(node)))
end end
def set(node, data) def set(node, data)
@ -779,26 +808,27 @@ module Tk::BLT
end end
args = [] args = []
data.each{|k, v| args << k << v} data.each{|k, v| args << k << v}
tk_call('::blt::tree', 'set', node, *args) tk_call('::blt::tree', 'set', tagid(node), *args)
self self
end end
def size(node) def size(node)
number(tk_call('::blt::tree', 'size', node)) number(tk_call('::blt::tree', 'size', tagid(node)))
end end
def sort(node, keys={}) def sort(node, keys={})
tk_call('::blt::tree', 'sort', node, __conv_keyonly_opts(keys)) tk_call('::blt::tree', 'sort', tagid(node), __conv_keyonly_opts(keys))
self self
end end
def tag_add(tag, *nodes) def tag_add(tag, *nodes)
tk_call(@path, 'tag', 'add', tag, *nodes) tk_call(@path, 'tag', 'add', tagid(tag), *(nodes.collect{|n| tagid(n)}))
self self
end end
def tag_delete(tag, *nodes) def tag_delete(tag, *nodes)
tk_call(@path, 'tag', 'delete', tag, *nodes) tk_call(@path, 'tag', 'delete', tagid(tag),
*(nodes.collect{|n| tagid(n)}))
self self
end end
@ -810,30 +840,32 @@ module Tk::BLT
end end
def tag_get(node, *patterns) def tag_get(node, *patterns)
simplelist(tk_call(@tpath, 'tag', 'get', node, *patterns)).collect{|str| simplelist(tk_call(@tpath, 'tag', 'get', tagid(node),
*(patterns.collect{|pat| tagid(pat)}))).collect{|str|
Tk::BLT::Tree::Tag.id2obj(self, str) Tk::BLT::Tree::Tag.id2obj(self, str)
} }
end end
def tag_names(node = None) def tag_names(node = None)
simplelist(tk_call(@tpath, 'tag', 'names', node)).collect{|str| simplelist(tk_call(@tpath, 'tag', 'names', tagid(node))).collect{|str|
Tk::BLT::Tree::Tag.id2obj(self, str) Tk::BLT::Tree::Tag.id2obj(self, str)
} }
end end
def tag_nodes(tag) def tag_nodes(tag)
simplelist(tk_call(@tpath, 'tag', 'nodes',tag)).collect{|node| simplelist(tk_call(@tpath, 'tag', 'nodes', tagid(tag))).collect{|node|
Tk::BLT::Tree::Node.id2obj(self, node) Tk::BLT::Tree::Node.id2obj(self, node)
} }
end end
def tag_set(node, *tags) def tag_set(node, *tags)
tk_call(@path, 'tag', 'set', node, *tags) tk_call(@path, 'tag', 'set', tagid(node), *(tags.collect{|t| tagid(t)}))
self self
end end
def tag_unset(node, *tags) def tag_unset(node, *tags)
tk_call(@path, 'tag', 'unset', node, *tags) tk_call(@path, 'tag', 'unset', tagid(node),
*(tags.collect{|t| tagid(t)}))
self self
end end
@ -841,18 +873,28 @@ module Tk::BLT
Tk::BLT::Tree::Trace.new(self, *args, &b) Tk::BLT::Tree::Trace.new(self, *args, &b)
end end
=begin
def trace_delete(*args) def trace_delete(*args)
if id.kind_of?(Tk::BLT::Tree::Trace) args.each{|id|
id.delete if id.kind_of?(Tk::BLT::Tree::Trace)
else id.delete
tk_call(@path, 'trace', 'delete', id) else
Tk::BLT::Tree::Trace::TraceID_TBL[@path].delete(id.to_s) tk_call(@path, 'trace', 'delete', id)
end Tk::BLT::Tree::Trace::TraceID_TBL[@path].delete(id.to_s)
end
self
}
end
=end
def trace_delete(*args)
args = args.collect{|id| tagid(id)}
tk_call(@path, 'trace', 'delete', *args)
args.each{|id| Tk::BLT::Tree::Trace::TraceID_TBL[@path].delete(id.to_s)}
self self
end end
def trace_info(*args) def trace_info(id)
lst = simplelist(tk_call(@path, 'trace', 'info', id)) lst = simplelist(tk_call(@path, 'trace', 'info', tagid(id)))
lst[0] = Tk::BLT::Tree::Trace.id2obj(self, lst[0]) lst[0] = Tk::BLT::Tree::Trace.id2obj(self, lst[0])
lst[2] = simplelist(lst[2]) lst[2] = simplelist(lst[2])
lst[3] = tk_tcl2ruby(lst[3]) lst[3] = tk_tcl2ruby(lst[3])
@ -866,16 +908,16 @@ module Tk::BLT
end end
def type(node, key) def type(node, key)
tk_call('::blt::tree', 'type', node, key) tk_call('::blt::tree', 'type', tagid(node), key)
end end
def unset(node, *keys) def unset(node, *keys)
tk_call('::blt::tree', 'unset', node, *keys) tk_call('::blt::tree', 'unset', tagid(node), *keys)
self self
end end
def values(node, key=None) def values(node, key=None)
simplelist(tk_call('::blt::tree', 'values', node, key)) simplelist(tk_call('::blt::tree', 'values', tagid(node), key))
end end
end end
end end

View File

@ -297,7 +297,7 @@ class Tk::BLT::Treeview
else else
cmd = Proc.new cmd = Proc.new
end end
_bind([@path, 'bind', tag], seq, cmd, *args) _bind([@path, 'bind', tagid(tag)], seq, cmd, *args)
self self
end end
def tag_bind_append(tag, seq, *args) def tag_bind_append(tag, seq, *args)
@ -306,15 +306,15 @@ class Tk::BLT::Treeview
else else
cmd = Proc.new cmd = Proc.new
end end
_bind_append([@path, 'bind', tag], seq, cmd, *args) _bind_append([@path, 'bind', tagid(tag)], seq, cmd, *args)
self self
end end
def tag_bind_remove(tag, seq) def tag_bind_remove(tag, seq)
_bind_remove([@path, 'bind', tag], seq) _bind_remove([@path, 'bind', tagid(tag)], seq)
self self
end end
def tag_bindinfo(tag, seq=nil) def tag_bindinfo(tag, seq=nil)
_bindinfo([@path, 'bind', tag], seq) _bindinfo([@path, 'bind', tagid(tag)], seq)
end end
def button_activate(tag) def button_activate(tag)
@ -328,7 +328,7 @@ class Tk::BLT::Treeview
else else
cmd = Proc.new cmd = Proc.new
end end
_bind([@path, 'button', 'bind', tag], seq, cmd, *args) _bind([@path, 'button', 'bind', tagid(tag)], seq, cmd, *args)
self self
end end
def button_bind_append(tag, seq, *args) def button_bind_append(tag, seq, *args)
@ -337,15 +337,15 @@ class Tk::BLT::Treeview
else else
cmd = Proc.new cmd = Proc.new
end end
_bind_append([@path, 'button', 'bind', tag], seq, cmd, *args) _bind_append([@path, 'button', 'bind', tagid(tag)], seq, cmd, *args)
self self
end end
def button_bind_remove(tag, seq) def button_bind_remove(tag, seq)
_bind_remove([@path, 'button', 'bind', tag], seq) _bind_remove([@path, 'button', 'bind', tagid(tag)], seq)
self self
end end
def button_bindinfo(tag, seq=nil) def button_bindinfo(tag, seq=nil)
_bindinfo([@path, 'button', 'bind', tag], seq) _bindinfo([@path, 'button', 'bind', tagid(tag)], seq)
end end
def close(*tags) def close(*tags)
@ -482,7 +482,7 @@ class Tk::BLT::Treeview
def find(first, last, keys={}) def find(first, last, keys={})
keys = _search_flags(keys) keys = _search_flags(keys)
keys['exec'] = _find_exec_flag_value(keys['exec']) if keys.key?('exec') keys['exec'] = _find_exec_flag_value(keys['exec']) if keys.key?('exec')
args = hash_kv(keys) << '--' << first << last args = hash_kv(keys) << '--' << tagid(first) << tagid(last)
simplelist(tk_send('find', *args)).collect{|id| tagid2obj(id)} simplelist(tk_send('find', *args)).collect{|id| tagid2obj(id)}
end end
@ -505,7 +505,7 @@ class Tk::BLT::Treeview
end end
keys = _search_flags(keys) keys = _search_flags(keys)
args = hash_kv(keys) << '--' args = hash_kv(keys) << '--'
args.concat(tags) args.concat(tags.collect{|t| tagid(t)})
tk_send('hide', *args) tk_send('hide', *args)
self self
end end
@ -530,7 +530,7 @@ class Tk::BLT::Treeview
end end
keys = _symbolkey2str(keys) keys = _symbolkey2str(keys)
keys['at'] = tag keys['at'] = tagid(tag)
Tk::BLT::Treeview::Node.new(pos, parent, keys) Tk::BLT::Treeview::Node.new(pos, parent, keys)
end end
@ -634,7 +634,7 @@ class Tk::BLT::Treeview
end end
keys = _search_flags(keys) keys = _search_flags(keys)
args = hash_kv(keys) << '--' args = hash_kv(keys) << '--'
args.concat(tags) args.concat(tags.collect{|t| tagid(t)})
tk_send('show', *args) tk_send('show', *args)
self self
end end
@ -991,7 +991,7 @@ class Tk::BLT::Treeview::Node < TkObject
if (id = keys['node']) if (id = keys['node'])
@path = @id = id @path = @id = id
tk_call(@tpath, 'move', @id, pos, parent) if parent tk_call(@tpath, 'move', @id, pos, tagid(parent)) if parent
else else
name = TreeNode_ID.join(TkCore::INTERP._ip_id_).freeze name = TreeNode_ID.join(TkCore::INTERP._ip_id_).freeze
TreeNode_ID[1].succ! TreeNode_ID[1].succ!
@ -1004,7 +1004,7 @@ class Tk::BLT::Treeview::Node < TkObject
path = [get_full(parent.id)[0], name] path = [get_full(parent.id)[0], name]
at = nil # ignore 'at' option at = nil # ignore 'at' option
else else
path = [parent, name] path = [parent.to_s, name]
end end
else else
path = name path = name
@ -1080,20 +1080,32 @@ class Tk::BLT::Treeview::Tag < TkObject
TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath] TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
TreeTagID_TBL[@tpath][@id] = self TreeTagID_TBL[@tpath][@id] = self
tk_call(@tpath, 'tag', 'add', @id, *ids) unless ids.empty? unless ids.empty?
tk_call(@tpath, 'tag', 'add', @id, *(ids.collect{|id| tagid(id)}))
end
end end
def tagid(tag)
if tag.kind_of?(Tk::BLT::Treeview::Node) \
|| tag.kind_of?(Tk::BLT::Treeview::Tag)
tag.id
else
tag
end
end
private :tagid
def id def id
@id @id
end end
def add(*ids) def add(*ids)
tk_call(@tpath, 'tag', 'add', @id, *ids) tk_call(@tpath, 'tag', 'add', @id, *(ids{|id| tagid(id)}))
self self
end end
def remove(*ids) def remove(*ids)
tk_call(@tpath, 'tag', 'delete', @id, *ids) tk_call(@tpath, 'tag', 'delete', @id, *(ids{|id| tagid(id)}))
self self
end end

View File

@ -70,9 +70,13 @@ class BLT_Graph_Demo
(1..39).each{|i| @graph.element_create("V#{i}", :x=>@x, :y=>@v[i])} (1..39).each{|i| @graph.element_create("V#{i}", :x=>@x, :y=>@v[i])}
@top = Tk::BLT::Tile::Toplevel.new @top = Tk::BLT::Tile::Toplevel.new
=begin
legend = Tk::BLT::Graph.new(@top, :widgetname=>'legend', legend = Tk::BLT::Graph.new(@top, :widgetname=>'legend',
:without_creating=>true) :without_creating=>true)
@graph.legend_configure(:position=>legend) @graph.legend_configure(:position=>legend)
=end
# legend = @graph.legend_window_create(@top, :widgetname=>'legend')
legend = @graph.legend_window_create(@top)
legend.pack(:fill=>:both, :expand=>true) legend.pack(:fill=>:both, :expand=>true)
Tk::BLT::Table.add(@root, @graph, [0,0], :fill=>:both) Tk::BLT::Table.add(@root, @graph, [0,0], :fill=>:both)