def readSettings(self, settings): qapp = QApplication.instance() # get the saved window geometry window_size = settings.get('MainWindow/size') if not isinstance(window_size, QSize): window_size = QSize(*window_size) window_pos = settings.get('MainWindow/position') if not isinstance(window_pos, QPoint): window_pos = QPoint(*window_pos) if settings.has('MainWindow/font'): font_string = settings.get('MainWindow/font').split(',') font = QFontDatabase().font(font_string[0], font_string[-1], int(font_string[1])) qapp.setFont(font) # reset font for ipython console to ensure it stays monospace self.ipythonconsole.console.reset_font() # make sure main window is smaller than the desktop desktop = QDesktopWidget() # this gives the maximum screen number if the position is off screen screen = desktop.screenNumber(window_pos) # recalculate the window size desktop_geom = desktop.availableGeometry(screen) w = min(desktop_geom.size().width(), window_size.width()) h = min(desktop_geom.size().height(), window_size.height()) window_size = QSize(w, h) # and position it on the supplied desktop screen x = max(window_pos.x(), desktop_geom.left()) y = max(window_pos.y(), desktop_geom.top()) if x + w > desktop_geom.right(): x = desktop_geom.right() - w if y + h > desktop_geom.bottom(): y = desktop_geom.bottom() - h window_pos = QPoint(x, y) # set the geometry self.resize(window_size) self.move(window_pos) # restore window state if settings.has('MainWindow/state'): if not self.restoreState(settings.get('MainWindow/state'), SAVE_STATE_VERSION): logger.warning( "The previous layout of workbench is not compatible with this version, reverting to default layout." ) else: self.setWindowState(Qt.WindowMaximized) # read in settings for children AlgorithmInputHistory().readSettings(settings) for widget in self.widgets: if hasattr(widget, 'readSettingsIfNotDone'): widget.readSettingsIfNotDone(settings)
def readSettings(self, settings): qapp = QApplication.instance() qapp.setAttribute(Qt.AA_UseHighDpiPixmaps) if hasattr(Qt, 'AA_EnableHighDpiScaling'): qapp.setAttribute(Qt.AA_EnableHighDpiScaling, settings.get('high_dpi_scaling')) # get the saved window geometry window_size = settings.get('MainWindow/size') if not isinstance(window_size, QSize): window_size = QSize(*window_size) window_pos = settings.get('MainWindow/position') if not isinstance(window_pos, QPoint): window_pos = QPoint(*window_pos) if settings.has('MainWindow/font'): font_string = settings.get('MainWindow/font').split(',') font = QFontDatabase().font(font_string[0], font_string[-1], int(font_string[1])) qapp.setFont(font) # make sure main window is smaller than the desktop desktop = QDesktopWidget() # this gives the maximum screen number if the position is off screen screen = desktop.screenNumber(window_pos) # recalculate the window size desktop_geom = desktop.availableGeometry(screen) w = min(desktop_geom.size().width(), window_size.width()) h = min(desktop_geom.size().height(), window_size.height()) window_size = QSize(w, h) # and position it on the supplied desktop screen x = max(window_pos.x(), desktop_geom.left()) y = max(window_pos.y(), desktop_geom.top()) if x + w > desktop_geom.right(): x = desktop_geom.right() - w if y + h > desktop_geom.bottom(): y = desktop_geom.bottom() - h window_pos = QPoint(x, y) # set the geometry self.resize(window_size) self.move(window_pos) # restore window state if settings.has('MainWindow/state'): self.restoreState(settings.get('MainWindow/state')) else: self.setWindowState(Qt.WindowMaximized) # read in settings for children AlgorithmInputHistory().readSettings(settings) for widget in self.widgets: if hasattr(widget, 'readSettings'): widget.readSettings(settings)
def readSettings(self, settings): qapp = QApplication.instance() qapp.setAttribute(Qt.AA_UseHighDpiPixmaps) if hasattr(Qt, 'AA_EnableHighDpiScaling'): qapp.setAttribute(Qt.AA_EnableHighDpiScaling, settings.get('high_dpi_scaling')) # get the saved window geometry window_size = settings.get('MainWindow/size') if not isinstance(window_size, QSize): window_size = QSize(*window_size) window_pos = settings.get('MainWindow/position') if not isinstance(window_pos, QPoint): window_pos = QPoint(*window_pos) # make sure main window is smaller than the desktop desktop = QDesktopWidget() # this gives the maximum screen number if the position is off screen screen = desktop.screenNumber(window_pos) # recalculate the window size desktop_geom = desktop.screenGeometry(screen) w = min(desktop_geom.size().width(), window_size.width()) h = min(desktop_geom.size().height(), window_size.height()) window_size = QSize(w, h) # and position it on the supplied desktop screen x = max(window_pos.x(), desktop_geom.left()) y = max(window_pos.y(), desktop_geom.top()) window_pos = QPoint(x, y) # set the geometry self.resize(window_size) self.move(window_pos) # restore window state if settings.has('MainWindow/state'): self.restoreState(settings.get('MainWindow/state')) else: self.setWindowState(Qt.WindowMaximized) # read in settings for children AlgorithmInputHistory().readSettings(settings) for widget in self.widgets: if hasattr(widget, 'readSettings'): widget.readSettings(settings)
def readSettings(self, settings): qapp = QApplication.instance() qapp.setAttribute(Qt.AA_UseHighDpiPixmaps) if hasattr(Qt, 'AA_EnableHighDpiScaling'): qapp.setAttribute(Qt.AA_EnableHighDpiScaling, settings.get('main/high_dpi_scaling')) # get the saved window geometry window_size = settings.get('main/window/size') if not isinstance(window_size, QSize): window_size = QSize(*window_size) window_pos = settings.get('main/window/position') if not isinstance(window_pos, QPoint): window_pos = QPoint(*window_pos) # make sure main window is smaller than the desktop desktop = QDesktopWidget() # this gives the maximum screen number if the position is off screen screen = desktop.screenNumber(window_pos) # recalculate the window size desktop_geom = desktop.screenGeometry(screen) w = min(desktop_geom.size().width(), window_size.width()) h = min(desktop_geom.size().height(), window_size.height()) window_size = QSize(w, h) # and position it on the supplied desktop screen x = max(window_pos.x(), desktop_geom.left()) y = max(window_pos.y(), desktop_geom.top()) window_pos = QPoint(x, y) # set the geometry self.resize(window_size) self.move(window_pos) # restore window state if settings.has('main/window/state'): self.restoreState(settings.get('main/window/state')) else: self.setWindowState(Qt.WindowMaximized) # have algorithm dialogs do their thing AlgorithmInputHistory().readSettings(settings)
def ensure_widget_is_on_screen(widget): """If the supplied widget is off the screen it will be moved so it is on the screen. The widget must already be 'shown' """ # this gives the maximum screen number if the position is off screen desktop = QDesktopWidget() screen = desktop.screenNumber(widget.pos()) # get the window size desktop_geom = desktop.availableGeometry(screen) # get the widget dimensions with any os added extras widget_geom = widget.frameGeometry() # and position it on the supplied desktop screen x = max(widget_geom.x(), desktop_geom.left()) y = max(widget_geom.y(), desktop_geom.top()) if x + widget_geom.width() > desktop_geom.right(): x = desktop_geom.right() - widget_geom.width() if y + widget_geom.height() > desktop_geom.bottom(): y = desktop_geom.bottom() - widget_geom.height() window_pos = QPoint(x, y) widget.move(window_pos)