Ejemplo n.º 1
0
class Cell:
    def __init__(self):
        self.style = "background: #646167;"
        self.styleSelected = "background: #30EDD5;"
        self.styleSelectedTrackNormal = "background: #8B878F;"
        self.styleEvaluated = "background: #5B00C3;"

        self.height = 90

        self.nameStyle = "background: rgba(255, 255, 255, 0.1); \
                border: none; \
                color: #343136; \
                selection-background-color: #5B00C3; \
                padding: 0 18px 0 18px; \
                margin: 0;"

        self.nameFont = QFont("Open Sans", 12)
        self.nameFont.setPixelSize(12)
        self.nameHeight = 18

        self.previewStyle = "padding: 5px 9px 9px 9px; \
                margin: 0; \
                border: none; \
                line-height: 14px; \
                color: #E1F0F9;"

        self.previewStyleSelected = "padding: 5px 9px 9px 9px; \
                margin: 0; \
                border: none; \
                line-height: 14px; \
                color: #343136;"

        self.previewFont = QFont("Fira Code", 11)
        self.previewFont.setWeight(QFont.Light)
        self.previewFont.setPixelSize(11)
Ejemplo n.º 2
0
    def __init__(
        self,
        rank,
        suit,
    ):
        super().__init__()

        font = QFont()
        font.setPixelSize(20)

        layout = QVBoxLayout(self)
        rank_label = QLabel(self)
        rank_label.setText(rank)
        rank_label.setFont(font)
        rank_label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        layout.addWidget(rank_label)

        suit_pixmap = QPixmap(f'./images/{suit}.svg')
        suit_label = QLabel()
        suit_label.setPixmap(suit_pixmap)
        h = suit_label.height()

        suit_label.setPixmap(
            suit_pixmap.scaled(h * 1.5, h / 5, Qt.KeepAspectRatio))
        suit_label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        layout.addWidget(suit_label)
Ejemplo n.º 3
0
 def __init__(self,
              parent=None,
              command="/bin/bash",
              font_name="Monospace",
              font_size=18):
     super(TerminalWidget, self).__init__(parent)
     self.parent().setTabOrder(self, self)
     self.setFocusPolicy(Qt.WheelFocus)
     self.setAutoFillBackground(False)
     self.setAttribute(Qt.WA_OpaquePaintEvent, True)
     self.setCursor(Qt.IBeamCursor)
     font = QFont(font_name)
     font.setPixelSize(font_size)
     self.setFont(font)
     self._session = None
     self._last_update = None
     self._screen = []
     self._text = []
     self._cursor_rect = None
     self._cursor_col = 0
     self._cursor_row = 0
     self._dirty = False
     self._blink = False
     self._press_pos = None
     self._selection = None
     self._clipboard = QApplication.clipboard()
     QApplication.instance().lastWindowClosed.connect(Session.close_all)
     if command:
         self.execute()
Ejemplo n.º 4
0
class CharIconEngine(TransparentIconEngine):
    """Specialization of QIconEngine used to draw font-based icons."""

    def __init__(self, char, color=None):
        """
        Args:
            char (str): character to use as the icon
            color (QColor, optional):
        """
        super().__init__()
        self.char = char
        self.color = color
        self.font = QFont('Font Awesome 5 Free Solid')

    def paint(self, painter, rect, mode=None, state=None):
        painter.save()
        size = 0.875 * round(min(rect.width(), rect.height()))
        self.font.setPixelSize(size)
        painter.setFont(self.font)
        if self.color:
            color = self.color
        else:
            palette = QPalette(QApplication.palette())
            if mode == QIcon.Disabled:
                palette.setCurrentColorGroup(QPalette.Disabled)
            elif mode == QIcon.Active:
                palette.setCurrentColorGroup(QPalette.Active)
            color = palette.buttonText().color()
        painter.setPen(color)
        painter.drawText(rect, Qt.AlignCenter | Qt.AlignVCenter, self.char)
        painter.restore()
Ejemplo n.º 5
0
    def __init__(self, pixmap):
        super(SplashScreen, self).__init__(pixmap)

        self._title = QLabel(self)
        self._title.setGeometry(50 * self.width() / 100,
                                20 * self.height() / 100,
                                50 * self.width() / 100,
                                11 * self.height() / 100)
        self._title.setStyleSheet('QLabel { color : rgb(191,180,110); }')
        font = QFont('Exo 2')
        font.setPixelSize(36)
        font.setBold(True)
        font.setItalic(True)
        self._title.setFont(font)

        font = QFont('Exo 2')
        font.setPixelSize(16)
        font.setBold(False)
        font.setItalic(True)
        self.setFont(font)

        self.progressBar = QProgressBar(self)
        self.progressBar.setGeometry(self.width() / 10, 8 * self.height() / 10,
                                     8 * self.width() / 10,
                                     self.height() / 30)
    def __init__(self, parent_item, src_item, dst_item, duration=2000):
        """Initializes animation stuff.

        Args:
            parent_item (QGraphicsItem): The item on top of which the animation should play.
            src_item (QGraphicsItem): The source item.
            dst_item (QGraphicsItem): The destination item.
            duration (int. optional): The desired duration of each loop in milliseconds, defaults to 1000.
        """
        self._parent_item = parent_item
        self.src_item = src_item
        self.dst_item = dst_item
        font = QFont('Font Awesome 5 Free Solid')
        size = 0.875 * round(parent_item.rect().height() / 2)
        font.setPixelSize(size)
        self.src_item.setFont(font)
        self.dst_item.setFont(font)
        self.src_opacity_effect = QGraphicsOpacityEffect()
        self.src_item.setGraphicsEffect(self.src_opacity_effect)
        self.dst_opacity_effect = QGraphicsOpacityEffect()
        self.dst_item.setGraphicsEffect(self.dst_opacity_effect)
        self.timer = QTimeLine()
        self.timer.setLoopCount(0)  # loop forever
        self.timer.setFrameRange(0, 10)
        self.timer.valueChanged.connect(self._handle_timer_value_changed)
        self.timer.setDuration(duration)
        self.src_animation = QGraphicsItemAnimation()
        self.src_animation.setItem(self.src_item)
        self.src_animation.setTimeLine(self.timer)
        self.dst_animation = QGraphicsItemAnimation()
        self.dst_animation.setItem(self.dst_item)
        self.dst_animation.setTimeLine(self.timer)
Ejemplo n.º 7
0
class CharIconEngine(QIconEngine):
    """Specialization of QIconEngine used to draw font-based icons."""
    def __init__(self, char, color=None):
        super().__init__()
        self.char = char
        self.color = color
        self.font = QFont('Font Awesome 5 Free Solid')

    def paint(self, painter, rect, mode=None, state=None):
        painter.save()
        size = 0.875 * round(rect.height())
        self.font.setPixelSize(size)
        painter.setFont(self.font)
        if self.color:
            color = self.color
        else:
            palette = QPalette(QApplication.palette())
            if mode == QIcon.Disabled:
                palette.setCurrentColorGroup(QPalette.Disabled)
            elif mode == QIcon.Active:
                palette.setCurrentColorGroup(QPalette.Active)
            color = palette.buttonText().color()
        painter.setPen(color)
        painter.drawText(rect, Qt.AlignCenter | Qt.AlignVCenter, self.char)
        painter.restore()

    def pixmap(self, size=QSize(512, 512), mode=None, state=None):
        pm = QPixmap(size)
        pm.fill(Qt.transparent)
        self.paint(QPainter(pm), QRect(QPoint(0, 0), size), mode, state)
        return pm
Ejemplo n.º 8
0
class ContextMenu:
    def __init__(self):
        self.style = """
            QMenu {
                background-color: rgba(0, 0, 0, 0.6);
                font-family: Open Sans;
                font-size: 13px;
            }

            QMenu::item {
                color: #D9EBF5;
            }

            QMenu::item:selected {
                color: #322F35;
                background: #D9EBF5;
            }

            QMenu::separator {
                height: 2px;
                background: rgba(255, 255, 255, 0.14);
                margin: 9px;
            }
        """
        self.font = QFont("Open Sans", 12)
        self.font.setPixelSize(12)
Ejemplo n.º 9
0
class Console:
    def __init__(self):
        self.style = "background-color: #242127; margin: 0; padding: 0; selection-background-color: #5B00C3;"
        self.stdoutFontColor = QColor(255, 246, 255)
        self.stderrFontColor = QColor(206, 24, 1)
        self.font = QFont("Fira Code", 12)
        self.font.setPixelSize(12)
        self.font.setWeight(QFont.Thin)
Ejemplo n.º 10
0
 def __create_title(self):
     self.title = QLabel()
     self.title.setAlignment(Qt.AlignCenter)
     font = QFont()
     font.setPixelSize(17)
     self.title.setFont(font)
     self.title.setStyleSheet(
         'padding: 12px; border: 1px solid #212121; border-radius: 10px;')
Ejemplo n.º 11
0
class Text(QWidget):
    def __init__(self, parent, config):
        super(Text, self).__init__(parent)

        self.config = config
        self.value = config["min"]

        self.font = QFont()
        self.note_font = QFont()
        self.color = QColor(config["color"])
        self.red_color = QColor(config["redline_color"])
        self.no_color = QColor()
        self.no_color.setAlpha(0)

        self.brush = QBrush(self.color)
        self.red_brush = QBrush(self.red_color)

        self.pen = QPen(self.color)
        self.red_pen = QPen(self.red_color)
        self.no_pen = QPen(self.no_color)

        self.font.setPixelSize(self.config["font_size"])
        self.note_font.setPixelSize(self.config["note_font_size"])
        self.pen.setWidth(3)
        self.red_pen.setWidth(3)

        self.red_value = config["redline"]
        if self.red_value is None:
            self.red_value = config["max"]

    def sizeHint(self):
        return QSize(300, 75)

    def render(self, response):
        self.value = response.value.magnitude
        self.update()

    def paintEvent(self, e):
        painter = QPainter()
        painter.begin(self)

        self.t_height = self.config["font_size"] + 8

        painter.setFont(self.font)
        painter.setPen(self.pen)
        painter.setRenderHint(QPainter.Antialiasing)

        h = 0

        if len(self.config["title"]) > 0:
            h += self.t_height
            r = QRect(0, 0, self.width(), self.t_height)
            painter.drawText(r, Qt.AlignVCenter, self.config["title"])

        r = QRect(0, h, self.width(), self.t_height)
        painter.drawText(r, Qt.AlignCenter, str(int(round(self.value))))

        painter.end()
Ejemplo n.º 12
0
    def drawHeader(self):
        """Draw logo/copyright in the header"""
        pHeight = 90
        pMargin = 15
        icon_path = cm.DIR_ICONS + "app.png"

        self.header_lbl.setMinimumHeight(pHeight)
        self.header_lbl.setFrameShape(QFrame.StyledPanel)
        self.header_lbl.setContentsMargins(0, 0, 0, 0)

        pixmap = QPixmap(450, pHeight)
        pixmap.fill(Qt.transparent)

        iconY = (pHeight - 64) / 2
        logoRect = QRect(pMargin, iconY, 64, 64)

        painter = QPainter(pixmap)
        painter.setBrush(QBrush(Qt.red))
        painter.drawPixmap(
            logoRect,
            QPixmap(icon_path).scaled(
                logoRect.width(),
                logoRect.height(),
                Qt.KeepAspectRatio,
                Qt.SmoothTransformation,
            ),
        )

        titleRect = QRect(logoRect.right() + 10, iconY, 200, pHeight)

        font = QFont()
        font.setBold(True)
        font.setPixelSize(16)
        painter.setFont(font)
        painter.setPen(QPen(QApplication.instance().palette().text().color()))
        painter.drawText(titleRect, Qt.AlignTop, "Cutevariant")

        font_metrics = QFontMetrics(font)
        font.setBold(False)
        font.setPixelSize(12)
        painter.setFont(font)
        painter.setPen(QPen(Qt.darkGray))
        titleRect.setY(titleRect.y() + font_metrics.height())

        painter.drawText(
            titleRect,
            Qt.AlignTop,
            f"Version %s\nGPL3 Copyright (C) 2018-2020\nLabsquare.org" % __version__,
        )

        self.header_lbl.setPixmap(pixmap)

        # Painting is finished !
        # Avoid Segfault:
        # QPaintDevice: Cannot destroy paint device that is being painted
        painter.end()
Ejemplo n.º 13
0
        def use_qchart():
            # Creating QChart
            self.chart = QtCharts.QChart()
            self.chart.setAnimationOptions(QtCharts.QChart.AllAnimations)

            font = QFont()
            font.setPixelSize(20)
            self.chart.setTitleFont(font)

            self.add_series("Amplitude (mV)")
            self.chart_view.setChart(self.chart)
Ejemplo n.º 14
0
class TrackHeader:
    def __init__(self):
        self.style = "background: #3D3B40;"
        self.styleSelected = "background: #0059FB;"
        self.height = 72

        self.backendNameFont = QFont("Open Sans", 13)
        self.backendNameFont.setPixelSize(13)
        self.backendNameFont.setWeight(QFont.DemiBold)
        self.backendNameStyle = "color: #D9EBF5;"

        self.userNameFont = QFont("Open Sans", 12)
        self.userNameFont.setPixelSize(12)
        self.userNameStyle = "color: #D9EBF5; \
Ejemplo n.º 15
0
    def __init__(self,
                 item,
                 duration=2000,
                 count=5,
                 percentage_size=0.24,
                 x_shift=0):
        """Initializes animation stuff.

        Args:
            item (QGraphicsItem): The item on top of which the animation should play.
        """
        self._item = item
        self.cubes = [QGraphicsTextItem("\uf1b2", item) for i in range(count)]
        self.opacity_at_value_path = QPainterPath(QPointF(0.0, 0.0))
        self.opacity_at_value_path.lineTo(QPointF(0.01, 1.0))
        self.opacity_at_value_path.lineTo(QPointF(0.5, 1.0))
        self.opacity_at_value_path.lineTo(QPointF(1.0, 0.0))
        self.time_line = QTimeLine()
        self.time_line.setLoopCount(0)  # loop forever
        self.time_line.setFrameRange(0, 10)
        self.time_line.setDuration(duration)
        self.time_line.setCurveShape(QTimeLine.LinearCurve)
        self.time_line.valueChanged.connect(
            self._handle_time_line_value_changed)
        self.time_line.stateChanged.connect(
            self._handle_time_line_state_changed)
        font = QFont('Font Awesome 5 Free Solid')
        item_rect = item.rect()
        cube_size = percentage_size * 0.875 * item_rect.height()
        font.setPixelSize(cube_size)
        rect = item_rect.translated(-0.5 * cube_size + x_shift, -cube_size)
        end = rect.center()
        ctrl = end - QPointF(0, 0.6 * rect.height())
        lower, upper = 0.2, 0.8
        starts = [lower + i * (upper - lower) / count for i in range(count)]
        starts = [
            rect.topLeft() + QPointF(start * rect.width(), 0)
            for start in starts
        ]
        self.paths = [QPainterPath(start) for start in starts]
        for path in self.paths:
            path.quadTo(ctrl, end)
        self.offsets = [i / count for i in range(count)]
        for cube in self.cubes:
            cube.setFont(font)
            cube.setDefaultTextColor("#003333")
            cube.setTransformOriginPoint(cube.boundingRect().center())
            cube.hide()
            cube.setOpacity(0)
Ejemplo n.º 16
0
 def createDropTextPixmap(self):
     pixmap = QPixmap(481, 300)
     pixmap.fill(QColor("#333333"))
     painter = QPainter(pixmap)
     font = QFont("Arial")
     font.setPixelSize(28)
     font.setBold(True)
     fm = QFontMetrics(font)
     painter.setFont(font)
     painter.setPen(QPen(QColor("#888888"), 1))
     text = "Drop the tileset image here"
     x = (pixmap.width()-fm.width(text))/2
     y = (pixmap.height()+fm.height())/2
     painter.drawText(x, y, text)
     del painter
     return pixmap
Ejemplo n.º 17
0
    def drawText(self, p, innerRect, innerRadius, value):
        if not self.format:
            return

        text = self.valueToText(value)

        # !!! to revise
        # f = self.font()
        f = QFont()
        f.setFamily("微軟正黑體")
        # f.setPixelSize(innerRadius * max(0.05, (0.35 - self.decimals * 0.08)))
        f.setPixelSize(60)
        p.setFont(f)

        textRect = innerRect
        p.setPen(self.palette().text().color())
        p.drawText(textRect, Qt.AlignCenter, text)
Ejemplo n.º 18
0
class TemplateInfo:
    def __init__(self):
        self.style = "background-color: #272629; margin: 0; padding: 0;"
        self.height = 204
        self.width = 216

        self.headerFont = QFont("Open Sans", 15)
        self.headerFont.setPixelSize(15)
        self.headerFont.setWeight(QFont.Light)
        self.headerFont.setItalic(True)
        self.headerStyle = "margin: 13px 9px 18px 9px; color: #4C4452;"

        self.textAreaStyle = "background-color: #272629; margin: 0 0 18px 9px; selection-background-color: #5B00C3;"
        self.textAreaFont = QFont("Open Sans", 13)
        self.textAreaFont.setPixelSize(13)
        self.textAreaFont.setWeight(QFont.Normal)
        self.textAreaFontColor = QColor(218, 214, 222)
Ejemplo n.º 19
0
def get_font(font_spec):
    # type: (FontSpec) -> QFont
    """Gets and if necessary caches QFont closest to the required params.

    :param font_spec: defines a font in terms of face/family and size
    :return: a :class:`QFont` that can be used for example by a :class:`QPainter`
    """
    if font_spec in FontManager.FONT_CACHE:
        return FontManager.FONT_CACHE[font_spec]

    _check_is_valid_font(font_spec)
    font = QFont()
    font.setPixelSize(font_spec.size)
    real_face = FontManager.REAL_FONT_FACES[FontFace(font_spec.face)]
    font.setFamily(real_face)
    FontManager.FONT_CACHE[font_spec] = font
    FontManager.METRICS_CACHE[font_spec] = QFontMetrics(font)
    return font
Ejemplo n.º 20
0
    def buildLabels(self, label):
        self.label = QLabel(label)
        self.data = QLabel(constants.DEFAULT_LABEL)

        # Center the text in the labels
        self.label.setAlignment(Qt.AlignCenter)
        self.data.setAlignment(Qt.AlignCenter)

        # Bold the label label
        labelFont = QFont()
        labelFont.setBold(True)

        # Make the data label font obnoxiously large
        dataFont = QFont()
        dataFont.setPixelSize(20)

        self.label.setFont(labelFont)
        self.data.setFont(dataFont)
Ejemplo n.º 21
0
    def __init__(self, parent, fn, *args):
        super(LoadingBar, self).__init__(parent)

        self.fn = fn
        self.args = args
        self.worker = Worker(fn, *args)
        self.worker.signals.result.connect(
            main_window.MainWindow.get_instance().calc_done)

        main_window.MainWindow.get_instance().threadpool.start(self.worker)

        # overlay
        # make the window frameless
        self.loading_icon = QSvgRenderer('resources/images/loading_icon.svg')
        self.qp = QPainter()

        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)

        self.fillColor = QColor(30, 30, 30, 120)
        self.penColor = QColor("#333333")

        self.close_btn = QPushButton(self)
        self.close_btn.setText("Abbrechen")

        font = QFont()
        font.setPixelSize(18)
        font.setBold(True)
        self.close_btn.setFont(font)
        self.close_btn.setStyleSheet("QPushButton {"
                                     "background-color: #EAEAEA;"
                                     "border: None;"
                                     "padding-top: 12px;"
                                     "padding-bottom: 12px;"
                                     "padding-left: 20px;"
                                     "padding-right: 20px;"
                                     "}"
                                     "QPushButton:hover {"
                                     "background-color: #DFDFDF;"
                                     "}")
        #self.close_btn.setFixedSize(30, 30)
        self.close_btn.clicked.connect(self._onclose)

        self.signals = LoadingBarSignals()
Ejemplo n.º 22
0
def add_label(context, text="", size="12", bold=False, alignment="left"):
    font = QFont()
    font.setPixelSize(int(size))
    if bold == "true":
        font.setBold(True)
    widget = QLabel()
    widget.setText(text)

    if alignment == "left":
        widget.setAlignment(Qt.AlignLeft)
    elif alignment == "right":
        widget.setAlignment(Qt.AlignRight)
    elif alignment == "center":
        widget.setAlignment(Qt.AlignCenter)

    widget.setWordWrap(True)
    widget.setFont(font)
    widget.setTextInteractionFlags(Qt.TextSelectableByMouse)
    context.ui.WebBodyLayout.addWidget(widget)
Ejemplo n.º 23
0
    def setup_widget(self):
        self.total_time_label = QLabel("00:00:00", self)
        self.exercise_time_label = QLabel("00:00:00", self)

        font = QFont(self.total_time_label.font())
        font.setPixelSize(48)
        self.total_time_label.setFont(font)
        self.exercise_time_label.setFont(font)

        self.exercise_name_label = QLabel(self)
        self.exercise_name_label.setAlignment(Qt.AlignCenter)
        self.exercise_description_label = QLabel(self)
        self.exercise_description_label.setAlignment(Qt.AlignCenter)

        font = QFont(self.exercise_name_label.font())
        font.setPixelSize(18)
        self.exercise_name_label.setFont(font)
        self.exercise_description_label.setFont(font)
        self.exercise_description_label.setWordWrap(True)
Ejemplo n.º 24
0
class MenuBar:
    def __init__(self):
        self.style = """
            QMenuBar {
                background-color: #272629;
                border: none;
            }

            QMenuBar::item {
                spacing: 18px;
                padding: 1px 9px;
                background: transparent;
                color: #DAD6DE;
            }

            QMenuBar::item:selected { /* when selected using mouse or keyboard */
                background: #DAD6DE;
                color: #272629;
            }

            QMenu {
                background-color: rgba(0, 0, 0, 0.6);
                font-family: Open Sans;
                font-size: 13px;
            }

            QMenu::item {
                color: #DAD6DE;
            }

            QMenu::item:selected {
                color: #322F35;
                background: #DAD6DE;
            }

            QMenu::separator {
                height: 2px;
                background: rgba(255, 255, 255, 0.14);
                margin: 9px;
            }
        """
        self.font = QFont("Open Sans", 13)
        self.font.setPixelSize(13)
Ejemplo n.º 25
0
class TemplateEditor:
    def __init__(self):
        self.style = """
            QWidget {
                background: #272629;
            }

            QWidget QLabel {
                font-family: \"Open Sans\";
                font-size: 12px;
                color: #DAD6DE;
            }
        """
        self.inputStyle = "background: rgba(255, 255, 255, 0.1); \
                border: none; \
                color: #DAD6DE; \
                selection-background-color: #5B00C3;"

        self.inputHeight = 18
        self.inputCodeFont = QFont("Fira Code", 11)
        self.inputCodeFont.setPixelSize(11)
        self.inputCodeFont.setWeight(QFont.Light)
        self.inputFont = QFont("Open Sans", 12)
        self.inputFont.setPixelSize(12)

        self.descriptionStyle = "background: #19181B; \
                border: none; \
                color: #DAD6DE; \
                selection-background-color: #5B00C3;"

        self.descriptionFont = QFont("Open Sans", 12)
        self.descriptionFont.setPixelSize(12)
Ejemplo n.º 26
0
class CharIconEngine(QIconEngine):
    """Specialization of QIconEngine used to draw font-based icons."""
    def __init__(self, char, color):
        super().__init__()
        self.char = char
        self.color = color
        self.font = QFont('Font Awesome 5 Free Solid')

    def paint(self, painter, rect, mode=None, state=None):
        painter.save()
        size = 0.875 * round(rect.height())
        self.font.setPixelSize(size)
        painter.setFont(self.font)
        painter.setPen(QColor(self.color))
        painter.drawText(rect, Qt.AlignCenter | Qt.AlignVCenter, self.char)
        painter.restore()

    def pixmap(self, size, mode=None, state=None):
        pm = QPixmap(size)
        pm.fill(Qt.transparent)
        self.paint(QPainter(pm), QRect(QPoint(0, 0), size), mode, state)
        return pm
Ejemplo n.º 27
0
    def update_view(self, text=''):
        text = text.lower()
        for i in reversed(range(self.list_layout.count())):
            self.list_layout.itemAt(i).widget().setParent(None)

        self.current_nodes.clear()
        self.all_current_node_widgets.clear()

        self.node_widget_index_counter = 0

        # select valid elements from text
        # nodes
        nodes_names_dict = {}
        for n in self.nodes:
            nodes_names_dict[n] = n.title.lower()
        sorted_indices = self.get_sorted_dict_matching_search(
            nodes_names_dict, text)
        for n, index in sorted_indices.items():
            self.current_nodes.append(n)

        # nodes
        if len(self.current_nodes) > 0:
            nodes_label = QLabel('Hover for description')
            nodes_label_font = QFont('Poppins')
            nodes_label_font.setPixelSize(15)
            nodes_label.setStyleSheet('color: #9bbf9dff; border: none;')
            nodes_label.setFont(nodes_label_font)
            self.list_layout.addWidget(nodes_label)

            for n in self.current_nodes:
                node_widget = self.create_list_item_widget(n)
                self.list_layout.addWidget(node_widget)
                self.all_current_node_widgets.append(node_widget)

        if len(self.all_current_node_widgets) > 0:
            self.set_active_node_widget_index(0)
Ejemplo n.º 28
0
class BrowserItem:
    def __init__(self):
        self.size = QSize(216, 108)

        self.headerFont = QFont("Open Sans", 13)
        self.headerFont.setPixelSize(13)
        self.headerFont.setWeight(QFont.DemiBold)
        self.headerStyle = "margin-left: 18px; margin-right: 9px; color: #DAD6DE;"
        self.headerStyleSelected = "margin-left: 18px; margin-right: 9px; color: #30EDD5;"

        self.commandFont = QFont("Fira Code", 11)
        self.commandFont.setPixelSize(11)
        self.commandFont.setWeight(QFont.Light)
        self.commandStyle = "margin-left: 18px; margin-right: 9px; color: #DAD6DE;"
        self.commandStyleSelected = "margin-left: 18px; margin-right: 9px; color: #30EDD5;"

        self.descriptionFont = QFont("Open Sans", 12)
        self.descriptionFont.setPixelSize(12)
        self.descriptionStyle = "margin-left: 9px; margin-right: 9px; color: rgba(218, 214, 222, 0.4);"
        self.descriptionStyleSelected = "margin-left: 9px; margin-right: 9px; color: rgba(48, 237, 213, 0.4);"
Ejemplo n.º 29
0
 def __font_width(size, family, text):
     font = QFont()
     font.setPixelSize(size)
     font.setFamily(family)
     metrics = QFontMetrics(font)
     return metrics.boundingRect(text).width()
Ejemplo n.º 30
0
    def paintEvent(self, event):
        """
        Draws the desks and students' names given the self.tiles list
        """
        painter = QPainter(self)
        color = AssetManager.getInstance().config(
            'colors', 'room_grid') if self.__is_config else "white"

        pen = QPen()
        pen.setColor(QColor(color))
        pen.setWidth(2)
        painter.setPen(pen)

        # Draw the grid
        for r in range(self.nb_rows):
            painter.drawLine(
                QPoint(0, r * self.desk_h_size),
                QPoint(self.desk_w_size * self.nb_columns,
                       r * self.desk_h_size))

        for c in range(self.nb_columns):
            painter.drawLine(
                QPoint(c * self.desk_w_size, 0),
                QPoint(c * self.desk_w_size, self.desk_h_size * self.nb_rows))

        # Update painter color and font size for tiles
        pen.setColor(
            QColor(AssetManager.getInstance().config('colors', 'tile_text')))
        painter.setPen(pen)

        font = QFont()
        font.setPixelSize(
            int(AssetManager.getInstance().config('size', 'font_size')))
        painter.setFont(font)

        # Current tile selected by the mouse
        tile_selected_pos = self.__convert_point(
            self.__mouse_pos[0],
            self.__mouse_pos[1]) if self.__mouse_pos else None
        tile_selected = None
        self.hovered = False

        # Drawing of all the tiles
        for t in list(self.__tiles.values()):
            y, x = self.__relative_mouse_position(t.real_position())
            if self.__relative_grid_position(
                    t.grid_position()
            ) == self.__click_pos and self.__is_config:  # If the tile is selected
                tile_selected = t
                color = QColor(AssetManager.getInstance().config(
                    'colors', 'drag_selected_tile'))
            elif self.__relative_grid_position(
                    t.grid_position()
            ) == tile_selected_pos and self.__is_config:  # If the mouse is hover
                self.hovered = True
                color = QColor(AssetManager.getInstance().config(
                    'colors', 'hovered_tile'))
            elif t.is_selected():
                color = QColor(AssetManager.getInstance().config(
                    'colors', 'selected_tile'))
            else:  # Regular tile
                color = QColor(AssetManager.getInstance().config(
                    'colors', 'tile'))
            rect = self.__get_rect_at(y, x)
            painter.fillRect(rect, color)
            painter.drawText(rect, Qt.AlignCenter | Qt.TextWordWrap,
                             f"{t.lastname()}\n{t.firstname()}")

        # Dragged tile
        if self.__click_pos != self.__relative_grid_position(tile_selected_pos) \
                and tile_selected and self.__mouse_pos and self.__is_config:
            # If the mouse is no longer hover the clicked tile we draw the dragged tile
            self.__draw_dragged_tile(painter, tile_selected,
                                     self.__mouse_pos[0], self.__mouse_pos[1])
Ejemplo n.º 31
0
class GL_Gauge(QOpenGLWidget):
    def __init__(self, parent, config):
        super(GL_Gauge, self).__init__(parent)

        self.config = config

        self.value = config["min"]

        self.font = QFont()
        self.note_font = QFont()
        self.color = QColor(config["color"])
        self.red_color = QColor(config["redline_color"])
        self.indicator_color = QColor(config["indicator_color"])

        self.brush = QBrush(self.color)
        self.indicator_brush = QBrush(self.indicator_color)

        self.pen = QPen(self.color)
        self.red_pen = QPen(self.red_color)
        self.indicator_pen = QPen(self.indicator_color)

        self.font.setPixelSize(self.config["font_size"])
        self.note_font.setPixelSize(self.config["note_font_size"])

        self.pen.setWidth(3)
        self.red_pen.setWidth(3)
        self.indicator_pen.setWidth(3)

        s = scale(config["min"], config["max"], config["scale_step"])

        self.angles = map_scale(s, 0, 270)
        self.str_scale, self.multiplier = str_scale(s, config["scale_mult"])

        self.red_angle = 270
        if config["redline"] is not None:
            self.red_angle = map_value(config["redline"], config["min"],
                                       config["max"], 0, 270)

        #self.initializeGL()
        self.resizeGL(config['w'], config['h'])
        #self.PartialUpdate     #self.setFormat('OpenGLES')

    def render(self, response):
        # approach the value
        self.value += (response.value.magnitude - self.value) / 8
        self.update()

    def sizeHint(self):
        return QSize(350, 300)

    def paintGL(self):

        r = min(self.width(), self.height()) / 2
        self.__text_r = r - (r / 10)  # radius of the text
        self.__tick_r = r - (r / 4)  # outer radius of the tick marks
        self.__tick_l = (r / 10)  # length of each tick, extending inwards
        self.__needle_l = (r / 5) * 3.5  # length of the needle

        painter = QPainter()
        painter.begin(self)

        painter.setFont(self.font)
        painter.setPen(self.pen)
        painter.setBrush(self.brush)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setRenderHint(QPainter.TextAntialiasing)

        self.draw_title(painter)
        if self.config["numerals"]:
            self.draw_multiplier(painter)
            self.draw_numbers(painter)
        self.draw_marks(painter)
        self.draw_needle(painter)
        painter.end()

    def draw_marks(self, painter):

        painter.save()

        painter.translate(self.width() / 2, self.height() / 2)

        # draw the ticks

        end = self.__tick_r - self.__tick_l

        for a in self.angles:
            painter.save()
            painter.rotate(90 + 45 + a)

            if a > self.red_angle:
                painter.setPen(self.red_pen)

            painter.drawLine(self.__tick_r, 0, end, 0)
            painter.restore()

        # draw the arc

        p = -self.__tick_r
        d = 2 * self.__tick_r
        r = QRect(p, p, d, d)

        # arc angles are in 16th of degrees
        s = -(90 + 45) * 16
        l = -self.red_angle * 16
        painter.drawArc(r, s, l)

        painter.setPen(self.red_pen)

        s += l
        l = -(270 - self.red_angle) * 16
        painter.drawArc(r, s, l)

        painter.restore()

    def draw_numbers(self, painter):

        for a, v in zip(self.angles, self.str_scale):
            painter.save()

            if a > self.red_angle:
                painter.setPen(self.red_pen)

            painter.translate(self.width() / 2, self.height() / 2)

            painter.rotate(a)
            painter.rotate(-45)
            painter.translate(-self.__text_r, 0)
            painter.rotate(45)
            painter.rotate(-a)

            r_width = self.config["font_size"] * len(v)
            r_height = self.config["font_size"]

            r = QRect(-r_width / 2, -r_height / 2, r_width, r_height)
            painter.drawText(r, Qt.AlignHCenter | Qt.AlignVCenter, v)

            painter.restore()

    def draw_needle(self, painter):

        painter.setBrush(self.indicator_brush)
        painter.setPen(self.indicator_pen)

        painter.save()
        painter.translate(self.width() / 2, self.height() / 2)
        angle = map_value(self.value, self.config["min"], self.config["max"],
                          0, 270)
        angle = min(angle, 270)
        angle -= 90 + 45
        painter.rotate(angle)
        painter.drawEllipse(QPoint(0, 0), 5, 5)
        painter.drawPolygon(
            QPolygon([
                QPoint(-5, 0),
                QPoint(0, -self.__needle_l),
                QPoint(5, 0),
                QPoint(-5, 0)
            ]))
        painter.restore()

    def draw_title(self, painter):
        painter.save()

        r_height = self.config["font_size"] + 20
        r = QRect(0, self.height() - r_height, self.width(), r_height)
        painter.drawText(r, Qt.AlignHCenter | Qt.AlignVCenter,
                         self.config["title"])

        painter.restore()

    def draw_multiplier(self, painter):
        if self.multiplier > 1:
            painter.save()

            painter.setFont(self.note_font)
            s = "x" + str(self.multiplier)
            r = QRect(0, -self.width() / 6, self.width(), self.height())
            painter.drawText(r, Qt.AlignHCenter | Qt.AlignVCenter, s)

            painter.restore()