Ejemplo n.º 1
0
def bgc_name_face(node, *args, **kargs):
    """
    This is the item generator. It must receive a node object, and
    returns a Qt4 graphics item that can be used as a node face.
    """
    # Receive an arbitrary number of arguments, in this case width and
    # Height of the faces and the information about the BGC
    width = args[0]
    height = args[1]
    # Add the popup
    interactive_face = InteractiveItem("Class : {}\nRelated MIBiG : {}\nCluster family : {}".format(args[2], args[4], args[3]), 0, 0, width, height)
    # Keep a link within the item to access node info
    interactive_face.node = node
    # Remove border around the masterItem
    interactive_face.setPen(QPen(QtCore.Qt.NoPen))
    # Add ellipse around text
    ellipse = QGraphicsEllipseItem(interactive_face.rect())
    ellipse.setParentItem(interactive_face)
    # Change ellipse color
    ellipse.setBrush(QBrush(QColor(args[6])))
    # Add node name within the ellipse
    text = QGraphicsTextItem(args[5])
    text.setTextWidth(50)
    text.setParentItem(ellipse)
    # Center text according to masterItem size
    text_width = text.boundingRect().width()
    text_height = text.boundingRect().height()
    center = interactive_face.boundingRect().center()
    text.setPos(center.x()-text_width/2, center.y()-text_height/2)
    return interactive_face
Ejemplo n.º 2
0
def iLabel(node, *args, **kargs):

    #code for making specialized faces for intermediates mostly cribbed from the ete2 website example (though not interactive):
    # http://pythonhosted.org/ete2/tutorial/tutorial_drawing.html#creating-your-custom-interactive-item-faces

    my_label = node.name

    ellipse = QGraphicsEllipseItem(
        0, 0, fontSize * 2, fontSize * 2
    )  #I think the first two are coords of center; second pair is major/minor axis
    ellipse.setPen(QPen(QColor('black')))
    ellipse.setBrush(QBrush(QColor('white')))

    text = QGraphicsSimpleTextItem(my_label)
    text.setParentItem(ellipse)
    text.setBrush(QBrush(QColor("black")))
    font = QFont("Arial", fontSize * .9, weight=80)
    font.setLetterSpacing(1, 2)  #add 2 pixels between letters for legibility
    text.setFont(font)

    #Center text according to masterItem size
    tw = text.boundingRect().width()
    th = text.boundingRect().height()
    center = ellipse.boundingRect().center()
    text.setPos(
        center.x() + 1 - tw / 2,
        center.y() - th / 2
    )  #since the last letter has an extra 2 pixels after it from the spacing command, adjust center to compensate

    return ellipse
Ejemplo n.º 3
0
    def test_anchoritem(self):
        anchoritem = NodeAnchorItem(None)
        self.scene.addItem(anchoritem)

        path = QPainterPath()
        path.addEllipse(0, 0, 100, 100)

        anchoritem.setAnchorPath(path)

        anchor = AnchorPoint()
        anchoritem.addAnchor(anchor)

        ellipse1 = QGraphicsEllipseItem(-3, -3, 6, 6)
        ellipse2 = QGraphicsEllipseItem(-3, -3, 6, 6)
        self.scene.addItem(ellipse1)
        self.scene.addItem(ellipse2)

        anchor.scenePositionChanged.connect(ellipse1.setPos)

        with self.assertRaises(ValueError):
            anchoritem.addAnchor(anchor)

        anchor1 = AnchorPoint()
        anchoritem.addAnchor(anchor1)

        anchor1.scenePositionChanged.connect(ellipse2.setPos)

        self.assertSequenceEqual(anchoritem.anchorPoints(), [anchor, anchor1])

        self.assertSequenceEqual(anchoritem.anchorPositions(), [0.5, 0.5])
        anchoritem.setAnchorPositions([0.5, 0.0])

        self.assertSequenceEqual(anchoritem.anchorPositions(), [0.5, 0.0])

        def advance():
            t = anchoritem.anchorPositions()
            t = [(t + 0.05) % 1.0 for t in t]
            anchoritem.setAnchorPositions(t)
            self.singleShot(20, advance)

        advance()

        self.app.exec_()
Ejemplo n.º 4
0
 def constructPieChart(self, distrib, numbs):
     pie = QGraphicsItemGroup()
     totArc = 0
     for j, num, dist in reversed(zip(range(len(numbs)), numbs, distrib)):
         arc = QGraphicsEllipseItem(-self.pieWidth/2, -self.pieWidth/2, self.pieWidth, self.pieHeight)
         arc.setPen(QPen(QColor(0, 0, 0), 1, Qt.SolidLine))
         arc.setBrush(QBrush(self.discPalette[j]))
         arc.setToolTip("%s: %.3f" % (self.attributes[self.selectedAttributes[j]][0], num) + (" (%2.1f%%)" % (dist/self.barHeight*100) if self.normalize else ""))
         arc.setStartAngle(totArc)
         arc.setSpanAngle(dist * 2880 / self.barHeight)
         pie.addToGroup(arc)
         totArc += dist * 2880 / self.barHeight
     return pie
Ejemplo n.º 5
0
 def __init__(self,
              pen=QPen(Qt.black),
              brush=QBrush(Qt.NoBrush),
              xCenter=0.0,
              yCenter=0.0,
              radius=1.0):
     OWCurve.__init__(self)
     self._item = QGraphicsEllipseItem(self)
     self.center = xCenter, yCenter
     self.radius = radius
     self._rect = QRectF(xCenter - radius, yCenter - radius, 2 * radius,
                         2 * radius)
     self.set_pen(pen)
     self.set_brush(brush)
Ejemplo n.º 6
0
def ugly_name_face(node, *args, **kargs):
    """ This is my item generator. It must receive a node object, and
    returns a Qt4 graphics item that can be used as a node face.
    """

    # receive an arbitrary number of arguments, in this case width and
    # height of the faces
    width = args[0][0]
    height = args[0][1]

    ## Creates a main master Item that will contain all other elements
    ## Items can be standard QGraphicsItem
    # masterItem = QGraphicsRectItem(0, 0, width, height)

    # Or your custom Items, in which you can re-implement interactive
    # functions, etc. Check QGraphicsItem doc for details.
    masterItem = InteractiveItem(0, 0, width, height)

    # Keep a link within the item to access node info
    masterItem.node = node

    # I dont want a border around the masterItem
    masterItem.setPen(QPen(QtCore.Qt.NoPen))

    # Add ellipse around text
    ellipse = QGraphicsEllipseItem(masterItem.rect())
    ellipse.setParentItem(masterItem)
    # Change ellipse color
    ellipse.setBrush(QBrush(QColor(random_color())))

    # Add node name within the ellipse
    text = QGraphicsSimpleTextItem(node.name)
    text.setParentItem(ellipse)
    text.setPen(QPen(QPen(QColor("white"))))

    # Center text according to masterItem size
    tw = text.boundingRect().width()
    th = text.boundingRect().height()
    center = masterItem.boundingRect().center()
    text.setPos(center.x() - tw / 2, center.y() - th / 2)

    return masterItem
Ejemplo n.º 7
0
def iLabel(node, *args, **kargs):

    #code for making specialized faces for intermediates mostly cribbed from the ete2 website example (though not interactive):
    # http://pythonhosted.org/ete2/tutorial/tutorial_drawing.html#creating-your-custom-interactive-item-faces

    my_label = args[0][0]  #or maybe just node.name?

    ellipse = QGraphicsEllipseItem(
        0, 0, fontSize * 2, fontSize * 2
    )  #I think the first two are coords of center; second pair is major/minor axis
    ellipse.setBrush(QBrush(QColor('black')))

    text = QGraphicsSimpleTextItem(my_label)
    text.setParentItem(ellipse)
    text.setBrush(QBrush(QColor("white")))
    text.setFont(QFont("Arial", fontSize * .75))

    #Center text according to masterItem size
    tw = text.boundingRect().width()
    th = text.boundingRect().height()
    center = ellipse.boundingRect().center()
    text.setPos(center.x() - tw / 2, center.y() - th / 2)

    return ellipse