Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 1609

Help: Rainmeter Skins • Re: Hide meters when no value available from WebParser

$
0
0
Another solution.
If you have enough time, you can try it, or you might be confused.
2024-12-28_preview.png

Code:
2024-12-28_RMAbout.png

reminders.json

Code:

{    "entity_id": "input_text.reminders",    "state": "reminder text 1, reminder text 2, reminder text 3, reminder text 4",    "attributes": {        "editable": true,        "min": 0,        "max": 9999999,        "pattern": null,        "mode": "text",        "icon": "mdi:checkbox-marked-circle-auto-outline",        "friendly_name": "Reminders"    }}

Skin.ini

Code:

;; 2024-12-28 | UTF-16 LE BOM[Variables];;;; Skin scaling - Based on display resolution recognized by the Rainmeter.exe;;            ;;  1.00 (100%) - 1920x1080, 1600x900, 1366x768, 1280x720;;  1.25 (125%) - 1920x1200;;  1.50 (150%) - 2560x1440, 2560x1600, 3440x1440;;  2.00 (200%) - 3840x2160;;  4.00 (400%) - 7680x4320;;;; $=(Max(1.00,Ceil(Min(#SCREENAREAWIDTH#,#SCREENAREAHEIGHT#)/1080*100/25)*25/100));;;; @see  Rainmeter and DPI in Windows 10 by jsmorley               | https://forum.rainmeter.net/viewtopic.php?t=22272;; @see  Get DPI scaling on the command line  `setdpi.exe value 1` | https://github.com/imniko/SetDPI;;$=(Max(1.00,Ceil(Min(#SCREENAREAWIDTH#,#SCREENAREAHEIGHT#)/1080*100/25)*25/100));;;; Basic size in pixel;;$B=(Round(#$#-0.25))BACKGROUND_W=160BACKGROUND_H=120BORDER_W=2;;;; CHECKBOX_STATE={0-31} | bit field | 1=CheckBox1, 2=CheckBox2, 4=CheckBox3, 8=CheckBox4, 16=CheckBox5;;CHECKBOX_STATE=0ITEM1=ITEM2=ITEM3=ITEM4=ITEM5=;;;; DefaultUpdateDivider | https://docs.rainmeter.net/manual/skins/rainmeter-section/#DefaultUpdateDivider;;[Rainmeter]Update=1000DefaultUpdateDivider=-1AccurateText=1MouseActionCursor=0;; =========================================================;; ===  Measures  ==========================================;; =========================================================;;;; WebParser measure | https://docs.rainmeter.net/manual/measures/webparser/;; PCRE syntax       | https://www.pcre.org/original/doc/html/pcresyntax.html;;[sWebParser]Measure=WebParserURL=file://#CURRENTPATH#reminders.jsonRegExp=^[\s\S]*$UpdateDivider=1; UpdateRate=600UpdateRate=30FinishAction=[!EnableMeasure aUpdateItems][!UpdateMeasure aUpdateItems][sData_state]Measure=WebParserURL=[sWebParser]RegExp="state":\s*"([^"]+)"StringIndex2=1;;;; How a skin is updated | https://forum.rainmeter.net/viewtopic.php?t=34774;; Nesting Variables     | https://docs.rainmeter.net/manual/variables/nesting-variables/;;;;  text1, text2, text3, text4 -> ITEM1=text1, ITEM2=text2, ITEM3=text3, ITEM4=text4, ITEM5=;;[aUpdateItems]Measure=StringString=[sData_state]DynamicVariables=1IfConditionMode=1IfCondition=1IfTrueAction=[!SetVariable NO "0"][!SetVariable ITEM1 ""][!SetVariable ITEM2 ""][!SetVariable ITEM3 ""][!SetVariable ITEM4 ""][!SetVariable ITEM5 ""]IfCondition2=1IfTrueAction2=[!HideMeterGroup gCheckBox][!HideMeterGroup gLabel]RegExpSubstitute=1Substitute="\s*([^,]+)":'[!SetVariable NO "([#*NO*]+1)"][!SetVariable ITEM[#*NO*] "\1"][!ShowMeter CheckBox[#*NO*]][!ShowMeter Label[#*NO*]]'OnUpdateAction=[aUpdateItems][!UpdateMeterGroup gLabel][!UpdateMeter Ninja][!Redraw]Disabled=1;;;; IfCondition | https://docs.rainmeter.net/manual/measures/general-options/ifconditions/;;[aSetCheckBoxes]Measure=StringDynamicVariables=1IfConditionMode=1IfCondition=1=1&[#CHECKBOX_STATE]IfTrueAction=[!SetOption CheckBox1 Text "[\x2611]"]IfFalseAction=[!SetOption CheckBox1 Text "[\x2610]"]IfCondition2=2=2&[#CHECKBOX_STATE]IfTrueAction2=[!SetOption CheckBox2 Text "[\x2611]"]IfFalseAction2=[!SetOption CheckBox2 Text "[\x2610]"]IfCondition3=4=4&[#CHECKBOX_STATE]IfTrueAction3=[!SetOption CheckBox3 Text "[\x2611]"]IfFalseAction3=[!SetOption CheckBox3 Text "[\x2610]"]IfCondition4=8=8&[#CHECKBOX_STATE]IfTrueAction4=[!SetOption CheckBox4 Text "[\x2611]"]IfFalseAction4=[!SetOption CheckBox4 Text "[\x2610]"]IfCondition5=16=16&[#CHECKBOX_STATE]IfTrueAction5=[!SetOption CheckBox5 Text "[\x2611]"]IfFalseAction5=[!SetOption CheckBox5 Text "[\x2610]"]IfCondition6=1IfTrueAction6=[!UpdateMeterGroup gCheckBox]Disabled=1;; =========================================================;; ===  Meters  ============================================;; =========================================================;;;; Rectangle - Shape meter | https://docs.rainmeter.net/manual/meters/shape/#Rectangle;;[Background]Meter=ShapeShape=Rectangle 0,0,#BACKGROUND_W#,#BACKGROUND_H#,(Trunc(5*#$#))|StrokeWidth 0|Extend BackgroundColorBackgroundColor=Fill Color 434C5EShape2=Rectangle 0,0,#BACKGROUND_W#,#BACKGROUND_H#,(Trunc(5*#$#))|StrokeWidth 0|Extend BorderColorBorderColor=Fill Color D08770Shape3=Rectangle (#BORDER_W#*#$B#),(#BORDER_W#*#$B#),(#BACKGROUND_W#-2*#BORDER_W#*#$B#),(#BACKGROUND_H#-2*#BORDER_W#*#$B#),(Trunc(5*#$#))|StrokeWidth 0|Fill Color FFFFFFShape4=Combine Shape2|Exclude Shape3;;;; Character Variables | https://docs.rainmeter.net/manual/variables/character-variables/;;;; [\x2610] box, [\x2611] box with check;;[tCheckBox]AntiAlias=1FontColor=E5E9F0FontFace=Segoe UI SymbolFontSize=(15*#$#)FontWeight=400Group=gCheckBoxText=[\x2610]X=(10*#$#)Y=(5*#$#)RHidden=1[CheckBox1]Meter=StringMeterStyle=tCheckBoxY=(5*#$#)LeftMouseUpAction=[!SetVariable CHECKBOX_STATE "([#CHECKBOX_STATE]-(1=1&[#CHECKBOX_STATE]?1:-1))"][!UpdateMeasure aSetCheckBoxes][!Redraw][CheckBox2]Meter=StringMeterStyle=tCheckBoxLeftMouseUpAction=[!SetVariable CHECKBOX_STATE "([#CHECKBOX_STATE]-(2=2&[#CHECKBOX_STATE]?2:-2))"][!UpdateMeasure aSetCheckBoxes][!Redraw][CheckBox3]Meter=StringMeterStyle=tCheckBoxLeftMouseUpAction=[!SetVariable CHECKBOX_STATE "([#CHECKBOX_STATE]-(4=4&[#CHECKBOX_STATE]?4:-4))"][!UpdateMeasure aSetCheckBoxes][!Redraw][CheckBox4]Meter=StringMeterStyle=tCheckBoxLeftMouseUpAction=[!SetVariable CHECKBOX_STATE "([#CHECKBOX_STATE]-(8=8&[#CHECKBOX_STATE]?8:-8))"][!UpdateMeasure aSetCheckBoxes][!Redraw][CheckBox5]Meter=StringMeterStyle=tCheckBoxLeftMouseUpAction=[!SetVariable CHECKBOX_STATE "([#CHECKBOX_STATE]-(16=16&[#CHECKBOX_STATE]?16:-16))"][!UpdateMeasure aSetCheckBoxes][!Redraw][tLabel]AntiAlias=1DynamicVariables=1FontColor=E5E9F0FontFace=Segoe UIFontSize=(15*#$#)FontWeight=500Group=gLabelHidden=1[Label1]Meter=StringMeterStyle=tLabelX=([CheckBox1:XW]+5*#$#)Y=[CheckBox1:Y]Text=#ITEM1#LeftMouseUpAction=[!SetVariable CHECKBOX_STATE "([#CHECKBOX_STATE]-(1=1&[#CHECKBOX_STATE]?1:-1))"][!UpdateMeasure aSetCheckBoxes][!Redraw][Label2]Meter=StringMeterStyle=tLabelX=([CheckBox2:XW]+5*#$#)Y=[CheckBox2:Y]Text=#ITEM2#LeftMouseUpAction=[!SetVariable CHECKBOX_STATE "([#CHECKBOX_STATE]-(2=2&[#CHECKBOX_STATE]?2:-2))"][!UpdateMeasure aSetCheckBoxes][!Redraw][Label3]Meter=StringMeterStyle=tLabelX=([CheckBox3:XW]+5*#$#)Y=[CheckBox3:Y]Text=#ITEM3#LeftMouseUpAction=[!SetVariable CHECKBOX_STATE "([#CHECKBOX_STATE]-(4=4&[#CHECKBOX_STATE]?4:-4))"][!UpdateMeasure aSetCheckBoxes][!Redraw][Label4]Meter=StringMeterStyle=tLabelX=([CheckBox4:XW]+5*#$#)Y=[CheckBox4:Y]Text=#ITEM4#LeftMouseUpAction=[!SetVariable CHECKBOX_STATE "([#CHECKBOX_STATE]-(8=8&[#CHECKBOX_STATE]?8:-8))"][!UpdateMeasure aSetCheckBoxes][!Redraw][Label5]Meter=StringMeterStyle=tLabelX=([CheckBox5:XW]+5*#$#)Y=[CheckBox5:Y]Text=#ITEM5#LeftMouseUpAction=[!SetVariable CHECKBOX_STATE "([#CHECKBOX_STATE]-(16=16&[#CHECKBOX_STATE]?16:-16))"][!UpdateMeasure aSetCheckBoxes][!Redraw][Ninja]Meter=StringHidden=1UpdateDivider=-1OnUpdateAction=[!SetVariable BACKGROUND_W "(Max([Label1:XW],Max([Label2:XW],Max([Label3:XW],Max([Label4:XW],[Label5:XW]))))+Trunc(10*#$#))"][!SetVariable BACKGROUND_H "([Label5:YH]+Trunc(5*#$#))"][!SetOption Background DynamicVariables 0][!UpdateMeter Background][!EnableMeasure aSetCheckBoxes][!UpdateMeasure aSetCheckBoxes];;-----------------------------------------------------------------------------;; Rainmeter Documentation | https://docs.rainmeter.net ;; Dynamic Cheat Sheet     | https://docs.rainmeter.net/tips/dynamiccheatsheet/;; Nesting Variables       | https://docs.rainmeter.net/manual/variables/nesting-variables/;; How a skin is updated   | https://forum.rainmeter.net/viewtopic.php?t=34774;;-----------------------------------------------------------------------------





When the WebParser is finished parsing, the following measure will be updated.
The string value [sData_state] (WebParser child measure) is something like text1, text2, text3, text4 (comma-separated data).

Code:

[aUpdateItems]Measure=StringString=[sData_state]DynamicVariables=1IfConditionMode=1IfCondition=1IfTrueAction=[!SetVariable NO "0"][!SetVariable ITEM1 ""][!SetVariable ITEM2 ""][!SetVariable ITEM3 ""][!SetVariable ITEM4 ""][!SetVariable ITEM5 ""]IfCondition2=1IfTrueAction2=[!HideMeterGroup gCheckBox][!HideMeterGroup gLabel]RegExpSubstitute=1Substitute="\s*([^,]+)":'[!SetVariable NO "([#*NO*]+1)"][!SetVariable ITEM[#*NO*] "\1"][!ShowMeter CheckBox[#*NO*]][!ShowMeter Label[#*NO*]]'OnUpdateAction=[aUpdateItems][!UpdateMeterGroup gLabel][!UpdateMeter Ninja][!Redraw]Disabled=1


What aUpdateItems measure doing is

1. Initialize variables
NO=0 (number, zero)
ITEM1=(empty string)
ITEM2=(empty string)
...
2. Hide all checkbox and label meters.
3. Generate bang action string using Substitute option.
From: text1, text2, text3, text4
To:
[!SetVariable ITEM1 "text1"][!ShowMeter CheckBox1][!ShowMeter Label1]
[!SetVariable ITEM2 "text2"][!ShowMeter CheckBox2][!ShowMeter Label2]
...
4. Perform bang actions in OnUpdateAction.
OnUpdateAction=[aUpdateItems]

Generating bang action string is based on Yincognito's code somewhere on this forum. Thank you, Yincognito!

See also: How a skin is updated by jsmorley, Nesting Variables

Statistics: Posted by nek — 29 minutes ago



Viewing all articles
Browse latest Browse all 1609

Trending Articles