blob: e7cc9e9a8b82d04711246f6a5ef0b46699446d5a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#!/usr/bin/tclsh
# See COPYING file for copyright and license details.
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 {
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 { [.top.id get] == "" } { return }
set cmd "[.bin get [.bin curselection]] [.top.id get]"
.dl configure -state disabled -text "downloading"
.st configure -text ""
set out [open "|$cmd 2>@1" "r"]
fileevent $out readable [list updateStatus $out]
}
frame .top
label .top.lab
entry .top.id -width 14
listbox .bin -listvariable bin -exportselection 0 -height [llength $bin]
bind .bin <<ListboxSelect>> {showopts}
.bin selection set 0
button .dl -text "download" -command go
label .st
showopts
pack .top .bin .dl .st
pack .top.lab -side left
pack .top.id
bind . <Return> go
|