#! /usr/bin/wish
#
# I dare you to make a simpler GUI!
#
# Usage: tkmythremote frontendhost

if { [ llength $argv ] != 1 } { 
    puts "Usage: $argv0 host\n" 
    exit 
}

# Configure pixmap location 
set pix "./pixmaps"

set host [lindex $argv 0]
wm title . $host

set f [socket $host 6546]
fconfigure $f -blocking 0 -buffering none

proc push {key} {
    global f
    puts $f "key $key\n"
    read $f
}

# Create all the buttons
button .esc     -image [image create bitmap -file "$pix/esc.xbm"] \
                -command "push escape"
button .play    -image [image create bitmap -file "$pix/p.xbm"] \
                -command "push p"
button .ent     -image [image create bitmap -file "$pix/ent.xbm"] \
                -command "push enter"
button .up      -image [image create bitmap -file "$pix/up.xbm"] \
                -command "push up"
button .down    -image [image create bitmap -file "$pix/down.xbm"] \
                -command "push down"
button .left    -image [image create bitmap -file "$pix/left.xbm"] \
                -command "push left"
button .right   -image [image create bitmap -file "$pix/right.xbm"] \
                -command "push right"
button .backcom -image [image create bitmap -file "$pix/dleft.xbm"] \
                -command "push q"
button .forwcom -image [image create bitmap -file "$pix/dright.xbm"] \
                -command "push z"
button .pgup    -image [image create bitmap -file "$pix/dup.xbm"] \
                -command "push pageup"
button .pgdown  -image [image create bitmap -file "$pix/ddown.xbm"] \
                -command "push pagedown"
button .quit    -image [image create bitmap -file "$pix/q.xbm"] \
                -command "exit"
button .delete  -image [image create bitmap -file "$pix/d.xbm"] \
                -command "push d"
button .menu    -image [image create bitmap -file "$pix/m.xbm"] \
                -command "push m"
button .info    -image [image create bitmap -file "$pix/i.xbm"] \
                -command "push i"
label .host -text "MythTV frontend:\n$host" 

# Arrange the buttons in  grid
# esc   ent  up   i   quit
# pgup  left p right  menu
# pgd   bc  down fc    del
grid .esc     -in . -row 1 -column 1
grid .ent     -in . -row 1 -column 2
grid .up      -in . -row 1 -column 3
grid .info    -in . -row 1 -column 4
grid .quit    -in . -row 1 -column 5
grid .pgup    -in . -row 2 -column 1
grid .left    -in . -row 2 -column 2
grid .play    -in . -row 2 -column 3
grid .right   -in . -row 2 -column 4
grid .pgdown  -in . -row 3 -column 1
grid .backcom -in . -row 3 -column 2
grid .down    -in . -row 3 -column 3
grid .forwcom -in . -row 3 -column 4
grid .delete  -in . -row 2 -column 5
grid .menu    -in . -row 3 -column 5
grid .host    -in . -row 4 -columnspan 5
