@@ -155,6 +155,17 @@ def scientific_notation(x, sigfigs=4, mode='eng'):
155
155
return result
156
156
157
157
158
+ def get_screen_geometry ():
159
+ """Return the a list of the geometries of each screen: each a tuple of
160
+ left, top, width and height"""
161
+ geoms = []
162
+ desktop = qapplication .desktop ()
163
+ for i in range (desktop .screenCount ()):
164
+ sg = desktop .screenGeometry (i )
165
+ geoms .append ((sg .left (), sg .top (), sg .width (), sg .height ()))
166
+ return geoms
167
+
168
+
158
169
class WebServer (ZMQServer ):
159
170
160
171
def handler (self , request_data ):
@@ -1950,8 +1961,10 @@ def get_save_data(self):
1950
1961
window_size = self .ui .size ()
1951
1962
save_data ['window_size' ] = (window_size .width (), window_size .height ())
1952
1963
window_pos = self .ui .pos ()
1964
+
1953
1965
save_data ['window_pos' ] = (window_pos .x (), window_pos .y ())
1954
1966
1967
+ save_data ['screen_geometry' ] = get_screen_geometry ()
1955
1968
save_data ['splitter' ] = self .ui .splitter .sizes ()
1956
1969
save_data ['splitter_vertical' ] = self .ui .splitter_vertical .sizes ()
1957
1970
save_data ['splitter_horizontal' ] = self .ui .splitter_horizontal .sizes ()
@@ -2022,31 +2035,44 @@ def load_configuration(self, filename):
2022
2035
self .filebox .last_opened_shots_folder = ast .literal_eval (lyse_config .get ('lyse_state' , 'LastFileBoxFolder' ))
2023
2036
except (LabConfig .NoOptionError , LabConfig .NoSectionError ):
2024
2037
pass
2025
- try :
2026
- self .ui .resize (* ast .literal_eval (lyse_config .get ('lyse_state' , 'window_size' )))
2027
- except (LabConfig .NoOptionError , LabConfig .NoSectionError ):
2028
- pass
2029
- try :
2030
- self .ui .move (* ast .literal_eval (lyse_config .get ('lyse_state' , 'window_pos' )))
2031
- except (LabConfig .NoOptionError , LabConfig .NoSectionError ):
2032
- pass
2033
2038
try :
2034
2039
if ast .literal_eval (lyse_config .get ('lyse_state' , 'analysis_paused' )):
2035
2040
self .filebox .pause_analysis ()
2036
2041
except (LabConfig .NoOptionError , LabConfig .NoSectionError ):
2037
2042
pass
2038
2043
try :
2039
- self .ui .splitter .setSizes (ast .literal_eval (lyse_config .get ('lyse_state' , 'splitter' )))
2040
- except (LabConfig .NoOptionError , LabConfig .NoSectionError ):
2041
- pass
2042
- try :
2043
- self .ui .splitter_vertical .setSizes (ast .literal_eval (lyse_config .get ('lyse_state' , 'splitter_vertical' )))
2044
- except (LabConfig .NoOptionError , LabConfig .NoSectionError ):
2045
- pass
2046
- try :
2047
- self .ui .splitter_horizontal .setSizes (ast .literal_eval (lyse_config .get ('lyse_state' , 'splitter_horizontal' )))
2044
+ screen_geometry = ast .literal_eval (lyse_config .get ('lyse_state' , 'screen_geometry' ))
2048
2045
except (LabConfig .NoOptionError , LabConfig .NoSectionError ):
2049
2046
pass
2047
+ else :
2048
+ # Only restore the window size and position, and splitter
2049
+ # positions if the screen is the same size/same number of monitors
2050
+ # etc. This prevents the window moving off the screen if say, the
2051
+ # position was saved when 2 monitors were plugged in but there is
2052
+ # only one now, and the splitters may not make sense in light of a
2053
+ # different window size, so better to fall back to defaults:
2054
+ current_screen_geometry = get_screen_geometry ()
2055
+ if current_screen_geometry == screen_geometry :
2056
+ try :
2057
+ self .ui .resize (* ast .literal_eval (lyse_config .get ('lyse_state' , 'window_size' )))
2058
+ except (LabConfig .NoOptionError , LabConfig .NoSectionError ):
2059
+ pass
2060
+ try :
2061
+ self .ui .move (* ast .literal_eval (lyse_config .get ('lyse_state' , 'window_pos' )))
2062
+ except (LabConfig .NoOptionError , LabConfig .NoSectionError ):
2063
+ pass
2064
+ try :
2065
+ self .ui .splitter .setSizes (ast .literal_eval (lyse_config .get ('lyse_state' , 'splitter' )))
2066
+ except (LabConfig .NoOptionError , LabConfig .NoSectionError ):
2067
+ pass
2068
+ try :
2069
+ self .ui .splitter_vertical .setSizes (ast .literal_eval (lyse_config .get ('lyse_state' , 'splitter_vertical' )))
2070
+ except (LabConfig .NoOptionError , LabConfig .NoSectionError ):
2071
+ pass
2072
+ try :
2073
+ self .ui .splitter_horizontal .setSizes (ast .literal_eval (lyse_config .get ('lyse_state' , 'splitter_horizontal' )))
2074
+ except (LabConfig .NoOptionError , LabConfig .NoSectionError ):
2075
+ pass
2050
2076
2051
2077
# Set as self.last_save_data:
2052
2078
save_data = self .get_save_data ()
0 commit comments