#!../t_wish
# -*- Tcl -*-
#
# This is simple TableList demo. This time we display the contents
# of the local /etc/passwd file, just to get some data...
#
# Usage: mywish -f pwdemo ?-numrows number? ?-numcols number?
#    (where mywish has the Itcl, BLT and TclX extensions)
#
# Copyright (c) 1994 Allan Brighton (allan@piano.sta.sub.org)


lappend auto_path ../library

#set_default_resources
#option readfile Xdefaults

itcl_class PwDemo {
    inherit TopLevelWidget
    
    
    # constructor: create a toplevel window for the demo

    constructor {config} {
	TopLevelWidget::constructor
	
	wm title $this "TableList /etc/passwd Demo"
	wm minsize $this 10 10 

	# get the data
	get_pw

	# create the TableList
	TableList $this.tlist \
	    -title "Contents of Passwd File" \
	    -headings $headings \
	    -info $info \
	    -selectmode extended
	pack $this.tlist -fill both -expand 1

	# add a row of buttons at botton
	pack [ButtonFrame $this.b -ok_cmd exit] -side bottom -fill x

	# note that the TableList widget sets gridded geometry on
	wm geometry $this 60x20

    }


    # read /etc/passwd (or for NIS, use ypcat) to get some data to display

    method get_pw {} {
	if {$use_yp} {
	    set fd [open "|ypcat passwd"]
	} else {
	    set fd [open /etc/passwd]
	}
	while {[gets $fd buf] != -1} {
	    lappend info [split $buf :]
	}	
    }		


    # -- public variables (also program options) -- 

    # if true, use ypcat, otherwise use /etc/passwd
    public use_yp 0

    
    # -- protected variables --
    
    # table headings
    protected headings {User Password UID GID Name Home Shell} 

    # data: list of table rows, where each row is a list strings
    protected info {}
}


# Start the demo:
# Note that "start" is a "member" proc in the TopLevelWidget class.
# It creates an instance of the above class and handles options and
# error checking.

PwDemo :: start

