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

UI Panel submenu

Community Beginner ,
Jan 03, 2018 Jan 03, 2018

Hello everyone,

I'm actually struggling with UI Panel on extendscript.

I managed to build a panel with multiple buttons, but not responsive or sizeable but i have a bigger problem, I want to "clean" my panel and create another with new icons when a button is clicked.

I tried the remove method, the visible parameter, everything, i don't see how it is doable.

I paste the code here so you'll better understand.

Thanks a lot

var dir = "(images)/";

var icons = {a: File(dir+"a.png"), b: File(dir+"b.png"),

c: File(dir+"c.png"), d: File(dir+"d.png")}

function createUI(thisObj) {

    var win = (thisObj instanceof Panel) ? thisObj : new Window("palette", "My Window", undefined);

    win.orientation = "row";

var myPanel = win.add("panel", [5,5,300,450]);

myPanel.orientation = "row";

    var aButton=myPanel.add("iconbutton",[undefined,undefined,120,120],icons.a);

    don.location = [10, 10];

    var bButton=myPanel.add("iconbutton",[undefined,undefined,120,120], icons.b);

    line.location = [160, 10];

    var cButton=myPanel.add("iconbutton",[undefined,undefined,120,120], icons.c);

    rad.location = [10, 160];

    var dButton = myPanel.add("iconbutton",[undefined,undefined,120,120], icons.d);

    hist.location = [160, 160];   

aButton.onClick = function(){ aFunction()};

bButton.onClick = function(){bFunction()};

cButton.onClick = function(){cFunction()};

dButton.onClick = function(){dFunction()};

return win;

}

TOPICS
Scripting
1.1K
Translate
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
Advocate ,
Jan 16, 2018 Jan 16, 2018

Here's a method to remove and create new items in same group:

(function (thisObj) {

    buildUI(thisObj);

    function buildUI(thisObj) {

        var win = (thisObj instanceof Panel) ? thisObj : new Window("palette", "script", undefined, {

            resizeable: true

        });

        var grpTab = win.add("group");

        var btn1 = grpTab.add("button", undefined, "1");

        btn1.onClick = function () {

            cleanUpGroup(grpContainer);

            var btn1_1 = grpContainer.add("button", undefined, "1_1");

            var btn1_2 = grpContainer.add("button", undefined, "1_2");

            var btn1_3 = grpContainer.add("button", undefined, "1_3");

            var btn1_4 = grpContainer.add("button", undefined, "1_4");

            updatePanel(win);

        };

        var btn2 = grpTab.add("button", undefined, "2");

        btn2.onClick = function () {

            cleanUpGroup(grpContainer);

            var btn2_1 = grpContainer.add("button", undefined, "2_1");

            var btn2_2 = grpContainer.add("button", undefined, "2_2");

            var btn2_3 = grpContainer.add("button", undefined, "2_3");

            var btn2_4 = grpContainer.add("button", undefined, "2_4");

            updatePanel(win);

        };

        var grpContainer = win.add("group");

        win.onResizing = win.onResize = function () {

            this.layout.resize();

        };

        win.onShow = function() {

            btn1.onClick();

        };

        if (win instanceof Window) {

            win.center();

            win.show();

        } else {

            win.layout.layout(true);

            win.layout.resize();

        }

    }

    function cleanUpGroup(container) {

        while (container.children[0]) {

            container.remove(container.children[0]);

        }

    }

    function updatePanel(win) {

        win.layout.layout(true);

    }

})(this);

Translate
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
Community Beginner ,
Jan 18, 2018 Jan 18, 2018

Thanks Tomas, I'll look that when I'll have some time.

But I found a solution which seems pretty similar to yours, i'll post it here soon.

Translate
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
Participant ,
Feb 18, 2020 Feb 18, 2020

Hey Tomas,

I think your above is the closest thing I'm finding to an answer to refresh my panel.

if I do this portion like this

btn1.onClick = function () {

cleanUpGroup(grpContainer);

//Create Array from aseFile var dataField = new Array();

for (var i=0; i<numColors; i++){

var colorData = data.values[i];

if(colorData.type == "RGB"){

if(colorData.name.indexOf(note.text) > -1){

color = [colorData.r, colorData.g, colorData.b, 1];

dataField[dataField.length] = new Array(color,colorData.name);

} } }

 

btna = grpContainer.add("button", undefined, dataField[0][1]);

btnb = grpContainer.add("button", undefined, dataField[1][1]);

updatePanel(win);

};

but if I loop it like below. It doesn't work 

(function (thisObj) {
    buildUI(thisObj);
    function buildUI(thisObj) {
        var win = (thisObj instanceof Panel) ? thisObj : new Window("palette", "script", undefined, {
            resizeable: true
        });
    
    var note = win.add('edittext',undefined,"Manheim ");
    
var aseFile = File("/Volumes/Server/Media/Brands/CA Brand Colours new.ase");
var data = app.parseSwatchFile(aseFile);
var numColors = data.values.length;



//Create Array from aseFile
var dataField = new Array();

for (var i=0; i<numColors; i++){
var colorData = data.values[i];
if(colorData.type == "RGB"){
if(colorData.name.indexOf(note.text) > -1){
    color = [colorData.r, colorData.g, colorData.b, 1];
    dataField[dataField.length] = new Array(color,colorData.name);
    }
    }
}
    
    
    
        var grpTab = win.add("group");
        var btn1 = grpTab.add("button", undefined, "APPLY");
        
        btn1.onClick = function () {
            cleanUpGroup(grpContainer);
            //Create Array from aseFile
var dataField = new Array();

for (var i=0; i<numColors; i++){
var colorData = data.values[i];
if(colorData.type == "RGB"){
if(colorData.name.indexOf(note.text) > -1){
    color = [colorData.r, colorData.g, colorData.b, 1];
    dataField[dataField.length] = new Array(color,colorData.name);
    }
    }
}
         for(var i = 0; i < dataField.length ; i++ ){
             btna[i] = grpContainer.add("button", undefined, dataField[i][1]);             
             }
            updatePanel(win);
        };
    
        var btn2 = grpTab.add("button", undefined, "2");
        btn2.onClick = function () {
            cleanUpGroup(grpContainer);
            var btn2_1 = grpContainer.add("button", undefined, "2_1");
            var btn2_2 = grpContainer.add("button", undefined, "2_2");
            var btn2_3 = grpContainer.add("button", undefined, "2_3");
            var btn2_4 = grpContainer.add("button", undefined, "2_4");
            updatePanel(win);
        };
    
    
    
    
        var grpContainer = win.add("group");
        win.onResizing = win.onResize = function () {
            this.layout.resize();
        };
    
        win.onShow = function() {
            btn1.onClick();
        };
    
        if (win instanceof Window) {
            win.center();
            win.show();
        } else {
            win.layout.layout(true);
            win.layout.resize();
        }
    }
    function cleanUpGroup(container) {
        while (container.children[0]) {
            container.remove(container.children[0]);
        }
    }
    function updatePanel(win) {
        win.layout.layout(true);
    }
})(this);

 

Translate
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
Participant ,
Feb 18, 2020 Feb 18, 2020

Weirdly however. Adding this fixed my problem.

var btna = grpContainer.add;

for(var i = 0; i < dataField.length; i++){

var btna = grpContainer.add;

btna[i] = grpContainer.add("button", undefined, dataField[i][1]);

}

Translate
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
Advocate ,
Feb 19, 2020 Feb 19, 2020

It doesn't work for you, because btna is not defined;

 

The way you fixed/hacked it, is:

  1. You created a new variable var btna and assigned group.add() method to it. That's fine, btna is now defined;
  2. Then you go and treat btna variable as an array btna[i] - this makes little to no sense at all - it's a function, not an Array. Please don't do that, as it makes your code completelly unreadable. And that's where all future bugs start to happen.

 

Since there's no indication how you're using btna variable later on in your code, you could just as easy ditch this variable and create an unassigned button by simply typing grpContainer.add("button", undefined, dataField[i][1]);

Translate
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
Participant ,
Feb 19, 2020 Feb 19, 2020
LATEST

That makes sense. I thought that when I realised it was working for btn2.

 

As for btna[I], I just wanted to get the buttons loading in first which was great as it did it.

 

I then use btna[I].onClick to uniquely do something.

 

Cheers for all the help and advice. Really appreciate it.

Translate
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