It is currently April 18th, 2024, 9:54 am

Thinking about an addon...

Share and get help with Plugins and Addons
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Thinking about an addon...

Post by jsmorley »

I was considering a very basic string handling addon (AutoIt) that could be !Executed. The basics are something like this:

Functions:
Regx
equal
contains
upper
lower
proper

If we assume [MeasureOne] returns "It is cold"

Calling:

Rainstring.exe "ConfigName" "Variable to set" "Function Name" "User Input to Function" "Rainmeter Input to Function"

Examples:

!Execute ["RainString.exe" "#CURRENTCONFIG#" "VarName" "Regx" "(?siU)It is (.*)" "[MeasureOne]"]
Sets $Result to "cold"

!Execute ["RainString.exe" "#CURRENTCONFIG#" "VarName" "equal" "It is cold" "[MeasureOne]"]
Sets $Result to "1"

!Execute ["RainString.exe" "#CURRENTCONFIG#" "VarName" "contains" "cold" "[MeasureOne]"]
Sets $Result to "1"

!Execute ["RainString.exe" "#CURRENTCONFIG#" "VarName" "upper" "" "[MeasureOne]"]
Sets $Result to "IT IS COLD"

In the case of "upper", "lower" and "proper" "User Input to Function" is null. In any case "Rainmeter Input to Function" can be a [MeasureName], a #Variable# or a literal.

Program does processing and then uses ShellExecute(Rainmeter.exe !RainmeterSetVariable VarName $Result $ConfigName) This will set the value of "VarName" initialized in the [Variables] section of the skin to $Result. Normal rules would apply... You would need DynamicVariables=1 on any measure or meter using the variable, and it won't work with plugins.

"ConfigName" doesn't HAVE to be the calling skin... This could be used to have one skin use a string comparison to set a variable in a different running skin. I have not tested yet, but I suspect that if "ConfigName" is "" (null) it will set the defined variable in all running skins.
RainString.zip
User avatar
Alex2539
Rainmeter Sage
Posts: 642
Joined: July 19th, 2009, 5:59 am
Location: Montreal, QC, Canada

Re: Thinking about an addon...

Post by Alex2539 »

Ideally, I would prefer it if the functionality were integrated directly into Rainmeter (as a new measure or perhaps an addon to Calc), but this isn't a bad solution at all. In fact, since it would be an external program, it would be fully compatible with Rainmeter 1.0 and onwards, without the need to upgrade or mess around with the beta releases.

My only question is how would the RegEx deal with multiple saved strings? That is to say, if you had something like: "The time is 12:34" and you used "The time is (.*):(.*)" as your RegEx, how would it deal with the second one? To me it seems like it would set $Result to "12" and ignore the rest. That may be all good and well, but it's a little bit counter intuitive to those who are used to how WebParser deals with things: you set the RegEx once and then just deal with the string indexes.
ImageImageImageImage
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Thinking about an addon...

Post by jsmorley »

Alex2539 wrote:Ideally, I would prefer it if the functionality were integrated directly into Rainmeter (as a new measure or perhaps an addon to Calc), but this isn't a bad solution at all. In fact, since it would be an external program, it would be fully compatible with Rainmeter 1.0 and onwards, without the need to upgrade or mess around with the beta releases.

My only question is how would the RegEx deal with multiple saved strings? That is to say, if you had something like: "The time is 12:34" and you used "The time is (.*):(.*)" as your RegEx, how would it deal with the second one? To me it seems like it would set $Result to "12" and ignore the rest. That may be all good and well, but it's a little bit counter intuitive to those who are used to how WebParser deals with things: you set the RegEx once and then just deal with the string indexes.
I would also like it internal, and there is someone (who escapes me at the moment) who is working on integrating a python string library with Rainmeter. I just kinda wanted something simple "for now" as I know that is a big effort and I don't have any idea on the timeline, or if perhaps the person has run into some issues.

As to the RegExp stuff, this is a very simple "one out one in" deal. It isn't meant to do what WebParser can do, and has no capability to do more than return the FIRST captured result. I used "regular expressions" instead of a simple "substring" routine as it has much more powerfull capabilities in finding and returning a "part" of a string based on matching a search, but it won't return an array of stringindexes and all that. I may not call the function "RegExp" so it isn't confused with WebParser's capabilities and usage. Maybe "RX" or "Regular".

It is meant for extracting one substring from a string and returning it so you can, for instance, use Perfmon to get the CPU measure for a single core, and when it returns "356 k" you can use this to strip off the " k" and use the result in a Calc statement. You can't easily today. It also could be used to see if a return of the "conditions" from a weather webparser measure contains the word "Sunny" for instance, and then take some action based on that.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Thinking about an addon...

Post by jsmorley »

First test...

Here is a skin which will test the "contains" function. It will check to see if a particular user (defined in variables) is currently logged onto our forums.

Code: Select all

[Rainmeter]
Update=1000

[Variables]
PersonToTrack=JSMorley
VarText=Disconnected
Connected=0

[MeasureForums]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=http://Rainmeter.net/forum
RegExp="(?siU)Registered users:(.*)</td>.*"
UpdateRate=30
StringIndex=1
FinishAction=!Execute ["#ADDONSPATH#RainString\RainString.exe" "#CURRENTCONFIG#" "Connected" "contains" "#PersonToTrack#" "[MeasureForums]"]

[ConnectedCalc]
Measure=Calc
DynamicVariables=1
Formula=#Connected#
IfEqualValue=0
IfEqualAction=!RainmeterSetVariable VarText Disconnected
IfAboveValue=0
IfAboveAction=!RainmeterSetVariable VarText Connected

[DisplayMeter]
Meter=String
FontFace=Trebuchet MS
FontSize=50
FontColor=255,255,255,255
DynamicVariables=1
W=700
W=100
Text=#PersonToTrack# is #VarText#
You will also need the RainString.exe executable, and it MUST be in Rainmeter\Addons\RainString

So just change the variable "PersonToTrack" to your name and open and close the forums in your browswer. Checks every 30 seconds... It actually tests faster if you log out and log in to the forums. They take up to 5 minutes to see you as "gone" if you just leave the site.

P.S. "contains" is never case sensitive.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Thinking about an addon...

Post by jsmorley »

I have everything working except "regular expressions" and it all works pretty well.

One thing I will say though is that we really should look at building this capability into Rainmeter as a parameter to existing measures or a new Measure= type. The functions are really simple 2 or 3 lines of code each and are all built into C++ except RegExp, which itself is just a simple call to a library that is already there. I mean it should be trivial to have "Upper=1", "Lower=1" "Proper=1" on any measure returning string values, including plugins. The "contains" and "equal" functions would probably have to be a new Measure=type which returns "0" or "1" so it can be used in a Calc.

[MeasureContains]
Measure=ContainsString
MeasureName=MeasureOne
SearchString="Moo Cow!"
CaseSensitive=0

[ResultCalc]
Measure=Calc
Formula=MeasureContains
IfEqualValue=1
IfEqualAction=!Execute [!RainmeterBangARang]

The reason I ask that maybe Spx or Mattking take a look at this is that calling an external program is all well and good, but if the return value you are acting on is something that runs really often, like TIME or CPU or something, the constant shelling out to the OS does have a CPU impact that is a high price for such a simple function.

I think that if we could get these working, inlcuding a simple RegExp that returns a single "substring" of a string, this could be the "big ticket item" for 1.2...
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Thinking about an addon...

Post by jsmorley »

One more test before I start thinking about how to package this for the public...

Grab this .zip. Put the skin folder in the obvious place and be SURE to put the entire \RainString folder in Rainmeter\Addons.

Lets you define a list of 10 software packages you want to "watch" and be alerted when there is a new version on FileHippo.com. Probably obvious, but the ones with "new" versions on FileHippo will be green, and clicking them goes to the package on the site.

No costmetics to speak of in this, it is mostly to test the technology. I'll toss it out in the public at some point and let folks pretty it up.
2-1-2010 1-03-45 PM.png
hippoalerts.zip
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Thinking about an addon...

Post by jsmorley »

Ok, here is a simple test of the "regx" (Regular Expression) function.

Code: Select all

[Rainmeter]
Author=Jeffrey Morley
Update=1000

[Variables]
FontFace=Trebuchet MS
FontSize=15
FontColor=255,255,255,255
StringStyle=BOLD
TestString=Hello World
ResultString1=""
ResultString2=""

[ParseIt]
Measure=Calc
Formula=Counter % 32
DynamicVariables=1
IfEqualValue=30
IfEqualAction=!Execute ["#ADDONSPATH#RainString\RainString.exe" "#CURRENTCONFIG#" "ResultString1" "regx" "(.*) " "#TestString#"]["#ADDONSPATH#RainString\RainString.exe" "#CURRENTCONFIG#" "ResultString2" "regx" " (.*)" "#TestString#"]

[MeterTestString]
Meter=String
FontFace=#FontFace#
FontSize=#FontSize#
FontColor=#FontColor#
StringStyle=#StringStyle#
AntiAlias=1
W=250
H=25
X=0
Y=0
Text=Lets split #TestString#

[MeterHello]
Meter=String
FontFace=#FontFace#
FontSize=#FontSize#
FontColor=#FontColor#
StringStyle=#StringStyle#
AntiAlias=1
DynamicVariables=1
W=210
H=25
X=0
Y=25r
Text=#ResultString1#

[MeterWorld]
Meter=String
FontFace=#FontFace#
FontSize=#FontSize#
FontColor=#FontColor#
StringStyle=#StringStyle#
AntiAlias=1
DynamicVariables=1
W=210
H=25
X=0
Y=25r
Text=#ResultString2#
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Thinking about an addon...

Post by jsmorley »

Folks are welcome to give this a go and let me know if it works ok for them.