summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.me.uk>2012-02-14 01:00:18 +0000
committerNick White <git@njw.me.uk>2012-02-14 01:00:18 +0000
commitaf580806a4ac5b481bd53a85832fd76cf9742dc4 (patch)
treefc6b822ed242abce991ede9ace23dbf61fe688e9
parent6a09f09349fdc0fe68615f2f933a5e13ea70e183 (diff)
Make gui update smartly
-rw-r--r--TODO2
-rwxr-xr-xgetxbookgui.tcl19
2 files changed, 12 insertions, 9 deletions
diff --git a/TODO b/TODO
index 4fa13a4..e420875 100644
--- a/TODO
+++ b/TODO
@@ -8,8 +8,6 @@ in getgbook, check that downloaded page doesn't match 'page not available' image
package for osx - https://github.com/kennethreitz/osx-gcc-installer
-use something smarter than update in gui to stop freezing
-
add https support to get (getabook can use it everywhere, others cannot)
write some little tests
diff --git a/getxbookgui.tcl b/getxbookgui.tcl
index dabab2b..9183f36 100755
--- a/getxbookgui.tcl
+++ b/getxbookgui.tcl
@@ -4,19 +4,24 @@ package require Tk
set bin [list getgbook getabook getbnbook]
+proc updateStatus {chan} {
+ if {![eof $chan]} {
+ set a [gets $chan]
+ if { $a != "" } { .st configure -text $a }
+ } else {
+ close $chan
+ .dl configure -state normal -text "download"
+ .st configure -text ""
+ }
+}
+
proc go {} {
if { [.id get] == "" } { return }
set cmd "[.bin get [.bin curselection]] [.id get]"
.dl configure -state disabled -text "downloading"
update
set out [open "|$cmd 2>@1" "r"]
- while {![eof $out]} {
- set a [gets $out]
- if { $a != "" } { .st configure -text $a }
- update
- }
- .dl configure -state normal -text "download"
- .st configure -text ""
+ fileevent $out readable [list updateStatus $out]
}
label .lab -text "book id"