Author Topic: PJSR: a few questions  (Read 5577 times)

Offline Ioannis Ioannou

  • PixInsight Addict
  • ***
  • Posts: 202
PJSR: a few questions
« on: 2012 April 25 13:53:17 »
OK, they may sound silly but I can not figure them out:

1) which method of Dialog I should use to perform a global cleanup ? (a destructor ? ) Maybe I have to overwrite "done" ?

2) how do I change the position on the screen of  an ImageWindow ? 

3) Is there a way to create a modless Dialog? 

Thanks in advance
Clear Skies
John (Ioannis)

FSQ106N+Robofocus+QHY-22+SX USB wheel+Baader filters
SX OAG+DSI Pro guiding a NEQ6
PI for the rest :)

Offline Ioannis Ioannou

  • PixInsight Addict
  • ***
  • Posts: 202
Re: PJSR: a few questions
« Reply #1 on: 2012 April 26 06:13:42 »
another one :


4 ) How do I exclude specific views from a ViewList ? The name (or a pattern of the name) of the views is my filter to exclude them.

getall() brings them all in.
remove() requires as a parameter a View object, which I do not have   (or maybe I have it somehow ?  :-\ ) ?

Clear Skies
John (Ioannis)

FSQ106N+Robofocus+QHY-22+SX USB wheel+Baader filters
SX OAG+DSI Pro guiding a NEQ6
PI for the rest :)

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PJSR: a few questions
« Reply #2 on: 2012 April 28 02:39:04 »
Hi Ioannis,

Sorry for taking so long in getting back to you.

Quote
1) which method of Dialog I should use to perform a global cleanup ? (a destructor ? ) Maybe I have to overwrite "done" ?

What do you mean by "global cleanup"? If you mean destroying the Dialog object synchronously ala C++ for example, then never mind: object destruction is automatic in JavaScript. For example, this code:

var A = new Matrix( 1000, 1000 );

creates a new Matrix object with 1,000,000 elements. After this code, suppose we have this at some point where A is still in scope:

A = null;

After this statement, if there are no other references to the original Matrix object, then it will eventually be destroyed. When? We actually have no control on this. The 'orphan' object will be destroyed when the JavaScript runtime's garbage collector decides to do so. JavaScript's garbage collector is a rather complex and sophisticated device. It frees memory asynchronously when it decides that the amount of released memory is worth the time required to run object destructors and restructure the internal memory arena. We have the gc() global function, which we can call to tell the engine that now is a good time to run the garbage collector, but it has the right to ignore our suggestion completely or partially.

Quote
Maybe I have to overwrite "done" ?

This has nothing to do with memory management. The done method of the Dialog object, namely:

void Dialog.done( int retCode )

can be called to terminate the current modal session. The retCode argument is the dialog's exit code. In general an exit code can be any integer value, but the standard dialog exit codes:

StdDialogCode_Cancel
StdDialogCode_Ok


should always be used.

Quote
2) how do I change the position on the screen of  an ImageWindow ?

By assigning a Point object to the position property of the ImageWindow object:

Point ImageWindow.position

For example:

ImageWindow w;
w.pos = new Point( 100, 200 ); // move w to x=100 y=200 in its parent workspace


Beware of setting ImageWindow.position properties directly such as the following code:

w.pos.x = 100;
w.pos.y = 200;


because it won't work. As soon as the compiler sees w.pos.x it generates a temporary Point object which is not the same as w.pos. This happens because ImageWindow is not a JavaScript object, but a reflection (an alias) of a native PixInsight/PCL object, so the JS engine does not know how to reference properties of properties of ImageWindow (JavaScript's prototype-based inheritance chain is broken for native aliased objects beyond the first layer of properties exposed by the engine).

Unfortunately, the JS engine in version 1.7 still doesn't implement many objects that are necessary to manage the entire PixInsight workspace. This functionality will be complete in version 1.8 with runtime objects such as Workspace, Icon, etc.

Quote
3) Is there a way to create a modless Dialog?

Nope. Dialogs are always modal in PJSR, and there is no way to integrate a JavaScript message loop with the core application's message loop. This is a limitation of the PJSR due to reentrancy problems, which I hope to overcome in version 2.0 of PixInsight.
 
Quote
4 ) How do I exclude specific views from a ViewList ? The name (or a pattern of the name) of the views is my filter to exclude them.

You can exclude a single view by assigning the corresponding View object to ViewList.excludedView. However you cannot exclude multiple views with a similar mechanism, beyond calling ViewList.getMainViews() and ViewList.getPreviews() to restrict the list to a particular type of views.

After loading all views (or previews / main views), you can implement a filter adapted to your needs with the ViewList.remove( View ) method.

Let me know if you need further help.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Ioannis Ioannou

  • PixInsight Addict
  • ***
  • Posts: 202
Re: PJSR: a few questions
« Reply #3 on: 2012 April 28 12:12:41 »
What do you mean by "global cleanup"? If you mean destroying the Dialog object synchronously ala C++ for example, then never mind: object destruction is automatic in JavaScript.

OK, I did not made my shelf clear, I do not worry for memory leaks or object destruction, and I know about calling ok, or cancel or done. The problem is that I want to close some temporary views (used internally in the script) under any condition. The script does this cleanup when it is calling ok or cancel, on the onClick of the corresponding button. But how about closing the Dialog from the [X] at the top right ? Or if the script dies abnormally (not too much abnormally, enough to catch the event and clean the garbage before exiting). Is there a central point of exit on the Dialog object to put some code ? Currently if I close from [X] (or if there is a bug in the script) there are residual views left around.

 
Quote
After loading all views (or previews / main views), you can implement a filter adapted to your needs with the ViewList.remove( View ) method.

Juan, I though so but I need a bit more push here. I have ImageWindow objects, I have names of the Views, but I do not have defined View objects in the code. Give me an example how to use remove please. Is there a way to go from the ImageWindow object to the corresponding View object ?

Never mind the above about an example for remove. I figured it out.


Thank you for your answers.
BTW, is there anywhere any kind of documentation, maybe a tree view of the objects in the library, and maybe showing inheritance relations between them etc? Exploring via the script editor is not always intuitive.
« Last Edit: 2012 April 30 02:09:41 by Ioannis Ioannou »
Clear Skies
John (Ioannis)

FSQ106N+Robofocus+QHY-22+SX USB wheel+Baader filters
SX OAG+DSI Pro guiding a NEQ6
PI for the rest :)

Offline Ioannis Ioannou

  • PixInsight Addict
  • ***
  • Posts: 202
Re: PJSR: a few questions
« Reply #4 on: 2012 April 30 03:02:05 »
Well, I was too fast to delete my second question. I used :

ViewList.remove(data.MyTmpImageWindow.currentView)

and it worked the first time. Then I did some other work inside the script and the next time I dropped the listbox down, the removed views were there !! But there is no other point where I call getall() to fill the ViewList ! The same if I remove the mainView instead of the currentView.

Maybe I did not got it right ?

thnks
Clear Skies
John (Ioannis)

FSQ106N+Robofocus+QHY-22+SX USB wheel+Baader filters
SX OAG+DSI Pro guiding a NEQ6
PI for the rest :)

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PJSR: a few questions
« Reply #5 on: 2012 May 02 07:19:47 »
Quote
The script does this cleanup when it is calling ok or cancel, on the onClick of the corresponding button. But how about closing the Dialog from the [X] at the top right ?

You can implement the onHide event handler for your dialog. A hide event occurs when the dialog's window is closed, either via the [x] button or by calling Dialog.done(), or by any other means:

function myDialog
{
   // ...
   this.onHide = function()
   {
      // do your cleanup stuff here ...
   };
}


Quote
ViewList.remove(data.MyTmpImageWindow.currentView)

This is the correct way to remove view items from a ViewList control. AFAIK this method works correctly. Maybe your code calls ViewList.getXXX() from an event handler that is being called as a side effect?

Quote
BTW, is there anywhere any kind of documentation, maybe a tree view of the objects in the library, and maybe showing inheritance relations between them etc?

Unfortunately, we have no documentation for PJSR yet. The Object Browser window (embedded in Script Editor) shows you all the inheritance relations in the object tree. For example, if you expand the node for Dialog, you'll see an item "Inherited from Control", and so on.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Ioannis Ioannou

  • PixInsight Addict
  • ***
  • Posts: 202
Re: PJSR: a few questions
« Reply #6 on: 2012 May 02 10:35:36 »
This is the correct way to remove view items from a ViewList control. AFAIK this method works correctly. Maybe your code calls ViewList.getXXX() from an event handler that is being called as a side effect?

I do not think so. The script I'm working is Silvercup's HaRGB script, take a look at the corresponding topic, I have some progress since the initial script . But .remove works the first time you click on the listboxes. As soon as a button has been pressed (or a console window has been triggered, do not yet know which one), and you click on the listboxes, you are getting all the removed items. But the ViewList has been created once, and immidiatelly after each getall() I have the .remove lines! I can put some debug lines to ensure that the Viewlists are not recreated, but I do not think so.

Clear Skies
John (Ioannis)

FSQ106N+Robofocus+QHY-22+SX USB wheel+Baader filters
SX OAG+DSI Pro guiding a NEQ6
PI for the rest :)