88 script.exit()
99 ```
1010"""
11- #pylint: disable=consider-using-f-string
11+ # pylint: disable=consider-using-f-string
1212
1313import sys
1414import os
3838# suppress any warning generated by native or third-party modules
3939warnings .filterwarnings ("ignore" )
4040
41- #pylint: disable=W0703,C0302,C0103,W0614
41+ # pylint: disable=W0703,C0302,C0103,W0614
4242mlogger = logger .get_logger (__name__ )
4343
4444
@@ -807,8 +807,8 @@ def restore_window_position(window, command_name=EXEC_PARAMS.command_name):
807807 Restore window position from saved data.
808808
809809 Args:
810- window: WPF window instance
811- command_name: Unique identifier for this window
810+ window (System.Windows.Window) : WPF window instance
811+ command_name (str) : Unique identifier for this window
812812
813813 Returns:
814814 bool: True if position was restored, False if centered to screen
@@ -820,26 +820,27 @@ def restore_window_position(window, command_name=EXEC_PARAMS.command_name):
820820 if not pos :
821821 raise Exception ("No saved position" )
822822
823- # Get all screen working areas
824- all_bounds = [s .WorkingArea for s in framework .Forms .Screen .AllScreens ]
825- x , y = pos .get ("Left" , 0 ), pos .get ("Top" , 0 )
826-
827- # Check if position is visible on any screen
828- visible = any (
829- (b .Left <= x <= b .Right and b .Top <= y <= b .Bottom ) for b in all_bounds
823+ left , top , width , height = (
824+ pos .get ("Left" , 0 ),
825+ pos .get ("Top" , 0 ),
826+ pos .get ("Width" , window .Width ),
827+ pos .get ("Height" , window .Height ),
830828 )
831829
832- if visible :
830+ if coreutils . is_box_visible_on_screens ( left , top , width , height ) :
833831 window .WindowStartupLocation = (
834832 framework .Windows .WindowStartupLocation .Manual
835833 )
836- window .Left = x
837- window .Top = y
834+ window .Left = left
835+ window .Top = top
836+ window .Width = width
837+ window .Height = height
838838 return True
839839 else :
840840 raise Exception ("Position not visible on any screen" )
841841
842- except Exception :
842+ except Exception as ex :
843+ mlogger .debug ("Could not restore window position: %s" , ex )
843844 window .WindowStartupLocation = (
844845 framework .Windows .WindowStartupLocation .CenterScreen
845846 )
@@ -851,9 +852,14 @@ def save_window_position(window, command_name=EXEC_PARAMS.command_name):
851852 Save window position to persistent storage.
852853
853854 Args:
854- window: WPF window instance
855- command_name: Unique identifier for this window
855+ window (System.Windows.Window) : WPF window instance
856+ command_name (str) : Unique identifier for this window
856857 """
857858 storage_key = "last_window_position_" + command_name
858- position_data = {"Left" : window .Left , "Top" : window .Top }
859+ position_data = {
860+ "Left" : window .Left ,
861+ "Top" : window .Top ,
862+ "Width" : window .ActualWidth ,
863+ "Height" : window .ActualHeight
864+ }
859865 store_data (storage_key , position_data , this_project = False )
0 commit comments