It is currently April 26th, 2024, 8:15 am

Editing "MinimalTimer" to show minutes instead of seconds

Get help with creating, editing & fixing problems with skins
User avatar
caze
Posts: 2
Joined: May 9th, 2022, 10:53 am
Location: Bournemouth, Dorset, UK

Editing "MinimalTimer" to show minutes instead of seconds

Post by caze »

Hello,

Been getting nowhere with editing this MinimalTimer config for hours on my own so I thought its time to ask for help. I've tried pilfering bits of code from various places and tacking it on to no avail. I've broken it more times than I can count!

I just want Stopwatch Text/MeterCenterText to show time left in minutes, rather than seconds as it is at the moment. If possible, seconds would also show in addition to minutes but in a smaller font. Then once there is less than a minute left, it would show just seconds again.

I have a feeling I'm looking at the right parameters with MeasureTimerScript and MeasureMinutesRemaining but I simply can't fathom how to bring it together. Edit: .. Maybe I should be looking somewhere in this lua script and adding a formula to divide seconds by 60?
image_2022-05-09_131738767.png
A secondary objective would be to automatically start timer sessions in a regimented way - i.e a work day with consistent breaks. Perhaps that might be too complicated?

Currently ini is as follows;

Code: Select all

; Minimal Timer
; by Shayne Holmes
[Rainmeter]
Update=250
DynamicWindowSize=0

;-----
; Skin-specific stuff

; Click to disable flashing
LeftMouseUpAction=[!SetVariable Flashing 0][!Update]

; Show quick buttons on hover
MouseOverAction=[!ToggleMeterGroup ButtonGroup][!Redraw]
MouseLeaveAction=[!ToggleMeterGroup ButtonGroup][!Redraw]

[Variables]
@includeState=#@#state.inc

; Presets
QuickTimer1PresetMinutes=52
QuickTimer1Color=0,188,213,255
QuickTimer2PresetMinutes=25
QuickTimer2Color=57,61,110,255
DefaultTimerLengthMinutes=5
DefaultTimerColor=232,101,0,255

; Stopwatch Text (shows time remaining)
; Hidden by default; unhide it by setting Hidden=0 in MeterCenterText below
Font=Comfortaa
FontSize=14
FontColor=255,255,255,255

; Visual theme values

WidgetSize=190
ArcBorderWidth=2
ArcBorderOuterRadiusRatio=0.91
ArcBorderInnerRadiusRatio=(#ArcBorderOuterRadiusRatio#-#ArcBorderWidth#/#WidgetSize#*2)
ArcTrackInnerRadiusRatio=0
ArcTrackOuterRadiusRatio=0.98
ArcTimerWidth=80
ArcTimerOuterRadiusRatio=(#ArcBorderInnerRadiusRatio#-0.1)
ArcButtonRadiusRatio=1

; Theme colors.
ColorBorder=105,155,115,90
ColorBackground=0,0,0,90

; Timer config values
MaximumTimeDisplayed=3600
FlashTimeoutSeconds=30

;----------
; Internal state
StateButtonsHidden=1
Flashing=0
; Calculations
ArcRadius=(#WidgetSize#/2)
; Variables in external state file
; TimerEndOfTimer=0
; ColorTimerArc=#DefaultTimerColor#
; EndOfTimerHash=0

;----------------------------------------------
; MEASURES

[MeasureInput]
Measure=Plugin
Plugin=InputText
SolidColor=0,0,0,255
FontColor=FFFFFF
FontFace=Comfortaa
FontSize=10
FocusDismiss=1
X=110
Y=110
H=25
W=40
DefaultValue=#DefaultTimerLengthMinutes#
Command1=!CommandMeasure "MeasureTimerScript" "StartTimer('$UserInput$','#DefaultTimerColor#',0)"
StringAlign=Center

[MeasureTime]
Measure=Time

[MeasureTimerBar]
Measure=Calc
Formula=(#Flashing#>0?(MeasureTime%2):(MeasureTimerScript)/#MaximumTimeDisplayed#)
DynamicVariables=1

[MeasureSecondsRemaining]
; includes leading zero
Measure=Calc
Formula=(MeasureTimerScript%60/100)
Substitute="0.":""

[MeasureMinutesRemaining]
; includes leading zero
Measure=Calc
Formula=FLOOR(MeasureTimerScript/60)/100
Substitute="0.":""

[MeasureAlways1]
Measure=Calc
Formula=1
UpdateDivider=-1

[MeasureAhkWindowMessaging]
Measure=Plugin
Plugin=WindowMessagePlugin
WindowClass=AutoHotkey

[MeasureTimerScript]
Measure=Script
ScriptFile=#@#timer.lua

;----------------------------------------------
; STYLES

[StyleText]
AntiAlias=1
StringAlign=CenterCenter
StringStyle=Bold
FontFace=#Font#
FontSize=#FontSize#
FontColor=#FontColor#

[StyleQuickButton]
Hidden=1
AntiAlias=1
StringAlign=CenterCenter
StringStyle=Bold
FontFace=#Font#
FontSize=#FontSize#
FontColor=#ThemeColorFull#
X=(#WidgetSize#+25)
Y=5R
W=30
H=30
UpdateDivider=-1
Group=ButtonGroup

[StyleArc]
X=0
Y=0
W=#WidgetSize#
H=#WidgetSize#
LineWidth=1
LineStart=0
StartAngle=4.7123889
RotationAngle=6.2831853
Solid=1
AntiAlias=1

;----------------------------------------------
; Meters

;-----------------------
; background

[MeterBackgroundCircle]
Meter=ROUNDLINE
MeasureName=MeasureAlways1
MeterStyle=StyleArc
LineColor=#ColorBackground#
Solid=1
LineLength=(#ArcRadius#*#ArcTrackInnerRadiusRatio#)
LineStart=(#ArcRadius#*#ArcTrackOuterRadiusRatio#)
UpdateDivider=-1

[MeterTimer]
Meter=ROUNDLINE
MeasureName=MeasureTimerbar
MeterStyle=StyleArc
LineLength=(#ArcRadius#*#ArcTimerOuterRadiusRatio#)
LineStart=0
; was (#ArcRadius#*#ArcTimerOuterRadiusRatio#-#ArcTimerWidth#)
LineColor=#ColorTimerArc#
StartAngle=((-[MeasureTimerbar]/2-#EndOfTimerHash#)*2*PI)
DynamicVariables=1

[MeterCenterText]
Meter=String
MeterStyle=StyleText
NumOfDecimals=0
MeasureName=MeasureTimerScript
X=(#WidgetSize#/2)
Y=(#WidgetSize#*5/8)
Text=%1
; Hidden by default; set Hidden=0 and uncomment the Group line to see it
Hidden=0
Group=ButtonGroup

[MeterBorderCircle]
Meter=ROUNDLINE
MeasureName=MeasureAlways1
MeterStyle=StyleArc
LineColor=#ColorBorder#
Solid=1
LineLength=(#ArcRadius#*#ArcBorderInnerRadiusRatio#)
LineStart=(#ArcRadius#*#ArcBorderOuterRadiusRatio#)
UpdateDivider=-1

;-----------------------
; Quick-set buttons

[MeterQuickButtonBackground]
UpdateDivider=-1
Meter=Image
SolidColor=0,0,0,1
Y=0
X=0
H=#WidgetSize#
W=(#WidgetSize#+45)

[MeterQuickButton1]
Meter=STRING
MeterStyle=StyleQuickButton
SolidColor=#QuickTimer1Color#
Y=(#WidgetSize#/2-30-5)
LeftMouseUpAction=[!CommandMeasure "MeasureTimerScript" "StartTimer(#QuickTimer1PresetMinutes#,'#QuickTimer1Color#',1)"]
Text=#QuickTimer1PresetMinutes#

[MeterQuickButton2]
Meter=STRING
MeterStyle=StyleQuickButton
SolidColor=#QuickTimer2Color#
LeftMouseUpAction=[!CommandMeasure "MeasureTimerScript" "StartTimer(#QuickTimer2PresetMinutes#,'#QuickTimer2Color#',0)"]
Text=#QuickTimer2PresetMinutes#

[MeterQuickButton3]
Meter=STRING
MeterStyle=StyleQuickButton
SolidColor=#DefaultTimerColor#
Text=?
LeftMouseUpAction=[!SetVariable Flashing 0][!Update][!CommandMeasure "MeasureInput" "ExecuteBatch ALL"]

[MeterQuickButtonCount]
Meter=STRING
MeterStyle=StyleQuickButton
Y=(#WidgetSize#*5/16)
X=((#WidgetSize#)/2)
Text=#TimerCount#
LeftMouseDoubleClickAction=[!SetVariable TimerCount 0][!WriteKeyValue Variables TimerCount 0 #@#state.inc][!UpdateMeterGroup ButtonGroup][!Redraw]
DynamicVariables=1

;----------------------------------------------
; METADATA

[Metadata]
Name=Minimal Timer
Author=Shayne Holmes 
Information=Simple pie-chart timer that plays a sound and flashes when it's done. | Hover over for time-setting buttons, as well as a count of how many 15-minute timers you've completed.
Version=1.0
License=Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
And the lua;

Code: Select all

function Initialize()
  -- Get variables from external state
  TimerEndOfTimer=tonumber(SKIN:GetVariable('TimerEndOfTimer', '0'))
  FlashTimeoutSeconds=tonumber(SKIN:GetVariable('FlashTimeoutSeconds', '30'))
  TimeMeasure=SKIN:GetMeasure('MeasureTime')
  TimeOffset=0 -- represents the offset between os.clock() and Rainmeter time
  Flashing=0
end

function Update()
  if TimeOffset == 0 then 
    TimeOffset=TimeMeasure:GetValue() - os.clock()
  end
  CurrentTime = os.clock() + TimeOffset
  returnVal = -1
  if TimerEndOfTimer == 0 then
    if Flashing > 0 and Flashing <= CurrentTime then
      Flashing = 0
      SKIN:Bang('!SetVariable', 'Flashing', Flashing)
    end
  elseif TimerEndOfTimer > CurrentTime then
    returnVal = TimerEndOfTimer - CurrentTime
  else
    EndTimer()
  end
  return returnVal
end

function EndTimer()
  TimerEndOfTimer = 0
  SetVariable('TimerEndOfTimer', TimerEndOfTimer)
  SetVariable('TimerCount', '(#TimerCount#+#ActiveTimerCount#)')
  if tonumber(SKIN:GetVariable('AlarmAtEnd', '0')) == 1 then
    SKIN:Bang('!CommandMeasure', 'MeasureAhkWindowMessaging', 'SendMessage 16687 1 0')
    SKIN:Bang('!execute [Play Alarm.Wav]') 
    Flashing = FlashTimeoutSeconds + TimeMeasure:GetValue()
    SKIN:Bang('!SetVariable', 'Flashing', Flashing)
  end
end

function StartTimerAPI(duration, color, active)
  StartTimerHelper(duration, color, active, 0)
end

function StartTimer(duration, color, active)
  StartTimerHelper(duration, color, active, 1)
  SKIN:Bang('!CommandMeasure', 'MeasureAhkWindowMessaging', 'SendMessage 16687 0 ' .. duration * 60)
end

function StartTimerHelper(duration, color, active, alarmatend)
  duration = tonumber(duration or 0)
  Flashing = 0
  SKIN:Bang('!SetVariable', 'Flashing', Flashing)
  if duration <= 0 then 
    TimerEndOfTimer = 0
  else
    TimerEndOfTimer = duration * 60 + TimeMeasure:GetValue()
  end
  SetVariable('TimerEndOfTimer', TimerEndOfTimer)
  SetVariable('ColorTimerArc', color)
  SetVariable('ActiveTimerCount', active or 0)
  SetVariable('AlarmAtEnd', alarmatend)
  -- riffing on https://www.cs.hmc.edu/~geoff/classes/hmc.cs070.200101/homework10/hashfuncs.html
  SetVariable('EndOfTimerHash', ((1+SKIN:GetVariable('EndOfTimerHash', '1'))*TimeMeasure:GetValue()*0.5*(math.sqrt(5)-1)) % 1)
  SKIN:Bang('!UpdateMeasure', 'MeasureTimerScript')
  SKIN:Bang('!Update')
end

function SetVariable(variablename, value)
  if value == nil then
    value = '#' .. variablename .. '#'
  else
    SKIN:Bang('!SetVariable', variablename, value)
  end
  SKIN:Bang('!WriteKeyValue', 'Variables', variablename, value, '#@#state.inc')
end
Rainmeter 4.5.13.3632 (64-bit)
Language: English (1033)
Build time: 2022-03-23 15:23:40
Windows 10 Home 2009 64-bit (build 19043) - English (2057)
Path: C:\Program Files\Rainmeter\
SkinPath: C:\Users\khome\Documents\Rainmeter\Skins\
SettingsPath: C:\Users\khome\AppData\Roaming\Rainmeter\
IniFile: C:\Users\khome\AppData\Roaming\Rainmeter\Rainmeter.ini

Thank you for any assistance rendered! :D
You do not have the required permissions to view the files attached to this post.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5406
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Editing "MinimalTimer" to show minutes instead of seconds

Post by eclectic-tech »

I just downloaded the skin package and will look at it to see about the changes you requested... may not be soon (too many outside projects!)

In the meantime, I created a Pomodore Technique skin recently that may be useful until an answer comes for this package.
User avatar
caze
Posts: 2
Joined: May 9th, 2022, 10:53 am
Location: Bournemouth, Dorset, UK

Re: Editing "MinimalTimer" to show minutes instead of seconds

Post by caze »

Awesome thanks! Of course not expecting a solution to be given immediately, on the contrary I'm very grateful for any help or direction at all.

I did actually come across your timer but discarded it as it didn't have the aesthetic I was looking for (probably put too much value on this to be fair). Now that I've looked at it properly, the functionality looks very good indeed! I'll have a go.

Cheers