예제 #1
0
 def __init__(self, face, node, text):
     QGraphicsSimpleTextItem.__init__(self, text)
     _ActionDelegator.__init__(self)
     self.node = node
     self.face = face
     self._bounding_rect = self.face.get_bounding_rect()
     self._real_rect = self.face.get_real_rect()
예제 #2
0
 def update_items(self):
     #self.item = QGraphicsRectItem(0,0,self._total_w, self.row_h)
     seq_width = 0
     nopen = QPen(QtCore.Qt.NoPen)
     font = QFont("Courier", self.fsize)
     rect_cls = self.InteractiveLetterItem if self.interact else QGraphicsRectItem
     for i, letter in enumerate(self.seq):
         width = self.col_w
         for m in self.special_col:
             if m[0] < i <= m[1]:
                 width = self.alt_col_w
                 break
         #load interactive item if called correspondingly
         rectItem = rect_cls(0, 0, width, self.row_h, parent=self.item)
         rectItem.setX(seq_width)  # to give correct X to children item
         rectItem.setBrush(self.bg_col[letter])
         rectItem.setPen(nopen)
         if self.interact:
             if self.codon:
                 rectItem.codon = '%s, %d: %s' % (
                     self.seq[i], i, self.codon[i * 3:i * 3 + 3])
             else:
                 rectItem.codon = '%s, %d' % (self.seq[i], i)
         # write letter if enough space
         if width >= self.fsize:
             text = QGraphicsSimpleTextItem(letter, parent=rectItem)
             text.setFont(font)
             text.setBrush(self.fg_col[letter])
             # Center text according to rectItem size
             tw = text.boundingRect().width()
             th = text.boundingRect().height()
             text.setPos((width - tw) / 2, (self.row_h - th) / 2)
         seq_width += width
     self.width = seq_width
예제 #3
0
파일: rulerface.py 프로젝트: meren/ebov
    def draw_x_axis(self):
        #lineItem = QGraphicsLineItem(self.col_w/2,
        #                                   self.coordY(self.ylim[0])+2,
        #                                   self.width-self.col_w/2,
        #                                   self.coordY(self.ylim[0])+2,
        #                                   parent=self.item)
        #lineItem.setPen(QPen(QColor('black')))
        #lineItem.setZValue(10)
        #all_vals = list(range(0, len(self.values), 5))
        #if (len(self.values)-1)%5:
        #    all_vals += [len(self.values)-1]
        for x, lab in enumerate(self.values):
#            lineItem = QGraphicsLineItem(0, self.coordY(self.ylim[0])+2,
#                                               0, self.coordY(self.ylim[0])+6,
#                                               parent=self.item)
#            lineItem.setX(x*self.col_w + self.col_w/2)
#            lineItem.setPen(QPen(QColor('black')))
#            lineItem.setZValue(10)
            text = QGraphicsSimpleTextItem(str(lab))
            text.rotate(-90)
            text.setFont(QFont("Arial", self.fsize-2))
            text.setParentItem(self.item)
            tw = text.boundingRect().height()
            # Center text according to masterItem size
            text.setPos(x*self.col_w-tw/2 + self.col_w/2,
                        self.coordY(self.ylim[0]))
예제 #4
0
 def __init__(self, longitude, latitude, text, scene, parent=None, min_zoom_visibility=None):
     pos = scene.posFromLonLat(longitude, latitude)
     QGraphicsSimpleTextItem.__init__(self, text, scene=scene, parent=parent)
     self._min_zoom = min_zoom_visibility
     self._lon, self._lat = longitude, latitude
     self.setPos(pos)
     self.updatePosition(scene)
예제 #5
0
 def __init__(self, face, node, text):
     QGraphicsSimpleTextItem.__init__(self, text)
     _ActionDelegator.__init__(self)
     self.node = node
     self.face = face
     self._bounding_rect = self.face.get_bounding_rect()
     self._real_rect = self.face.get_real_rect()
예제 #6
0
    def update_items(self):
        self.item = QGraphicsRectItem(
            0, 0, self.width, self.row_h * self.coeff_h)
        seq_width = 0
        nopen = QPen(Qt.NoPen)
        self.item.setPen(nopen)
        font = QFont(self.ftype, self.fsize)
        if self.fstyle == "italic":
            font.setStyle(QFont.StyleItalic)
        elif self.fstyle == "oblique":
            font.setStyle(QFont.StyleOblique)
        rect_cls = QGraphicsRectItem
        for i, val in enumerate(self.liste):
            width = self.col_w
            height = self.row_h * len(str(val)) + 1
            rectitem = rect_cls(0, 0, width, height, parent=self.item)
            rectitem.setX(seq_width)  # to give correct X to children item
            rectitem.setBrush(QBrush(QColor(self.bgcolor)))
            rectitem.setPen(nopen)

            # write letter if enough space in height
            if height >= self.fsize:
                text = QGraphicsSimpleTextItem(str(val), parent=rectitem)
                text.setFont(font)
                text.setBrush(QBrush(QColor(self.fgcolor)))
                # Center text according to rectitem size
                # txtw = text.boundingRect().width()
                txth = text.boundingRect().height()
                text.setRotation(self.rot)
                text.setX(txth)
            seq_width += width
        self.width = seq_width
예제 #7
0
    def paint( self, painter, option, widget ):
        color = self.__settings.lineColor
        if self.color:
            color = self.color

        self.setBrush( QBrush( color ) )
        QGraphicsSimpleTextItem.paint( self, painter, option, widget )
        return
예제 #8
0
    def __init__( self, settings, text ):
        QGraphicsSimpleTextItem.__init__( self )
        self.__settings = settings

        self.setFont( settings.badgeFont )
        self.setText( text )

        self.color = None
        return
예제 #9
0
 def update_items(self):
     #self.item = QGraphicsRectItem(0,0,self._total_w, self.row_h)
     seq_width = 0
     nopen = QPen(QtCore.Qt.NoPen)
     font = QFont("Courier", self.fsize)
     rect_cls = self.InteractiveLetterItem if self.interact else QGraphicsRectItem
     for i, letter in enumerate(self.seq):
         width = self.col_w
         for m in self.special_col:
             if m[0] < i <= m[1]:
                 width = self.alt_col_w
                 break
         #load interactive item if called correspondingly
         rectItem = rect_cls(0, 0, width, self.row_h, parent=self.item)
         rectItem.setX(seq_width) # to give correct X to children item
         rectItem.setBrush(self.bg_col[letter])
         rectItem.setPen(nopen)
         if self.interact:
             if self.codon:
                 rectItem.codon = '%s, %d: %s' % (self.seq[i], i,
                                                  self.codon[i*3:i*3+3])
             else:
                 rectItem.codon = '%s, %d' % (self.seq[i], i)
         # write letter if enough space
         if width >= self.fsize:
             text = QGraphicsSimpleTextItem(letter, parent=rectItem)
             text.setFont(font)
             text.setBrush(self.fg_col[letter])
             # Center text according to rectItem size
             tw = text.boundingRect().width()
             th = text.boundingRect().height()
             text.setPos((width - tw)/2, (self.row_h - th)/2)
         seq_width += width
     self.width = seq_width
예제 #10
0
    def update_items(self):
        rect_cls = QGraphicsRectItem
        self.item = rect_cls(0, 0, self.width, self.row_h)
        seq_width = 0
        nopen = QPen(Qt.NoPen)
        font = QFont("Courier", self.fsize)
        for i, letter in enumerate(self.seq):
            width = self.col_w
            for reg in self.special_col:
                if reg[0] < i <= reg[1]:
                    width = self.alt_col_w
                    break
            rectitem = rect_cls(0, 0, width, self.row_h, parent=self.item)
            rectitem.setX(seq_width)  # to give correct X to children item
            rectitem.setBrush(self.bg_col[letter])
            rectitem.setPen(nopen)

            # write letter if enough space
            if width >= self.fsize:
                text = QGraphicsSimpleTextItem(letter, parent=rectitem)
                text.setFont(font)
                text.setBrush(self.fg_col[letter])
                # Center text according to rectitem size
                txtw = text.boundingRect().width()
                txth = text.boundingRect().height()
                text.setPos((width - txtw) / 2, (self.row_h - txth) / 2)
            seq_width += width
        self.width = seq_width
예제 #11
0
 def showMoveHelper(self, visible=True):
     """show help text In empty HandBoards"""
     if visible:
         if not self.__moveHelper:
             splitter = QGraphicsRectItem(self)
             hbCenter = self.rect().center()
             splitter.setRect(hbCenter.x() * 0.5, hbCenter.y(), hbCenter.x() * 1, 1)
             helpItems = [splitter]
             for name, yFactor in [(m18n('Move Exposed Tiles Here'), 0.5),
                                     (m18n('Move Concealed Tiles Here'), 1.5)]:
                 helper = QGraphicsSimpleTextItem(name, self)
                 helper.setScale(3)
                 nameRect = QRectF()
                 nameRect.setSize(helper.mapToParent(helper.boundingRect()).boundingRect().size())
                 center = QPointF(hbCenter)
                 center.setY(center.y() * yFactor)
                 helper.setPos(center - nameRect.center())
                 if self.sceneRotation() == 180:
                     rotateCenter(helper, 180)
                 helpItems.append(helper)
             self.__moveHelper = self.scene().createItemGroup(helpItems)
         self.__moveHelper.setVisible(True)
     else:
         if self.__moveHelper:
             self.__moveHelper.setVisible(False)
예제 #12
0
    def __init__(self, table, vector, mass=1.0):
        """Documentation here"""

        self.name = table.name
        self._mediator = Mediator()

        # layout widget
        x, y = vector.x, vector.y
        text = QGraphicsSimpleTextItem('{0} as {1}'.format(self.name, self.alias))
        width = text.boundingRect().width()
        QGraphicsRectItem.__init__(self, x, y, width + 10, 22)

        self.table = table.alias(self.alias)

        self.setBrush(Qt.cyan)
        self.setPen(Qt.darkCyan)

        self.width = width + 10
        self.height = 22
        self.setFlag(self.ItemIsSelectable, True)

        text.setParentItem(self)
        text.setX(x + 5)
        text.setY(y + 5)

        self.point = vector
        self.mass = mass
        self.velocity = Vector(0, 0)
        self.force = Vector(0, 0)
        self.instances.append(self)
    def set_labels(self, labels):
        """Set the text labels."""
        self.clear()
        orientation = Qt.Horizontal if self.orientation == Qt.Vertical else Qt.Vertical
        for text in labels:
            item = QGraphicsSimpleTextItem(text, self)
            item.setFont(self.font())
            item.setToolTip(text)
            witem = WrapperLayoutItem(item, orientation, parent=self)
            self.layout().addItem(witem)
            self.layout().setAlignment(witem, self.alignment)
            self.label_items.append(item)

        self.layout().activate()
        self.updateGeometry()
예제 #14
0
 def __init__(self,
              longitude,
              latitude,
              text,
              scene,
              parent=None,
              min_zoom_visibility=None):
     pos = scene.posFromLonLat(longitude, latitude)
     QGraphicsSimpleTextItem.__init__(self,
                                      text,
                                      scene=scene,
                                      parent=parent)
     self._min_zoom = min_zoom_visibility
     self._lon, self._lat = longitude, latitude
     self.setPos(pos)
     self.updatePosition(scene)
예제 #15
0
 def __init__(self, game):
     """init and position the wall"""
     # we use only white dragons for building the wall. We could actually
     # use any tile because the face is never shown anyway.
     game.wall = self
     Wall.__init__(self, game)
     self.__square = Board(1, 1, Internal.field.tileset)
     self.__square.setZValue(ZValues.marker)
     sideLength = len(self.tiles) // 8
     self.__sides = [UIWallSide(Internal.field.tileset, boardRotation, sideLength) \
         for boardRotation in (0, 270, 180, 90)]
     for side in self.__sides:
         side.setParentItem(self.__square)
         side.lightSource = self.lightSource
         side.windTile = PlayerWind('E',
                                    Internal.field.windTileset,
                                    parent=side)
         side.windTile.hide()
         side.nameLabel = QGraphicsSimpleTextItem('', side)
         font = side.nameLabel.font()
         font.setPointSize(48)
         side.nameLabel.setFont(font)
         side.message = YellowText(side)
         side.message.setZValue(ZValues.popup)
         side.message.setVisible(False)
         side.message.setPos(side.center())
     self.__sides[0].setPos(yWidth=sideLength)
     self.__sides[3].setPos(xHeight=1)
     self.__sides[2].setPos(xHeight=1, xWidth=sideLength, yHeight=1)
     self.__sides[1].setPos(xWidth=sideLength, yWidth=sideLength, yHeight=1)
     self.showShadows = Preferences.showShadows
     Internal.field.centralScene.addItem(self.__square)
예제 #16
0
    def update_items(self):
        try:
            max_codons = math.ceil(
                max([len(x) for x in self.readict.values()]) / 2.0) * 2
        except:
            max_codons = 1
        if self.maxcodon:
            max_codons = max(max_codons, self.maxcodon)

        max_h = max_codons * (self.h + self.spacer)
        rect_cls = QGraphicsRectItem
        self.item = rect_cls()
        nopen = QPen(QColor('#EEEEEE'))
        nobrush = QBrush(Qt.NoBrush)
        width = self.mgl
        font = QFont(self.ffamily, self.fsize)
        for aa in self.aa_list:
            codons = self.readict.get(aa, [])
            tot_codons = len(codons)
            hpos = (self.h + self.spacer) * (max_codons - tot_codons) / 2.0

            for cod in codons:
                rectitem = rect_cls(0, 0, self.w, self.h, parent=self.item)
                rectitem.setX(width)
                rectitem.setY(hpos)
                rectitem.setBrush(self.bgcolor[aa])
                rectitem.setPen(nopen)
                hpos += (self.h + self.spacer)
                # write letter if enough space
                if self.w >= self.fsize:
                    text = QGraphicsSimpleTextItem(cod, parent=rectitem)
                    text.setFont(font)
                    text.setBrush(self.fgcolor[aa])
                    # Center text according to rectitem size
                    txtw = text.boundingRect().width()
                    txth = text.boundingRect().height()
                    text.setPos((self.w - txtw) / 2, (self.h - txth) / 2)

            # this only happen if codon reassignment not found for aa
            # we do not need a spacer if it's an internal node (I hope)
            if hpos == 0 and self.is_leaf:
                rectitem = rect_cls(0, 0, self.w, self.h, parent=self.item)
                rectitem.setX(width)
                rectitem.setY(hpos)
                rectitem.setBrush(nobrush)
                rectitem.setPen(nopen)

            width += self.w + self.spacer

        self.width = width
        self.item.setPen(nopen)
        self.item.setRect(0, 0, self.width, max_h)
예제 #17
0
    def update_items(self):
        rect_cls = QGraphicsRectItem
        nobrush = QBrush(Qt.NoBrush)
        nopen = QPen(QColor('#FFFFFF'))
        grad = Qt.NoBrush
        self.item = rect_cls()

        for codon in self.codons.keys():
            rectitem = rect_cls(self.width, self.margin,
                                self.w, self.h, parent=self.item)
            total_rea = len(self.aa_list[codon])
            if total_rea > 0:

                grad = QLinearGradient(QPointF(0, 0.5), QPointF(1, 0.5))
                grad.setCoordinateMode(QLinearGradient.ObjectBoundingMode)
                pointpos = 1.0 / total_rea
                starting = -0.001
                for reqcol, aa in enumerate(self.aa_list[codon]):
                    curcol = self.bgcolor[aa]
                    # use the same color twice to mark start and end
                    grad.setColorAt(starting + 0.001, curcol)
                    starting += pointpos
                    grad.setColorAt(starting, curcol)

                    # grad.setColorAt(starting, QColor(curcol))
            # put small rec in big rec
            # Comment award of the year !
            brush = QBrush(QColor('#CCCCCC'))
            pen = QPen(QColor('#BBBBBB'))
            if self.codons[codon]:
                brush = QBrush(grad)
                pen = QPen(QColor('#000000'))

            rectitem.setBrush(brush)
            rectitem.setPen(pen)
            # Center text according to rectitem size
            text = QGraphicsSimpleTextItem(self.codons[codon], parent=rectitem)
            text.setFont(self.font)
            text.setBrush(self.fgcolor)
            center = rectitem.boundingRect().center()
            txtw = text.boundingRect().width()
            txth = text.boundingRect().height()
            text.setPos(center.x() - txtw / 2, center.y() - txth / 2)

            self.width += self.w + self.margin

        # now plot the big rect (with margin)
        self.item.setPen(nopen)
        self.item.setBrush(nobrush)
        self.item.setRect(0, 0, self.width, self.h + (2 * self.margin))
예제 #18
0
    def update_items(self):
        rect_h = self.height
        if self.x_axis:
            rect_h += 30
        self.item = QGraphicsRectItem(0, 0, self.width + 40, rect_h)
        self.item.setPen(QPen(QColor('white')))

        #X axis

        if self.x_axis:
            self.draw_x_axis()

        # Legend

        self.draw_legend()

        # Y axes and colo rect
        yi = -1
        for model in ["PCOC", "PC", "OC", "Topological", "Identical"]:
            if self.dict_values_pcoc.has_key(model):
                yi += 1
                y = yi * self.col_w

                # Y axes
                ## Stick
                yaxis = (yi + 0.5) * self.col_w
                lineItem = QGraphicsLineItem(self.width,
                                             yaxis,
                                             self.width + 5,
                                             yaxis,
                                             parent=self.item)
                lineItem.setPen(QPen(QColor('black')))
                ## Text
                text = QGraphicsSimpleTextItem(model)
                text.setFont(QFont("Arial", self.fsize - 2))
                text.setParentItem(self.item)
                tw = text.boundingRect().width()
                th = text.boundingRect().height()
                ## Center text according to masterItem size
                text.setPos(self.width + 5, yaxis - th / 2)

                # Color rect for each model
                values = self.dict_values_pcoc[model]
                for i, val in enumerate(values):
                    self.draw_fun(i * self.col_w, y, val, col_width=self.col_w)
예제 #19
0
파일: pageView.py 프로젝트: kzwkt/dff
 def setPageHead(self, len):
     count = 0
     x = 95
     while count < len:
         item = QGraphicsSimpleTextItem()
         item.setFont(self.font)
         item.setText("%.2x" % count)
         item.setPos(x, 3)
         self.scene.addItem(item)
         x += self.pagew + 2
         count += 1
예제 #20
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
예제 #21
0
        def hoverEnterEvent(self, e):
            """ when mouse is over"""
            if not self.label:
                self.label = QGraphicsRectItem(parent=self)
                #self.label.setY(-18)
                self.label.setX(11)
                self.label.setBrush(QBrush(QColor("white")))
                self.label.text = QGraphicsSimpleTextItem(parent=self.label)

            self.setZValue(1)
            self.label.text.setText(self.codon)
            self.label.setRect(self.label.text.boundingRect())
            self.label.setVisible(True)
예제 #22
0
 def setNumber(self):
     """docstring for setNumber"""
     if self.label == None:
         self.label = QGraphicsSimpleTextItem("%d" % self._number)
         self.label.setFont(self.font)
         self.label.setParentItem(self)
     y_val = self.radius / 3
     if self._number < 10:
         self.label.setPos(self.radius / 1.5, y_val)
     elif self._number < 100:
         self.label.setPos(self.radius / 3, y_val)
     else: # _number >= 100
         self.label.setPos(0, y_val)
예제 #23
0
    def draw_legend(self):
        legend_h = self.height * ((self.nb_models - 1) / float(self.nb_models))
        if legend_h < 35:
            legend_h = 35
        legend_rect = QGraphicsRectItem(-20, 0, 10, legend_h, parent=self.item)
        x0 = -20
        n_cat = 6.
        for y, str_y in [(1, 1), (1 / n_cat * 5, 0.99), (1 / n_cat * 4, 0.9),
                         (1 / n_cat * 3, 0.8), (1 / n_cat * 2, 0.7),
                         (1 / n_cat * 1, 0.5), (1 / n_cat * 0, 0)]:
            y_stick = legend_h - y * legend_h
            lineItem = QGraphicsLineItem(x0 - 5,
                                         y_stick,
                                         x0,
                                         y_stick,
                                         parent=self.item)
            lineItem.setPen(QPen(QColor('black')))
            text = QGraphicsSimpleTextItem(str(str_y))
            text.setFont(QFont("Arial", self.fsize - 4))
            text.setParentItem(self.item)
            tw = text.boundingRect().width()
            th = text.boundingRect().height()
            # Center text according to masterItem size
            text.setPos(x0 - tw - 7, y_stick - th / 2)

        for (y1, y2, c) in [(1, 1 / n_cat * 5, 0.99),
                            (1 / n_cat * 5, 1 / n_cat * 4, 0.9),
                            (1 / n_cat * 4, 1 / n_cat * 3, 0.8),
                            (1 / n_cat * 3, 1 / n_cat * 2, 0.7),
                            (1 / n_cat * 2, 1 / n_cat * 1, 0.5),
                            (1 / n_cat * 1, 1 / n_cat * 0, 0)]:
            y1_stick = legend_h - y1 * legend_h
            y2_stick = legend_h - y2 * legend_h
            self.draw_fun(x0,
                          y1_stick,
                          c,
                          col_width=10,
                          col_height=y2_stick - y1_stick)
예제 #24
0
 def __init__(self, pathHelixGroup):
     super(ActiveSliceHandle, self).__init__(pathHelixGroup)
     self._pathHelixGroup = None
     self._activeSlice = 0
     self._dragMode = False
     self._label = QGraphicsSimpleTextItem("", parent=self)
     self._label.setPos(0, -18)
     self._label.setFont(self._myfont)
     self._label.setBrush(self._labelbrush)
     self._label.hide()
     self.setPathHelixGroup(pathHelixGroup)
     self.setFlag(QGraphicsItem.ItemIsMovable)
     self.setAcceptHoverEvents(True)
     self.setZValue(styles.ZACTIVESLICEHANDLE)
예제 #25
0
파일: item_faces.py 프로젝트: xguse/ete
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
예제 #26
0
    def hoverEnterEvent(self, e):
        # There are many ways of adding interactive elements. With the
        # following code, I show/hide a text item over my custom
        # DynamicItemFace
        if not self.label:
            self.label = QGraphicsRectItem()
            self.label.setParentItem(self)
            # This is to ensure that the label is rendered over the
            # rest of item children (default ZValue for items is 0)
            self.label.setZValue(1)
            self.label.setBrush(QBrush(QColor("white")))
            self.label.text = QGraphicsSimpleTextItem()
            self.label.text.setParentItem(self.label)

        self.label.text.setText(self.node.name)
        self.label.setRect(self.label.text.boundingRect())
        self.label.setVisible(True)
예제 #27
0
    def set_labels(self, labels):
        """Set the text labels."""
        self.clear()
        orientation = Qt.Horizontal if self.orientation == Qt.Vertical else Qt.Vertical
        for text in labels:
            item = QGraphicsSimpleTextItem(text, self)
            item.setFont(self.font())
            item.setToolTip(text)
            witem = WrapperLayoutItem(item, orientation, parent=self)
            self.layout().addItem(witem)
            self.layout().setAlignment(witem, self.alignment)
            self.label_items.append(item)

        self.layout().activate()
        self.updateGeometry()
예제 #28
0
 def __init__(self, parentPH, fromStrand, fromIdx, toVH, toIdx, orientedLeft):
     super(PreCrossoverHandle, self).__init__(parentPH)
     self.fromVH = parentPH.vhelix()
     self.fromStrand = fromStrand
     self.fromIdx = fromIdx
     self.toVH = toVH
     self.toIdx = toIdx
     self.orientedLeft = orientedLeft
     
     self.fromVH.basesModified.connect(self.updateVisibilityAndEnabledness)
     self.toVH.basesModified.connect(self.updateVisibilityAndEnabledness)
     
     self.label = QGraphicsSimpleTextItem(str(toVH.number()), parent=self)
     self.label.setFont(self.toHelixNumFont)
     
     x = self.baseWidth * self.fromIdx
     y = (-1.25 if self.onTopStrand() else 2.25) * self.baseWidth
     self.setPos(x, y)
     halfLabelW = self.label.boundingRect().width() / 2
     labelX = self.baseWidth/2 - halfLabelW
     labelY = (-.10 if self.onTopStrand() else .48) * self.baseWidth
     self.label.setPos(labelX, labelY)
     self.updateVisibilityAndEnabledness()
예제 #29
0
파일: rulerface.py 프로젝트: meren/ebov
 def draw_y_axis(self):
     lineItem = QGraphicsLineItem(0, self.coordY(self.ylim[0]),
                                  0, self.coordY(self.ylim[1]),
                                  parent=self.item)
     lineItem.setPen(QPen(QColor('black')))
     lineItem.setZValue(10)
     max_w = 0
     for y in set(self.hlines + list(self.ylim)):
         lineItem = QGraphicsLineItem(0, self.coordY(y),
                                            -5, self.coordY(y),
                                            parent=self.item)
         lineItem.setPen(QPen(QColor('black')))
         lineItem.setZValue(10)
         text = QGraphicsSimpleTextItem(str(y))
         text.setFont(QFont("Arial", self.fsize-2))
         text.setParentItem(self.item)
         tw = text.boundingRect().width()
         max_w = tw if tw > max_w else max_w
         th = text.boundingRect().height()
         # Center text according to masterItem size
         text.setPos(-tw - 5, self.coordY(y)-th/2)
     if self.ylabel:
         text = QGraphicsSimpleTextItem(self.ylabel)
         text.setFont(QFont("Arial", self.fsize-1))
         text.setParentItem(self.item)
         text.rotate(-90)
         tw = text.boundingRect().width()
         th = text.boundingRect().height()
         # Center text according to masterItem size
         text.setPos(-th -5-max_w, tw/2+self.coordY(sum(self.ylim)/2))
예제 #30
0
 def __init__(self, face, node, text):
     QGraphicsSimpleTextItem.__init__(self, text)
     _ActionDelegator.__init__(self)
     self.node = node
예제 #31
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
예제 #32
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
예제 #33
0
파일: rulerface.py 프로젝트: meren/ebov
 def write_header(self):
     text = QGraphicsSimpleTextItem(self.header)
     text.setFont(QFont("Arial", self.fsize))
     text.setParentItem(self.item)
     text.setPos(0, 5)
예제 #34
0
class QPokerWidget(QWidget):
    def __init__(self, dataDir="", parent=None):
        QWidget.__init__(self, parent)
        self.renderer = QSvgRenderer(dataDir + "poker.svg")
        self.scene = QGraphicsScene()
        self.chat = QGraphicsSimpleTextItem()
        self.table = QGraphicsSvgItem(dataDir + "poker.svg")
        self.table.setSharedRenderer(self.renderer)
        self.table.setElementId("table")
        self.table.setMatrix(self.renderer.matrixForElement("transform_table"))
        self.scene.addItem(self.chat)
        self.scene.addItem(self.table)
        self.board = []
        for i in range(5):
            card = AnimatedGraphicsSvgItem(dataDir + "svg-cards.svg",
                                           self.table)
            card.setElementId("back")
            parent = self.renderer.matrixForElement("transform_table")
            child = self.renderer.matrixForElement("transform_card%i" % i)
            cardMatrix = child.translate(-parent.dx(), -parent.dy())
            card.setMatrix(cardMatrix)
            #card.setFlag(QGraphicsSvgItem.ItemIsMovable, True)
            card.scale(0.5, 0.5)
            card.hide()
            self.scene.addItem(card)
            self.board.append(card)
        self.seats = []
        self.names = []
        self.moneys = []
        self.bets = []
        for i in range(10):
            seat = SeatItem()

            def seatClickedEvent(seat=i):
                seatClickedCallback = self.seatClicked
                seatClickedCallback(seat)

            seat.event = seatClickedEvent
            seat.setSharedRenderer(self.renderer)
            seat.setElementId("seat")
            seat.setMatrix(
                self.renderer.matrixForElement("transform_seat%i" % i))
            self.scene.addItem(seat)
            self.seats.append(seat)
            name = QGraphicsSimpleTextItem(seat)
            name.setMatrix(self.renderer.matrixForElement("seat_name"))
            self.scene.addItem(name)
            self.names.append(name)
            money = QGraphicsSimpleTextItem(seat)
            money.setMatrix(self.renderer.matrixForElement("seat_money"))
            self.scene.addItem(money)
            self.moneys.append(money)
            bet = QGraphicsSimpleTextItem()
            bet.setMatrix(self.renderer.matrixForElement("transform_bet%i" %
                                                         i))
            self.scene.addItem(bet)
            self.bets.append(bet)
        self.pots = []
        for i in range(9):
            pot = QGraphicsSimpleTextItem()
            pot.setMatrix(self.renderer.matrixForElement("transform_pot%i" %
                                                         i))
            self.scene.addItem(pot)
            self.pots.append(pot)
        self.view = QGraphicsView(self)
        self.view.setScene(self.scene)
        self.view.resize(800, 600)
        self.fold = ActionItem()
        self.fold.setText("fold")
        self.fold.setPos(0, 550)
        self.scene.addItem(self.fold)
        self.fold.event = lambda: self.foldClicked()
        self.check = ActionItem()
        self.check.setText("check")
        self.check.setPos(50, 550)
        self.scene.addItem(self.check)
        self.check.event = lambda: self.checkClicked()
        self.call = ActionItem()
        self.call.setText("call")
        self.call.setPos(100, 550)
        self.scene.addItem(self.call)
        self.call.event = lambda: self.callClicked()
        self.bet = ActionItem()
        self.bet.setText("bet")
        self.bet.setPos(150, 550)
        self.scene.addItem(self.bet)
        self.bet.event = lambda: self.betClicked()

    def renderChat(self, message):
        self.chat.setText(message)

    def renderBoard(self, cards):
        for i in range(len(cards)):
            item = self.board[i]
            card = cards[i]
            item.setElementId(card2SvgElement(card))
            if item.isVisible() == False:
                item.show()
        for i in range(len(cards), len(self.board)):
            item = self.board[i]
            item.hide()
            item.setElementId('back')

    def renderStart(self):
        map(lambda svgItem: svgItem.setElementId('back'), self.board)
        map(lambda svgItem: svgItem.hide(), self.board)

    def renderPlayerArrive(self, seat, name):
        self.names[seat].setText(name)
        self.names[seat].show()

    def renderPlayerLeave(self, seat):
        self.names[seat].setText('')
        self.names[seat].hide()
        self.moneys[seat].hide()
        self.bets[seat].hide()

    def renderPlayerChips(self, seat, money, bet):
        if bet > 0:
            self.bets[seat].setText(str(bet))
            self.bets[seat].show()
        else:
            self.bets[seat].hide()
        self.moneys[seat].setText(str(money))
        self.moneys[seat].show()

    def renderPot(self, index, amount):
        self.pots[index].setText(str(amount))
        self.pots[index].show()

    def renderPotReset(self):
        for pot in self.pots:
            pot.setText("")
            pot.hide()

    def renderPosition(self, seatInPosition):
        for i in range(len(self.seats)):
            seat = self.seats[i]
            if i == seatInPosition:
                seat.setElementId("seat_inposition")
            else:
                seat.setElementId("seat")

    def renderPositionReset(self):
        for seat in self.seats:
            seat.setElementId("seat")

    def keyPressEvent(self, event):
        if event.text() == "q":
            self.view.scale(1.1, 1.1)
        elif event.text() == "a":
            self.view.scale(0.9, 0.9)

    seatClicked = lambda seat: None
    foldClicked = lambda: None
    checkClicked = lambda: None
    callClicked = lambda: None
    betClicked = lambda: None
예제 #35
0
class PreCrossoverHandle(QGraphicsItem):
    scafpen = QPen(styles.pch_scaf_stroke, styles.PATH_STRAND_STROKE_WIDTH)
    scafpen.setCapStyle(Qt.FlatCap)  # or Qt.RoundCap
    scafpen.setJoinStyle(Qt.RoundJoin)
    stappen = QPen(styles.pch_stap_stroke, styles.PATH_STRAND_STROKE_WIDTH)
    stappen.setCapStyle(Qt.FlatCap)  # or Qt.RoundCap
    stappen.setJoinStyle(Qt.RoundJoin)
    disabpen = QPen(styles.pch_disab_stroke, styles.PATH_STRAND_STROKE_WIDTH)
    disabpen.setCapStyle(Qt.FlatCap)
    disabpen.setJoinStyle(Qt.RoundJoin)
    disabbrush = QBrush(styles.pch_disab_stroke)  # For the helix number label
    enabbrush = QBrush(Qt.SolidPattern)  # Also for the helix number label
    baseWidth = styles.PATH_BASE_WIDTH
    rect = QRectF(0, 0, styles.PATH_BASE_WIDTH, styles.PATH_BASE_WIDTH)
    toHelixNumFont = QFont("Times", 10, QFont.Bold)
    
    def __init__(self, parentPH, fromStrand, fromIdx, toVH, toIdx, orientedLeft):
        super(PreCrossoverHandle, self).__init__(parentPH)
        self.fromVH = parentPH.vhelix()
        self.fromStrand = fromStrand
        self.fromIdx = fromIdx
        self.toVH = toVH
        self.toIdx = toIdx
        self.orientedLeft = orientedLeft
        
        self.fromVH.basesModified.connect(self.updateVisibilityAndEnabledness)
        self.toVH.basesModified.connect(self.updateVisibilityAndEnabledness)
        
        self.label = QGraphicsSimpleTextItem(str(toVH.number()), parent=self)
        self.label.setFont(self.toHelixNumFont)
        
        x = self.baseWidth * self.fromIdx
        y = (-1.25 if self.onTopStrand() else 2.25) * self.baseWidth
        self.setPos(x, y)
        halfLabelW = self.label.boundingRect().width() / 2
        labelX = self.baseWidth/2 - halfLabelW
        labelY = (-.10 if self.onTopStrand() else .48) * self.baseWidth
        self.label.setPos(labelX, labelY)
        self.updateVisibilityAndEnabledness()
    
    def onTopStrand(self):
        return self.fromVH.evenParity() and self.fromStrand==StrandType.Scaffold or\
               not self.fromVH.evenParity() and self.fromStrand==StrandType.Staple
            
    def couldFormNewCrossover(self):
        return self.fromVH.possibleNewCrossoverAt(self.fromStrand, self.fromIdx, self.toVH, self.toIdx)
    
    def crossoverExists(self):
        return self.fromVH.hasCrossoverAt(self.fromStrand, self.fromIdx)
    
    def is3pEndOfCrossover(self):
        return self.orientedLeft and self.onTopStrand() or\
               not self.orientedLeft and not self.onTopStrand
    
    def updateVisibilityAndEnabledness(self):
        shouldBeVisible = not self.crossoverExists()
        self.setVisible(shouldBeVisible)
        self.label.setVisible(shouldBeVisible)
        if self.couldFormNewCrossover():
            self.label.setBrush(self.enabbrush)
        else:
            self.label.setBrush(self.disabbrush)
        self.update()
    
    def paint(self, painter, option, widget=None):
        #Look Up Table
        pathLUT = (_ppathRD, _ppathRU, _ppathLD, _ppathLU)
        path = pathLUT[2*int(self.orientedLeft) + int(self.onTopStrand())]
        pen = self.disabpen
        if self.couldFormNewCrossover():
            if self.fromStrand == StrandType.Scaffold:
                pen = self.scafpen
            else:
                pen = self.stappen
        painter.setPen(pen)
        painter.drawPath(path)
    
    def boundingRect(self):
        return self.rect
    
    def mousePressEvent(self, event):
        if event.button() != Qt.LeftButton:
            return QGraphicsItem.mousePressEvent(self, event)
        if not self.couldFormNewCrossover():
            return
        # Determine upstream base
        fromHelix, toHelix = self.fromVH, self.toVH
        fromIdx, toIdx = self.fromIdx, self.toIdx
        if not self.is3pEndOfCrossover():
            fromHelix, toHelix = toHelix, fromHelix
            fromIdx, toIdx = toIdx, fromIdx
        # Create XoverHandlePair and store references
        # fromHelix.installXoverFrom3To5(StrandType.Scaffold, \
        #                                 fromIndex, toHelix, toIndex)
        fromHelix.installXoverFrom3To5(self.fromStrand, \
                                        fromIdx, toHelix, toIdx)
예제 #36
0
 def write_header(self):
     text = QGraphicsSimpleTextItem(self.header)
     text.setFont(QFont("Arial", self.fsize))
     text.setParentItem(self.item)
     text.setPos(0, 5)
예제 #37
0
 def __init__(self, face, node, text):
     QGraphicsSimpleTextItem.__init__(self, text)
     _ActionDelegator.__init__(self)
     self.node = node
예제 #38
0
 def draw_x_axis(self):
     #lineItem = QGraphicsLineItem(self.col_w/2,
     #                                   self.coordY(self.ylim[0])+2,
     #                                   self.width-self.col_w/2,
     #                                   self.coordY(self.ylim[0])+2,
     #                                   parent=self.item)
     #lineItem.setPen(QPen(QColor('black')))
     #lineItem.setZValue(10)
     #all_vals = list(range(0, len(self.values), 5))
     #if (len(self.values)-1)%5:
     #    all_vals += [len(self.values)-1]
     for x, lab in enumerate(self.values):
         #            lineItem = QGraphicsLineItem(0, self.coordY(self.ylim[0])+2,
         #                                               0, self.coordY(self.ylim[0])+6,
         #                                               parent=self.item)
         #            lineItem.setX(x*self.col_w + self.col_w/2)
         #            lineItem.setPen(QPen(QColor('black')))
         #            lineItem.setZValue(10)
         text = QGraphicsSimpleTextItem(str(lab))
         text.rotate(-90)
         text.setFont(QFont("Arial", self.fsize - 2))
         text.setParentItem(self.item)
         tw = text.boundingRect().height()
         # Center text according to masterItem size
         text.setPos(x * self.col_w - tw / 2 + self.col_w / 2,
                     self.coordY(self.ylim[0]))
예제 #39
0
class PathHelixHandle(QGraphicsItem):
    """docstring for PathHelixHandle"""
    radius = styles.PATHHELIXHANDLE_RADIUS
    rect = QRectF(0, 0, 2*radius, 2*radius)
    defBrush = QBrush(styles.grayfill)
    defPen = QPen(styles.graystroke, styles.PATHHELIXHANDLE_STROKE_WIDTH)
    hovBrush = QBrush(styles.bluefill)
    hovPen = QPen(styles.bluestroke, styles.PATHHELIXHANDLE_STROKE_WIDTH)
    useBrush = QBrush(styles.orangefill)
    usePen = QPen(styles.orangestroke, styles.PATHHELIXHANDLE_STROKE_WIDTH)

    def __init__(self, vhelix, parent):
        super(PathHelixHandle, self).__init__(parent)
        self.vhelix = vhelix
        
        self.parent = parent
        self.restoreParentItem = parent
        self.setParentItem(parent)
        
        self._number = self.vhelix.number()
        self.label = None
        self.focusRing = None
        self.beingHoveredOver = False
        self.setAcceptsHoverEvents(True)
        self.font = QFont("Times", 30, QFont.Bold)
        self.setNumber()
        #self.setFlag(QGraphicsItem.ItemIsMovable)
        self.setFlag(QGraphicsItem.ItemIsSelectable)
        self.setFlag(QGraphicsItem.ItemSendsScenePositionChanges)
    # end def

    def boundingRect(self):
        return self.rect

    def paint(self, painter, option, widget=None):
        if self._number >= 0:
            if self.isSelected():
                painter.setBrush(self.hovBrush)
                painter.setPen(self.hovPen)
            else:
                painter.setBrush(self.useBrush)
                painter.setPen(self.usePen)
        else:
            painter.setBrush(self.defBrush)
            painter.setPen(self.defPen)
        if self.beingHoveredOver:
            painter.setPen(self.hovPen)
        painter.drawEllipse(self.rect)

    def setNumber(self):
        """docstring for setNumber"""
        if self.label == None:
            self.label = QGraphicsSimpleTextItem("%d" % self._number)
            self.label.setFont(self.font)
            self.label.setParentItem(self)
        y_val = self.radius / 3
        if self._number < 10:
            self.label.setPos(self.radius / 1.5, y_val)
        elif self._number < 100:
            self.label.setPos(self.radius / 3, y_val)
        else: # _number >= 100
            self.label.setPos(0, y_val)

    def number(self):
        """docstring for number"""
        return self._number

    class FocusRingPainter(QGraphicsItem):
        """Draws a focus ring around helix in parent"""
        def __init__(self, helix, scene, parent=None):
            super(PathHelixHandle.FocusRingPainter, self).__init__(parent)
            self.parent = parent
            self.scene = scene
            self.helix = helix
            self.setPos(helix.pos())

        def paint(self, painter, option, widget=None):
            painter.setPen(PathHelixHandle.hovPen)
            painter.drawEllipse(self.helix.rect)

        def boundingRect(self):
            return self.helix.rect
    # end class

    def hoverEnterEvent(self, event):
        """
        hoverEnterEvent changes the PathHelixHandle brush and pen from default
        to the hover colors if necessary.
        """
        if self.focusRing == None:
            self.focusRing = PathHelixHandle.FocusRingPainter(self,\
                                                         self.scene(),\
                                                         self.parentItem())
        self.update(self.rect)
    # end def

    def hoverLeaveEvent(self, event):
        """
        hoverEnterEvent changes the PathHelixHanle brush and pen from hover
        to the default colors if necessary.
        """
        if self.focusRing != None:
            self.focusRing.setParentItem(None)
            self.focusRing = None
        self.update(self.rect)
    # end def

    def mousePressEvent(self, event):
        selectionGroup = self.group()
        if selectionGroup == None:
            selectionGroup = self.parent.phhSelectionGroup
        selectionGroup.setSelected(False)
        selectionGroup.addToGroup(self)
        self.setSelected(True)
        selectionGroup.mousePressEvent(event)
    # end def
    
    def restoreParent(self):
        tempP = self.restoreParentItem.mapFromItem(self.parentItem(), self.pos())
        self.setParentItem(self.restoreParentItem)
        self.setPos(tempP)
    # end def

    def itemChange(self, change, value):
        # for selection changes test against QGraphicsItem.ItemSelectedChange
        # intercept the change instead of the has changed to enable features.
        # if change == QGraphicsItem.ItemSelectedHasChanged and self.scene():
        if change == QGraphicsItem.ItemSelectedChange and self.scene():
            selectionGroup = self.parent.phhSelectionGroup
            lock = selectionGroup.parentItem().selectionLock
            if value == True and (lock == None or lock == selectionGroup):
                selectionGroup.addToGroup(self)
                selectionGroup.parentItem().selectionLock = selectionGroup
                return QGraphicsItem.itemChange(self, change, True)
            # end if
            else:
                return QGraphicsItem.itemChange(self, change, False)
            # end else
            self.update(self.boundingRect())
        return QGraphicsItem.itemChange(self, change, value)
예제 #40
0
    def replot_experiments(self):
        """Replot the whole quality plot.
        """
        self.scene.clear()
        labels = []

        max_dist = numpy.nanmax(list(filter(None, self.distances)))
        rug_widgets = []

        group_pen = QPen(Qt.black)
        group_pen.setWidth(2)
        group_pen.setCapStyle(Qt.RoundCap)
        background_pen = QPen(QColor(0, 0, 250, 150))
        background_pen.setWidth(1)
        background_pen.setCapStyle(Qt.RoundCap)

        main_widget = QGraphicsWidget()
        layout = QGraphicsGridLayout()
        attributes = self.data.domain.attributes
        if self.data is not None:
            for (group, indices), dist_vec in zip(self.groups, self.distances):
                indices_set = set(indices)
                rug_items = []
                if dist_vec is not None:
                    for i, attr in enumerate(attributes):
                        # Is this a within group distance or background
                        in_group = i in indices_set
                        if in_group:
                            rug_item = ClickableRugItem(dist_vec[i] / max_dist,
                                           1.0, self.on_rug_item_clicked)
                            rug_item.setPen(group_pen)
                            tooltip = experiment_description(attr)
                            rug_item.setToolTip(tooltip)
                            rug_item.group_index = indices.index(i)
                            rug_item.setZValue(rug_item.zValue() + 1)
                        else:
                            rug_item = ClickableRugItem(dist_vec[i] / max_dist,
                                           0.85, self.on_rug_item_clicked)
                            rug_item.setPen(background_pen)
                            tooltip = experiment_description(attr)
                            rug_item.setToolTip(tooltip)

                        rug_item.group = group
                        rug_item.index = i
                        rug_item.in_group = in_group

                        rug_items.append(rug_item)

                rug_widget = RugGraphicsWidget(parent=main_widget)
                rug_widget.set_rug(rug_items)

                rug_widgets.append(rug_widget)

                label = group_label(self.selected_split_by_labels(), group)
                label_item = QGraphicsSimpleTextItem(label, main_widget)
                label_item = GraphicsSimpleTextLayoutItem(label_item, parent=layout)
                label_item.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
                labels.append(label_item)

        for i, (label, rug_w) in enumerate(zip(labels, rug_widgets)):
            layout.addItem(label, i, 0, Qt.AlignVCenter)
            layout.addItem(rug_w, i, 1)
            layout.setRowMaximumHeight(i, 30)

        main_widget.setLayout(layout)
        self.scene.addItem(main_widget)
        self.main_widget = main_widget
        self.rug_widgets = rug_widgets
        self.labels = labels
        self.on_view_resize(self.scene_view.size())
예제 #41
0
 def __init__(self, face, text):
     QGraphicsSimpleTextItem.__init__(self, text)
     self.face = face
     self._bounding_rect = self.face.get_bounding_rect()
     self._real_rect = self.face.get_real_rect()
예제 #42
0
    def draw_x_axis(self):
        lineItem = QGraphicsLineItem(self.col_w / 2,
                                     self.coordY(self.ylim[0]) + 2,
                                     self.width - self.col_w / 2,
                                     self.coordY(self.ylim[0]) + 2,
                                     parent=self.item)
        lineItem.setPen(QPen(QColor('black')))
        lineItem.setZValue(10)
        all_vals = list(range(0, len(self.values), self.x_inter_values))
        if (len(self.values) - 1) % self.x_inter_values:
            all_vals += [len(self.values) - 1]

        hp_x = []
        if self.hp:
            for x in list(range(0, len(self.values))):
                if self.x_values[x] in self.hp:
                    hp_x.append(x)
                    if not x in all_vals:
                        all_vals += [x]
        all_vals.sort()

        for x in all_vals:
            lineItem = QGraphicsLineItem(0,
                                         self.coordY(self.ylim[0]) + 2,
                                         0,
                                         self.coordY(self.ylim[0]) + 6,
                                         parent=self.item)
            lineItem.setX(x * self.col_w + self.col_w / 2)
            lineItem.setPen(QPen(QColor('black')))
            lineItem.setZValue(10)
            if x in hp_x:
                text = QGraphicsSimpleTextItem("*" + str(self.x_values[x]))
                qfont = QFont("Arial", self.fsize - 1)
                #qfont.setBold(True)
                text.setFont(qfont)
            else:
                text = QGraphicsSimpleTextItem(" " + str(self.x_values[x]))
                text.setFont(QFont("Arial", self.fsize - 1))
            text.rotate(-90)
            text.setParentItem(self.item)
            text.setZValue(10)
            tw = text.boundingRect().width()
            th = text.boundingRect().height()
            # Center text according to masterItem size
            text.setPos(x * self.col_w - th / 2 + self.col_w / 2,
                        tw + self.coordY(self.ylim[0]) + 7)
예제 #43
0
def polygon_name_face(node, *args, **kwargs):
    """create a wedge shaped face in the style of ARB

    Args:
    width (int): size in pixels for the width of the wedge
    height (int): size in pixels for the height of the wedge
    width_percent (float): change the angle of the point of the wedge.
    This must be a number between 0 and 1

    Returns:
    QGraphicsRectItem: The Qt graphics item of the polygon
    """

    n_leaves = len(node.get_leaves())
    closest_leaf_dist = node.get_closest_leaf()[1]
    farthest_leaf_dist = node.get_farthest_leaf()[1]

    base_height = 30
    width = 60
    height = math.log(n_leaves, 2) + base_height

    width_percent = closest_leaf_dist / farthest_leaf_dist

    #print(width, height, width_percent)

    points = [
    (0.0, 0.0), # top left point
    (width, 0.0), # top right point
    (width * width_percent, height), # bottom right point
    (0.0, height), # bottom left point
    (0.0, 0.0) # back to the beginning
    ]
    shape = QPolygonF()
    for i in points:
        shape << QtCore.QPointF(*i)

    ## Creates a main master Item that will contain all other elements
    ## Items can be standard QGraphicsItem
    masterItem = QGraphicsRectItem(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))

    polygon = QGraphicsPolygonItem(shape, masterItem)
    # Make the wedge grey in color
    polygon.setBrush(QBrush(QColor( '#D3D3D3')))

    # Print the name of the node
    # Center text according to masterItem size
    center = masterItem.boundingRect().center()

    text = QGraphicsSimpleTextItem(node.name)
    text.setParentItem(polygon)

    tw = text.boundingRect().width()
    th = text.boundingRect().height()
    text.setPos(center.x() + tw/2, center.y() - th/2)

    # this is a hack to prevent the name being printed twice
    # we set the node name to blank after we write it with the QGraphicsSimpleTextItem
    # it must be set to a blank string for it not to be printed later
    node.name = ''


    # print the number of collapsed leaves in the polygon
    leaves_count_text = QGraphicsSimpleTextItem('('+str(n_leaves)+')')
    leaves_count_text.setParentItem(polygon)
    leaves_count_text.setFont(QFont('Veranda', 6))
    leaves_count_text.setPos(masterItem.boundingRect().x() + 5, center.y() - leaves_count_text.boundingRect().height()/2)

    polygon.setPos(0, masterItem.boundingRect().y()/1.5)

    return masterItem
예제 #44
0
    def replot_experiments(self):
        """Replot the whole quality plot.
        """
        self.scene.clear()
        labels = []

        max_dist = numpy.nanmax(list(filter(None, self.distances)))
        rug_widgets = []

        group_pen = QPen(Qt.black)
        group_pen.setWidth(2)
        group_pen.setCapStyle(Qt.RoundCap)
        background_pen = QPen(QColor(0, 0, 250, 150))
        background_pen.setWidth(1)
        background_pen.setCapStyle(Qt.RoundCap)

        main_widget = QGraphicsWidget()
        layout = QGraphicsGridLayout()
        attributes = self.data.domain.attributes
        if self.data is not None:
            for (group, indices), dist_vec in zip(self.groups, self.distances):
                indices_set = set(indices)
                rug_items = []
                if dist_vec is not None:
                    for i, attr in enumerate(attributes):
                        # Is this a within group distance or background
                        in_group = i in indices_set
                        if in_group:
                            rug_item = ClickableRugItem(
                                dist_vec[i] / max_dist, 1.0,
                                self.on_rug_item_clicked)
                            rug_item.setPen(group_pen)
                            tooltip = experiment_description(attr)
                            rug_item.setToolTip(tooltip)
                            rug_item.group_index = indices.index(i)
                            rug_item.setZValue(rug_item.zValue() + 1)
                        else:
                            rug_item = ClickableRugItem(
                                dist_vec[i] / max_dist, 0.85,
                                self.on_rug_item_clicked)
                            rug_item.setPen(background_pen)
                            tooltip = experiment_description(attr)
                            rug_item.setToolTip(tooltip)

                        rug_item.group = group
                        rug_item.index = i
                        rug_item.in_group = in_group

                        rug_items.append(rug_item)

                rug_widget = RugGraphicsWidget(parent=main_widget)
                rug_widget.set_rug(rug_items)

                rug_widgets.append(rug_widget)

                label = group_label(self.selected_split_by_labels(), group)
                label_item = QGraphicsSimpleTextItem(label, main_widget)
                label_item = GraphicsSimpleTextLayoutItem(label_item,
                                                          parent=layout)
                label_item.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
                labels.append(label_item)

        for i, (label, rug_w) in enumerate(zip(labels, rug_widgets)):
            layout.addItem(label, i, 0, Qt.AlignVCenter)
            layout.addItem(rug_w, i, 1)
            layout.setRowMaximumHeight(i, 30)

        main_widget.setLayout(layout)
        self.scene.addItem(main_widget)
        self.main_widget = main_widget
        self.rug_widgets = rug_widgets
        self.labels = labels
        self.on_view_resize(self.scene_view.size())
예제 #45
0
    def __init__(self, dataDir="", parent=None):
        QWidget.__init__(self, parent)
        self.renderer = QSvgRenderer(dataDir + "poker.svg")
        self.scene = QGraphicsScene()
        self.chat = QGraphicsSimpleTextItem()
        self.table = QGraphicsSvgItem(dataDir + "poker.svg")
        self.table.setSharedRenderer(self.renderer)
        self.table.setElementId("table")
        self.table.setMatrix(self.renderer.matrixForElement("transform_table"))
        self.scene.addItem(self.chat)
        self.scene.addItem(self.table)
        self.board = []
        for i in range(5):
            card = AnimatedGraphicsSvgItem(dataDir + "svg-cards.svg",
                                           self.table)
            card.setElementId("back")
            parent = self.renderer.matrixForElement("transform_table")
            child = self.renderer.matrixForElement("transform_card%i" % i)
            cardMatrix = child.translate(-parent.dx(), -parent.dy())
            card.setMatrix(cardMatrix)
            #card.setFlag(QGraphicsSvgItem.ItemIsMovable, True)
            card.scale(0.5, 0.5)
            card.hide()
            self.scene.addItem(card)
            self.board.append(card)
        self.seats = []
        self.names = []
        self.moneys = []
        self.bets = []
        for i in range(10):
            seat = SeatItem()

            def seatClickedEvent(seat=i):
                seatClickedCallback = self.seatClicked
                seatClickedCallback(seat)

            seat.event = seatClickedEvent
            seat.setSharedRenderer(self.renderer)
            seat.setElementId("seat")
            seat.setMatrix(
                self.renderer.matrixForElement("transform_seat%i" % i))
            self.scene.addItem(seat)
            self.seats.append(seat)
            name = QGraphicsSimpleTextItem(seat)
            name.setMatrix(self.renderer.matrixForElement("seat_name"))
            self.scene.addItem(name)
            self.names.append(name)
            money = QGraphicsSimpleTextItem(seat)
            money.setMatrix(self.renderer.matrixForElement("seat_money"))
            self.scene.addItem(money)
            self.moneys.append(money)
            bet = QGraphicsSimpleTextItem()
            bet.setMatrix(self.renderer.matrixForElement("transform_bet%i" %
                                                         i))
            self.scene.addItem(bet)
            self.bets.append(bet)
        self.pots = []
        for i in range(9):
            pot = QGraphicsSimpleTextItem()
            pot.setMatrix(self.renderer.matrixForElement("transform_pot%i" %
                                                         i))
            self.scene.addItem(pot)
            self.pots.append(pot)
        self.view = QGraphicsView(self)
        self.view.setScene(self.scene)
        self.view.resize(800, 600)
        self.fold = ActionItem()
        self.fold.setText("fold")
        self.fold.setPos(0, 550)
        self.scene.addItem(self.fold)
        self.fold.event = lambda: self.foldClicked()
        self.check = ActionItem()
        self.check.setText("check")
        self.check.setPos(50, 550)
        self.scene.addItem(self.check)
        self.check.event = lambda: self.checkClicked()
        self.call = ActionItem()
        self.call.setText("call")
        self.call.setPos(100, 550)
        self.scene.addItem(self.call)
        self.call.event = lambda: self.callClicked()
        self.bet = ActionItem()
        self.bet.setText("bet")
        self.bet.setPos(150, 550)
        self.scene.addItem(self.bet)
        self.bet.event = lambda: self.betClicked()
예제 #46
0
 def __init__(self, txt, font=def_font, loc=(0, 0)):
     QGraphicsSimpleTextItem.__init__(self, txt)
     self.setPos(*loc)
     self.setFont(font)
예제 #47
0
파일: video.py 프로젝트: compmem/psyqt
 def __init__(self,txt,font=def_font,loc=(0,0)):
     QGraphicsSimpleTextItem.__init__(self,txt)
     self.setPos(*loc)
     self.setFont(font)
예제 #48
0
 def display_question(self, question, answers, selected_index = None, correct = None):
     self._init_scene()
     x = 50
     y = 25
     item =  QGraphicsSimpleTextItem(question)
     item.setBrush(self.TEXT_COLOR)
     item.setFont(self.BOLDISH) 
     item.setX(x)
     item.setY(y)
     self.qtscene.addItem(item)
     self.references.append(item)
     y += 75
     
     for index, answer in enumerate(answers):
         index += 1
         item =  QGraphicsSimpleTextItem("%s) %s" % (index, answer))
         item.setBrush(self.TEXT_COLOR)
         item.setFont(self.NORMALISH) 
         item.setX(x)
         item.setY(y)
         item.setAcceptHoverEvents(True)
         self.qtscene.addItem(item)
         self.references.append(item)
         #TODO: do not register click but do show check or not
         if not selected_index:
             item.hoverEnterEvent = partial(self.on_hover_answer, item) 
             item.hoverLeaveEvent = partial(self.on_unhover_answer, item) 
             item.mousePressEvent = partial(self.on_click_answer, index) 
         elif selected_index == index:
             if correct:
                 item =  QGraphicsSimpleTextItem(u"\u2713")
                 item.setBrush(QBrush(QColor(0,150,0)))
                 item.setX(0)
             else:
                 item =  QGraphicsSimpleTextItem("X")
                 item.setBrush(QBrush(QColor(255,0,0)))
                 item.setX(3)
             item.setFont(self.BOLDISH)
             item.setY(y)
             self.qtscene.addItem(item)
             self.references.append(item)
             
         y += 50
     return x, y
예제 #49
0
 def display_answer(self, question, answers, correct_answer, description, selected_index, correct):
     x, y = self.display_question(question, answers, selected_index, correct) #TODO pass what to check and if right or wrong
     y += 50
     item =  QGraphicsSimpleTextItem("Correct Answer: %s" % correct_answer)
     item.setBrush(self.TEXT_COLOR)
     font = QFont(self.BOLDISH)
     font.setUnderline(True)
     item.setFont(font) 
     item.setX(x)
     item.setY(y)
     self.qtscene.addItem(item)
     self.references.append(item)
     
     y += 60
     item =  QGraphicsSimpleTextItem(make_pretty(description, 55))
     item.setBrush(self.TEXT_COLOR)
     item.setFont(self.NORMALISH) 
     item.setX(x)
     item.setY(y)
     self.qtscene.addItem(item)
     self.references.append(item)
     
     item = QPushButton('Next')
     item.clicked.connect(self.on_next)
     item.setFont(self.BOLDISH) 
     item.move(x+700, y)
     self.qtscene.addWidget(item)
     self.references.append(item)
예제 #50
0
 def draw_y_axis(self):
     lineItem = QGraphicsLineItem(0,
                                  self.coordY(self.ylim[0]),
                                  0,
                                  self.coordY(self.ylim[1]),
                                  parent=self.item)
     lineItem.setPen(QPen(QColor('black')))
     lineItem.setZValue(10)
     max_w = 0
     for y in set(self.hlines + list(self.ylim)):
         lineItem = QGraphicsLineItem(0,
                                      self.coordY(y),
                                      -5,
                                      self.coordY(y),
                                      parent=self.item)
         lineItem.setPen(QPen(QColor('black')))
         lineItem.setZValue(10)
         text = QGraphicsSimpleTextItem(str(y))
         text.setFont(QFont("Arial", self.fsize - 2))
         text.setParentItem(self.item)
         tw = text.boundingRect().width()
         max_w = tw if tw > max_w else max_w
         th = text.boundingRect().height()
         # Center text according to masterItem size
         text.setPos(-tw - 5, self.coordY(y) - th / 2)
     if self.ylabel:
         text = QGraphicsSimpleTextItem(self.ylabel)
         text.setFont(QFont("Arial", self.fsize - 1))
         text.setParentItem(self.item)
         text.rotate(-90)
         tw = text.boundingRect().width()
         th = text.boundingRect().height()
         # Center text according to masterItem size
         text.setPos(-th - 5 - max_w,
                     tw / 2 + self.coordY(sum(self.ylim) / 2))
예제 #51
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
예제 #52
0
 def add_text(self):
     if (self.labels):
         center = self.item.boundingRect().center()
         text = QGraphicsSimpleTextItem(str(self.labels))
         text.setFont(QFont("Arial", self.label_size))
         text.setParentItem(self.item)
         text.setBrush(QBrush(QColor('#ddd')))
         tw = text.boundingRect().width() / 2.
         th = text.boundingRect().height() / 2.
         x = -tw + center.x()
         y = -th + center.y()
         # Center text according to masterItem size
         text.setPos(x, y)