Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Previous page Next page Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Page 1 of 2
Topic:
CF.widget(panel, page, activity).label problem
This thread has 15 replies. Displaying all posts.
Post 1 made on Friday December 14, 2007 at 19:14
sgtoma
Long Time Member
Joined:
Posts:
December 2007
73
Hi guys,
I am only a beginner and I started playing with this TSU9600 few weeks ago.

Can you please guide me through this?

I have a panel (PSname )COUNTER, and I try to use it to store an variable.
This is a test code based on my original function.



onHold = function()
{
var x = CF.widget("COUNTER", "SCRIPTS", "RESOURCES");
var counter = x.label;

//bla bla
//some conditions
++counter;
x.label = counter;
System.print(counter +"-"+ x.label);
};
onHoldInterval = 300;

My aim is to increase the counter and write it to the panel LABEL so that on next function execution,
my var counter
will take the incremented value from the widget's LABEL to start with .

What happens is that whatever value I put in the LABEL's field (ie 0), my function takes this value (0) every time it is executed.
In the debug window I can read the values of booth counter - x.label
1 -0
What am I doing wrong that the
x.label = counte;
doesn't actually take it's incremented value 1?

Any answer will be much appreciated.

Cheers

Sorin



,
Post 2 made on Friday December 14, 2007 at 20:00
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
You need:

var counter = parseInt(x.label,10);
++counter;
x.label = counter.toString();
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 3 made on Saturday December 15, 2007 at 05:19
sgtoma
Long Time Member
Joined:
Posts:
December 2007
73
Hi Lyndel,

Thanks for reply. I was hoping a reply from you or Barry. :)

Unfortunately the method you hinted doesn't write the new value to the x.label

I also tried the following variants my debug feedback being
System.print("counter++="+counter +"\n xlabel="+ x.label);



x.label = valueOf(++counter).toString(10);
----
x.label = valueOf(++counter)
------
++counter;
x.label = valueOf(counter);
-------
++counter;
x.label = valueOf(counter).toString(10);


---------

all of these including your method returns:
counter++= 1
x.label= 0

If I manually modify the widget's label say 3
it then returns
counter++= 4
x.label=3

This is worrying for me as I know that you guys are very knowledgeable and you really know your stuff. Honestly I see no reason why this doesn't work.

Any other ideas?

Last edited by sgtoma on December 15, 2007 07:29.
Post 4 made on Saturday December 15, 2007 at 06:35
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
Don't know what the original value of the label is but I will assume it was an empty string or possibly text. You most likely were trying to increment a value that was NaN (Not A Number).

FYI, It's Lyndel (one L at the end) and Barry, not Lyndell and Gordon.

Try this

onHold = function()
{
var x = CF.widget("COUNTER", "SCRIPTS", "RESOURCES");
var counter = 0;
if (x) counter = parseInt(x.label,10);
if (isNaN(counter)) counter = 0;

//bla bla
//some conditions
counter++;
x.label = String(counter).valueOf();
System.print(counter +"-"+ x.label);
};
onHoldInterval = 300;
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 5 made on Saturday December 15, 2007 at 07:54
sgtoma
Long Time Member
Joined:
Posts:
December 2007
73
Please accept my apologies for getting your names wrong.

I pasted your code under PS and it doesn't do any different.
CF.widget("COUNTER", "SCRIPTS", "RESOURCES") the label is: 0 (zero), but whatever other value say 3(three) it behaves as stated above.
The label is not empty/null but - isNaN is a clever way to put this kind of error wright - cheers.
However, for the test purpose I deleted the label's value and guess what:
if label is blank it returns:
1-

if it contains a letter say t it returns:
1-t

I would have expected the script to change the panel's label from- blank or t to 0 as per isNaN condition.
I really hope it is some silly error of mine (despite all embarrassment) but I don't know where to look for.
Can I email you the .xcf?
I have just reloaded the firmware on my tsu9600 and no difference.
Firmware version 1.4.28
Post 6 made on Saturday December 15, 2007 at 12:35
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
You can email it but I'm in the middle of doing something else at the moment and will try to get to it in a couple of days. If it's not something simple, I'll let you know and if you want me to fix, we can discuss options offline.

What you are attempting to do is plain javascript. I suspect that some of your logic elsewhere may be updating that label to a non-numeric value which, when it does, you lose the value of your counter.


What happens if you change ?
from:
counter++
to:
counter = 1 + counter;

How about storing counter into its own field name in the widget w instead of using w.label?

You have to remember that widgets are javascript objects too. That is, you can add your own fields to them with a few side-effects. All you have to worry about is that your fields are persisted across multiple calls to CF.widget() or GUI.widget().

var w = CF.widget('blah');
w.myCounter = 0;
w.label = w.myCounter;

Now, label can operate independently from the field myCounter...

Last edited by Lyndel McGee on December 15, 2007 12:43.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 7 made on Saturday December 15, 2007 at 14:27
sgtoma
Long Time Member
Joined:
Posts:
December 2007
73
Lyndel, you are great!
counter = 1 + counter; didn't work but the new widget's field myCounter does increment and it is exactly what I needed.

As for my test xcf it had only one activity/page/panel aside from main page containing 1 button. The script we discussed was under the main page's only button.
Good luck with your project and pardon me if I picked your brains a bit.
Thank very much you for your help, it is much appreciated.
Sorin
Post 8 made on Saturday December 15, 2007 at 20:01
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
I do not know if this is related to your problem, but one issue I have with Java Script is the overloading of the operator "+". In Java Script the Symbol "+" can be concatenation as in string work or addition as in numeric work. The specific instance of the operator is determined by the left operand of the operator. If it is a string then + is concatenate and the right operand is converted to a string. ergo things like:

var a="1"; var b=a+1; system.print("b="+b) will print out b=11

The sequence var a="1"; var b=(a-0)+1; System.print("b="+b) will print b=2

AFAIK isNaN should report everything in the above examples (a or b) to be false i.e they are numeric, but I have just never tried it
OP | Post 9 made on Sunday December 16, 2007 at 06:20
sgtoma
Long Time Member
Joined:
Posts:
December 2007
73
Hi Barry,

Thank you for reply,

I was aware (you stated this in another post and I hate ++ as much as you guys do) about the ++ operator concatenation and I had tried to increment counter by using: counter = counter-0+1 in hope that it will force an arithmetic operation.
The problem I had/have is that I can't write/modify a CF.widget's label from another activity. I wanted to use the label to store the counter value.
Lyndel was very helpful in suggesting to define a widget.field to store the value and it works fine. Please note that I am still a beginner and did not have any programming formal training, should you find some errors/misinterpretations in my statements.

I needed to modify the CF.widget.label in another application to display an error message:

Some code;
if (error )
{CF.widget(PANEL, error_page, activity)= "respective error msg";
CF.widget(action_jump_to_error_page, page, activity).executeActions;
}

My aim was to use same page/panel to jump to & display various error messages should that be the case.
Post 10 made on Sunday December 16, 2007 at 07:37
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
In my work I use a common error page to display an error message, But it is a page of the activity so it is not addressed by multiple activities. I do not see why you couldn't have a common "Error Activity" with a single or multiple error pages. The only restriction would be that parameters that were passed to this activity should be stored as System Globals using System.setGlobal and System.getGlobal to hold the things the page needs to display.

If a variable or object holds a number either as a real number or as a string which is clearly a number (e.g. "5") then the incrementation and decrementation operators should always work as ++ and -- are not overloaded as the plus sign is. I have not tried it for the numeric string case but the incrementation and decrementation operators should force an auto conversion just as the case for a="5" B=5*a, (or b=a*5) System.print("B="+b) should print B=25
OP | Post 11 made on Sunday December 16, 2007 at 12:41
sgtoma
Long Time Member
Joined:
Posts:
December 2007
73
Thank you for reply Barry,

System.setGlobal is exactly what I used to get this working.

some code;
if (error)
{ System.setGlobal ("MSG", "respective error message");
CF.widget(action_jump_to_error_page, error_page, activity).executeActions;
}


and in PS of error_page:
error_panel.label = System.getGlobal("MSG");

Thank you for furthering my knowledge on ++/-- operators. I was not aware of that.
It has been a pleasure to "talk" booth to you and Lyndel.
You are the two pillars of this forum and many lads ,beginners or advanced, have found comfort in your advice.
My “Javascript definitive guide” by Flangan is on the way.

Thank you for your great support.

Kind regards

Sorin Toma
Post 12 made on Sunday December 16, 2007 at 13:32
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
Glad to help

"Feed a man a fish, feed a man for a day; Teach a man to fish, feed a man for life"
OP | Post 13 made on Sunday December 16, 2007 at 13:43
sgtoma
Long Time Member
Joined:
Posts:
December 2007
73
GOOD MOTTO,

In my case I am sure I still need a lot of fishing lessons though.

Sorin
Post 14 made on Wednesday February 13, 2008 at 16:43
MVis
Long Time Member
Joined:
Posts:
July 2007
94
On a related note - can one refresh a widget.label or image that is not on the active page ? Same activity, but different page.

More specifically - if one refreshes a widget not on the active page (label, image, etc), does it actually refresh ? It does not generate an error, so it is legal to do so.

I have an activity where I'm using the rotary wheel to update a list. My code is all at the activity level. I carry the changes done to the list to widgets that are available on each of the pages. Basically, when idle, I preload some images, set the panel images and while I'm there, I set some button labels.

If I'm not on the page when the update is called, the panels and buttons don't seem to update.

Also, when returning to a page, the labels seem to be empty until I actively refresh them with data.

Is this expected? Still looking through docs to see if it's stated.
Post 15 made on Wednesday February 13, 2008 at 21:37
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
Yes, it is expected that changes to widgets only affect the current page.

Upon entry to a page, the widgets are reloaded from the editor version (CF object). You can work with widgets using either GUI.widget() or CF.widget(). GUI.widget() only affects widgets on the current page. CF.widget() will indeed allow you to change labels/locations, etc on other pages but as soon as you load the page, the widgets revert to the editor settings.

Therefore, use GUI.widget() in your page scripts to setup the page just before display to ensure correct location, labels, etc... You can use CF.widget() as well but the best use for CF.widget() is to retrieve image resources, etc... from widgets in other pages/activities.

Note that on a page, CF.widget() and GUI.widget() return exactly the same object (used === identity to check) so you can basically use them interchangeably in a single page.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Page 1 of 2


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse