Skip to main content
Shulipa Bernad
Inspiring
August 3, 2022
Answered

View Palette

  • August 3, 2022
  • 1 reply
  • 995 views

Hello everyone, everything good?
I'm trying to create a script that has two types of dialog boxes, a main and a second window, which when opened I can manipulate the elements of the main window. The solution would be a palette-type window, but I have no idea how to make it stay open when executed.
Is there any chance this pallete will be visible when executed? Thanks.

dlg = new Window("palette"); 
dlg.text = "Dialog"; 
dlg.orientation = "column"; 
dlg.alignChildren = ["center","top"]; 

array=[];
p1 = dlg.add("panel", undefined, undefined, {name: "p1"}); 
p1.text = "Panel"; 
p1.preferredSize.width = 150; 
p1.orientation = "column"; 
p1.alignChildren = ["left","top"]; 
p1.spacing = 10; 
p1.margins = 10; 

var valor = 25.00;
b1 = dlg.add("button", undefined, undefined, {name: "b1"}); 
b1.text = "Adicionar"; 
b1.preferredSize.width = 150; 

adiconar();
b2 = dlg.add("button", undefined, undefined, {name: "b2"}); 
b2.text = "Somar"; 
b2.preferredSize.width = 150; 

dlg.layout.layout (true);
b1.onClick = function(){
adiconar();
}

function adiconar(){
    t1 = p1.add("Button"); t1.text = "✔ Moldura 1 : R$ " + valor;
    array.push([ t1.text.split("R$")[1] ]);
    dlg.layout.layout (true);
}

b2.onClick = function(){
	var soma_total = 0;
	for (i = 0; i < array.length; i++) {
		soma_total += Number(array[i]);
		}
    b2.text ="R$: "+ soma_total.toFixed(2).replace('.', ',').replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.');
}

dlg.show();
This topic has been closed for replies.
Correct answer jazz-y

Palette for UI problems 

1 reply

jazz-yCorrect answer
Legend
August 3, 2022
Shulipa Bernad
Inspiring
August 3, 2022

@jazz-y  Thanks! You are a genius! The palette worked fine, however I tried to run the palette by clicking a button in the main dialog and I noticed that the palette only opens when the main window is closed, the idea would be to keep both of them open. You as a great genius that you are, would you know of any method that I can fix this?

var dialog = new Window("dialog"); 
dialog.text = "Dialog"; 
dialog.orientation = "column"; 
dialog.alignChildren = ["center","top"]; 
dialog.spacing = 10; 
dialog.margins = 16; 

var button1 = dialog.add("button", undefined, undefined, {name: "button1"}); 
button1.text = "Button"; 

button1.onClick = function(){adicionar_mais()}

dialog.show();




function adicionar_mais(){

	var bt = new BridgeTalk(); 
	bt.target = "photoshop"; 
	bt.body = "var palette = " + fn.toString() + "; palette();"
	bt.send(); 

	function fn () {
		dlg = new Window("palette",  undefined, undefined, {closeButton:true}); 
		dlg.text = "Dialog"; 
		dlg.orientation = "column"; 
		dlg.alignChildren = ["center","top"]; 

		array=[];
		p1 = dlg.add("panel", undefined, undefined, {name: "p1"}); 
		p1.text = "Panel"; 
		p1.preferredSize.width = 150; 
		p1.orientation = "column"; 
		p1.alignChildren = ["left","top"]; 
		p1.spacing = 10; 
		p1.margins = 10; 

		var valor = 25.00;
		b1 = dlg.add("button", undefined, undefined, {name: "b1"}); 
		b1.text = "Adicionar"; 
		b1.preferredSize.width = 150; 

		adiconar();
		b2 = dlg.add("button", undefined, undefined, {name: "b2"}); 
		b2.text = "Somar"; 
		b2.preferredSize.width = 150; 

		dlg.layout.layout (true);
		b1.onClick = function(){
		adiconar();
		}

		function adiconar(){
			t1 = p1.add("Button"); t1.text = "✔ Moldura 1 : R$ " + valor;
			array.push([ t1.text.split("R$")[1] ]);
			dlg.layout.layout (true);
		}

		b2.onClick = function(){
			var soma_total = 0;
			for (i = 0; i < array.length; i++) {
				soma_total += Number(array[i]);
				}
			b2.text ="R$: "+ soma_total.toFixed(2).replace('.', ',').replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.');
		}

		dlg.show();
	}


}
Legend
August 11, 2022

Using a window in palette mode has certain limitations. You can try to start both windows in this mode, but it seems to me that it is easier to change interface logic so that there is no need to interact with two windows at the same time.

var bt = new BridgeTalk();
bt.target = "photoshop";
bt.body = "var palette = " + fn.toString() + "; palette();"
bt.send();
function fn() {
    var dialog = new Window("palette", undefined, undefined, { closeButton: true });
    dialog.text = "Dialog";
    dialog.orientation = "column";
    dialog.alignChildren = ["center", "top"];
    dialog.spacing = 10;
    dialog.margins = 16;
    var button1 = dialog.add("button", undefined, undefined, { name: "button1" });
    button1.text = "Button";
    button1.onClick = function () { adicionar_mais() };
    dialog.show();
    function adicionar_mais() {
        var bt = new BridgeTalk();
        bt.target = "photoshop";
        bt.body = "var palette = " + fn.toString() + "; palette();"
        bt.send();
        function fn() {
            dlg = new Window("dialog", undefined, undefined, { closeButton: true });
            dlg.text = "Dialog";
            dlg.orientation = "column";
            dlg.alignChildren = ["center", "top"];
            array = [];
            p1 = dlg.add("panel", undefined, undefined, { name: "p1" });
            p1.text = "Panel";
            p1.preferredSize.width = 150;
            p1.orientation = "column";
            p1.alignChildren = ["left", "top"];
            p1.spacing = 10;
            p1.margins = 10;
            var valor = 25.00;
            b1 = dlg.add("button", undefined, undefined, { name: "b1" });
            b1.text = "Adicionar";
            b1.preferredSize.width = 150;
            adiconar();
            b2 = dlg.add("button", undefined, undefined, { name: "b2" });
            b2.text = "Somar";
            b2.preferredSize.width = 150;
            dlg.layout.layout(true);
            b1.onClick = function () {
                adiconar();
            }
            function adiconar() {
                t1 = p1.add("Button"); t1.text = "✔ Moldura 1 : R$ " + valor;
                array.push([t1.text.split("R$")[1]]);
                dlg.layout.layout(true);
            }
            b2.onClick = function () {
                var soma_total = 0;
                for (i = 0; i < array.length; i++) {
                    soma_total += Number(array[i]);
                }
                b2.text = "R$: " + soma_total.toFixed(2).replace('.', ',').replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.');
            }
            dlg.show();
        }
    }
}