It is currently September 29th, 2024, 3:29 pm

Dynamic meter/measure creation with Lua and other thoughts.

General topics related to Rainmeter.
User avatar
jsmorley
Developer
Posts: 22790
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Dynamic meter/measure creation with Lua and other though

Post by jsmorley »

!MoveMeter, whether in a skin or a Lua script, does not support any concept of "relative" positioning, and is always two absolute values for X and Y.

Since you can't set X or Y with !SetOption, the only other approach might be to use a variable and !SetVariable.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]
Meter2Y=2R

[Meter1]
Meter=Image
SolidColor=255,0,255,255
W=30
H=30
X=0
Y=0
LeftMouseUpAction=!SetVariable Meter2Y 10R

[Meter2]
Meter=Image
SolidColor=0,255,255,255
W=30
H=30
X=0
Y=#Meter2Y#
DynamicVariables=1
dreaken667
Posts: 2
Joined: June 2nd, 2014, 9:59 pm

Re: Dynamic meter/measure creation with Lua and other though

Post by dreaken667 »

I hate to resurrect a long-dead post, but did you have any success with this? I'm attempting to do something similar and so far I haven't been able to accomplish the task completely. What I have so far is a combination of @Include to include a skin dynamically generated by a lua script through a FinishAction. I was just wondering if I was reinventing the wheel for no reason.
greatwolf
Posts: 8
Joined: May 15th, 2012, 3:11 am

Re: Dynamic meter/measure creation with Lua and other though

Post by greatwolf »

dreaken667 wrote:I hate to resurrect a long-dead post, but did you have any success with this? I'm attempting to do something similar and so far I haven't been able to accomplish the task completely. What I have so far is a combination of @Include to include a skin dynamically generated by a lua script through a FinishAction. I was just wondering if I was reinventing the wheel for no reason.
So it seems like I'm not the only one looking for this feature. Sadly, I haven't looked at this in a while -- I don't believe there's any new development on this since. I did entertain the idea of implementing this myself in C++ and lua since I do have knowledge of both languages.

Alas I never found the time to really dig into the rainmeter source and do this.
dreaken667
Posts: 2
Joined: June 2nd, 2014, 9:59 pm

Re: Dynamic meter/measure creation with Lua and other though

Post by dreaken667 »

I haven't found a way to do this automatically when the skin is loaded, but I did manage to get it working with the press of a button and some outside assistance. Here are the highlights:

Skin Code:

Code: Select all

[refresh]
Meter=Button
ButtonImage=images\refresh.png
ButtonCommand=[C:\Users\XXXXX\Documents\Rainmeter\Skins\scripts\updatetoolbox.vbs]
X=0
Y=0

...

@Include=data\systems.inc
updatetoolbox.vbs:

Code: Select all

Dim WshShell

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run "wget -qnv -O C:\Users\XXXXX\Documents\Rainmeter\Skins\data\systems.inc http://username:password@toolbox.net:81", 0
WScript.Sleep 2000
WshShell.Run """C:\Program Files\Rainmeter\Rainmeter.exe"" !Refresh", 0
PHP code at toolbox.net:

Code: Select all

<?php

function generateINI()
{

...
        $count = 1;
        $column = 0;
        $mysqli = new mysqli("localhost", "username", "password", "database");
        $query = "SELECT description, hostname, URL FROM table";
        $result = $mysqli->query($query);
        if ($result->num_rows > 0)
        {
                while ($row = $result->fetch_assoc())
                {
                        $system = $row['hostname'];
                        $style = ($count % 2 == 0)?"NormalEven":"NormalOdd";
                        $xpos = ($column * 250) + 10;
                        $ypos = ($count * 22) - ($column * 30 * 22) + 12;
                        echo "[sub" . $count . "]\r\nMeter=String\r\nMeterStyle=$style\r\nGroup=Systems\r\nHidden=1\r\nText=\"" . $row['description'] . "\"\r\nX=$xpos\r\nY=$ypos\r\nLeftMouseUpAction=!Execute [\"" . $row['URL'] . "\"][!SetOption SystemName String \"$system\"][!RainmeterToggleMeterGroup Systems][!RainmeterRedraw]\r\nMouseOverAction=!SetOption sub" . $count . " MeterStyle Hover\r\nMouseLeaveAction=!SetOption sub" . $count . " MeterStyle $style\r\n\r\n";
                        if ($count % 30 == 0)
                        {
                                $column++;
                        }
                        $count++;
                }
        }
        mysqli_close($mysqli);
}

generateINI();

?>
The basic gist is that the button runs the VBScript that fetches the web page which generates and updated INI that gets included in the skin, then the skin is refreshed. There is some superfluous stuff in the generated INI that I am using to group the meters so they can be toggled on and off, to split the meters into columns so they fit on the screen and to style the rows, making them more legible.

Now if I can figure out how to pass the value of a measure as a parameter to a ButtomCommand then I'll be golden.