It is currently October 15th, 2024, 12:34 am

Simple countdown timer

Get help with creating, editing & fixing problems with skins
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5540
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Simple countdown timer

Post by eclectic-tech »

sl23 wrote: July 22nd, 2021, 8:55 pm Ahh! I was literally putting the value in seconds rather than the formula.

Unfortunately this doesn't seem to work. :???:
Sorry, my quick reply will not work on that measure (it never changes value). :uhuh:

Without seeing all of your code, the MinValue/MaxValue must be set on a measure that calculates the remaining seconds from the current time to the target time; that measure would then be used in your bar meter.
You may need to create a new measure to calculate that value if one is not already in your skin.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5540
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Simple countdown timer

Post by eclectic-tech »

I took a closer look at TimerNixie and your code and found all you need to do is add the MinValue and MaxValue to [mLua] and bind that to your bar meter (I understood you want to replace the 'seconds' bar with the countdown bar).

So the changes to your code would look like this:

Code: Select all

...
[mLua]
Measure=Script
Group=Timers
ScriptFile=#CURRENTPATH#Timer.lua
IfCondition=mLua <= 0
IfTrueAction=#ActionToTake#
Disabled=1
MaxValue=((#TimerHours# * 3600) + (#TimerMinutes# * 60) + #TimerSeconds#)
MinValue=0

; [Second]
; Meter=Bar
; MeasureName=mSecond
; BarColor=235,170,0,255
; BarOrientation=Horizontal
; SolidColor=255,255,255,60
; X=r
; Y=12R
; W=150
; H=2

[TimerBar]
Meter=Bar
MeasureName=mLua
BarColor=235,170,0,255
BarOrientation=Horizontal
SolidColor=255,255,255,60
;Flip=1
X=r
Y=12R
W=150
H=2

...
shutdown20.png
Aside:
In working with your code I noticed a few issues.
You broke the countdown display by changing the section names the script expected to find and use to write updated time values; they must be named: [MeasureSeconds], [MeasureMinutes], and [MeasureHours].
Rather than hardcode the warning message times as variables, add those as seconds remaining (10 min = 600 seconds) and test them in a second 'IfCondition' in the [mLua] section.

Feel free to ignore these additional suggestions, it is your skin and it does work as you intended.
Here is your code with those suggestions:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
LeftMouseUpAction=[PlayStop]
RightMouseUpAction=[PlayStop]

[Bg]
Meter=Shape
Shape=Rectangle Rectangle 1,1,300+20,38,5 | StrokeWidth 1 | Extend StrokeAlpha | Fill Color 0,0,0,100
StrokeAlpha=Stroke Color 128,255,0,100
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
X=1

[Variables]
@Include=TimeSettings.inc
ActionToTake=[PlayLoop Alarm.wav][Shutdown=shutdown.exe -s -t 60 -f]

; Shutdown=shutdown.exe -s -t 60 -f
; HybridShutdown=shutdown.exe /s /hybrid /f /t 60
; Restart=shutdown.exe -r -t 0
; Hibernate=rundll32.exe powrprof.dll,SetSuspendState
; Lock=rundll32.exe user32.dll, LockWorkStation

Alarm=PlayLoop Alarm.wav
AlarmTime=8.05
OffTime=8.15

========================================
; Process
========================================
[mProcessTimerStart]
Measure=Calc
Formula=1
IfCondition=(mProcessRainmeter=1)
IfTrueAction=[!EnableMeasureGroup Timers][!UpdateMeasureGroup Timers][!Redraw]
IfFalseAction=[!DisableMeasureGroup Timers][!UpdateMeasureGroup Timers][!Redraw]

[mProcessRainmeter]
Measure=Plugin
Plugin=Process
ProcessName=Rainmeter.exe

========================================
; Timer Measures
========================================
[mNow]
Measure=Time
Group=Timers
UpdateDivider=-1
Disabled=1

[mTotalSeconds]
Measure=Calc
Group=Timers
Formula=(#TimerHours# * 3600) + (#TimerMinutes# * 60) + #TimerSeconds#
UpdateDivider=-1
Disabled=1

[mTarget]
Measure=Time
Group=Timers
Format=%#m/%#d/%Y %#H:%M:%S
TimeStamp=([mNow:TimeStamp] + [mTotalSeconds])
UpdateDivider=1
Disabled=1
DynamicVariables=1
OnUpdateAction=[!SetVariable Target "[mTarget]"][!UpdateMeasure mLua]

[mLua]
Measure=Script
Group=Timers
ScriptFile=#CURRENTPATH#Timer.lua
IfCondition=mLua <= 0
IfTrueAction=[!HideMeter Message1][!ShowMeter Message2][!Redraw][#ActionToTake#]
IfCondition2=(#CURRENTSECTION#=600)
IfTrueAction2=[!HideMeter Action][!ShowMeter Message1][#Alarm#][!Redraw]
Disabled=1
MaxValue=[&mTotalSeconds]
MinValue=0
DynamicVariables=1

[MeasureHours]
Measure=Calc
Formula=#TimerHours#
[MeasureMinutes]
Measure=Calc
Formula=#TimerMinutes#
[MeasureSeconds]
Measure=Calc
Formula=#TimerSeconds#

========================================
; TIME
========================================
[Style]
FontFace=Aller
AntiAlias=1
H=26

[mTime]
Measure=Time
Format=%#I.%M %p
Substitute=".":":"

[Time]
Meter=String
MeasureName=mTime
MeterStyle=Style
FontSize=24
FontColor=0,255,255
InlineSetting=Size | 15
InlinePattern=.*( .*)$
X=10
Y=-4

[TimerBar]
Meter=Bar
MeasureName=mLua
BarColor=235,170,0,255
BarOrientation=Horizontal
SolidColor=255,255,255,60
;Flip=1
X=r
Y=12R
W=150
H=2

[Action]
Meter=String
MeterStyle=Style
FontColor=235,170,100
FontSize=9
Text=Shutdown in:
X=180
Y=0
Hidden=0

[TimerDisplay]
Meter=String
MeasureName=MeasureSeconds
MeasureName2=MeasureMinutes
MeasureName3=MeasureHours
MeterStyle=Style
FontSize=15
FontColor=255,228,110,255
Text=%3h %2m %1s
X=r
Y=13

[Message1]
Meter=String
MeterStyle=Style
FontColor=255,128,0
Text=!! 10 Mins 'til Shutdown !!
Hidden=1
X=150
Y=0

[Message2]
Meter=String
MeterStyle=Style
FontColor=255,128,0
Text=!! Shutting down Now !!
Hidden=1
X=r
Y=0
You do not have the required permissions to view the files attached to this post.
User avatar
sl23
Posts: 1832
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Simple countdown timer

Post by sl23 »

:welcome:
Last edited by sl23 on September 4th, 2024, 6:54 am, edited 1 time in total.
57686174 77696C6C 6265 77696C6C 6265
User avatar
sl23
Posts: 1832
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Simple countdown timer

Post by sl23 »

:welcome:
Last edited by sl23 on September 4th, 2024, 6:55 am, edited 1 time in total.
57686174 77696C6C 6265 77696C6C 6265
User avatar
Yincognito
Rainmeter Sage
Posts: 8467
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Simple countdown timer

Post by Yincognito »

sl23 wrote: July 24th, 2021, 11:37 am How is this so difficult to achieve and why aren't the leading zeros there by default?
Not difficult at all - in the eclectic-tech's code above just add:

Code: Select all

RegExpSubstitute=1
Substitute="^(.*)$":"0\1","^.*(.{2})$":"\1"
to your [MeasureHours], [MeasureMinutes] and [MeasureSeconds] measures. If you want the same thing for the time on the left, just adjust the [mTime] measure's Format option accordingly, e.g. %H:%M:
CD.jpg
Note: What the substitute above does is add a 0 at the start of the string, irrespective of the number there, then keep the last 2 characters. For example, 9 -> 09 -> 09 and 21 -> 021 -> 21:
^ = start of string
$ = end of string
. = any character (with some exceptions, but they don't matter here)
* = any number of times for the preceding pattern (. in this case, so overall .* means any character any number of times)
() = the pattern between round brackets is "captured" (or "retained", if you like)
\1 = reference to capture number 1
{} = the pattern between curly brackets is a "quantifier", so the preceding pattern is taken {N} times
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1832
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Simple countdown timer

Post by sl23 »

:welcome:
Last edited by sl23 on September 4th, 2024, 6:56 am, edited 1 time in total.
57686174 77696C6C 6265 77696C6C 6265
User avatar
Yincognito
Rainmeter Sage
Posts: 8467
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Simple countdown timer

Post by Yincognito »

sl23 wrote: July 24th, 2021, 12:54 pm Thanks, that's useful to know :thumbup:

Sorry, but which bit of code do I add it to? I've tried several measures and nothing changes. :oops:
I already explained this above:
- take eclectic-tech code from the Spoiler here and paste it in your skin's .INI file, replacing its previous contents
- make the modifications I mentioned, where I mentioned
- save the .INI file
- refresh the skin
Is it clearer now? :D
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1832
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Simple countdown timer

Post by sl23 »

:welcome:
Last edited by sl23 on September 4th, 2024, 6:56 am, edited 1 time in total.
57686174 77696C6C 6265 77696C6C 6265
User avatar
Yincognito
Rainmeter Sage
Posts: 8467
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Simple countdown timer

Post by Yincognito »

sl23 wrote: July 24th, 2021, 1:11 pm Sorry my mistake, I forgot to remove the code causing the issue! :oops:

Thanks again :thumbup:
Yeah, I kind of suspected that, that's why I added "replacing its previous contents" to my post afterwards.
Basically, so that you understand things better for the future, the order in which Rainmeter does things in a skin is more or less:
- measures ([sections] having Measure=... parts)
- [!bangs] in those measures, according to each measure and the options=... where those bangs belong
- meters ([sections] having Meter=... parts)
What you need to do when debugging something that has a visual expression in your skin is therefore, sort of backwards:
- identify the incriminated meter (quite obvious in this case, [TimerDisplay], judging by the contents or Text=... of the other meters)
- identify which measures are "linked" or "associated" with the said meter (by looking for MeasureNameN=... options)
- jump to those measures and see what's happening there and how stuff can be adjusted
In this specific case, since a measure has a number value and a string value, you had to modify the string value to match your preferences, naturally by manipulating that value through a substitution.

Most of this is easily noticeable when looking at the Skins Tab from the About window, where the number and the string value of every measure in your skin is shown. You can even make "step-by-step" substitutions, like only the Substitute="^(.*)$":"0\1" part, see the result after editing, saving and refreshing the skin, and then add the second part, i.e. ,"^.*(.{2})$":"\1" to the same Substitute option, in order to see exactly what's happening in each step of the way.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1832
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Simple countdown timer

Post by sl23 »

:welcome:
Last edited by sl23 on September 4th, 2024, 6:57 am, edited 1 time in total.
57686174 77696C6C 6265 77696C6C 6265