Python PyQt5.QtGui 模块,QColor() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用PyQt5.QtGui.QColor()

项目:notepad    作者:lfsando    | 项目源码 | 文件源码
def init_ui(self):

        background_color = QColor()
        background_color.setNamedColor('#282821')

        color_palette = self.text_editor.palette()
        color_palette.setColor(QPalette.Text, Qt.white)
        color_palette.setColor(QPalette.Base, background_color)
        self.text_editor.setPalette(color_palette)

        default_font = self.text_editor.font()
        default_font.setPointSize(9)
        self.text_editor.setFont(default_font)

        self.setWindowTitle('Example')
        self.setCentralWidget(self.text_editor)
        self.setGeometry(500, 500, 500, 500)

        self.show()
项目:PyNoder    作者:johnroper100    | 项目源码 | 文件源码
def generateNodes(count, offset, depth):
    for i in range(count):
        node1 = Node(graph, 'node' + str(depth) + str(i))
        node1.addPort(InputPort(node1, graph, 'InPort', QtGui.QColor(128, 170, 170, 255), 'MyDataX'))
        node1.addPort(OutputPort(node1, graph, 'OutPort', QtGui.QColor(32, 255, 32, 255), 'MyDataX'))
        node1.setNodePos(QtCore.QPointF(offset, i * 100))

        graph.addNode(node1)

        global totalCount
        totalCount += 1

    if depth < 6:
        generateNodes(count * 2, offset+160, depth+1)

        for i in range(count):
            graph.connectPorts('node' + str(depth) + str(i), 'OutPort', 'node' + str(depth+1) + str(i*2), 'InPort')
            graph.connectPorts('node' + str(depth) + str(i), 'OutPort', 'node' + str(depth+1) + str(i*2+1), 'InPort')
    elif depth < 12:
        generateNodes(int(count / 2), offset+160, depth+1)

        for i in range(count//2):
            graph.connectPorts('node' + str(depth) + str(i), 'OutPort', 'node' + str(depth+1) + str(int(i)), 'InPort')
项目:PyNoder    作者:johnroper100    | 项目源码 | 文件源码
def mouseMoveEvent(self, event):
        self.unhighlight()
        scenePos = self.mapToScene(event.pos())

        # When clicking on an UI port label, it is ambigous which connection point should be activated.
        # We let the user drag the mouse in either direction to select the conneciton point to activate.
        delta = scenePos - self.__mousDownPos
        if delta.x() < 0:
            if self.__port.inCircle() is not None:
                self.__port.inCircle().mousePressEvent(event)
        else:
            if self.__port.outCircle() is not None:
                self.__port.outCircle().mousePressEvent(event)

    # def paint(self, painter, option, widget):
    #     super(PortLabel, self).paint(painter, option, widget)
    #     painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 255)))
    #     painter.drawRect(self.windowFrameRect())
项目:PyNoder    作者:johnroper100    | 项目源码 | 文件源码
def mousePressEvent(self, event):

        self.unhighlight()

        scenePos = self.mapToScene(event.pos())

        from .mouse_actions import MouseGrabber
        if self.isInConnectionPoint():
            MouseGrabber(self._graph, scenePos, self, 'Out')
        elif self.isOutConnectionPoint():
            MouseGrabber(self._graph, scenePos, self, 'In')

    # def paint(self, painter, option, widget):
    #     super(PortCircle, self).paint(painter, option, widget)
    #     painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 0)))
    #     painter.drawRect(self.windowFrameRect())
项目:PyNoder    作者:johnroper100    | 项目源码 | 文件源码
def __init__(self, graph, srcPortCircle, dstPortCircle):
        super(Connection, self).__init__()

        self.__graph = graph
        self.__srcPortCircle = srcPortCircle
        self.__dstPortCircle = dstPortCircle
        penStyle = QtCore.Qt.DashLine

        self.__connectionColor = QtGui.QColor(0, 0, 0)
        self.__connectionColor.setRgbF(*self.__srcPortCircle.getColor().getRgbF())
        self.__connectionColor.setAlpha(125)

        self.__defaultPen = QtGui.QPen(QtGui.QColor("#A7A7A7"), 1.5)

        self.__connectionHoverColor = QtGui.QColor(0, 0, 0)
        self.__connectionHoverColor.setRgbF(*self.__srcPortCircle.getColor().getRgbF())
        self.__connectionHoverColor.setAlpha(255)

        self.__hoverPen = QtGui.QPen(self.__connectionHoverColor, 1.5)

        self.setPen(self.__defaultPen)
        self.setZValue(-1)

        self.setAcceptHoverEvents(True)
        self.connect()
项目:Computer-graphics    作者:Panda-Lewandowski    | 项目源码 | 文件源码
def __init__(self):
        QtWidgets.QWidget.__init__(self)
        uic.loadUi("window.ui", self)
        self.scene = QtWidgets.QGraphicsScene(0, 0, 511, 511)
        self.mainview.setScene(self.scene)
        self.image = QImage(511, 511, QImage.Format_ARGB32_Premultiplied)
        self.pen = QPen()
        self.color_line = QColor(Qt.black)
        self.color_bground = QColor(Qt.white)
        self.draw_once.clicked.connect(lambda: draw_once(self))
        self.clean_all.clicked.connect(lambda: clear_all(self))
        self.btn_bground.clicked.connect(lambda: get_color_bground(self))
        self.btn_line.clicked.connect(lambda: get_color_line(self))
        self.draw_centr.clicked.connect(lambda: draw_centr(self))
        layout = QtWidgets.QHBoxLayout()
        layout.addWidget(self.what)
        layout.addWidget(self.other)
        self.setLayout(layout)
        self.circle.setChecked(True)
        self.canon.setChecked(True)
        #self.circle.toggled.connect(lambda : change_text(self))
项目:networkzero    作者:tjguk    | 项目源码 | 文件源码
def __init__(self, parent=None):
        super(Adventure, self).__init__(parent)

        #
        # Top-half of the
        #
        self.image_panel = QtWidgets.QLabel()
        self.image_panel.setAlignment(QtCore.Qt.AlignCenter)
        self.image = QtGui.QPixmap("image.jpg")
        self.image_panel.setPixmap(self.image)

        self.text_panel = QtWidgets.QTextEdit()
        self.text_panel.setReadOnly(True)
        self.text_panel.setTextBackgroundColor(QtGui.QColor("blue"))
        self.text_panel.setHtml("""<h1>Hello, World!</h1>

        <p>You are in a spacious ballroom with the sound of music playing all around you.</p>
        """)

        self.data_panel = QtWidgets.QTextEdit()
        self.data_panel.setReadOnly(True)

        self.input = QtWidgets.QLineEdit()

        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self.image_panel, 1)
        hlayout = QtWidgets.QHBoxLayout()
        hlayout.addWidget(self.text_panel, 3)
        hlayout.addWidget(self.data_panel, 1)
        layout.addLayout(hlayout, 1)
        layout.addWidget(self.input)

        self.setLayout(layout)
        self.setWindowTitle("Westpark Adventure")
项目:Milis-Yukleyici    作者:sonakinci41    | 项目源码 | 文件源码
def asama_ciz(asama,tum_asama):
    #Amac?m?z pencerenin üzerinde gözüken ad?m k?sm? için gerekli resmi olu?turmak
    resim = QImage(950,10,QImage.Format_RGB32)
    boyayici = QPainter()
    boyayici.begin(resim)
    mavi_kalem = QPen(QColor("#00bbf2"))
    mavi_firca = QBrush(QColor("#00bbf2"))
    beyaz_kalem = QPen(QColor("#ffffff"))
    beyaz_firca = QBrush(QColor("#ffffff"))
    boyayici.setPen(beyaz_kalem)
    boyayici.setBrush(beyaz_firca)
    boyayici.drawRect(0,0,950,10)
    boyayici.setPen(mavi_kalem)
    boyayici.setBrush(mavi_firca)
    en_hesabi = (asama/tum_asama)*950
    boyayici.drawRect(0,0,int(en_hesabi),10)
    boyayici.end()
    return resim
项目:vidcutter    作者:ozmartian    | 项目源码 | 文件源码
def __init__(self):
        super(VideoStyleLight, self).__init__()
        palette = qApp.palette()
        palette.setColor(QPalette.Window, QColor(239, 240, 241))
        palette.setColor(QPalette.WindowText, QColor(49, 54, 59))
        palette.setColor(QPalette.Base, QColor(252, 252, 252))
        palette.setColor(QPalette.AlternateBase, QColor(239, 240, 241))
        palette.setColor(QPalette.ToolTipBase, QColor(239, 240, 241))
        palette.setColor(QPalette.ToolTipText, QColor(49, 54, 59))
        palette.setColor(QPalette.Text, QColor(49, 54, 59))
        palette.setColor(QPalette.Button, QColor(239, 240, 241))
        palette.setColor(QPalette.ButtonText, QColor(49, 54, 59))
        palette.setColor(QPalette.BrightText, QColor(255, 255, 255))
        palette.setColor(QPalette.Link, QColor(41, 128, 185))
        palette.setColor(QPalette.Highlight, QColor(136, 136, 136))
        palette.setColor(QPalette.HighlightedText, QColor(239, 240, 241))
        palette.setColor(QPalette.Disabled, QPalette.Light, Qt.white)
        palette.setColor(QPalette.Disabled, QPalette.Shadow, QColor(234, 234, 234))
        qApp.setPalette(palette)
项目:vidcutter    作者:ozmartian    | 项目源码 | 文件源码
def __init__(self):
        super(VideoStyleDark, self).__init__()
        palette = qApp.palette()
        palette.setColor(QPalette.Window, QColor(27, 35, 38))
        palette.setColor(QPalette.WindowText, QColor(234, 234, 234))
        palette.setColor(QPalette.Base, QColor(27, 35, 38))
        palette.setColor(QPalette.AlternateBase, QColor(12, 15, 16))
        palette.setColor(QPalette.ToolTipBase, QColor(27, 35, 38))
        palette.setColor(QPalette.ToolTipText, Qt.white)
        palette.setColor(QPalette.Text, QColor(234, 234, 234))
        palette.setColor(QPalette.Button, QColor(27, 35, 38))
        palette.setColor(QPalette.ButtonText, Qt.white)
        palette.setColor(QPalette.BrightText, QColor(100, 215, 222))
        palette.setColor(QPalette.Link, QColor(126, 71, 130))
        palette.setColor(QPalette.Highlight, QColor(126, 71, 130))
        palette.setColor(QPalette.HighlightedText, Qt.white)
        palette.setColor(QPalette.Disabled, QPalette.Light, Qt.black)
        palette.setColor(QPalette.Disabled, QPalette.Shadow, QColor(12, 15, 16))
        qApp.setPalette(palette)
项目:BATS-Bayesian-Adaptive-Trial-Simulator    作者:ContaTP    | 项目源码 | 文件源码
def changeTab(self, index):

        if index == 0:

            self.log_tabWidget.setTabIcon(0, QtGui.QIcon(":/resources/tab_log.png"))
            self.log_tabWidget.setTabIcon(1, QtGui.QIcon(":/resources/tab_info_disabled.png"))
            self.log_tabWidget.tabBar().setTabTextColor(0, QtGui.QColor("#4f8a10"))     
            self.log_tabWidget.tabBar().setStyleSheet("QTabBar:tab:selected{ border-color: #4f8a10;} QTabBar:tab:selected:hover{color:#4f8a10;}") 

        else:

            self.log_tabWidget.setTabIcon(0, QtGui.QIcon(":/resources/tab_log_disabled.png"))
            self.log_tabWidget.setTabIcon(1, QtGui.QIcon(":/resources/tab_info.png"))
            self.log_tabWidget.tabBar().setTabTextColor(1, QtGui.QColor("#00529b"))
            self.log_tabWidget.tabBar().setStyleSheet("QTabBar:tab:selected{ border-color: #00529b;} QTabBar:tab:selected:hover{color:#00529b;}")


    # Write log
项目:plexdesktop    作者:coryo    | 项目源码 | 文件源码
def draw_progress_bar(plex_item, pixmap, height=6):
    """draw a progress indicator on the bottom of pixmap with height pixels"""
    if not hasattr(plex_item, 'in_progress'):
        return
    if not plex_item.in_progress:
        return
    progress_color = QtGui.QColor(204, 123, 25)
    progress = plex_item.view_offset / max(1, plex_item.duration)
    p = QtGui.QPainter(pixmap)
    rect = p.window()
    progress_rect = QtCore.QRect(rect.bottomLeft() - QtCore.QPoint(0, height),
                                 rect.bottomRight())
    progress_fill = QtCore.QRect(progress_rect)
    progress_fill.setWidth(rect.width() * progress)
    p.fillRect(progress_rect, QtGui.QBrush(QtCore.Qt.black))
    p.fillRect(progress_fill, QtGui.QBrush(progress_color))
项目:plexdesktop    作者:coryo    | 项目源码 | 文件源码
def draw_unwatched_indicator(plex_item, pixmap, size=0.20):
    """draw a triangle on the top right of pixmap"""
    if not hasattr(plex_item, 'watched') and not hasattr(plex_item, 'in_progress'):
        return
    if plex_item.watched or plex_item.in_progress:
        return
    p = QtGui.QPainter(pixmap)
    rect = p.window()
    top_right = rect.topRight()
    size = pixmap.height() * size
    color = QtGui.QColor(204, 123, 25)
    triangle = QtGui.QPolygon([top_right, top_right - QtCore.QPoint(size, 0),
                               top_right + QtCore.QPoint(0, size)])
    p.setPen(QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 120)), 6))
    p.drawLine(triangle.point(1), triangle.point(2))
    p.setBrush(QtGui.QBrush(color))
    p.setPen(color)
    p.drawPolygon(triangle)
项目:thegame    作者:afg984    | 项目源码 | 文件源码
def paint(
            self,
            painter: QPainter,
            option: QStyleOptionGraphicsItem,
            widget: QWidget):
        pen = QPen()
        pen.setWidth(3)
        painter.setRenderHint(QPainter.Antialiasing)
        pen.setColor(QColor(61, 61, 61, 255))
        painter.setPen(pen)
        painter.setBrush(QBrush(QColor(61, 61, 61, 255), Qt.SolidPattern))
        painter.drawRect(
            QRectF(-self.maxWidth / 2, -10, self.maxWidth, 20))
        painter.setBrush(QBrush(QColor(240, 217, 108, 255), Qt.SolidPattern))
        painter.drawRect(
            QRectF(-self.maxWidth / 2, -10, self.displayWidth, 20))
        path = QPainterPath()

        path.addText(-self.maxWidth / 2, 35, QFont('monospace', 18, QFont.Bold), f'{self.name}  Lv.{self.level}  Exp. {self.actualExperience:{len(str(self.maxExperience))}}/{self.maxExperience}')

        # pen.setColor(Qt.white)
        pen.setWidth(2)
        painter.setPen(pen)
        painter.setBrush(QBrush(QColor(0, 0, 0, 61), Qt.SolidPattern))
        painter.drawPath(path)
项目:thegame    作者:afg984    | 项目源码 | 文件源码
def paint(
            self,
            painter: QPainter,
            option: QStyleOptionGraphicsItem,
            widget: QWidget):
        pen = QPen()
        pen.setWidth(1)
        painter.setRenderHint(QPainter.Antialiasing)
        pen.setColor(QColor(81, 81, 81, 255))
        painter.setPen(pen)
        painter.setBrush(QBrush(QColor(81, 81, 81, 255), Qt.SolidPattern))
        path = QPainterPath()
        path.addText(
            -self.width,
            self.height,
            QFont('monospace', 13, QFont.PreferNoHinting),
            self.text)
        painter.drawPath(path)
项目:thegame    作者:afg984    | 项目源码 | 文件源码
def paint(
            self,
            painter: QPainter,
            option: QStyleOptionGraphicsItem,
            widget: QWidget):
        pen = QPen()
        pen.setWidth(1)
        painter.setRenderHint(QPainter.Antialiasing)
        pen.setColor(QColor(81, 81, 81, 255))
        painter.setPen(pen)
        painter.setBrush(QBrush(QColor(81, 81, 81, 255), Qt.SolidPattern))
        for i, score in enumerate(self.scores):
            path = QPainterPath()
            path.addText(
                -self.width,
                14 + i * 16,
                QFont('monospace', 13, QFont.PreferNoHinting),
                f'{score.score:6}[{score.level:2}]  {score.hero_name}')
            painter.drawPath(path)
项目:kawaii-player    作者:kanishka-linux    | 项目源码 | 文件源码
def __init__(self, parent=None, ui_widget=None, home=None, window=None, logr=None):
        global ui, MainWindow, logger
        QtWidgets.QSystemTrayIcon.__init__(self, parent)
        ui = parent
        MainWindow = window
        logger = logr
        icon_img = os.path.join(home, 'src', 'tray.png')
        self.right_menu = RightClickMenuIndicator(ui_widget=ui_widget,
                                                  window=window, logr=logr)
        self.setContextMenu(self.right_menu)

        self.activated.connect(self.onTrayIconActivated)
        self.p = QtGui.QPixmap(24, 24)
        self.p.fill(QtGui.QColor("transparent"))
        painter = QtGui.QPainter(self.p)
        if os.path.exists(icon_img):
            self.setIcon(QtGui.QIcon(icon_img))
        else:
            self.setIcon(QtGui.QIcon(""))
        self.full_scr = 1
        del painter
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __init__(self, text='S', startp=Point(x=0.0, y=0.0),):
        """
        Initialisation of the class.
        """
        QGraphicsItem.__init__(self)

        self.setFlag(QGraphicsItem.ItemIsSelectable, False)

        self.text = text
        self.sc = 1.0
        self.startp = QtCore.QPointF(startp.x, -startp.y)

        pencolor = QColor(0, 200, 255)
        self.brush = QColor(0, 100, 255)

        self.pen = QPen(pencolor, 1, QtCore.Qt.SolidLine)
        self.pen.setCosmetic(True)

        self.path = QPainterPath()
        self.path.addText(QtCore.QPointF(0, 0),
                          QFont("Arial", 10/self.sc),
                          self.text)
项目:HearthPacks    作者:Arzaroth    | 项目源码 | 文件源码
def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.fillRect(event.rect(), QBrush(QColor(127, 127, 127, 127)))
        painter.setPen(QPen(Qt.NoPen))

        for i in range(6):
            if int(self.counter / 10) % 6 == i:
                factor = self.counter % 10
                if factor >= 5:
                    factor = 5 - (self.counter % 5)
                painter.setBrush(QBrush(QColor(95 + factor * 32, 127, 127)))
            else:
                painter.setBrush(QBrush(QColor(127, 127, 127)))
            painter.drawEllipse(
                self.width() / 2 + 30 * math.cos(2 * math.pi * i / 6.0) - 10,
                self.height() / 2 + 30 * math.sin(2 * math.pi * i / 6.0) - 10,
                20, 20)

        painter.end()
项目:gpvdm    作者:roderickmackenzie    | 项目源码 | 文件源码
def init(self):
        self.cpus=multiprocessing.cpu_count()

        self.tab.setTabsClosable(True)
        self.tab.setMovable(True)
        self.tab.setTabBar(QHTabBar())
        self.tab.setTabPosition(QTabWidget.West)

        self.font = QFont()
        self.font.setFamily('Monospace')
        self.font.setStyleHint(QFont.Monospace)
        self.font.setFixedPitch(True)
        self.font.setPointSize(int(12))

        self.terminals=[]
        self.process=[]
        for i in range(0,self.cpus):
            term=QTextEdit()
            term.setFont(self.font)

            pal = QPalette()
            bgc = QColor(0, 0, 0)
            pal.setColor(QPalette.Base, bgc)
            textc = QColor(230, 230, 230)
            pal.setColor(QPalette.Text, textc)
            term.setPalette(pal)

            proc=QProcess(self)
            proc.readyRead.connect(functools.partial(self.dataReady,i))
            self.process.append(proc)
            self.terminals.append(term)
            self.tab.addTab(term,_("CPU")+" "+str(i))

        if enable_betafeatures()==True:
            self.cluster=hpc_class()
            self.tab.addTab(self.cluster,_("Cluster"))
            global_object_register("cluster_tab",self.cluster)
项目:gpvdm    作者:roderickmackenzie    | 项目源码 | 文件源码
def drawWidget(self, qp):
        font = QFont('Sans', 11, QFont.Normal)
        qp.setFont(font)

        pen = QPen(QColor(20, 20, 20), 1, Qt.SolidLine)

        qp.setPen(pen)
        qp.setBrush(Qt.NoBrush)

        if self.value==True:
            qp.setBrush(QColor(95,163,235))
            qp.drawRoundedRect(0, 0.0, 80.0,22.0,5.0,5.0)
            qp.setBrush(QColor(230,230,230))
            qp.drawRoundedRect(40, 2, 38,18.0,5.0,5.0)

            qp.drawText(8, 17, _("ON"))
        else:
            qp.setBrush(QColor(180,180,180))
            qp.drawRoundedRect(0, 0.0, 80.0,22.0,5.0,5.0)           
            qp.setBrush(QColor(230,230,230))
            qp.drawRoundedRect(2, 2, 38,18.0,5.0,5.0)
            qp.drawText(44, 17, _("OFF"))
项目:defconQt    作者:trufont    | 项目源码 | 文件源码
def _doubleClicked(self, index):
        model = self.model()
        if model is None:
            return
        data = model.data(index)
        if isinstance(data, QColor):
            if QApplication.keyboardModifiers() & Qt.AltModifier:
                model.setData(index, QColor())
            else:
                dialog = QColorDialog(self)
                dialog.setCurrentColor(data)
                dialog.setOption(QColorDialog.ShowAlphaChannel)
                ret = dialog.exec_()
                if ret:
                    color = dialog.currentColor()
                    model.setData(index, color)

    # -------------------
    # Convenience methods
    # -------------------
项目:asprilo    作者:potassco    | 项目源码 | 文件源码
def __init__(self, ID = 0, x = 0, y = 0):
        QGraphicsItem.__init__(self)
        visualizerItem.VisualizerItem.__init__(self)
        self._kind_name = ''
        self._id = ID
        self._model = None
        self._position = (x, y) 
        self._start_position = (x, y)
        self._dragged = None
        self._enable_drag = False
        self._graphics_item = None
        self._text = None
        self._actions = []
        self._colors = [QColor(0,0,0)]
        self._display_mode = 0

        self.setAcceptedMouseButtons(Qt.MouseButtons(1))
项目:pisi-player    作者:mthnzbk    | 项目源码 | 文件源码
def __init__(self, parent=None):
        super().__init__()
        self.parent = parent
        hlayout = QHBoxLayout()
        self.setLayout(hlayout)

        font_combobox = QFontComboBox()
        font_combobox.setEditable(False)
        font_combobox.setFixedHeight(30)
        font_combobox.setStyleSheet("QFontComboBox {background-color: white; color: black; border-radius: 3px;\
                                     border-color: lightgray; border-style: solid; border-width:2px;} \
                                     QFontComboBox::down-arrow {image: url(/usr/share/icons/breeze/actions/24/arrow-down)} \
                                     QFontComboBox::drop-down {border:none;}")
        font_combobox.setCurrentText(settings().value("Subtitle/font"))
        hlayout.addWidget(font_combobox)

        self.color_button = QPushButton()
        self.color_button.setFixedSize(30, 30)
        self.color_button.setStyleSheet("QPushButton {border: 1px solid black; border-radius: 3px; \
                                    background-color: %s; }"%(settings().value("Subtitle/color") or QColor("#ffffff")).name())
        hlayout.addWidget(self.color_button)

        self.color_button.clicked.connect(self.colorSelected)
        font_combobox.currentIndexChanged[str].connect(self.fontChanged)
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def __init__(self):
        super(StickMan, self).__init__()

        self.m_sticks = True
        self.m_isDead = False
        self.m_pixmap = QPixmap('images/head.png')
        self.m_penColor = QColor(Qt.white)
        self.m_fillColor = QColor(Qt.black)

        # Set up start position of limbs.
        self.m_nodes = []
        for x, y in Coords:
            node = Node(QPointF(x, y), self)
            node.positionChanged.connect(self.childPositionChanged)
            self.m_nodes.append(node)

        self.m_perfectBoneLengths = []
        for n1, n2 in Bones:
            node1 = self.m_nodes[n1]
            node2 = self.m_nodes[n2]

            dist = node1.pos() - node2.pos()
            self.m_perfectBoneLengths.append(math.hypot(dist.x(), dist.y()))

        self.startTimer(10)
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
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))
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def data(self, role):
        if role in (Qt.EditRole, Qt.StatusTipRole):
            return self.formula()
        if role == Qt.DisplayRole:
            return self.display()
        t = str(self.display())
        try:
            number = int(t)
        except ValueError:
            number = None
        if role == Qt.TextColorRole:
            if number is None:
                return QColor(Qt.black)
            elif number < 0:
                return QColor(Qt.red)
            return QColor(Qt.blue)

        if role == Qt.TextAlignmentRole:
            if t and (t[0].isdigit() or t[0] == '-'):
                return Qt.AlignRight | Qt.AlignVCenter
        return super(SpreadSheetItem, self).data(role)
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, self.antialiased)
        painter.translate(self.width() / 2, self.height() / 2)

        for diameter in range(0, 256, 9):
            delta = abs((self.frameNo % 128) - diameter / 2)
            alpha = 255 - (delta * delta) / 4 - diameter
            if alpha > 0:
                painter.setPen(QPen(QColor(0, diameter / 2, 127, alpha), 3))

                if self.floatBased:
                    painter.drawEllipse(QRectF(-diameter / 2.0,
                            -diameter / 2.0, diameter, diameter))
                else:
                    painter.drawEllipse(QRect(-diameter / 2,
                            -diameter / 2, diameter, diameter))
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def __init__(self, parent=None):
        super(SvgView, self).__init__(parent)

        self.renderer = SvgView.Native
        self.svgItem = None
        self.backgroundItem = None
        self.outlineItem = None
        self.image = QImage()

        self.setScene(QGraphicsScene(self))
        self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
        self.setDragMode(QGraphicsView.ScrollHandDrag)
        self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)

        # Prepare background check-board pattern.
        tilePixmap = QPixmap(64, 64)
        tilePixmap.fill(Qt.white)
        tilePainter = QPainter(tilePixmap)
        color = QColor(220, 220, 220)
        tilePainter.fillRect(0, 0, 32, 32, color)
        tilePainter.fillRect(32, 32, 32, 32, color)
        tilePainter.end()

        self.setBackgroundBrush(QBrush(tilePixmap))
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def __init__(self, parent=None):

        super(BubblesWidget, self).__init__(parent)

        self.pen = QPen(QColor("#cccccc"))
        self.bubbles = []
        self.backgroundColor1 = self.randomColor()
        self.backgroundColor2 = self.randomColor().darker(150)
        self.newBubble = None

        random.seed()

        self.animation_timer = QTimer(self)
        self.animation_timer.setSingleShot(False)
        self.animation_timer.timeout.connect(self.animate)
        self.animation_timer.start(25)

        self.bubbleTimer = QTimer()
        self.bubbleTimer.setSingleShot(False)
        self.bubbleTimer.timeout.connect(self.expandBubble)

        self.setMouseTracking(True)
        self.setMinimumSize(QSize(200, 200))
        self.setWindowTitle("Bubble Maker")
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def displayText(value):
        if isinstance(value, (bool, int, QByteArray)):
            return str(value)
        if isinstance(value, str):
            return value
        elif isinstance(value, float):
            return '%g' % value
        elif isinstance(value, QColor):
            return '(%u,%u,%u,%u)' % (value.red(), value.green(), value.blue(), value.alpha())
        elif isinstance(value, (QDate, QDateTime, QTime)):
            return value.toString(Qt.ISODate)
        elif isinstance(value, QPoint):
            return '(%d,%d)' % (value.x(), value.y())
        elif isinstance(value, QRect):
            return '(%d,%d,%d,%d)' % (value.x(), value.y(), value.width(), value.height())
        elif isinstance(value, QSize):
            return '(%d,%d)' % (value.width(), value.height())
        elif isinstance(value, list):
            return ','.join(value)
        elif value is None:
            return '<Invalid>'

        return '<%s>' % value
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
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)
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def paintEvent(self, event):
        sineTable = (0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38)

        metrics = QFontMetrics(self.font())
        x = (self.width() - metrics.width(self.text)) / 2
        y = (self.height() + metrics.ascent() - metrics.descent()) / 2
        color = QColor()

        painter = QPainter(self)

        for i, ch in enumerate(self.text):
            index = (self.step + i) % 16
            color.setHsv((15 - index) * 16, 255, 191)
            painter.setPen(color)
            painter.drawText(x, y - ((sineTable[index] * metrics.height()) / 400), ch)
            x += metrics.width(ch)
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def createImage(self, transform):
        scaledRect = transform.mapRect(QRect(0, 0, ScanItem.ITEM_WIDTH, ScanItem.ITEM_HEIGHT))
        image = QImage(scaledRect.width(), scaledRect.height(),
                QImage.Format_ARGB32_Premultiplied)
        image.fill(QColor(0, 0, 0, 0).rgba())
        painter = QPainter(image)
        painter.setRenderHint(QPainter.Antialiasing)

        if Colors.useEightBitPalette:
            painter.setPen(QPen(QColor(100, 100, 100), 2))
            painter.setBrush(QColor(206, 246, 117))
            painter.drawEllipse(1, 1, scaledRect.width() - 2,
                    scaledRect.height() - 2)
        else:
            painter.setPen(QPen(QColor(0, 0, 0, 15), 1))
            painter.setBrush(QColor(0, 0, 0, 15))
            painter.drawEllipse(1, 1, scaledRect.width() - 2,
                    scaledRect.height() - 2)

        return image
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def createImage(self, transform):
        if self.type == DemoTextItem.DYNAMIC_TEXT:
            return None

        sx = min(transform.m11(), transform.m22())
        sy = max(transform.m22(), sx)

        textItem = QGraphicsTextItem()
        textItem.setHtml(self.text)
        textItem.setTextWidth(self.textWidth)
        textItem.setFont(self.font)
        textItem.setDefaultTextColor(self.textColor)
        textItem.document().setDocumentMargin(2)

        w = textItem.boundingRect().width()
        h = textItem.boundingRect().height()
        image = QImage(int(w * sx), int(h * sy),
                QImage.Format_ARGB32_Premultiplied)
        image.fill(QColor(0, 0, 0, 0).rgba())
        painter = QPainter(image)
        painter.scale(sx, sy)
        style = QStyleOptionGraphicsItem()
        textItem.paint(painter, style, None)

        return image
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def __init__(self):
        super(StickMan, self).__init__()

        self.m_sticks = True
        self.m_isDead = False
        self.m_pixmap = QPixmap('images/head.png')
        self.m_penColor = QColor(Qt.white)
        self.m_fillColor = QColor(Qt.black)

        # Set up start position of limbs.
        self.m_nodes = []
        for x, y in Coords:
            node = Node(QPointF(x, y), self)
            node.positionChanged.connect(self.childPositionChanged)
            self.m_nodes.append(node)

        self.m_perfectBoneLengths = []
        for n1, n2 in Bones:
            node1 = self.m_nodes[n1]
            node2 = self.m_nodes[n2]

            dist = node1.pos() - node2.pos()
            self.m_perfectBoneLengths.append(math.hypot(dist.x(), dist.y()))

        self.startTimer(10)
项目:coliform-project    作者:uprm-research-resto    | 项目源码 | 文件源码
def initUI(self):

        # QToolTip.setFont(QFont('SansSerif', 9))

        self.cwidget = GUICenterWidget()
        self.setCentralWidget(self.cwidget)

        # self.setToolTip('This is a <b>QWidget</b> widget')

        self.statusBar().showMessage('Ready')

        self.center()
        self.setWindowTitle('Coliform Control GUI')

        self.onewiretimer = QTimer(self)
        self.onewiretimer.timeout.connect(self.cwidget.onewireOn)
        self.onewiretimer.start(1000)

        # self.p = QPalette(self.palette())
        # self.p.setColor(QPalette.Window, QColor(53, 53, 53))
        # self.p.setColor(QPalette.WindowText, Qt.white)
        # self.p.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
        # self.p.setColor(QPalette.ToolTipBase, Qt.white)
        # self.p.setColor(QPalette.ToolTipText, Qt.white)
        # self.p.setColor(QPalette.Button, QColor(53, 53, 53))
        # self.p.setColor(QPalette.ButtonText, Qt.white)
        # self.p.setColor(QPalette.BrightText, Qt.red)
        # self.p.setColor(QPalette.Highlight, QColor(142, 45, 197).lighter())
        # self.p.setColor(QPalette.HighlightedText, Qt.black)
        # self.setPalette(self.p)

        self.show()
项目:coliform-project    作者:uprm-research-resto    | 项目源码 | 文件源码
def initUI(self):

        # QToolTip.setFont(QFont('SansSerif', 9))

        self.cwidget = CameraCenterWidget()
        self.setCentralWidget(self.cwidget)

        # self.setToolTip('This is a <b>QWidget</b> widget')

        self.center()
        self.setWindowTitle('Camera Control GUI')

        self.statusBarTimer = QTimer(self)
        self.statusBarTimer.timeout.connect(self.statusUpdate)
        self.statusBarTimer.start(100)

        # self.p = QPalette(self.palette())
        # self.p.setColor(QPalette.Window, QColor(53, 53, 53))
        # self.p.setColor(QPalette.WindowText, Qt.white)
        # self.p.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
        # self.p.setColor(QPalette.ToolTipBase, Qt.white)
        # self.p.setColor(QPalette.ToolTipText, Qt.white)
        # self.p.setColor(QPalette.Button, QColor(53, 53, 53))
        # self.p.setColor(QPalette.ButtonText, Qt.white)
        # self.p.setColor(QPalette.BrightText, Qt.red)
        # self.p.setColor(QPalette.Highlight, QColor(142, 45, 197).lighter())
        # self.p.setColor(QPalette.HighlightedText, Qt.black)
        # self.setPalette(self.p)

        self.show()
项目:coliform-project    作者:uprm-research-resto    | 项目源码 | 文件源码
def initUI(self):

        # QToolTip.setFont(QFont('SansSerif', 9))

        self.cwidget = RGBCenterWidget()
        self.setCentralWidget(self.cwidget)

        # self.setToolTip('This is a <b>QWidget</b> widget')

        self.center()
        self.setWindowTitle('RGB Sensor GUI')

        self.statusBarTimer = QTimer(self)
        self.statusBarTimer.timeout.connect(self.statusUpdate)
        self.statusBarTimer.start(100)

        # self.p = QPalette(self.palette())
        # self.p.setColor(QPalette.Window, QColor(53, 53, 53))
        # self.p.setColor(QPalette.WindowText, Qt.white)
        # self.p.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
        # self.p.setColor(QPalette.ToolTipBase, Qt.white)
        # self.p.setColor(QPalette.ToolTipText, Qt.white)
        # self.p.setColor(QPalette.Button, QColor(53, 53, 53))
        # self.p.setColor(QPalette.ButtonText, Qt.white)
        # self.p.setColor(QPalette.BrightText, Qt.red)
        # self.p.setColor(QPalette.Highlight, QColor(142, 45, 197).lighter())
        # self.p.setColor(QPalette.HighlightedText, Qt.black)
        # self.setPalette(self.p)

        self.show()
项目:notepad    作者:lfsando    | 项目源码 | 文件源码
def format(color, style=''):

    word_color = QColor()
    word_color.setNamedColor(color)
    word_format = QTextCharFormat()
    word_format.setForeground(word_color)
    if 'italic' in style:
        word_format.setFontItalic(True)
    elif 'bold' in style:
        word_format.setFontWeight(QFont.Bold)

    return word_format
项目:notepad    作者:lfsando    | 项目源码 | 文件源码
def default_visual(self):

        # Pallete
        default_palette = self.text_widget.palette()

        # Background
        default_background_color = QtGui.QColor()
        default_background_color.setNamedColor('#2B2B2B')
        default_palette.setColor(QtGui.QPalette.Base, default_background_color)

        # Font Color
        default_font_color = QtGui.QColor()
        default_font_color.setNamedColor('#F8F8F2')
        default_palette.setColor(QtGui.QPalette.Text, default_font_color)

        # Font Type
        default_font = QtGui.QFont('Consolas', 13)
        self.text_widget.setFont(default_font)

        self.text_widget.setPalette(default_palette)
项目:binja_dynamics    作者:nccgroup    | 项目源码 | 文件源码
def highlight_stack_pointer(self, sp, width=8):
        """ Removes old stack pointer highlights and creates a new one """
        if self.stack_pointer is not None:
            self.get_widget('stack').clear_named_highlight('sp')
        self.highlight_bytes_at_address('stack', sp, width, QColor(162, 217, 175), 'sp')
        self.stack_pointer = sp
项目:binja_dynamics    作者:nccgroup    | 项目源码 | 文件源码
def highlight_base_pointer(self, bp, width=8):
        """ Highlights the base pointer """
        if self.base_pointer is not None:
            self.get_widget('stack').clear_named_highlight('bp')
        self.highlight_bytes_at_address('stack', bp, width, QColor(128, 198, 233), 'bp')
        self.base_pointer = bp
项目:binja_dynamics    作者:nccgroup    | 项目源码 | 文件源码
def highlight_retn_addr(self, ret, width=8):
        """ Highlights the return address, unsurprisingly """
        if self.retn_address is not None:
            self.get_widget('stack').clear_named_highlight('ret')
        if (ret is not None):
            self.highlight_bytes_at_address('stack', ret, width, QColor(222, 143, 151), 'ret')
        self.retn_address = ret
项目:activity-browser    作者:LCA-ActivityBrowser    | 项目源码 | 文件源码
def write(self, text):
        # TODO: Doesn't seem to have any effect
        if self.color:
            original = self.edit_widget.textColor()
            self.edit_widget.setTextColor(QtGui.QColor(self.color))

        self.edit_widget.moveCursor(QtGui.QTextCursor.End)
        self.edit_widget.insertPlainText(text)

        if self.color:
            self.edit_widget.setTextColor(original)

        if self.out:
            self.out.write(text)
项目:echolocation    作者:hgross    | 项目源码 | 文件源码
def _add_measurement(self, length, angle, added_time):
        """
        Adds a visualization for a measured distance to the scene
        :param length: length in cm
        :param angle: the angle
        """
        mx, my = self._get_middle()
        angle_rad = deg2rad(angle)
        ex, ey = mx + length * math.cos(angle_rad), my + length * math.sin(angle_rad)

        age = time.time() - added_time
        age = age if age < self.fade_out_time else self.fade_out_time
        alpha_channel_value = scale((0, self.fade_out_time), (255, 0), age)
        assert 0 <= alpha_channel_value <= 255

        brush_color = QColor(self.measured_distances_color)
        brush_color.setAlpha(alpha_channel_value)
        brush = QBrush(brush_color)
        tpen = QPen(brush_color)

        self.scene.addLine(mx, my, ex, ey, pen=tpen)
        self.scene.addEllipse(ex-self.dot_width/2, ey-self.dot_width/2, self.dot_width, self.dot_width, pen=tpen, brush=brush)
项目:gui_tool    作者:UAVCAN    | 项目源码 | 文件源码
def colorize_can_id(frame):
    if not frame.extended:
        return
    mask = 0b11111
    priority = (frame.id >> 24) & mask
    col = QColor()
    col.setRgb(0xFF, 0xFF - (mask - priority) * 6, 0xFF)
    return col
项目:gui_tool    作者:UAVCAN    | 项目源码 | 文件源码
def colorize_transfer_id(e):
    if len(e[1].data) < 1:
        return

    # Making a rather haphazard hash using transfer ID and a part of CAN ID
    x = (e[1].data[-1] & 0b11111) | (((e[1].id >> 16) & 0b1111) << 5)
    red = ((x >> 6) & 0b111) * 25
    green = ((x >> 3) & 0b111) * 25
    blue = (x & 0b111) * 25

    col = QColor()
    col.setRgb(0xFF - red, 0xFF - green, 0xFF - blue)
    return col
项目:gui_tool    作者:UAVCAN    | 项目源码 | 文件源码
def __call__(self, e):
        ts = datetime.datetime.fromtimestamp(e[1].ts_real).strftime(self.FORMAT)
        col = QColor()

        # Constraining delta to [0, 1]
        delta = min(1, e[1].ts_real - self._prev_ts)
        if delta < 0:
            col.setRgb(255, 230, 230)
        else:
            self._prev_ts = e[1].ts_real
            col.setRgb(*([255 - int(192 * delta)] * 3))
        return ts, col
项目:gui_tool    作者:UAVCAN    | 项目源码 | 文件源码
def _set_color(widget, role, color):
    pal = widget.palette()
    pal.setColor(role, QColor(color))
    widget.setAutoFillBackground(True)
    widget.setPalette(pal)
    widget.update()