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

Login:
Pass:
 
 

Original thread:
Post 1 made on Tuesday March 15, 2016 at 17:50
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
Consider that you are using scripts/applications (someone else's code and cannot change it) and perhaps the code retrieves a widget on the screen that is used to display for example, an input source mapping which is often represented in the Denon/Marantz world as 3/4/.1 to represent 7.1 audio or 2/0/.0 to represent stereo, etc...


Vendor's code does the following statement.
// execute SSINFAISFOR ?
GUI.widget('INPUT_CHANNEL_FORMAT').label = valueRetrieved;

Now, let's say you don't want to display that ugly string but rather turn on one or more panels as channel signal indicators. Without modifying the vendor code, this is typically not possible.

GUI, Activity, and functions on these objects are actually Javascript properties that can be replaced (the industry term is proxy or curry).

In order to support such functionality, you'd need the ability to do 2 things.

1. You need a way to intercept the call to GUI.widget() such that you can supply your own widget or widget proxy.
2. Next, the Widget Proxy must support intercept of the 'label' property and the make other calls as necessary to retrieve other widgets with different tag names (tags must be different to prevent recursive calls).

So, let's have a look at how to accomplish this.

If you execute this piece of script prior to any other script at the activity level, you can safely intercept any call to GUI.widget(tag). If have left System.print statements in here so you can actually see this in action.

Create a new Activity and add this code to the Activity Script. Note that a new page is created as well. Be sure to add the following to the Activity Script.


var proxy = null;
var old = GUI.widget;
function guiWidgetProxy(tag)
{
System.print('intercepted request for:' + tag);
if (tag === 'INPUT_CHANNEL_FORMAT')
return proxy;

return old(tag);
}
GUI.widget = guiWidgetProxy;
System.print('Installed Proxy');

// Class/function to provide a base implementation of #2.
// Note that this implementation is not a complete implementation.
// As we only need to intercept the storage of the 'label' property
// I have chosen to implement only the 'label' and 'tag'.
function WidgetProxy(tag){
var target = this;
target.tag = tag;
target._label = '';

function setLabel(newValue)
{
target._label = newValue;
// do whatever you need to do with newValue to setup other widgets as
needed.
var w = GUI.widget('TEST_PANEL');
if (w) w.label = 'intercepted:' + target._label;
}
function getLabel()
{
return target.label;
}

function getTag()
{
return target.tag;
}
function setTag(newValue)
{
// tag is immutable so do nothing.
}
target.__defineGetter__('label', getLabel);
target.__defineSetter__('label', setLabel);
target.__defineGetter__('tag', getTag);
target.__defineSetter__('tag', setTag);
}


On the page script for this new activity, add the following code.

// Assign proxy at the application level specific to this page.
proxy = new WidgetProxy('INPUT_CHANNEL_FORMAT');


Create a panel with a ProntoScript Name (aka tag) named 'TEST_PANEL'.

Create a button add the following code.


var w = GUI.widget('INPUT_CHANNEL_FORMAT')
if (w) w.label = '2/0/.0';


This solution is being provided as a proof of concept to illustrate something I've been thinking about recently. For sure, it can be cleaned up to better use memory (create prototype functions for WidgetProxy instead of creating functions each time a new proxy is created).

However, I wanted to share this as it is entirely possible to 'intercept' calls to GUI.widget() in cases where it may not be possible to modify calling script (protected - .pjs or obfuscated script).
Lyndel McGee
Philips Pronto Addict/Beta Tester


Hosting Services by ipHouse