It is currently April 19th, 2024, 9:30 am

Simple countdown timer

Get help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Simple countdown timer

Post by jsmorley »

Yincognito wrote: July 31st, 2021, 11:16 pm Let me know of that code as well. I have my own, it works perfectly, but since it's about PowerShell, is also slower (compared to CMD related alternatives), so if by any chance that code is fast AND effective, I'm interested in finding out more about the approach.
It was here:

https://forum.rainmeter.net/viewtopic.php?f=5&t=4194&start=10#p194633

The real reason why I suggested Powershell in the end was that he wanted to be able to close multiple programs with one command, and you can't stack up cmd.exe commands outside of a batch file. In any case, executing a simple command like taskkill.exe isn't going to take more than a few milliseconds either way, cmd.exe or Powershell.
User avatar
Yincognito
Rainmeter Sage
Posts: 7125
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Simple countdown timer

Post by Yincognito »

jsmorley wrote: August 1st, 2021, 2:39 am It was here:

https://forum.rainmeter.net/viewtopic.php?f=5&t=4194&start=10#p194633

The real reason why I suggested Powershell in the end was that he wanted to be able to close multiple programs with one command, and you can't stack up cmd.exe commands outside of a batch file. In any case, executing a simple command like taskkill.exe isn't going to take more than a few milliseconds either way, cmd.exe or Powershell.
Well, for the record, if it's only about taskkill, one can kill multiple processes at once using either multiple /PID parameters (slightly more difficult to apply because of this little particularity which I didn't get an answer to yet, though it's possible I have some mistakes in the initial code there) or by filtering using the /FI parameter (which unfortunately is quite limited for such cases). Obviously, using taskkill with the help of PowerShell's clean multi-command features is much more clearer and not limited in any way like the CMD-based alternatives, so it was a good choice.

That being said, while my self-elevated PS solution works very well, your approach here looks better as it skips one extra step I currently do (since I use PS to also kill the process). If taskkill is able to kill compattelrunner.exe and the like, that is, because the last time I tried it wasn't (can't remember if I ran it as an administrator then though).

The problem I have with PS in my current approach is mainly speed. When a process is using 80-90% of the CPU, running PS to kill it will take a while. I encountered a couple of Windows crashes/restarts due to "critical process stopped" either because of the speed factor or some mistake in my code that made PS kill the "wrong process", i.e. not the one I double clicked on. It could have been because I used a [&UsageMonitorMeasure] directly in the Parameter option for PS and somehow it got updated to a different process name before PS sluggishly managed to execute its Stop-Process cmdlet, so it's not a definitive conclusion that lack of speed caused this, but in the meantime I implemented a more static variable based approach that should make it clear if the issue was in my code for such "collateral damage". I even re-enabled compattelrunner back in the scheduled tasks to see if this code adjustment solves those wrong process killed instances, LOL.

Thanks for letting me know of the thread. I'll try a couple of those approaches as well so I can settle for a solution that is both effective and quick(er). :thumbup:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Simple countdown timer

Post by sl23 »

Latest code:

Code: Select all

[Rainmeter]
Update=50
BackgroundMode=2
SolidColor=0,0,0,1
DynamicWindowSize=1
;MouseOverAction=[!ShowMeterGroup Menu]
;MouseLeaveAction=[!HideMeterGroup Menu]
OnRefreshAction=[!ShowMeter Action1]
AccurateText=1

[Metadata]
Name=Countdown Timer
Author=zzeneg & balala, Yincognito, eclectic tech, death crafter, jsmorley
Information=Based on balala's CountdownTimer, but heavily edited with some added features.
Version=2021.8.1

========================================
; Background
========================================
[Bg]
Meter=Shape
Shape=Rectangle 1,1,220,65,5 | Fill Color 0,0,0,130 | StrokeWidth 2 | Extend StrokeAlpha
StrokeAlpha=Stroke Color 255,255,255,60
MouseOverAction=[!SetOption #CURRENTSECTION# StrokeAlpha "Stroke Color 0,255,255,255"][!UpdateMeter *][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# StrokeAlpha "Stroke Color 255,255,255,60"][!UpdateMeter *][!Redraw]
DynamicVariables=1
Padding=5,5,5,5

[Variables]
Alarm=Alarm.wav

DefaultTime=100
MaxVal=#DefaultTime#
;DefaultTime is the time (6000=10mins in one-tenth of seconds!) which appears when you refresh the skin. 

CloseApps=[!CommandMeasure mClose "Run"]
APP1=Dolphin.exe
APP2=pcsx2.exe
APP3=rpcs3.exe
APP4=retroarch.exe
APP5=

Hibernate=rundll32.exe powrprof.dll,SetSuspendState
Shutdown=shutdown.exe -s -t 5 -f
Lock=rundll32.exe user32.dll, LockWorkStation

Act=#CloseApps#

========================================
; STYLES
========================================
[sAllText]
FontFace=Aller
StringStyle=Bold
StringAlign=Center
FontSize=9
FontColor=255,255,255,200
StringEffect=Shadow
FontEffectColor=0,0,0,150
AntiAlias=1

[sHighlight]
MouseOverAction=[!SetOption #CURRENTSECTION# FontColor "128,255,0"] [!UpdateMeter #CURRENTSECTION#] [!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# FontColor ""] [!UpdateMeter #CURRENTSECTION#] [!Redraw]

[mClose]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell
Parameter=taskkill /IM #APP1#;taskkill /IM #APP2#;taskkill /IM #APP3#;taskkill /IM #APP4#;taskkill /IM #APP5#

[MeterOne]
Meter=String
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Test Close Apps
LeftMouseUpAction=#CloseApps#
Y=80
========================================
; MEASURES
========================================
[mTime]
Measure=Time

[mCounterTimer]
Measure=Calc
Formula=(( mCounterTimer = 0 ) ? ( mTime - mTimer / 10 ) : mCounterTimer )
Disabled=1

[mTimer]
Measure=Calc
Formula=(( mCounterTimer = 0 ) ? mTimer : ( mTime - mCounterTimer ) * 10 )

[mSp]
Measure=Calc
Formula=(( mSp + 1 ) % 2 )
Disabled=1
IfAboveValue=0
IfAboveAction=[!DisableMeasure mSp]

[mSm]
Measure=Calc
Formula=(( mSm + 1 ) % 2 )
Disabled=1
IfAboveValue=0
IfAboveAction=[!DisableMeasure mSm]

[mMp]
Measure=Calc
Formula=(( mMp + 1 ) % 2 )
Disabled=1
IfAboveValue=0
IfAboveAction=[!DisableMeasure mMp]

[mMm]
Measure=Calc
Formula=(( mMm + 1 ) % 2 )
Disabled=1
IfAboveValue=0
IfAboveAction=[!DisableMeasure mMm]

[mHp]
Measure=Calc
Formula=(( mHp + 1 ) % 2 )
Disabled=1
IfAboveValue=0
IfAboveAction=[!DisableMeasure mHp]

[mHm]
Measure=Calc
Formula=(( mHm + 1 ) % 2 )
Disabled=1
IfAboveValue=0
IfAboveAction=[!DisableMeasure mHm]

[mTimerSet]
Measure=Calc
Formula=((( mTimerSet + 10 * mSp - 10 * mSm + 600 * mMp - 600 * mMm + 36000 * mHp - 36000 * mHm + #DefaultTime# ) < 0 ) ? ( #DefaultTime# * ( -1 )) : ( mTimerSet + 10 * mSp - 10 * mSm + 600 * mMp - 600 * mMm + 36000 * mHp - 36000 * mHm ))
OnChangeAction=[!SetVariable MaxVal (#DefaultTime#-[mTimer:]+[mTimerSet:])]
DynamicVariables=1

[mTimer2]
Measure=Calc
Format=%S
Formula=( #DefaultTime# - mTimer + mTimerSet )
IfBelowValue=1
IfBelowAction=[!DisableMeasure mCounterTimer]
MinValue=0
MaxValue=#MaxVal#
DynamicVariables=1

[mTimer3Act]
Measure=Calc
Formula=(( mCounterTimer = 0 ) ? 1 : ( mTimer2 - 1 ))
IfBelowValue=0
IfBelowAction=[!DisableMeasure mCounterTimer][#Act#][!HideMeter Stop][!HideMeter Start][!ShowMeter Reset]
DynamicVariables=1

[mTimer4Alarm]
Measure=Calc
Formula=(( mCounterTimer = 0 ) ? 1 : ( mTimer2 - 1 ))
IfBelowValue=0
IfBelowAction=[PLAY #Alarm#][!HideMeter Stop][!HideMeter Start][!ShowMeter Reset]
DynamicVariables=1

[mTimerHours]
Measure=Calc
Formula=(( FLOOR ( mTimer2 / 36000 )) % 100 )
RegExpSubstitute=1
Substitute="^(.*)$":"0\1","^.*(.{2})$":"\1"

[mTimerMinutes]
Measure=Calc
Formula=(( FLOOR ( mTimer2 / 600 )) % 60 )
RegExpSubstitute=1
Substitute="^(.*)$":"0\1","^.*(.{2})$":"\1"

[mTimerSeconds]
Measure=Calc
Formula=(( FLOOR ( mTimer2 / 10 )) % 60 )
RegExpSubstitute=1
Substitute="^(.*)$":"0\1","^.*(.{2})$":"\1"

========================================
; Timers
========================================
[sTimerDisplay]
FontSize=16
Group=TimerDisplay

[TimerDisplayHr]
Meter=String
MeterStyle=sAllText | sTimerDisplay
MeasureName=mTimerHours
Text=%1:
MouseScrollUpAction=
MouseScrollDownAction=
X=45
Y=25

[TimerDisplayMin]
Meter=String
MeterStyle=sAllText | sTimerDisplay
MeasureName=mTimerMinutes
Text=%1
MouseScrollUpAction=
MouseScrollDownAction=
X=28r
Y=r

[TimerDisplaySec]
Meter=String
MeterStyle=sAllText | sTimerDisplay
MeasureName=mTimerSeconds
FontSize=10
Text=%1
InlineSetting=Size | 10
InlinePattern=.+( .+)
;MouseScrollUpAction=[!EnableMeasure mSp] [!Redraw]
;MouseScrollDownAction=[!EnableMeasure mSm] [!Redraw]
X=26r
Y=9r

========================================
; Buttons
========================================
[sButton]
Shape=Rectangle 0,0,10,10,50 | Extend FillAlpha | StrokeWidth 2 | Extend StrokeAlpha
FillAlpha=FillColor 200,100,100
StrokeAlpha=StrokeColor 128,255,0,0
MouseOverAction=[!SetOption #CURRENTSECTION# StrokeAlpha "StrokeColor 255,255,0,255"] [!UpdateMeter *][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# StrokeAlpha ""] [!UpdateMeter *] [!Redraw] 
DynamicVariables=1
Group=Button
Hidden=1
UpdateDivider=-1
X=20r
Y=0r

[Button1]
Meter=Shape
MeterStyle=sButton
LeftMouseUpAction=[!SetOptionGroup Button FillAlpha "FillColor 200,100,100"][!SetOption #CURRENTSECTION# FillAlpha "FillColor 128,255,0,255"][!SetVariable Act "#CloseApps#"] [!UpdateMeter *][!Redraw]
ToolTipText=Close Apps
X=15
Y=12

[Button2]
Meter=Shape
MeterStyle=sButton
LeftMouseUpAction=[!SetOptionGroup Button FillAlpha "FillColor 200,100,100"][!SetOption #CURRENTSECTION# FillAlpha "FillColor 128,255,0,255"][!SetVariable Act "#Hibernate#"][!EnableMeasure mTimer3Act][!DisableMeasure mTimer4Alarm] [!UpdateMeter *][!Redraw]
ToolTipText=Hibernate

[Button3]
Meter=Shape
MeterStyle=sButton
LeftMouseUpAction=[!SetOptionGroup Button FillAlpha "FillColor 200,100,100"][!SetOption #CURRENTSECTION# FillAlpha "FillColor 128,255,0,255"][!SetVariable Act "#Shutdown#"][!EnableMeasure mTimer3Act][!DisableMeasure mTimer4Alarm] [!UpdateMeter *][!Redraw]
ToolTipText=Shutdown

[Button4]
Meter=Shape
MeterStyle=sButton
LeftMouseUpAction=[!SetOptionGroup Button FillAlpha "FillColor 200,100,100"][!SetOption #CURRENTSECTION# FillAlpha "FillColor 128,255,0,255"][!SetVariable Act "#Lock#"][!EnableMeasure mTimer3Act][!DisableMeasure mTimer4Alarm] [!UpdateMeter *][!Redraw]
ToolTipText=Lock

[Button5]
Meter=Shape
MeterStyle=sButton
LeftMouseUpAction=[!SetOptionGroup Button FillAlpha "FillColor 200,100,100"][!SetOption #CURRENTSECTION# FillAlpha "FillColor 128,255,0,255"][!SetVariable Act ""][!EnableMeasure mTimer3Act][!DisableMeasure mTimer4Alarm] [!UpdateMeter *][!Redraw]
ToolTipText=Off

========================================
; Controls
========================================
[sControls]
Group=Controls
Y=50

[Start]
Meter=String
MeterStyle=sAllText | sHighlight | sControls
Text=Start
LeftMouseDownAction=[!EnableMeasure mCounterTimer][!HideMeter Start][!ShowMeter Stop][!HideMeter Reset][!HideMeter Set][!SetOptionGroup TimerDisplay FontColor "255,255,0"]
X=30

[Stop]
Meter=String
MeterStyle=sAllText | sHighlight | sControls
Text=Stop
LeftMouseDownAction=[!DisableMeasure mCounterTimer][!HideMeter Stop][!ShowMeter Start][!ShowMeter Reset][!ShowMeter Set][!SetOptionGroup TimerDisplay FontColor ""]
Hidden=1
X=30

[Reset]
Meter=String
MeterStyle=sAllText | sHighlight | sControls
Text=Reset
LeftMouseDownAction=[!DisableMeasure mTimer]
LeftMouseUpAction=[!EnableMeasure mTimer][!ShowMeter Start][!ShowMeter Set][!HideMeter Reset][PlayStop "#Alarm#"]
Hidden=1
X=76

[Set]
Meter=String
MeterStyle=sAllText | sHighlight | sControls
Text=Set
LeftMouseUpAction=[!HideMeterGroup Controls][!ShowMeter OK]   [!DisableMeasure mCounterTimer]   [!SetOptionGroup TimerDisplay MeterStyle "sAllText | sHighlight | sTimerDisplay"][!SetOptionGroup Button Hidden "0"]   [!SetOption TimerDisplayHr MouseScrollUpAction """ [!EnableMeasure mHp]"""]   [!SetOption TimerDisplayHr MouseScrollDownAction """ [!EnableMeasure mHm]"""]   [!SetOption TimerDisplayMin MouseScrollUpAction """ [!EnableMeasure mMp]"""]   [!SetOption TimerDisplayMin MouseScrollDownAction """ [!EnableMeasure mMm]"""] [!UpdateMeter *][!Redraw]
X=123

[OK]
Meter=String
MeterStyle=sAllText | sHighlight | sSetting
Text=OK
LeftMouseupAction=[!HideMeter OK][!ShowMeterGroup Controls]   [!HideMeter Reset][!ShowMeter Start][!HideMeter Stop]   [!SetOptionGroup Button Hidden "1"][!SetOptionGroup TimerDisplay MouseScrollUpAction ""][!SetOptionGroup TimerDisplay MouseScrollDownAction ""]   [!SetOptionGroup TimerDisplay MeterStyle "sAllText | sTimerDisplay"] [!UpdateMeter *][!Redraw]
Hidden=1
X=123
Y=50

========================================
; Round Bar
========================================
[sRoundBar]
LineStart=12
LineLength=16
StartAngle=(Rad(270))
RotationAngle=6.2831853
Antialias=1
Solid=1
X=135
Y=25

[RoundBarBack]
Meter=RoundLine
MeterStyle=sRoundBar
LineColor=255,255,255,20

[RoundBarFore]
Meter=RoundLine
MeasureName=mTimer2
MeterStyle=sRoundBar
LineColor=100,100,200
LineWidth=4
Solid=0

========================================
; Menu
========================================
;[Menu]
;Meter=IMAGE
;ImageName=;MenuXR.png
;Hidden=1
;Group=Menu
;X=127
;Y=0
;
;[Close]
;Meter=Shape
;Shape=Rectangle 127,0,20,20,15 | FillColor 200,100,100 | StrokeWidth 2 | Extend StrokeAlpha
;StrokeAlpha=Stroke Color 128,255,0,100
;LeftMouseupAction=!DeactivateConfig
;MouseOverAction=[!SetOption #CURRENTSECTION# StrokeAlpha "Stroke Color 0,255,255,255"] [!UpdateMeter *][!Redraw]
;MouseLeaveAction=[!SetOption #CURRENTSECTION# StrokeAlpha "Stroke Color 128,255,0,100"] [!UpdateMeter *] [!Redraw] 
;DynamicVariables=1
;Hidden=1
;Group=Menu
;
;[More]
;Meter=Shape
;Shape=Rectangle 127,21,20,20,15 | FillColor 100,100,200 | StrokeWidth 2 | Extend StrokeAlpha
;StrokeAlpha=Stroke Color 128,255,0,100
;LeftMouseupAction=!ActivateConfig "#CURRENTCONFIG#" "Stopwatch.ini"
;MouseOverAction=[!SetOption #CURRENTSECTION# StrokeAlpha "Stroke Color 0,255,255,255"] [!UpdateMeter *][!Redraw]
;MouseLeaveAction=[!SetOption #CURRENTSECTION# StrokeAlpha "Stroke Color 128,255,0,100"] [!UpdateMeter *] [!Redraw] 
;DynamicVariables=1
;Hidden=1
;Group=Menu
Ok, so I've tried to change the whole left click on the Action strings due to it not working. But the new buttons I've created do the same thing!!! So it must be an issue with the variable.

Basically, the Test Close Apps button works fine. But when I click Set and then the red buttons to set an action, they all work except the first one for CloseApps. This always locks the PC and I just can't figure out why? Please could someone take a look at the code to see what's wrong?

Thank you.
- MuLab -
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Simple countdown timer

Post by balala »

sl23 wrote: August 1st, 2021, 4:20 pm Basically, the Test Close Apps button works fine. But when I click Set and then the red buttons to set an action, they all work except the first one for CloseApps. This always locks the PC and I just can't figure out why? Please could someone take a look at the code to see what's wrong?
There is an extra pair of brackets in the IfBelowAction option of the [mTimer3Act] measure. The Act variable, as set into the LeftMouseUpAction option of the [Button1] meter, already contains the brackets required by the !CommandMeasure bang, but in the mentioned IfBelowAction option you added one more. So correctly this option should be: IfBelowAction=[!DisableMeasure mCounterTimer]#Act#[!HideMeter Stop][!HideMeter Start][!ShowMeter Reset], not as you had it IfBelowAction=[!DisableMeasure mCounterTimer][#Act#][!HideMeter Stop][!HideMeter Start][!ShowMeter Reset].
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Simple countdown timer

Post by sl23 »

balala wrote: August 1st, 2021, 6:04 pm There is an extra pair of brackets in the IfBelowAction option of the [mTimer3Act] measure. The Act variable, as set into the LeftMouseUpAction option of the [Button1] meter, already contains the brackets required by the !CommandMeasure bang, but in the mentioned IfBelowAction option you added one more. So correctly this option should be: IfBelowAction=[!DisableMeasure mCounterTimer]#Act#[!HideMeter Stop][!HideMeter Start][!ShowMeter Reset], not as you had it IfBelowAction=[!DisableMeasure mCounterTimer][#Act#][!HideMeter Stop][!HideMeter Start][!ShowMeter Reset].
Damn! I had that pointed out to me a little while ago too! Completely missed that. Thanks balala, that solved it, thank you
- MuLab -
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Simple countdown timer

Post by balala »

sl23 wrote: August 1st, 2021, 6:08 pm Damn! I had that pointed out to me a little while ago too! Completely missed that. Thanks balala, that solved it, thank you
Always glad to help. Is there any other question related to your skin (because to be honest I didn't follow too closely the topic these days)?
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Simple countdown timer

Post by sl23 »

I'm still wondering why the update rate is so fast. I have other skins that use MouseScrollActions and they are all set to Update=1000. Is the fast update rate required for the timer to function? But then it seems to function correctly when I increase the Update rate. The only thing I seem to have trouble with is the MouseScrollActions. Any ideas?
- MuLab -
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Simple countdown timer

Post by balala »

sl23 wrote: August 1st, 2021, 6:15 pm I'm still wondering why the update rate is so fast. I have other skins that use MouseScrollActions and they are all set to Update=1000. Is the fast update rate required for the timer to function? But then it seems to function correctly when I increase the Update rate. The only thing I seem to have trouble with is the MouseScrollActions. Any ideas?
Yep. Years ago, when I wrote the code of Timer, my knowledge was not enough to write a proper code. You probably took the LeftMouseUpAction options of the + and - buttons I wrote then and used them on scrolling actions. If you take a look, when scrolling, the otherwise disabled measures are enabled, then disabled again. And this takes a time, the !UpdateMeasure bang doesn't seem to help too much. So we have to wait for the next update cycle in order the scrolling to work again. If the Update value of the skin is too high (and in this case the default Update=1000 is too high!), the scrolling goes on as you saw. The only way to fix this is to reduce the Update value.
Probably the whole code should be rewritten, in order to can take the skin to properly work with the default Update as well. Don't say it is impossible, but there for sure is a lot of work. If I'll have enough time, I'll try to rewrite it, however I1m not sure at all when this gonna happen. Sorry, but this is it...
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Simple countdown timer

Post by sl23 »

Ok thank you, at least I sort of know now why it is the way it is. What about the Mirage skin? Does that require a fast Update rate too?
Maybe I should've used that as my starting point?

Anyway, thank you for your time and help and also, for allowing me to use your skins. :thumbup:
- MuLab -
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Simple countdown timer

Post by balala »

sl23 wrote: August 1st, 2021, 8:19 pm What about the Mirage skin? Does that require a fast Update rate too?
No, at all. If you check it, you'll see its Timer skin (which integrates in fact four skins, on four tabs) uses the default Update=1000.
sl23 wrote: August 1st, 2021, 8:19 pm Maybe I should've used that as my starting point?

Anyway, thank you for your time and help and also, for allowing me to use your skins. :thumbup:
Obviously. I always publish my skins under "Creative Commons Attribution-Noncommercial-No Derivative Works", so you (or anybody) can freely use it. Just asking, if possible, mention me when publishing your work.
Here note just that looking to your code, I just got the idea to use the mouse scrolling in the settings panels of my Timer. Hope you don't mind. Thanks in advance.