Exemplo n.º 1
0
def center_widget_on_screen(widget):
    """
    Centers a given QWidget on the active screen
    :param widget: QWidget
    """

    frame_geo = widget.frameGeometry()
    screen = QApplication.desktop().screenNumber(
        QApplication.desktop().cursor().pos())
    center_point = QApplication.desktop().screenGeometry(screen).center()
    frame_geo.moveCenter(center_point)
    widget.move(frame_geo.topLeft())
Exemplo n.º 2
0
def get_screen_color(global_pos):
    """
    Grabs the screen color of the given global position in the current active screen
    :param global_pos: QPoint
    :return: QColor
    """

    screen_num = QApplication.desktop().screenNumber(global_pos)
    screen = QApplication.screens()[screen_num]
    wid = QApplication.desktop().winId()
    img = screen.grabWindow(wid, global_pos.x(), global_pos.y(), 1,
                            1).toImage()

    return QColor(img.pixel(0, 0))
Exemplo n.º 3
0
    def center(self, to_cursor=False):
        """
        Move the dialog to the center of the current window
        """

        frame_geo = self.frameGeometry()
        if to_cursor:
            pos = QApplication.desktop().cursor().pos()
            screen = QApplication.desktop().screenNumber(pos)
            center_point = QApplication.desktop().screenGeometry(
                screen).center()
        else:
            center_point = QDesktopWidget().availableGeometry().center()
        frame_geo.moveCenter(center_point)
        self.move(frame_geo.topLeft())
Exemplo n.º 4
0
    def startDrag(self, o, e):
        if self._dragStart is None:
            self._dragStart = e.pos()
            dtop = QApplication.desktop()
            sn = dtop.screenNumber(o.mapToGlobal(e.pos()))
            self._screen = dtop.availableGeometry(sn)

        if abs(e.x() - self._dragStart.x()) > self.startSensitivity:
            self._dragType = self.DRAG_HORIZONTAL
        elif abs(e.y() - self._dragStart.y()) > self.startSensitivity:
            self._dragType = self.DRAG_VERTICAL

        if self._dragType:
            self._leftover = 0
            self._lastPos = e.pos()
            self._firstDrag = True

            self.dragPressed.emit()
            self.doOverrideCursor()

            if self.isSpinbox:
                if e.buttons() & self.dragButton:
                    # Send mouseRelease to spin buttons when dragging
                    # otherwise the spinbox will keep ticking.  @longClickFix
                    # There's gotta be a better way to do this :-/
                    mouseup = QMouseEvent(QEvent.MouseButtonRelease, e.pos(),
                                          self.dragButton, e.buttons(),
                                          e.modifiers())
                    QApplication.sendEvent(o, mouseup)
Exemplo n.º 5
0
def dpi_multiplier():
    """
    Returns current application DPI multiplier
    :return: float
    """

    return max(
        1,
        float(QApplication.desktop().logicalDpiY()) / float(DEFAULT_DPI))
Exemplo n.º 6
0
    def getscreenshot(self):
        # screen = QGuiApplication.screenAt(QApplication.desktop().cursor().pos())
        # self.screenPixel = screen.grabWindow(0)

        # dw = QtWidgets.QApplication.desktop()
        # self.screenPixel = QPixmap.grabWindow( dw.winId(), 0, 0, dw.width(), dw.height() )

        screenGeometry = QApplication.primaryScreen().virtualGeometry()
        try:
            self.screenPixel = QApplication.primaryScreen().grabWindow(
                QApplication.desktop().winId(), screenGeometry.x(),
                screenGeometry.y(), screenGeometry.width(),
                screenGeometry.height())
        except:
            self.screenPixel = QApplication.primaryScreen().grabWindow(
                int(QApplication.desktop().winId()), screenGeometry.x(),
                screenGeometry.y(), screenGeometry.width(),
                screenGeometry.height())
Exemplo n.º 7
0
 def _on_show_detail(self):
     dlg = QTextEdit(self)
     dlg.setReadOnly(True)
     geo = QApplication.desktop().screenGeometry()
     dlg.setGeometry(geo.width() / 2,
                     geo.height() / 2,
                     geo.width() / 4,
                     geo.height() / 4)
     dlg.setWindowTitle('Error Detail Information')
     dlg.setText(self.property('history'))
     dlg.setWindowFlags(Qt.Dialog)
     dlg.show()
Exemplo n.º 8
0
def screens_contains_point(point):
    """
    Returns whether given point is contained in current screen
    :param point: QPoint
    :return: bool
    """

    desktop = QApplication.desktop()
    for i in range(desktop.screenCount()):
        if desktop.geometry().contains(point):
            return True

    return False
Exemplo n.º 9
0
    def __init__(
            self,
            tool=None,
            name='MainWindow',
            title='MainWindow',
            size=(800, 535),
            fixed_size=False,
            parent=None,
            *args,
            **kwargs):

        self._tool = tool

        super(MainWindow, self).__init__(
            name=name,
            title=title,
            size=size,
            fixed_size=fixed_size,
            auto_run=True,
            frame_less=True,
            use_style=False,
            parent=parent,
            *args,
            **kwargs
        )

        if self.parent():
            for widget in self.parent().findChildren(QMainWindow):
                if widget is not self:
                    if widget.objectName() == self.objectName():
                        widget.close()

        screen_geo = QApplication.desktop().screenGeometry()
        screen_width = screen_geo.width()
        screen_height = screen_geo.height()
        new_width = self.width()
        new_height = self.height()
        if self.width() > screen_width:
            new_width = 500
        if self.height() > screen_height:
            new_height = 500
        self.resize(new_width, new_height)
        self.center()
Exemplo n.º 10
0
 def _popup_menu(self):
     if self._search_menu:
         screen_rect = QApplication.desktop().availableGeometry(
             self._search_btn)
         size_hint = self._search_menu.sizeHint()
         rect = self._search_btn.rect()
         top_diff = rect.top() - size_hint.height()
         x = rect.right() - size_hint.width(
         ) if self._search_btn.isRightToLeft() else rect.left()
         y = rect.bottom(
         ) if self._search_btn.mapToGlobal(QPoint(0, rect.bottom())).y(
         ) + size_hint.height() <= screen_rect.height() else top_diff
         point = self._search_btn.mapToGlobal(QPoint(x, y))
         point.setX(
             max(screen_rect.left(),
                 min(point.x(),
                     screen_rect.right() - size_hint.width())))
         point.setY(point.y() + 1)
         print('pop up on {}'.format(point))
         self._search_menu.popup(point)
Exemplo n.º 11
0
    def __init__(self,
                 controller,
                 script=None,
                 add_empty_tab=False,
                 parent=None):
        super(ScriptsTab, self).__init__(parent=parent)

        self._controller = controller
        self._last_search = [0, None]
        self._parent = parent
        self._desktop = QApplication.desktop()
        self._ask_save_before_close = True

        self.tabBar().setContextMenuPolicy(Qt.CustomContextMenu)
        self.currentChanged.connect(self._on_hide_all_completers)
        self.tabBar().customContextMenuRequested.connect(self._on_open_menu)
        self.tabBar().addTabClicked.connect(self._on_add_new_tab)

        if script and os.path.isfile(script):
            self.add_new_tab(os.path.basename(script), script)
        else:
            if add_empty_tab:
                self.add_new_tab()
Exemplo n.º 12
0
 def getWindowHeight(cls):
     return QApplication.desktop().height()
Exemplo n.º 13
0
 def getWindowWidth(cls):
     return QApplication.desktop().width()