From: Arjan on 9 Feb 2010 04:54 This is so basic, but I can't find it on the Wiki/in the manuals. Sorry! I added a progress-bar to my gui. The length of the dark part is controlled by a variable named "myprogress", which runs from 0 (just started) to 100 (run completed). The external program is started by pressing a "start"-button on the gui. It generates a run-log file to which, among others, lines are written like this: --> Step 75 time 2007 4 18 14 28 in run until 2007 4 18 18 0 I found a nice tcl-routine named "tailminf", which reads the last line added to my run-log and checks it for meeting a certain grep characterisic, e.g. contains the sub-string "--> Step". That line is stored into a variable named "line". When I let that routine print $line to screen, it looks okay. Question: how do I extract the number given after "--> Step" in the line (assuming that 100 steps = 100 %, which completes my external program) and put it into variable "myprogress", in order to let my progress-bar work? Arjan
From: Arjen Markus on 9 Feb 2010 05:39 On 9 feb, 10:54, Arjan <arjan.van.d...(a)rivm.nl> wrote: > This is so basic, but I can't find it on the Wiki/in the manuals. > Sorry! > > I added a progress-bar to my gui. The length of the dark part is > controlled by a variable named "myprogress", which runs from 0 (just > started) to 100 (run completed). > > The external program is started by pressing a "start"-button on the > gui. It generates a run-log file to which, among others, lines are > written like this: > > --> Step 75 time 2007 4 18 14 28 in run until > 2007 4 18 18 0 > > I found a nice tcl-routine named "tailminf", which reads the last line > added to my run-log and checks it for meeting a certain grep > characterisic, e.g. contains the sub-string "--> Step". That line is > stored into a variable named "line". When I let that routine print > $line to screen, it looks okay. > > Question: how do I extract the number given after "--> Step" in the > line (assuming that 100 steps = 100 %, which completes my external > program) and put it into variable "myprogress", in order to let my > progress-bar work? > > Arjan If you can be sure there are no special characters - mostly {, } and ", then you can treat the line as a list: set progress_percentage [lindex $line 2] (The text string is automatically transformed into a list, using whitespace as the separator.) Otherwise the [scan] command is your friend: scan $line "%s%s%s" dummy dummy percentage Regards, Arj-e-n
From: Arjan on 9 Feb 2010 07:57 > set progress_percentage [lindex $line 2] > > (The text string is automatically transformed into a list, using > whitespace as the separator.) This works! Thanks! A.
|
Pages: 1 Prev: Problem in mixing namespace separator and widget path Next: text widget : get -displaychars |