It is currently October 14th, 2024, 11:14 am

Text editor skin?

Get help with creating, editing & fixing problems with skins
ItsJustRyan
Posts: 81
Joined: October 25th, 2019, 1:20 am

Text editor skin?

Post by ItsJustRyan »

Hi!

I wanted to make a rainmeter skin which can read for instance, a .txt file, and be able to also write to the file as if it were the Windows notepad app, probably when a button to save is clicked. I saw in the documentation on some lua functions that can read and write to/from files. I figured to do this (correct me if I'm wrong :P), I would use the read function to get the txt file, save that to a variable and display it in a text meter, and to use the write function to act as a save function when a "save" button is clicked. However, I am not sure how to make it so you can click around the "text editor" and edit text, a bit like a word editor.

Thanks!
User avatar
Alloutofmercy
Posts: 142
Joined: November 17th, 2021, 5:51 am

Re: Text editor skin?

Post by Alloutofmercy »

This sounds like a great idea !
BOOTY
User avatar
Yincognito
Rainmeter Sage
Posts: 8451
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Text editor skin?

Post by Yincognito »

ItsJustRyan wrote: February 6th, 2022, 4:03 am Hi!

I wanted to make a rainmeter skin which can read for instance, a .txt file, and be able to also write to the file as if it were the Windows notepad app, probably when a button to save is clicked. I saw in the documentation on some lua functions that can read and write to/from files. I figured to do this (correct me if I'm wrong :P), I would use the read function to get the txt file, save that to a variable and display it in a text meter, and to use the write function to act as a save function when a "save" button is clicked. However, I am not sure how to make it so you can click around the "text editor" and edit text, a bit like a word editor.

Thanks!
Actually, you can do this not only by using Lua, but also by using the !WriteKeyValue bang, the only difference would be that the latter would be limited to a Key=Value standard INI file format, so it might not suit your described purpose.

That being said, yes, the steps you mentioned are mostly correct when it comes to Lua. To make it possible for the read text you display in the meter to be editable like in a text editor, all you need to do is use an InputText measure (you'll find info on that in the InputText plugin section of the Rainmeter manual) and place it precisely "over" the meter you use to display the file text.

Obviously, things will have to be adjusted further in order to get what you want and there are a couple of minor "quirks" to keep in mind when using InputText measures, but in terms of basic steps to achieve your goal, it's entirely possible. Personally, I even made a save game "editor" on those principles, so I know for a fact how it works (and what are the few limitations if it).
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
ItsJustRyan
Posts: 81
Joined: October 25th, 2019, 1:20 am

Re: Text editor skin?

Post by ItsJustRyan »

Yincognito wrote: February 7th, 2022, 9:51 am Actually, you can do this not only by using Lua, but also by using the !WriteKeyValue bang, the only difference would be that the latter would be limited to a Key=Value standard INI file format, so it might not suit your described purpose.

That being said, yes, the steps you mentioned are mostly correct when it comes to Lua. To make it possible for the read text you display in the meter to be editable like in a text editor, all you need to do is use an InputText measure (you'll find info on that in the InputText plugin section of the Rainmeter manual) and place it precisely "over" the meter you use to display the file text.

Obviously, things will have to be adjusted further in order to get what you want and there are a couple of minor "quirks" to keep in mind when using InputText measures, but in terms of basic steps to achieve your goal, it's entirely possible. Personally, I even made a save game "editor" on those principles, so I know for a fact how it works (and what are the few limitations if it).
It doesn't have to be saved as a text file, just needs to be saved somewhere so that it remains after rainmeter or the device is turned off. Would that mean the !WriteKeyValue bang you suggested could work or would it still not retain the info?
User avatar
Yincognito
Rainmeter Sage
Posts: 8451
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Text editor skin?

Post by Yincognito »

ItsJustRyan wrote: February 8th, 2022, 11:26 am It doesn't have to be saved as a text file, just needs to be saved somewhere so that it remains after rainmeter or the device is turned off. Would that mean the !WriteKeyValue bang you suggested could work or would it still not retain the info?
It would retain the info for sure, it's just that it would be in an .INI / .INC format, like (KeyN and ValueN can be anything, below it's just how it would look like):

Code: Select all

Key0=Value0
Key1=Value1
Key2=Value2
...
...
...
It depends on your actual goal to determine if such a format for storing information is suited for your case. Think of being able to save some data, just that you're limited to save it in an XML, JSON or some other particular text format - it's more or less the same. Oh, and the file would need to exist prior to saving, when it comes to the !WriteKeyValue, meaning you cannot create a new, previously non-existant, file, like you'd be able to do with Lua.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
ItsJustRyan
Posts: 81
Joined: October 25th, 2019, 1:20 am

Re: Text editor skin?

Post by ItsJustRyan »

Yincognito wrote: February 8th, 2022, 1:37 pm It would retain the info for sure, it's just that it would be in an .INI / .INC format, like (KeyN and ValueN can be anything, below it's just how it would look like):

Code: Select all

Key0=Value0
Key1=Value1
Key2=Value2
...
...
...
It depends on your actual goal to determine if such a format for storing information is suited for your case. Think of being able to save some data, just that you're limited to save it in an XML, JSON or some other particular text format - it's more or less the same. Oh, and the file would need to exist prior to saving, when it comes to the !WriteKeyValue, meaning you cannot create a new, previously non-existant, file, like you'd be able to do with Lua.
Currently this is what I got: A button that allows you to enter text (with multi-line functionality) which it can save to a variable and correctly display it after. However, as can be seen on the second box on the right the write key value doesnt seem to work. however, it does sometimes randomly work when i refresh all in rainmeter. Otherwise it just remains as it is. What am I doing wrong?

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[Variables]
CurrentInput="Blank File"
Store=Blank File

[MeterButton]
Meter=String
FontSize=12
FontColor=255,156,0
SolidColor=100,100,100,0
StringStyle=Bold
Padding=5,5,5,5
AntiAlias=1
Text=X
LeftMouseUpAction=[!CommandMeasure MeasureInput "ExecuteBatch 1-2"][!WriteKeyValue Variables Store "#CurrentInput#"][!Redraw]

[MeterInputLabel]
Meter=String
X=25
Y=0r
W=170
FontSize=12
FontColor=255,156,0
SolidColor=100,100,100,50
Padding=5,6,5,4
StringStyle=Italic
AntiAlias=1
DynamicVariables=1
Text=#CurrentInput#

[MeterPerma]
Meter=String
X=210
Y=0r
W=170
;H=18
FontSize=12
FontColor=255,156,0
SolidColor=100,100,100,50
Padding=5,6,5,4
StringStyle=Italic
AntiAlias=1
DynamicVariables=1
Text=#Store#

[MeasureInput]
Measure=Plugin
Plugin=InputText
X=27
Y=4
W=171
H=20
FontSize=12
FontColor=255,255,255,255
SolidColor=47,47,47,255
AntiAlias=1
FocusDismiss=1
DefaultValue=#CurrentInput#
OnDismissAction=[!SetVariable CurrentInput ""]
Command1=[!SetVariable CurrentInput "$UserInput$"][!UpdateMeter *][!Redraw]

User avatar
Active Colors
Moderator
Posts: 1318
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

Re: Text editor skin?

Post by Active Colors »

ItsJustRyan wrote: February 10th, 2022, 12:21 pm Currently this is what I got: A button that allows you to enter text (with multi-line functionality) which it can save to a variable and correctly display it after. However, as can be seen on the second box on the right the write key value doesnt seem to work. however, it does sometimes randomly work when i refresh all in rainmeter. Otherwise it just remains as it is. What am I doing wrong?

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[Variables]
CurrentInput="Blank File"
Store=Blank File

[MeterButton]
Meter=String
FontSize=12
FontColor=255,156,0
SolidColor=100,100,100,0
StringStyle=Bold
Padding=5,5,5,5
AntiAlias=1
Text=X
LeftMouseUpAction=[!CommandMeasure MeasureInput "ExecuteBatch 1-2"][!WriteKeyValue Variables Store "#CurrentInput#"][!Redraw]

[MeterInputLabel]
Meter=String
X=25
Y=0r
W=170
FontSize=12
FontColor=255,156,0
SolidColor=100,100,100,50
Padding=5,6,5,4
StringStyle=Italic
AntiAlias=1
DynamicVariables=1
Text=#CurrentInput#

[MeterPerma]
Meter=String
X=210
Y=0r
W=170
;H=18
FontSize=12
FontColor=255,156,0
SolidColor=100,100,100,50
Padding=5,6,5,4
StringStyle=Italic
AntiAlias=1
DynamicVariables=1
Text=#Store#

[MeasureInput]
Measure=Plugin
Plugin=InputText
X=27
Y=4
W=171
H=20
FontSize=12
FontColor=255,255,255,255
SolidColor=47,47,47,255
AntiAlias=1
FocusDismiss=1
DefaultValue=#CurrentInput#
OnDismissAction=[!SetVariable CurrentInput ""]
Command1=[!SetVariable CurrentInput "$UserInput$"][!UpdateMeter *][!Redraw]

I am not sure about your use case because I got confused with some of the logic. I just changed slightly some parts of the code to show you how to reflect the change and I fixed some part because I thought this was some logical issue:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[Variables]
CurrentInput=Hey

[MeterButton]
Meter=String
FontSize=12
FontColor=255,156,0
SolidColor=100,100,100,0
StringStyle=Bold
Padding=5,5,5,5
AntiAlias=1
Text=X
LeftMouseUpAction=[!CommandMeasure MeasureInput "ExecuteBatch 1"][!Redraw]

[MeterInputLabel]
Meter=String
X=25
Y=0r
W=170
FontSize=12
FontColor=255,156,0
SolidColor=100,100,100,50
Padding=5,6,5,4
StringStyle=Italic
AntiAlias=1
DynamicVariables=1
Text=#CurrentInput#

[MeasureInput]
Measure=Plugin
Plugin=InputText
X=27
Y=4
W=171
H=20
FontSize=12
FontColor=255,255,255,255
SolidColor=47,47,47,255
AntiAlias=1
FocusDismiss=1
DefaultValue=#CurrentInput#
Command1=[!WriteKeyValue Variables CurrentInput "$UserInput$"][!SetVariable CurrentInput "[MeasureInput]"][!UpdateMeter *][!Redraw]
User avatar
Yincognito
Rainmeter Sage
Posts: 8451
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Text editor skin?

Post by Yincognito »

ItsJustRyan wrote: February 10th, 2022, 12:21 pmWhat am I doing wrong?
Sorry for the delay, I was busy with some other stuff as well. This should do what I think you wanted in the above code:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[Variables]
CurrentInput="Blank File"
Store=iiiiiiiiiiiiii

[MeterButton]
Meter=String
FontSize=12
FontColor=255,156,0
SolidColor=100,100,100,0
StringStyle=Bold
Padding=5,5,5,5
AntiAlias=1
Text=X
LeftMouseUpAction=[!CommandMeasure MeasureInput "ExecuteBatch 1"]

[MeterInputLabel]
Meter=String
X=25
Y=0r
W=170
FontSize=12
FontColor=255,156,0
SolidColor=100,100,100,50
Padding=5,6,5,4
StringStyle=Italic
AntiAlias=1
DynamicVariables=1
Text=#CurrentInput#

[MeterPerma]
Meter=String
X=210
Y=0r
W=170
;H=18
FontSize=12
FontColor=255,156,0
SolidColor=100,100,100,50
Padding=5,6,5,4
StringStyle=Italic
AntiAlias=1
DynamicVariables=1
Text=#Store#

[MeasureInput]
Measure=Plugin
Plugin=InputText
X=27
Y=4
W=171
H=20
FontSize=12
FontColor=255,255,255,255
SolidColor=47,47,47,255
AntiAlias=1
FocusDismiss=1
DefaultValue=#CurrentInput#
Command1=[!SetVariable CurrentInput "$UserInput$"][!SetVariable Store "[MeasureInput]"][!WriteKeyValue Variables Store "[MeasureInput]"][!UpdateMeter *][!Redraw]
DynamicVariables=1
I don't think this solves your original problem though. First, what you do in the above code is write things to the SAME file. Sure, this can be changed to write to some other existing INI/INC file, but it won't be "multiline" the way you think, since each line would basically be an option that can be overwritten, and that ends as soon as the newline character is encountered...

EDIT: ActiveColors beat me to it, but there are some differences between the codes.
EDIT2: What I'm trying to say is that if you actually want a "text file editor" where you can freely create, edit and save stuff with real multiline support, the Lua route is what you want, while the WritekeyValue route works for other cases. As I said, it depends on what you actually want from this.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
ItsJustRyan
Posts: 81
Joined: October 25th, 2019, 1:20 am

Re: Text editor skin?

Post by ItsJustRyan »

Yincognito wrote: February 10th, 2022, 1:20 pm Sorry for the delay, I was busy with some other stuff as well. This should do what I think you wanted in the above code:

I don't think this solves your original problem though. First, what you do in the above code is write things to the SAME file. Sure, this can be changed to write to some other existing INI/INC file, but it won't be "multiline" the way you think, since each line would basically be an option that can be overwritten, and that ends as soon as the newline character is encountered...

EDIT: ActiveColors beat me to it, but there are some differences between the codes.
EDIT2: What I'm trying to say is that if you actually want a "text file editor" where you can freely create, edit and save stuff with real multiline support, the Lua route is what you want, while the WritekeyValue route works for other cases. As I said, it depends on what you actually want from this.
Oh yeah it didnt work the way I thought it worked. The current code makes it so that I would have to rewrite everything I wanted it to say each time I want to change something, which isn't what I had intended. Still learned a little something for future skins with !WriteKeyValue :P
User avatar
Yincognito
Rainmeter Sage
Posts: 8451
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Text editor skin?

Post by Yincognito »

ItsJustRyan wrote: February 10th, 2022, 1:43 pm Oh yeah it didnt work the way I thought it worked. The current code makes it so that I would have to rewrite everything I wanted it to say each time I want to change something, which isn't what I had intended. Still learned a little something for future skins with !WriteKeyValue :P
Which begs the question ... what you intended? :confused:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth