예제 #1
0
    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)

        for y in range(self.ocean.height):
            for x in range(self.ocean.width):
                if type(ocean.field[y][x]) != EmptyCell:
                    if type(ocean.field[y][x]) == Obstacle:
                        painter.fillRect(x * self.cell_width,
                                         y * self.cell_heigth, self.cell_width,
                                         self.cell_heigth,
                                         PyQt5.QtCore.Qt.black)
                    elif type(ocean.field[y][x]) == Victim:
                        painter.setBrush(PyQt5.QtCore.Qt.green)
                        painter.drawEllipse(x * self.cell_width,
                                            y * self.cell_heigth,
                                            self.cell_width, self.cell_heigth)
                    elif type(ocean.field[y][x]) == Predator:
                        color = QColor(255, 0, 0)
                        live_rate = ((ocean.field[y][x].full_health -
                                      ocean.field[y][x].health) * 200 /
                                     ocean.field[y][x].full_health)
                        painter.setBrush(QBrush(color.darker(100 + live_rate)))
                        painter.drawEllipse(x * self.cell_width,
                                            y * self.cell_heigth,
                                            self.cell_width, self.cell_heigth)

        painter.end()
예제 #2
0
    def draw_storey(self, painter, x, y, storey_state):
        color_table = [Qt.black, Qt.yellow, Qt.blue]
        color = QColor(color_table[storey_state])

        painter.fillRect(x + 1, y + 1,
                         self.square_width() - 2,
                         self.square_height() - 2, color)

        painter.setPen(color.lighter())
        painter.drawLine(x, y + self.square_height() - 1, x, y)
        painter.drawLine(x, y, x + self.square_width() - 1, y)

        painter.setPen(color.darker())
        painter.drawLine(x + 1, y + self.square_height() - 1,
                         x + self.square_width() - 1,
                         y + self.square_height() - 1)
        painter.drawLine(x + self.square_width() - 1,
                         y + self.square_height() - 1,
                         x + self.square_width() - 1, y + 1)

        if storey_state != StoreyState.EMPTY:
            if not self.current_state.is_open:
                painter.setBrush(QBrush(Qt.DiagCrossPattern))
                painter.drawRect(x + 1, y + 1,
                                 self.square_width() - 2,
                                 self.square_height() - 2)

            if self.current_state.weight > 0:
                painter.setPen(Qt.red)
                painter.drawText(
                    QRect(x + 1, y + 1,
                          self.square_width() - 2,
                          self.square_height() - 2), Qt.AlignCenter,
                    str(self.current_state.weight))
예제 #3
0
    def draw(self, painter, x, y, shape):

        painter.drawRect(self.game_top_left[0], self.game_top_left[1],
                         self.game_width, self.game_height)
        painter.drawRect(self.score_top_left[0], self.score_top_left[1],
                         self.score_width, self.score_height)
        painter.drawRect(self.predict_top_left[0], self.predict_top_left[1],
                         self.predict_width, self.predict_height)
        # for i in range(self.square_height_num):
        #     for j in range(self.square_width_num):
        #         painter.drawRect(self.game_top_left[0] + j * self.square_width, self.game_top_left[1] + i * self.square_height,self.square_width,self.square_height)
        # 加个网格看得清

        colorTable = [
            0x000000, 0xCC6666, 0x66CC66, 0x6666CC, 0xCCCC66, 0xCC66CC,
            0x66CCCC, 0xDAAA00
        ]

        color = QColor(colorTable[shape])
        painter.fillRect(x + 1, y + 1, self.square_width - 2,
                         self.square_height - 2, color)
        painter.setPen(color.lighter())
        painter.drawLine(x, y + self.square_height - 1, x, y)
        painter.drawLine(x, y, x + self.square_width - 1, y)

        painter.setPen(color.darker())
        painter.drawLine(x + 1, y + self.square_height - 1,
                         x + self.square_width - 1, y + self.square_height - 1)
        painter.drawLine(x + self.square_width - 1, y + self.square_height - 1,
                         x + self.square_width - 1, y + 1)
예제 #4
0
    def drawSquare(self, painter, x, y, shape):
        '''draws a square of a shape'''

        colorTable = [
            0x000000, 0xCC6666, 0x66CC66, 0x6666CC, 0xCCCC66, 0xCC66CC,
            0x66CCCC, 0xDAAA00
        ]

        color = QColor(colorTable[shape])
        painter.fillRect(x + 1, y + 1,
                         self.squareWidth() - 2,
                         self.squareHeight() - 2, color)

        pen = QPen(Qt.black, 2, Qt.DashDotLine)
        painter.setPen(pen)
        # painter.setPen(color.lighter())
        painter.drawLine(x, y + self.squareHeight() - 1, x, y)
        painter.drawLine(x, y, x + self.squareWidth() - 1, y)

        painter.setPen(color.darker())
        painter.drawLine(x + 1, y + self.squareHeight() - 1,
                         x + self.squareWidth() - 1,
                         y + self.squareHeight() - 1)
        painter.drawLine(x + self.squareWidth() - 1,
                         y + self.squareHeight() - 1,
                         x + self.squareWidth() - 1, y + 1)
예제 #5
0
    def draw_square(self, left, top, sq_type):
        """ отрисовка квадратика """

        w = left * self.scale_width()
        h = top * self.scale_height()

        painter = QPainter(self)

        if sq_type == config.FIELD_TYPE_NONE:
            painter.fillRect(w, h, self.scale_width(), self.scale_height(), QColor(config.Colors[sq_type]))
            return
        elif sq_type == config.FIELD_TYPE_BODY:
            color = QColor(self.body_gradient[self.engine.body_index(top, left)].get_hex())
        else:
            color = QColor(config.Colors[sq_type])

        painter.fillRect(w + 1, h + 1, self.scale_width() - 2, self.scale_height() - 2, color)

        painter.setPen(color.lighter())
        painter.drawLine(w, h + self.scale_height() - 1, w, h)
        painter.drawLine(w, h, w + self.scale_width() - 1, h)

        painter.setPen(color.darker(150))
        painter.drawLine(w + 1, h + self.scale_height() - 1, w + self.scale_width() - 1, h + self.scale_height() - 1)
        painter.drawLine(w + self.scale_width() - 1, h + self.scale_height() - 1, w + self.scale_width() - 1, h + 1)
예제 #6
0
    def drawSquare(self, painter, x, y, shape):
        """绘制方块图形"""

        colorTable = [
            0x000000, 0xCC6666, 0x66CC66, 0x6666CC, 0xCCCC66, 0xCC66CC,
            0x66CCCC, 0xDAAA00
        ]

        color = QColor(colorTable[shape])

        painter.fillRect(x + 1, y + 1,
                         self.squareWidth() - 2,
                         self.squareHeight() - 2, color)

        painter.setPen(color.lighter())

        painter.drawLine(x, y + self.squareHeight() - 1, x, y)

        painter.drawLine(x, y, x + self.squareWidth() - 1, y)

        painter.setPen(color.darker())

        painter.drawLine(x + 1, y + self.squareHeight() - 1,
                         x + self.squareWidth() - 1,
                         y + self.squareHeight() - 1)

        painter.drawLine(x + self.squareWidth() - 1,
                         y + self.squareHeight() - 1,
                         x + self.squareWidth() - 1, y + 1)
예제 #7
0
    def __init__(self,
                 parent=None,
                 color=None,
                 shape=E5LedCircular,
                 rectRatio=1):
        """
        Constructor
        
        @param parent reference to parent widget (QWidget)
        @param color color of the LED (QColor)
        @param shape shape of the LED (E5LedCircular, E5LedRectangular)
        @param rectRatio ratio width to height, if shape is rectangular (float)
        """
        super(E5Led, self).__init__(parent)

        if color is None:
            color = QColor("green")

        self.__led_on = True
        self.__dark_factor = 300
        self.__offcolor = color.darker(self.__dark_factor)
        self.__led_color = color
        self.__framedLed = True
        self.__shape = shape
        self.__rectRatio = rectRatio

        self.setColor(color)
예제 #8
0
    def _refresh_colors(self):
        """
        Refresh elements in the node
        """
        # color around ellipse
        outline_color = QColor('grey')
        outline_style = Qt.SolidLine
        outline_width = 1
        if self.status_wallet:
            outline_width = 2
        if not self.status_member:
            outline_color = QColor('red')

        if self.status_sentry:
            outline_color = QColor('black')
            outline_width = 3

        self.setPen(QPen(outline_color, outline_width, outline_style))

        if self.highlighted:
            text_color = QColor('grey')
        else:
            text_color = QColor('black')

        if self.status_wallet == NodeStatus.HIGHLIGHTED:
            text_color = QColor('grey')

        if self.text_item:
            self.text_item.setBrush(QBrush(text_color))

        # create gradient inside the ellipse
        gradient = QRadialGradient(
            QPointF(0,
                    self.boundingRect().height() / 4),
            self.boundingRect().width())
        color = QColor()
        color.setHsv(120 - 60 / self.steps_max * self.steps,
                     180 + 50 / self.steps_max * self.steps,
                     60 + 170 / self.steps_max * self.steps)
        if self.highlighted:
            color = color.darker(200)
        color = color.lighter(
            math.fabs(math.sin(self.loading_counter / 100 * math.pi) * 100) +
            100)
        gradient.setColorAt(0, color)
        gradient.setColorAt(1, color.darker(150))
        self.setBrush(QBrush(gradient))
예제 #9
0
파일: main.py 프로젝트: Erokha/course_cg
 def paintEvent(self, e: QPaintEvent):
     #print(e)
     #qp = QPainter()
     #qp.begin(self)
     if self.needRedraw:
         self.initzbuf()
         for i in range(len(self.model)):
             avg = self.model[i].avg()
             #avg = self.model[i].a
             # TODO try to get int from text field
             # TODO lightpoint?
             # xlight = int(float(self.xLightPointTextField.text()))
             # ylight = int(float(self.yLightPointTextField.text()))
             # zlight = int(float(self.zLightPointTextField.text()))
             # self.lightpoint = tr.Point3d(xlight, ylight, zlight)
             # self.lightpoint.rotateAround(self.xangle, self.yangle, self.zangle, MIDDLPOINT)
             #self.drawLightPoint(qp)
             m = self.model[i].getRotatedTriangle(self.xangle, self.yangle,
                                                  self.zangle, MIDDLPOINT)
             yAbs = abs(MINIY) + abs(MAXIY)
             y = (avg.y + abs(MINIY)) / yAbs
             if y > 0.92:
                 color = QColor(Qt.white)
             elif y > 0.8:
                 color = QColor(Qt.gray)
             elif y > 0.75:
                 color = QColor(Qt.darkGray)
             elif y > 0.6:
                 color = QColor(Qt.darkGreen)
             elif y > 0.45:
                 color = QColor(Qt.green)
             elif y > 0.15:
                 color = QColor(Qt.blue)
             else:
                 color = QColor(Qt.darkBlue)
             n = self.model[i].getNormal()
             l = Vector(avg.x, avg.y, avg.z, self.lightpoint.x,
                        self.lightpoint.y, self.lightpoint.z)
             ia = 0.3
             ka = 0.3
             il = 0.8
             kd = 0.8
             try:
                 I = abs(ia * ka + il * kd *
                         (n.x * l.x + n.y * l.y + n.z * l.z) /
                         (sqrt(n.x**2 + n.y**2 + n.z**2) *
                          sqrt(l.x**2 + l.y**2 + l.z**2)))
             except ZeroDivisionError:
                 I = 1
             color = color.darker(int(300 - I * 200))
             self.modelToZBuf(m.getAsPureArray(), color, m.getEquation())
             #self.strokeTriangle(m.getAsPureArray(), qp)
         if self.toggleCheatMode:
             for i in range(15):
                 self.zbuf_cheat()
         self.drawFromZbuf(None)  #(qp)
         self.needRedraw = False
예제 #10
0
    def updateLineGradient(self):
        pos_top = self.boundingRect().top()
        pos_bot = self.boundingRect().bottom()
        if self.item2.scenePos().y() >= self.item1.scenePos().y():
            pos1 = 0
            pos2 = 1
        else:
            pos1 = 1
            pos2 = 0

        port_type1 = self.item1.getPortType()
        port_type2 = self.item2.getPortType()
        port_gradient = QLinearGradient(0, pos_top, 0, pos_bot)

        #if port_type1 == PORT_TYPE_AUDIO_JACK:
        #port_gradient.setColorAt(pos1, canvas.theme.line_audio_jack_sel if self.m_lineSelected else canvas.theme.line_audio_jack)
        #elif port_type1 == PORT_TYPE_MIDI_JACK:
        #port_gradient.setColorAt(pos1, canvas.theme.line_midi_jack_sel if self.m_lineSelected else canvas.theme.line_midi_jack)
        #elif port_type1 == PORT_TYPE_MIDI_ALSA:
        #port_gradient.setColorAt(pos1, canvas.theme.line_midi_alsa_sel if self.m_lineSelected else canvas.theme.line_midi_alsa)
        #elif port_type1 == PORT_TYPE_PARAMETER:
        #port_gradient.setColorAt(pos1, canvas.theme.line_parameter_sel if self.m_lineSelected else canvas.theme.line_parameter)

        #if port_type2 == PORT_TYPE_AUDIO_JACK:
        #port_gradient.setColorAt(pos2, canvas.theme.line_audio_jack_sel if self.m_lineSelected else canvas.theme.line_audio_jack)
        #elif port_type2 == PORT_TYPE_MIDI_JACK:
        #port_gradient.setColorAt(pos2, canvas.theme.line_midi_jack_sel if self.m_lineSelected else canvas.theme.line_midi_jack)
        #elif port_type2 == PORT_TYPE_MIDI_ALSA:
        #port_gradient.setColorAt(pos2, canvas.theme.line_midi_alsa_sel if self.m_lineSelected else canvas.theme.line_midi_alsa)
        #elif port_type2 == PORT_TYPE_PARAMETER:
        #port_gradient.setColorAt(pos2, canvas.theme.line_parameter_sel if self.m_lineSelected else canvas.theme.line_parameter)

        base_color = canvas.theme.line_audio_jack
        if self.m_lineSelected:
            base_color = canvas.theme.line_audio_jack_sel

        if port_type1 == PORT_TYPE_MIDI_JACK:
            base_color = canvas.theme.port_midi_jack_bg
            if self.m_lineSelected:
                base_color = canvas.theme.port_midi_jack_bg_sel

        if self.m_is_semi_hidden:
            base_color = QColor(
                int(base_color.red() * canvas.semi_hide_opacity + 0.5),
                int(base_color.green() * canvas.semi_hide_opacity + 0.5),
                int(base_color.blue() * canvas.semi_hide_opacity + 0.5))

        if self.m_ready_to_disc:
            port_gradient.setColorAt(pos1, QColor(34, 34, 34))
            port_gradient.setColorAt(pos2, QColor(34, 34, 34))
            self.setPen(QPen(port_gradient, 2, Qt.DotLine))
        else:
            port_gradient.setColorAt(0, base_color.lighter(130))
            port_gradient.setColorAt(0.5, base_color.darker(130))
            port_gradient.setColorAt(1, base_color.lighter(130))

        self.setPen(QPen(port_gradient, 1.750001, Qt.SolidLine, Qt.FlatCap))
예제 #11
0
파일: game_gui.py 프로젝트: ztypl/RLTetris
 def draw_square(painter, x, y, val, s):
     if val != 0:
         color = QColor(Drawing.color_table[val])
         painter.fillRect(x+1, y+1, s-2, s-2, color)
         painter.setPen(color.lighter())
         painter.drawLine(x, y + s - 1, x, y)
         painter.drawLine(x, y, x + s - 1, y)
         painter.setPen(color.darker())
         painter.drawLine(x + 1, y + s - 1, x + s - 1, y + s - 1)
         painter.drawLine(x + s - 1, y + s - 1, x + s - 1, y + 1)
예제 #12
0
 def set_color(self, color):
     """Set the color palette."""
     for button in (self.dress, self.drop):
         col = QColor(color)
         if not button.isEnabled():
             col.setAlpha(150)
         pal = button.palette()
         pal.setColor(self.backgroundRole(), col)
         pal.setColor(QPalette.ButtonText, col.darker())
         button.setPalette(pal)
예제 #13
0
 def paintEvent(self, event=None):
     font = QFont(self.font())
     font.setPointSize(font.pointSize() - 1)
     fm = QFontMetricsF(font)
     fracWidth = fm.width(FractionSlider.WSTRING)
     indent = fm.boundingRect("9").width() / 2.0
     if not X11:
         fracWidth *= 1.5
     span = self.width() - (FractionSlider.XMARGIN * 2)
     value = self.__numerator / float(self.__denominator)
     painter = QPainter(self)
     painter.setRenderHint(QPainter.Antialiasing)
     painter.setRenderHint(QPainter.TextAntialiasing)
     painter.setPen(self.palette().color(QPalette.Mid))
     painter.setBrush(self.palette().brush(QPalette.AlternateBase))
     painter.drawRect(self.rect())
     segColor = QColor(Qt.green).darker(120)
     segLineColor = segColor.darker()
     painter.setPen(segLineColor)
     painter.setBrush(segColor)
     painter.drawRect(FractionSlider.XMARGIN, FractionSlider.YMARGIN, span,
                      fm.height())
     textColor = self.palette().color(QPalette.Text)
     segWidth = span / self.__denominator
     segHeight = fm.height() * 2
     nRect = fm.boundingRect(FractionSlider.WSTRING)
     x = FractionSlider.XMARGIN
     yOffset = segHeight + fm.height()
     for i in range(self.__denominator + 1):
         painter.setPen(segLineColor)
         painter.drawLine(x, FractionSlider.YMARGIN, x, segHeight)
         painter.setPen(textColor)
         y = segHeight
         rect = QRectF(nRect)
         rect.moveCenter(QPointF(x, y + fm.height() / 2.0))
         # painter.drawText(rect, Qt.AlignCenter,
         # QString.number(i))
         painter.drawText(rect, Qt.AlignCenter, str(i))
         y = yOffset
         rect.moveCenter(QPointF(x, y + fm.height() / 2.0))
         painter.drawText(rect, Qt.AlignCenter, str(self.__denominator))
         painter.drawLine(QPointF(rect.left() + indent, y),
                          QPointF(rect.right() - indent, y))
         x += segWidth
     span = int(span)
     y = FractionSlider.YMARGIN - 0.5
     triangle = [
         QPointF(value * span, y),
         QPointF((value * span) + (2 * FractionSlider.XMARGIN), y),
         QPointF((value * span) + FractionSlider.XMARGIN, fm.height())
     ]
     painter.setPen(Qt.yellow)
     painter.setBrush(Qt.darkYellow)
     painter.drawPolygon(QPolygonF(triangle))
예제 #14
0
def drawCell(painter, x, y, shape, grid_size):
	colors = [0x000000, 0xCC6666, 0x66CC66, 0x6666CC, 0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00]
	if shape == 0:
		return
	color = QColor(colors[shape])
	painter.fillRect(x+1, y+1, grid_size-2, grid_size-2, color)
	painter.setPen(color.lighter())
	painter.drawLine(x, y+grid_size-1, x, y)
	painter.drawLine(x, y, x+grid_size-1, y)
	painter.setPen(color.darker())
	painter.drawLine(x+1, y+grid_size-1, x+grid_size-1, y+grid_size-1)
	painter.drawLine(x+grid_size-1, y+grid_size-1, x+grid_size-1, y+1)
예제 #15
0
    def draw_cube(self, qp, x, y, color):
        color = QColor(color)

        width = self.board_cube_width()
        height = self.board_cube_height()
        x *= width
        y *= height

        qp.fillRect(x + 1, y + 1, width - 2, height - 2, color)

        qp.setPen(color.lighter())
        qp.setPen(color.darker())
예제 #16
0
    def data(self, index, role):
        # print(index.row(), index.column(), role)
        # print(type(role), type(self.StringValueRole))
        # print(self._rows)
        row = index.row()
        col = index.column()
        field = self._cols[col]
        insKey = self._rows[row]
        ## print(f'field: {field} insId: {insId} data: {self._data}')
        #if role == self.DataTypeRole:
        #    if field == "instrument":
        #        return "instrumentCombo"
        #    if field in ("bidPrice", "askPrice", "lastPrice"):
        #        return "tickerPrice"
        #    else:
        #        return "string"
        #if role == self.StringValueRole:
        #    print(f"get data from {role}")
        #    if insId is None:
        #        return ""
        #    return self._data[insId].get(field, "")
        #if role == self.TickDirectionRole:
        #    key = field + "TickDirection"
        #    return self._data[insId].get(key, True)
        if role == Qt.DisplayRole:
            if insKey is not None:
                # print(self._data[insKey])
                # print(insKey, field)
                return QVariant(self._data[insKey].get(field, ""))
            # return "test"
        elif role == Qt.ForegroundRole:
            key = field + "TickDirection"
            val = self._data[insKey].get(key, 0)
            if val == 1:
                return QBrush(QColor("#698476"))
            if val == -1:
                return QBrush(QColor("#CD5362"))
            if col == g.colEditable:
                return QBrush(QColor("#000000"))
            else:
                return QBrush(Qt.white)
        elif role == Qt.BackgroundRole:
            if col == g.colEditable:
                color = QColor("#C8A355")
                if row % 2 == 0:
                    return QBrush(QColor.darker(color, 120))
                return QBrush(color)
        elif role == Qt.TextAlignmentRole:
            if col != g.colEditable:
                return Qt.AlignRight | Qt.AlignVCenter

        return QVariant()
예제 #17
0
    def draw_item(self, qp, x, y, m, n):
        # x 10, y 10, z 25, w: 25

        color = QColor(0xCCCC66)
        qp.fillRect(x + 1, y + 1, m - 2, n - 2, color)

        qp.setPen(color.lighter())
        qp.drawLine(x, y + n - 1, x, y)
        qp.drawLine(x, y, x + m - 1, y)

        qp.setPen(color.darker())
        qp.drawLine(x + 1, y + n - 1, x + m - 1, y + n - 1)
        qp.drawLine(x + n - 1, y + n - 1, x + m - 1, y + 1)
    def setFlatStyle(self, button: QPushButton,
                     darker_if_checked: bool=True,
                     padding: str='',
                     color: QColor=None,
                     text_color: QColor=None) -> None:
        if color is None:
            color = QPalette().color(QPalette.Background)
        default_color = color.name(QColor.HexRgb)

        if darker_if_checked:
            checked_color = color.darker(125).name(QColor.HexRgb)
        else:
            checked_color = default_color

        hover_color = color.darker(110).name(QColor.HexRgb)

        if not padding:
            padding = self._padding

        if text_color is not None:
            text = 'color: {};'.format(text_color.name(QColor.HexRgb))
        else:
            text = ''

        # outline:none is used to remove the rectangle that appears on a
        # button when the button has focus
        # http://stackoverflow.com/questions/17280056/qt-css-decoration-on-focus
        stylesheet = """
        QPushButton { background-color: %s;
                      border: 0px;
                      outline: none;
                      %s
                      %s}
        QPushButton:checked { background-color: %s; border: none; }
        QPushButton:hover{ background-color: %s; border-style: inset; }
        """ % (default_color, padding, text, checked_color, hover_color) #

        button.setStyleSheet(stylesheet)
예제 #19
0
    def drawPort(painter, isOutput, portIndex, portData):
        pos = NodePainter.getPortPos(isOutput, portIndex)

        color = QColor(20, 20, 20)

        if portData == 0:
            color = QColor(255, 0, 0)
        elif portData == 1:
            color = QColor(0, 255, 0)

        painter.setBrush(color)
        painter.setPen(QPen(color.darker(200), 2.0))

        painter.drawEllipse(pos, PORT_RADIUS, PORT_RADIUS)
    def draw_square(self, x, y, size, color):
        width, height = size
        color = QColor(color)

        painter = self.painter
        painter.fillRect(x + 1, y + 1, width - 2, height - 2, color)

        painter.setPen(color.lighter())
        painter.drawLine(x, y + height - 1, x, y)
        painter.drawLine(x, y, x + width - 1, y)

        painter.setPen(color.darker())
        painter.drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1)
        painter.drawLine(x + width - 1, y + height - 1, x + width - 1, y + 1)
예제 #21
0
    def brush(self, option: QStyleOptionToolButton):
        over = option.state & QStyle.State_MouseOver
        pressed = option.state & QStyle.State_Sunken

        g1 = QColor(219, 217, 215)
        g2 = QColor(205, 202, 199)
        g3 = QColor(187, 183, 180)

        if pressed:
            g1 = g1.darker(120)
            g2 = g2.darker(120)
            g3 = g3.darker(120)
        elif over:
            g1 = g1.lighter(110)
            g2 = g2.lighter(110)
            g3 = g3.lighter(110)

        gradient = QLinearGradient(0, 0, 0, self.height())
        gradient.setColorAt(0.0, g1)
        gradient.setColorAt(0.40, g2)
        gradient.setColorAt(1.0, g3)

        return QBrush(gradient)
예제 #22
0
    def _refresh_colors(self):
        """
        Refresh elements in the node
        """
        # color around ellipse
        outline_color = QColor('black')
        outline_style = Qt.SolidLine
        outline_width = 1
        if self.status_wallet:
            outline_color = QColor('grey')
            outline_width = 2
        if not self.status_member:
            outline_color = QColor('red')
            outline_style = Qt.SolidLine
        self.setPen(QPen(outline_color, outline_width, outline_style))

        if self.highlighted:
            text_color = QColor('grey')
        else:
            text_color = QColor('black')

        if self.status_wallet == NodeStatus.HIGHLIGHTED:
            text_color = QColor('grey')
        self.text_item.setBrush(QBrush(text_color))

        # create gradient inside the ellipse
        gradient = QRadialGradient(QPointF(0, self.boundingRect().height() / 4), self.boundingRect().width())
        color = QColor()
        color.setHsv(120 - 60 / self.steps_max * self.steps,
                     180 + 50 / self.steps_max * self.steps,
                     60 + 170 / self.steps_max * self.steps)
        if self.highlighted:
            color = color.darker(200)
        color = color.lighter(math.fabs(math.sin(self.loading_counter / 100 * math.pi) * 100) + 100)
        gradient.setColorAt(0, color)
        gradient.setColorAt(1, color.darker(150))
        self.setBrush(QBrush(gradient))
예제 #23
0
    def drawBlock(self, painter, x, y, c):
        w = self.size
        h = self.size
        x = self.size * x + self.offset
        y = self.size * y + self.offset
        color = QColor(c)
        painter.fillRect(x + 1, y + 1, w - 2, h - 2, color)

        painter.setPen(color.lighter())
        painter.drawLine(x, y + h - 1, x, y)
        painter.drawLine(x, y, x + w - 1, y)

        painter.setPen(color.darker())
        painter.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1)
        painter.drawLine(x + w - 1, y + h - 1, x + w - 1, y + 1)
예제 #24
0
def format(color, style='', darker=100, lighter=100):
    """Return a QTextCharFormat with the given attributes.
    """
    _color = QColor(color)
    _color = _color.darker(darker)
    _color = _color.lighter(lighter)

    _format = QTextCharFormat()
    _format.setForeground(_color)
    if 'bold' in style:
        _format.setFontWeight(QFont.Bold)
    if 'italic' in style:
        _format.setFontItalic(True)

    return _format
예제 #25
0
파일: Drawer.py 프로젝트: wicket1001/OWAI
    def draw_square(painter, x, y, size, color):
        """draws a square of a shape"""
        color = QColor(color)
        painter.fillRect(x + 1, y + 1, size[1] - 2,
                         size[0] - 2, color)

        painter.setPen(color.lighter())
        painter.drawLine(x, y + size[0] - 1, x, y)
        painter.drawLine(x, y, x + size[1] - 1, y)

        painter.setPen(color.darker())
        painter.drawLine(x + 1, y + size[0] - 1,
                         x + size[1] - 1, y + size[0] - 1)
        painter.drawLine(x + size[1] - 1,
                         y + size[0] - 1, x + size[1] - 1, y + 1)
예제 #26
0
def drawSquare(painter, x, y, val, s):
    colorTable = [0x000000, 0xCC6666, 0x66CC66, 0x6666CC,
                  0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00, 0xFFFFFF]
    if val == 0:
        return
        
    color = QColor(colorTable[val])
    painter.fillRect(x + 1, y + 1, s - 2, s - 2, color)

    painter.setPen(color.lighter())
    painter.drawLine(x, y + s - 1, x, y)
    painter.drawLine(x, y, x + s - 1, y)

    painter.setPen(color.darker())
    painter.drawLine(x + 1, y + s - 1, x + s - 1, y + s - 1)
    painter.drawLine(x + s - 1, y + s - 1, x + s - 1, y + 1)
예제 #27
0
    def painter_square(self, qp, x, y, width, height, shape_type):
        # 根据长宽和起始地点画框
        x *= self.every_square_per_width()
        y *= self.every_square_per_height()
        width *= self.every_square_per_width()
        height *= self.every_square_per_height()

        color = QColor(ShapeType.Shape_Colors[shape_type])
        qp.fillRect(x + 1, y + 1, width - 1, height - 2, color)

        qp.setPen(color.lighter())
        qp.drawLine(x, y, x + width - 1, y)
        qp.drawLine(x, y, x, y + height - 1)
        qp.setPen(color.darker())
        qp.drawLine(x + width - 1, y + 1, x + width - 1, y + height - 1)
        qp.drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1)
예제 #28
0
    def __updatePen(self):
        self.prepareGeometryChange()
        self.__boundingRect = None
        if self.__dynamic:
            if self.__dynamicEnabled:
                color = QColor(0, 150, 0, 150)
            else:
                color = QColor(150, 0, 0, 150)

            normal = QPen(QBrush(color), 2.0)
            hover = QPen(QBrush(color.darker(120)), 2.1)
        else:
            normal = QPen(QBrush(QColor("#9CACB4")), 2.0)
            hover = QPen(QBrush(QColor("#7D7D7D")), 2.1)

        self.curveItem.setCurvePenSet(normal, hover)
예제 #29
0
 def updateColor(self, item):
     pixmap = QPixmap(16, 16)
     color = QColor()
     # if item:
     #     color = item.backgroundColor()
     if not color.isValid():
         color = self.palette().base().color()
     painter = QPainter(pixmap)
     painter.fillRect(0, 0, 16, 16, color)
     lighter = color.lighter()
     painter.setPen(lighter)
     # light frame
     painter.drawPolyline(QPoint(0, 15), QPoint(0, 0), QPoint(15, 0))
     painter.setPen(color.darker())
     # dark frame
     painter.drawPolyline(QPoint(1, 15), QPoint(15, 15), QPoint(15, 1))
     painter.end()
예제 #30
0
def drawSquare(painter, x, y, val, s):
    colorTable = [0x000000, 0xCC6666, 0x66CC66, 0x6666CC,
                  0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00]

    if val == 0:
        return

    color = QColor(colorTable[val])
    painter.fillRect(x + 1, y + 1, s - 2, s - 2, color)

    painter.setPen(color.lighter())
    painter.drawLine(x, y + s - 1, x, y)
    painter.drawLine(x, y, x + s - 1, y)

    painter.setPen(color.darker())
    painter.drawLine(x + 1, y + s - 1, x + s - 1, y + s - 1)
    painter.drawLine(x + s - 1, y + s - 1, x + s - 1, y + 1)
예제 #31
0
파일: tetrix.py 프로젝트: Axel-Erfurt/pyqt5
    def drawSquare(self, painter, x, y, shape):
        colorTable = [0x000000, 0xCC6666, 0x66CC66, 0x6666CC,
                      0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00]

        color = QColor(colorTable[shape])
        painter.fillRect(x + 1, y + 1, self.squareWidth() - 2,
                self.squareHeight() - 2, color)

        painter.setPen(color.lighter())
        painter.drawLine(x, y + self.squareHeight() - 1, x, y)
        painter.drawLine(x, y, x + self.squareWidth() - 1, y)

        painter.setPen(color.darker())
        painter.drawLine(x + 1, y + self.squareHeight() - 1,
                x + self.squareWidth() - 1, y + self.squareHeight() - 1)
        painter.drawLine(x + self.squareWidth() - 1,
                y + self.squareHeight() - 1, x + self.squareWidth() - 1, y + 1)
예제 #32
0
 def updateColor(self, item):
     pixmap = QPixmap(16, 16)
     color = QColor()
     if item:
         color = item.backgroundColor()
     if not color.isValid():
         color = self.palette().base().color()
     painter = QPainter(pixmap)
     painter.fillRect(0, 0, 16, 16, color)
     lighter = color.lighter()
     painter.setPen(lighter)
     # light frame
     painter.drawPolyline(QPoint(0, 15), QPoint(0, 0), QPoint(15, 0))
     painter.setPen(color.darker())
     # dark frame
     painter.drawPolyline(QPoint(1, 15), QPoint(15, 15), QPoint(15, 1))
     painter.end()
     self.colorAction.setIcon(QIcon(pixmap))
예제 #33
0
    def draw_square(self, painter, x, y, shape):

        color = QColor(self.ColorScheme[shape - 1])
        painter.fillRect(x + 1, y + 1,
                         self.square_width() - 2,
                         self.square_height() - 2, color)

        painter.setPen(color.lighter())
        painter.drawLine(x, y + self.square_height() - 1, x, y)
        painter.drawLine(x, y, x + self.square_width() - 1, y)

        painter.setPen(color.darker())
        painter.drawLine(x + 1, y + self.square_height() - 1,
                         x + self.square_width() - 1,
                         y + self.square_height() - 1)
        painter.drawLine(x + self.square_width() - 1,
                         y + self.square_height() - 1,
                         x + self.square_width() - 1, y + 1)
예제 #34
0
    def create_atom(self, atom: Atom, root_entity, color: QColor):
        if atom.element in self._materials_dict:
            material = self._materials_dict[atom.element]
        else:
            material = QDiffuseSpecularMaterial(root_entity)
            material.setDiffuse(color)
            material.setAmbient(color.darker(200))
            self._materials_dict[atom.element] = material

        sphere_entity = QEntity(root_entity)
        sphere_mesh = QSphereMesh()
        sphere_mesh.setRadius(0.5)
        sphere_transform = QTransform()
        sphere_transform.setTranslation(QVector3D(*atom.coords_cartesian))

        sphere_entity.addComponent(sphere_mesh)
        sphere_entity.addComponent(sphere_transform)
        sphere_entity.addComponent(material)
예제 #35
0
파일: traces.py 프로젝트: gpiantoni/phypno
    def display_markers(self):
        """Add markers on top of first plot."""
        for item in self.idx_markers:
            self.scene.removeItem(item)
        self.idx_markers = []

        window_start = self.parent.value('window_start')
        window_length = self.parent.value('window_length')
        window_end = window_start + window_length
        y_distance = self.parent.value('y_distance')

        markers = []
        if self.parent.info.markers is not None:
            if self.parent.value('marker_show'):
                markers = self.parent.info.markers

        for mrk in markers:
            if window_start <= mrk['end'] and window_end >= mrk['start']:

                mrk_start = max((mrk['start'], window_start))
                mrk_end = min((mrk['end'], window_end))
                color = QColor(self.parent.value('marker_color'))

                item = QGraphicsRectItem(mrk_start, 0,
                                         mrk_end - mrk_start,
                                         len(self.idx_label) * y_distance)
                item.setPen(color)
                item.setBrush(color)
                item.setZValue(-9)
                self.scene.addItem(item)

                item = TextItem_with_BG(color.darker(200))
                item.setText(mrk['name'])
                item.setPos(mrk['start'],
                            len(self.idx_label) *
                            self.parent.value('y_distance'))
                item.setFlag(QGraphicsItem.ItemIgnoresTransformations)
                item.setRotation(-90)
                self.scene.addItem(item)
                self.idx_markers.append(item)
예제 #36
0
파일: E5Led.py 프로젝트: pycom/EricShort
 def __init__(self, parent=None, color=None, shape=E5LedCircular,
              rectRatio=1):
     """
     Constructor
     
     @param parent reference to parent widget (QWidget)
     @param color color of the LED (QColor)
     @param shape shape of the LED (E5LedCircular, E5LedRectangular)
     @param rectRatio ratio width to height, if shape is rectangular (float)
     """
     super(E5Led, self).__init__(parent)
     
     if color is None:
         color = QColor("green")
     
     self.__led_on = True
     self.__dark_factor = 300
     self.__offcolor = color.darker(self.__dark_factor)
     self.__led_color = color
     self.__framedLed = True
     self.__shape = shape
     self.__rectRatio = rectRatio
     
     self.setColor(color)
예제 #37
0
파일: traces.py 프로젝트: gpiantoni/phypno
    def display_annotations(self):
        """Mark all the bookmarks/events, on top of first plot."""
        for item in self.idx_annot:
            self.scene.removeItem(item)
        self.idx_annot = []

        window_start = self.parent.value('window_start')
        window_length = self.parent.value('window_length')
        window_end = window_start + window_length
        y_distance = self.parent.value('y_distance')
        raw_chan_name = list(map(take_raw_name, self.chan))

        bookmarks = []
        events = []

        if self.parent.notes.annot is not None:
            if self.parent.value('annot_show'):
                bookmarks = self.parent.notes.annot.get_bookmarks()
                events = self.parent.notes.get_selected_events((window_start,
                                                                window_end))
        annotations = bookmarks + events

        for annot in annotations:

            if window_start <= annot['end'] and window_end >= annot['start']:

                mrk_start = max((annot['start'], window_start))
                mrk_end = min((annot['end'], window_end))
                if annot in bookmarks:
                    color = QColor(self.parent.value('annot_bookmark_color'))
                if annot in events:
                    color = convert_name_to_color(annot['name'])

                if annot['chan'] == ['']:
                    h_annot = len(self.idx_label) * y_distance
                    y_annot = (0, )

                    item = TextItem_with_BG(color.darker(200))
                    item.setText(annot['name'])
                    item.setPos(annot['start'],
                                len(self.idx_label) * y_distance)
                    item.setFlag(QGraphicsItem.ItemIgnoresTransformations)
                    item.setRotation(-90)
                    self.scene.addItem(item)
                    self.idx_annot.append(item)
                    zvalue = -8

                else:
                    h_annot = y_distance
                    # find indices of channels with annotations
                    chan_idx_in_mrk = in1d(raw_chan_name, annot['chan'])
                    y_annot = asarray(self.chan_pos)[chan_idx_in_mrk]
                    y_annot -= y_distance / 2
                    zvalue = -7

                for y in y_annot:
                    item = QGraphicsRectItem(mrk_start, y,
                                             mrk_end - mrk_start, h_annot)
                    item.setPen(color)
                    item.setBrush(color)
                    item.setZValue(zvalue)
                    self.scene.addItem(item)
                    self.idx_annot.append(item)