Ejemplo n.º 1
0
 def paint(self, painter, option, widget=None):
     rect = self.rect()
     if self.isSelected():
         option.state ^= QStyle.State_Selected
     font = self.document().defaultFont()
     painter.setFont(font)
     if self.parent:
         draw_text = self.node_inst.description
         if self.parent.x() > self.x():  # node is to the left
             fm = QFontMetrics(font)
             x = rect.width() / 2 - fm.width(draw_text) - 4
         else:
             x = rect.width() / 2 + 4
         painter.drawText(QPointF(x, -self.line_descent - 1), draw_text)
     painter.save()
     painter.setBrush(self.backgroundBrush)
     painter.setPen(QPen(Qt.black, 3 if self.isSelected() else 0))
     adjrect = rect.adjusted(-3, 0, 0, 0)
     if not self.node_inst.children:
         painter.drawRoundedRect(adjrect, 4, 4)
     else:
         painter.drawRect(adjrect)
     painter.restore()
     painter.setClipRect(rect)
     return QGraphicsTextItem.paint(self, painter, option, widget)
Ejemplo n.º 2
0
 def __naturalsh(self):
     fm = QFontMetrics(self.font())
     spacing = self.__spacing
     N = len(self.__items)
     width = max((fm.width(text) for text in self.__items),
                 default=0)
     height = N * fm.height() + (N - 1) * spacing
     return QSizeF(width, height)
Ejemplo n.º 3
0
 def update_contents(self):
     self.prepareGeometryChange()
     self.setTextWidth(-1)
     self.setTextWidth(self.document().idealWidth())
     self.droplet.setPos(self.rect().center().x(), self.rect().height())
     self.droplet.setVisible(bool(self.branches))
     fm = QFontMetrics(self.document().defaultFont())
     attr = self.node_inst.attr
     self.attr_text_w = fm.width(attr.name if attr else "")
     self.attr_text_h = fm.lineSpacing()
     self.line_descent = fm.descent()
     if self.pie is not None:
         self.pie.setPos(self.rect().right(), self.rect().center().y())
Ejemplo n.º 4
0
 def update_contents(self):
     self.prepareGeometryChange()
     self.setTextWidth(-1)
     self.setTextWidth(self.document().idealWidth())
     self.droplet.setPos(self.rect().center().x(), self.rect().height())
     self.droplet.setVisible(bool(self.branches))
     fm = QFontMetrics(self.document().defaultFont())
     attr = self.tree_adapter.attribute(self.node_inst)
     self.attr_text_w = fm.width(attr.name if attr else "")
     self.attr_text_h = fm.lineSpacing()
     self.line_descent = fm.descent()
     if self.pie is not None:
         self.pie.setPos(self.rect().right(), self.rect().center().y())
Ejemplo n.º 5
0
    def _update_points_labels(self):
        if self.plotdata.points is None:
            return
        for point_label in self.plotdata.point_labels:
            self.graph.plot_widget.removeItem(point_label)
        self.plotdata.point_labels = []
        sx, sy = self.graph.view_box.viewPixelSize()

        for row in self.plotdata.points:
            ti = TextItem()
            metrics = QFontMetrics(ti.textItem.font())
            text_width = ((RANGE.width())/2. - np.abs(row[0])) / sx
            name = row[2].name
            ti.setText(name)
            ti.setTextWidth(text_width)
            ti.setColor(QColor(0, 0, 0))
            br = ti.boundingRect()
            width = metrics.width(name) if metrics.width(name) < br.width() else br.width()
            width = sx * (width + 5)
            height = sy * br.height()
            ti.setPos(row[0] - (row[0] < 0) * width, row[1] + (row[1] > 0) * height)
            self.plotdata.point_labels.append(ti)
            self.graph.plot_widget.addItem(ti)
Ejemplo n.º 6
0
    def _update_points_labels(self):
        if self.plotdata.points is None:
            return
        for point_label in self.plotdata.point_labels:
            self.graph.plot_widget.removeItem(point_label)
        self.plotdata.point_labels = []
        sx, sy = self.graph.view_box.viewPixelSize()

        for row in self.plotdata.points:
            ti = TextItem()
            metrics = QFontMetrics(ti.textItem.font())
            text_width = ((RANGE.width())/2. - np.abs(row[0])) / sx
            name = row[2].name
            ti.setText(name)
            ti.setTextWidth(text_width)
            ti.setColor(QColor(0, 0, 0))
            br = ti.boundingRect()
            width = metrics.width(name) if metrics.width(name) < br.width() else br.width()
            width = sx * (width + 5)
            height = sy * br.height()
            ti.setPos(row[0] - (row[0] < 0) * width, row[1] + (row[1] > 0) * height)
            self.plotdata.point_labels.append(ti)
            self.graph.plot_widget.addItem(ti)
Ejemplo n.º 7
0
    def __init__(self, model, node_inst, parent=None):
        super().__init__(parent)
        self.model = model
        self.node_inst = node_inst

        fm = QFontMetrics(self.document().defaultFont())
        attr = node_inst.attr
        self.attr_text_w = fm.width(attr.name if attr else "")
        self.attr_text_h = fm.lineSpacing()
        self.line_descent = fm.descent()
        self._rect = None

        if model.domain.class_var.is_discrete:
            self.pie = PieChart(node_inst.value, 8, self)
        else:
            self.pie = None
Ejemplo n.º 8
0
    def __init__(self, model, node_inst, parent=None):
        super().__init__(parent)
        self.model = model
        self.node_inst = node_inst

        fm = QFontMetrics(self.document().defaultFont())
        attr = node_inst.attr
        self.attr_text_w = fm.width(attr.name if attr else "")
        self.attr_text_h = fm.lineSpacing()
        self.line_descent = fm.descent()
        self._rect = None

        if model.domain.class_var.is_discrete:
            self.pie = PieChart(node_inst.value, 8, self)
        else:
            self.pie = None
Ejemplo n.º 9
0
    def __init__(self, tree_adapter, node_inst, parent=None):
        super().__init__(parent)
        self.tree_adapter = tree_adapter
        self.model = self.tree_adapter.model
        self.node_inst = node_inst

        fm = QFontMetrics(self.document().defaultFont())
        attr = self.tree_adapter.attribute(node_inst)
        self.attr_text_w = fm.width(attr.name if attr else "")
        self.attr_text_h = fm.lineSpacing()
        self.line_descent = fm.descent()
        self._rect = None

        if self.model.domain.class_var.is_discrete:
            self.pie = PieChart(self.tree_adapter.get_distribution(node_inst)[0], 8, self)
        else:
            self.pie = None
Ejemplo n.º 10
0
    def __init__(self, tree_adapter, node_inst, parent=None):
        super().__init__(parent)
        self.tree_adapter = tree_adapter
        self.model = self.tree_adapter.model
        self.node_inst = node_inst

        fm = QFontMetrics(self.document().defaultFont())
        attr = self.tree_adapter.attribute(node_inst)
        self.attr_text_w = fm.width(attr.name if attr else "")
        self.attr_text_h = fm.lineSpacing()
        self.line_descent = fm.descent()
        self._rect = None

        if self.model.domain.class_var.is_discrete:
            self.pie = PieChart(self.tree_adapter.get_distribution(node_inst)[0], 8, self)
        else:
            self.pie = None
Ejemplo n.º 11
0
    def paintEvent(self, event):
        super().paintEvent(event)
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)
        p.setBrush(self.indicator_color)

        p.save()
        p.setPen(Qt.NoPen)
        fm = QFontMetrics(self.font())
        width = self.rect().width()
        height = fm.height() + 6
        rect = QRectF(0, 0, width, height)
        p.drawRoundedRect(rect, 5, 5)
        p.restore()

        textstart = (width - fm.width(self.indicator_text)) / 2
        p.drawText(textstart, height / 2 + 5, self.indicator_text)
Ejemplo n.º 12
0
 def minimumSizeHint(self):
     fm = QFontMetrics(self.font())
     width = round(fm.width(self.indicator_text)) + 10
     height = fm.height() + 6
     return QSize(width, height)
Ejemplo n.º 13
0
    def _load_code_editor_settings(self):
        """
		Load settings on the code editor like, font style, margins, scroll, etc.
		Based on the example from http://eli.thegreenplace.net/2011/04/01/sample-using-qscintilla-with-pyqt/
		"""

        item = self.form.font_size.currentText()
        size = int(item)

        # Set the default font
        font = QFont()
        font.setFamily('Courier')
        font.setFixedPitch(True)
        font.setPointSize(size)
        self._code_editor.setFont(font)
        self._code_editor.setMarginsFont(font)

        # Margin 0 is used for line numbers
        fontmetrics = QFontMetrics(font)
        self._code_editor.setMarginsFont(font)
        self._code_editor.setMarginWidth(0, fontmetrics.width("00000") + 6)
        self._code_editor.setMarginLineNumbers(0, True)
        self._code_editor.setMarginsBackgroundColor(QColor("#cccccc"))

        # Clickable margin 1 for showing markers
        self._code_editor.setMarginSensitivity(1, True)
        self._code_editor.marginClicked.connect(self.on_margin_clicked)
        self._code_editor.markerDefine(QsciScintilla.RightArrow,
                                       self.ARROW_MARKER_NUM)
        self._code_editor.setMarkerBackgroundColor(QColor("#ee1111"),
                                                   self.ARROW_MARKER_NUM)

        # Detect changes to text
        self._code_editor.modificationChanged.connect(
            self.on_modification_changed)

        # Brace matching: enable for a brace immediately before or after the current position
        self._code_editor.setBraceMatching(QsciScintilla.SloppyBraceMatch)

        # Current line visible with special background color
        self._code_editor.setCaretLineVisible(True)
        self._code_editor.setCaretLineBackgroundColor(QColor("#ffe4e4"))

        # Set Python lexer
        # Set style for Python comments (style number 1) to a fixed-width Courier.
        lexer = self.lexer()
        lexer.setDefaultFont(font)
        self._code_editor.setLexer(lexer)
        self._code_editor.setIndentationWidth(4)
        # self._code_editor.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Courier')
        self._code_editor.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1)

        # Don't want to see the horizontal scrollbar at all
        # Use raw message to Scintilla here (all messages are documented here: http://www.scintilla.org/ScintillaDoc.html)
        self._code_editor.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)

        self._lexer_obj = lexer
        self.qsci_api = QsciAPIs(self._lexer_obj)
        ## Add autocompletion strings
        self.qsci_api.add("aLongString")
        self.qsci_api.add("aLongerString")
        self.qsci_api.add("aDifferentString")
        self.qsci_api.add("sOmethingElse")
        ## Compile the api for use in the lexer
        self.qsci_api.prepare()
        self._code_editor.setAutoCompletionThreshold(1)
        self._code_editor.setAutoCompletionSource(QsciScintilla.AcsAll)
Ejemplo n.º 14
0
    def paint(self, painter, option, index):

        image_space = 5
        icon = index.data(Qt.DecorationRole)
        gene_obj = index.data(Qt.DisplayRole)

        bold_font = QFont()
        bold_font.setBold(True)
        fm = QFontMetrics(QFont())

        input_name_str = 'Input name:  '
        type_of_match_str = 'Input type:  '
        gene_id_str = 'Gene ID:  '

        if not icon.isNull():
            # paint icon
            icon.paint(
                painter,
                option.rect.adjusted(image_space, image_space, -image_space,
                                     -image_space),
                Qt.AlignVCenter | Qt.AlignLeft)
            # if image is set, change space variable
            image_space = 55

        # paint gene object data

        # input string
        r = option.rect.adjusted(image_space, 7, 0,
                                 0)  # left, top, width and height

        painter.setFont(bold_font)
        painter.drawText(r.left(), r.top(), r.width(), r.height(),
                         Qt.AlignLeft, input_name_str)

        painter.setFont(QFont())
        painter.drawText(r.left() + fm.width(input_name_str), r.top(),
                         r.width(), r.height(), Qt.AlignLeft,
                         str(gene_obj.input_name))

        # gene id string
        r = option.rect.adjusted(image_space, 22, 0,
                                 0)  # left, top, width and height

        painter.setFont(bold_font)
        painter.drawText(r.left(), r.top(), r.width(), r.height(),
                         Qt.AlignLeft, type_of_match_str)

        painter.setFont(QFont())
        painter.drawText(
            r.left() + fm.width(input_name_str), r.top(), r.width(),
            r.height(), Qt.AlignLeft,
            str(gene_obj.type_of_match)
            if gene_obj.type_of_match else 'Unknown')

        # type of match string
        r = option.rect.adjusted(image_space, 37, 0,
                                 0)  # left, top, width and height

        painter.setFont(bold_font)
        painter.drawText(r.left(), r.top(), r.width(), r.height(),
                         Qt.AlignLeft, gene_id_str)

        painter.setFont(QFont())
        painter.drawText(
            r.left() + fm.width(input_name_str), r.top(), r.width(),
            r.height(), Qt.AlignLeft,
            str(gene_obj.ncbi_id) if gene_obj.ncbi_id else 'Unknown')