It is currently May 6th, 2024, 12:44 pm

RegExp Problems

Get help with creating, editing & fixing problems with skins
MuffMan
Posts: 3
Joined: September 27th, 2011, 3:55 am

RegExp Problems

Post by MuffMan »

Hi all,

I'm very new to coding in Rainmeter, and I'm having some trouble with RegExp. From the log file, my expression works fine, and I get the values that I'm looking for stored into StringIndex. The problem comes in that my meters aren't displaying the contents of StringIndex when called, and instead just display nothing. Just to see what would happen, I added the line

Code: Select all

Substitute="":"Test"
to my StringIndex=1 measure and now when I refresh the skin, the alternate text is displayed and then replaced by the original string I was trying to get to print before. Only problem now is that it's all grayed out and partially obscured as if something black was drawn on top of it.

Like I said, I'm very new to all of this, so I feel like I'm making a simple mistake here, I just can't seem to find it. Does anyone have any advice?

Thanks.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: RegExp Problems

Post by jsmorley »

if you can post the skin code in tags, we can certainly take a look at it.
MuffMan
Posts: 3
Joined: September 27th, 2011, 3:55 am

Re: RegExp Problems

Post by MuffMan »

Ah, should have done that before. This is all I have at the moment:

Code: Select all

;Get printer status

[Variables]
fontName=Trebuchet MS
textSize=8
colorBar=235,170,0,255
colorText=255,255,255,205

;========================

[measurePrinter]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1500
Url=http://studentaffairs.case.edu/services/print2here/
RegExp="(?siU)<tr><td>Print2Carlton</td><td align="right"><font color="(.*)">(.*)</span>.*<tr><td>Print2Fribley</td><td align="right"><font color="(.*)">(.*)</span>"
StringIndex=1
Substitute="":"Test"

Debug=2


[measurePrinter2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[measurePrinter]
StringIndex=2


;==========Everything Below Taken from other skin to test the meter properties


[styleTitle]
StringAlign=CENTER
StringCase=UPPER
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,50
FontColor=#colorText#
FontFace=#fontName#
FontSize=10
AntiAlias=1
ClipString=1

[meterTitle]
Meter=STRING
MeterStyle=styleTitle
MeasureName=measurePrinter
X=100
Y=12
W=190
H=18
Text="%1"
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: RegExp Problems

Post by jsmorley »

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]
fontName=Trebuchet MS
textSize=8
colorBar=235,170,0,255
colorText=255,255,255,205

[measurePrinter]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1500
Url=http://studentaffairs.case.edu/services/print2here/
RegExp="(?siU)<tr><td>Print2Carlton</td><td align="right"><font color="(.*)">(.*)</span>.*<tr><td>Print2Fribley</td><td align="right"><font color="(.*)">(.*)</span>"

[measurePrinter1Name]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[measurePrinter]
StringIndex=1

[measurePrinter1Status]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[measurePrinter]
StringIndex=2

[measurePrinter2Name]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[measurePrinter]
StringIndex=3

[measurePrinter2Status]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[measurePrinter]
StringIndex=4

[styleTitle]
StringAlign=CENTER
StringCase=UPPER
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,50
FontColor=#colorText#
FontFace=#fontName#
FontSize=10
AntiAlias=1

[MeterPrinter1Name]
Meter=STRING
MeterStyle=styleTitle
MeasureName=measurePrinter1Name
W=100
H=15
X=50
Y=0

[MeterPrinter1Status]
Meter=STRING
MeterStyle=styleTitle
MeasureName=measurePrinter1Status
W=100
H=15
X=50
Y=R

[MeterPrinter2Name]
Meter=STRING
MeterStyle=styleTitle
MeasureName=measurePrinter2Name
W=100
H=15
X=130
Y=0

[MeterPrinter2Status]
Meter=STRING
MeterStyle=styleTitle
MeasureName=measurePrinter2Status
W=100
H=15
X=130
Y=R
The key thing you were stumbling on is how "parent" and "child" WebParser meters work with StringIndexes.

What you are doing in the first "parent" WebParser measure, [measurePrinter], is to "capture" four different things from the HTML stream. It will put them in four StringIndexes, 1-4. Your RegExp works just fine, so that is a great start.

Now you want to use four different "child" WebParser measures, to pick off each of those StringIndexes one at a time. Note that the "child" measure reference the "parent" as the URL= setting. Then you can reference those four new measures in any meters you like to display the results.

So I changed things so you are getting the right results in the right measures. Then I just whacked out some meters to display the text. You will no doubt want to mess with the cosmetics and positioning and such, but this should get you started.

Be careful with StringAlign=Center and StringAlign=Right. They require both a W= (width) that is big enough to hold the entire string, and then an X= (left to right position) that is where you want to position it. In a lot of cases folks will use for instance W=100 and X=50, which you might guess will center it on the 50th pixel, half to the left and half to the right. StringAlign=Right works much the same way, but you need to specify where the X= should be, and it will display "back" from there. In either case you need a W= set so there is enough room to display things. My point is that if you for instance use X=0 and StringAlign=Center, half the text will just not show at all. Same with StringAlign=Right. X=0 and StringAlign=Right will result in no text at all. It's all on the floor off the left of your screen...

9-27-2011 12-43-00 AM.jpg
You do not have the required permissions to view the files attached to this post.
MuffMan
Posts: 3
Joined: September 27th, 2011, 3:55 am

Re: RegExp Problems

Post by MuffMan »

Thanks a bundle! Based on this, am I to understand that you have to create a WebParser plugin measure for each string index that you captured before attempting to use any of the values in a meter?
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: RegExp Problems

Post by jsmorley »

MuffMan wrote:Thanks a bundle! Based on this, am I to understand that you have to create a WebParser plugin measure for each string index that you captured before attempting to use any of the values in a meter?
Correct. You capture as many StringIndexes as you want (well, up to 99) in the parent measure with (.*) then you pick them off one at a time in child measures so you get one "result" per measure. Then you reference those child measures in meters with MeasureName=xxxx and you are off and running.

The exception to this is if you only have ONE capture (.*) in the parent measure. Then you can just put StringIndex=1 on it and use it directly.
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: RegExp Problems

Post by MerlinTheRed »

I have a weather skin that uses WebParser to get the weather data. In this skin the first StringIndex is the location and I grab it directly from the parent measure with StringIndex=1. The other measures have then set StringIndex=2 etc. From what you're saying, it somehow seems that this should not work, but it does for me.
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: RegExp Problems

Post by jsmorley »

MerlinTheRed wrote:I have a weather skin that uses WebParser to get the weather data. In this skin the first StringIndex is the location and I grab it directly from the parent measure with StringIndex=1. The other measures have then set StringIndex=2 etc. From what you're saying, it somehow seems that this should not work, but it does for me.
Yes, that will in fact work that way. When I am explaining how the WebParser Parent/Child thing works though, I find it easier to explain, and at the end of the day an easier to understand skin, if I use the "the parent measure collects all the StringIndexes, and the child measures use them" approach.