Пример #1
0
    def requestPixmap(self, path, rsize, size):
        """@reimp @public
    @param[in]  providerId  unicode  unused
    @param[out]  rsize  QSize
    @param[in]  size  QSize
    @return  QPixmap not None

    virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
    """

        ret = QPixmap(QUrl(path).toLocalFile())
        if ret.isNull():
            derror("failed to load image: '%s'" % path)
        elif size != ret.size() and not size.isEmpty() and not ret.size(
        ).isEmpty():
            if ret.width() * size.height() > ret.height() * size.width():
                ret = ret.scaledToHeight(min(800, size.height()),
                                         Qt.SmoothTransformation)
            else:
                w = 1000 if ret.width() > ret.height() else 600
                ret = ret.scaledToWidth(min(w, size.width()),
                                        Qt.SmoothTransformation)
        #elif size != ret.size():
        #  ret = (ret.scaled(size, Qt.KeepAspectRatio, Qt.SmoothTransformation) if not size.isEmpty() else
        #         ret.scaledToWidth(size.width(), Qt.SmoothTransformation) if size.width() > 0 else
        #         ret.scaledToHeight(size.height(), Qt.SmoothTransformation) if size.height() > 0 else
        #         ret)
        rsize.setWidth(ret.width())
        rsize.setHeight(ret.height())
        return ret
Пример #2
0
    def load_image(self, img_path):
        """Load an image in widget from a file.

        Args:
            img_path -- Path of image file to load (str)
        """
        img_path = str(img_path)
        pixmap = QPixmap(img_path)
        self.imglabel.setPixmap(pixmap)
        self.imglabel.resize(pixmap.size())
        self.namelabel.setText(f"File: {img_path}")
        self._img_path = img_path
        self._initial_size = pixmap.size()
Пример #3
0
 def __init__(self, parent=None):
     super(SearchEdit, self).__init__(parent)
     
     clr_pixmap = QPixmap(':/icons/clear.png')
     self._btn_clear = QToolButton(self)
     self._btn_clear.setIcon(clr_pixmap)
     self._btn_clear.setIconSize(clr_pixmap.size())
     self._btn_clear.setCursor(Qt.ArrowCursor)
     self._btn_clear.setStyleSheet('QToolButton { border: none; padding: 0px; }');
     self._btn_clear.clicked.connect(self.clear)
     fw = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
     
     #TODO: Make a Search glyph show up properly
     self.setStyleSheet('QLineEdit { padding-right: %dpx; }' % (self._btn_clear.sizeHint().width() + fw + 1))
     msz = self.minimumSizeHint()
     self.setMinimumSize(max([msz.width(), self._btn_clear.sizeHint().height() + fw * 2 + 2]), 
                         max([msz.height(), self._btn_clear.sizeHint().height() + fw * 2 + 2]))
     self.setPlaceholderText('Search')
Пример #4
0
    def requestPixmap(self, name, rsize, size):
        """@reimp @public
    @param[in]  providerId  unicode  unused
    @param[out]  rsize  QSize
    @param[in]  size  QSize
    @return  QPixmap not None

    virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
    """
        ret = QPixmap(rc.image_path(name))
        if ret.isNull():
            derror("failed to load image: '%s'" % name)
        elif ret.size() != size:
            ret = (
                ret.scaled(size, Qt.KeepAspectRatio, Qt.SmoothTransformation)
                if not size.isEmpty() else ret.scaledToWidth(
                    size.width(), Qt.SmoothTransformation) if size.width() > 0
                else ret.scaledToHeight(size.height(), Qt.SmoothTransformation)
                if size.height() > 0 else ret)
        rsize.setWidth(ret.width())
        rsize.setHeight(ret.height())
        return ret
Пример #5
0
        if 'coords' in self.flags:
            print('x: {:.2f} {}'.format(x * scale, units))
            print('y: {:.2f} {}'.format(y * scale, units))
            print('angle: {:.2f} degrees'.format(angle))

    def draw_line(self, linef):
        line = QGraphicsLineItem(linef)
        line.setPen(QPen(QBrush(QColor(0, 0, 0)), 1))
        self.addItem(line)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    loader = QUiLoader()
    ui = loader.load('line_gui.ui')
    ui.show()

    pixmap = QPixmap(u'Top.jpg')
    pixmap = pixmap.scaled(2 * pixmap.size())

    scene = GraphicsScene('tricavity', ['axis', 'coords'],
                          scale_triplet=(.55, 3.04, 3.08))
    pix_item = scene.addPixmap(pixmap)
    pix_item.setCursor(Qt.CrossCursor)

    layout = ui.findChild(QGridLayout, 'gridLayout')
    view = QGraphicsView(scene)
    layout.addWidget(view)

    app.exec_()
Пример #6
0
        if 'coords' in self.flags:
            print('x: {:.2f} {}'.format(x*scale, units))
            print('y: {:.2f} {}'.format(y*scale, units))
            print('angle: {:.2f} degrees'.format(angle))


    def draw_line(self, linef):
        line = QGraphicsLineItem(linef)
        line.setPen(QPen(QBrush(QColor(0, 0, 0)), 1))
        self.addItem(line)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    loader = QUiLoader()
    ui = loader.load('line_gui.ui')
    ui.show()
    
    pixmap = QPixmap(u'Top.jpg')
    pixmap = pixmap.scaled(2*pixmap.size())

    scene = GraphicsScene('tricavity', ['axis', 'coords'], scale_triplet=(.55,3.04,3.08))
    pix_item = scene.addPixmap(pixmap)
    pix_item.setCursor(Qt.CrossCursor)

    layout = ui.findChild(QGridLayout, 'gridLayout')
    view = QGraphicsView(scene)
    layout.addWidget(view)

    app.exec_()