From: yahalom on 19 Mar 2010 02:19 I have a small tk app that part of its job is to copy big files (100Mb +) from usb connected recorders. Of course I want to show file copy progress as the file transfer from the recorders is slow. I use ttk::progressbar in a toplevel window but it is not updated when file copy is being done so my app looks stuck.. Is there a way to do this with events or should I go for threads?
From: Roger O on 19 Mar 2010 04:07 I do a standard "fcopy" in my app. It copies a bit (selectable amount), and then calls a function to do whatever. Usually one just copies a bit more. This continues until the file copy is done. In the callback you set up, in addition to the continuation of the copy, you can determine the progress in the file and update a progress variable. This is yet another fine standard Tcl feature.
From: Emiliano on 19 Mar 2010 10:44 On 19 mar, 03:19, yahalom <yahal...(a)gmail.com> wrote: > I have a small tk app that part of its job is to copy big files (100Mb > +) from usb connected recorders. Of course I want to show file copy > progress as the file transfer from the recorders is slow. I use > ttk::progressbar in a toplevel window but it is not updated when file > copy is being done so my app looks stuck.. Is there a way to do this > with events or should I go for threads? Example adapted from the fcopy(n) man page: ========================================================= package require Tk 8.5 proc CopyMore {in out chunk w bytes {error {}}} { set current [expr { int([$w cget -value])}] $w configure -value [incr current $bytes] if {([string length $error] != 0) || [chan eof $in]} { chan close $in chan close $out exit } else { after idle [list after 0 [list \ chan copy $in $out \ -size $chunk \ -command [list CopyMore $in $out $chunk $w] ]] } } set source /some/big/sourcefile set dest /some/big/destfile set in [open $source] set out [open $dest w] chan configure $in -translation binary -encoding binary chan configure $out -translation binary -encoding binary set chunk [expr {16 * 1024}] ; # 16 kb ttk::progressbar .pb -maximum [file size $source] pack .pb -expand 1 -fill both chan copy $in $out \ -size $chunk \ -command [list CopyMore $in $out $chunk .pb] ========================================================= Hope this helps. Emiliano
|
Pages: 1 Prev: Running tcl when have a malloc issue Next: fcopy -size limit |