Author Topic: [PJSR] How to know screen size ?  (Read 6331 times)

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
[PJSR] How to know screen size ?
« on: 2013 January 30 21:34:52 »
Is there a way in PI PJSR to kown the whole screen size.  If not, at lesat to know the workspace size ?  On some script the dialog is larger than the screen (on portable PC), so I would like to make the dialog size depends on the screen size.
-- bitli
Thanks

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: [PJSR] How to know screen size ?
« Reply #1 on: 2013 February 11 03:34:07 »
Currently you cannot know the screen size directly from a JavaScript script in PixInsight. I am considering a new core JavaScript object to provide information like display metrics, system folders, memory limits, etc. This could be a System object.

On X11 (FreeBSD  and Linux) you can use xrandr to find the current screen geometry. For example:

Code: [Select]
xrandr -q | grep Screen
which on my workstation gives:

Screen 0: minimum 320 x 200, current 2560 x 1440, maximum 2560 x 2560

Using the ExternalProcess object it is very easy to get xrandr's output, where one can find the required information:

Code: [Select]
var X = new ExternalProcess( "xrandr", ["-q"] );
console.writeln( "<raw>" + X.standardOutput + "</raw>" );

I don't know if similar commands exist on Windows or Mac OS X.

Besides that, if you need to know screen dimensions, that's probably because you're trying to do something nonportable. If you design your script's dialog to fit well in a reasonable screen resolution, such as 1280x960 for example, there should be no problems.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Re: [PJSR] How to know screen size ?
« Reply #2 on: 2013 February 11 05:00:18 »
Thanks,
The goal is to make the window reasonable on a normal screen (so the user does not have to resize it), but usable on a small screen (like 1300x760). 

I agree that it is too small to make significant work, but this is often what we have when we do demo or tutorial of PI (either because small portable screen or because we have a low-end projector). Surely the goal is worth some compromise ?

More specifically the dialog consists of a fixed sized dialog and a variable list that should be as large as possible (like in FITSFileManager). I tried to put a minimal size on the variable part of the window, and a desired (larger) size as default, so that the window manager makes the window smaller if needed. Unfortunately the window is not correctly reduced on some OS.  I think I reported this on another thread. So an alternative would be to make the iminal size depends on screen size. Or any other solution.

From a philosophical point of view, I do not think that trying to make the program work on a variety of hardware is limiting the portability... but this is better discussed late evening around a beer   :)

-- bitli

 

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Re: [PJSR] How to know screen size ?
« Reply #3 on: 2013 February 11 06:51:45 »
Bitli,
maybe you can start the GUI initially with a small size, and store the user selected size as a default once the user leaves the script. This should be a way to  adapt to the users screen without actually knowing its dimensions.
Georg
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Re: [PJSR] How to know screen size ?
« Reply #4 on: 2013 February 11 08:18:15 »
Yes, this is an alternative I am pursuing.  Thanks.  -- bitli

Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729
Re: [PJSR] How to know screen size ?
« Reply #5 on: 2013 February 11 08:18:58 »
osx:  system_profiler SPDisplaysDataType | grep Resolution


Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Re: [PJSR] How to know screen size ?
« Reply #6 on: 2013 March 20 13:53:11 »
Much better way on PI RC 4, you can get screen parameters from the global settings. Example below:
Code: [Select]
#include <pjsr/DataType.jsh>
Console.writeln(Settings.readGlobal("/MainWindow/Geometry/Width",DataType_UInt32));
Console.writeln(Settings.readGlobal("/MainWindow/Geometry/Height",DataType_UInt32));
Console.writeln(Settings.readGlobal("/MainWindow/Geometry/FullScreen",DataType_Boolean));
Console.writeln(Settings.readGlobal("/MainWindow/Geometry/Maximized",DataType_Boolean));
Console.writeln(Settings.readGlobal("/MainWindow/Geometry/DesktopWidth",DataType_UInt32));
Console.writeln(Settings.readGlobal("/MainWindow/Geometry/DesktopHeight",DataType_UInt32));
Console.writeln(Settings.readGlobal("/MainWindow/Geometry/PrimaryScreenWidth",DataType_UInt32));
Console.writeln(Settings.readGlobal("/MainWindow/Geometry/PrimaryScreenHeight",DataType_UInt32));
This seems to work on Windows and Linux, however I do not know if this will be valid in the future. But it is convenient.

-- bitli