Determining window size

This thread relates to the one on supporting clients with varying resolutions. We have experimented with various relative and fixed layouts with anchors. These settings are OK for some screen resizing, but some issues like widescreen vs 4:3, can’t really be gotten around. You pretty much end up leaving a bunch of empty real estate on one side if you want a 4:3 aspect ratio client to be able to view the screen acceptably.

I was wondering if there was any way to know in scripting what the size of the Vision window is and what the size of the client desktop is. That way we might be able to have differing default layouts and screens for various clients. I don’t see anything in the system area of the scripting manual.

Thanks for your assistance.

Yes, you’re right - making content that look equally good on standard aspect ratio and wide-screen aspect ratio is downright hard (not just in our software either - this is pretty much true for anything).

Getting the size of an open window from an event handler is easy:

window = system.gui.getParentWindow(event) print "Window size is: %dx%d" % (window.width, window.height)

Getting the size of the client also possible from an event handler:

[code]from javax.swing import JFrame, SwingUtilities

window = system.gui.getParentWindow(event)

frame = SwingUtilities.getAncestorOfClass(JFrame, window)
print “Frame size is: %dx%d” % (frame.width, frame.height)[/code]

Hope this helps,

Thanks, Carl. That is a big help.

I tried that out and it works well to get the size of a window and the size of the frame that Ignition is filling. This one might be trickier since it needs to get information from the client OS… Is there a way to get the size of the operating system desktop?

Sure, thats no problem.

[code]from java.awt import GraphicsEnvironment

env = GraphicsEnvironment.getLocalGraphicsEnvironment()
screen = env.getDefaultScreenDevice()
size = screen.getDefaultConfiguration().bounds
print “The main screen is %dx%d” % (size.width, size.height)[/code]

You can get the screen size of any other monitors too by looping through the results of [tt]env.getScreenDevices()[/tt]

[quote=“MCC”]…but some issues like widescreen vs 4:3, can’t really be gotten around. You pretty much end up leaving a bunch of empty real estate on one side if you want a 4:3 aspect ratio client to be able to view the screen acceptably…[quote]

Fwiw, I had the same issue at a customer site. They had everything from nice wide screens to small 4:3 monitors. I didn’t want separate screens or projects, so I ended up using the setFont, resizeComponent, and moveComponent functions to dynamically populate the screen upon opening. I did it by detecting the size of the containers, but windows would work the same way.

It came out very nice, and the screens look great even on the cheesyist monitors.

Hi,
Step7, could you share your code. I’d like to use it on Perspective Module, is it possible?

Step7’s code would be for Vision Windows which means it will not work for Perspective. Many users have requested this feature for Perspective, but few have actually upvoted the requested feature.

Dear Carl. Please Help!! I don’t know where I should run this code.
On a component? on a window? on a script console?

when I run it on script console I get:

SyntaxError: (u"no viable alternative at character '\u201c'", ('<input>', 5, 6, u'print \u201cThe main screen is %dx%d\u201d % (size.width, size.height)\n'))

That error is due to the curly quotes “” around the print statement (many text editors auto-replace straight quotes with these, and forum upgrade since original post may have done so). Replace them with straight quotes "" and it will run in the script console.

from java.awt import GraphicsEnvironment

env = GraphicsEnvironment.getLocalGraphicsEnvironment()
screen = env.getDefaultScreenDevice()
size = screen.getDefaultConfiguration().bounds
print "The main screen is %dx%d" % (size.width, size.height)
>>> 
The main screen is 1366x768
>>> 
1 Like

oh wow. Thanks for your help. It worked

It would be nice if I could login to vote. Perhaps there is something broken with the Ignition Features and Ideas site.

There is a way to determine screen width (viewport) in Perspective. We are using the result regularly to modify tag history query density, adjust font, etc. I have held back on posting how to do it so Inductive could post a more controlled solution. What are your plans?

There is. It delegates to canny.io via a third-party cookie. Tight browser security breaks this. A secure method of passing the session status is in the works, but I haven’t received a time estimate.

We’ve had an internal ticket to provide viewport properties as a new feature for over a year now. There does seem to have been some bookkeeping done on the ticket recently so it’s not something I would consider to be “lost in the ether”, but it’s also not a priority.

The feature would include viewport dimensions, screen dimensions, and scroll values as session properties.