From 4e6e2adeff8b4869de7c4c4fa0a5a3ab241d3a29 Mon Sep 17 00:00:00 2001 From: Nick White Date: Fri, 17 Feb 2012 18:29:14 +0000 Subject: Many gui improvements Feedback on successful download Appropriate list box sizing Better widget placement Show usage of each command Add program dir to path (so can be run from extracted tarball) Be resiliant to errors --- getxbookgui.tcl | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/getxbookgui.tcl b/getxbookgui.tcl index 9183f36..e7cc9e9 100755 --- a/getxbookgui.tcl +++ b/getxbookgui.tcl @@ -3,33 +3,48 @@ package require Tk set bin [list getgbook getabook getbnbook] +set binopts [list "book id" "isbn 10" "isbn 13"] + +set env(PATH) "[file dirname $::argv0]:$env(PATH)" proc updateStatus {chan} { if {![eof $chan]} { set a [gets $chan] if { $a != "" } { .st configure -text $a } } else { - close $chan + if { ! [catch {close $chan}] } { + .st configure -text "[.top.id get] done" + } .dl configure -state normal -text "download" .st configure -text "" } } +proc showopts {} { + global binopts + .top.lab configure -text [lindex $binopts [.bin curselection]] +} + proc go {} { - if { [.id get] == "" } { return } - set cmd "[.bin get [.bin curselection]] [.id get]" + if { [.top.id get] == "" } { return } + set cmd "[.bin get [.bin curselection]] [.top.id get]" .dl configure -state disabled -text "downloading" - update + .st configure -text "" set out [open "|$cmd 2>@1" "r"] fileevent $out readable [list updateStatus $out] } -label .lab -text "book id" -entry .id -listbox .bin -listvariable bin -exportselection 0 +frame .top +label .top.lab +entry .top.id -width 14 +listbox .bin -listvariable bin -exportselection 0 -height [llength $bin] +bind .bin <> {showopts} .bin selection set 0 button .dl -text "download" -command go -label .st -relief sunken -width 20 +label .st +showopts -pack .lab .id .bin .dl .st +pack .top .bin .dl .st +pack .top.lab -side left +pack .top.id bind . go -- cgit v1.2.3