コード例 #1
0
ファイル: qt.py プロジェクト: giumas/gsdview
    def _setupFormats(self):
        '''Setup a different format for the different message types.'''

        fmap = {}

        fmt = QtGui.QTextCharFormat()
        fmt.setForeground(QtGui.QColor('red'))
        fmap['error'] = fmt

        fmt = QtGui.QTextCharFormat()
        fmt.setForeground(QtGui.QColor('orange'))
        fmap['warning'] = fmt

        fmt = QtGui.QTextCharFormat()
        fmt.setForeground(QtGui.QColor('blue'))
        fmap['info'] = fmt

        fmt = QtGui.QTextCharFormat()
        fmt.setForeground(QtGui.QColor('gray'))
        fmap['debug'] = fmt

        fmt = QtGui.QTextCharFormat()
        fmt.setFontWeight(QtGui.QFont.Bold)
        fmap['cmd'] = fmt

        return fmap
コード例 #2
0
    def plot(self, polygon):
        #~ if points[0] != points[-1]:
            #~ poly.append(poly[0])

        # View box on the overview
        pen = QtGui.QPen(QtCore.Qt.SolidLine)
        pen.setColor(QtGui.QColor(QtCore.Qt.red))

        item = self.graphicsview.scene().addPolygon(polygon, pen)
        item.setZValue(1)

        return item
コード例 #3
0
ファイル: gdalqt.py プロジェクト: giumas/gsdview
def gdalcolorentry2qcolor(colrentry, interpretation=gdal.GPI_RGB):
    qcolor = QtGui.QColor()

    if interpretation == gdal.GPI_RGB:
        qcolor.setRgb(colrentry.c1, colrentry.c2, colrentry.c3, colrentry.c4)
    elif interpretation == gdal.GPI_Gray:
        qcolor.setRgb(colrentry.c1, colrentry.c1, colrentry.c1)
    elif interpretation == gdal.GPI_CMYK:
        qcolor.setCmyk(colrentry.c1, colrentry.c2, colrentry.c3, colrentry.c4)
    elif interpretation == gdal.GPI_HLS:
        qcolor.setHsv(colrentry.c1, colrentry.c2, colrentry.c3)
        # , colrentry.c4)
    else:
        raise ValueError('invalid color intepretatin: "%s"' % interpretation)

    return qcolor
コード例 #4
0
        elif isinstance(obj, QtCore.QAbstractItemModel):
            doc = modelToTextDocument(obj)
            doc.print_(printer)
        else:
            coreprint(obj, printer)


# QImage helpers ###########################################################
# from PyQt4.Qwt5 import toQImage as _toQImage
# def numpy2qimage(data):
#    # @NOTE: for Qwt5 < 5.2.0
#    # return toQImage(data.transpose())
#    return _toQImage(data)

import numpy as np
GRAY_COLORTABLE = [QtGui.QColor(i, i, i).rgba() for i in range(256)]
RED_COLORTABLE = [QtGui.QColor(i, 0, 0).rgba() for i in range(256)]
GREEN_COLORTABLE = [QtGui.QColor(0, i, 0).rgba() for i in range(256)]
BLUE_COLORTABLE = [QtGui.QColor(0, 0, i).rgba() for i in range(256)]
JET_COLORTABLE = [QtGui.QColor(r, g, b).rgba() for r, g, b in [
    [  0,   0, 128],
    [  0,   0, 132],
    [  0,   0, 137],
    [  0,   0, 141],
    [  0,   0, 146],
    [  0,   0, 150],
    [  0,   0, 155],
    [  0,   0, 159],
    [  0,   0, 164],
    [  0,   0, 168],
    [  0,   0, 173],
コード例 #5
0
class NavigationGraphicsView(QtWidgets.QGraphicsView):
    '''Graphics view for dataset navigation.

    The view usually displays an auto-scalled low resolution overview
    of the scene with a red box indicating the area currently displayed
    in the high resolution view.

    :SIGNALS:

        * :attr:`mousePressed`
        * :attr:`mouseMoved`

    '''

    BOXCOLOR = QtGui.QColor(QtCore.Qt.red)
    BOXWIDTH = 50

    #: SIGNAL: it is emitted when a mouse button is presses on the view
    #:
    #: :param point:
    #:     the scene position
    #: :param mousebutton:
    #:     the ID of the pressed button
    #: :param dragmode:
    #:     current darg mode
    #:
    #: :C++ signature: `void mousePressed(QPointF, Qt::MouseButtons,
    #:                                    QGraphicsView::DragMode)`
    mousePressed = QtCore.Signal(QtCore.QPointF, QtCore.Qt.MouseButtons,
                                 QtWidgets.QGraphicsView.DragMode)

    #: SIGNAL: it is emitted when the mouse is moved on the view
    #:
    #: :param point:
    #:     the scene position
    #: :param mousebutton:
    #:     the ID of the pressed button
    #: :param dragmode:
    #:     current darg mode
    #:
    #: :C++ signature: `void mouseMoved(QPointF, Qt::MouseButtons,
    #:                                    QGraphicsView::DragMode)`
    mouseMoved = QtCore.Signal(QtCore.QPointF, QtCore.Qt.MouseButtons,
                               QtWidgets.QGraphicsView.DragMode)

    def __init__(self, parent=None, **kwargs):
        super(NavigationGraphicsView, self).__init__(parent, **kwargs)
        self._viewbox = None
        self._autoscale = True
        self.setMouseTracking(True)

        # default pen
        self._pen = QtGui.QPen()
        self._pen.setColor(self.BOXCOLOR)
        self._pen.setWidth(self.BOXWIDTH)

    @property
    def viewbox(self):
        '''Viewport box in scene coordinates'''
        return self._viewbox

    @viewbox.setter
    def viewbox(self, box):
        '''Set the viewport box in scene coordinates'''
        assert isinstance(box, (QtCore.QRect, QtCore.QRectF))
        self._viewbox = box
        if self.isVisible():
            # @WARNING: calling "update" on the scene causes a repaint of
            #           *all* attached views and for each view the entire
            #           exposedRect is updated.
            #           Using QGraphicsView.invalidateScene with the
            #           QtWidgets.QGraphicsScene.ForegroundLayer parameter
            #           should be faster and repaint only one layer of the
            #           current view.

            # @TODO: check
            #self.invalidateScene(self.sceneRect(),
            #                     QtWidgets.QGraphicsScene.ForegroundLayer)
            self.scene().update()

    def drawForeground(self, painter, rect):
        if not self.viewbox:
            return

        pen = painter.pen()
        try:
            box = self.viewbox.intersected(self.sceneRect())
            painter.setPen(self._pen)
            painter.drawRect(box)
            #painter.drawConvexPolygon(self.viewbox) #@TODO: check
        finally:
            painter.setPen(pen)

    def fitInView(self, rect=None, aspectRatioMode=QtCore.Qt.KeepAspectRatio):
        if not rect:
            scene = self.scene()
            if scene:
                rect = scene.sceneRect()
            else:
                return
        QtWidgets.QGraphicsView.fitInView(self, rect, aspectRatioMode)

    @property
    def autoscale(self):
        return self._autoscale

    @autoscale.setter
    def autoscale(self, flag):
        self._autoscale = bool(flag)
        if self._autoscale:
            self.fitInView()
        else:
            self.setTransform(QtGui.QTransform())
            self.update()

    def resizeEvent(self, event):
        if self.autoscale:
            self.fitInView()
        return QtWidgets.QGraphicsView.resizeEvent(self, event)

    # @TODO: use event filters
    def mousePressEvent(self, event):
        pos = self.mapToScene(event.pos())
        self.mousePressed.emit(pos, event.buttons(), self.dragMode())
        return QtWidgets.QGraphicsView.mousePressEvent(self, event)

    def mouseMoveEvent(self, event):
        pos = self.mapToScene(event.pos())
        self.mouseMoved.emit(pos, event.buttons(), self.dragMode())
        return QtWidgets.QGraphicsView.mouseMoveEvent(self, event)