def get_screen_resolution(self): """ """ widget = QDesktopWidget() geometry = widget.availableGeometry(widget.primaryScreen()) value = "{0}x{1}".format(geometry.width(), geometry.height()) return value
def get_screen_size(): """Get **available** screen size/resolution.""" if mpl.get_backend().startswith('Qt'): # Inspired by spyder/widgets/shortcutssummary.py from qtpy.QtWidgets import QDesktopWidget # noqa widget = QDesktopWidget() sg = widget.availableGeometry(widget.primaryScreen()) x0 = sg.x() y0 = sg.y() w0 = sg.width() h0 = sg.height() elif mpl.get_backend() == "TkAgg": # https://stackoverflow.com/a/42951711/38281 window = plt.get_current_fig_manager().window x0, y0 = 0, 0 w0, h0 = window.wm_maxsize() # h = window.winfo_screenheight() # w = window.winfo_screenwidth() else: # Mac Retina Early 2013 x0 = 0 y0 = 23 w0 = 1280 h0 = 773 return x0, y0, w0, h0
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 get_screen_resolution(): """Return the screen resolution of the primary screen.""" try: widget = QDesktopWidget() geometry = widget.availableGeometry(widget.primaryScreen()) value = "{0}x{1}".format(geometry.width(), geometry.height()) except Exception: value = None return value
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 get_screen_size(): """Get **available** screen size/resolution.""" if mpl.get_backend().startswith('Qt'): # Inspired by spyder/widgets/shortcutssummary.py from qtpy.QtWidgets import QDesktopWidget widget = QDesktopWidget() sg = widget.availableGeometry(widget.primaryScreen()) x0 = sg.x() y0 = sg.y() w0 = sg.width() h0 = sg.height() else: # Mac Retina Early 2013 x0 = 0 y0 = 23 w0 = 1280 h0 = 773 return x0, y0, w0, h0
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)
def get_screen_resolution(self): """Return the screen resolution of the primary screen.""" widget = QDesktopWidget() geometry = widget.availableGeometry(widget.primaryScreen()) return geometry.width(), geometry.height()