XWidgetSoft Forum

XWidget & XLaunchpad , Desktop customization
It is currently May 2nd, 2025, 4:39 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: November 23rd, 2012, 6:41 am 
Offline
User avatar

Joined: June 10th, 2012, 5:57 am
Posts: 313
Some widgets support user defined settings, such as slider shadow style by 9yomo . We should save these user defined settings in external file and reload them when XWidget restarts or widget reloads.

There are 2 ways to save user defined settings, one way is setvalue() and getvalue() functions , the other way is setinivalue() and getinivalue().
Before starting learning them, please read post managing themes. It’s helpful.

What’s the difference between these 2 ways?
  • The function setvalue() will save variables in the theme file "theme.xwt". If one widget is closed, the variables saved before will be deleted. Function Getvalue() could not get these variables again.
  • The function setinivalue() will save variables in an external ini file. Even if you close the widget, these variables would not be lost. Function Getinivalue() is able to get them again every time you load the widget.

The knowledge of form of ini file is required. The form is shown below.
Attachment:
iniform.jpg
iniform.jpg [ 34.31 KiB | Viewed 12518 times ]


Setvalue() & Getvalue()
Code:
Setvalue("keyName","keyValue");
Savevalue();

theme.xwt file is a kind of ini file indeed. Setvalue() saves variable from widget to memory and savevalue() saves variable from memory to disk. They must be used together.

Code:
Getvalue("keyName","defaultValue");

Getvalue() is written in the function widgetOnLoad() generally. If you write
Code:
var num=Getvalue("uptime",18);

and there is not a keyname called "uptime" in theme.xwt, Getvalue() returns 18. Hence, num=18.

Setinivalue & Getinivalue
Code:
Setinivalue("inifile path","section","keyName","keyValue");

"inifile path" is the full path of the ini file to which you want to save variable, such as
Code:
"C:\\Program Files\\XWidget\\uptime.ini"

or
Code:
widgetpath+"uptime.ini"

Please use double '\' in the path. widgetpath is a variable provided by XWidget that presents the path of the widget.

Code:
Getinivalue("inifile path","section","keyName","defaultValue");


Examples
  • Saving font.fill.color
    Code:
    function text1OnClick()
    {
      Setvalue("fontcolor",text1.font.fill.color);
      Savevalue();
    }

    function widgetOnLoad()
    {
      text1.font.fill.color=Getvalue("fontcolor",rgba(0,0,0,255));
    }


    Code:
    function text1OnClick()
    {
      Setinivalue(widgetpath+"colors.ini","colors","text1fontcolor",text1.font.fill.color);
      Setinivalue(widgetpath+"colors.ini","colors","text2fontcolor",text2.font.fill.color);
    }

    function widgetOnLoad()
    {
      text1.font.fill.color=Getinivalue(widgetpath+"colors.ini","colors","text1fontcolor",rgba(0,0,0,255));
      text2.font.fill.color=Getinivalue(widgetpath+"colors.ini","colors","text2fontcolor",rgba(255,0,0,255));
    }

  • Saving image src
    Code:
    function image1OnClick()
    {
      Setvalue("src",image1.src);
      Savevalue();
    }

    function widgetOnLoad()
    {
      image1.src=Getvalue("src",widgetpath+"black.png");
    }


    Code:
    function image1OnClick()
    {
      Setinivalue("D:\\mydocumets\\src.ini","src","image1src",image1.src);
      Setinivalue("D:\\mydocumets\\src.ini","src","image2src",image2.src);
    }

    function widgetOnLoad()
    {
      iamge1.src=Getinivalue("D:\\mydocumets\\src.ini","src","image1src","D:\\myimages\\black.png");
      iamge2.src=Getinivalue("D:\\mydocumets\\src.ini","src","image2src","D:\\myimages\\white.jpg");
    }

  • Saving integer variable
    Code:
    var num=18;
    function menuitem1OnClick()
    {
      Setvalue("number",num);
      Setvalue("number2",100);
      Savevalue();
    }

    function widgetOnLoad()
    {
      num=parseInt(Getvalue("number",10));
    }

    Sometimes you need to converte data from string to other types since all the data will be saved and gotten as string.


Top
 Profile  
 
PostPosted: November 23rd, 2012, 9:50 am 
Offline
User avatar

Joined: June 12th, 2012, 11:05 am
Posts: 257
Location: Barcelona
We will waiting... ;)


Top
 Profile  
 
PostPosted: April 20th, 2013, 3:00 am 
Offline

Joined: June 18th, 2012, 12:07 am
Posts: 268
Thank you qiancang for this valuable information :D
Could you please add a description for the function SaveAsDefIni() :?:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 46 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB® Forum Software © phpBB Group