def __honour_image_aspect_ratio(self): ''' resizes the window to fit the image aspect ratio based on the chart size ''' if len(self.image.text()) > 0: width, height = Image.open(self.image.text()).size width_delta = width - self.__x height_delta = height - self.__y if width_delta != 0 or height_delta != 0: win_size = self.size() target_size = QSize(win_size.width() + width_delta, win_size.height() + height_delta) available_size = QDesktopWidget().availableGeometry() if available_size.width() < target_size.width() or available_size.height() < target_size.height(): target_size.scale(available_size.width() - 48, available_size.height() - 48, Qt.KeepAspectRatio) self.resize(target_size)
def _detrend_end(self, result): self.detrendButton.setEnabled(True) self.df_fit = result['fit'] self.df_residual = result['residual'] self.df_continuous = result['continuous'] if self.actionDetrendLog.isChecked(): pos = self.frameGeometry().topRight() x = pos.x() y = pos.y() rect = QDesktopWidget().screenGeometry() if x + 10 > rect.width(): x -= 320 y += 30 else: y += 20 x += 20 self.logDialog = TSLogDialog(parent=self, name=self.site, log=result['log']) self.logDialog.setGeometry(x, y, 300, self.frameGeometry().height() - 20) self.logDialog.show() else: log = result['log'] self.display_information(log) self.detrend_plot_check() self._update_data_combox()
def __init__(self, parent=None): super(NativeNotification, self).__init__(parent=parent) time = datetime.now() current_time = "{}:{}".format(time.hour, time.minute) self.setWindowFlags(Qt.Tool | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.WindowSystemMenuHint) resolution = QDesktopWidget().screenGeometry(-1) screenWidth = resolution.width() screenHeight = resolution.height() self.nMessages = 0 self.mainLayout = QVBoxLayout(self) self.move(screenWidth, 0)
class AbstractSlideDisplay(QWidget): """ Abstract class for all slide bars. This will be inherited by the HSVSlideDisplay and UnitSlideDisplay. The base properties of this widget are to create the containter for these widgets, and then subclass this widget and draw the visuals. Kwargs: ** alignment (QtCore.Qt.Align): where the widget should be align relative to the display ** depth (int): how wide/tall the widget should be depending on its orientation ** display_widget (QWidget): optional argument. If entered, the display will show up over that widget rather than over the main display. Attributes: alignment (Qt.Alignment): Where widget should be aligned depth (int): width/height of the slideBar (depends on orientation) display_widget (QWidget): optional argument. If entered, the display will show up over that widget rather than over the main display. Notes: - This should be abstracted for SliderBar--> HueSlideDisplay SatSlideDisplay ValueSlideDisplay UnitSlideDisplay """ def __init__(self, parent=None, alignment=Qt.AlignBottom, depth=50, display_widget=None): super(AbstractSlideDisplay, self).__init__(parent) setAsTool(self) # set properties self.setDisplayWidget(display_widget) self.setDepth(depth) self.setAlignment(alignment) """ API """ def getDepth(self): return self._depth def setDepth(self, depth): self._depth = depth def getAlignment(self): return self._alignment def setAlignment(self, alignment): self._alignment = alignment def getDisplayWidget(self): return self._display_widget def setDisplayWidget(self, display_widget): self._display_widget = display_widget """ UTILS """ def setWidgetPosition(self, alignment, widget=None): """ Picks which algorithm to use to determine the widgets position If 'display_widget' is defined, then it will align to that widget, if not, it will align to the main display on the system. """ _accepted = [Qt.AlignLeft, Qt.AlignRight, Qt.AlignTop, Qt.AlignBottom] if alignment in _accepted: if widget: self.alignToWidget(alignment, widget) else: self.alignToDisplay(alignment) def alignToWidget(self, alignment, widget): """ Determines where on the monitor the widget should be located Args: * alignment (QtCore.Qt.Alignment): Determines where on the monitor to position the widget. AlignLeft AlignRight AlignTop AlignBottom * widget (QWidget): The QWidget that the slide bar should be aligned to. """ screen_pos = getGlobalPos(widget) if alignment == Qt.AlignLeft: height = widget.height() width = self.getDepth() pos = screen_pos elif alignment == Qt.AlignRight: height = widget.height() width = self.getDepth() pos_x = (screen_pos.x() + widget.width() - self.getDepth()) pos = QPoint(pos_x, screen_pos.y()) elif alignment == Qt.AlignTop: height = self.getDepth() width = widget.width() pos = screen_pos elif alignment == Qt.AlignBottom: height = self.getDepth() width = widget.width() pos_y = (screen_pos.y() + widget.height() - self.getDepth()) pos = QPoint(screen_pos.x(), pos_y) self.setFixedHeight(height) self.setFixedWidth(width) self.move(pos) def alignToDisplay(self, alignment): """ Determines where on the monitor the widget should be located Args: Alignment (QtCore.Qt.Alignment): Determines where on the monitor to position the widget. AlignLeft AlignRight AlignTop AlignBottom """ # set screen properties self.screen_geometry = QDesktopWidget().screenGeometry(-1) self.screen_width = self.screen_geometry.width() self.screen_height = self.screen_geometry.height() self.screen_pos = self.screen_geometry.topLeft() if alignment == Qt.AlignLeft: height = self.screen_height width = self.getDepth() pos = self.screen_pos elif alignment == Qt.AlignRight: height = self.screen_height width = self.getDepth() pos_x = (self.screen_pos.x() + self.screen_width - self.getDepth()) pos = QPoint(pos_x, self.screen_pos.y()) elif alignment == Qt.AlignTop: height = self.getDepth() width = self.screen_width pos = self.screen_pos elif alignment == Qt.AlignBottom: height = self.getDepth() width = self.screen_width pos_y = (self.screen_pos.y() + self.screen_height - self.getDepth()) pos = QPoint(self.screen_pos.x(), pos_y) self.setFixedHeight(height) self.setFixedWidth(width) self.move(pos) def update(self, *args, **kwargs): print('you need to reimplement this on: {}'.format(self)) return QWidget.update(self, *args, **kwargs) """ EVENTS""" def keyPressEvent(self, event, *args, **kwargs): if event.key() == Qt.Key_Escape: self.close() return QWidget.keyPressEvent(self, event, *args, **kwargs)
def placescreen(self, pos): resolution = QDesktopWidget().screenGeometry() self.move( (resolution.width() / pos) - (self.frameSize().width() / pos), (resolution.height() / pos) - (self.frameSize().height() / pos))
def center_window(window: QWidget): screen = QDesktopWidget().screenGeometry() size = window.geometry() window.move(int((screen.width() - size.width()) / 2), int((screen.height() - size.height()) / 2))
def eventloop(shell, init_code=None, init_file=None, console_id=0, pictures=None): """ The GUI Process and Thread running the eventloop """ shell.logdir.find_log_path() qapp = GuiApplication(shell, sys.argv) qapp.setShortCuts() qapp.newWindow('main') #To run in a new thread but on the same gui process #panid = qapp.mainWindow.newThread() qapp.mainWindow.show() desktopGeometry = QDesktopWidget().availableGeometry() qapp.mainWindow.resize(int(desktopGeometry.width() * 3 / 5), int(desktopGeometry.height() * 3 / 5)) qtRectangle = qapp.mainWindow.frameGeometry() centerPoint = desktopGeometry.center() qtRectangle.moveCenter(centerPoint) qapp.mainWindow.move(qtRectangle.topLeft()) # Make sure the gui proxy for the main thread is created qapp.panels.restore_state_from_config('base') # if not config['debug']['skip_restore_perspective']: # if config['default_perspective'] != 'base': # qapp.panels.restore_state_from_config(config['default_perspective']) qapp.processEvents() qapp.cmdserver = CommandServer(shell) if not init_file is None: cmd = {'cmd': 'execute_file', 'args': (init_file, console_id)} qapp.cmdserver.cmd_queue.put(cmd) if not init_code is None: cmd = {'cmd': 'execute_code', 'args': (init_code, console_id)} qapp.cmdserver.cmd_queue.put(cmd) if not pictures is None: cmd = {'cmd': 'open_images', 'args': pictures} qapp.cmdserver.cmd_queue.put(cmd) cmd = config.get('init_command') qapp.cmdserver.cmd_queue.put(cmd) qapp.cmdserver.start_queue_loop(qapp) qapp.cmdserver.start(qapp) exit_code = qapp.exec_() #Kill all the children parent = psutil.Process(os.getpid()) for child in parent.children(recursive=True): child.kill() from pylab import plt plt.close('all') sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ print(f'Exiting {PROGNAME}. Releasing lock.') shell.logdir.release_lock_file()
def screen_resolutions(self): width = 0 for displayNr in range(QDesktopWidget().screenCount()): sizeObject = QDesktopWidget().screenGeometry(displayNr) width += sizeObject.width() return width - 5