It is currently March 29th, 2024, 12:02 pm

Change variable then run command not occurring in the correct order.

Get help with creating, editing & fixing problems with skins
Nomig
Posts: 2
Joined: April 8th, 2021, 10:32 pm

Change variable then run command not occurring in the correct order.

Post by Nomig »

Edit: Solved, thanks Brian.

I'm making a skin that currently has 10 button images that all do the same thing, except with a different parameter (I'm using this to control my smart lights, so the button will run a python script with a different parameter). The way I'm doing this is a Measure for each button image, and on click each one will set a variable to a specific value (0 for the first one, then increasing until 254 for the last), and after setting the variable THEN run the python script. This is the code I'm using:

Code: Select all

[Variables]
ButtonWidth=1000
ButtonHeight=100
ButtonSpacing=35
Brightness=0

[MeasureRun]
DynamicVariables=1
Measure=Plugin
Plugin=RunCommand
Program=bash
StartInFolder="C:/devlibs/Lights/pytradfri-master"
Parameter=-ic "python3 control.py "#Brightness#
State=Hide

[MeterLight0]
Meter=Button
DynamicVariables=1
ButtonImage=#@#Images/Bulb2.png
ButtonCommand= [!SetVariable Brightness "0"] [!CommandMeasure MeasureRun "Run"]
W=#ButtonWidth#
H=#ButtonHeight#
x=0
y=0


With MeterLight repeated 10 times with different values for Brightness.

The problem I'm having is that the button command runs the SetVariable after the command, no matter the order. In practice this means when I click a button it sets the brightness to that of the last button I pressed. Any solutions? Also, this is the first skin I'm making, so any suggestions for the whole scheme (i.e. a better way of doing it than 10 images) are also appreciated.
Last edited by Nomig on April 8th, 2021, 11:09 pm, edited 1 time in total.
User avatar
Sam12345
Posts: 80
Joined: February 27th, 2021, 9:41 pm
Location: London

Re: Change variable then run command not occurring in the correct order.

Post by Sam12345 »

Here before Jsmorley or another moderator in time to say: "Please use the </> for code". :D
I'm afraid that's going to be all my contribution, I'm not good enough to help you with that problem.
Last edited by Sam12345 on April 8th, 2021, 10:45 pm, edited 2 times in total.
Insert inspirational quote here
User avatar
Brian
Developer
Posts: 2674
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Change variable then run command not occurring in the correct order.

Post by Brian »

After setting the variable, you need to update the MeasureRun measure before running it.

Something like this:

Code: Select all

[Variables]
ButtonWidth=1000
ButtonHeight=100
ButtonSpacing=35
Brightness=0

[MeasureRun]
DynamicVariables=1
Measure=Plugin
Plugin=RunCommand
Program=bash
StartInFolder="C:/devlibs/Lights/pytradfri-master"
Parameter=-ic "python3 control.py "#Brightness#
State=Hide

[MeterLight0]
Meter=Button
DynamicVariables=1
ButtonImage=#@#Images/Bulb2.png
ButtonCommand= [!SetVariable Brightness "0"][!UpdateMeasure MeasureRun][!CommandMeasure MeasureRun "Run"]
W=#ButtonWidth#
H=#ButtonHeight#
x=0
y=0
Hopefully that helps.

-Brian
Nomig
Posts: 2
Joined: April 8th, 2021, 10:32 pm

Re: Change variable then run command not occurring in the correct order.

Post by Nomig »

Brian wrote: April 8th, 2021, 10:44 pm After setting the variable, you need to update the MeasureRun measure before running it.

Something like this:

Code: Select all

[Variables]
ButtonWidth=1000
ButtonHeight=100
ButtonSpacing=35
Brightness=0

[MeasureRun]
DynamicVariables=1
Measure=Plugin
Plugin=RunCommand
Program=bash
StartInFolder="C:/devlibs/Lights/pytradfri-master"
Parameter=-ic "python3 control.py "#Brightness#
State=Hide

[MeterLight0]
Meter=Button
DynamicVariables=1
ButtonImage=#@#Images/Bulb2.png
ButtonCommand= [!SetVariable Brightness "0"][!UpdateMeasure MeasureRun][!CommandMeasure MeasureRun "Run"]
W=#ButtonWidth#
H=#ButtonHeight#
x=0
y=0
Hopefully that helps.

-Brian
That worked perfectly, thanks.
User avatar
StArL0rd84
Posts: 424
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: Change variable then run command not occurring in the correct order.

Post by StArL0rd84 »

Nomig wrote: April 8th, 2021, 10:33 pm Parameter=-ic "python3 control.py "#Brightness#
How did you load the brightness variable onto the script?
Just started learning to use python today because I had a use for it changing neopixel colors on my 3d printer via serial.

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Program=C:\Windows\py.exe
Parameter=#@#Scripts\test.py

Code: Select all

import serial
import time

ser = serial.Serial("COM3", 115200)

time.sleep(2)
ser.write(str.encode('M150 B255\n'))
time.sleep(1)
([mWorkTime] = 1 ? #Work# : ([mEnergyLoss:%] >= 70% ? #Chillmode# : </>))
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Change variable then run command not occurring in the correct order.

Post by death.crafter »

StArL0rd84 wrote: October 31st, 2021, 2:05 pm How did you load the brightness variable onto the script?
Just started learning to use python today because I had a use for it changing neopixel colors on my 3d printer via serial.

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Program=C:\Windows\py.exe
Parameter=#@#Scripts\test.py

Code: Select all

import serial
import time

ser = serial.Serial("COM3", 115200)

time.sleep(2)
ser.write(str.encode('M150 B255\n'))
time.sleep(1)
https://www.geeksforgeeks.org/command-line-arguments-in-python/
from the Realm of Death
User avatar
StArL0rd84
Posts: 424
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: Change variable then run command not occurring in the correct order.

Post by StArL0rd84 »

Thank you but could you give me a hint? :confused:
([mWorkTime] = 1 ? #Work# : ([mEnergyLoss:%] >= 70% ? #Chillmode# : </>))
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Change variable then run command not occurring in the correct order.

Post by death.crafter »

StArL0rd84 wrote: October 31st, 2021, 2:25 pm Thank you but could you give me a hint? :confused:
Don't know much python but you could take it like:

Code: Select all

import sys

# your code here

argc = len(sys.argv)

if argc >= 2:
	try:
		myprinter.setNeoPixelcolor(sys.argv[1])
	except:
		# handle your exceptions here, in case provided argument is invalid
from the Realm of Death