Skip to main content
Geppetto Luis
Legend
August 21, 2018
Answered

Memorize panel position

  • August 21, 2018
  • 2 replies
  • 1556 views

I use my panels on some PCs

at home, at work and to show my evolutions as friends

My problem and the position of the panel

with the script below I can position it where I want

but it happens that if the slide for 21-inch full-hd screens is not good for 27-inch screens or 17-inch notebooks

You can create a button to memorize the panel position

so once put at the point where I need to memorize the position

and I do not have to move it anymore.

Thanks again for everything you do for me and for others.

win = new Window("dialog", "test");

win.orientation = "column";

FC = win.add("group");

baton22 = FC.add("group");

Res = FC.add("button", undefined, "Memory position panel");

Res.onClick = function () {

}

closeBtn = FC.add("button", undefined, "ok");

closeBtn.onClose = function () {

win.close();

};

// position panel

win.onShow = function(){ 

  var ww = win.bounds.width; 

  var hh = win.bounds.height; 

  win.bounds.x  = 1000; 

  win.bounds.y  = 500; 

  win.bounds.width  = ww; 

  win.bounds.height  = hh; 

}  

// end

win.show();

This topic has been closed for replies.
Correct answer Kukurykus

Kukurykus  ha scritto

regarding 'evl = (...)' I didn't say to put it at beginning of code, but at beggining of win.onShow function.

I see that you did not read my last sentence as well. Your snippet looks unreadable, actually is awful

excuse in the trduction and lost the sense

your solution is fine

but then I close photoshop and then I reopen my memory and come back

everything like before

You can store it so when I reopen photoshop

do you stay as last position?


Of course it doesn't remember last position after you quit Photoshop, as it works only for Ps session. Why don't you save that position to .txt file, so it will work after you relaunch Photoshop as well. You know how to do it, don't you?

do you stay as last position?

It's bad translation, so it means nothing, can you ask the same correctly, as I have no idea what you ask for?

Put at top of your code:

fle = File(Folder.desktop + '/.txt')

Change Res.OnClick function to:

fle.open('w'), fle.writeln(win.frameLocation), fle.close()

Put at top of win.OnShow function:

fle.open('r'), r = fle.read(), fle.close()

evl = eval('[' + r + ']')

and use these lines in the same function:

win.bounds.x = r ? evl[0] : 1000

win.bounds.y = r ? evl[1] : 500

2 replies

Legend
August 21, 2018

Try using this method to save the window position.

Re: Preference in checkboxes in the user interface.

upd.

var settings = new File(app.preferencesFolder + "/My settings 12345.dat")

if (settings.exists) $.evalFile(settings);

var bounds_x; if (bounds_x == undefined) bounds_x = 1000;

var bounds_y; if (bounds_y == undefined) bounds_y = 500;

win = new Window("dialog", "test"); 

 

win.orientation = "column"; 

FC = win.add("group"); 

baton22 = FC.add("group"); 

 

Res = FC.add("button", undefined, "Memory position panel"); 

 

Res.onClick = function () { 

closeBtn = FC.add("button", undefined, "ok"); 

 

closeBtn.onClose = function () { 

win.close(); 

}; 

 

// position panel 

win.onShow = function(){   

  var ww = win.bounds.width;   

  var hh = win.bounds.height; 

  win.bounds.x = bounds_x;   

  win.bounds.y = bounds_y;   

  win.bounds.width  = ww;   

  win.bounds.height  = hh;

}    

win.onClose = function(){   

bounds_x = win.bounds.x;

bounds_y = win.bounds.y;

save_settings();

}

// end 

win.show(); 

function save_settings()

    {

    try

        {

        settings.open("w");

        settings.writeln("var bounds_x = " + bounds_x);

        settings.writeln("var bounds_y = " + bounds_y);

        if (settings.error) alert(settings.error);

        settings.close();

        }

    catch (e) { alert(e); }

    }

Kukurykus
Legend
August 21, 2018

Res.onClick = function() {alert(win.frameLocation)}

Geppetto Luis
Legend
August 21, 2018

Kukurykus

I already used it in the past

but it's not good for what I need

I would like it to memorize the position of the panel

with the memory button

so the next time I open the panel

automatically it is positioned where I memorized.

I hope I explained myself well

Kukurykus
Legend
August 21, 2018

Change last function I changed to:

Res.onClick = function() {$.setenv('fL', win.frameLocation)}

At beginning of win.onShow function put:

evl = eval('[' + (ge = $.getenv('fL')) + ']')

Finally change 2 lines in that function to:

win.bounds.x = ge ? evl[0] : 1000; win.bounds.y = ge ? evl[1] : 500

btw if you want others to change your codes why you don't care to compose them they were accessible by a way they look?