Esempio n. 1
0
 def __init__(self, future_build_info, x=0, y=0, selectable=True):
     QGraphicsRectItem.__init__(self, x, y, self.WIDTH, self.WIDTH)
     self.future_build_info = future_build_info
     if selectable:
         self.setFlags(self.ItemIsSelectable | self.ItemIsFocusable)
     else:
         self.setFlags(self.ItemIsFocusable)
Esempio n. 2
0
    def paint(self, painter, option, widget):
        """ Draws a filled rectangle and then adds a title """

        # Hide the dotted outline
        itemOption = QStyleOptionGraphicsItem(option)
        if itemOption.state & QStyle.State_Selected != 0:
            itemOption.state = itemOption.state & ~QStyle.State_Selected

        # Draw the rectangle
        pen = painter.pen()
        pen.setJoinStyle(Qt.RoundJoin)
        painter.setPen(pen)
        QGraphicsRectItem.paint(self, painter, itemOption, widget)

        # Draw text over the rectangle
        font = QFont("Arial", 10)
        painter.setFont(font)
        painter.setPen(QPen(QColor(255, 255, 255)))
        painter.drawText(self.__node.posX - self.__node.width / 2.0,
                         self.__node.posY - self.__node.height / 2.0,
                         self.__node.width, self.__node.height, Qt.AlignCenter,
                         self.__node.label.replace('\\n', '\n'))

        if self.__outside:
            pixmap = PixmapCache().getPixmap("nonprojectentrydgm.png")
            pixmapPosX = self.__node.posX - self.__node.width / 2.0 + 2
            pixmapPosY = self.__node.posY + self.__node.height / 2.0 - \
                         pixmap.height() - 2
            painter.setRenderHint(QPainter.SmoothPixmapTransform)
            painter.drawPixmap(pixmapPosX, pixmapPosY, pixmap)
        return
Esempio n. 3
0
 def keyPressEvent(self, event):
     """navigate in the board"""
     key = Board.mapChar2Arrow(event)
     if key in Board.arrows:
         self.__moveCursor(key)
     else:
         QGraphicsRectItem.keyPressEvent(self, event)
Esempio n. 4
0
    def __init__(self, node, fileName, lineNumber, outside):
        QGraphicsRectItem.__init__(self)
        self.__node = node
        self.__fileName = fileName
        self.__lineNumber = lineNumber
        self.__outside = outside

        posX = node.posX - node.width / 2.0
        posY = node.posY - node.height / 2.0
        QGraphicsRectItem.__init__(self, posX, posY, node.width, node.height)

        self.setRectanglePen()

        # node.color is like "#fe0400"
        if node.color.startswith("#"):
            color = QColor(int(node.color[1:3], 16), int(node.color[3:5], 16),
                           int(node.color[5:], 16))
        else:
            color = QColor(220, 255, 220)
        self.setBrush(color)

        # To make item selectable
        self.setFlag( QGraphicsItem.ItemIsSelectable,
                      os.path.isabs( self.__fileName ) and \
                      self.__lineNumber > 0 )

        # Set tooltip as a function docstring
        if fileName != "" and lineNumber != 0:
            self.setToolTip( \
                    GlobalData().getFileLineDocstring( fileName, lineNumber ) )
        return
Esempio n. 5
0
 def __init__(self, rect):
     QGraphicsRectItem.__init__(self, rect)
     self._color = None
     self._darkColor = None
     self._pos = None
     self._value = 0
     self._label = ""
Esempio n. 6
0
 def mouseReleaseEvent(self, e):
     """ !!! This method does not receive control because module is distracted before...
     """
     #print 'mouseReleaseEvent'
     QGraphicsRectItem.mouseReleaseEvent(self, e)
     #QtGui.QApplication.setOverrideCursor(QtGui.QCursor(self.hover_cursor))
     QtGui.QApplication.restoreOverrideCursor()
Esempio n. 7
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)
 class InteractiveLetterItem(QGraphicsRectItem):
     """This is a class"""
     def __init__(self, *arg, **karg):
         QGraphicsRectItem.__init__(self, *arg, **karg)
         self.codon = None
         self.label = None
         self.setAcceptsHoverEvents(True)
 
     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)
 
     def hoverLeaveEvent(self, e):
         """when mouse leaves area"""
         if self.label: 
             self.label.setVisible(False)
             self.setZValue(0)
Esempio n. 9
0
    def update_items(self):
        self.item = QGraphicsRectItem(-30, 0, self.width + 40,
                                      self.height + 70)
        #self.item.setPen(QPen(QColor('gray')))
        self.item.setPen(QPen(QColor('white')))

        try:
            put_colored_boxes = self.put_colored_boxes
        except AttributeError:
            put_colored_boxes = (False, 0)

        if put_colored_boxes[0]:
            (_, tree_h) = put_colored_boxes
            self.draw_colored_boxes(tree_h)

        # draw lines
        for line, col in zip(self.hlines, self.hlines_col):
            self.draw_hlines(line, col)
        # draw plot
        width = self.col_w
        for i, val in enumerate(self.values):
            self.draw_fun(width * i + self.col_w / 2, val, i)
        # draw error bars
        if self.errors:
            for i in range(len(self.errors)):
                self.draw_errors(width * i + self.col_w / 2, i)
        # draw x axis
        self.draw_x_axis()
        # draw y axis
        self.draw_y_axis()
        # put header
        self.write_header()
Esempio n. 10
0
    def __init__(self,
                 parent,
                 name='Untitled',
                 width=180,
                 height=40,
                 blockColor="#A5A2A5",
                 data=None,
                 bold=False,
                 italic=False,
                 status=True):
        """
        Constructor
        """
        QGraphicsRectItem.__init__(self)

        self.parentWidget = parent
        self.internalData = data
        self.status = status

        color = QColor(0, 0, 0)
        color.setNamedColor(blockColor)
        self.setPen(QPen(color, 2))

        if sys.version_info > (3, ) and isinstance(name, bytes):
            name = str(name, "utf8", errors="ignore")

        self.label = QGraphicsTextItem(name, self)

        self.setFlags(self.ItemIsSelectable)
        self.setCursor(QCursor(Qt.PointingHandCursor))

        self.changeSize(width, height)
Esempio n. 11
0
    def paint( self, painter, option, widget ):
        """ Draws a filled rectangle and then adds a title """

        # Hide the dotted outline
        itemOption = QStyleOptionGraphicsItem( option )
        if itemOption.state & QStyle.State_Selected != 0:
            itemOption.state = itemOption.state & ~QStyle.State_Selected

        # Draw the rectangle
        QGraphicsRectItem.paint( self, painter, itemOption, widget )

        # Draw text over the rectangle
        font = QFont( "Arial", 10 )
        painter.setFont( font )
        painter.drawText( self.__node.posX - self.__node.width / 2.0,
                          self.__node.posY - self.__node.height / 2.0,
                          self.__node.width, self.__node.height,
                          Qt.AlignCenter, self.__srcobj.text )

        pixmap = PixmapCache().getPixmap( "docstring.png" )
        pixmapPosX = self.__node.posX + self.__node.width / 2.0 - \
                     pixmap.width() / 2.0
        pixmapPosY = self.__node.posY - self.__node.height / 2.0 - \
                     pixmap.height() / 2.0
        painter.setRenderHint( QPainter.SmoothPixmapTransform )
        painter.drawPixmap( pixmapPosX, pixmapPosY, pixmap )
        return
Esempio n. 12
0
    class InteractiveLetterItem(QGraphicsRectItem):
        """This is a class"""
        def __init__(self, *arg, **karg):
            QGraphicsRectItem.__init__(self, *arg, **karg)
            self.codon = None
            self.label = None
            self.setAcceptsHoverEvents(True)

        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)

        def hoverLeaveEvent(self, e):
            """when mouse leaves area"""
            if self.label:
                self.label.setVisible(False)
                self.setZValue(0)
Esempio n. 13
0
    def paint(self, painter, option, widget):
        """ Draws a filled rectangle and then adds a title """

        # Hide the dotted outline
        itemOption = QStyleOptionGraphicsItem(option)
        if itemOption.state & QStyle.State_Selected != 0:
            itemOption.state = itemOption.state & ~QStyle.State_Selected

        # Draw the rectangle
        QGraphicsRectItem.paint(self, painter, itemOption, widget)

        # Draw text over the rectangle
        font = QFont("Arial", 10)
        painter.setFont(font)
        painter.drawText(self.__node.posX - self.__node.width / 2.0,
                         self.__node.posY - self.__node.height / 2.0,
                         self.__node.width, self.__node.height, Qt.AlignCenter,
                         self.__srcobj.text)

        pixmap = PixmapCache().getPixmap("docstring.png")
        pixmapPosX = self.__node.posX + self.__node.width / 2.0 - \
                     pixmap.width() / 2.0
        pixmapPosY = self.__node.posY - self.__node.height / 2.0 - \
                     pixmap.height() / 2.0
        painter.setRenderHint(QPainter.SmoothPixmapTransform)
        painter.drawPixmap(pixmapPosX, pixmapPosY, pixmap)
        return
Esempio n. 14
0
    def mousePressEvent(self, event):
        pos = event.scenePos()
        any_item = self.scene.item_at(pos)
        if not any_item and event.button() & Qt.LeftButton:
            self.modifiers = event.modifiers()
            self.selection_rect = QRectF(pos, QSizeF(0, 0))
            self.rect_item = QGraphicsRectItem(
                self.selection_rect.normalized())

            self.rect_item.setPen(
                QPen(QBrush(QColor(51, 153, 255, 192)), 0.4, Qt.SolidLine,
                     Qt.RoundCap))

            self.rect_item.setBrush(QBrush(QColor(168, 202, 236, 192)))

            self.rect_item.setZValue(-100)

            # Clear the focus if necessary.
            if not self.scene.stickyFocus():
                self.scene.clearFocus()

            if not self.modifiers & Qt.ControlModifier:
                self.scene.clearSelection()

            event.accept()
            return True
        else:
            self.cancel(self.ErrorReason)
            return False
Esempio n. 15
0
 def __init__(self, future_build_info, x=0, y=0, selectable=True):
     QGraphicsRectItem.__init__(self, x, y, self.WIDTH, self.WIDTH)
     self.future_build_info = future_build_info
     if selectable:
         self.setFlags(self.ItemIsSelectable | self.ItemIsFocusable)
     else:
         self.setFlags(self.ItemIsFocusable)
Esempio n. 16
0
 def __init__(self, bgc_info, *args, **kargs):
     QGraphicsRectItem.__init__(self, *args, **kargs)
     self.node = None
     self.label = None
     self.bgc_info = bgc_info
     self.setCursor(QtCore.Qt.PointingHandCursor)
     self.setAcceptsHoverEvents(True)
Esempio n. 17
0
 def keyPressEvent(self, event):
     """navigate in the board"""
     key = Board.mapChar2Arrow(event)
     if key in Board.arrows:
         self.__moveCursor(key)
     else:
         QGraphicsRectItem.keyPressEvent(self, event)
Esempio n. 18
0
    def __init__(self, title, palette, values, parent):
        QGraphicsObject.__init__(self, parent)
        GraphicsWidgetAnchor.__init__(self)
        self.parent = self.legend = parent
        self.palette = palette
        self.values = values

        self.title = QGraphicsTextItem('%s:' % title, self)
        f = self.title.font()
        f.setBold(True)
        self.title.setFont(f)
        self.title_item = QGraphicsRectItem(self.title.boundingRect(), self)
        self.title_item.setPen(QPen(Qt.NoPen))
        self.title_item.stackBefore(self.title)

        self.label_items = [QGraphicsTextItem(text, self) for text in values]
        for i in self.label_items:
            i.setTextWidth(50)

        self.rect = QRectF()

        self.gradient_item = QGraphicsRectItem(self)
        self.gradient = QLinearGradient()
        self.gradient.setStops([(v * 0.1, self.palette[v * 0.1])
                                for v in range(11)])
        self.orientation = Qt.Horizontal
        self.set_orientation(Qt.Vertical)

        self.setFlag(QGraphicsItem.ItemIgnoresTransformations, True)
        self.setFlag(QGraphicsItem.ItemIsMovable, True)
Esempio n. 19
0
    def __init__( self, node, fileName, lineNumber, outside ):
        QGraphicsRectItem.__init__( self )
        self.__node = node
        self.__fileName = fileName
        self.__lineNumber = lineNumber
        self.__outside = outside

        posX = node.posX - node.width / 2.0
        posY = node.posY - node.height / 2.0
        QGraphicsRectItem.__init__( self, posX, posY,
                                    node.width, node.height )

        self.setRectanglePen()

        # node.color is like "#fe0400"
        if node.color.startswith( "#" ):
            color = QColor( int( node.color[ 1:3 ], 16 ),
                            int( node.color[ 3:5 ], 16 ),
                            int( node.color[ 5: ], 16 ) )
        else:
            color = QColor( 220, 255, 220 )
        self.setBrush( color )

        # To make item selectable
        self.setFlag( QGraphicsItem.ItemIsSelectable,
                      os.path.isabs( self.__fileName ) and \
                      self.__lineNumber > 0 )

        # Set tooltip as a function docstring
        if fileName != "" and lineNumber != 0:
            self.setToolTip( \
                    GlobalData().getFileLineDocstring( fileName, lineNumber ) )
        return
Esempio n. 20
0
    def paint( self, painter, option, widget ):
        """ Draws a filled rectangle and then adds a title """

        # Hide the dotted outline
        itemOption = QStyleOptionGraphicsItem( option )
        if itemOption.state & QStyle.State_Selected != 0:
            itemOption.state = itemOption.state & ~QStyle.State_Selected

        # Draw the rectangle
        pen = painter.pen()
        pen.setJoinStyle( Qt.RoundJoin )
        painter.setPen( pen )
        QGraphicsRectItem.paint( self, painter, itemOption, widget )

        # Draw text over the rectangle
        font = QFont( "Arial", 10 )
        painter.setFont( font )
        painter.setPen( QPen( QColor( 255, 255, 255 ) ) )
        painter.drawText( self.__node.posX - self.__node.width / 2.0,
                          self.__node.posY - self.__node.height / 2.0,
                          self.__node.width, self.__node.height,
                          Qt.AlignCenter,
                          self.__node.label.replace( '\\n', '\n' ) )

        if self.__outside:
            pixmap = PixmapCache().getPixmap( "nonprojectentrydgm.png" )
            pixmapPosX = self.__node.posX - self.__node.width / 2.0 + 2
            pixmapPosY = self.__node.posY + self.__node.height / 2.0 - \
                         pixmap.height() - 2
            painter.setRenderHint( QPainter.SmoothPixmapTransform )
            painter.drawPixmap( pixmapPosX, pixmapPosY, pixmap )
        return
Esempio n. 21
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)
Esempio n. 22
0
 def hide(self):
     """remove all tile references so they can be garbage collected"""
     for tile in self.tiles:
         tile.hide()
     self.tiles = []
     self._focusTile = None
     if isAlive(self):
         QGraphicsRectItem.hide(self)
Esempio n. 23
0
 def __init__(self, parent, start, stop, refobj, slot):
     QGraphicsRectItem.__init__(self, start, 0, stop-start, parent.height, parent)
     self.refobj = refobj
     self.slot = slot
     self.brush = self.__class__.inactive_brush
     self.setPen(QPen(Qt.NoPen))
     self.setCursor(Qt.PointingHandCursor)
     self.setAcceptsHoverEvents(True)
Esempio n. 24
0
 def setEnabled(self, enabled):
     """enable/disable this board"""
     if isAlive(self):
         # aborting a running game: the underlying C++ object might
         # already have been destroyed
         self.tileDragEnabled = enabled and \
         (self.player.game.isScoringGame() or self.player == self.player.game.myself)
         QGraphicsRectItem.setEnabled(self, enabled)
Esempio n. 25
0
    def __init__(self, rect, parent=None, scene=None):
        QGraphicsRectItem.__init__(self, rect, parent, scene)

        self.setAcceptHoverEvents(True)
        self.setAcceptTouchEvents(True)
        #self.setAcceptedMouseButtons(Qt.LeftButton)
        self.setCursorHover()
        self.setCursorGrab()
Esempio n. 26
0
    def __init__(self, ref, canvas, x, y, kind):
        ScopeCellElement.__init__(self, ref, canvas, x, y)
        QGraphicsRectItem.__init__(self)
        self.kind = CellElement.DECOR_SCOPE
        self.subKind = kind

        # To make double click delivered
        self.setFlag(QGraphicsItem.ItemIsSelectable, True)
        return
Esempio n. 27
0
 def __init__(self, parent, start, stop, refobj, slot):
     QGraphicsRectItem.__init__(self, start, 0, stop - start, parent.height,
                                parent)
     self.refobj = refobj
     self.slot = slot
     self.brush = self.__class__.inactive_brush
     self.setPen(QPen(Qt.NoPen))
     self.setCursor(Qt.PointingHandCursor)
     self.setAcceptsHoverEvents(True)
Esempio n. 28
0
 def __init__(self, text, parent):
     QGraphicsObject.__init__(self, parent)
     self.text_item = QGraphicsTextItem(text + ':', self)
     f = self.text_item.font()
     f.setBold(True)
     self.text_item.setFont(f)
     self.rect_item = QGraphicsRectItem(self.text_item.boundingRect(), self)
     self.rect_item.setPen(QPen(Qt.NoPen))
     self.rect_item.stackBefore(self.text_item)
Esempio n. 29
0
 def __init__(self, side):
     QGraphicsRectItem.__init__(self, side)
     self.side = side
     self.font = QFont()
     self.font.setPointSize(48)
     self.height = 62
     self.width = 200
     self.msg = None
     self.setText('')
Esempio n. 30
0
    def __init__( self, ref, canvas, x, y, kind ):
        ScopeCellElement.__init__( self, ref, canvas, x, y )
        QGraphicsRectItem.__init__( self )
        self.kind = CellElement.DECOR_SCOPE
        self.subKind = kind

        # To make double click delivered
        self.setFlag( QGraphicsItem.ItemIsSelectable, True )
        return
Esempio n. 31
0
 def __init__(self, side):
     QGraphicsRectItem.__init__(self, side)
     self.side = side
     self.font = QFont()
     self.font.setPointSize(48)
     self.height = 62
     self.width = 200
     self.msg = None
     self.setText('')
Esempio n. 32
0
class TextItem(QObject):

	def __init__(self, text, scene, dimensions, transform_fn):
		"""\
		transform_fn(dimensions, w, h): returns a QTransform

		 * dimensions: plotter dimension object
		 * w: text width in pixels
		 * h: text height in pixels
		"""
		QObject.__init__(self)

		self.text = text
		self.scene = scene
		self.dimensions = dimensions
		self.transform = transform_fn

		self.text_item = None
		self.rect = None
		for signal in text.changed, dimensions.changed:
			signal.connect(self.update)

		self.update()

	def update(self):
		# Delete previous text item
		if self.text_item != None:
			self.scene.removeItem(self.text_item)
			# Line below not for QGraphicsSimpleTextItem
			self.text_item.deleteLater()
			self.scene.removeItem(self.rect)

		# Exit if any parameters unset
		if self.text.text == None or self.text.style == None:
			return

		self.text_item = self.get_text_item()
		size = self.text_item.boundingRect()
		w = size.width()
		h = size.height()
		transform = self.transform(self.dimensions, w, h)
		self.text_item.setTransform(transform)
		self.scene.addItem(self.text_item)

		self.rect = QGraphicsRectItem(0,0, w,h)
		self.rect.setTransform(transform)
		if config.debug.plotter.show_text_boxes:
			self.scene.addItem(self.rect)

	def get_text_item(self):
		text_item = QGraphicsTextItem(self.text.text, None)
		text_item.setDefaultTextColor(self.text.style.colour) # QGraphicsTextItem
		#text_item.setPen(self.text.style.colour) # QGraphicsSimpleTextItem
		text_item.setFont(self.text.style.font)
		text_item.setPos(0,0)
		return text_item
Esempio n. 33
0
 def __init__(self,settings,i,j,cellI,cellJ,state=0):
     QGraphicsRectItem.__init__(self,
                                j*(settings.atomWidth+settings.atomMargin) + cellJ*settings.cellMargin + settings.edgeLeftMargin,
                                i*(settings.atomHeight+settings.atomMargin) + cellI*settings.cellMargin + settings.edgeTopMargin,
                                settings.atomWidth,
                                settings.atomHeight)
     self.settings = settings
     self.i = i
     self.j = j
     self.state = state
Esempio n. 34
0
 def __init__(self, font_loader, logger, opts, width=0, height=0, parent=None, x=0, y=0):
     QGraphicsRectItem.__init__(self, x, y, width, height, parent)
     self.font_loader, self.logger, self.opts = font_loader, logger, opts
     self.current_y, self.max_y, self.max_x = 0, height, width
     self.is_full = False
     pen = QPen()
     pen.setStyle(Qt.NoPen)
     self.setPen(pen)
     if not hasattr(self, "children"):
         self.children = self.childItems
Esempio n. 35
0
 def __init__(self,
              pen=QPen(Qt.black),
              brush=QBrush(Qt.white),
              xData=None,
              yData=None,
              tooltip=None):
     OWCurve.__init__(self, xData, yData, tooltip=tooltip)
     self.set_pen(pen)
     self.set_brush(brush)
     self._item = QGraphicsRectItem(self)
Esempio n. 36
0
 def __init__(self):
     QGraphicsScene.__init__(self)
     self.__disableFocusRect = False
     self._focusBoard = None
     self.focusRect = QGraphicsRectItem()
     pen = QPen(QColor(Qt.blue))
     pen.setWidth(6)
     self.focusRect.setPen(pen)
     self.addItem(self.focusRect)
     self.focusRect.setZValue(ZValues.marker)
     self.focusRect.hide()
Esempio n. 37
0
 def computeRect(self):
     """translate from our rect coordinates to scene coord"""
     sizeX = self.tileset.faceSize.width() * self.__fixedWidth
     sizeY = self.tileset.faceSize.height() * self.__fixedHeight
     if self.showShadows:
         sizeX += self.tileset.shadowWidth() + 2 * self.tileset.shadowHeight()
         sizeY += self.tileset.shadowHeight()
     rect = self.rect()
     rect.setWidth(sizeX)
     rect.setHeight(sizeY)
     self.prepareGeometryChange()
     QGraphicsRectItem.setRect(self, rect)
Esempio n. 38
0
 def computeRect(self):
     """translate from our rect coordinates to scene coord"""
     sizeX = self.tileset.faceSize.width() * self.__fixedWidth
     sizeY = self.tileset.faceSize.height() * self.__fixedHeight
     if self.showShadows:
         sizeX += self.tileset.shadowWidth() + 2 * self.tileset.shadowHeight()
         sizeY += self.tileset.shadowHeight()
     rect = self.rect()
     rect.setWidth(sizeX)
     rect.setHeight(sizeY)
     self.prepareGeometryChange()
     QGraphicsRectItem.setRect(self, rect)
Esempio n. 39
0
    def __init__(self, node):
        QGraphicsRectItem.__init__(self)
        self.__node = node

        posX = node.posX - node.width / 2.0
        posY = node.posY - node.height / 2.0
        QGraphicsRectItem.__init__(self, posX, posY, node.width, node.height)
        pen = QPen(QColor(0, 0, 0))
        pen.setWidth(2)
        self.setPen(pen)

        self.setBrush(QColor(216, 216, 207))
        return
Esempio n. 40
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)
Esempio n. 41
0
    def _setSceneRect(self):
        w, h = self.dataShape
        rect = self.data2scene.mapRect(QRect(0, 0, w, h))
        sw, sh = rect.width(), rect.height()
        self.setSceneRect(0, 0, sw, sh)

        #this property represent a parent to QGraphicsItems which should
        #be clipped to the data, such as temporary capped lines for brushing.
        #This works around ilastik issue #516.
        self.dataRect = QGraphicsRectItem(0, 0, sw, sh)
        self.dataRect.setPen(QPen(QColor(0, 0, 0, 0)))
        self.dataRect.setFlag(QGraphicsItem.ItemClipsChildrenToShape)
        self.addItem(self.dataRect)
Esempio n. 42
0
    def __init__(self, x, y, h, w, scene=None, parent=None, editor=None):
        """"
        This class implements the resizable rectangle item which is dispalied on the scene
         x y should be the original positions in scene coordinates
         h,w are the height and the width of the rectangle
        """

        self._editor = editor

        QGraphicsRectItem.__init__(self,
                                   0,
                                   0,
                                   w,
                                   h,
                                   scene=scene,
                                   parent=parent)
        self.Signaller = QGraphicsResizableRectSignaller(parent=parent)

        #Default Appearence Properties
        self._fontColor = QColor(255, 255, 255)
        self._fontSize = 10
        self._lineWidth = 1

        ##Note: need to do like this because the x,y of the graphics item fix the position
        # of the zero relative to the scene
        self.moveBy(x, y)

        #Flags
        self.setFlag(QGraphicsItem.ItemIsMovable, True)
        self.setFlag(QGraphicsItem.ItemIsSelectable, True)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True)

        self.setAcceptHoverEvents(True)
        self.setAcceptedMouseButtons(Qt.LeftButton | Qt.RightButton)

        self._resizeHandles = []

        # A bit of flags
        self._hovering = False
        self._normalColor = QColor(0, 0, 255)
        self.updateColor()
        self._has_moved = False
        self._selected = False
        self._dbg = False
        self._setupTextItem()
        self._isFixed = False

        self.initHandles()
        self.hideHandles()

        self.setToolTip("Hold CTRL to drag the box")
Esempio n. 43
0
    def __init__( self, node ):
        QGraphicsRectItem.__init__( self )
        self.__node = node

        posX = node.posX - node.width / 2.0
        posY = node.posY - node.height / 2.0
        QGraphicsRectItem.__init__( self, posX, posY,
                                    node.width, node.height )
        pen = QPen( QColor( 0, 0, 0) )
        pen.setWidth( 2 )
        self.setPen( pen )

        self.setBrush( QColor( 216, 216, 207 ) )
        return
 def __init__(self,x,y,h,w,scene=None,parent=None):
     """"
     This class implements the resizable rectangle item which is dispalied on the scene
      x y should be the original positions in scene coordinates
      h,w are the height and the width of the rectangle
     """    
 
     QGraphicsRectItem.__init__(self,0,0,w,h,scene=scene,parent=parent)
     self.Signaller=QGraphicsResizableRectSignaller(parent=parent)
 
 
     #Default Appearence Properties
     self._fontColor=QColor(255, 255, 255)
     self._fontSize=10
     self._lineWidth=1
     
     
     
     
     ##Note: need to do like this because the x,y of the graphics item fix the position 
     # of the zero relative to the scene
     self.moveBy(x,y)
     self.width=w
     self.height=h
     self.shape=(h,w)
     
     #Flags
     self.setFlag(QGraphicsItem.ItemIsMovable,True  )
     self.setFlag(QGraphicsItem.ItemIsSelectable,True)
     self.setFlag(QGraphicsItem.ItemSendsGeometryChanges ,True)
      
     #self.setFlag(QtGui.QGraphicsItem.ItemIsFocusable,True)
     self.setAcceptHoverEvents(True)
     self.setAcceptedMouseButtons(Qt.LeftButton | Qt.RightButton)
     
     
     self._resizeHandles=[]
     
     # A bit of flags
     self._hovering=False
     self._normalColor   = QColor(0, 0, 255)
     self.updateColor()
     self._has_moved=False
     self._selected=False
     self._dbg=False
     self._setupTextItem() 
     self._isFixed = False
     
     self.resetHandles()
Esempio n. 45
0
 def setGeometry(self):
     """move the board to the correct position and set its rect surrounding all its
     items. This is needed for enabling drops into the board.
     This is also called when the tileset or the light source for this board changes"""
     width = self.tileset.faceSize.width()
     height = self.tileset.faceSize.height()
     if not self.showShadows:
         offsets = (0, 0)
     elif self.isHandBoard:
         offsets = (-self.tileset.shadowHeight() * 2, 0)
     else:
         offsets = self.tileset.shadowOffsets(self._lightSource, self.sceneRotation())
     newX = self.xWidth*width+self.xHeight*height + offsets[0]
     newY = self.yWidth*width+self.yHeight*height + offsets[1]
     QGraphicsRectItem.setPos(self, newX, newY)
Esempio n. 46
0
 def maximize(self):
     """make it as big as possible within the wall"""
     cWall = Internal.field.game.wall
     newSceneX = cWall[3].sceneBoundingRect().right()
     newSceneY = cWall[2].sceneBoundingRect().bottom()
     QGraphicsRectItem.setPos(self, newSceneX, newSceneY)
     tileset = self.tileset
     avail = (cWall[2].sceneBoundingRect().width()
         - 2 * tileset.shadowHeight()
         - tileset.faceSize.height())
     xScaleFactor = avail / (self.width * tileset.faceSize.width() + tileset.shadowWidth())
     yScaleFactor = avail / (self.height * tileset.faceSize.height() + tileset.shadowHeight())
     Board.setScale(self, min(xScaleFactor, yScaleFactor))
     for tile in self.tiles:
         tile.board.placeTile(tile)
Esempio n. 47
0
 def setGeometry(self):
     """move the board to the correct position and set its rect surrounding all its
     items. This is needed for enabling drops into the board.
     This is also called when the tileset or the light source for this board changes"""
     width = self.tileset.faceSize.width()
     height = self.tileset.faceSize.height()
     if not self.showShadows:
         offsets = (0, 0)
     elif self.isHandBoard:
         offsets = (-self.tileset.shadowHeight() * 2, 0)
     else:
         offsets = self.tileset.shadowOffsets(self._lightSource, self.sceneRotation())
     newX = self.xWidth*width+self.xHeight*height + offsets[0]
     newY = self.yWidth*width+self.yHeight*height + offsets[1]
     QGraphicsRectItem.setPos(self, newX, newY)
Esempio n. 48
0
 def maximize(self):
     """make it as big as possible within the wall"""
     cWall = InternalParameters.field.game.wall
     newSceneX = cWall[3].sceneBoundingRect().right()
     newSceneY = cWall[2].sceneBoundingRect().bottom()
     QGraphicsRectItem.setPos(self, newSceneX, newSceneY)
     tileset = self.tileset
     avail = (cWall[2].sceneBoundingRect().width()
         - 2 * tileset.shadowHeight()
         - tileset.faceSize.height())
     xScaleFactor = avail / (self.width * tileset.faceSize.width() + tileset.shadowWidth())
     yScaleFactor = avail / (self.height * tileset.faceSize.height() + tileset.shadowHeight())
     Board.setScale(self, min(xScaleFactor, yScaleFactor))
     for tile in self.tiles:
         tile.board.placeTile(tile)
Esempio n. 49
0
    def paint( self, painter, option, widget ):
        """ Draws a filled rectangle and then adds a title """

        # Draw the rectangle
        QGraphicsRectItem.paint( self, painter, option, widget )

        # Draw text over the rectangle
        font = QFont( "Arial", 10 )
        font.setBold( True )
        painter.setFont( font )
        painter.setPen( QPen( QColor( 90, 90, 88 ) ) )
        painter.drawText( self.__node.posX - self.__node.width / 2.0,
                          self.__node.posY - self.__node.height / 2.0,
                          self.__node.width, self.__node.height,
                          Qt.AlignCenter, self.__node.label )
        return
Esempio n. 50
0
    def paint(self, painter, option, widget):
        """ Draws a filled rectangle and then adds a title """

        # Draw the rectangle
        QGraphicsRectItem.paint(self, painter, option, widget)

        # Draw text over the rectangle
        font = QFont("Arial", 10)
        font.setBold(True)
        painter.setFont(font)
        painter.setPen(QPen(QColor(90, 90, 88)))
        painter.drawText(self.__node.posX - self.__node.width / 2.0,
                         self.__node.posY - self.__node.height / 2.0,
                         self.__node.width, self.__node.height, Qt.AlignCenter,
                         self.__node.label)
        return
Esempio n. 51
0
    def __init__(self,
                 values,
                 errors=None,
                 colors=None,
                 header='',
                 fsize=9,
                 height=0,
                 hlines=None,
                 kind='bar',
                 hlines_col=None,
                 extras=None,
                 col_width=11,
                 ylim=None,
                 xlabel='',
                 ylabel=''):

        self.col_w = float(col_width)
        self.height = height
        #        self.values = [float(v) for v in values]
        self.values = [int(v) for v in values]
        self.width = self.col_w * len(self.values)
        self.errors = errors if errors else []
        self.colors = colors if colors else ['gray'] * len(self.values)
        self.header = header
        self.fsize = fsize
        if ylim:
            self.ylim = tuple((float(y) for y in ylim))
        else:
            self.ylim = (int(min(self.values) - 0.5),
                         int(max(self.values) + 0.5))
        self.xlabel = xlabel
        self.ylabel = ylabel

        if self.errors:
            if type(self.errors[0]) is list or type(self.errors[0]) is tuple:
                self._up_err = [float(e[1]) for e in self.errors]
                self._dw_err = [float(-e[0]) for e in self.errors]
            else:
                self._up_err = [float(e) for e in self.errors]
                self._dw_err = [float(-e) for e in self.errors]
        if kind == 'bar':
            self.draw_fun = self.draw_bar
        elif kind == 'stick':
            self.draw_fun = self.draw_stick
        elif kind == 'curve':
            self.draw_fun = self.draw_curve
        else:
            raise 'kind %s not yet implemented... ;)'

        self.hlines = [float(h) for h in hlines] if hlines else [1.0]
        self.hlines_col = hlines_col if hlines_col else ['black'] * len(
            self.hlines)

        self.extras = extras if extras else ['']
        if len(self.extras) != len(self.values):
            self.extras = ['']

        super(RulerFace, self).__init__(
            QGraphicsRectItem(-40, 0, self.width + 40, self.height + 50))
        self.item.setPen(QPen(QColor('white')))
Esempio n. 52
0
 def mousePressEvent(self, event):
     self.start = event.pos()
     if not self.rubber_band:
         self.rubber_band = QGraphicsRectItem(None, self.scene())
     self.rubber_band.setRect(self.mapToScene(QRect(self.start,QSize())).boundingRect())
     self.scene().addItem(self.rubber_band)
     logging.info(self.__class__.__name__+' press')
Esempio n. 53
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
Esempio n. 54
0
    def mousePressEvent(self, event):
        pos = event.scenePos()
        any_item = self.scene.item_at(pos)
        if not any_item and event.button() & Qt.LeftButton:
            self.modifiers = event.modifiers()
            self.selection_rect = QRectF(pos, QSizeF(0, 0))
            self.rect_item = QGraphicsRectItem(
                self.selection_rect.normalized()
            )

            self.rect_item.setPen(
                QPen(QBrush(QColor(51, 153, 255, 192)),
                     0.4, Qt.SolidLine, Qt.RoundCap)
            )

            self.rect_item.setBrush(
                QBrush(QColor(168, 202, 236, 192))
            )

            self.rect_item.setZValue(-100)

            # Clear the focus if necessary.
            if not self.scene.stickyFocus():
                self.scene.clearFocus()

            if not self.modifiers & Qt.ControlModifier:
                self.scene.clearSelection()

            event.accept()
            return True
        else:
            self.cancel(self.ErrorReason)
            return False
Esempio n. 55
0
class Meterbar(Button):
    def __init__(self, max=255, filename=None, width=None, height=None, x=0, y=0, pixmap=None, group=None, pos=None, size=None, padding=None):
        Button.__init__(self, filename, width, height, x, y, pixmap, group, pos, size, padding)
        self.max = max
        self.outer = QGraphicsRectItem(x,y,width,max + 2)
        self.outer.setPen(QPen(QColor(Qt.black), 1, Qt.SolidLine))
        self.outer.setBrush(Qt.green)
#         self.outer.hide()
        self.inner = QGraphicsRectItem(x + 1,y + 1,width - 2,max)
        self.inner.setPen(QPen(QColor(Qt.green), 1, Qt.SolidLine))
        self.inner.setBrush(Qt.blue)
        self.items = [self.outer, self.inner]
        self.current = 255
        self.effect = QGraphicsDropShadowEffect()
        self.effect.setOffset(0, 0)
        self.effect.setBlurRadius(0)
        self.effect.setColor(Qt.green)
        self.item = self.outer
        self.addEffect('shadow', self.effect, True)
        self.addAnimation('glow', Glow(15, 300, self, maxRadius=80, minRadius=5))
#         self.test(10)
    
    def test(self, x):
        self.tl = QTimeLine(10000)
        self.tl.setFrameRange(0, 10000)
        self.a = QGraphicsItemAnimation()
        self.a.setItem(self.inner)
        self.a.setTimeLine(self.tl)
#         self.a.setPosAt(0, QPointF(self.getX(), self.current))
#         self.a.setTranslationAt(1, self.getX(), self.getY() + self.max - x + 1)
        self.a.setScaleAt(0, 1, 1)
        self.a.setScaleAt(1, 1, 0.1)
        self.current = x
        self.tl.start()
        
    def update(self, x):
        x2 = 1 - (float(x) * 1.0 / float(self.max))
#         print x
#         return
        self.tl = QTimeLine(10)
        self.tl.setFrameRange(0, 10)
        self.a = QGraphicsItemAnimation()
        self.a.setItem(self.inner)
        self.a.setTimeLine(self.tl)
#         self.a.setPosAt(0, QPointF(self.getX(), self.current))
#         self.a.setTranslationAt(1, self.getX(), self.getY() + self.max - x + 1)
        self.a.setScaleAt(0, 1, self.current)
        self.a.setScaleAt(1, 1, x2)
        self.current = x
        self.tl.start()
        if x > 3 :
            self.play('glow')
        
    def setScene(self, scene):
        self.scene = scene
        for item in self.items :
            self.scene.addItem(item)
Esempio n. 56
0
    def paint( self, painter, option, widget ):
        " Draws a filled rectangle, adds title, classes/funcs/globs sections "

        # Hide the dotted outline
        itemOption = QStyleOptionGraphicsItem( option )
        if itemOption.state & QStyle.State_Selected != 0:
            itemOption.state = itemOption.state & ~QStyle.State_Selected

        # Draw the rectangle
        QGraphicsRectItem.paint( self, painter, itemOption, widget )


        # Start from the bottom to automatically take potential spare
        # pixels for the title
        font = QFont( "Arial", 10 )
        painter.setFont( font )
        posX = self.__node.posX - self.__node.width / 2.0
        posY = self.__node.posY + self.__node.height / 2.0 - 1.5 * self.__pixelsPerLine

        occupiedPixels = 0
        for index in xrange( len( self.__lines ) - 1, 0, -1 ):
            if self.__lines[ index ] is None:
                # Draw a separation line
                painter.drawLine( posX + 1, posY + self.__pixelsPerLine / 2.0,
                                  posX + self.__node.width,
                                  posY + self.__pixelsPerLine / 2.0)
            elif self.__lines[ index ] != "":
                # Draw a text line
                # Sometimes the bottom part of 'g' is not drawn so I add 2
                # spare pixels.
                painter.drawText( int( posX ), int( posY ),
                                  int( self.__node.width ), self.__pixelsPerLine + 2,
                                  Qt.AlignCenter, self.__lines[ index ] )
            occupiedPixels += self.__pixelsPerLine
            posY -= self.__pixelsPerLine

        # Draw the title in bold
        font.setBold( True )
        painter.setFont( font )

        available = self.__node.height - occupiedPixels
        posY = self.__node.posY - self.__node.height / 2.0
        painter.drawText( int( posX ), int( posY ),
                          int( self.__node.width ), int( available ),
                          Qt.AlignCenter, self.__lines[ 0 ] )
        return
 def mouseReleaseEvent(self, event):
     
     if self._has_moved:
         self.Signaller.signalHasMoved.emit(self.pos())
         #self._has_moved=False
     
         self._has_moved=False
     return QGraphicsRectItem.mouseReleaseEvent(self, event)