示例#1
0
def test_opts():
    # test that curve and scatter plot properties get updated from PlotDataItem methods
    y = list(np.random.normal(size=100))
    x = np.linspace(5, 10, 100)
    pdi = pg.PlotDataItem(x, y)
    pen = QtGui.QPen(QtGui.QColor('#FF0000'))
    pen2 = QtGui.QPen(QtGui.QColor('#FFFF00'))
    brush = QtGui.QBrush(QtGui.QColor('#00FF00'))
    brush2 = QtGui.QBrush(QtGui.QColor('#00FFFF'))
    float_value = 1.0 + 20 * np.random.random()
    pen2.setWidth(int(float_value))
    pdi.setPen(pen)
    assert pdi.curve.opts['pen'] == pen
    pdi.setShadowPen(pen2)
    assert pdi.curve.opts['shadowPen'] == pen2
    pdi.setFillLevel(float_value)
    assert pdi.curve.opts['fillLevel'] == float_value
    pdi.setFillBrush(brush2)
    assert pdi.curve.opts['brush'] == brush2

    pdi.setSymbol('t')
    assert pdi.scatter.opts['symbol'] == 't'
    pdi.setSymbolPen(pen)
    assert pdi.scatter.opts['pen'] == pen
    pdi.setSymbolBrush(brush)
    assert pdi.scatter.opts['brush'] == brush
    pdi.setSymbolSize(float_value)
    assert pdi.scatter.opts['size'] == float_value
    def setBackground(self):

        self.bgType = self.settings_widget.p[("ViewBox Options",
                                              "ViewBox Background", "bg-type")]
        self.bgColor1 = self.settings_widget.p[("ViewBox Options",
                                                "ViewBox Background",
                                                "bg-color 1")]
        self.bgColor2 = self.settings_widget.p[("ViewBox Options",
                                                "ViewBox Background",
                                                "bg-color 2")]

        bg = self.view_box.background
        self.view_box.background.show()
        bg.setVisible(True)
        if self.bgType == "LinearGradientPattern":
            g = QtGui.QLinearGradient(
                QtCore.QRectF(self.rect()).topLeft(),
                QtCore.QRectF(self.rect()).bottomLeft(),
            )
            g.setColorAt(0, self.bgColor1)
            g.setColorAt(1, self.bgColor2)
            brush = QtGui.QBrush(g)
        else:
            brush = QtGui.QBrush()
            brush.setStyle(getQtPattern(self.bgType))
            brush.setColor(self.bgColor1)

        bg.setBrush(brush)
示例#3
0
    def set_background(self):
        self.bg_type = self.settings_widget.p[('ViewBox Options',
                                               'ViewBox Background',
                                               'bg-type')]
        self.bg_color1 = self.settings_widget.p[('ViewBox Options',
                                                 'ViewBox Background',
                                                 'bg-color 1')]
        self.bg_color2 = self.settings_widget.p[('ViewBox Options',
                                                 'ViewBox Background',
                                                 'bg-color 2')]

        bg = self.view_box.background
        self.view_box.background.show()
        bg.setVisible(True)
        if self.bg_type == 'LinearGradientPattern':
            g = QtGui.QLinearGradient(
                QtCore.QRectF(self.rect()).topLeft(),
                QtCore.QRectF(self.rect()).bottomLeft())
            g.setColorAt(0, self.bg_color1)
            g.setColorAt(1, self.bg_color2)
            brush = QtGui.QBrush(g)
        else:
            brush = QtGui.QBrush()
            brush.setStyle(get_qt_pattern(self.bg_type))
            brush.setColor(self.bg_color1)

        bg.setBrush(brush)
示例#4
0
    def paintEvent(self, pevent):
        painter = QtGui.QPainter(self)

        # Background
        if self.orientation == QtCore.Qt.Horizontal:
            bg_rect = QtCore.QRectF(SC_LEFT_RIGHT_MARGIN,
                                    (self.height() - SC_SLIDER_BAR_HEIGHT) / 2,
                                    self.width() - SC_LEFT_RIGHT_MARGIN * 2,
                                    SC_SLIDER_BAR_HEIGHT)
        else:
            bg_rect = QtCore.QRectF((self.width() - SC_SLIDER_BAR_HEIGHT) / 2,
                                    SC_LEFT_RIGHT_MARGIN, SC_SLIDER_BAR_HEIGHT,
                                    self.height() - SC_LEFT_RIGHT_MARGIN * 2)

        painter.setPen(QtGui.QPen(QtCore.Qt.black, 0.8))
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setBrush(QtGui.QBrush(OUTLINE_RECT_COLOR))
        painter.drawRoundedRect(bg_rect, 1, 1)
        painter.fillRect(bg_rect, QtGui.QBrush(OUTLINE_RECT_COLOR))

        # First value handle rect
        pen = QtGui.QPen(HANDLE_OUTLINE_COLOR, 0.8)
        painter.setPen(pen)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setBrush(QtGui.QBrush(HANDLE_COLOR))

        left_handle_rect = self.first_handle_rect
        if self.range_type & HandleOption.LeftHandle:
            painter.drawRoundedRect(left_handle_rect, 2, 2)

        # Second value handle rect
        right_handle_rect = self.second_handle_rect
        if self.range_type & HandleOption.RightHandle:
            painter.drawRoundedRect(right_handle_rect, 2, 2)

        # Handles
        selected_rect = QtCore.QRectF(bg_rect)
        if self.orientation == QtCore.Qt.Horizontal:
            selected_rect.setLeft(
                (left_handle_rect.right() if self.range_type
                 & HandleOption.LeftHandle else left_handle_rect.left()) + 0.5)
            selected_rect.setRight(
                (right_handle_rect.left() if self.range_type
                 & HandleOption.RightHandle else right_handle_rect.right()) -
                0.5)
        else:
            selected_rect.setTop(
                (left_handle_rect.bottom() if self.range_type
                 & HandleOption.LeftHandle else left_handle_rect.top()) + 0.5)
            selected_rect.setBottom(
                (right_handle_rect.top() if self.range_type
                 & HandleOption.RightHandle else right_handle_rect.bottom()) -
                0.5)

        if self.isEnabled():
            painter.setPen(QtCore.Qt.NoPen)
        painter.setBrush(QtGui.QBrush(self.bg_color))
        painter.drawRect(selected_rect)
示例#5
0
 def update(self):
     self.update_ct()
     self.gradient.setStops([(i / 255, QtGui.QColor(*tuple(self.lut[i])))
                             for i in range(256)])
     self.color_bar.setBrush(QtGui.QBrush(self.gradient))
     self.imageItem.setLookupTable(self.lut)
     self.update_cmap_norm()
    def __init__(self):
        super(TemplateBaseClass, self).__init__()
        
        # Create the main window
        self.ui = WindowTemplate()
        self.ui.setupUi(self)
        
        #setup uv vis plot
        self.plot = self.ui.plotWidget.getPlotItem()
        self.plot.setTitle(title="Wavelength vs. Intensity")
        self.plot.setLabel('bottom', 'Wavelength', unit='nm')
        self.plot.setLabel('left', 'Intensity', unit='a.u.')
        self.plot.setLogMode(x=None, y=1)

        #setup line rois for laser and emission
        self.laser_region = pg.LinearRegionItem(brush=QtGui.QBrush(QtGui.QColor(255, 0, 0, 50)))
        self.laser_region.sigRegionChanged.connect(self.update_laser_spinBoxes)
        self.emission_region = pg.LinearRegionItem()
        self.emission_region.sigRegionChanged.connect(self.update_emission_spinBoxes)
        self.laser_region.setRegion((200, 400))
        self.emission_region.setRegion((700, 800))

        #setup ui signals
        self.ui.load_data_pushButton.clicked.connect(self.open_data_file)
        self.ui.plot_pushButton.clicked.connect(self.plot_intensity)
        self.ui.clear_pushButton.clicked.connect(self.clear)
        self.ui.calculate_plqe_pushButton.clicked.connect(self.calculate_plqe)
        self.ui.laser_start_spinBox.valueChanged.connect(self.update_laser_region)
        self.ui.laser_stop_spinBox.valueChanged.connect(self.update_laser_region)
        self.ui.emission_start_spinBox.valueChanged.connect(self.update_emission_region)
        self.ui.emission_stop_spinBox.valueChanged.connect(self.update_emission_region)

        self.show()
示例#7
0
    def registerCmap(self, cmapNames):
        """ Add matplotlib cmaps to the GradientEditors context menu"""
        self.gradientEditorItem.menu.addSeparator()
        savedLength = self.gradientEditorItem.length
        self.gradientEditorItem.length = 100

        # iterate over the list of cmap names and check if they're avaible in MPL
        for cmapName in cmapNames:
            if not hasattr(cm, cmapName):
                print('[extendedimageview] Unknown cmap name: \'{}\'. Your Matplotlib installation might be outdated.'.format(cmapName))
            else:
                # create a Dictionary just as the one at the top of GradientEditorItem.py
                cmap = getattr(cm, cmapName)
                self.mplCmaps[cmapName] = {'ticks': cmapToColormap(cmap), 'mode': 'rgb'}

                # Create the menu entries
                # The following code is copied from pyqtgraph.ImageView.__init__() ...
                px = QtGui.QPixmap(100, 15)
                p = QtGui.QPainter(px)
                self.gradientEditorItem.restoreState(self.mplCmaps[cmapName])
                grad = self.gradientEditorItem.getGradient()
                brush = QtGui.QBrush(grad)
                p.fillRect(QtCore.QRect(0, 0, 100, 15), brush)
                p.end()
                label = QtGui.QLabel()
                label.setPixmap(px)
                label.setContentsMargins(1, 1, 1, 1)
                act = QtGui.QWidgetAction(self.gradientEditorItem)
                act.setDefaultWidget(label)
                act.triggered.connect(self.cmapClicked)
                act.name = cmapName
                self.gradientEditorItem.menu.addAction(act)
        self.gradientEditorItem.length = savedLength
        def edge_glow(strength, hue, saturation, lightness):
            if strength == 0:
                return
            hue %= 1

            radius = 5.5
            brightness = util.lerp(strength, 0, 1, 0, 1.0, clip=True)

            grad = QtGui.QRadialGradient(0.5, 0.5, 0.5)
            grad.setCoordinateMode(QtGui.QGradient.ObjectBoundingMode)
            grad.setColorAt(0.0, QtCore.Qt.transparent)
            grad.setColorAt(0.6, QtCore.Qt.transparent)
            grad.setColorAt(
                0.8,
                QtGui.QColor.fromHsvF(hue, saturation, lightness,
                                      brightness * 0.8))
            grad.setColorAt(
                1.0,
                QtGui.QColor.fromHsvF(hue, saturation * 0.3, lightness,
                                      brightness))
            painter.setBrush(QtGui.QBrush(grad))
            painter.setPen(QtCore.Qt.NoPen)

            painter.drawEllipse(
                QtCore.QRectF(-radius, -radius, radius * 2, radius * 2))
示例#9
0
    def updateBackground(self):
        self.background.show()
        self.background.setVisible(True)
        if self.bgType == 'LinearGradientPattern':
            g = QtGui.QLinearGradient(
                QtCore.QRectF(self.rect()).topLeft(),
                QtCore.QRectF(self.rect()).bottomLeft())
            g.setColorAt(0, self.bgColor1)
            g.setColorAt(1, self.bgColor2)
            brush = QtGui.QBrush(g)
        else:
            brush = QtGui.QBrush()
            brush.setStyle(nameToPattern[str(self.bgType)])
            brush.setColor(self.bgColor1)

        self.background.setBrush(brush)
示例#10
0
    def setDefault(self, rnum=None):
        if rnum is None and self.table.currentRow() < 0:
            QtGui.QMessageBox.warning(None, "Set Default", "No item selected")
        else:
            if rnum is None:
                rnum = self.table.currentRow()
            else:
                self.table.setCurrentCell(rnum, 0)

            highlight = QtGui.QBrush(QtGui.QColor(0, 255, 0))

            for row in range(0, self.table.rowCount()):
                for col in range(0, self.table.columnCount()):
                    item = self.table.item(row, col)
                    if row == rnum:
                        self.table.item(row, col).setBackground(highlight)
                        # item.setFlags(item.flags() | QtCore.Qt.ItemIsSelectable)
                    else:
                        self.table.item(row, col).setBackground(
                            self.oldbackgrounds[row])
                        # item.setFlags(item.flags() & ~QtCore.Qt.ItemIsSelectable)

            if self.editor:
                desc = self.table.item(rnum, 0).text()
                fname = self.table.item(rnum, 1).text()
                self.editor(filename=fname, filedesc=desc, default=True)
示例#11
0
    def process(self, input, display=True):
        #print "scatterplot process"
        if not display:
            return {'plot': None}

        self.updateKeys(input[0])

        x = str(self.ctrls['x'].currentText())
        y = str(self.ctrls['y'].currentText())
        size = str(self.ctrls['size'].currentText())
        pen = QtGui.QPen(QtGui.QColor(0, 0, 0, 0))
        points = []
        for i in input:
            pt = {'pos': (i[x], i[y])}
            if self.ctrls['sizeEnabled'].isChecked():
                pt['size'] = i[size]
            if self.ctrls['borderEnabled'].isChecked():
                pt['pen'] = QtGui.QPen(self.ctrls['border'].getColor(i))
            else:
                pt['pen'] = pen
            if self.ctrls['colorEnabled'].isChecked():
                pt['brush'] = QtGui.QBrush(self.ctrls['color'].getColor(i))
            points.append(pt)
        self.item.setPxMode(not self.ctrls['absoluteSize'].isChecked())

        self.item.setPoints(points)

        return {'plot': self.item}
示例#12
0
    def __init__(self, param, depth):
        ParameterItem.__init__(self, param, depth)
        if depth == 0:
            for c in [0, 1]:
                self.setBackground(c, QtGui.QBrush(QtGui.QColor(100, 100,
                                                                100)))
                self.setForeground(c, QtGui.QBrush(QtGui.QColor(220, 220,
                                                                255)))
                font = self.font(c)
                font.setBold(True)
                font.setPointSize(font.pointSize() + 1)
                self.setFont(c, font)
                self.setSizeHint(0, QtCore.QSize(0, 25))
        else:
            for c in [0, 1]:
                self.setBackground(c, QtGui.QBrush(QtGui.QColor(220, 220,
                                                                220)))
                font = self.font(c)
                font.setBold(True)
                #font.setPointSize(font.pointSize()+1)
                self.setFont(c, font)
                self.setSizeHint(0, QtCore.QSize(0, 20))

        self.addItem = None
        if 'addText' in param.opts:
            addText = param.opts['addText']
            if 'addList' in param.opts:
                self.addWidget = QtGui.QComboBox()
                self.addWidget.addItem(addText)
                for t in param.opts['addList']:
                    self.addWidget.addItem(t)
                self.addWidget.currentIndexChanged.connect(self.addChanged)
            else:
                self.addWidget = QtGui.QPushButton(addText)
                self.addWidget.clicked.connect(self.addClicked)
            w = QtGui.QWidget()
            l = QtGui.QHBoxLayout()
            l.setContentsMargins(0, 0, 0, 0)
            w.setLayout(l)
            l.addWidget(self.addWidget)
            l.addItem(
                QtGui.QSpacerItem(200, 10, QtGui.QSizePolicy.Expanding,
                                  QtGui.QSizePolicy.Minimum))
            self.addWidgetBox = w
            self.addItem = QtGui.QTreeWidgetItem([])
            self.addItem.setFlags(QtCore.Qt.ItemIsEnabled)
            ParameterItem.addChild(self, self.addItem)
示例#13
0
    def _make_arrow_picture(self, ix, bar, sig):
        arrow_picture = QtGui.QPicture()
        painter = QtGui.QPainter(arrow_picture)

        if sig == 'BK':
            painter.setPen(self._white_pen)
            brush = QtGui.QBrush(QtGui.QColor("red"))
            painter.setFont(NORMAL_FONT)
            painter.setBrush(brush)

            # 绘制箭头和文本
            text = ['BK', bar.trade_price]
            painter_path = self.makeArrowPath(ix, bar.low, "up", text)
            painter.drawPath(painter_path)

        elif sig == 'SP':
            painter.setPen(self._white_pen)
            brush = QtGui.QBrush(QtGui.QColor("gray"))
            painter.setBrush(brush)

            text = ['SP', bar.trade_price]
            painter_path = self.makeArrowPath(ix, bar.high, "down", text)
            painter.drawPath(painter_path)

        elif sig == 'SK':
            painter.setPen(self._white_pen)
            brush = QtGui.QBrush(QtGui.QColor("white"))
            painter.setBrush(brush)

            text = ['SK', bar.trade_price]
            painter_path = self.makeArrowPath(ix, bar.high, "down", text)
            painter.drawPath(painter_path)

        elif sig == 'BP':
            painter.setPen(self._white_pen)
            brush = QtGui.QBrush(QtGui.QColor("darkRed"))
            painter.setBrush(brush)
            painter_path = self.makeArrowPath(ix, bar.low, "up")
            painter.drawPath(painter_path)

            text = ['BP', bar.trade_price]
            painter_path = self.makeArrowPath(ix, bar.low, "up", text)
            painter.drawPath(painter_path)

        painter.end()
        return arrow_picture
示例#14
0
 def generatePicture(self):
     self.picture = QtGui.QPicture()
     p = QtGui.QPainter(self.picture)
     p.setPen(QtGui.QPen(Qt.black, 0.5, Qt.SolidLine))
     p.setBrush(QtGui.QBrush(Qt.yellow, Qt.SolidPattern))
     p.drawEllipse(self.pose, self.R, self.R)
     p.drawLine(self.pose, self.pt)
     p.end()
示例#15
0
    def paintEvent(self, ev):
        if self.dropArea is None:
            return
        p = QtGui.QPainter(self)
        rgn = self.rect()

        p.setBrush(QtGui.QBrush(QtGui.QColor(100, 100, 255, 50)))
        p.setPen(QtGui.QPen(QtGui.QColor(50, 50, 150), 3))
        p.drawRect(rgn)
示例#16
0
 def __init__(self, sides, parent=None):
     QtWidgets.QWidget.__init__(self, parent)
     self.pen = QtGui.QPen(QtGui.QColor(0, 0, 0))  # set lineColor
     self.pen.setWidth(3)  # set lineWidth
     self.brush = QtGui.QBrush(QtGui.QColor(255, 255, 255,
                                            255))  # set fillColor
     self.polygon = self.createPoly(
         sides, 260,
         18)  # polygon with n points, radius, angle of the first point
示例#17
0
    def analyse_display(self,
                        classified=False,
                        a_segments=[],
                        b_segments=[],
                        c_segments=[]):
        self.analysebttn.setEnabled(False)
        self.line.clear()
        self.curve = self.line.plot()
        if self.filtered_signal != []:
            self.curve.setData(self.ppg_x_2,
                               self.filtered_signal[:len(self.ppg_x_2)])
        else:
            self.curve.setData(self.ppg_x, self.data)

        if not classified:
            self.a_segments, self.b_segments, self.c_segments = self.classify()
        else:
            self.a_segments = a_segments
            self.b_segments = b_segments
            self.c_segments = c_segments

        self.period = int(self.fs) * 3
        print("a segments: ", self.a_segments)
        print("b segments: ", self.b_segments)
        print("c segments: ", self.c_segments)
        for a in self.a_segments:
            a_lr = pg.LinearRegionItem(values=[a, (a + 3)],
                                       movable=False,
                                       brush=QtGui.QBrush(
                                           QtGui.QColor(0, 255, 0, 50)))
            # a_lr= pg.LinearRegionItem(values=[a,(a+3)],movable=False, brush=QtGui.QBrush(QtGui.QColor(255, 0, 0, 50)))
            self.line.addItem(a_lr)
        for b in self.b_segments:
            b_lr = pg.LinearRegionItem(values=[b, (b + 3)],
                                       movable=False,
                                       brush=QtGui.QBrush(
                                           QtGui.QColor(0, 0, 255, 50)))
            self.line.addItem(b_lr)
        for c in self.c_segments:
            c_lr = pg.LinearRegionItem(values=[c, (c + 3)],
                                       movable=False,
                                       brush=QtGui.QBrush(
                                           QtGui.QColor(255, 0, 0, 50)))
            self.line.addItem(c_lr)
示例#18
0
 def paintEvent(self, event):
     # print("paintevent")
     painter = QtGui.QPainter()
     painter.begin(self)
     brush = QtGui.QBrush(self.pixmap)
     painter.setBrush(brush)
     painter.drawRect(0, 0, 1000, 800)
     painter.end()
     time.sleep(0.05)
     self.update()
示例#19
0
 def updateDepth(self, depth):
     ## Change item's appearance based on its depth in the tree
     ## This allows highest-level groups to be displayed more prominently.
     if depth == 0:
         for c in [0,1]:
             self.setBackground(c, QtGui.QBrush(QtGui.QColor(100,100,100)))
             self.setForeground(c, QtGui.QBrush(QtGui.QColor(220,220,255)))
             font = self.font(c)
             font.setBold(True)
             font.setPointSize(font.pointSize()+1)
             self.setFont(c, font)
             self.setSizeHint(0, QtCore.QSize(0, 25))
     else:
         for c in [0,1]:
             self.setBackground(c, QtGui.QBrush(QtGui.QColor(220,220,220)))
             font = self.font(c)
             font.setBold(True)
             #font.setPointSize(font.pointSize()+1)
             self.setFont(c, font)
             self.setSizeHint(0, QtCore.QSize(0, 20))
示例#20
0
    def drawHeader(self, painter):
        try:
            bgBrush = QtGui.QBrush(QtGui.QColor(255, 255, 153))
            painter.setBrush(bgBrush)

            adjustWidth = 60
            painter.drawRect(
                QtCore.QRectF(self.rect.x(), self.rect.y(),
                              (self.rect.width() / 2) - adjustWidth,
                              self.rect.height()))
            painter.drawText(
                QtCore.QRectF(self.rect.x() + 5,
                              self.rect.y() + 5,
                              (self.rect.width() / 2) - adjustWidth,
                              self.rect.height()), "CE OI")
            ceLtpX = (self.rect.width() / 2) - adjustWidth
            ceLtpW = 35
            painter.drawRect(
                QtCore.QRectF(ceLtpX, self.rect.y(), ceLtpW,
                              self.rect.height()))
            painter.drawText(
                QtCore.QRectF(ceLtpX + 5,
                              self.rect.y() + 5, ceLtpW, self.rect.height()),
                "LTP")
            strikeX = ceLtpX + ceLtpW
            strikeW = 50
            painter.drawRect(
                QtCore.QRectF(strikeX, self.rect.y(), strikeW + 3,
                              self.rect.height()))
            painter.drawText(
                QtCore.QRectF(strikeX + 5,
                              self.rect.y() + 5, strikeW, self.rect.height()),
                "Strike")
            peLtpX = strikeX + strikeW
            peLtpW = 35
            painter.drawRect(
                QtCore.QRectF(peLtpX + 3, self.rect.y(), peLtpW,
                              self.rect.height()))
            painter.drawText(
                QtCore.QRectF(peLtpX + 5,
                              self.rect.y() + 5, peLtpW, self.rect.height()),
                "LTP")
            painter.drawRect(
                QtCore.QRectF((self.rect.width() / 2) + adjustWidth,
                              self.rect.y(),
                              (self.rect.width() / 2) - adjustWidth,
                              self.rect.height()))
            painter.drawText(
                QtCore.QRectF((self.rect.width() / 2) + adjustWidth + 5,
                              self.rect.y() + 5,
                              (self.rect.width() / 2) - adjustWidth,
                              self.rect.height()), "PE OI")
        except:
            log.logException("Exception in OpenInterestChangeItem while paint")
示例#21
0
 def __init__(self, size, offset):
     self.size = size
     self.offset = offset
     UIGraphicsItem.__init__(self)
     self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
     self.brush = QtGui.QBrush(QtGui.QColor(200, 0, 0))
     self.pen = QtGui.QPen(QtGui.QColor(0, 0, 0))
     self.labels = {'max': 1, 'min': 0}
     self.gradient = QtGui.QLinearGradient()
     self.gradient.setColorAt(0, QtGui.QColor(0, 0, 0))
     self.gradient.setColorAt(1, QtGui.QColor(255, 0, 0))
示例#22
0
 def set_gradient_brush():
     """set color gradient, return QtGui.QBrush obj"""
     grad = QtGui.QLinearGradient(0, 0, 0, 1)
     grad.setColorAt(0.1, pg.mkColor("#FF0000"))
     grad.setColorAt(0.24, pg.mkColor("#FF7F00"))
     grad.setColorAt(0.38, pg.mkColor("#FFFF00"))
     grad.setColorAt(0.52, pg.mkColor("#00FF00"))
     grad.setColorAt(0.66, pg.mkColor("#0000FF"))
     grad.setColorAt(0.80, pg.mkColor("#4B0082"))
     grad.setColorAt(0.94, pg.mkColor("#9400D3"))
     grad.setCoordinateMode(QtGui.QGradient.ObjectMode)
     return QtGui.QBrush(grad)
示例#23
0
 def paintEvent(self, ev):
     QtGui.QPushButton.paintEvent(self, ev)
     p = QtGui.QPainter(self)
     rect = self.rect().adjusted(6, 6, -6, -6)
     ## draw white base, then texture for indicating transparency, then actual color
     p.setBrush(functions.mkBrush('w'))
     p.drawRect(rect)
     p.setBrush(QtGui.QBrush(QtCore.Qt.DiagCrossPattern))
     p.drawRect(rect)
     p.setBrush(functions.mkBrush(self._color))
     p.drawRect(rect)
     p.end()
示例#24
0
 def get_brushes(self, intensities):
     a = min(intensities)
     b = max(intensities)
     colormap = matplotlib.cm.viridis
     positions = np.linspace(a, b, len(colormap.colors), endpoint=True)
     q_colormap = pg.ColorMap(pos=positions, color=colormap.colors)
     color_for_points = q_colormap.map(intensities)
     brushes = [
         QtGui.QBrush(QtGui.QColor(*color_for_points[i, :].tolist()))
         for i in range(color_for_points.shape[0])
     ]
     return brushes
示例#25
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.setRenderHints(QtGui.QPainter.Antialiasing
                            | QtGui.QPainter.SmoothPixmapTransform)

        scene = QtGui.QGraphicsScene()
        scene.setBackgroundBrush(QtGui.QBrush(QtCore.Qt.black))

        size = 10
        spacing = 4

        self.pixels = np.empty(config.DISPLAY_SHAPE, dtype=np.object_)
        for x, y in np.ndindex(self.pixels.shape):
            pixel = scene.addEllipse(x * (size + spacing),
                                     y * (size + spacing), size, size)
            pixel.setPen(
                QtGui.QPen(QtGui.QBrush(QtGui.QColor(127, 127, 127)), 1.0))
            pixel.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 0)))
            self.pixels[x, y] = pixel

        self.setScene(scene)
示例#26
0
    def __init__(self,
                 pos,
                 size,
                 centered=False,
                 movable=True,
                 sideScalers=True,
                 parent=None,
                 **args):
        #QtGui.QGraphicsRectItem.__init__(self, 0, 0, size[0], size[1])
        pg.ROI.__init__(self, pos, size, movable=movable, **args)
        self.parent = parent
        self.mouseHovering = False
        self.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 255, 50)))
        self.setHoverBrush(QtGui.QBrush(QtGui.QColor(0, 0, 255, 100)))
        self.transparent = True

        #self.addTranslateHandle(center)
        if self.translatable:
            self.addScaleHandle([1, 1], [0, 0])  # top right
            self.addScaleHandle([1, 0], [0, 1])  # bottom right
            self.addScaleHandle([0, 1], [1, 0])  # top left
            self.addScaleHandle([0, 0], [1, 1])  # bottom left
示例#27
0
    def paint(self, p, opt, widget):
        super(GradientLegend, self).paint(p, opt, widget)
        pen = QtGui.QPen(QtGui.QColor(0, 0, 0))
        rect = self.boundingRect()
        unit = self.pixelSize()

        offset = 10, 10
        size = widget.width() / 10, widget.height() / 3
        padding = 10

        x1 = rect.left() + unit[0] * offset[0]
        x2 = x1 + unit[0] * size[0]
        y1 = rect.bottom() - unit[1] * offset[1]
        y2 = y1 - unit[1] * size[1]

        # Draw background
        p.setPen(pen)
        p.setBrush(QtGui.QBrush(QtGui.QColor(255, 255, 255, 100)))
        rect = QtCore.QRectF(
            QtCore.QPointF(x1 - padding * unit[0], y1 + padding * unit[1]),
            QtCore.QPointF(x2 + padding * unit[0], y2 - padding * unit[1]))
        p.drawRect(rect)

        p.scale(unit[0], unit[1])

        # Draw color bar
        gradient = QtGui.QLinearGradient()
        i = 0.0
        while i < 1:
            color = plt.get_cmap(self.cm_type)(i)
            color = [x * 255 for x in color]
            gradient.setColorAt(i, QtGui.QColor(*color))
            i += 0.1
        gradient.setStart(0, y1 / unit[1])
        gradient.setFinalStop(0, y2 / unit[1])
        p.setBrush(gradient)
        rect = QtCore.QRectF(QtCore.QPointF(x1 / unit[0], y1 / unit[1]),
                             QtCore.QPointF(x2 / unit[0], y2 / unit[1]))
        p.drawRect(rect)

        # Draw labels
        self.labelsize = self.maximumLabelSize(p)
        lh = self.labelsize.height()
        p.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0)))
        for label in self.labels:
            y = y1 + self.labels[label] * (y2 - y1)
            p.drawText(
                QtCore.QRectF(x1 + widget.width() / 20, y - lh / 2.0, 1000,
                              lh), QtCore.Qt.AlignVCenter, str(label))
示例#28
0
    def __init__(self, pos, id=None, **kargs):
        pg.ROI.__init__(self, pos, **kargs)
        self.posx = pos[0]
        self.posy = pos[1]
        # set the size and color of the handle
        self.handleSize = 9
        self.handlePen = QtGui.QPen(QtGui.QColor(255, 255, 255))
        self.hand1 = None
        self.hand2 = None

        #status
        self._isLocked = False
        self._remove_flag = False
        self._empty = True
        self._updated = False
        self._selected = False

        self._old_style = ""
        # save old style before applying new ones
        self._current_style = "empty"
        #default style since _empty =True is the default state

        # content : this is where graphical object store the logical class
        self.content = -1

        if "parent" in kargs:
            self.parent = kargs["parent"]

        # object id (used to refer to this object by parent or other classes)
        self.id = id
        self.content = None
        # logical object linked to this  graphic object

        #define the Brush and default color
        brush = QtGui.QBrush(QtGui.QColor(0, 255, 255, 150))
        self.setBrush(brush)

        # define the text item and set it to empty string
        # it is positioned at top left of the  box
        self.text_label = ""
        self.showText = False
        self.textItem = pg.TextItem(self.text_label)
        self.textItem.setParentItem(self)
        width, height = self.size()

        self.textItem.setPos(0, height + .1 * height)

        self.menu = None
示例#29
0
    def recolor(self, color=None, recurse=True):
        if color is None:
            if not self.isConnected():
                # disconnected terminals are black
                color = QtGui.QColor(0, 0, 0)
            elif self.isInput() and not self.hasInput():
                # input terminal with no connected output terminals
                color = QtGui.QColor(200, 200, 0)
            else:
                # terminal has bad
                color = QtGui.QColor(255, 255, 255)
        self.graphicsItem().setBrush(QtGui.QBrush(color))

        if recurse:
            for t in self.connections():
                t.recolor(color, recurse=False)
示例#30
0
    def paint(self, p, opt, widget):
        #brush = QtGui.QBrush(QtGui.QColor(0, 0, 255, 50))
        if not hasattr(self, 'currentBrush'):
            self.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 255, 50)))
        if not hasattr(self, 'currentPen'):
            self.setPen(QtGui.QPen(QtGui.QColor(255, 0, 0, 255)))
        p.save()
        r = self.boundingRect()
        p.setRenderHint(QtGui.QPainter.Antialiasing)
        p.setPen(self.currentPen)
        p.setBrush(self.currentBrush)

        p.translate(r.left(), r.top())
        p.scale(r.width(), r.height())
        p.drawRect(0, 0, 1, 1)
        p.restore()