Mod /
Xtree
Search:  


Table Of Contents (show)

  1. 1. Trees with *xtree

1.  Trees with *xtree

The *xtree utility command simplifies creating hierarchical data in a Tcl tree?. The new sub-command takes 2 arguments: the variable name and the data in XTL form which is used to populate the tree.

An XTL is a name/value pair list, with the name containing tag, flag and attributes. If the flag (the second value) is a plus "+" it indicates a subtree, and a minus "-" or no value indicates a terminal. Terminals with a non-empty value is stored in the "=" attribute.

Here is an example:

namespace eval ::myapp {

    Mod export

    *xtree new mtr { 
        {system + Name SYS} {
            {sol  - OS Linux Version 3.4 } {}
            {bing - OS Win Version 7 } {}
            {gui  + OS Mac Version 8 } {
               A 1 B 2
            }
        }
        {network + Name NET Level 1} {
            {intra - Address 192.168.1  Netmask 255.255.255.0 } {}
            {dmz   - Address 192.168.10 Netmask 255.255.255.0 } {}
            {wan   - Address 0.0.0.0 Netmask 0.0.0.0 Class {A 1 B 4}} {}
        }
        # "This is a comment"
        {admins +} {
            {sully    - Name "Sully Van Damme" Level 3 } {}
            {maverick - Name "Maverick Gump" Level 1 } {}
        }
    }

    proc Main {args} {
        variable mtr

        puts "SYS: [$mtr get 0->system->sol]"
        $mtr incr 0->system->bing Version
        puts "BING: [$mtr get 0->system->bing Version]"

        pack [treeview .t -tree $mtr -width 600] -fill both -expand y
        eval .t col insert end [lsort [$mtr keys all]]

        .t open all
    }

    eval Main $argv
}

This displays:

Note: unlike *tree, *xtree provides no duplicate checking or tags.

© 2008 Peter MacDonald

Page last modified on January 04, 2010, at 01:27 PM