• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

How to avoid repeating call when the panel has not been closed in script?

Contributor ,
Dec 30, 2023 Dec 30, 2023

Copy link to clipboard

Copied

I have written two JSX scripts,
where clicking a button in panel A calls another script from panel B.
However, the current way of calling causes the panel to be repeated every time the button is clicked on panel A.
How can I avoid repeating the call when the panel has not been closed?
For example, if panel B's script is still running and the button on panel A is clicked again without closing it,
it should not repeat the call.
Here is an example code:

var panelA = new Window("palette", "PanelA", undefined);
var button = Apanel.add("button", undefined, "Button");

button.onClick = function() {
panelB();
}
panelA.show();

function panelB () {
var panelB = new Window("palette", "PanelB", undefined);
var button2 = PanelB.add("button", undefined, "Button2");
button2.onClick = function() {
alert("this is panelB")
}
panelB.show();
}

TOPICS
Scripting

Views

243

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Dec 31, 2023 Dec 31, 2023

In this case enable the button when you close panelB

    var panelA = new Window("palette", "PanelA", undefined)
    var button = panelA.add("button", undefined, "Button")

    button.onClick = function() {
      panelB()
      this.enabled = false; // disable the button
    }
    panelA.show();

    function panelB() {
      var panelB = new Window("palette", "PanelB", undefined)
      var button2 = panelB.add("button", undefined, "Button2")
      button2.onClick = function() {
        alert("th
...

Votes

Translate

Translate
Engaged ,
Dec 30, 2023 Dec 30, 2023

Copy link to clipboard

Copied

You can disable the button:

var panelA = new Window("palette", "PanelA", undefined);
var button = panelA.add("button", undefined, "Button");

button.onClick = function() {
  panelB();
  this.enabled = false; // disable the button
}
panelA.show();

function panelB() {
  var panelB = new Window("palette", "PanelB", undefined);
  var button2 = panelB.add("button", undefined, "Button2");
  button2.onClick = function() {
    alert("this is panelB")
  }
  panelB.show();
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 31, 2023 Dec 31, 2023

Copy link to clipboard

Copied

But if the button is disabled, when panel B closes, it won't be able to call again by push button.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 31, 2023 Dec 31, 2023

Copy link to clipboard

Copied

In this case enable the button when you close panelB

    var panelA = new Window("palette", "PanelA", undefined)
    var button = panelA.add("button", undefined, "Button")

    button.onClick = function() {
      panelB()
      this.enabled = false; // disable the button
    }
    panelA.show();

    function panelB() {
      var panelB = new Window("palette", "PanelB", undefined)
      var button2 = panelB.add("button", undefined, "Button2")
      button2.onClick = function() {
        alert("this is panelB")
      }
      panelB.onClose = function() {
        button.enabled = true
      }
      panelB.show()
    }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 31, 2023 Dec 31, 2023

Copy link to clipboard

Copied

Thank you, this approach is effective.

In addition, I have two more questions.
1. Is there a better way to merge two JSX elements into one by calling a button?
2. How can I refresh the Panel A when changing the button number in Panel B through its button?
Here is an example:

var panelA = new Window("palette", "PanelA", undefined)
var button = panelA.add("button", undefined, "Button")

button.onClick = function() {
panelB()
this.enabled = false; // disable the button
}
panelA.show();

function panelB() {
var panelB = new Window("palette", "PanelB", undefined)
var button2 = panelB.add("button", undefined, "Button2")

button2.onClick = function() {
var button3 = panelA.add("button", undefined, "Button3")
}

panelB.onClose = function() {
button.enabled = true
}


panelB.show()
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 31, 2023 Dec 31, 2023

Copy link to clipboard

Copied

To refresh the panel, you can use:

panelA.layout.layout(true); // refresh the panel

 

var panelA = new Window("palette", "PanelA", undefined)
var button = panelA.add("button", undefined, "Button")

button.onClick = function() {
  panelB()
  this.enabled = false; // disable the button
}
panelA.show();

function panelB() {
  var panelB = new Window("palette", "PanelB", undefined)
  var button2 = panelB.add("button", undefined, "Button2")

  button2.onClick = function() {
    var button3 = panelA.add("button", undefined, "Button3")
    panelA.layout.layout(true); // refresh the panel
  }

  panelB.onClose = function() {
    button.enabled = true
  }
  panelB.show()
}

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 31, 2023 Dec 31, 2023

Copy link to clipboard

Copied

LATEST

Thank you very much.
If I use the file calling JSX method, how can I check if a window is close and set the value to true?


if (file.exists) {
$.evalFile(file);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 31, 2023 Dec 31, 2023

Copy link to clipboard

Copied

To prevent repeated instantiation of Panel B, add a check within panelB function to see if the panel is already open before creating a new instance. You can use a flag variable like isPane1B0pen and set it to true when the panel is created, then check this flag before creating the panel again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 31, 2023 Dec 31, 2023

Copy link to clipboard

Copied

I have tried using the example with a flag to check if Panel B is open or not, but I want to make Panel B the focus when the flag is true. However, using

if(isPane1B0pen == false){

panelB();

} else {

panelB.show();

}

does not move the focus to Panel B after clicking on it. Have I made a mistake somewhere?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines