TclTk sample gui program
Here's an embarassingly simple tcl/tk program to demonstrate the simplest of gui applications.
The program will display a window/frame containing 3 buttons, placed side by side, expanded to fit the available space in the frame. Each button is mapped to perform a task, such as "ssh localhost", or "ssh remotehost".
You can edit and add more buttons and tasks.
You'll need packages tcl and tk in order to run this. (apt-get install -y tcl tk)
Posted this for Ben. See it's really not that hard to build a GUI application! ;-)
Here's the code:
#!/usr/bin/wish
# vi:set nu ai ap smd showmatch tabstop=4 shiftwidth=4:
# Name: cygterms
# Author: Tom Sandholm
# Version: 1.0
# Date: Fri Jan 5 09:47:47 EST 2007
# Summary: simple gui application to open ssh sessions to
# remote systems.
# pickup the DISPLAY variable
# NOTE: this is only declared if cygwin startxwin has been run
# (X is running).
global D
set D $env(DISPLAY)
global BUTTON_NUMBER
set BUTTON_NUMBER 1
# function to create a button
proc NewButton {Label UserName HostName} {
global BUTTON_NUMBER
global D
# chop out the username & hostname from the button label
#
set tmp [split "$Label" "\n"]
set user [lindex $tmp 0]
set rhost [lindex $tmp 1]
button .b${BUTTON_NUMBER} \
-text "$Label" \
-command "exec xterm -title \"${user}_${rhost}\" \
-n \"${user}_${rhost}\" -display $D -sb -fn 7x14 \
-e ssh -Y ${UserName}@${HostName} &"
pack .b${BUTTON_NUMBER} -expand true -fill both -side left
incr BUTTON_NUMBER
}
proc RemoteTop {Label UserName HostName} {
global BUTTON_NUMBER
global D
set tmp [split "$Label" "\n"]
set user [lindex $tmp 0]
set rhost [lindex $tmp 1]
button .c${BUTTON_NUMBER} \
-text "$Label" \
-command "exec xterm -title \"${user}_${rhost}\" \
-n \"${user}_${rhost}\" -display $D -sb -fn 7x14 \
-e top &"
pack .c${BUTTON_NUMBER} -expand true -fill both -side left
incr BUTTON_NUMBER
}
# local windows (xterms)
# these lines create some local buttons; different colors...
button .d -text "local\nblack" -command "exec xterm -title \"local_black\" -n \"local_black\" -display $D -sb -fn 7x14 &"
pack .d -expand true -fill both -side left
# remote xterms
# NOTE: First argument is the button label.
# Label is to be formatted as "username\nhostname",
# with a "\n" separating the username from hostname".
# 2nd arg is the username to perform the ssh as.
# 3rd arg is the remote hostname.
# syntax: NewButton "label" "username" "hostname"
NewButton "linux-tee\nxterm" "sandholm" "linux-tee"
RemoteTop "linux-tee\ntop" "sandholm" "linux-tee"