From d018b3d5034035caadb2f9ed1084bc44bda17620 Mon Sep 17 00:00:00 2001 From: Nick White Date: Sat, 18 Aug 2012 17:40:43 +0100 Subject: Add a progress bar to the gui --- TODO | 2 -- getabook.c | 1 + getbnbook.c | 1 + getgbook.c | 1 + getxbookgui.tcl | 17 +++++++++++++++-- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index 27d5d4e..2afcbd8 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ getxbookgui, check whether the input box starts http and if so check against url patterns -print number of pages (which may be) available in 1st line of output from tools, and use that to generate a progress bar (even if not perfect, still good). - submit 'pad' file to websites http://padsites.asp-software.org/ diff --git a/getabook.c b/getabook.c index 3b88289..db4ca96 100644 --- a/getabook.c +++ b/getabook.c @@ -211,6 +211,7 @@ int main(int argc, char *argv[]) if(pages[i]->url[0] == '\0') getpageurls(pages[i]->num); getpage(pages[i]); + printf("%.0f%% done\n", (float)i / (float)numpages * 100); } } else if(argv[1][0] == '-' && argv[1][1] == 'n') { while(fgets(buf, BUFSIZ, stdin)) { diff --git a/getbnbook.c b/getbnbook.c index a10d98e..6fa247f 100644 --- a/getbnbook.c +++ b/getbnbook.c @@ -136,6 +136,7 @@ int main(int argc, char *argv[]) continue; } getpage(pages[i]); + printf("%.0f%% done\n", (float)i / (float)numpages * 100); } } else if(argv[1][0] == '-' && argv[1][1] == 'n') { while(fgets(buf, BUFSIZ, stdin)) { diff --git a/getgbook.c b/getgbook.c index b869b7f..6f2342a 100644 --- a/getgbook.c +++ b/getgbook.c @@ -214,6 +214,7 @@ int main(int argc, char *argv[]) } searchpage(pages[i]); getpage(pages[i]); + printf("%.0f%% done\n", (float)i / (float)numpages * 100); } } else if(argv[1][0] == '-') { while(fgets(buf, BUFSIZ, stdin)) { diff --git a/getxbookgui.tcl b/getxbookgui.tcl index 06cf3c7..f7135df 100755 --- a/getxbookgui.tcl +++ b/getxbookgui.tcl @@ -19,12 +19,20 @@ proc updateStatus {chan} { global dling if {![eof $chan]} { set a [gets $chan] - if { $a != "" } { .st configure -text $a } + if { $a != "" } { + if { [string match "*%*" "$a"] } { + if { [regexp {^([0-9]*)} $a m num] } { + .prog coords bar 0 0 [expr $num * 2] 20 + } + } else { .st configure -text $a } + } } else { if { ! [catch {close $chan}] } { .st configure -text "[.input.id get] Done" + .prog coords bar 0 0 200 20 } .dl configure -state normal -text "Download" + .input.id configure -state normal set dling 0 } } @@ -35,7 +43,9 @@ proc go {} { set cmd "[lindex [lindex $cmds $cmdselected] 0] [.input.id get]" set dling 1 .dl configure -state disabled -text "Downloading" + .input.id configure -state readonly .st configure -text "" + .prog coords bar 0 0 0 20 set out [open "|$cmd 2>@1" "r"] fileevent $out readable [list updateStatus $out] } @@ -102,10 +112,13 @@ foreach b $cmds { button .dl -text "Download" -command go label .st +canvas .prog -width 200 -height 20 -relief sunken -bd 1 +.prog create rectangle 0 0 0 20 -tags bar -fill black + pack .input.lab -side left pack .input.id -pack .cmdfr .input .dl .st +pack .cmdfr .input .dl .prog .st bind . go bind .input.id {set manual 1} -- cgit v1.2.3