Please help with sample plugin form SDK Guide

Everything regarding the Power-Grid SDK can be asked and discussed here.

Please help with sample plugin form SDK Guide

Postby Andre » 31. Jul 2015, 12:16

Hi guys,
first of all I tried to make that sample plugin form SDK Guide working.
When I put it as it was described, it didn't work.
So I had to play around with code and make some changes.
1) OnMouseClick: "MyOnMouseClick" event handler in plugin.json moved from Skin to Layout level.
Code: Select all
    Skins: [
        {
            Name: "MySkin",
//            OnMouseClick: "MyOnMouseClick",
            Layouts: [
                {
                    Name: "MyLayoutElement",
                    Type: "Gfx",
                    Gfx: "MyGfx",
                    Left: "0",
                    Top: "0",
                    Height: "160",
                    Width: "160"
                }
                {
                    Name: "MyText",
      OnMouseClick: "MyOnMouseClick",
                    Type: "Text",
                    Text: "Test",
                    Font: "EuroD, 16",
                    Color: "Blue",
                    Left: "0",
                    Top: "0",
                    Height: "160",
                    Width: "160"
                }
            ] //MySkin::Layouts
       } //MySkin
    ], //Skins

2) p_xSkin.FindLayout("MyText") in MyPlugin.qs changed to this.FindLayout("MyText")
Code: Select all
var my_global_counter = 0;
function MyOnMouseClick (p_xSkin) {
print("### PLUGIN ### mouse pressed!");
my_global_counter = (my_global_counter +1)%10;
var mytext = this.FindLayout("MyText");
mytext.setText(my_global_counter);
}


Could someone be kind enough to explain me:
why OnMouseClick event didn't work at Skin level?
what is p_xSkin?

Here is a link to a hole SamplePlugin.zip with my case.
https://yadi.sk/d/9cgZtNXbiCGMN
Andre
 
Posts: 21
Joined: 26. Jul 2015, 14:51

Re: Please help with sample plugin form SDK Guide

Postby Addihash » 31. Jul 2015, 13:55

Works fine for me, but the text is really hard to read. I would suggest to change its colour to white and the fontsize so 24.

The p_xSkin variable is there to hand over values which can be saved json style:
Code: Select all
function my_init_function(p_xSkin){
    p_xSkin.data={
        value1:1,
        value2:"val2"
    };
}

and so on. With that parameter you can avoid global variables which can cause problems in power-grid.
When multiple instances of one grid are loaded they share their global variables which can obviously cause problems.

Some Tips for Debugging:
In power-grid you can open an output console (where the print goes to) through pressing alt, then you can see the version in the top right corner. Double click that and the console opens.

When your grid is not even recognized I would suggest to tage a look at the log.txt which is located in "%LOCALAPPDATA%\Temp\ROCCAT\Power-Grid\log.txt"
Attachments
debugging.PNG
debugging.PNG (15.83 KiB) Viewed 11753 times
Addihash
Administrator
 
Posts: 232
Joined: 2. Feb 2015, 14:35

Re: Please help with sample plugin form SDK Guide

Postby Andre » 31. Jul 2015, 14:29

Thank you for the tips Addihash!
So, before one can use p_xSkin, one should declare and assign some value to it?
Andre
 
Posts: 21
Joined: 26. Jul 2015, 14:51

Re: Please help with sample plugin form SDK Guide

Postby Addihash » 31. Jul 2015, 14:45

No, you can already use it, the Skin is stored in it. So you can call Skin related functions from it such as FindLayout("..");
Addihash
Administrator
 
Posts: 232
Joined: 2. Feb 2015, 14:35

Re: Please help with sample plugin form SDK Guide

Postby Andre » 31. Jul 2015, 15:18

Hm... I'm having an error in such a case
TypeError: Result of expression 'p_xSkin.FindLayout' [undefined] is not a function.
Andre
 
Posts: 21
Joined: 26. Jul 2015, 14:51

Re: Please help with sample plugin form SDK Guide

Postby Addihash » 31. Jul 2015, 15:38

Oh my bad, you can store this in the datatype then it works (p_xSkin.data.xThis.FindLayout()). Had not enough coffee today ;)

A you can see in the doxygen documentation DCSkin has three methods:

Code: Select all
int numLayouts()

Code: Select all
DCLayout getLayout(int i)

and
Code: Select all
DCControl getControl()]


you can use these three methods without assigning anything to p_xSkin.data
Addihash
Administrator
 
Posts: 232
Joined: 2. Feb 2015, 14:35

Re: Please help with sample plugin form SDK Guide

Postby Andre » 31. Jul 2015, 16:07

Trying to use it in such a way
Code: Select all
var my_global_counter = 0;
function MyOnMouseClick (p_xSkin) {
print("### PLUGIN ### mouse pressed!");
my_global_counter = (my_global_counter +1)%10;
//var mytext = this.FindLayout("MyText");
var mytext = p_xSkin.data.xThis.FindLayout("MyText")
mytext.setText(my_global_counter);
}

getting an error
TypeError: Result of expression 'p_xSkin.data' [undefined] is not an object. @ Line:6"
Andre
 
Posts: 21
Joined: 26. Jul 2015, 14:51

Re: Please help with sample plugin form SDK Guide

Postby Addihash » 31. Jul 2015, 16:21

Well sorry for beeing unclear but in meant that you can assign this to it.
it would have to look like this:

Code: Select all
function func(p_xSkin){
    p_xSkin.data={
        xThis:this
    };
    p_xSkin.data.xThis.FindLayout("..");
}

This comes handy in situations where this is not referring to the skin. (i.e. as an argument for a function).
Addihash
Administrator
 
Posts: 232
Joined: 2. Feb 2015, 14:35

Re: Please help with sample plugin form SDK Guide

Postby Andre » 31. Jul 2015, 16:49

I had to correct your example a bit
function func(p_xSkin){
p_xSkin.data={
xThis : this
};
p_xSkin.data.xThis.FindLayout("..");
}
and now it works. Thank you!
Andre
 
Posts: 21
Joined: 26. Jul 2015, 14:51

Re: Please help with sample plugin form SDK Guide

Postby Addihash » 31. Jul 2015, 16:55

Thanks I edited my post ;)
Addihash
Administrator
 
Posts: 232
Joined: 2. Feb 2015, 14:35


Return to Power-Grid SDK

Who is online

Users browsing this forum: No registered users and 1 guest

cron