1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
|
#
# tkextlib/blt/tree.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
module Tk::BLT
class Tree < TkObject
TkCommandNames = ['::blt::tree'.freeze].freeze
###################################
class Node < TkObject
TreeNodeID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
TreeNodeID_TBL.mutex.synchronize{ TreeNodeID_TBL.clear }
}
def self.id2obj(tree, id)
tpath = tree.path
TreeNodeID_TBL.mutex.synchronize{
if TreeNodeID_TBL[tpath]
if TreeNodeID_TBL[tpath][id]
TreeNodeID_TBL[tpath][id]
else
begin
# self.new(tree, nil, 'node'=>Integer(id))
id = Integer(id)
if bool(tk_call(@tpath, 'exists', id))
(obj = self.allocate).instance_eval{
@parent = @tree = tree
@tpath = tpath
@path = @id = id
TreeNodeID_TBL[@tpath] = {} unless TreeNodeID_TBL[@tpath]
TreeNodeID_TBL[@tpath][@id] = self
}
obj
else
id
end
rescue
id
end
end
else
id
end
}
end
def self.new(tree, parent, keys={})
keys = _symbolkey2str(keys)
tpath = tree.path
TreeNodeID_TBL.mutex.synchronize{
TreeNodeID_TBL[tpath] ||= {}
if (id = keys['node']) && (obj = TreeNodeID_TBL[tpath][id])
keys.delete('node')
tk_call(tree.path, 'move', id, parent, keys) if parent
return obj
end
(obj = self.allocate).instance_eval{
initialize(tree, parent, keys)
TreeNodeID_TBL[tpath][@id] = self
}
obj
}
end
def initialize(tree, parent, keys={})
@parent = @tree = tree
@tpath = @parent.path
if (id = keys['node']) && bool(tk_call(@tpath, 'exists', id))
@path = @id = id
keys.delete('node')
tk_call(@tpath, 'move', @id, parent, keys) if parent
else
parent = tk_call(@tpath, 'root') unless parent
@path = @id = tk_call(@tpath, 'insert', parent, keys)
end
end
def id
@id
end
def apply(keys={})
@tree.apply(@id, keys)
self
end
def children()
@tree.children(@id)
end
def copy(parent, keys={})
@tree.copy(@id, parent, keys)
end
def copy_to(dest_tree, parent, keys={})
@tree.copy_to(@id, dest_tree, parent, keys)
end
def degree()
@tree.degree(@id)
end
def delete()
@tree.delete(@id)
self
end
def depth()
@tree.depth(@id)
end
def dump()
@tree.dump(@id)
end
def dump_to_file(file)
@tree.dump_to_file(@id, file)
self
end
def exist?(keys={})
@tree.exist?(@id, keys)
end
def find(keys={})
@tree.find(@id, keys)
end
def find_child(label)
@tree.find_child(@id, label)
end
def first_child()
@tree.first_child(@id)
end
def get()
@tree.get(@id)
end
def get_value(key, default_val=None)
@tree.get_value(@id, key, default_val)
end
def index()
@tree.index(@id)
end
def leaf?()
@tree.leaf?(@id)
end
def link?()
@tree.link?(@id)
end
def root?()
@tree.root?(@id)
end
def keys()
@tree.keys(@id)
end
def label(text = nil)
@tree.label(@id, nil)
end
def label=(text)
@tree.label(@id, text)
end
def last_child()
@tree.last_child(@id)
end
def move(dest, keys={})
@tree.keys(@id, dest, keys)
self
end
def next()
@tree.next(@id)
end
def next_sibling()
@tree.next_sibling(@id)
end
def parent()
@tree.parent(@id)
end
def fullpath()
@tree.fullpath(@id)
end
def position()
@tree.position(@id)
end
def previous()
@tree.previous(@id)
end
def prev_sibling()
@tree.prev_sibling(@id)
end
def restore(str, keys={})
@tree.restore(@id, str, keys)
self
end
def restore_overwrite(str, keys={})
@tree.restore_overwrite(@id, str, keys)
self
end
def restore_from_file(file, keys={})
@tree.restore_from_file(@id, file, keys)
self
end
def restore_overwrite_from_file(file, keys={})
@tree.restore_overwrite_from_file(@id, file, keys)
self
end
def root()
@tree.root(@id)
self
end
def set(data)
@tree.set(@id, data)
self
end
def size()
@tree.size(@id)
end
def sort(keys={})
@tree.sort(@id, keys)
self
end
def type(key)
@tree.type(@id, key)
end
def unset(*keys)
@tree.unset(@id, *keys)
self
end
def values(key=None)
@tree.values(@id, key)
end
end
###################################
class Tag < TkObject
TreeTagID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
TreeTagID_TBL.mutex.synchronize{ TreeTagID_TBL.clear }
}
(TreeTag_ID = ['blt_tree_tag'.freeze, TkUtil.untrust('00000')]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
def self.id2obj(tree, id)
tpath = tree.path
TreeTagID_TBL.mutex.synchronize{
if TreeTagID_TBL[tpath]
if TreeTagID_TBL[tpath][id]
TreeTagID_TBL[tpath][id]
else
begin
# self.new(tree, id)
(obj = self.allocate).instance_eval{
@parent = @tree = tree
@tpath = @parent.path
@path = @id = id.dup.freeze if id
TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
TreeTagID_TBL[@tpath][@id] = self
}
obj
rescue
id
end
end
else
id
end
}
end
def initialize(tree, tag_str = nil)
@parent = @tree = tree
@tpath = @parent.path
if tag_str
@path = @id = tag_str.dup.freeze
else
TreeTag_ID.mutex.synchronize{
@path = @id = TreeTag_ID.join(TkCore::INTERP._ip_id_)
TreeTag_ID[1].succ!
}
end
TreeTagID_TBL.mutex.synchronize{
TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
TreeTagID_TBL[@tpath][@id] = self
}
end
def id
@id
end
def add(*nodes)
tk_call(@tpath, 'tag', 'add', @id, *nodes)
self
end
def delete(*nodes)
tk_call(@tpath, 'tag', 'delete', @id, *nodes)
self
end
def forget()
tk_call(@tpath, 'tag', 'forget', @id)
TreeTagID_TBL.mutex.synchronize{
TreeTagID_TBL[@tpath].delete(@id)
}
self
end
def nodes()
simplelist(tk_call(@tpath, 'tag', 'nodes', @id)).collect{|node|
Tk::BLT::Tree::Node.id2obj(@path, node)
}
end
def set(node)
tk_call(@tpath, 'tag', 'set', node, @id)
self
end
def unset(node)
tk_call(@tpath, 'tag', 'unset', node, @id)
self
end
end
###################################
class Notify < TkObject
NotifyID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
NotifyID_TBL.mutex.synchronize{ NotifyID_TBL.clear }
}
def self.id2obj(tree, id)
tpath = tree.path
NotifyID_TBL.mutex.synchronize{
if NotifyID_TBL[tpath]
if NotifyID_TBL[tpath][id]
NotifyID_TBL[tpath][id]
else
(obj = self.allocate).instance_eval{
@parent = @tree = tree
@tpath = @parent.path
@path = @id = id
NotifyID_TBL[@tpath] ||= {}
NotifyID_TBL[@tpath][@id] = self
}
obj
end
else
return id
end
}
end
def self.new(tree, *args, &b)
NotifyID_TBL.mutex.synchronize{
if tree.kind_of?(Array)
# not create
tpath = tree[0].path
NotifyID_TBL[tpath] ||= {}
unless (obj = NotifyID_TBL[tpath][tree[1]])
(NotifyID_TBL[tpath][tree[1]] =
obj = self.allocate).instance_eval{
@parent = @tree = tree[0]
@tpath = @parent.path
@path = @id = tree[1]
}
end
return obj
end
(obj = self.allocate).instance_eval{
initialize(tree, *args, &b)
NotifyID_TBL[@tpath] ||= {}
NotifyID_TBL[@tpath][@id] = self
}
return obj
}
end
def initialize(tree, *args, &b)
@parent = @tree = tree
@tpath = @parent.path
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
if TkComm._callback_entry?(args[0])
cmd = args.shift
# elsif args[-1].kind_of?(Proc) || args[-1].kind_of?(Method)
elsif TkComm._callback_entry?(args[-1])
cmd = args.pop
elsif b
cmd = Proc.new(&b)
else
fail ArgumentError, "lack of 'command' argument"
end
args = args.collect{|arg| '-' << arg.to_s}
args << proc{|id, type|
cmd.call(Tk::BLT::Tree::Node.id2obj(@tree, id),
((type[0] == ?-)? type[1..-1]: type))
}
@path = @id = tk_call(@tpath, 'notify', 'create', *args)
end
def id
@id
end
def delete()
tk_call(@tpath, 'notify', 'delete', @id)
NotifyID_TBL.mutex.synchronize{
NotifyID_TBL[@tpath].delete(@id)
}
self
end
def info()
lst = simplelist(tk_call(@tpath, 'notify', 'info', id))
lst[0] = Tk::BLT::Tree::Notify.id2obj(@tree, lst[0])
lst[1] = simplelist(lst[1]).collect{|flag| flag[1..-1]}
lst[2] = tk_tcl2ruby(lst[2])
lst
end
end
###################################
class Trace < TkObject
TraceID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
TraceID_TBL.mutex.synchronize{ TraceID_TBL.clear }
}
def self.id2obj(tree, id)
tpath = tree.path
TraceID_TBL.mutex.synchronize{
if TraceID_TBL[tpath]
if TraceID_TBL[tpath][id]
TraceID_TBL[tpath][id]
else
begin
# self.new([tree, id])
(obj = self.allocate).instance_eval{
@parent = @tree = tree
@tpath = @parent.path
@path = @id = node # == traceID
TraceID_TBL[@tpath] ||= {}
TraceID_TBL[@tpath][@id] = self
}
obj
rescue
id
end
end
else
id
end
}
end
def self.new(tree, *args, &b)
TraceID_TBL.mutex.synchronize{
if tree.kind_of?(Array)
# not create
tpath = tree[0].path
TraceID_TBL[tpath] ||= {}
unless (obj = TraceID_TBL[tpath][tree[1]])
(TraceID_TBL[tpath][tree[1]] =
obj = self.allocate).instance_eval{
@parent = @tree = tree
@tpath = @parent.path
@path = @id = tree[1] # == traceID
}
end
return obj
end
# super(true, tree, *args, &b)
(obj = self.allocate).instance_eval{
initialize(tree, *args, &b)
TraceID_TBL[@tpath] ||= {}
TraceID_TBL[@tpath][@id] = self
}
return obj
}
end
def initialize(tree, node, key, opts, cmd=nil, &b)
@parent = @tree = tree
@tpath = @parent.path
if !cmd
if b
cmd = Proc.new(&b)
else
fail ArgumentError, "lack of 'command' argument"
end
end
@path = @id = tk_call(@tpath, 'trace', 'create', node, key, opts,
proc{|t, id, k, ops|
tobj = Tk::BLT::Tree.id2obj(t)
if tobj.kind_of?(Tk::BLT::Tree)
nobj = Tk::BLT::Tree::Node.id2obj(tobj, id)
else
nobj = id
end
cmd.call(tobj, nobj, k, ops)
})
end
def id
@id
end
def delete()
tk_call(@tpath, 'trace', 'delete', @id)
TraceID_TBL.mutex.synchronize{
TraceID_TBL[tpath].delete(@id)
}
self
end
def info()
lst = simplelist(tk_call(@tpath, 'trace', 'info', id))
lst[0] = Tk::BLT::Tree::Trace.id2obj(@tree, lst[0])
lst[2] = simplelist(lst[2])
lst[3] = tk_tcl2ruby(lst[3])
lst
end
end
###################################
TreeID_TBL = TkCore::INTERP.create_table
(Tree_ID = ['blt_tree'.freeze, TkUtil.untrust('00000')]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
def __keyonly_optkeys
{
# apply / find command
'invert'=>nil, 'leafonly'=>nil, 'nocase'=>nil,
# apply / find / sort command
'path'=>nil,
# copy / restore / restorefile command
'overwrite'=>nil,
# copy command
'recurse'=>nil, 'tags'=>nil,
# sort command
'ascii'=>nil, 'decreasing'=>nil, 'disctionary'=>nil,
'integer'=>nil, 'real'=>nil, 'recurse'=>nil, 'reorder'=>nil,
}
end
def self.id2obj(id)
TreeID_TBL.mutex.synchronize{
TreeID_TBL[id]? TreeID_TBL[id]: id
}
end
def self.names(pat = None)
simplelist(tk_call('::blt::tree', 'names', pat)).collect{|name|
id2obj(name)
}
end
def self.destroy(*names)
tk_call('::blt::tree', 'destroy',
*(names.collect{|n| (n.kind_of?(Tk::BLT::Tree))? n.id: n }) )
end
def self.new(name = nil)
TreeID_TBL.mutex.synchronize{
if name && TreeID_TBL[name]
TreeID_TBL[name]
else
(obj = self.allocate).instance_eval{
initialize(name)
TreeID_TBL[@id] = self
}
obj
end
}
end
def initialzie(name = nil)
if name
@path = @id = name
else
Tree_ID.mutex.synchronize{
@path = @id = Tree_ID.join(TkCore::INTERP._ip_id_)
Tree_ID[1].succ!
}
end
tk_call('::blt::tree', 'create', @id)
end
def __destroy_hook__
Tk::BLT::Tree::Node::TreeNodeID_TBL.mutex.synchronize{
Tk::BLT::Tree::Node::TreeNodeID_TBL.delete(@path)
}
Tk::BLT::Tree::Tag::TreeTagID_TBL.mutex.synchronize{
Tk::BLT::Tree::Tag::TreeTagID_TBL.delete(@path)
}
Tk::BLT::Tree::Notify::NotifyID_TBL.mutex.synchronize{
Tk::BLT::Tree::Notify::NotifyID_TBL.delete(@path)
}
Tk::BLT::Tree::Trace::TraceID_TBL.mutex.synchronize{
Tk::BLT::Tree::Trace::TraceID_TBL.delete(@path)
}
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 parameters
end
end
def destroy()
tk_call('::blt::tree', 'destroy', @id)
self
end
def ancestor(node1, node2)
Tk::BLT::Tree::Node.id2obj(self, tk_call('::blt::tree', 'ancestor',
tagid(node1), tagid(node2)))
end
def apply(node, keys={})
tk_call('::blt::tree', 'apply', tagid(node), __conv_keyonly_opts(keys))
self
end
def attach(tree_obj)
tk_call('::blt::tree', 'attach', tree_obj)
self
end
def children(node)
simplelist(tk_call('::blt::tree', 'children', tagid(node))).collect{|n|
Tk::BLT::Tree::Node.id2obj(self, n)
}
end
def copy(src, parent, keys={})
id = tk_call('::blt::tree', 'copy', tagid(src), tagid(parent),
__conv_keyonly_opts(keys))
Tk::BLT::Tree::Node.new(self, nil, 'node'=>id)
end
def copy_to(src, dest_tree, parent, keys={})
return copy(src, parent, keys={}) unless dest_tree
id = tk_call('::blt::tree', 'copy', tagid(src), dest_tree,
tagid(parent), __conv_keyonly_opts(keys))
Tk::BLT::Tree::Node.new(dest_tree, nil, 'node'=>id)
end
def degree(node)
number(tk_call('::blt::tree', 'degree', tagid(node)))
end
def delete(*nodes)
tk_call('::blt::tree', 'delete', *(nodes.collect{|node| tagid(node)}))
Tk::BLT::Tree::Node::TreeNodeID_TBL.mutex.synchronize{
nodes.each{|node|
if node.kind_of?(Tk::BLT::Tree::Node)
Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.id)
else
Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.to_s)
end
}
}
self
end
def depth(node)
number(tk_call('::blt::tree', 'depth', tagid(node)))
end
def dump(node)
simplelist(tk_call('::blt::tree', 'dump', tagid(node))).collect{|n|
simplelist(n)
}
end
def dump_to_file(node, file)
tk_call('::blt::tree', 'dumpfile', tagid(node), file)
self
end
def exist?(node, key=None)
bool(tk_call('::blt::tree', 'exists', tagid(node), key))
end
def find(node, keys={})
simplelist(tk_call('::blt::tree', 'find', tagid(node),
__conv_keyonly_opts(keys))).collect{|n|
Tk::BLT::Tree::Node.id2obj(self, n)
}
end
def find_child(node, label)
ret = tk_call('::blt::tree', 'findchild', tagid(node), label)
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def first_child(node)
ret = tk_call('::blt::tree', 'firstchild', tagid(node))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def get(node)
Hash[*simplelist(tk_call('::blt::tree', 'get', tagid(node)))]
end
def get_value(node, key, default_val=None)
tk_call('::blt::tree', 'get', tagid(node), key, default_val)
end
def index(node)
Tk::BLT::Tree::Node.id2obj(self,
tk_call('::blt::tree', 'index', tagid(node)))
end
def insert(parent, keys={})
id = tk_call('::blt::tree', 'insert', tagid(parent), keys)
Tk::BLT::Tree::Node.new(self, nil, 'node'=>id)
end
def ancestor?(node1, node2)
bool(tk_call('::blt::tree', 'is', 'ancestor',
tagid(node1), tagid(node2)))
end
def before?(node1, node2)
bool(tk_call('::blt::tree', 'is', 'before',
tagid(node1), tagid(node2)))
end
def leaf?(node)
bool(tk_call('::blt::tree', 'is', 'leaf', tagid(node)))
end
def link?(node)
bool(tk_call('::blt::tree', 'is', 'link', tagid(node)))
end
def root?(node)
bool(tk_call('::blt::tree', 'is', 'root', tagid(node)))
end
def keys(node, *nodes)
if nodes.empty?
simplelist(tk_call('blt::tree', 'keys', tagid(node)))
else
simplelist(tk_call('blt::tree', 'keys', tagid(node),
*(nodes.collect{|n| tagid(n)}))).collect{|lst|
simplelist(lst)
}
end
end
def label(node, text=nil)
if text
tk_call('::blt::tree', 'label', tagid(node), text)
text
else
tk_call('::blt::tree', 'label', tagid(node))
end
end
def last_child(node)
ret = tk_call('::blt::tree', 'lastchild', tagid(node))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def link(parent, node, keys={})
ret = tk_call('::blt::tree', 'link', tagid(parent), tagid(node),
__conv_keyonly_opts(keys))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def move(node, dest, keys={})
tk_call('::blt::tree', 'move', tagid(node), tagid(dest), keys)
self
end
def next(node)
ret = tk_call('::blt::tree', 'next', tagid(node))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def next_sibling(node)
ret = tk_call('::blt::tree', 'nextsibling', tagid(node))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def notify_create(*args, &b)
Tk::BLT::Tree::Notify.new(self, *args, &b)
end
def notify_delete(id)
if id.kind_of?(Tk::BLT::Tree::Notify)
id.delete
else
tk_call(@path, 'notify', 'delete', id)
Tk::BLT::Tree::Notify::NotifyID_TBL.mutex.synchronize{
Tk::BLT::Tree::Notify::NotifyID_TBL[@path].delete(id.to_s)
}
end
self
end
def notify_info(id)
lst = simplelist(tk_call(@path, 'notify', 'info', tagid(id)))
lst[0] = Tk::BLT::Tree::Notify.id2obj(self, lst[0])
lst[1] = simplelist(lst[1]).collect{|flag| flag[1..-1]}
lst[2] = tk_tcl2ruby(lst[2])
lst
end
def notify_names()
tk_call(@path, 'notify', 'names').collect{|id|
Tk::BLT::Tree::Notify.id2obj(self, id)
}
end
def parent(node)
ret = tk_call('::blt::tree', 'parent', tagid(node))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def fullpath(node)
tk_call('::blt::tree', 'path', tagid(node))
end
def position(node)
number(tk_call('::blt::tree', 'position', tagid(node)))
end
def previous(node)
ret = tk_call('::blt::tree', 'previous', tagid(node))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def prev_sibling(node)
ret = tk_call('::blt::tree', 'prevsibling', tagid(node))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def restore(node, str, keys={})
tk_call('::blt::tree', 'restore', tagid(node), str,
__conv_keyonly_opts(keys))
self
end
def restore_overwrite(node, str, keys={})
keys = __conv_keyonly_opts(keys)
keys.delete('overwrite')
keys.delete(:overwrite)
tk_call('::blt::tree', 'restore', tagid(node), str, '-overwrite', keys)
self
end
def restore_from_file(node, file, keys={})
tk_call('::blt::tree', 'restorefile', tagid(node), file,
__conv_keyonly_opts(keys))
self
end
def restore_overwrite_from_file(node, file, keys={})
keys = __conv_keyonly_opts(keys)
keys.delete('overwrite')
keys.delete(:overwrite)
tk_call('::blt::tree', 'restorefile', tagid(node), file,
'-overwrite', keys)
self
end
def root(node=None)
Tk::BLT::Tree::Node.id2obj(self, tk_call('::blt::tree', 'root',
tagid(node)))
end
def set(node, data)
unless data.kind_of?(Hash)
fail ArgumentError, 'Hash is expected for data'
end
args = []
data.each{|k, v| args << k << v}
tk_call('::blt::tree', 'set', tagid(node), *args)
self
end
def size(node)
number(tk_call('::blt::tree', 'size', tagid(node)))
end
def sort(node, keys={})
tk_call('::blt::tree', 'sort', tagid(node), __conv_keyonly_opts(keys))
self
end
def tag_add(tag, *nodes)
tk_call(@path, 'tag', 'add', tagid(tag), *(nodes.collect{|n| tagid(n)}))
self
end
def tag_delete(tag, *nodes)
tk_call(@path, 'tag', 'delete', tagid(tag),
*(nodes.collect{|n| tagid(n)}))
self
end
def tag_forget(tag)
tag = tag.id if tag.kind_of?(Tk::BLT::Tree::Tag)
tk_call(@path, 'tag', 'forget', tag)
TreeTagID_TBL.mutex.synchronize{
TreeTagID_TBL[@path].delete(tag)
}
self
end
def tag_get(node, *patterns)
simplelist(tk_call(@tpath, 'tag', 'get', tagid(node),
*(patterns.collect{|pat| tagid(pat)}))).collect{|str|
Tk::BLT::Tree::Tag.id2obj(self, str)
}
end
def tag_names(node = None)
simplelist(tk_call(@tpath, 'tag', 'names', tagid(node))).collect{|str|
Tk::BLT::Tree::Tag.id2obj(self, str)
}
end
def tag_nodes(tag)
simplelist(tk_call(@tpath, 'tag', 'nodes', tagid(tag))).collect{|node|
Tk::BLT::Tree::Node.id2obj(self, node)
}
end
def tag_set(node, *tags)
tk_call(@path, 'tag', 'set', tagid(node), *(tags.collect{|t| tagid(t)}))
self
end
def tag_unset(node, *tags)
tk_call(@path, 'tag', 'unset', tagid(node),
*(tags.collect{|t| tagid(t)}))
self
end
def trace_create(*args, &b)
Tk::BLT::Tree::Trace.new(self, *args, &b)
end
=begin
def trace_delete(*args)
args.each{|id|
if id.kind_of?(Tk::BLT::Tree::Trace)
id.delete
else
tk_call(@path, 'trace', 'delete', id)
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)
Tk::BLT::Tree::Trace::TraceID_TBL.mutex.synchronize{
args.each{|id| Tk::BLT::Tree::Trace::TraceID_TBL[@path].delete(id.to_s)}
}
self
end
def trace_info(id)
lst = simplelist(tk_call(@path, 'trace', 'info', tagid(id)))
lst[0] = Tk::BLT::Tree::Trace.id2obj(self, lst[0])
lst[2] = simplelist(lst[2])
lst[3] = tk_tcl2ruby(lst[3])
lst
end
def trace_names()
tk_call(@path, 'trace', 'names').collect{|id|
Tk::BLT::Tree::Trace.id2obj(self, id)
}
end
def type(node, key)
tk_call('::blt::tree', 'type', tagid(node), key)
end
def unset(node, *keys)
tk_call('::blt::tree', 'unset', tagid(node), *keys)
self
end
def values(node, key=None)
simplelist(tk_call('::blt::tree', 'values', tagid(node), key))
end
end
end
|