Static text with multiline

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

d3mac123

Static text with multiline

Post by d3mac123 »

I am trying to create a replacement for the original alert function, because on Windows it shows as an "Script Alert", which confuses users (some of them think this is an error). This is what I am trying to do:
Code: Select allfunction alerta(title,header, msg) {
    var imgFile = File("/Applications/Adobe\ Photoshop\ CS5/Plug-ins/Panels/Kwik/images/portrait.png");
    var z = "dialog { alignChildren: 'right', orientation:'row', text: '', \
            img: Image {}, \
             header: Group {orientation: 'column', alignment:'left',  \
                    s: StaticText {text: 'Name:', alignment:'left'}, \
                    msg: StaticText {text: 'Name:', alignment:'left',}, \
                    msgEmpty: StaticText {text: '', alignment:'left',}, \
                    cb: Button {text:'OK', name:'cancel', alignment: 'right'},\
             } \
    }";
    zf = new Window (z);
   
    zf.text = title
    zf.header.s.text = header
    zf.header.s.graphics.font = ScriptUI.newFont ("dialog", "Bold", 12)
    zf.header.msg.text = msg
    zf.header.msg.multiline = true


    zf.img.image = imgFile;
   
    zf.show()
}


alerta("Important Alert", "Pay Attention", "You must select blue. \rThen yellow!")


The problem is, the multiline does not work. In the message above, only "You must select blue." shows up. Any idea what am I doing wrong?
Thanks a lot!
Alex

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

Static text with multiline

Post by Mike Hale »

I can't show you how to fix it using resource strings but I think the problem is multiline is what Adobe calls a creation property and needs to be supplied when the control is defined/created. Adding it later doesn't work.
Code: Select allvar w = new Window ('dialog', 'title');
w.st = w.add('statictext',undefined,'');
w.st.multiline =  true;// doesn't make the control multiline
w.st.text = 'You must select blue. \rThen yellow!';
w.show();
var w = new Window ('dialog', 'title');
w.st = w.add('statictext',undefined,'',{multiline:true});
w.st.text = 'You must select blue. \rThen yellow!';
w.show();
undavide

Static text with multiline

Post by undavide »

Strangely the following doesn't work:

Code: Select alls: StaticText {text: 'Name:', alignment:'left', properties: { multiline: 'true' } }, \

(tried multiline, Multiline, MultiLine, true, 'true' to no avail - wild guessing)

Davide
Mike Hale

Static text with multiline

Post by Mike Hale »

I guess when all else fails - read the manual.

Code: Select allmsg: StaticText {text: 'Name:', alignment:'left',properties:{multiline:true},}, \
cbourn

Static text with multiline

Post by cbourn »

Code: Select allvar dlg = new Window ('dialog');
dlg.preferredSize = [200, 200];
var txt = dlg.add('statictext', undefined, 'Multiline Output\nSecond Line\nThird Line', {multiline: true});
txt.preferredSize = [200, 200];
Sizes are useful for word wrap customization.
Mike Hale

Static text with multiline

Post by Mike Hale »

You don't need the lineCode: Select alldlg.preferredSize = [200, 200];The ScriptUI auto layout will size the window to fit it's contents.

You can also specify just width or height if only one is neededCode: Select alltxt.preferredSize.height = 200;

And because of the default spacing around controls, auto layout will make the window larger than the specified 200,200 because you set the size of one of the controls to those values.

Finally setting the size is really only needed when you either don't set the text so auto layout can't determine the size, or if you are trying to fine tune auto layout.