def paint(self, painter, option, index):
        """
        Overrides the selection highlight color.

        https://www.qtcentre.org/threads/41299-How-to-Change-QTreeView-highlight-color
        Note: this can actually do alot more than that with the QPalette...
            which is something I should learn how to use apparently...

        """
        from qtpy.QtGui import QPalette
        item = index.internalPointer()
        new_option = QStyleOptionViewItem(option)
        brush = QBrush()
        if item.isEnabled():
            color = QColor(*iColor["rgba_text"])
        else:
            color = QColor(*iColor["rgba_text_disabled"])
        # TODO highlight selection color???
        # why did I move this here?
        brush.setColor(color)

        # brush2 = QBrush(QColor(0, 255, 0, 128))
        new_option.palette.setBrush(QPalette.Normal, QPalette.HighlightedText,
                                    brush)
        # new_option.palette.setBrush(QPalette.Normal, QPalette.Highlight, brush2)

        QStyledItemDelegate.paint(self, painter, new_option, index)

        # if option.state == QStyle.State_Selected:
        #     brush2 = QBrush(QColor(0, 255, 255, 128))
        return
示例#2
0
    def __init__(self, obj, obj_name='', attr_cols=None, parent=None):
        """
        Constructor

        :param obj: any Python object or variable
        :param obj_name: name of the object as it will appear in the root node
                         If empty, no root node will be drawn.
        :param attr_cols: list of AttributeColumn definitions
        :param parent: the parent widget
        """
        super(TreeModel, self).__init__(parent)
        self._attr_cols = attr_cols

        self.regular_font = QFont()  # Font for members (non-functions)
        # Font for __special_attributes__
        self.special_attribute_font = QFont()
        self.special_attribute_font.setItalic(False)

        self.regular_color = QBrush(QColor(ima.MAIN_FG_COLOR))
        self.callable_color = QBrush(QColor(
            ima.MAIN_FG_COLOR))  # for functions, methods, etc.

        # The following members will be initialized by populateTree
        # The rootItem is always invisible. If the obj_name
        # is the empty string, the inspectedItem
        # will be the rootItem (and therefore be invisible).
        # If the obj_name is given, an
        # invisible root item will be added and the
        # inspectedItem will be its only child.
        # In that case the inspected item will be visible.
        self._inspected_node_is_visible = None
        self._inspected_item = None
        self._root_item = None
        self.populateTree(obj, obj_name=obj_name)
示例#3
0
    def data(self, index, role=Qt.DisplayRole):
        if role == Qt.DisplayRole or role == Qt.EditRole:
            key = self._columns[index.column()]
            tnum = sorted(self._tool_table)[index.row() + 1]
            return self._tool_table[tnum][key]

        elif role == Qt.TextAlignmentRole:
            col = self._columns[index.column()]
            if col == 'R':  # Remark
                return Qt.AlignVCenter | Qt.AlignLeft
            elif col in 'TPQ':  # Integers (Tool, Pocket, Orient)
                return Qt.AlignVCenter | Qt.AlignCenter
            else:  # All the other floats
                return Qt.AlignVCenter | Qt.AlignRight

        elif role == Qt.TextColorRole:
            tnum = sorted(self._tool_table)[index.row() + 1]
            if self.stat.tool_in_spindle == tnum:
                return QBrush(self.current_tool_color)
            else:
                return QStandardItemModel.data(self, index, role)

        elif role == Qt.BackgroundRole and self.current_tool_bg is not None:
            tnum = sorted(self._tool_table)[index.row() + 1]
            if self.stat.tool_in_spindle == tnum:
                return QBrush(self.current_tool_bg)
            else:
                return QStandardItemModel.data(self, index, role)

        return QStandardItemModel.data(self, index, role)
示例#4
0
    def __init__(self):
        QMainWindow.__init__(self)

        view = MapGraphicsView(tileSource=MapTileSourceHere())

        self.setCentralWidget(view)
        view.scene().setCenter(31.789339, 41.450508)
        view.setOptimizationFlag(QGraphicsView.DontSavePainterState, True)
        view.setRenderHint(QPainter.Antialiasing, True)
        view.setRenderHint(QPainter.SmoothPixmapTransform, True)
        pointItem = view.scene().addCircle(31.789339, 44.860767, 3.0)
        pointItem.setBrush(Qt.black)
        pointItem.setToolTip('31.789339, 41.450508')
        pointItem.setFlag(QGraphicsItem.ItemIsSelectable, True)
        pointItem = view.scene().addCircle(31.789339, 44.860767, 5.0)
        pointItem.setBrush(Qt.green)
        pointItem.setPen(QPen(Qt.NoPen))
        pointItem.setToolTip('%f, %f' % (31.789339, 44.860767))
        pointItem.setFlag(QGraphicsItem.ItemIsSelectable, True)
        lineItem = view.scene().addLine(32.859741, 39.933365, 31.789339,
                                        41.450508)
        lineItem.setPen(QPen(QBrush(Qt.blue), 3.0))

        polylineItem = view.scene().addPolyline('41.450508', '31.789339')
        polylineItem.setPen(QPen(QBrush(Qt.red), 3.0))
        pix = QPixmap(24, 24)
        pix.fill(Qt.red)
        pixmapItem = view.scene().addPixmap(31.789339, 44.860767, pix)
        pixmapItem.setOffset(-12, -12)
示例#5
0
    def data(self, index, role=Qt.DisplayRole):
        row, col = index.row(), index.column()

        #all_active_codes = [self.active_g_codes, self.active_m_codes]

        if role == Qt.DisplayRole or role == Qt.EditRole:
            if self.active_codes_only:
                a_code = self.active_g_codes[row]
            else:
                a_code = GM_CODES.keys()[row]

            if col == 0:
                return a_code
            elif col == 1:
                return GM_CODES[a_code]

        if self.active_codes_only:
            if role == Qt.TextColorRole:
                return QBrush(self.active_code_color)

            elif role == Qt.BackgroundRole and self.active_code_bg is not None:
                return QBrush(self.active_code_bg)
        else:
            if role == Qt.TextColorRole:
                if GM_CODES.keys()[row] in self.active_g_codes:
                    return QBrush(self.active_code_color)

            elif role == Qt.BackgroundRole and self.active_code_bg is not None:
                if GM_CODES.keys()[row] in self.active_g_codes:
                    return QBrush(self.active_code_bg)

        return QStandardItemModel.data(self, index, role)
示例#6
0
    def paint(self, painter, option, index):
        QItemDelegate.paint(self, painter, option, index)
        column = index.column()
        row = index.row()
        rect = option.rect

        # Draw borders
        pen = QPen()
        pen.setWidth(1)
        pen.setColor(QColor('#cdcdcd'))
        painter.setPen(pen)
        painter.drawLine(rect.topLeft(), rect.topRight())

        if (row == self.current_hover_row() or row == self.current_row() and
                (self.has_focus_or_context())):
            brush = QBrush(Qt.SolidPattern)
            brush.setColor(QColor(255, 255, 255, 100))
            painter.fillRect(rect, brush)
            if row == self.current_row() and column in [const.COL_START]:
                pen = QPen()
                pen.setWidth(10)
                pen.setColor(QColor('#7cbb4c'))
                painter.setPen(pen)
                dyt = QPoint(0, 5)
                dyb = QPoint(0, 4)
                painter.drawLine(rect.bottomLeft()-dyb, rect.topLeft()+dyt)
示例#7
0
 def __init__(self, parent=None, circle=False):
     super(PyDMBitIndicator, self).__init__(parent)
     self.setAutoFillBackground(True)
     self.circle = circle
     self._painter = QPainter()
     self._brush = QBrush(Qt.SolidPattern)
     self._pen = QPen(Qt.SolidLine)
示例#8
0
    def __init__(self, *args):
        QFrame.__init__(self, *args)

        self.xMap = QwtScaleMap()
        self.xMap.setScaleInterval(-0.5, 10.5)
        self.yMap = QwtScaleMap()
        self.yMap.setScaleInterval(-1.1, 1.1)

        # frame style
        self.setFrameStyle(QFrame.Box | QFrame.Raised)
        self.setLineWidth(2)
        self.setMidLineWidth(3)

        # calculate values
        self.x = np.arange(0, 10.0, 10.0 / 27)
        self.y = np.sin(self.x) * np.cos(2 * self.x)

        # make curves with different styles
        self.curves = []
        self.titles = []
        # curve 1
        self.titles.append("Style: Sticks, Symbol: Ellipse")
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.red))
        curve.setStyle(QwtPlotCurve.Sticks)
        curve.setSymbol(
            QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.yellow), QPen(Qt.blue),
                      QSize(5, 5)))
        self.curves.append(curve)
        # curve 2
        self.titles.append("Style: Lines, Symbol: None")
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.darkBlue))
        curve.setStyle(QwtPlotCurve.Lines)
        self.curves.append(curve)
        # curve 3
        self.titles.append("Style: Lines, Symbol: None, Antialiased")
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.darkBlue))
        curve.setStyle(QwtPlotCurve.Lines)
        curve.setRenderHint(QwtPlotItem.RenderAntialiased)
        self.curves.append(curve)
        # curve 4
        self.titles.append("Style: Steps, Symbol: None")
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.darkCyan))
        curve.setStyle(QwtPlotCurve.Steps)
        self.curves.append(curve)
        # curve 5
        self.titles.append("Style: NoCurve, Symbol: XCross")
        curve = QwtPlotCurve()
        curve.setStyle(QwtPlotCurve.NoCurve)
        curve.setSymbol(
            QwtSymbol(QwtSymbol.XCross, QBrush(), QPen(Qt.darkMagenta),
                      QSize(5, 5)))
        self.curves.append(curve)

        # attach data, using Numeric
        for curve in self.curves:
            curve.setData(self.x, self.y)
示例#9
0
    def set_header_style(self):

        fnt = QFont()
        fnt.setWeight(QFont.Black)
        self.setFont(fnt)
        self.setBackground(QBrush(QColor(HEADER_BACKGROUND)))
        self.setForeground(QBrush(QColor(HEADER_FOREGROUND)))
示例#10
0
文件: byte.py 项目: slaclab/pydm
class PyDMBitIndicator(QWidget):
    """
    A QWidget which draws a colored circle or rectangle

    Parameters
    ----------
    parent : QWidget
        The parent widget for the Label

    """
    def __init__(self, parent=None, circle=False):
        super(PyDMBitIndicator, self).__init__(parent)
        self.setAutoFillBackground(True)
        self.circle = circle
        self._painter = QPainter()
        self._brush = QBrush(Qt.SolidPattern)
        self._pen = QPen(Qt.SolidLine)

    def paintEvent(self, event):
        """
        Paint events are sent to widgets that need to update themselves,
        for instance when part of a widget is exposed because a covering
        widget was moved.

        Parameters
        ----------
        event : QPaintEvent
        """
        self._painter.begin(self)
        opt = QStyleOption()
        opt.initFrom(self)
        self.style().drawPrimitive(QStyle.PE_Widget, opt, self._painter, self)
        self._painter.setRenderHint(QPainter.Antialiasing)
        self._painter.setBrush(self._brush)
        self._painter.setPen(self._pen)
        if self.circle:
            rect = event.rect()
            w = rect.width()
            h = rect.height()
            r = min(w, h) / 2.0 - 2.0 * max(self._pen.widthF(), 1.0)
            self._painter.drawEllipse(QPoint(w / 2.0, h / 2.0), r, r)
        else:
            self._painter.drawRect(event.rect())
        self._painter.end()

    def setColor(self, color):
        """
        Property for the color to be used when drawing

        Parameters
        ----------
        QColor
        """
        self._brush.setColor(color)
        self.update()

    def minimumSizeHint(self):
        fm = QFontMetrics(self.font())
        return QSize(fm.height(), fm.height())
示例#11
0
class PyDMBitIndicator(QWidget):
    """
    A QWidget which draws a colored circle or rectangle

    Parameters
    ----------
    parent : QWidget
        The parent widget for the Label

    """
    def __init__(self, parent=None, circle=False):
        super(PyDMBitIndicator, self).__init__(parent)
        self.setAutoFillBackground(True)
        self.circle = circle
        self._painter = QPainter()
        self._brush = QBrush(Qt.SolidPattern)
        self._pen = QPen(Qt.SolidLine)

    def paintEvent(self, event):
        """
        Paint events are sent to widgets that need to update themselves,
        for instance when part of a widget is exposed because a covering
        widget was moved.

        Parameters
        ----------
        event : QPaintEvent
        """
        self._painter.begin(self)
        opt = QStyleOption()
        opt.initFrom(self)
        self.style().drawPrimitive(QStyle.PE_Widget, opt, self._painter, self)
        self._painter.setRenderHint(QPainter.Antialiasing)
        self._painter.setBrush(self._brush)
        self._painter.setPen(self._pen)
        if self.circle:
            rect = self.rect()
            w = rect.width()
            h = rect.height()
            r = min(w, h) / 2.0 - 2.0 * max(self._pen.widthF(), 1.0)
            self._painter.drawEllipse(QPoint(w / 2.0, h / 2.0), r, r)
        else:
            self._painter.drawRect(self.rect())
        self._painter.end()

    def setColor(self, color):
        """
        Property for the color to be used when drawing

        Parameters
        ----------
        QColor
        """
        self._brush.setColor(color)
        self.update()

    def minimumSizeHint(self):
        fm = QFontMetrics(self.font())
        return QSize(fm.height(), fm.height())
示例#12
0
 def _reset_appearance_of(self, cell):
     cell.setOpacity(0.2)
     if self._debug and self._debug_color:
         cell.setPen(QPen(Qt.black))
         cell.setBrush(QBrush(self._debug_color))
     else:
         cell.setPen(QPen(Qt.NoPen))
         cell.setBrush(QBrush(Qt.NoBrush))
示例#13
0
    def make(
        cls,
        style=None,
        brush=None,
        pen=None,
        size=None,
        path=None,
        pixmap=None,
        graphic=None,
        svgdocument=None,
        pinpoint=None,
    ):
        """
        Create and setup a new `QwtSymbol` object (convenience function).
        
        :param style: Symbol Style
        :type style: int or None
        :param brush: Brush to fill the interior
        :type brush: QBrush or None
        :param pen: Outline pen
        :type pen: QPen or None
        :param size: Size
        :type size: QSize or None
        :param path: Painter path
        :type path: QPainterPath or None
        :param path: Painter path
        :type path: QPainterPath or None
        :param pixmap: Pixmap as symbol
        :type pixmap: QPixmap or None
        :param graphic: Graphic
        :type graphic: qwt.graphic.QwtGraphic or None
        :param svgdocument: SVG icon as symbol

        .. seealso::
        
            :py:meth:`setPixmap()`, :py:meth:`setGraphic()`, :py:meth:`setPath()`
        """
        style = QwtSymbol.NoSymbol if style is None else style
        brush = QBrush(Qt.gray) if brush is None else QBrush(brush)
        pen = QPen(Qt.black, 0) if pen is None else QPen(pen)
        size = QSize() if size is None else size
        if not isinstance(size, QSize):
            if isinstance(size, tuple) and len(size) == 2:
                size = QSize(size[0], size[1])
            else:
                raise TypeError("Invalid size %r" % size)
        item = cls(style, brush, pen, size)
        if path is not None:
            item.setPath(path)
        elif pixmap is not None:
            item.setPixmap(pixmap)
        elif graphic is not None:
            item.setGraphic(graphic)
        elif svgdocument is not None:
            item.setSvgDocument(svgdocument)
        if pinpoint is not None:
            item.setPinPoint(pinpoint)
        return item
示例#14
0
 def update_light(self, _in, _out):
     """Update the light beams striking and emitting from the device"""
     for (widget, state) in zip((self.beam_indicator, self.out_indicator),
                                (_in, _out)):
         # Set color
         if state:
             widget.brush = QBrush(QColor('#00ffff'))
         else:
             widget.brush = QBrush(QColor('#a0a0a4'))
示例#15
0
    def __init__(self, shape=Shape.CIRCLE, color=Qt.red, size=3, filled=True):
        super().__init__()
        self._brush = QBrush()
        self._pen = QPen()

        self.set_marker_shape(shape)
        self.set_marker_size(size)
        self.set_marker_color(color)
        self.set_marker_fill(filled)
示例#16
0
    def __init__(self, vim_cursor):
        self.color_fg = QBrush(QColor('#A9B7C6'))
        self.color_bg = QBrush(QColor('#30652F'))
        self.txt_searched = ''
        self.selection_list = []
        self.vim_cursor = vim_cursor
        self.ignorecase = True

        self.set_color()
示例#17
0
    def __init__(self, *args):
        QFrame.__init__(self, *args)

        self.setFrameStyle(QFrame.Box | QFrame.Raised)
        self.setLineWidth(2)
        self.setMidLineWidth(3)

        p = QPalette()
        p.setColor(self.backgroundRole(), QColor(30, 30, 50))
        self.setPalette(p)
        # make curves and maps
        self.tuples = []
        # curve 1
        curve = QwtPlotCurve()
        curve.setPen(QPen(QColor(150, 150, 200), 2))
        curve.setStyle(QwtPlotCurve.Lines)
        curve.setSymbol(
            QwtSymbol(QwtSymbol.XCross, QBrush(), QPen(Qt.yellow, 2),
                      QSize(7, 7)))
        self.tuples.append(
            (curve, QwtScaleMap(0, 100, -1.5,
                                1.5), QwtScaleMap(0, 100, 0.0, 2 * np.pi)))
        # curve 2
        curve = QwtPlotCurve()
        curve.setPen(QPen(QColor(200, 150, 50), 1, Qt.DashDotDotLine))
        curve.setStyle(QwtPlotCurve.Sticks)
        curve.setSymbol(
            QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.blue), QPen(Qt.yellow),
                      QSize(5, 5)))
        self.tuples.append(
            (curve, QwtScaleMap(0, 100, 0.0,
                                2 * np.pi), QwtScaleMap(0, 100, -3.0, 1.1)))
        # curve 3
        curve = QwtPlotCurve()
        curve.setPen(QPen(QColor(100, 200, 150)))
        curve.setStyle(QwtPlotCurve.Lines)
        self.tuples.append(
            (curve, QwtScaleMap(0, 100, -1.1,
                                3.0), QwtScaleMap(0, 100, -1.1, 3.0)))
        # curve 4
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.red))
        curve.setStyle(QwtPlotCurve.Lines)
        self.tuples.append(
            (curve, QwtScaleMap(0, 100, -5.0,
                                1.1), QwtScaleMap(0, 100, -1.1, 5.0)))
        # data
        self.phase = 0.0
        self.base = np.arange(0.0, 2.01 * np.pi, 2 * np.pi / (USize - 1))
        self.uval = np.cos(self.base)
        self.vval = np.sin(self.base)
        self.uval[1::2] *= 0.5
        self.vval[1::2] *= 0.5
        self.newValues()
        # start timer
        self.tid = self.startTimer(250)
示例#18
0
    def set_color(self):
        """Set the color of search results."""
        self.color_fg = QBrush(
            QColor(CONF.get(CONF_SECTION, 'search_fg_color')))
        self.color_bg = QBrush(
            QColor(CONF.get(CONF_SECTION, 'search_bg_color')))

        for sel in self.selection_list:
            sel.format.setForeground(self.color_fg)
            sel.format.setBackground(self.color_bg)
示例#19
0
    def addMark(self, new_mark: VideoSliderMark, update: bool = True):
        """Adds a marked value to the slider.

        Args:
            new_mark: value to mark
            update: Whether to redraw slider with new mark.

        Returns:
            None.
        """
        # check if mark is within slider range
        if new_mark.val > self._val_max:
            return
        if new_mark.val < self._val_min:
            return

        self._marks.add(new_mark)

        v_top_pad = self._header_height + 1
        v_bottom_pad = 1
        v_top_pad += new_mark.top_pad
        v_bottom_pad += new_mark.bottom_pad

        width = new_mark.visual_width

        v_offset = v_top_pad

        height = new_mark.get_height(container_height=self.box_rect.height() -
                                     self._header_height)

        color = new_mark.QColor
        pen = QPen(color, 0.5)
        pen.setCosmetic(True)
        brush = QBrush(color) if new_mark.filled else QBrush()

        line = self.scene.addRect(-width // 2, v_offset, width, height, pen,
                                  brush)
        self._mark_items[new_mark] = line

        if new_mark.mark_type == "tick":
            # Show tick mark behind other slider marks
            self._mark_items[new_mark].setZValue(0)

            # Add a text label to show in header area
            mark_label_text = (
                # sci notation if large
                f"{new_mark.val + self.tick_index_offset:g}")
            self._mark_labels[new_mark] = self.scene.addSimpleText(
                mark_label_text, self._base_font)
        else:
            # Show in front of tick marks and behind track lines
            self._mark_items[new_mark].setZValue(1)

        if update:
            self._update_visual_positions()
示例#20
0
 def data(self, index, role):
     if role in [QtCore.Qt.DisplayRole, QtCore.Qt.EditRole]:
         return self._data[index.row()][index.column()]
     if role == QtCore.Qt.BackgroundRole:
         if self.columnCount() < 3 or self._data[
                 index.row()][2] == "Connected":
             return QBrush(QtCore.Qt.white)
         if self._data[index.row()][3] == "Disconnected":
             return QBrush(QtCore.Qt.red)
         if self._data[index.row()][3] == "Moved":
             return QBrush(QtCore.Qt.yellow)
示例#21
0
    def paint(self, painter, styles, widget=None):
        pen1 = QPen(Qt.SolidLine)
        pen1.setColor(QColor(128, 128, 128))
        painter.setPen(pen1)

        brush1 = QBrush(Qt.SolidPattern)
        brush1.setColor(self.color)
        painter.setBrush(brush1)

        painter.setRenderHint(QPainter.Antialiasing)  # 反锯齿
        painter.drawRoundedRect(self.boundingRect(), 10, 10)
示例#22
0
    def get_gauge(self, parent, macros):
        aux = []
        for k, v in macros.items():
            aux.append('{}\t{}\n'.format(k, v))
        tooltip = ''.join(aux)

        width = 320
        height = 100

        frame = QFrame(parent)
        frame.setGeometry(QRect(10, 10, width, height))
        frame.setMinimumSize(width, height)
        frame.setFrameShape(QFrame.StyledPanel)
        frame.setFrameShadow(QFrame.Raised)
        frame.setObjectName("frame")

        brush = QBrush(QColor(180, 180, 180))
        brush.setStyle(Qt.NoBrush)

        alarmRec = PyDMDrawingRectangle(frame)
        alarmRec.channel = "ca://{}".format(macros.get('ALARM', None))
        alarmRec.setGeometry(QRect(0, 0, width, height))
        alarmRec.setToolTip(tooltip)
        alarmRec.setProperty("alarmSensitiveContent", True)
        alarmRec.setProperty("brush", brush)
        alarmRec.setObjectName("alarmRec")
        # alarmRec.setStyleSheet("margin:5px; border:3px solid rgb(0, 0, 0);")

        lblName = QLabel(frame)
        lblName.setGeometry(QRect(width * 0.05, 50, width - width * 0.05, 20))
        font = QFont()
        font.setPointSize(12)
        lblName.setFont(font)
        lblName.setAlignment(Qt.AlignCenter)
        lblName.setText("{}".format(macros.get('DISP', None)))
        lblName.setObjectName("lblName")
        lblName.setToolTip(tooltip)

        lblVal = PyDMLabel(frame)
        lblVal.setGeometry(QRect(width * 0.05, 10, width - width * 0.05, 30))
        font = QFont()
        font.setPointSize(18)
        lblVal.setFont(font)
        lblVal.setToolTip(tooltip)
        lblVal.setAlignment(Qt.AlignCenter)
        lblVal.setProperty("showUnits", False)
        lblVal.setObjectName("lblVal")
        lblVal.channel = "ca://{}".format(macros.get('PV', None))
        lblVal.precisionFromPV = False
        lblVal.precision = 2
        if self.macros.get('FORMAT', '') == 'EXP':
            lblVal.displayFormat = PyDMLabel.DisplayFormat.Exponential
        return frame
示例#23
0
    def get_gauge(self, parent, pv_info: PVInfo):
        tooltip = "".join(
            [f"{key}\t{value}\n" for key, value in pv_info.__dict__.items()]
        )

        width = 320
        height = 100

        frame = QFrame(parent)
        frame.setGeometry(QRect(10, 10, width, height))
        frame.setMinimumSize(width, height)
        frame.setFrameShape(QFrame.StyledPanel)
        frame.setFrameShadow(QFrame.Raised)
        frame.setObjectName("frame")

        brush = QBrush(QColor(180, 180, 180))
        brush.setStyle(Qt.NoBrush)

        alarmRec = PyDMDrawingRectangle(frame)
        alarmRec.channel = "ca://{}".format(pv_info.ALARM)
        alarmRec.setGeometry(QRect(0, 0, width, height))
        alarmRec.setToolTip(tooltip)
        alarmRec.setProperty("alarmSensitiveContent", True)
        alarmRec.setProperty("brush", brush)
        alarmRec.setObjectName("alarmRec")
        # alarmRec.setStyleSheet("margin:5px; border:3px solid rgb(0, 0, 0);")

        lblName = QLabel(frame)
        lblName.setGeometry(QRect(width * 0.05, 50, width - width * 0.05, 20))
        font = QFont()
        font.setPointSize(12)
        lblName.setFont(font)
        lblName.setAlignment(Qt.AlignCenter)
        lblName.setText("{}".format(pv_info.DISP))
        lblName.setObjectName("lblName")
        lblName.setToolTip(tooltip)

        lblVal = PyDMLabel(frame)
        lblVal.setGeometry(QRect(width * 0.05, 10, width - width * 0.05, 30))
        font = QFont()
        font.setPointSize(18)
        lblVal.setFont(font)
        lblVal.setToolTip(tooltip)
        lblVal.setAlignment(Qt.AlignCenter)
        lblVal.setProperty("showUnits", False)
        lblVal.setObjectName("lblVal")
        lblVal.channel = "ca://{}".format(pv_info.PV)
        lblVal.precisionFromPV = False
        lblVal.precision = 2
        if self.macros().get("FORMAT", "") == "EXP":
            lblVal.displayFormat = PyDMLabel.DisplayFormat.Exponential
        return frame
示例#24
0
    def __init__(self, parent=None):
        super(VLine, self).__init__(parent)
        self.chartItemFlags = ChartItemFlags.FLAG_NO_AUTO_RANGE

        self._x = None
        self._label = None

        self._pen = QPen(QBrush(Qt.green), 1.0, Qt.SolidLine)
        self._pen.setCosmetic(True)
        self._brush = QBrush(QColor(255, 255, 255, 0))

        finfo = np.finfo(np.float32)
        self.b_rect = QRectF(0, finfo.min / 2.0, 0, finfo.max)
示例#25
0
    def __init__(self,
                 shape: Shape,
                 size: int,
                 key: Optional[int] = None,
                 **kwargs):
        super().__init__()
        self._shape = shape
        self._size = size
        self.key = key
        self.info = kwargs

        self._pen = QPen()
        self._pen.setWidthF(0.25)
        self._brush = QBrush()
示例#26
0
    def update_style(self):

        self.setBackground(QBrush(QColor(CELL_BACKGROUND)))
        if self.style == u'numeric':
            self.setForeground(QBrush(QColor(CELL_NUMERIC_FOREGROUND)))
            self.setTextAlignment(Qt.AlignRight)
        elif self.style == u'text':
            self.setForeground(QBrush(QColor(CELL_TEXT_FOREGROUND)))
            self.setTextAlignment(Qt.AlignLeft)
        elif self.style == u'header':
            self.setTextAlignment(Qt.AlignCenter)
            self.set_header_style()
        else:
            raise ValueError(u'Unknown style: %s' % self.style)
示例#27
0
    def set_value(self, value: List[List[Union[int, float, str]]]):
        self.check_data(value)
        self.ctrl.setRowCount(len(value))
        cols = len(value[0])
        if isinstance(self.foreground_color, str):
            fg = [[self.foreground_color for i in range(cols)]
                  for j in range(len(value))]

        else:
            fg = self.foreground_color
        if isinstance(self.background_color, str):
            bg = [[self.background_color for i in range(cols)]
                  for j in range(len(value))]
        else:
            bg = self.background_color
        for row, row_list in enumerate(value):
            for col, content in enumerate(row_list):
                if len(str(content)) * self.char_width > self.ctrl.columnWidth(
                        col):
                    self.ctrl.setColumnWidth(
                        col,
                        len(str(content)) * self.char_width + 10)
                table_item = QTableWidgetItem(str(content))
                table_item.setTextAlignment(Qt.AlignCenter)
                # 字体颜色(红色)
                if fg[row][col] == '':
                    table_item.setForeground(self.default_fg)
                else:
                    table_item.setForeground(
                        QBrush(QColor(*color_str2tup(fg[row][col]))))

                # 背景颜色(红色)
                if bg[row][col] == '':
                    table_item.setBackground(self.default_bg)
                else:
                    table_item.setBackground(
                        QBrush(QColor(*color_str2tup(bg[row][col]))))
                self.ctrl.setItem(row, col, table_item)

        if self.size_restricted:
            if self.header_adaption_h:
                self.ctrl.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
                scrollbar_area_width = 0
            else:
                self.ctrl.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
                scrollbar_area_width = 10
            self.ctrl.setMaximumHeight((self.ctrl.rowCount() + 1) * 30 +
                                       scrollbar_area_width)
            self.setMaximumHeight((self.ctrl.rowCount() + 1) * 30 +
                                  scrollbar_area_width)
示例#28
0
 def set_resizable(self, resizing):
     # Update the resizer handle appearance and movability based on
     # the specified resizing state.
     if resizing:
         if self._debug:
             if self._anchor in ["B", "T", "R", "L"]:
                 self.setBrush(QBrush(Qt.NoBrush))
             else:
                 self.setBrush(QBrush(Qt.green))
             self.setPen(QPen(Qt.green))
         self.setFlag(self.ItemIsMovable)
     else:
         self.setBrush(QBrush(Qt.NoBrush))
         self.setPen(QPen(Qt.NoPen))
         self.setFlag(self.ItemIsMovable, False)
示例#29
0
    def init_ui(self, history, blockcount):
        self.content_layout = QGridLayout(self)
        self.content_layout.setContentsMargins(0, 0, 0, 0)
        # self.content_layout.setSpacing(0)

        self.input_layout = QGridLayout()
        self.input_layout.setContentsMargins(0, 0, 0, 0)
        self.input_layout.setSpacing(0)

        # display for output
        self.out_display = ConsoleDisplay(blockcount)
        self.content_layout.addWidget(self.out_display, 1, 0, 1, 2)

        # colors to differentiate input, output and stderr
        self.inpfmt = self.out_display.currentCharFormat()
        self.inpfmt.setForeground(
            QBrush(QColor(self.window_theme.colors['primaryColor'])))
        self.outfmt = QTextCharFormat(self.inpfmt)
        self.outfmt.setForeground(
            QBrush(QColor(self.window_theme.colors['secondaryTextColor'])))
        self.errfmt = QTextCharFormat(self.inpfmt)
        self.errfmt.setForeground(
            QBrush(QColor(self.window_theme.colors['danger'])))

        # display input prompt left besides input edit
        self.prompt_label = QLabel('> ', self)
        self.prompt_label.setFixedWidth(15)
        self.input_layout.addWidget(self.prompt_label, 0, 0, 1, 1)
        self.prompt_label.hide()

        # command "text edit" for large code input
        self.inptextedit = ConsoleInputTextEdit(self.window_theme)
        self.input_layout.addWidget(self.inptextedit, 1, 0, 2, 2)
        self.inptextedit.hide()

        # command line
        self.inpedit = ConsoleInputLineEdit(self.inptextedit,
                                            max_history=history)
        self.inpedit.returned.connect(self.push)
        self.input_layout.addWidget(self.inpedit, 0, 1, 1, 1)

        self.content_layout.addLayout(self.input_layout, 2, 0, 1, 2)

        self.interp = None
        self.reset_interpreter()

        self.buffer = []
        self.num_added_object_contexts = 0
示例#30
0
 def drawRoundFrame(self, painter, rect, palette, lineWidth, frameStyle):
     """
     Draw a round frame
     
     :param QPainter painter: Painter
     :param QRectF rect: Target rectangle
     :param QPalette palette: `QPalette.WindowText` is used for plain borders, `QPalette.Dark` and `QPalette.Light` for raised or sunken borders
     :param int lineWidth: Line width
     :param int frameStyle: bitwise OR´ed value of `QFrame.Shape` and `QFrame.Shadow`
     """
     Plain, Sunken, Raised = list(range(3))
     style = Plain
     if (frameStyle & QFrame.Sunken) == QFrame.Sunken:
         style = Sunken
     elif (frameStyle & QFrame.Raised) == QFrame.Raised:
         style = Raised
     lw2 = 0.5 * lineWidth
     r = rect.adjusted(lw2, lw2, -lw2, -lw2)
     if style != Plain:
         c1 = palette.color(QPalette.Light)
         c2 = palette.color(QPalette.Dark)
         if style == Sunken:
             c1, c2 = c2, c1
         gradient = QLinearGradient(r.topLeft(), r.bottomRight())
         gradient.setColorAt(0.0, c1)
         gradient.setColorAt(1.0, c2)
         brush = QBrush(gradient)
     else:
         brush = palette.brush(QPalette.WindowText)
     painter.save()
     painter.setPen(QPen(brush, lineWidth))
     painter.drawEllipse(r)
     painter.restore()
示例#31
0
    def __init__(self, parent=None):
        super(InteractiveVerticalLine, self).__init__(parent)
        self.setFlags(
            QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemSendsGeometryChanges
        )
        self.chartItemFlags = ChartItemFlags.FLAG_NO_AUTO_RANGE
        self.setZValue(1e6)

        self.setAcceptHoverEvents(True)

        self._x = None
        self._label = None

        self._pen = QPen(QBrush(Qt.green), 1.0, Qt.SolidLine)
        self._pen.setCosmetic(True)
        self._brush = QBrush(QColor(255, 255, 255, 0))
示例#32
0
文件: byte.py 项目: slaclab/pydm
 def __init__(self, parent=None, circle=False):
     super(PyDMBitIndicator, self).__init__(parent)
     self.setAutoFillBackground(True)
     self.circle = circle
     self._painter = QPainter()
     self._brush = QBrush(Qt.SolidPattern)
     self._pen = QPen(Qt.SolidLine)