toolbar
TCL/TK UseCase1
Abstract :  Sets up the floating tool bar window.
Comments : New tools can be added to the tool bar without much effect 
           at all. All you'll need to do is update the tools list 
           variable with the tool type, button color, bitmap name, 
           and description. (Bitmaps are stored in the /bitmaps folder 
           of the code directory and you 'll have to create one there
           ....note: optional edge bitmaps are already there but aren't 
           in use at this time.) Everything is then placed into the 
           window and event bindings are automagically created and 
           changed when the tool is selected and deselected. 
           The program is runable....but the tool won't function. To 
           add functionality to the new tool, make action procedures in 
           the bindings.tcl file. Pay close attention to procedure names
           and how they are are callled. Action event procedures are called
           by testing to see if a procedure exists with a name relating 
           to the event that took place (like mouse click) and which tool
           was selected at the time (mouse click with vertex tool.)  If 
           the procedure doesn't exist nothing happens.  This is pretty 
           slick and will allow you to add functionally to your new tool
           easily and quickly.
set INCLUDE "$env(BIT_DIR)"
set style flat
#
# Array for all tools on the tool bar
#  Fields are {    }
set tools { \
	{ Select black select.xbm } \
	{ Constr blue constr.xbm } \
	{ Alter blue alter.xbm } \
	{ Req_Constr_Edge blue edgereq.xbm } \
	{ Req_Alter_Edge blue edgealtreq.xbm } \
	{ Rename red rename.xbm } \
	{ Delete red trash.xbm } \
}
#	{ Opt_Constr_Edge blue edgeopt.xbm } \
#	{ Opt_Alter_Edge blue edgealtopt.xbm } \
#
# Set initial value here
set tool_type Select
#
# createButton
#  Procedure to create a tool button
#  Parameters: createButton   
proc createButton {name color file} {
    global style
    global INCLUDE
    global tool_type
    radiobutton .toolwin.toolframe.b_$name \
	    -relief $style \
	    -variable tool_type \
	    -value $name \
	    -foreground $color \
	    -bitmap "@$INCLUDE/$file" \
	    -command "set tool_type $name"
}
#
# bindButton
#  Procedure to set up appropriate bindings for the radio buttons
#  Parameters: bindButton 
proc bindButton {name} {
    bind .toolwin.toolframe.b_$name  \
	    "shoutit $name"
    bind .toolwin.toolframe.b_$name  \
	    "set tool_type $name"
}
#
# setup_tools
#  Procedure to set up the tool bar
proc init_tools {} {
    global tool_type
    global tools
    global style
    # Make toplevel
    toplevel .toolwin
    wm transient .toolwin .
    frame .toolwin.toolframe 
    # Make the buttons
    foreach i $tools {
	createButton [lindex $i 0] [lindex $i 1] [lindex $i 2]
    }
    # Setup the binding
    foreach i $tools {
	bindButton [lindex $i 0]
    }
    #Testing stuff
    #button .toolwin.toolframe.test1 -text "Tool?" -command shoutit
    #button .toolwin.toolframe.test2 -text "Quit!" -command exit
    text .toolwin.toolframe.text -height 3 -width 15 -background white
    # Pack the buttons
    pack .toolwin.toolframe
    foreach i $tools {
	set name [lindex $i 0]
	pack .toolwin.toolframe.b_$name -fill x
    }
    pack .toolwin.toolframe.text -fill x
}
proc flashy { speed } {
global tool_type
global tools
foreach i $tools {
    set tool_type [lindex $i 0]
    after $speed
    update
}
for {set i [expr [llength $tools] - 2 ]} \
	{$i >= 0} {incr i -1} {
    set j [lindex $tools $i]
    set tool_type [lindex $j 0]
    after $speed
    update
}
}
proc shoutit {passing} {
.toolwin.toolframe.text delete 1.0 end
.toolwin.toolframe.text insert end "This is the\n$passing\ntOOl."
}
proc setup_tools {} {
init_tools
update
flashy 50
bind .toolwin  {
    shoutit $tool_type
}
}
 
 
 
 
 
 
 
 
