I have 4 windows, a header, a footer, a sidebar for navigation, and a main window with a plot. From time to time users want need to watch the plot from afar as they make adjustments to a DUT to troubleshoot a problem. My goal is to make the one window with the plot full-screen and leave the other windows untouched and to have a button that can move back and forth between full-screen and the way the windows were before.
Attempts:
I have the following hacky code working to solve this problem. It shows an expand icon in a button on the plot when the window opens initially or after updates (updates also exit full-screen mode automatically so this luckily works pretty well). When the user clicks the button, I make the plot window full-screen and change to a shrink icon on the button.
This solution works currently, but it is hackyâŚ
I set the window to always on top and use that as a check to see if I am currently in full-screen and need to shrink instead of expand the window to full-screen. When an update comes in the windows snap back to their normal positions though and sometimes I have to hit the button twice after this to go to full-screen.
`from javax.swing import JFrame, SwingUtilities
'''
The purpose of this script is to enable full-screen for the PIM plot window,
to make data visually easier from afar.
'''
def show_window_full_screen(win_name = 'testing/pim_swept'):
internal_frame = system.gui.getWindow(win_name)
win = SwingUtilities.getWindowAncestor(internal_frame)
internal_frame.setSize(win.getSize())
internal_frame.setLocation(0,0)
win.dispose()
win.setAlwaysOnTop(True)
win.setExtendedState(JFrame.MAXIMIZED_BOTH)
win.setUndecorated(True)
win.setVisible(True)
def exit_full_screen(win_name = 'testing/pim_swept'):
internal_frame = system.gui.getWindow(win_name)
win = SwingUtilities.getWindowAncestor(internal_frame)
win.dispose()
win.setAlwaysOnTop(False)
win.setUndecorated(False)
win.setVisible(True)
win_name = 'testing/pim_swept'
internal_frame = system.gui.getWindow(win_name)
win = SwingUtilities.getWindowAncestor(internal_frame)
if not win.isAlwaysOnTop():
system.util.invokeLater(show_window_full_screen,50)
system.util.invokeLater(show_window_full_screen,250)
event.source.path = 'shrink.png'
else:
exit_full_screen(win_name)
event.source.path = 'expand.png'
`
Before:
After:
Question:
Does anyone have a less hacky solution to this problem?
Update:
Trying to go completely full-screen (without the header bar and hiding the taskbar on the computer) creates too many problems. I have resolved to just use the following functions to achieve my goal.
I had to add a timer just to update the icon on the button in case an update came in when one of the internal frames is maximized, because everything snaps back to their original positions but the icon is stuck on the shrink icon. The timer script fixed this by checking if my plot window is visually intersecting another window I know will always be present.
component scripts on the full-screen button to enter/exit full-screen for the plot.
def enter_full_screen(winname):
from javax.swing import SwingUtilities, JFrame
internal_frame = system.gui.getWindow(winname)
win = SwingUtilities.getWindowAncestor(internal_frame)
internal_frame.setSize(win.getContentPane().getSize())
internal_frame.setLocation(0,0)
internal_frame.moveToFront()
internal_frame.setSelected(True)
def exit_full_screen(winname):
from javax.swing import SwingUtilities
win = SwingUtilities.getWindowAncestor(system.gui.getWindow(winname))
win.dispose()
win.setVisible(True)
The timer script to reset the icon by checking if the other window is getting covered upâŚ
win_name = 'testing/test_window'
c1 = system.gui.getWindow(win_name)
c2 = system.gui.getWindow('testing/sugar')
is_covering_other_window = c1.getBounds().intersects(c2.getBounds())
if is_covering_other_window:
event.source.parent.getComponent('expand_compress_btn').path = 'shrink.png'
else:
event.source.parent.getComponent('expand_compress_btn').path = 'expand.png'
Again, hacky solutionâŚbut no one seems to have a better one. If you do, please reply!