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

Sum up variables from text file

General topics related to Rainmeter.
User avatar
rbriddickk84
Rainmeter Sage
Posts: 276
Joined: February 17th, 2014, 12:39 pm
Location: Hungary

Sum up variables from text file

Post by rbriddickk84 »

First i am really sorry, if i make a duplicate!
I was searching for over and over for solution. It is even possible in Rainmeter to search in a text file for a number, or some kind?
Here is what i want to do:

I made a preferences skin, where i can modify a lots of thigs, username, etc...
I've a text file, named temp.txt. In there are a lots of variables from "ChangedA" -to "ChangedK". Those vars are equal with "0".
I want to create a function or calc where i can check all those variables at once, if some of that is/are equal with "1". If is, i display a text that says: "You have unsaved contents".

Back in time there wasn't any solution for Arrays, not any tricks, and i am out of ideas how to manage that! I think i am going crazy on this :???:

Any help is much appretiated!
User avatar
jsmorley
Developer
Posts: 22790
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Sum up variables from text file

Post by jsmorley »

This sounds like it would be best to handle in a Lua script, where you can read the file and put the keys and values into a "table" (really an array) and do a for / next loop to check the contents. Then you can have the Lua script send bangs to Rainmeter to take whatever actions you desire in the skin.

I could probably be a bit more specific if I had some representative sample of what the temp.txt file looks like, and maybe some more details on how you see this working.
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: Sum up variables from text file

Post by moshi »

if i understood the question correctly the value of these variables is either 0 or 1?

one could use a calc measure:

Code: Select all

[NameOfTheMeasure]
Measure=Calc
Formula=#VariableA#+#VariableB#+#VariableC#+ ...
IfAboveValue=0
IfAboveAction=[!SetOption NameOfAMeter Text "Something has changed"]
or if the whole thing should be more specific, think in binaries:

Code: Select all

[NameOfTheMeasure]
Measure=Calc
Formula=(#VariableA#)+(#VariableB#*2)+(#VariableC#*4)+ ...
IfCondition=NameOfTheMeasure = 1
IfTrueAction=[!SetOption NameOfAMeter Text "A has changed"]
IfCondition2=NameOfTheMeasure = 2
IfTrueAction2=[!SetOption NameOfAMeter Text "B has changed"]
IfCondition3=NameOfTheMeasure = 3
IfTrueAction3=[!SetOption NameOfAMeter Text "A and B have changed"]
IfCondition4=NameOfTheMeasure = 4
IfTrueAction4=[!SetOption NameOfAMeter Text "C has changed"]
IfCondition5=NameOfTheMeasure = 5
IfTrueAction5=[!SetOption NameOfAMeter Text "A and C have changed"]
IfCondition6=NameOfTheMeasure = 6
IfTrueAction6=[!SetOption NameOfAMeter Text "B and C have changed"]
IfCondition7=NameOfTheMeasure = 7
IfTrueAction7=[!SetOption NameOfAMeter Text "A, B and C have changed"]
...
User avatar
jsmorley
Developer
Posts: 22790
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Sum up variables from text file

Post by jsmorley »

Yeah, I'd like to see more specifics about how the "configuration" tool works and the skin uses the values, and what the temp.txt file looks like. I'm not clear yet that a lot of complexity is really needed. If all you want to do is set some "dirty" flag that you detect, it may not be necessary to read in every element and look at each one, simply have the tool set some "dirty" variable to "1" when you change a value, and to "0" when you save. Hard to say without knowing more.

However, my gut reaction is that if there are dozens of elements being changed by the configuration tool, I'd be inclined to read the elements into an array in one Lua statement, and just loop through them, as you say, the approach would likely be to just aggregate the values and if you end up with a value greater than one, it's "dirty". Having to use WebParser and then dozens of child measures in the skin seems kinda brute force and bloated to me, but again, it will depend a bit on where we are starting from. You never know, with dynamic WebParser now, it might be possible to just use one main WebParser measure and one child measure that just loops through the StringIndexes based on a counter.
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: Sum up variables from text file

Post by moshi »

one could get even "dirtier" and just use the Quote plugin with a non-existing Separator and OnChangeAction.
that would probably be faster than the WebParser plugin.
User avatar
rbriddickk84
Rainmeter Sage
Posts: 276
Joined: February 17th, 2014, 12:39 pm
Location: Hungary

Re: Sum up variables from text file

Post by rbriddickk84 »

Yes, actually Moshi's answer seems really good for solution.

This is the "temp.txt" contents:

TchangedA=0
TchangedB=0
TchangedC=0
TchangedD=0
TchangedE=0
TchangedF=0
TchangedG=0
TchangedH=0
TchangedI=0
TchangedJ=0

These 10 variable changes to 1 if some of the corresponding data is changed.

Code: Select all

[NameArea]
Measure=Plugin
Plugin=InputText
SolidColor=72FFE3
FontColor=0,0,0,255
FontSize=14
X=139
Y=82
H=26
W=160
Command1=[!WriteKeyValue Variables TnameA "$UserInput$" #SKINSPATH#HiTech\@Resources\temp.txt]
Command2=[!WriteKeyValue Variables TchangedA 1 #SKINSPATH#HiTech\@Resources\temp.txt][!refresh]
The code above change the variables in the text file if modification happens.

I am not pro at programming, the basic structures, commands and syntax i understand, but don't know the capabilities of e.g. a "calc measure". I didn't knew that code of Moshi were allowed and working. Of course i don't want to create a pc eating skin with codes, obviously the sorter is better, but not always. :)

Thank you for your answers!!!!!

Oh sorry, almost fogot!
My code is a really mess right now, but i can sum up easier:
I have 10 names in the .ini, and that 10 variables in the temp.txt
Every area, where the user can change a name have an "undo" button.
So if you want to change the 4th name, on hit the enter the undo button appears and changes the 4th (TchangedD) in the temp.txt. But you can undo single changes.
User avatar
rbriddickk84
Rainmeter Sage
Posts: 276
Joined: February 17th, 2014, 12:39 pm
Location: Hungary

Re: Sum up variables from text file

Post by rbriddickk84 »

moshi wrote:if i understood the question correctly the value of these variables is either 0 or 1?

one could use a calc measure:

Code: Select all

[NameOfTheMeasure]
Measure=Calc
Formula=#VariableA#+#VariableB#+#VariableC#+ ...
IfAboveValue=0
IfAboveAction=[!SetOption NameOfAMeter Text "Something has changed"]
I tried this, of course this is great, how did i not think of this! :D

I manage to gather up a usable code from my whole code. Two txt file needed for this.

temp.txt contents:

Code: Select all

[Variables]
TchangedA=0
TchangedB=0
TchangedC=0
TchangedD=0
TchangedE=0
TchangedF=0
TchangedG=0
TchangedH=0
TchangedI=0
TchangedJ=0

TnameA=none
TnameB=none
TnameC=none
TnameD=none
TnameE=none
TnameF=none
TnameG=none
TnameH=none
TnameI=none
TnameJ=none
settings.txt contents:

Code: Select all

[Variables]
nameA=none
nameB=none
nameC=none
nameD=none
nameE=none
nameF=none
nameG=none
nameH=none
nameI=none
nameJ=none
The control.ini skin file contents:

Code: Select all

[Variables]
@include=..\@Resources\settings.txt
@include2=..\@Resources\temp.txt

[MeasureEqualsA]
Measure=Calc
Formula=#TchangedA# = 1 ? 0 : 1
ifEqualValue=0
ifEqualAction=[!ShowMeterGroup btnA]
ifEqualValue=1
ifEqualAction=[!HideMeterGroup btnA]

[NameA]
Measure=Plugin
Plugin=InputText
SolidColor=72FFE3
FontColor=0,0,0
FontSize=14
X=139
Y=82
H=26
W=160
Command1=[!WriteKeyValue Variables TnameA "$UserInput$" #SKINSPATH#HiTech\@Resources\temp.txt]
Command2=[!WriteKeyValue Variables TchangedA 1 #SKINSPATH#HiTech\@Resources\temp.txt][!refresh]

[NameChangeA]
Meter=String
X=140
Y=80
W=134
H=30
ClipString=1
FontSize=20
Text=#TnameA#
LeftMouseDownAction=!CommandMeasure "NameA" "ExecuteBatch 1-2"

[NameACancelBtn]
Meter=Button
ButtonImage=..\@Resources\undo.png
ImageTint=255,255,255
X=340
Y=83
LeftMouseDownAction=[!WriteKeyValue Variables "TnameA" "#nameA#" "#SKINSPATH#HiTech\@Resources\temp.txt"]
LeftMouseUpAction=[!WriteKeyValue Variables TchangedA 0 #SKINSPATH#HiTech\@Resources\temp.txt][!refresh]
Group=btnA
Hidden=1

[IsThereChange]
Measure=Calc
Formula=#TchangedA#+#TchangedB#+#TchangedC#+#TchangedD#+#TchangedE#+#TchangedF#+#TchangedG#+#TchangedH#+#TchangedI#+#TchangedJ#
ifEqualValue=0
ifEqualAction=[!HideMeterGroup pmod]
ifAboveValue=0
ifAboveAction=[!ShowMeterGroup pmod]

[PmodText]
Meter=String
StringAlign=Center
Text=There are unsaved modifications! Please save or cancel!
FontSize=12
X=200
Y=52
FontColor=200,200,200,
DynamicVariables=1
AntiAlias=1
Group=pmod
Hidden=1
I have a save button which is copying from temp.txt to settings.txt the name datas, but not included here. Sorry for that!

Perfectly worked, million thanks for the help!!!!! :thumbup:
User avatar
rbriddickk84
Rainmeter Sage
Posts: 276
Joined: February 17th, 2014, 12:39 pm
Location: Hungary

Re: Sum up variables from text file

Post by rbriddickk84 »

Is there possible to check a String instead of Number?
So if i put a sentence in the text file, and i want to find a word from it, is there a way to find it with simply Rainmeter, or must i use Lua for that?
I am thinking about a password protection for this preferences skin.
User avatar
jsmorley
Developer
Posts: 22790
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Sum up variables from text file

Post by jsmorley »

rbriddickk84 wrote:Is there possible to check a String instead of Number?
So if i put a sentence in the text file, and i want to find a word from it, is there a way to find it with simply Rainmeter, or must i use Lua for that?
I am thinking about a password protection for this preferences skin.
http://docs.rainmeter.net/manual-beta/measures/general-options/ifmatchactions

http://rainmeter.net/forum/viewtopic.php?f=113&t=17421

Requires the latest 3.1 beta version of Rainmeter.

I will caution that at best any kind of password protection in Rainmeter is strictly a "locks are to keep honest people honest" level of security. Rainmeter just cannot be made at all secure in any real way.
User avatar
rbriddickk84
Rainmeter Sage
Posts: 276
Joined: February 17th, 2014, 12:39 pm
Location: Hungary

Re: Sum up variables from text file

Post by rbriddickk84 »

jsmorley wrote: http://docs.rainmeter.net/manual-beta/measures/general-options/ifmatchactions

http://rainmeter.net/forum/viewtopic.php?f=113&t=17421

Requires the latest 3.1 beta version of Rainmeter.

I will caution that at best any kind of password protection in Rainmeter is strictly a "locks are to keep honest people honest" level of security. Rainmeter just cannot be made at all secure in any real way.
Yes :) i know that Rainmeter is not the best for protect files, but it's good against little kids, who maybe click accidentally on the preferences button. :)
Thank you very much for you advice, but i will wait for the stabil 3.1v. ;) I'm just superstitious :)