Chronometer Thread last updated on 2004-04-19 02:26:25

Posted by member 106308 on 2004-04-14 17:31:41

Have been searching The LS Info for a module that can display
time 00:00:00 and whenever you click it starts counting you click again stops, click again resets and so on.
It will be usefull to time any task or even a (call you back in ....) type of usaje.
Is there a way to have something like this happened.
The closest I got was to try to reset uptime on a label but couldnt doit.
Maybe one of our Brains come with an solution.
Thankyou.

(Proud to be part of LiteStep)

Posted by member 1316 on 2004-04-14 17:47:53 link

dunno, try timer.dll 0.5

Posted by member 1 on 2004-04-14 20:40:58 link

For something like this you would want to use Timer, mzScript and Label. With the three of these it would be possible to get this done...but boy would it not be fun.

Posted by member 106308 on 2004-04-14 22:43:58 link

Thanks DeVilbOi Im gonna start studying mzscript, Is the one module I havent gotten to play with yet.
Thanks.
Any other Ideas please post.

Posted by member 1 on 2004-04-14 23:05:10 link

you will only need it to store your variable information that you are incrementing with a timer.

Posted by member 37809 on 2004-04-15 11:16:56 link

And it shouldn't be difficult to format the timestamp for something more readable.

In addition to incrementing your elapsed time on each timer expiration you could use div and mod operations (through some form of runtime evar arithmetic) on your elapsed time and then set label text accordingly.

Of course you first have to understand what the heck I mean. There are few formal terms in the context of scripting since scripts involve many modules :S

Posted by member 99 on 2004-04-15 18:22:38 link

If you want to be really accurate, use mzscript's time variables and subtract rather than counting seconds. Timers don't happen at exact intervals, although offhand I don't know if the error would accumulate or not. But counting seconds should be simple enough that you can just try it and run it for a long time to see. (if you hit high CPU load, you *will* miss timeouts though)

Posted by member 37809 on 2004-04-15 19:35:33 link

Another way would be to use [uptime('d:h:m:s')] in an xlabel, !labelmzscriptvarcopy that over to mzscript, convert to seconds and subtract those (and reformat for display in another label), at least within your last boot :)

Posted by member 106308 on 2004-04-17 16:44:01 link

Thanks guys, The truth is that the explanations are for now beyond my understanding.
Im trying to master scripts but for now no cigar.
Anyway if someone has the time and thinks a function like the one I describe is usefull not only for me.
Then post a script that could do the job.(Is not that I havent tryied myself).
Thanks a lot.

Posted by member 99 on 2004-04-17 22:28:18 link

Get two times from label as 's:m:h:d' (note that this is backwards from what tnl said, I hope that's possible), then use !TimeInterval %{start} %{end}:
*script bang !TimeInterval
*script exec !setlistsep :
*script exec !varset start ":%{\1}"
*script exec !varset end ":%{\2}"
*script exec !varset max ":60:60:24:"
*script exec !varset result ""
*script exec !varset part ""
*script label noborrow
*script exec !varset borrow "0"
*script label borrow
*script exec !varset result "%{result}:%{part}"
*script exec !varset end "%{end:_}"
*script exec !varset start "%{start:_}"
*script exec !varset max "%{max:_}"
*script exec !varset part "%#%{end:}-%{start:}-%{borrow}%#"
*script gotoif ("%{max}" = "") done
*script gotoif ("%{part}" >= "0") noborrow
*script exec !varadd part "%{max:}"
*script exec !varset borrow "1"
*script goto borrow
*script label done
*script exec !varset result "%{result:_}:%{part}"
*script exec !varset result "%{result:_}"
*script ~bang

Then %{result} is almost what you want. There's gotta be some way to make it build the result the other way around, or failing that it's not too hard to flip it later. But maybe each piece needs to be formatted anyway, so it wouldn't matter what order they're in... I dunno. I've already timed out my ls.net login, so I'm done for now. :P

Posted by member 37809 on 2004-04-17 23:52:22 link

"Fancy novelty chronograph".

Note:
I couldn't help but try to do 1/100 seconds. They're for novelty and appear incorrect (Toggle it quickly to see what I mean?) Either using litestep to do this doesn't produce the required precision/accuracy and/or my logic is off :D Those parts of the script are commented.

Tested under:
xlabellight-2.8.3
timer-0.5
mzscript-0.9-beta_12

.rc settings:
; used to update our label
*Timer chronometer #l 1s !mchronometer_update
;*Timer chronometer #l 20 !mchronometer_update ; 20ms is overkill

; the label used to display the elapsed duration from the last reset
*Label chronometer
chronometerStartHidden false
chronometerUpdateInterval 999999
chronometerText "CHRONOGRAPH"
chronometerWidth 100
chronometerHeight 22
chronometerImage bar.png
chronometerAlign right
chronometerFont "Tahoma"
chronometerFontHeight 13
chronometerFontSmoothing true
chronometerRightBorder 5
chronometerFontColor 000000
chronometerOnLeftClick !mchronometer_toggle
chronometerOnLeftDoubleClick !mchronometer_toggle
chronometerOnMiddleClick !LabelClipboardCopy chronometer
chronometerOnMiddleDoubleClick !LabelClipboardCopy chronometer
chronometerOnRightClick !mchronometer_reset
chronometerOnRightDoubleClick !mchronometer_reset

; needed only to extract uptime information
*Label chronometerbackend
chronometerbackendStartHidden
chronometerbackendUpdateInterval 999999
chronometerbackendText "[uptime('d:h:n:s')]"
chronometerbackendWidth 1
chronometerbackendHeight 1


in a *mzVarFile:
; boolean: whether or not the chronometer is running
mchronometer_going 0

; number: the start time as your system uptime in number of seconds
mchronometer_starttime 0

; number: the number of seconds elapsed from the start time
mchronometer_duration 0


in a *mzScriptFile:
; needed because i don't have luck with !varmod
; c = a mod b
*script bang !mymod ;c a b
*script exec !varset mymodt %#%{\2}/%{\3}%#
*script exec !varset %{\1} %#%{\2}-%{mymodt}*%{\3}%#
*script exec !varremove mymodt
*script ~bang

; reset our duration to 0
*script bang !mchronometer_reset
*script exec !ifeval ("%{mchronometer_going}" = "1") '|TimerKill chronometer'
*script exec !mchronometer_set mchronometer_starttime
*script exec !varset mchronometer_duration 0
*script exec !LabelSetText chronometer "0’00”"
;*script exec !LabelSetText chronometer "0’00”00"
*script exec !ifeval ("%{mchronometer_going}" = "1") '|TimerStart chronometer'
*script ~bang

; update the text in our label with the current elapsed duration
*script bang !mchronometer_update
*script exec !mchronometer_set mchronometer_duration
*script exec !varadd mchronometer_duration "-%{mchronometer_starttime}"
*script exec !varset d %#%{mchronometer_duration}/86400%#
*script exec !mymod h %#%{mchronometer_duration}/3600%# 24
*script exec !mymod m %#%{mchronometer_duration}/60%# 60
*script exec !mymod s %{mchronometer_duration} 60
*script exec !ifeval ("10" > "%{s}") '|varset s "0%{s}"'
;*script exec !varset n %#%{milli}/10%#
;*script exec !ifeval ("10" > "%{n}") '|varset n "0%{n}"'
*script gotoif ("%{d}" > "0") d
*script gotoif ("%{h}" > "0") h
*script exec !LabelSetText chronometer "%{m}’%{s}”"
;*script exec !LabelSetText chronometer "%{m}’%{s}”%{n}"
*script exit
*script label d
*script exec !LabelSetText chronometer "%{d}d %{h}h %{m}’%{s}”"
;*script exec !LabelSetText chronometer "%{d}d %{h}h %{m}’%{s}”%{n}"
*script exit
*script label h
*script exec !LabelSetText chronometer "%{h}h %{m}’%{s}”"
;*script exec !LabelSetText chronometer "%{h}h %{m}’%{s}”%{n}"
*script ~bang

; set varname to current system uptime in number of seconds
*script bang !mchronometer_set ;varname
*script exec !LabelUpdate chronometerbackend
*script exec !LabelmzscriptVarCopy chronometerbackend s
*script exec !varset d %{s:}
*script exec !varset s %{s:_}
*script exec !varset h %{s:}
*script exec !varset s %{s:_}
*script exec !varset m %{s:}
*script exec !varset %{\1} %#%{d}*86400+%{h}*3600+%{m}*60+%{s:_}%#
*script ~bang

; start or stop our chronometer
*script bang !mchronometer_toggle
*script gotoif ("%{mchronometer_going}" = "1") stop
*script exec !mchronometer_set mchronometer_starttime
*script exec !varadd mchronometer_starttime "-%{mchronometer_duration}"
*script exec !TimerStart chronometer
*script exec !varset mchronometer_going 1
*script exec !LabelSetFontColor chronometer 000000
*script goto rest
*script label stop
*script exec !TimerKill chronometer
*script exec !varset mchronometer_going 0
*script exec !LabelSetFontColor chronometer 7f7f7f
*script label rest
*script exec !mchronometer_update
*script ~bang

; restore the state of our chronometer at startup/recycle of litestep
*script bang !mchronometer_restore
*script gotoif ("%{mchronometer_going}" = "0") stopped
*script exec !mchronometer_set mchronometer_starttime
*script exec !varadd mchronometer_starttime "-%{mchronometer_duration}"
*script exec !TimerStart chronometer
*script goto rest
*script label stopped
*script exec !LabelSetFontColor chronometer 7f7f7f
*script label rest
*script exec !mchronometer_update
*script ~bang

*script start !mchronometer_restore


[P.S. should this be in the Code forum or not?]

Posted by member 106308 on 2004-04-18 14:35:47 link

Working on it now

Posted by member 106308 on 2004-04-18 16:17:44 link

Ok,Big Thanks "It works"
got to say you guys up there,
now small problems I guess are that Im getting a "?" beetween the hour-minute and minute-second dysplay instead of a ":".(any idea why)
another would be that after recycle i get a stopped uptime (but I imagen that is supose to be invisible using the correct background (please confirm) being that the case problem would be that if you left click it will start counting from that elapsed uptime (meaningless number)
well after the firt time you reset to 0 seems to work pretty good being that the left click stops and another left click resumes.(looks good to me)
now the right-click cero's and starts counting on the same click (that could not be to cool maybe its possible to reset on the first right click and start on the second).
The word Chronograph on the display only apears for a second after recycle
Well got to say that is the first time that I got to use any script and even xlabel. so far my themes were 70% label 1.99
so I had to make a test-theme to try the function (made me learn on a hurry so I apologize If the remaining questions have obvious solutions.
I tnl code on 98SE System (latest litestep)

Posted by member 106308 on 2004-04-19 02:26:25 link

Ok,tnl works perfect,
just changed the !LabelSetText chronometer "%{h}h %{m}?%{s}?" for !LabelSetText chronometer "%{h}hrs %{m}min %{s}sec" and to control it i'm ussing ClockWorkOnLeftDown !Execute [!labelCreate chronometer] [!LabelAlwaysOnTop chronometer][!mchronometer_reset]
ClockWorkOnLeftUp !mchronometer_toggle
ClockWorkOnRightDown !labelDestroy chronometer
I made really smallclockwork that only shows the seconds hand to control the timer(looks pretty cool)
works just the way I wanted.
Thanks a lot.