Tcl同步秒表和计数器不起作用

问题描述 投票:0回答:1

我确实有一个TK / TCL秒表,从一个xterm开始一个unix计数器,但是它不显示计数器图片中的计数。 Unix计数器完成后(有4次迭代),然后秒表中的显示会显示并计数。单击运行按钮后如何继续显示计数?

stopwatch with its buttons control

这里是代码(在第3行中替换您的相应“愿望”:]]

#!/bin/sh
####################################################################### \
exec /sw/freetools/tk/8.5.6/Linux/rh5/x86_64/bin/wish8.5 "$0" ${1+"$@"}
package require Tk

wm title . "TEST-GUI"
. configure -padx 50 -pady 50 -relief raised -borderwidth 2

###STOPWATCH -begin-
set COLOR_BACKGROUND "black"
set COLOR_FOREGROUND "sky blue"
font create FONT0 -family {VL PGothic} -size -20 -weight normal
set ::time 00:00:00

proc every {ms body} {
 eval $body
 after $ms [namespace code [info level 0]]
}
proc Start {} {
 if {$::time eq {00:00:00}} {
  set ::time0 [clock clicks -milliseconds]
 }
 every 10 {
  set m [expr {[clock clicks -milliseconds] - $::time0}]
  set ::time [format %2.2d:%2.2d:%2.2d [expr {$m/60000}] [expr {($m/1000)%60}] [expr {$m%1000/10}]]
 }
 .frame1.run config -state disabled
}
proc Stop {} {
 if {[llength [after info]]} {
  after cancel [after info]
 } else {set ::time 00:00:00}
 .frame1.run config -state normal
}
###STOPWATCH -end-


frame .frame1 -highlightbackground black \
              -highlightthickness 1 \
              -width 200 -height 200

label .frame1.time -textvar ::time -font FONT0 -background $COLOR_BACKGROUND -foreground $COLOR_FOREGROUND

button .frame1.run -text "RUN" -foreground black -bg coral \
                               -borderwidth 3 -height 0 -width 3 -font {-family symbol -size 8} -pady 2 \
                               -command {
                             Start
                         gui_run
                                        }

button .frame1.exit -text "EXIT" -foreground black \
                     -borderwidth 3 -height 0 -width 3 -font {-family symbol -size 8} -pady 2 \
                                 -command {exit}

pack .frame1
pack .frame1.run -side top
pack .frame1.exit -side bottom
pack .frame1.time

proc xterm_counter {} {
 set fileid [open "./xterm_counter.txt" w]
 puts $fileid "#!/bin/csh -f"
 puts $fileid ""
 puts $fileid "set i = 0"
 puts $fileid "echo \"testing programm counting -start- \`date +%X\`\""
 puts $fileid "while (\$i <= 3)"
 puts $fileid " sleep 2"
 puts $fileid " set i = \`expr \$i + 1\`"
 puts $fileid " echo \"testing programm counting here => \$i\""
 puts $fileid "end"
 puts $fileid "echo \"testing programm counting -end-   \`date +%X\`\""
 close $fileid
}

proc gui_run {} {
 xterm_counter
 exec chmod 744 "./xterm_counter.txt"
 if {[catch {exec ./xterm_counter.txt >@ stdout}]} {
  puts "RUN FAILED, exit programm"
  exit
 } else {
  puts "RUN SUCCESSFULL, stop stopwatch now"
 }
}

我确实有一个TK / TCL秒表,从一个xterm开始一个unix计数器,但是它没有在计数器图像中显示计数。 Unix计数器完成(它有4次迭代)后,显示在...

tcl stopwatch simultaneous
1个回答
0
投票

问题是exec命令暂停Tcl进程,直到另一个进程完成运行。对于像chmod的快速运行而言,这不是一个大问题,但是对于长时间运行的计时器显示,这是一个主要的难题。

© www.soinside.com 2019 - 2024. All rights reserved.