Author Topic: Obtaining a list of all open images and previews  (Read 8844 times)

Offline David Serrano

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 503
Obtaining a list of all open images and previews
« on: 2007 August 25 14:09:11 »
[English below]

Hola a todos.

Tal como se ha hablado en el hilo del script de kappa-sigma, pienso en poner en el interface del script una lista con todas las imágenes y previews, de forma que el usuario pueda seleccionar las que quiera sumar. Pensaba en recorrer los elementos de un ViewList previamente rellenado con su método getAll pero no encontré forma de hacerlo.

Hice una búsqueda por todos los objetos de la lista "Core Javascript Objects" de algo que tuviera buena punta pero el resultado fue el mismo. Así que, ¿cómo obtengo esa lista?

Gracias.



Hi all.

As discussed in the kappa-sigma script thread, I plan to feature an interface with a list of all images and previews, so the user can select the ones she wants to combine. I was thinking about iterating the elements of a ViewList previously populated with its getAll method but found no way of doing that.

Did a search in all "Core Javascript Objects" that looked promising but the result was the same. So, how do I get such a list?

Thank you,
--
 David Serrano

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Obtaining a list of all open images and previews
« Reply #1 on: 2007 August 26 02:08:40 »
Hi David,

What you are trying to do requires a TreeBox control populated with all existing views. Here's a script that you can use to start playing. Let me know if you need more help to extract relevant data (= the identifiers of all selected nodes) from the tree nodes.

Lo que quieres hacer requiere un control TreeBox con información sobre todas las vistas existentes. Aquí tienes un script de ejemplo que te ayudará a empezar a jugar. Dime si necesitas más ayuda para extraer los datos relevantes (=el identificador de cada vista seleccionada) de los nodos del árbol.

Code: [Select]

#include <pjsr/Sizer.jsh>
#include <pjsr/TextAlign.jsh>

function ShowMeTheViewsDialog()
{
   // Execute the constructor of Dialog for this object.
   // In that way we add all Dialog's properties to this.
   this.__base__ = Dialog;
   this.__base__();

   // Set up the tree of views
   this.view_Tree = new TreeBox( this );
   this.view_Tree.setMinSize( 600, 200 );
   this.view_Tree.alternateRowColor = true;
   this.view_Tree.font = new Font( "monospace", 10 ); // best to show tabulated data
   this.view_Tree.numberOfColumns = 3;
   this.view_Tree.headerVisible = true;
   this.view_Tree.headerSorting = true;
   this.view_Tree.setHeaderText( 0, "Views" );
   this.view_Tree.setHeaderText( 1, "Dimensions" );
   this.view_Tree.setHeaderText( 2, "Format" );
   this.view_Tree.setHeaderAlignment( 0, Align_Left );
   this.view_Tree.setHeaderAlignment( 1, Align_Left );
   this.view_Tree.setHeaderAlignment( 2, Align_Left );

   // Node creation helper
   function addViewNode( parent, view )
   {
      var node = new TreeBoxNode( parent );
      node.checkable = true;
      node.checked = true;

      node.setText( 0, view.id );

      var image = view.image;
      node.setText( 1, format( "%5d x %5d x %d", image.width, image.height, image.numberOfChannels ) );

      if ( view.isMainView ) // don't show redundant info
      {
         var window = view.window;
         node.setText( 2, format( "%2d-bit %s", window.bitsPerSample, window.isFloatSample ? "floating point" : "integer" ) );
      }

      return node;
   }

   // Build the view tree structure
   var windows = ImageWindow.windows;
   for ( var i = 0; i < windows.length; ++i )
   {
      var node = addViewNode( this.view_Tree, windows[i].mainView );
      node.expanded = false; // or true to initially expand all preview lists

      var previews = windows[i].previews;
      for ( var j = 0; j < previews.length; ++j )
         addViewNode( node, previews[j] );
   }

   // Ensure that all columns are initially visible
   this.view_Tree.adjustColumnWidthToContents( 0 );
   this.view_Tree.adjustColumnWidthToContents( 1 );
   this.view_Tree.adjustColumnWidthToContents( 2 );

   // Standard OK and Cancel buttons

   this.ok_Button = new PushButton( this );
   this.ok_Button.text = " OK ";

   this.ok_Button.onClick = function()
   {
      this.dialog.ok();
   };

   this.cancel_Button = new PushButton( this );
   this.cancel_Button.text = " Cancel ";

   this.cancel_Button.onClick = function()
   {
      this.dialog.cancel();
   };

   this.buttons_Sizer = new HorizontalSizer;
   this.buttons_Sizer.spacing = 4;
   this.buttons_Sizer.addStretch();
   this.buttons_Sizer.add( this.ok_Button );
   this.buttons_Sizer.add( this.cancel_Button );

   //

   this.sizer = new VerticalSizer;
   this.sizer.margin = 6;
   this.sizer.spacing = 6;
   this.sizer.add( this.view_Tree, 100 ); // let the tree expand as possible
   this.sizer.addSpacing( 4 );
   this.sizer.add( this.buttons_Sizer );

   this.windowTitle = "DoSomethingNiceWithThoseViews Script";
   this.adjustToContents();
}

// Our dialog must inherit all properties and methods from the core Dialog object.
ShowMeTheViewsDialog.prototype = new Dialog;

/*
 * Script entry point.
 */
function main()
{
   // Hide the console while our dialog is active.
   console.hide();

   var dialog = new ShowMeTheViewsDialog();
   for ( ;; )
   {
      if ( !dialog.execute() )
         break;

      // Perhaps show the console to give some feedback to the user.
      console.show();

      // You can allow users to abort execution of this script.
      console.abortEnabled = true;

      /* Do something with the selected views in dialog. Note that at this
         point the dialog object is still intact, e.g. you can traverse
         dialog.view_Tree to obtain information from its nodes. */

      // Quit after successful execution.
      break;
   }
}

main();
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline David Serrano

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 503
Obtaining a list of all open images and previews
« Reply #2 on: 2007 August 26 16:33:21 »
Quote from: "Juan Conejero"
Code: [Select]
  var windows = ImageWindow.windows;


Hmm, este era el pequeño trocito de información que necesitaba y que no fui capaz de encontrar en toda la pila de propiedades y métodos existentes :).
--
 David Serrano