Reopening dialog makes it none responsive

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Kukurykus, Tom, xbytor

schroef
Posts: 32
Joined: Sat Apr 11, 2020 6:22 am

Reopening dialog makes it none responsive

Post by schroef »

Im busy with a custom new documents dialog window. Everything works including color picker, preset for colors and frames and seconds.

I was trying to build in a preset system using json files. This also work now. The issue im having is using descriptor to reload them into inputs and dropdowns.
They way i try to set all the inputs and dropdowns is by using descriptortoBoject and ObjecttoDiscriptor. I had an issue with this becuse this normally is run just before when the dialog opens. So i reused that part and added a reuse variable, so if its true it uses preset defaults.

In order to get this to work in the dialog i need to close it, then reopen it. On Windows i see the dialog then close and reopen and everything works fine, also the dropdown menu. On OSX i dont see it close and reopen and also the dropdown menu dont respond anymore. When i did some checks, like removing that close function for the dialog. I do get one extra dialog and the old stays open, that means the close function does work.

Im wondering why those dropdowns dont seem to be responding to onChange function.

Lots of parts of this script are from the layer to files jsx file. In the core for the settings i use exportInfo for storing settings. The descriptorToObject and objectToDescriptor is also from this script.

Other buttons do keep responding. For instance ive got this reset buttons which basically reads the default exportInfo settings, runs them through the obecjtToDescriptor, close the window and then reopens it. Weird things is, after this button, the dropdown sill dont work yet the reset button, cancel and ok button do work?!
Attachments
Screen Shot 2022-01-12 at 16.07.34.png
Screen Shot 2022-01-12 at 16.07.34.png (67.06 KiB) Viewed 989 times

User avatar
Kukurykus
Posts: 451
Joined: Mon Jul 25, 2016 12:36 pm

Re: Reopening dialog makes it none responsive

Post by Kukurykus »

Share basic dialog with only part you have a problem together with descriptor code you want to use with.

schroef
Posts: 32
Joined: Sat Apr 11, 2020 6:22 am

Re: Reopening dialog makes it none responsive

Post by schroef »

Kukurykus wrote:
Thu Jan 13, 2022 12:44 am
Share basic dialog with only part you have a problem together with descriptor code you want to use with.
Sorry, but i dont quite understand the first part of your reply..

I was already thinking this explanation isnt good enough. Ive made a simple dialog, though this one works without objectToDescriptor and descriptorToObject. I get the same issue, as soon as the dialog closes and reopen on OSX, the dropdown menu dont work. on WIndows this works fine, there i see the dialog hide and show for half a second orso. Photoshop in Windows is sluggish for me, its not as smooth as Photoshop on OSX.

On OSX i dont even the see the dialog close and reopen, its either super super fast or its not closing at all. Perhaps i should add a $.sleep(500) orso, then im sure it closes

Okay here's the example, its really simple. You pick something from the dropdown menu, the window will close/reopen and it will still show that item and the message string part with show it as well. THe reset puts all back to default. cancel and ok do nothing.

Ive another script which also uses this method, it closes and reopens the main dialog to show other dialogs windows. That one seems to work just fune. But that doesnt use descriptorToObject. Should not matter, my little example also diesnt work. On Windows its fine, works as intended.
Super simple dialog
Super simple dialog
Screen Shot 2022-01-13 at 10.19.34.png (24.3 KiB) Viewed 968 times

Code: Select all

// Add objectToDescriptor / discriptorToObject function, see if this works on mac


/*
Code for Import https://scriptui.joonas.me — (Triple click to select): 
{"activeId":0,"items":{"item-0":{"id":0,"type":"Dialog","parentId":false,"style":{"enabled":true,"varName":"dialogWindow","windowType":"Dialog","creationProps":{"su1PanelCoordinates":false,"maximizeButton":false,"minimizeButton":false,"independent":false,"closeButton":true,"borderless":false,"resizeable":false},"text":"Dialog Test","preferredSize":[300,0],"margins":16,"orientation":"column","spacing":10,"alignChildren":["center","top"]}},"item-1":{"id":1,"type":"Panel","parentId":0,"style":{"enabled":true,"varName":null,"creationProps":{"borderStyle":"etched","su1PanelCoordinates":false},"text":"Panel","preferredSize":[250,0],"margins":10,"orientation":"row","spacing":10,"alignChildren":["left","top"],"alignment":null}},"item-4":{"id":4,"type":"Group","parentId":0,"style":{"enabled":true,"varName":"btnsGrp","preferredSize":[0,0],"margins":0,"orientation":"row","spacing":10,"alignChildren":["right","center"],"alignment":"fill"}},"item-5":{"id":5,"type":"Button","parentId":4,"style":{"enabled":true,"varName":"okBtn","text":"OK","justify":"center","preferredSize":[0,0],"alignment":null,"helpTip":null}},"item-6":{"id":6,"type":"Button","parentId":4,"style":{"enabled":true,"varName":"cancelBtn","text":"Cancel","justify":"center","preferredSize":[0,0],"alignment":null,"helpTip":null}},"item-7":{"id":7,"type":"Button","parentId":4,"style":{"enabled":true,"varName":"resetBtn","text":"Reset","justify":"center","preferredSize":[0,0],"alignment":null,"helpTip":null}},"item-8":{"id":8,"type":"StaticText","parentId":1,"style":{"enabled":true,"varName":"messageStt","creationProps":{"truncate":"none","multiline":false,"scrolling":false},"softWrap":false,"text":"Message","justify":"left","preferredSize":[0,0],"alignment":"fill","helpTip":null}},"item-9":{"id":9,"type":"DropDownList","parentId":1,"style":{"enabled":true,"varName":"menuDD","text":"DropDownList","listItems":"Item 1, -, Item 2,Item 3, Item 4","preferredSize":[0,0],"alignment":null,"selection":0,"helpTip":null}}},"order":[0,1,9,8,4,7,6,5],"settings":{"importJSON":true,"indentSize":false,"cepExport":false,"includeCSSJS":true,"showDialog":true,"functionWrapper":false,"afterEffectsDockable":false,"itemReferenceList":"None"}}
*/
// ok and cancel button
var runButtonID = 1;
var cancelBtnID = 2;
var exportInfo = new Object();

function initExportInfo(exportInfo) {
    exportInfo.message = "Message";
    exportInfo.dropDown = 0;
}

function settingDialog(exportInfo) {
    // DIALOGWINDOW
    // ============
    var dialogWindow = new Window("dialog");
    dialogWindow.text = "Dialog Test";
    dialogWindow.preferredSize.width = 300;
    dialogWindow.orientation = "column";
    dialogWindow.alignChildren = ["center", "top"];
    dialogWindow.spacing = 10;
    dialogWindow.margins = 16;

    // PANEL1
    // ======
    var panel1 = dialogWindow.add("panel", undefined, undefined, {
        name: "panel1"
    });
    panel1.text = "Panel";
    panel1.preferredSize.width = 250;
    panel1.orientation = "row";
    panel1.alignChildren = ["left", "top"];
    panel1.spacing = 10;
    panel1.margins = 10;

    var menuDD_array = ["Item 1", "-", "Item 2", "Item 3", "Item 4"];
    var menuDD = panel1.add("dropdownlist", undefined, undefined, {
        name: "menuDD",
        items: menuDD_array
    });
    menuDD.selection = exportInfo.dropDown;

    var messageStt = panel1.add("statictext", undefined, undefined, {
        name: "messageStt"
    });
    messageStt.text = exportInfo.message; //"Message"; 
    messageStt.alignment = ["left", "fill"];

    // BTNSGRP
    // =======
    var btnsGrp = dialogWindow.add("group", undefined, {
        name: "btnsGrp"
    });
    btnsGrp.orientation = "row";
    btnsGrp.alignChildren = ["right", "center"];
    btnsGrp.spacing = 10;
    btnsGrp.margins = 0;
    btnsGrp.alignment = ["fill", "top"];

    var resetBtn = btnsGrp.add("button", undefined, undefined, {
        name: "resetBtn"
    });
    resetBtn.text = "Reset";

    var cancelBtn = btnsGrp.add("button", undefined, undefined, {
        name: "cancelBtn"
    });
    cancelBtn.text = "Cancel";

    var okBtn = btnsGrp.add("button", undefined, undefined, {
        name: "okBtn"
    });
    okBtn.text = "OK";

    menuDD.onChange = function() {
        messageStt.text = this.selection.text;
        exportInfo.message = menuDD.selection.text;
        exportInfo.dropDown = menuDD.selection.index;
        dialogWindow.close(cancelBtnID);
        newProjectDialog(reuse = false);
    }

    resetBtn.onClick = function() {
        menuDD.selection = 0;
        messageStt.text = "Sleep 3 seconds";
        exportInfo.message = menuDD.selection.text;
        // alert(exportInfo.message)
        // $.sleep(100);
        // $.sleep(3000);
        dialogWindow.close(cancelBtnID);
        newProjectDialog(reuse = true);
    }
    cancelBtn.onClick = function() {
        dialogWindow.close(cancelBtnID);
        alert("Canceled")
    }

    okBtn.onClick = function() {
        dialogWindow.close(runButtonID);
        alert("Done")
    }

    // in case we double clicked the file
    app.bringToFront();
    dialogWindow.center();

    // dialogWindow.show();
    var result = dialogWindow.show();

    if (cancelBtnID == result) {
        return result; // close to quit
    }
}

function newProjectDialog(reuse) {
    app.playbackDisplayDialogs = DialogModes.ALL;
    if (reuse) {
        initExportInfo(exportInfo);
    }
    if (DialogModes.ALL == app.playbackDisplayDialogs) {
        if (cancelBtnID == settingDialog(exportInfo)) {
            return "cancel"; // quit, returning "cancel" (dont localize) makes the actions palette not record our script
        }
    }
    app.playbackDisplayDialogs = DialogModes.ALL;
}

newProjectDialog(reuse = true)

schroef
Posts: 32
Joined: Sat Apr 11, 2020 6:22 am

Re: Reopening dialog makes it none responsive

Post by schroef »

My other solution now is read all the items from exportInfo and set them directly in the same onChange function, so im skipping the close and reopen window. This seems to be working. Yet im still wondering why closing and reopen the dialog makes the dropdown menu render useless. The other script i have using same princeple of closing and reopening dialog window works just fine.

So my function for the preset dropdown now looks like this. I know its different then the example i showed earlier, but that original file im working in is quite extended. Now i need to check if this also works on Windows. What i dislike about i, is when i add or change something in the exportInfo now, i need to adjust many instance where i read and write it back into the dialog.

Code: Select all

presetListDropDown.onChange = function(){
            // cancel main dialog window
            // load JSON preset
            var presetFile = presetListDropDown.selection.text;
            var presetsJSON = loadJsonPresetDoc(presetFile);
            // initExportInfo(presetsJSON)
            // alert(presetsJSON.docName)
            // Use last set items
            var d = objectToDescriptor(presetsJSON, strMessage, preProcessExportInfo);
            app.putCustomOptions("d69fc733-75b4-4d5c-ae8a-c6d6f9a899aa", d);

            var dd = objectToDescriptor(presetsJSON, strMessage);
            app.playbackParameters = dd;

            descriptorToObject(presetsJSON, app.playbackParameters, strMessage, postProcessExportInfo);
            
            app.playbackDisplayDialogs = DialogModes.ALL;
        
            initExportInfo(exportInfo);
            descriptorToObject(exportInfo, app.playbackParameters, strMessage, postProcessExportInfo);
            
            // newDocCustomDialogBox.close(cancelButtonID);
            // $.sleep(1000)
            // // settingDialog(exportInfo);
            // newProjectDialog(reuse=true);

            projectnameInput.text = exportInfo.docName;
            // exportInfo.docColorMode = getColorMode(colormodeDropdown);//colormodeDropdown.selection.index
            colormodeDropdown.selection.index = exportInfo.docColorModeIndex;
            heightInput.text = exportInfo.docHeight;
            widthInput.text = exportInfo.docWidth;
            colorprofileDropdown.selection.index = exportInfo.docICC;//getColorProfile(colorprofileDropdown);
            bitDepthDropdown.selection.index = exportInfo.docBitD;//getBitDepth(bitDepthDropdown);
            resolutionInput.text = exportInfo.docDPI;

            // Timeline Settings
            durationInput.text = exportInfo.tmlnDuration;
            fpsInput.text = exportInfo.tmlnFps;
            fpsDropdown.selection.index = exportInfo.fpsPreset;

            // Background Color
            projectBgGrp.backgroundColor = exportInfo.projectBgColor; // this is RGB we need HSB
            projectBgGrp.bgSelection.selection = exportInfo.projectBgColorIndex;
            // alert(exportInfo.projectBgColorIndex)
            // Extra Options
            splitTmlnCheck.value = exportInfo.splitTmln;
            splitTmlnDropdown.selection.index = exportInfo.splitTmlnIndex;
        }

schroef
Posts: 32
Joined: Sat Apr 11, 2020 6:22 am

Re: Reopening dialog makes it none responsive

Post by schroef »

I got everything working now inlcuding the color picker, its also changes color now when i use one of the preset. Now i need to clean code and see where i can make parts of the code simpler and perhaps see where i can reuse code make new function.

Still need to check if this also still works in Windows. And still need to check why these darn dropdown's render useless. Found another script i made while back, uses sort of the same method. Closes a dialog, opens a new dialog, that one also works jsut fine.

User avatar
Kukurykus
Posts: 451
Joined: Mon Jul 25, 2016 12:36 pm

Re: Reopening dialog makes it none responsive

Post by Kukurykus »

So I understand you must reopen dialog to update the descriptor? Isn't it possible to use palette to do the same without reopning current window?

schroef
Posts: 32
Joined: Sat Apr 11, 2020 6:22 am

Re: Reopening dialog makes it none responsive

Post by schroef »

Well at the time i didnt know an easy method of reading the JSON preset and setting all input fields and dropdown menus with the settings from that preset file. So my workaround was read the preset send it to the descriptor, so its read as last used setting. Then reopen the main dialog so it would read those settings. As i got mixed results now and some custom script do work using this same approach, i kinda gave up on that method.

Now i simply read the settings and set the inputs, dropdown etc directly. Then when the document is created it does send it to descriptor correctly.

Still wondering why with other scripts this closing and reopening the main dialog work and dropdown menu keeps working. The issue occurs on OSX only, yet other scripts still work on OSX using the same method. Weird right?!

Im sort of glad i got it to work how its intended, if its clean coding, i doubt. :)

Still need to improve couple scripts as iv not optimized it properly.

I dont really like palettes since they act strange and dont have interaction i want.