My bug, a PI bug, or a Feature?

aworonow

Well-known member
When I edit the value in one of my script's NumericControl boxes then, with no intervening clicks or actions, drag an instance to the desktop, the new, just entered value in the text box is not updated in the instance icon. Is there something I can do to update that value automatically (without clicking another control) to assure that the most recent value is capture in the desktop icon?

Maybe on a related topic, if after I've edited a NumericControl, if I hit 'enter' on the keyboard, the script tries to execute, whereas all I wanted was that the new entry to be accepted and its value updated. Can this enter somehow be captured and disregarded--or not regarded as a desire to execute the script?

Any help on these things much appreciated. Alex
 
Hi @aworonow, you have to programmatically store the values you would like to embed into the instance you're going to create on the workspace first, then you can create the instance. To do that, you need to use the Parameters.set(keyName, value) function, invoked once for each parameter you would like to set.
Once the script gets executed from the instance, you need to restore back the values using the functions provide again by the Parameters object. a common pattern is:

if ( Parameters.has( "myParameter" ) )
this.myParameter = Parameters.getBoolean( "myParameter" );

This code is reading a boolean value but you have other functions to parse integer, numeric, strings etc... check out the Parameter object in the Object Explorer window in PixInsight for the complete list of functions.

You can also check my video on Scripting in PixInsight, I talk on creating an instance and restore/execute it here:


Hope it helps!
Robyx
 
Thanks Robyx. I have the "set" and "get" codes at the top of my program. But they apparently called not called until the focus leaves the edited Numerical Control. If I click another control before creating the desktop instance, all is fine...but that seems like it should be unnecessary and that dragging the blue triangle to the desktop should cause the numerical value to update before generating the icon.

I got started on my first script after watching the live presentation by Roberto...really excellent!
alex
 
Thanks Robyx. I have the "set" and "get" codes at the top of my program. But they apparently called not called until the focus leaves the edited Numerical Control. If I click another control before creating the desktop instance, all is fine...but that seems like it should be unnecessary and that dragging the blue triangle to the desktop should cause the numerical value to update before generating the icon.
hmm not sure what exactly means to have the set and get codes at the top of the program, the top should be executed once at the beginning. If you're willing to share the script I can quickly check the flow, if not maybe providing a bit deeper detail on where the parameters saving occurs in the code.
As a general principle I would suggest to store the vales through Parameters.set function just before creating the instance, not somewhere else in the project unless you really know how you code works and why you make a different choice.

I got started on my first script after watching the live presentation by Roberto...really excellent!
alex
wow great to hear!! :): )
 
Ok, I see what you're saying. Thanks! I had the code, just wasn't calling at the correct time, apparently.
A
 
Hi @aworonow, you have to programmatically store the values you would like to embed into the instance you're going to create on the workspace first, then you can create the instance. To do that, you need to use the Parameters.set(keyName, value) function, invoked once for each parameter you would like to set.
Once the script gets executed from the instance, you need to restore back the values using the functions provide again by the Parameters object. a common pattern is:

if ( Parameters.has( "myParameter" ) )
this.myParameter = Parameters.getBoolean( "myParameter" );

This code is reading a boolean value but you have other functions to parse integer, numeric, strings etc... check out the Parameter object in the Object Explorer window in PixInsight for the complete list of functions.

You can also check my video on Scripting in PixInsight, I talk on creating an instance and restore/execute it here:


Hope it helps!
Robyx

Hi,
I found your YouTube video to be very very clear and concise. It was refreshing to get all the pertinent info in a very organized manner.

I did have a problem with the NumericControl.

I am running: Ripley v1.8.8-12 on Windows 10

I needed to add the following to get the NumericControl to work properly:


var LchSatParameters = {
satAmount: 0,
targetView: undefined,
myNC: undefined <-------------------Added this NC is short for NumericControl
};


//create the numerical control
this.satAmount = new NumericControl(this);
this.satAmount.label.text = "Amount of Saturation";
this.satAmount.setRange(0, 1);
this.satAmount.setPrecision(2);
this.satAmount.slider.setRange(0, 100);
LchSatParameters.myNC = this.satAmount; <----- added so we can access object in even handler
this.satAmount.slider.onValueUpdated = function(value){
LchSatParameters.satAmount = value/100; <------ divided by 100
//Only way to update the value in the text box?
LchSatParameters.myNC.setValue(value/100); <----- else text box with value does not get updated

}


---------------
I saw behavior such that value received in the event handler (onValueUpdated) was a number between 0 and 100 (the slider value) and not between 0 and 1.

The above got around that problem.

Am I missing something?

Thanks!

-Pierre Fleurant
 
Back
Top