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.
#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();