Exemplo n.º 1
0
def decorate_welcome_icon(icon, background_color):
    # type: (QIcon, Union[QColor, str]) -> QIcon
    """Return a `QIcon` with a circle shaped background.
    """
    welcome_icon = QIcon()
    sizes = [32, 48, 64, 80, 128, 256]
    background_color = NAMED_COLORS.get(background_color, background_color)
    background_color = QColor(background_color)
    grad = radial_gradient(background_color)
    for size in sizes:
        icon_size = QSize(int(5 * size / 8), int(5 * size / 8))
        icon_rect = QRect(QPoint(0, 0), icon_size)
        pixmap = QPixmap(size, size)
        pixmap.fill(Qt.transparent)
        p = QPainter(pixmap)
        p.setRenderHint(QPainter.Antialiasing, True)
        p.setBrush(QBrush(grad))
        p.setPen(Qt.NoPen)
        ellipse_rect = QRect(0, 0, size, size)
        p.drawEllipse(ellipse_rect)
        icon_rect.moveCenter(ellipse_rect.center())
        icon.paint(
            p,
            icon_rect,
            Qt.AlignCenter,
        )
        p.end()

        welcome_icon.addPixmap(pixmap)

    return welcome_icon
Exemplo n.º 2
0
    def __setControlAreaVisible(self, visible):
        # type: (bool) -> None
        if self.__splitter is None or self.__splitter.count() < 2:
            return
        self.controlAreaVisible = visible
        splitter = self.__splitter  # type: QSplitter
        w = splitter.widget(0)
        # Set minimum width to 1 (overrides minimumSizeHint) when control area
        # is not visible to allow the main area to shrink further. Reset the
        # minimum width with a 0 if control area is visible.
        w.setMinimumWidth(int(not visible))

        sizes = splitter.sizes()
        current_size = sizes[0]
        if bool(current_size) == visible:
            return

        current_width = w.width()
        geom = self.geometry()
        frame = self.frameGeometry()
        framemargins = QMargins(
            frame.left() - geom.left(),
            frame.top() - geom.top(),
            frame.right() - geom.right(),
            frame.bottom() - geom.bottom()
        )
        splitter.setSizes([int(visible), QWIDGETSIZE_MAX])
        if not self.isWindow() or \
                self.windowState() not in [Qt.WindowNoState, Qt.WindowActive]:
            # not a window or not in state where we can move move/resize
            return

        # force immediate resize recalculation
        splitter.refresh()
        self.layout().invalidate()
        self.layout().activate()

        if visible:
            # move left and expand by the exposing widget's width
            diffx = -w.width()
            diffw = w.width()
        else:
            # move right and shrink by the collapsing width
            diffx = current_width
            diffw = -current_width
        newgeom = QRect(
            geom.x() + diffx, geom.y(), geom.width() + diffw, geom.height()
        )
        # bound/move by available geometry
        bounds = QApplication.desktop().availableGeometry(self)
        bounds = bounds.adjusted(
            framemargins.left(), framemargins.top(),
            -framemargins.right(), -framemargins.bottom()
        )
        newsize = newgeom.size().boundedTo(bounds.size())
        newgeom = QRect(newgeom.topLeft(), newsize)
        newgeom.moveLeft(max(newgeom.left(), bounds.left()))
        newgeom.moveRight(min(newgeom.right(), bounds.right()))
        self.setGeometry(newgeom)
Exemplo n.º 3
0
 def _subControlRect(self, subcontrol):
     if subcontrol == QStyle.SC_SliderGroove:
         return self.rect()
     if subcontrol == QStyle.SC_SliderHandle:
         if self.orientation() == Qt.Horizontal:
             return QRect(-self._HANDLE_WIDTH / 2, 0, self._HANDLE_WIDTH, self.rect().height())
         else:
             return QRect(0, -self._HANDLE_WIDTH / 2, self.rect().width(), self._HANDLE_WIDTH)
Exemplo n.º 4
0
    def mouseMoveEvent(self, event):
        if event.buttons() & Qt.LeftButton and self.__dragging:
            r1, c1 = self._cellAt(event.buttonDownPos(Qt.LeftButton))
            r2, c2 = self._cellCloseTo(event.pos())
            selrange = QRect(c1, r1, 1, 1).united(QRect(c2, r2, 1, 1))
            self.__elastic_band_select(selrange, self.Select)

        super().mouseMoveEvent(event)
        event.accept()
Exemplo n.º 5
0
    def paintEvent(self, event):
        # based on
        # https://github.com/qt/qtbase/blob/f40dbe0d0b54ce83d2168e82905cf4f75059a841/src/widgets/widgets/qslider.cpp#L315
        # https://github.com/enthought/traitsui/blob/master/traitsui/qt4/extra/range_slider.py
        painter = QStylePainter(self)
        minpos = self._min_position
        maxpos = self._max_position

        # Draw the groove
        opt = QStyleOptionSlider()
        self.initStyleOption(opt)
        # Draw empty grove
        opt.sliderPosition = opt.minimum
        opt.subControls = QStyle.SC_SliderGroove
        if self.tickPosition() != self.NoTicks:
            opt.subControls |= QStyle.SC_SliderTickmarks
        painter.drawComplexControl(QStyle.CC_Slider, opt)
        # Draw the highlighted part on top
        # Qt4.8 and Qt5.3 draw the highlighted groove in a weird way because they
        # transpose opt.rect. Qt5.7 works fine.
        if QT_VERSION_STR >= '5.7.0':
            opt.subControls = QStyle.SC_SliderGroove
            opt.sliderPosition = opt.maximum
            if self.orientation() == Qt.Horizontal:
                _w = opt.rect.width() / opt.maximum
                x = round(_w * minpos)
                w = round(_w * (maxpos - minpos))
                opt.rect = QRect(x, 0, w, opt.rect.height())
            else:
                _h = opt.rect.height() / opt.maximum
                y = round(_h * minpos)
                h = round(_h * (maxpos - minpos))
                opt.rect = QRect(0, y, opt.rect.width(), h)
            painter.drawComplexControl(QStyle.CC_Slider, opt)

        # Draw the handles
        for i, position in enumerate((minpos, maxpos)):
            opt = QStyleOptionSlider()
            self.initStyleOption(opt)
            opt.subControls = QStyle.SC_SliderHandle

            if self.__pressed_control and (self.__active_slider == i or
                                           self.__active_slider < 0):
                opt.activeSubControls = self.__pressed_control
                opt.state |= QStyle.State_Sunken
            else:
                opt.activeSubControls = self.__hovered_control

            opt.sliderPosition = position
            opt.sliderValue = position
            painter.drawComplexControl(QStyle.CC_Slider, opt)
Exemplo n.º 6
0
    def drawBackground(self, painter, rect):
        super().drawBackground(painter, rect)

        if not self.__backgroundIcon.isNull():
            painter.setClipRect(rect)
            vrect = QRect(QPoint(0, 0), self.viewport().size())
            vrect = self.mapToScene(vrect).boundingRect()

            pm = self.__backgroundIcon.pixmap(vrect.size().toSize().boundedTo(
                QSize(200, 200)))
            pmrect = QRect(QPoint(0, 0), pm.size())
            pmrect.moveCenter(vrect.center().toPoint())
            if rect.toRect().intersects(pmrect):
                painter.drawPixmap(pmrect, pm)
Exemplo n.º 7
0
    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            r, c = self._cellAt(event.pos())
            if r != -1 and c != -1:
                # Clear existing selection
                # TODO: Fix extended selection.
                self.__select(QRect(), self.Clear)
                selrange = QRect(c, r, 1, 1)
                self.__elastic_band_select(selrange, self.Select | self.Clear)
        elif event.button() == Qt.RightButton:
            self.__select(QRect(), self.Clear)

        super().mousePressEvent(event)
        event.accept()
Exemplo n.º 8
0
 def test_popup_util(self):
     geom = QRect(10, 10, 100, 400)
     screen = QRect(0, 0, 600, 600)
     g1 = combobox.dropdown_popup_geometry(geom, QRect(200, 100, 100, 20),
                                           screen)
     self.assertEqual(g1, QRect(200, 120, 100, 400))
     g2 = combobox.dropdown_popup_geometry(geom, QRect(-10, 0, 100, 20),
                                           screen)
     self.assertEqual(g2, QRect(0, 20, 100, 400))
     g3 = combobox.dropdown_popup_geometry(geom, QRect(590, 0, 100, 20),
                                           screen)
     self.assertEqual(g3, QRect(600 - 100, 20, 100, 400))
     g4 = combobox.dropdown_popup_geometry(geom, QRect(0, 500, 100, 20),
                                           screen)
     self.assertEqual(g4, QRect(0, 500 - 400, 100, 400))
Exemplo n.º 9
0
    def setGeometry(self, rect: QRect) -> None:
        if rect == self.__rect:
            return
        self.__rect = QRect(rect)

        QStackedLayout.setGeometry(self, rect)
        for i in range(self.count()):
            w = self.widget(i)
            hint = w.sizeHint()
            geom = QRect(rect)
            size = clipMinMax(rect.size(), w.minimumSize(), w.maximumSize())
            size = fixSizePolicy(size, hint, w.sizePolicy())
            geom.setSize(size)
            if geom != w.geometry():
                w.setGeometry(geom)
Exemplo n.º 10
0
    def __updateGeometry(self):
        # type: () -> None
        """
        Update the shadow geometry to fit the widget's changed
        geometry.
        """
        assert self.__widget is not None
        widget = self.__widget
        parent = self.__widgetParent
        radius = self.radius_
        offset = self.__offset
        pos = widget.pos()
        if parent is not None and parent != widget.parentWidget():
            pos = widget.parentWidget().mapTo(parent, pos)

        geom = QRect(pos, widget.size())
        geom = geom.adjusted(-radius, -radius, radius, radius)
        geom = geom.translated(offset)
        if geom != self.geometry():
            self.setGeometry(geom)

        # Set the widget mask (punch a hole through to the `widget` instance.
        rect = self.rect()
        mask = QRegion(rect)

        rect = rect.adjusted(radius, radius, -radius, -radius)
        rect = rect.translated(-offset)
        transparent = QRegion(rect)
        mask = mask.subtracted(transparent)
        self.setMask(mask)
Exemplo n.º 11
0
    def paint(self, painter, option, index):
        dist = self.distribution(index)
        if dist is None or self.colors is None:
            super().paint(painter, option, index)
            return

        if option.widget is not None:
            style = option.widget.style()
        else:
            style = QApplication.style()

        self.initStyleOption(option, index)

        text = option.text
        metrics = option.fontMetrics

        margin = style.pixelMetric(QStyle.PM_FocusFrameHMargin, option,
                                   option.widget) + 1
        bottommargin = min(margin, 1)
        rect = option.rect.adjusted(margin, margin, -margin, -bottommargin)

        textrect = style.subElementRect(QStyle.SE_ItemViewItemText, option,
                                        option.widget)
        # Are the margins included in the subElementRect?? -> No!
        textrect = textrect.adjusted(margin, margin, -margin, -bottommargin)

        text = option.fontMetrics.elidedText(text, option.textElideMode,
                                             textrect.width())

        spacing = max(metrics.leading(), 1)

        distheight = rect.height() - metrics.height() - spacing
        distheight = numpy.clip(distheight, 2, metrics.height())

        painter.save()
        painter.setClipRect(option.rect)
        painter.setFont(option.font)
        painter.setRenderHint(QPainter.Antialiasing)

        style.drawPrimitive(QStyle.PE_PanelItemViewRow, option, painter,
                            option.widget)
        style.drawPrimitive(QStyle.PE_PanelItemViewItem, option, painter,
                            option.widget)

        if option.state & QStyle.State_Selected:
            color = option.palette.highlightedText().color()
        else:
            color = option.palette.text().color()
        painter.setPen(QPen(color))

        textrect = textrect.adjusted(0, 0, 0, -distheight - spacing)
        distrect = QRect(textrect.bottomLeft() + QPoint(0, spacing),
                         QSize(rect.width(), distheight))
        painter.setPen(QPen(Qt.lightGray, 0.3))
        self.drawDistBar(painter, distrect, dist)
        painter.restore()
        if text:
            style.drawItemText(painter, textrect, option.displayAlignment,
                               option.palette,
                               option.state & QStyle.State_Enabled, text)
Exemplo n.º 12
0
def widget_popup_geometry(pos, widget):
    # type: (QPoint, QWidget) -> QRect
    widget.ensurePolished()

    if widget.testAttribute(Qt.WA_Resized):
        size = widget.size()
    else:
        size = widget.sizeHint()

    screen = QApplication.screenAt(pos)
    if screen is None:
        screen = QApplication.primaryScreen()
    screen_geom = screen.availableGeometry()
    size = size.boundedTo(screen_geom.size())
    geom = QRect(pos, size)

    if geom.top() < screen_geom.top():
        geom.moveTop(screen_geom.top())
    if geom.left() < screen_geom.left():
        geom.moveLeft(screen_geom.left())

    bottom_margin = screen_geom.bottom() - geom.bottom()
    right_margin = screen_geom.right() - geom.right()
    if bottom_margin < 0:
        # Falls over the bottom of the screen, move it up.
        geom.translate(0, bottom_margin)

    # TODO: right to left locale
    if right_margin < 0:
        # Falls over the right screen edge, move the menu to the
        # other side of pos.
        geom.translate(-size.width(), 0)

    return geom
Exemplo n.º 13
0
    def __updatePixmap(self):
        """
        Update the cached shadow pixmap.
        """
        rect_size = QSize(50, 50)
        left = top = right = bottom = self.radius_

        # Size of the pixmap.
        pixmap_size = QSize(rect_size.width() + left + right,
                            rect_size.height() + top + bottom)
        shadow_rect = QRect(QPoint(left, top), rect_size)
        pixmap = QPixmap(pixmap_size)
        pixmap.fill(QColor(0, 0, 0, 0))
        rect_fill_color = self.palette().color(QPalette.Window)

        pixmap = render_drop_shadow_frame(
            pixmap,
            QRectF(shadow_rect),
            shadow_color=self.color_,
            offset=QPointF(0, 0),
            radius=self.radius_,
            rect_fill_color=rect_fill_color,
        )

        self.__shadowPixmap = pixmap
        self.update()
Exemplo n.º 14
0
    def __updateGeometry(self):
        """
        Update the shadow geometry to fit the widget's changed
        geometry.

        """
        widget = self.__widget
        parent = self.__widgetParent
        radius = self.radius_
        pos = widget.pos()
        if parent != widget.parentWidget():
            pos = widget.parentWidget().mapTo(parent, pos)

        geom = QRect(pos, widget.size())
        geom.adjust(-radius, -radius, radius, radius)
        if geom != self.geometry():
            self.setGeometry(geom)

        # Set the widget mask (punch a hole through to the `widget` instance.
        rect = self.rect()

        mask = QRegion(rect)
        transparent = QRegion(rect.adjusted(radius, radius, -radius, -radius))

        mask = mask.subtracted(transparent)
        self.setMask(mask)
Exemplo n.º 15
0
    def paintEvent(self, event):
        # type: (QPaintEvent) -> None
        if self.__flat:
            opt = QStyleOptionToolButton()
            self.initStyleOption(opt)
            p = QStylePainter(self)
            p.drawControl(QStyle.CE_ToolButtonLabel, opt)
            p.end()
        else:
            super().paintEvent(event)

        # paint shadow
        shadow = innerShadowPixmap(self.__shadowColor,
                                   self.size(),
                                   self.__shadowPosition,
                                   length=self.__shadowLength)

        p = QPainter(self)

        rect = self.rect()
        targetRect = QRect(rect.left() + 1,
                           rect.top() + 1,
                           rect.width() - 2,
                           rect.height() - 2)

        p.drawPixmap(targetRect, shadow, shadow.rect())
        p.end()
Exemplo n.º 16
0
    def paint(self, painter, option, index):
        if option.widget is not None:
            style = option.widget.style()
        else:
            style = QApplication.instance().style()

        style.drawPrimitive(QStyle.PE_PanelItemViewRow, option, painter,
                            option.widget)
        style.drawPrimitive(QStyle.PE_PanelItemViewItem, option, painter,
                            option.widget)
        rect = option.rect
        val = index.data(Qt.DisplayRole)

        if isinstance(val, float):
            if np.isfinite(val):
                minv, maxv = self.scale
                val = (val - minv) / (maxv - minv)
                rect = rect.adjusted(1, 1,
                                     -int(rect.width() * (1.0 - val)) - 2, -2)
            else:
                rect = QRect()

            painter.save()
            if option.state & QStyle.State_Selected:
                painter.setOpacity(0.75)
            painter.setBrush(self.brush)
            painter.drawRect(rect)
            painter.restore()
Exemplo n.º 17
0
    def update_map(self):
        """Get current view box to calculate which tiles to draw."""
        [min_x, max_x], [min_y, max_y] = self.view_box.viewRange()

        new_zoom = self.view_box.get_zoom()
        self.zoom_changed = self.tz != new_zoom
        self.tz = new_zoom

        # flip y to calculate edge tiles
        tile_min_x, tile_max_y = norm2tile(min_x, 1 - min_y, self.tz)
        tile_max_x, tile_min_y = norm2tile(max_x, 1 - max_y, self.tz)

        # round them to get edge tiles x, y
        tile_min_x = max(int(np.floor(tile_min_x)), 0)
        tile_min_y = max(int(np.floor(tile_min_y)), 0)
        tile_max_x = min(int(np.ceil(tile_max_x)), 2**self.tz)
        tile_max_y = min(int(np.ceil(tile_max_y)), 2**self.tz)

        self.ts = QRect(tile_min_x, tile_min_y, tile_max_x - tile_min_x,
                        tile_max_y - tile_min_y)

        # transform rounded tile coordinates back
        min_edge_x, min_edge_y = tile2norm(tile_min_x, tile_min_y, self.tz)
        max_edge_x, max_edge_y = tile2norm(tile_max_x, tile_max_y, self.tz)

        # flip y back to transform map
        min_edge_y, max_edge_y = 1 - min_edge_y, 1 - max_edge_y

        # rectangle where to put the map into
        self.ts_norm = QRectF(min_edge_x, min_edge_y, max_edge_x - min_edge_x,
                              max_edge_y - min_edge_y)

        self._map_z_shift()
        self._load_new_map()
Exemplo n.º 18
0
    def __testaxis(self, event):
        viewbox = self.parent()
        widget = event.widget()
        assert widget is not None
        view = widget.parent()
        assert isinstance(view, QGraphicsView)
        pos = view.mapFromGlobal(event.screenPos())
        hitarea = view.mapToScene(QRect(pos - QPoint(2, 2), QSize(4, 4)))
        hitarea = viewbox.mapFromScene(hitarea)
        hitarea = viewbox.mapToView(hitarea).boundingRect()
        center = hitarea.center()

        if center.x() < 0:
            hitarea.moveCenter(QPointF(-center.x(), center.y()))

        cx = self.selection[1][1].x()
        cy = self.selection[1][1].y()
        if hitarea.contains(QPointF(cx, cy)):
            axes = Qt.Horizontal | Qt.Vertical
        elif hitarea.bottom() > cy > hitarea.top() and hitarea.left() > cx:
            axes = Qt.Vertical
        elif hitarea.left() < cx < hitarea.right() and hitarea.bottom() > cy:
            axes = Qt.Horizontal
        else:
            axes = 0
        return axes
Exemplo n.º 19
0
    def test_splashscreen(self):
        splash = pkg_resources.resource_filename(
            config.__package__, "icons/orange-canvas-core-splash.svg"
        )
        w = SplashScreen()
        w.setPixmap(QPixmap(splash))
        w.setTextRect(QRect(100, 100, 400, 50))
        w.show()

        def advance_time():
            now = datetime.now()
            time = now.strftime("%c : %f")
            i = now.second % 3
            if i == 2:
                w.setTextFormat(Qt.RichText)
                time = "<i>" + time + "</i>"
            else:
                w.setTextFormat(Qt.PlainText)

            w.showMessage(time, alignment=Qt.AlignCenter)

            rect = QRect(100, 100 + i * 20, 400, 50)
            w.setTextRect(rect)

            self.assertEqual(w.textRect(), rect)

        timer = QTimer(w, interval=1)
        timer.timeout.connect(advance_time)
        timer.start()

        self.app.exec_()
Exemplo n.º 20
0
    def popup(self, pos=None, searchText=""):
        """
        Popup the menu at `pos` (in screen coordinates). 'Search' text field
        is initialized with `searchText` if provided.

        """
        if pos is None:
            pos = QPoint()

        self.__clearCurrentItems()

        self.__search.setText(searchText)
        patt = QRegExp("(^|\W)" + searchText)
        patt.setCaseSensitivity(False)
        self.__suggestPage.setFilterRegExp(patt)

        self.ensurePolished()

        if self.testAttribute(Qt.WA_Resized) and self.sizeGripEnabled():
            size = self.size()
        else:
            size = self.sizeHint()

        desktop = QApplication.desktop()
        screen_geom = desktop.availableGeometry(pos)

        # Adjust the size to fit inside the screen.
        if size.height() > screen_geom.height():
            size.setHeight(screen_geom.height())
        if size.width() > screen_geom.width():
            size.setWidth(screen_geom.width())

        geom = QRect(pos, size)

        if geom.top() < screen_geom.top():
            geom.setTop(screen_geom.top())

        if geom.left() < screen_geom.left():
            geom.setLeft(screen_geom.left())

        bottom_margin = screen_geom.bottom() - geom.bottom()
        right_margin = screen_geom.right() - geom.right()
        if bottom_margin < 0:
            # Falls over the bottom of the screen, move it up.
            geom.translate(0, bottom_margin)

        # TODO: right to left locale
        if right_margin < 0:
            # Falls over the right screen edge, move the menu to the
            # other side of pos.
            geom.translate(-size.width(), 0)

        self.setGeometry(geom)

        self.show()

        if searchText:
            self.setFocusProxy(self.__search)
        else:
            self.setFocusProxy(None)
Exemplo n.º 21
0
def splash_screen():
    """
    """
    pm = QPixmap(
        pkg_resources.resource_filename(__name__,
                                        "icons/orange-splash-screen.png"))

    version = QCoreApplication.applicationVersion()
    size = 21 if len(version) < 5 else 16
    font = QFont("Helvetica")
    font.setPixelSize(size)
    font.setBold(True)
    font.setItalic(True)
    font.setLetterSpacing(QFont.AbsoluteSpacing, 2)
    metrics = QFontMetrics(font)
    br = metrics.boundingRect(version).adjusted(-5, 0, 5, 0)
    br.moveCenter(QPoint(436, 224))

    p = QPainter(pm)
    p.setRenderHint(QPainter.Antialiasing)
    p.setRenderHint(QPainter.TextAntialiasing)
    p.setFont(font)
    p.setPen(QColor("#231F20"))
    p.drawText(br, Qt.AlignCenter, version)
    p.end()
    return pm, QRect(88, 193, 200, 20)
Exemplo n.º 22
0
    def __shadowPixmapForDpr(self, dpr=1.0):
        # type: (float) -> QPixmap
        """
        Return a shadow pixmap rendered in `dpr` device pixel ratio.
        """
        offset = self.offset()
        radius = self.radius()
        color = self.color()
        fill_color = self.palette().color(QPalette.Window)
        rect_size = QSize(int(50 * dpr), int(50 * dpr))
        left = top = right = bottom = int(radius * dpr)
        # Size of the pixmap.
        pixmap_size = QSize(rect_size.width() + left + right,
                            rect_size.height() + top + bottom)
        shadow_rect = QRect(QPoint(left, top) - offset * dpr, rect_size)
        pixmap = QPixmap(pixmap_size)
        pixmap.fill(Qt.transparent)

        pixmap = render_drop_shadow_frame(
            pixmap,
            QRectF(shadow_rect),
            shadow_color=color,
            offset=QPointF(offset * dpr),
            radius=radius * dpr,
            rect_fill_color=fill_color
        )
        pixmap.setDevicePixelRatio(dpr)
        return pixmap
Exemplo n.º 23
0
    def splash_screen():
        splash_n = random.randint(1, 3)
        path = pkg_resources.resource_filename(
            __name__, f"icons/orange-splash-screen-{splash_n:02}.png")
        pm = QPixmap(path)

        version = Config.ApplicationVersion
        if version:
            version_parsed = LooseVersion(version)
            version_comp = version_parsed.version
            version = ".".join(map(str, version_comp[:2]))
        size = 13
        font = QFont("Helvetica")
        font.setPixelSize(size)
        metrics = QFontMetrics(font)
        br = metrics.boundingRect(version)
        br.moveTopLeft(QPoint(171, 438))

        p = QPainter(pm)
        p.setRenderHint(QPainter.Antialiasing)
        p.setRenderHint(QPainter.TextAntialiasing)
        p.setFont(font)
        p.setPen(QColor("#000000"))
        p.drawText(br, Qt.AlignLeft, version)
        p.end()
        return pm, QRect(23, 24, 200, 20)
Exemplo n.º 24
0
    def __autoScrollAdvance(self):
        """Advance the auto scroll
        """
        pos = QCursor.pos()
        pos = self.mapFromGlobal(pos)
        margin = self.__autoScrollMargin

        vvalue = self.verticalScrollBar().value()
        hvalue = self.horizontalScrollBar().value()

        vrect = QRect(0, 0, self.width(), self.height())

        # What should be the speed
        advance = 10

        # We only do auto scroll if the mouse is inside the view.
        if vrect.contains(pos):
            if pos.x() < vrect.left() + margin:
                self.horizontalScrollBar().setValue(hvalue - advance)
            if pos.y() < vrect.top() + margin:
                self.verticalScrollBar().setValue(vvalue - advance)
            if pos.x() > vrect.right() - margin:
                self.horizontalScrollBar().setValue(hvalue + advance)
            if pos.y() > vrect.bottom() - margin:
                self.verticalScrollBar().setValue(vvalue + advance)

            if self.verticalScrollBar().value() == vvalue and \
                    self.horizontalScrollBar().value() == hvalue:
                self.__stopAutoScroll()
        else:
            self.__stopAutoScroll()

        log.debug("Auto scroll advance")
Exemplo n.º 25
0
 def __visualRectForSelection(self, rect):
     h, w = self.image.shape
     rect = rect.normalized()
     rect = rect.intersected(QRect(0, 0, w, h))
     r1, r2 = rect.top(), rect.bottom() + 1
     c1, c2 = rect.left(), rect.right() + 1
     return QRectF(QPointF(c1, r1), QPointF(c2, r2))
Exemplo n.º 26
0
 def setTextRect(self, rect):
     # type: (QRect) -> None
     """
     Set the rectangle (:class:`QRect`) in which to show the message text.
     """
     if self.__textRect != rect:
         self.__textRect = QRect(rect)
         self.update()
Exemplo n.º 27
0
 def __init__(self, parent=None, **kwargs):
     # type: (Union[QWidget, QLayout, None], Any) -> None
     self.__rect = QRect()
     if parent is not None:
         super().__init__(parent, **kwargs)
     else:
         super().__init__(**kwargs)
     self.currentChanged.connect(self._onCurrentChanged)
Exemplo n.º 28
0
 def viewport_rect(self):
     """
     Return the bounding rect of the document's viewport on the scene.
     """
     view = self.document.view()
     vsize = view.viewport().size()
     viewportrect = QRect(0, 0, vsize.width(), vsize.height())
     return view.mapToScene(viewportrect).boundingRect()
Exemplo n.º 29
0
 def advance_time():
     now = datetime.now()
     time = now.strftime("%c : %f")
     w.showMessage(time, alignment=Qt.AlignCenter)
     i = now.second % 3
     rect = QRect(100, 100 + i * 20, 400, 50)
     w.setTextRect(rect)
     self.assertEqual(w.textRect(), rect)
Exemplo n.º 30
0
    def __init__(self, *args, **kwargs):
        self.__scaledMinimum = kwargs.pop('minimum', 0)
        self.__scaledMaximum = kwargs.pop('maximum', 99)
        tracking = kwargs.pop('tracking', True)

        self.__steps = max(kwargs.pop('steps', 1024), 1)
        self.__scale = (self.__scaledMaximum -
                        self.__scaledMinimum) / self.__steps
        self._tickList = kwargs.pop('ticks', None)

        if self._tickList is not None:
            self._tickList = np.unique(self._tickList)

        self._tickImage = QPixmap()

        minimum = kwargs['minimum'] = 0
        maximum = kwargs['maximum'] = self.__steps

        self.__position0 = self.__value0 = kwargs.pop('value0', minimum)
        self.__position1 = self.__value1 = kwargs.pop('value1', maximum)

        self._handleWidth = kwargs.pop('handleWidth', 10)
        self._tickHeight = 4

        kwargs['orientation'] = Qt.Horizontal
        super().__init__(*args, **kwargs)

        self.setTracking(tracking)
        self.setMouseTracking(True)
        self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)

        # holds bounding rectangles for handle0, handle1, inner handle and groove respectively; last rect is invalid
        self._rects = [QRect(), QRect(), QRect(), QRect()]

        # the index of the handle used as index to _rects; -1 is none
        self._hover = -1
        self._press = -1

        # used to calculate mouse events
        self._handleOffset = QPoint()
        self._lastPos = (maximum, minimum)
        self._lastClick = QPoint()

        #
        self._makeTickMarks()