Skip to main content
tssee
Inspiring
July 6, 2016
Question

Double panel - open close

  • July 6, 2016
  • 1 reply
  • 846 views

Good morning

I have a panel A

which it has a button that opens a second panel B

I want to know if you can do this:

When you click the OPEN PANEL button B

In the panel you have to close

Then when I close the panel B

You must reopen the panel A.

///////script

/////////////////panel  1

var win = new Window("palette", "PANEL A");

win.cancelOk = win.add('panel', [10,495,300,540], "");

   win.cancelOk.buildBtn = win.cancelOk.add('button', [10,10,180,35], 'OPEN PANEL B', {name:'ok'});

   win.closeButton = win.cancelOk.add("button",  [190,10,280,35], "CLOSE PANEL A");

////////////////////////////////////////////start panel 2//////////////////////////////////////////

   win.cancelOk.buildBtn.onClick = function () {

var win = new Window("palette", "PANEL B");

win.cancel2Ok = win.add('panel', [10,495,300,540], "");

  

   win.closeButton = win.cancel2Ok.add("button",  [10,10,280,35], "CLOSE PANEL B");

win.onDeactivate = function(){

   win.update();

   };

var closeWin = false;

win.closeButton.onClick = function(){

   closeWin = true;

   win.close();

    };

win.onClose = function(){

   closeWin = true;

    };

win.show();

while(closeWin == false){

   app.refresh();

    };

  }

  ////////////////////////////////////////////finish panel 2//////////////////////////////////////////

  

//////////////finisch panel 1

win.onDeactivate = function(){

   win.update();

   };

var closeWin = false;

win.closeButton.onClick = function(){

   closeWin = true;

   w.close();

    };

win.onClose = function(){

   closeWin = true;

    };

win.show();

while(closeWin == false){

   app.refresh();

    };

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
July 6, 2016

Why a palette and not a dialog?

Quote from JavaScript Tools Guide CC.pdf:

Floating palette: Also called modeless dialog, allows activity in other application windows. (Adobe Photoshop® does not support script creation of palette windows.)

With dialogs it seems possible:

#target photoshop

panelOne ();

/////////////////panel  1

function panelOne () {

var win = new Window("dialog", "PANEL A");

win.cancelOk = win.add('panel', [10,495,300,540], "");

win.cancelOk.buildBtn = win.cancelOk.add('button', [10,10,180,35], 'OPEN PANEL B');

win.closeButton = win.cancelOk.add("button",  [190,10,280,35], "CLOSE PANEL A");

win.cancelOk.buildBtn.onClick = function () {

  win.close();

  panelTwo ()

  };

win.closeButton.onClick = function () {

  win.close();

  };

win.show();

};

////////////////////////////////////////////start panel 2//////////////////////////////////////////

function panelTwo () {

var win = new Window("dialog", "PANEL B");

win.cancel2Ok = win.add('panel', [10,495,300,540], "");

win.closeButton = win.cancel2Ok.add("button",  [10,10,280,35], "CLOSE PANEL B");

win.closeButton.onClick = function () {

  win.close();

  panelOne ()

  };

win.show();

};

JJMack
Community Expert
Community Expert
July 6, 2016

Very nice.

But about Palette windows while Photoshop Scripting does not support them  you can Program a Palette in a Photoshop script it just will not function like a palette window Photoshop will close it when the script finishes it execution.

However Palette windows are supported in Photoshop Extension,  Scripted extensions can have Palette windows and extensions can launch Photoshop Scripts.  Therefore you program a Photoshop scripts with a palette window if it is launched by an extension a side effect will be the palette window will not be closed when its execution ends. It will not be closed till the the script closes the palette window or the thread it is in terminates.  So it depends on how the extension that launches  the Photoshop  task has been coded when and how the task terminates.

In CC 2014 I browsed the Photoshop ADD-ons available.  I found one that interested me. "JSX Launcher"  It provides a list of JSX file that can be launch. Will install in CC 2014 and CC 2015 not CC 2015.5.  Makes it easy to develop and test script that you have not yet added to Photoshop.  I found out that launched Photoshop script task are associated with the active document and will be terminated when that document is closed.  If there is no active document the launched script task is associated with the Photoshop extension and a Palette widows will not be closed till the script closes it, or you reset the extension, or you close down  or terminate Photoshop.

So you can if you want add Palettes to Photoshop.

var p = new Window( "palette" ,"JJMack PS Palette");

p.btn = p.add( "button", undefined,'Actual' );

p.btb = p.add( "button", undefined,'Zoom out' );

p.btc = p.add( "button", undefined,'Zoom in' );

p.cls = p.add( "button", undefined, "Close Palette");

customEventManager = {

  events: {},

  addListener: function( evt, handler, context ) {

    if ( !this.events[ evt ] ) {

      this.events[ evt ] = [];

    }

    this.events[ evt ].push( { "handler": handler, "context": context } );

  },

  trigger: function( evt ) {

    if ( this.events[ evt ] ) {

      for ( var i = 0; i < this.events[ evt ].length; i++ ) {

        this.events[ evt ][ i ].handler.call( this.events[ evt ][ i ].context, evt );

      }

    }

  }

}

p.btn.onClick = function() {

  p.evt.trigger( "Actual" );

}

p.btb.onClick = function() {

   p.evt.trigger( "Out" );

}

p.btc.onClick = function() {

   p.evt.trigger( "In" );

}

p.cls.onClick = function(){

   p.close();

};

aHandler = function( evt) {

  if (documents.length!=0) {runMenuItem(app.charIDToTypeID("ActP"));}

}

bHandler = function( evt) {

  if (documents.length!=0) {runMenuItem(app.charIDToTypeID("ZmOt"));}

}

cHandler = function( evt) {

  if (documents.length!=0) {runMenuItem(app.charIDToTypeID("ZmIn"));}

  //alert( evt );

}

p.evt = customEventManager;

p.evt.addListener( "Actual", aHandler );

p.evt.addListener( "Out", bHandler );

p.evt.addListener( "In", cHandler );

p.show();

JJMack