Example #1
0
    def __init__(self, whex):
        QGraphicsTextItem.__init__(self)
        self.initValues(whex)
        self.initPosition()
#        self.initDocument()
        self.initFont()
        self.initMetricsValues()
Example #2
0
    def __init__(self, text, parent=None):
        QGraphicsWidget.__init__(self, parent)
        self.labelItem = QGraphicsTextItem(self)
        self.setHtml(text)

        self.labelItem.document().documentLayout().documentSizeChanged.connect(
            self.onLayoutChanged)
Example #3
0
File: Canvas1.py Project: iras/JADE
 def focusInEvent (self, event):
     '''Re-implementation of the QGraphicsTextItem's method focusOInEvent in order to change the text colour to red.
     
     @param event event
     '''
     self.setDefaultTextColor (Qt.red)
     QGraphicsTextItem.focusOutEvent(self, event)
Example #4
0
 def initHeads(self):
     self.offHead = QGraphicsTextItem()
     self.hexHead = QGraphicsTextItem()
     self.asciiHead = QGraphicsTextItem()
     #Set Color
     self.offHead.setDefaultTextColor(QColor(Qt.red))
     self.hexHead.setDefaultTextColor(QColor(Qt.black))
     self.asciiHead.setDefaultTextColor(QColor(Qt.darkCyan))
     #Create Font
     self.font = QFont("Gothic")
     self.font.setFixedPitch(1)
     self.font.setBold(False)
     self.font.setPixelSize(14)
     #Set Font
     self.offHead.setFont(self.font)
     self.hexHead.setFont(self.font)
     self.asciiHead.setFont(self.font)
     #Set Text
     self.offHead.setPlainText("Offset")
     self.hexHead.setPlainText("0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F")
     self.asciiHead.setPlainText("Ascii")
     #Position
     self.offHead.setPos(20, 0)
     self.hexHead.setPos(95, 0)
     self.asciiHead.setPos(520, 0)
     #Add to scene
     self.scene.addItem(self.offHead)
     self.scene.addItem(self.hexHead)
     self.scene.addItem(self.asciiHead)
     headLine = QGraphicsLineItem(QLineF(0, 20, 615, 20))
     self.scene.addItem(headLine)
Example #5
0
    def __init__(self, parent=None, scene=None):
        super(EControlsGroup, self).__init__(parent, scene)

        self.setFlag(QGraphicsItem.ItemIsMovable, True)
        self.setAcceptsHoverEvents(True)

        self.__kId = str(uuid.uuid1())
        self.__name = QGraphicsTextItem()
        self.__name.setPlainText('EddGroup')

        self.__sWidth = 500
        self.__sHeight = 20
        self.__sExtra = 8
        self.__controlsOffset = 5

        self.__isDefaultPen = False

        self.__pens = {
            0: EDraw.EColor.DefaultLeaveHoverPen,
            1: EDraw.EColor.DefaultEnterHoverPen
        }
        self.setPen(self.__pens[self.__isDefaultPen])

        self.__shapeRect = QRectF(0, 0, self.__sWidth, self.__sHeight)
        self.__controls = []
Example #6
0
 def setBlockHead(self):
     self.blockHead = QGraphicsTextItem()
     self.blockHead.setDefaultTextColor(QColor(Qt.red))
     self.blockHead.setFont(self.font)
     self.blockHead.setPlainText("Block")
     self.blockHead.setPos(15, 0)
     self.scene.addItem(self.blockHead)
class PendulumGraphics(Pendulum):
    """pendulum which renders itself in a QGraphicsView"""

    def initGraphics(self, gView):
        self.gView = gView
        self.gScene = QGraphicsScene(self.gView)
        self.gView.setScene(self.gScene)

        self.gText = QGraphicsTextItem("Pendulum")
        self.gText.moveBy(0, -120)
        self.gGrid = Graphics.Items.Grid(size=(-140, -140, 140, 140), xstep=20, ystep=20,
            toolTip='the main grid')
        self.gCross = Graphics.Items.CrossX(toolTip='this is the fix point of the pendulum')
        self.gAxes = Graphics.Items.Axes(toolTip='theese are x,y-axes')
        self.gPendulum = GPendulum()
        self.gPendulum.setProperties((self.mass, self.length, self.radius, self.gravity,
            self.omega, self.friction))
        self.gScene.addItem(self.gGrid)
        self.gScene.addItem(self.gText)
        self.gScene.addItem(self.gCross)
        self.gScene.addItem(self.gAxes)
        self.gScene.addItem(self.gPendulum)
        self.gView.setSceneRect(QRectF(-140, -140, 280, 280))
        self.gPendulum.rotate(self.phi.v)

    def reset(self):
        self.gPendulum.rotate(self.initValues['phi']-self.phi.v)
        Pendulum.reset(self)

    def update(self, timeStep):
        Pendulum.update(self, timeStep)
        self.gPendulum.rotate(self.phiStep)
Example #8
0
    def __init__(self, parent=None, scene=None):
        super(EFrameLayout, self).__init__(parent, scene)

        self.setFlag(QGraphicsItem.ItemIsMovable, True)
        self.setAcceptsHoverEvents(True)

        self.__name = QGraphicsTextItem()
        self.__name.setPlainText('Frame Layout')

        self.__handleWidth = 500
        self.__handleHeight = 20
        self.__separator = 5
        self.__boundExtra = 3 + self.pen().width()
        self.__handleRect = QRectF(0.0, 0.0, self.__handleWidth,
                                   self.__handleHeight)

        self.__controlsBound = 0.0
        self.__controls = []

        self.__isDefaultPen = False
        self.__isCollapsed = True

        self.__pens = {
            0: EDraw.EColor.DefaultLeaveHoverPen,
            1: EDraw.EColor.DefaultEnterHoverPen
        }
        self.setPen(self.__pens[self.__isDefaultPen])
Example #9
0
    def __init__(self, canvas, text="", x=0, y=0,
                 alignment=Qt.AlignLeft | Qt.AlignTop, bold=0, font=None, z=0,
                 html_text=None, tooltip=None, show=1, vertical=False):
        QGraphicsTextItem.__init__(self, text, None)

        if font:
            self.setFont(font)
        if bold:
            font = self.font()
            font.setBold(bold)
            self.setFont(font)
        if html_text:
            self.setHtml(html_text)

        self.alignment = alignment
        self.vertical = vertical
        if vertical:
            self.setRotation(-90)

        self.setPos(x, y)
        self.x, self.y = x, y
        self.setZValue(z)
        if tooltip:
            self.setToolTip(tooltip)
        if show:
            self.show()
        else:
            self.hide()

        if canvas is not None:
            canvas.addItem(self)
Example #10
0
 def showTextLabel(self, x, y, secure=25):
     """
     add labels of principle peaks of spectrum or chroma
     on the plot, return the labels, that we can show hide
     
     """
     maxis = []  #will contain tuple(rt, intens)
     indexes = []
     #from core.MetObjects import MSAbstractTypes
     from scipy.ndimage import gaussian_filter1d as gauss
     z = gauss(y, 1)
     #z = MSAbstractTypes.computeBaseLine(z, 92., 0.8)
     i = 0
     while i < len(z) - 1:
         while z[i + 1] >= z[i] and i < len(y) - 2:
             i += 1
         maxis.append((x[i], y[i]))
         indexes.append(i)
         while z[i + 1] <= z[i] and i < len(z) - 2:
             i += 1
         i += 1
     labels = []
     for t in sorted(maxis, key=lambda x: x[1])[-5:]:
         g = QGraphicsTextItem(str(t[0]))
         g.setFlag(QGraphicsItem.ItemIgnoresTransformations)
         font = QApplication.font()
         font.setPointSizeF(6.5)
         g.setFont(font)
         g.setDefaultTextColor(Qt.black)
         g.setPos(t[0], t[1])
         labels.append(g)
         self.pw.addItem(g)
     return labels
Example #11
0
File: Canvas1.py Project: iras/JADE
 def keyPressEvent (self, event):
     '''Re-implementation of the QGraphicsTextItem's method  keyPressEvent in order to provide QGraphicsTextItem with the QLineEdit's textChanged Event.
     
     @param event event
     '''
     self.emit (SIGNAL ('textChanged(QString)'), QString(self.toPlainText()))
     QGraphicsTextItem.keyPressEvent(self, event)
Example #12
0
 def setOffsetHead(self):
     self.offHead = QGraphicsTextItem()
     self.offHead.setDefaultTextColor(QColor(Qt.red))
     self.offHead.setFont(self.font)
     self.offHead.setPlainText("Offset(Kb)")
     self.offHead.setPos(5, 0)
     self.scene.addItem(self.offHead)
Example #13
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)
Example #14
0
    def __init__(self, *args):
        QGraphicsObject.__init__(self, *args)
        self.setFlag(QGraphicsItem.ItemHasNoContents, True)
        self.setAcceptedMouseButtons(Qt.RightButton | Qt.LeftButton)
        self.setAcceptHoverEvents(True)

        self.setZValue(self.Z_VALUE)

        self.sourceItem = None
        self.sourceAnchor = None
        self.sinkItem = None
        self.sinkAnchor = None

        self.curveItem = LinkCurveItem(self)

        self.sourceIndicator = LinkAnchorIndicator(self)
        self.sinkIndicator = LinkAnchorIndicator(self)
        self.sourceIndicator.hide()
        self.sinkIndicator.hide()

        self.linkTextItem = QGraphicsTextItem(self)

        self.__sourceName = ""
        self.__sinkName = ""

        self.__dynamic = False
        self.__dynamicEnabled = False

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

        if font:
            self.setFont(font)
        if bold:
            font = self.font()
            font.setBold(bold)
            self.setFont(font)
        if html_text:
            self.setHtml(html_text)

        self.alignment = alignment
        self.vertical = vertical
        if vertical:
            self.setRotation(-90)

        self.setPos(x, y)
        self.x, self.y = x, y
        self.setZValue(z)
        if tooltip:
            self.setToolTip(tooltip)
        if show:
            self.show()
        else:
            self.hide()

        if canvas is not None:
            canvas.addItem(self)
Example #17
0
    def keyPressEvent(self, keyEvent):

        if keyEvent.key() == Qt.Key_Return or keyEvent.key() == Qt.Key_Enter:
            if self.__isSingleLine:
                self.setTextInteractionFlags(Qt.NoTextInteraction)
            return

        QGraphicsTextItem.keyPressEvent(self, keyEvent)
Example #18
0
    def __init__(self, text, parent=None, **kwargs):
        super().__init__(parent, **kwargs)
        self.labelItem = QGraphicsTextItem(self)
        self.setHtml(text)

        self.labelItem.document().documentLayout().documentSizeChanged.connect(
            self.onLayoutChanged
        )
Example #19
0
File: Canvas1.py Project: iras/JADE
 def focusOutEvent (self, event):
     '''Re-implementation of the QGraphicsTextItem's method focusOutEvent in order to provide QGraphicsTextItem with the QLineEdit's textChanged Event.
     
     @param event event
     '''
     self.emit (SIGNAL ('textChanged(QString)'), QString(self.toPlainText()))
     self.setDefaultTextColor (QColor (Qt.white).light (255))
     QGraphicsTextItem.focusOutEvent(self, event)
Example #20
0
    def keyPressEvent(self, keyEvent):

        if keyEvent.key() == Qt.Key_Return or keyEvent.key() == Qt.Key_Enter:
            if self.__isSingleLine:
                self.setTextInteractionFlags(Qt.NoTextInteraction)
            return

        QGraphicsTextItem.keyPressEvent(self, keyEvent)
Example #21
0
File: Hook0.py Project: iras/JADE
 def __init__(self, str0='', parent=None, scene=None):
     
     QGraphicsTextItem.__init__ (self, str0, parent, scene)
     
     self.setAcceptHoverEvents (False)
     self.setAcceptedMouseButtons (Qt.NoButton)
     self.setAcceptDrops (False)
     self.setAcceptTouchEvents (False)
    def keyPressEvent(self, event):
        """ Stuff to do during key press events.

        For now we have to adjust the outline box.

        """

        QGraphicsTextItem.keyPressEvent(self, event)
        self.adjust_size()
    def keyPressEvent(self, event):
        """ Stuff to do during key press events.

        For now we have to adjust the outline box.

        """

        QGraphicsTextItem.keyPressEvent(self, event)
        self.adjust_size()
Example #24
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)
    def paint( self, painter, option, widget ):
        """ Draws the edge text """

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

        QGraphicsTextItem.paint( self, painter, itemOption, widget )
        return
Example #26
0
    def paint(self, painter, option, widget):
        """ Draws the edge text """

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

        QGraphicsTextItem.paint(self, painter, itemOption, widget)
        return
Example #27
0
 def showTextLabel(self, x, y, secure=25):
     """
     add labels of principle peaks of spectrum or chroma
     on the plot, return the labels, that we can show hide
     
     """
     maxis=[]#will contain tuple(rt, intens)
     indexes=[]
     #from core.MetObjects import MSAbstractTypes
     from scipy.ndimage import gaussian_filter1d as gauss        
     z=gauss(y, 1)
     #z = MSAbstractTypes.computeBaseLine(z, 92., 0.8)
     i=0
     while i <len(z)-1:
         while z[i+1] >= z[i] and i < len(y)-2:
             i+=1
         maxis.append((x[i], y[i])) 
         indexes.append(i)
         while z[i+1] <= z[i] and i<len(z)-2:
             i+=1
         i+=1
     labels=[]    
     for t in sorted(maxis, key=lambda x:x[1])[-5:]:
         g=QGraphicsTextItem(str(t[0]))
         g.setFlag(QGraphicsItem.ItemIgnoresTransformations)
         font=QApplication.font()
         font.setPointSizeF(6.5)
         g.setFont(font)
         g.setDefaultTextColor(Qt.black)
         g.setPos(t[0], t[1])
         labels.append(g)
         self.pw.addItem(g)
     return labels
Example #28
0
File: plot.py Project: khedron/Plot
def qt_test():
	"""
	Test that Qt actually works
	"""
	scene = QGraphicsScene()
	text = QGraphicsTextItem(None, scene)
	text.setHtml("<h2 align=\"center\">hello</h2><h2 align=\"center\">world 12334345354444444444444444444444444</h2>123");
	text.setPos(QPointF(25,25))
	view = QGraphicsView(scene)
	view.show()
	sys.exit(app.exec_())
Example #29
0
    def __init__(self, parent=None, text=""):
        super(QGraphicsPathItem, self).__init__(parent)
        self.setAcceptHoverEvents(True)
        self.setPen(QPen(Qt.NoPen))

        self.text = QGraphicsTextItem(self)
        layout = self.text.document().documentLayout()
        layout.documentSizeChanged.connect(self._onLayoutChanged)

        self._text = ""
        self._anchor = QPointF()
Example #30
0
 def __init__(self, parent=None, graphicView=None, graphicScene=None):
     QGraphicsItem.__init__(self)
     self.set_default_data()
     self.className = QGraphicsTextItem(self)
     self.functionsItem = FunctionsContainerModel(self)
     self.className.setPlainText(self.defaultClassName)
     self.setFlag(self.ItemIsMovable)
     self.setFlag(self.ItemSendsGeometryChanges)
     self.functionsItem.setPos(0, self.__get_title_height())
     self.attributesItem = FunctionsContainerModel(self)
     self.attributesItem.setPos(0, self.functionsItem.get_height())
Example #31
0
 def label(self):
     if self._label:
         return self._label
     label = QGraphicsTextItem("")
     label.setVisible(False)
     label.setFont(self._font)
     label.setParentItem(self)
     label.setTextInteractionFlags(Qt.TextEditorInteraction)
     label.inputMethodEvent = self.inputProcess
     self._label = label
     self._label.hide()
     return label
Example #32
0
    def __init__(self,
                 id,
                 title='',
                 title_above=False,
                 title_location=AxisMiddle,
                 line=None,
                 arrows=0,
                 plot=None,
                 bounds=None):
        QGraphicsItem.__init__(self)
        self.setFlag(QGraphicsItem.ItemHasNoContents)
        self.setZValue(AxisZValue)
        self.id = id
        self.title = title
        self.title_location = title_location
        self.data_line = line
        self.plot = plot
        self.graph_line = None
        self.size = None
        self.scale = None
        self.tick_length = (10, 5, 0)
        self.arrows = arrows
        self.title_above = title_above
        self.line_item = QGraphicsLineItem(self)
        self.title_item = QGraphicsTextItem(self)
        self.end_arrow_item = None
        self.start_arrow_item = None
        self.show_title = False
        self.scale = None
        path = QPainterPath()
        path.setFillRule(Qt.WindingFill)
        path.moveTo(0, 3.09)
        path.lineTo(0, -3.09)
        path.lineTo(9.51, 0)
        path.closeSubpath()
        self.arrow_path = path
        self.label_items = []
        self.label_bg_items = []
        self.tick_items = []
        self._ticks = []
        self.zoom_transform = QTransform()
        self.labels = None
        self.values = None
        self._bounds = bounds
        self.auto_range = None
        self.auto_scale = True

        self.zoomable = False
        self.update_callback = None
        self.max_text_width = 50
        self.text_margin = 5
        self.always_horizontal_text = False
Example #33
0
    def paint(self, painter, option, widget=None):

        painter.setPen(self.pen())
        painter.setBrush( EDraw.EColor.DefaultFillColor )

        style = QStyleOptionGraphicsItem()
        style.state = ( QStyle.State_None )

        painter.drawPolygon( EDraw.DefaultPolygon( self.boundingRect().width(), self.boundingRect().height() ) )

        painter.translate( self.boundingRect().height() / 2  , 0.0)

        QGraphicsTextItem.paint(self, painter, style, widget)
Example #34
0
    def LoopText(self):
        self.textItem = QGraphicsTextItem()
        self.textItem.setPlainText('Muodostui silmukka')
        self.scene().addItem(self.textItem)
        self.textItem.setZValue(2)
        self.textItem.setPos(200,0)

        fontti = QFont()
        fontti.setPointSize(40)

        self.textItem.setFont(fontti)

        timer = QTimer()
        timer.singleShot(3000,self.removeLoopText)
Example #35
0
class GraphicsTextWidget(QGraphicsWidget):
    def __init__(self, text, parent=None, **kwargs):
        super().__init__(parent, **kwargs)
        self.labelItem = QGraphicsTextItem(self)
        self.setHtml(text)

        self.labelItem.document().documentLayout().documentSizeChanged.connect(
            self.onLayoutChanged
        )

    def setGeometry(self, rect):
        self.prepareGeometryChange()
        super().setGeometry(rect)

    def onLayoutChanged(self, *args):
        self.updateGeometry()

    def sizeHint(self, which, constraint=QSizeF()):
        if which == Qt.MinimumSize:
            return self.labelItem.boundingRect().size()
        else:
            return self.labelItem.boundingRect().size()

    def setTextWidth(self, width):
        self.labelItem.setTextWidth(width)

    def setHtml(self, text):
        self.labelItem.setHtml(text)
Example #36
0
def scientific_name_face(node, *args, **kwargs):
    scientific_name_text = QGraphicsTextItem()
    words = node.visual_label.split()
    text = []
    if hasattr(node, 'bg_col'):
        container_div = '<div style="background-color:{};">'.format(node.bgcolor)
        text.append(container_div)
    if len(words) < 2:
        # some sort of acronym or bin name, leave it alone
        text.extend(words)

    elif len(words) > 2:
        if words[0] == 'Candidatus':
            # for candidatus names, only the Candidatus part is italicised
            # name shortening it for brevity
            text.append('<i>Ca.</i>')
            text.extend(words[1:])
        elif re.match('^[A-Z]+$', words[0]):
            # If the first word is in all caps then it is an abreviation
            # so we don't want to italicize that at all
            text.extend(words)
        else:
            # assume that everything after the second word is strain name
            # which should not get italicised
            text.extend(['<i>'+words[0],words[1]+'</i>'])
            text.extend(words[2:])
    else:
        text.extend(['<i>'+words[0],words[1]+'</i>'])

    if hasattr(node, 'bg_col'):
        text.append('</div>')
    scientific_name_text.setHtml(' '.join(text))
    #print(scientific_name_text.boundingRect().width(), scientific_name_text.boundingRect().height())

    # below is a bit of a hack - I've found that the height of the bounding
    # box gives a bit too much padding around the name, so I just minus 10
    # from the height and recenter it. Don't know whether this is a generally
    # applicable number to use
    masterItem = QGraphicsRectItem(0, 0, scientific_name_text.boundingRect().width(), scientific_name_text.boundingRect().height() - 10)


    scientific_name_text.setParentItem(masterItem)
    center = masterItem.boundingRect().center()
    scientific_name_text.setPos(masterItem.boundingRect().x(), center.y() - scientific_name_text.boundingRect().height()/2)
    # I dont want a border around the masterItem
    masterItem.setPen(QPen(QtCore.Qt.NoPen))


    return masterItem
Example #37
0
    def __init__(self, parent, *args, **kwargs):
        QGraphicsTextItem.__init__(self, *args)
        GraphNode.__init__(self, **kwargs)
        self._background_brush = None
        self._rect = None

        self.parent = parent
        font = self.font()
        font.setPointSize(10)
        self.setFont(font)
        self.droplet = GraphicsDroplet(-5, 0, 10, 10, self)
        self.droplet.setPos(self.rect().center().x(), self.rect().height())
        self.document().contentsChanged.connect(self.update_contents)
        self.isOpen = True
        self.setFlag(QGraphicsItem.ItemIsSelectable, True)
Example #38
0
    def paint(self, painter, option, widget=None):

        painter.setPen(self.pen())
        painter.setBrush(EDraw.EColor.DefaultFillColor)

        style = QStyleOptionGraphicsItem()
        style.state = (QStyle.State_None)

        painter.drawPolygon(
            EDraw.DefaultPolygon(self.boundingRect().width(),
                                 self.boundingRect().height()))

        painter.translate(self.boundingRect().height() / 2, 0.0)

        QGraphicsTextItem.paint(self, painter, style, widget)
Example #39
0
 def paint(self, painter, option, widget=None):
     rect = self.rect()
     if self.isSelected():
         option.state ^= QStyle.State_Selected
     font = self.document().defaultFont()
     painter.setFont(font)
     if self.parent:
         draw_text = self.node_inst.description
         if self.parent.x() > self.x():  # node is to the left
             fm = QFontMetrics(font)
             x = rect.width() / 2 - fm.width(draw_text) - 4
         else:
             x = rect.width() / 2 + 4
         painter.drawText(QPointF(x, -self.line_descent - 1), draw_text)
     painter.save()
     painter.setBrush(self.backgroundBrush)
     painter.setPen(QPen(Qt.black, 3 if self.isSelected() else 0))
     adjrect = rect.adjusted(-3, 0, 0, 0)
     if not self.node_inst.children:
         painter.drawRoundedRect(adjrect, 4, 4)
     else:
         painter.drawRect(adjrect)
     painter.restore()
     painter.setClipRect(rect)
     return QGraphicsTextItem.paint(self, painter, option, widget)
    def __init__(self, rect=None):
        super(TaskGraphicsItem, self).__init__()

        if rect is not None:
            self.setRect(rect)

        self.setPen(QPen(Qt.NoPen))

        # Setup the text item
        self.textItem = QGraphicsTextItem()
        self.textItem.setParentItem(self)
        self.textItem.rotate(-90)
        self.textItem.setDefaultTextColor(QColor(255, 255, 255))

        # The dimensions to reach via a LERP.
        self.startPos = QPointF(0, 0)
        self.endPos = QPointF(0, 0)
        self.startDiameter = 1
        self.endDiameter = 1

        self.centerMark = QGraphicsEllipseItem()
        self.centerMark.setBrush(QBrush(Qt.white))
        self.centerMark.setPen(QPen(Qt.NoPen))
        self.centerMark.setParentItem(self)

        self.pid = -1

        # To determine if it is associated with an active process.
        self.used = False
Example #41
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)
Example #42
0
    def __init__(self, *args):
        QGraphicsObject.__init__(self, *args)
        self.setFlag(QGraphicsItem.ItemHasNoContents, True)
        self.setAcceptedMouseButtons(Qt.RightButton | Qt.LeftButton)
        self.setAcceptHoverEvents(True)

        self.setZValue(self.Z_VALUE)

        self.sourceItem = None
        self.sourceAnchor = None
        self.sinkItem = None
        self.sinkAnchor = None

        self.curveItem = LinkCurveItem(self)

        self.sourceIndicator = LinkAnchorIndicator(self)
        self.sinkIndicator = LinkAnchorIndicator(self)
        self.sourceIndicator.hide()
        self.sinkIndicator.hide()

        self.linkTextItem = QGraphicsTextItem(self)

        self.__sourceName = ""
        self.__sinkName = ""

        self.__dynamic = False
        self.__dynamicEnabled = False

        self.hover = False
Example #43
0
    def __init__( self, edge ):
        text = edge.label.replace( '\\n', '\n' )
        QGraphicsTextItem.__init__( self, text )

        font = QFont( "Arial", 10 )
        self.setFont( font )

        metric = QFontMetrics( font )
        rec = metric.boundingRect( 0, 0, 10000, 10000, Qt.AlignCenter, text )

        self.setPos( edge.labelX - rec.width() / 2,
                     edge.labelY - rec.height() / 2 )

        # To make double click not delivered
        self.setFlag( QGraphicsItem.ItemIsSelectable, False )
        return
Example #44
0
 def setPos(self, x, y):
     self.x, self.y = x, y
     rect = QGraphicsTextItem.boundingRect(self)
     if self.vertical:
         h, w = rect.height(), rect.width()
         rect.setWidth(h)
         rect.setHeight(-w)
     if int(self.alignment & Qt.AlignRight):
         x -= rect.width()
     elif int(self.alignment & Qt.AlignHCenter):
         x -= rect.width() / 2.
     if int(self.alignment & Qt.AlignBottom):
         y -= rect.height()
     elif int(self.alignment & Qt.AlignVCenter):
         y -= rect.height() / 2.
     QGraphicsTextItem.setPos(self, x, y)
Example #45
0
 def setPos(self, x, y):
     self.x, self.y = x, y
     rect = QGraphicsTextItem.boundingRect(self)
     if self.vertical:
         h, w = rect.height(), rect.width()
         rect.setWidth(h)
         rect.setHeight(-w)
     if int(self.alignment & Qt.AlignRight):
         x -= rect.width()
     elif int(self.alignment & Qt.AlignHCenter):
         x -= rect.width() / 2.
     if int(self.alignment & Qt.AlignBottom):
         y -= rect.height()
     elif int(self.alignment & Qt.AlignVCenter):
         y -= rect.height() / 2.
     QGraphicsTextItem.setPos(self, x, y)
Example #46
0
    def __init__(self, edge):
        text = edge.label.replace('\\n', '\n')
        QGraphicsTextItem.__init__(self, text)

        font = QFont("Arial", 10)
        self.setFont(font)

        metric = QFontMetrics(font)
        rec = metric.boundingRect(0, 0, 10000, 10000, Qt.AlignCenter, text)

        self.setPos(edge.labelX - rec.width() / 2,
                    edge.labelY - rec.height() / 2)

        # To make double click not delivered
        self.setFlag(QGraphicsItem.ItemIsSelectable, False)
        return
Example #47
0
    def setItems(self, items):
        if self._items:
            self.clear()

        self._items = list(items)

        for item in self._items:
            item.setParentItem(self)
            item.setVisible(True)

        fmt = self.TitleFormat.format

        font = self.font()
        font.setPixelSize(14)

        for item in items:
            text = GraphicsTextEdit(self)
            text.setFont(font)
            text.setDefaultTextColor(QColor("#333"))
            text.setHtml(fmt(escape(item.text), item.count))
            text.adjustSize()
            text.editingStarted.connect(self._on_editingStarted)
            text.editingFinished.connect(self._on_editingFinished)
            text.documentSizeChanged.connect(self._on_itemTextSizeChanged)

            self._textitems.append(text)

        self._vennareas = [
            VennIntersectionArea(parent=self) for i in range(2**len(items))
        ]
        self._subsettextitems = [
            QGraphicsTextItem(parent=self) for i in range(2**len(items))
        ]

        self._updateLayout()
Example #48
0
class TimestampItem(QGraphicsRectItem):
    """ 
    Represents a block in the diagram
    """
    def __init__(self, parent, name='Untitled', width=180, height=40):
        """
        Constructor
        """
        QGraphicsRectItem.__init__(self)

        self.parentWidget = parent

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

        self.label = QGraphicsTextItem(name, self)

        self.setColor(blockColor="#FFFFFF")

        self.changeSize(width, height)

    def setColor(self, blockColor):
        """
        Set color
        """
        color = QColor(0, 0, 0)
        color.setNamedColor(blockColor)
        self.setPen(QPen(color, 1))

        self.setBrush(QBrush(color))

    def changeSize(self, w, h):
        """
        Resize block function
        """
        # Limit the block size
        self.setRect(0.0, 0.0, w, h)

        # center label:
        rect = self.label.boundingRect()
        lw, lh = rect.width(), rect.height()
        lx = (w - lw) / 2
        ly = (h - lh) / 2
        self.label.setPos(lx, ly)

        return w, h
Example #49
0
    def __init__(self, text, parent=None):
        QGraphicsWidget.__init__(self, parent)
        self.labelItem = QGraphicsTextItem(self)
        self.setHtml(text)

        self.labelItem.document().documentLayout().documentSizeChanged.connect(
            self.onLayoutChanged
        )
Example #50
0
    def paint(self, painter, option, widget=None):
        QGraphicsTextItem.paint(self, painter, option, widget)

        # Draw placeholder text if necessary
        if not (self.toPlainText() and self.toHtml()) and \
                self.__placeholderText and \
                not (self.hasFocus() and \
                     self.textInteractionFlags() & Qt.TextEditable):
            brect = self.boundingRect()
            painter.setFont(self.font())
            metrics = painter.fontMetrics()
            text = metrics.elidedText(self.__placeholderText, Qt.ElideRight,
                                      brect.width())
            color = self.defaultTextColor()
            color.setAlpha(min(color.alpha(), 150))
            painter.setPen(QPen(color))
            painter.drawText(brect, Qt.AlignTop | Qt.AlignLeft, text)
Example #51
0
    def paint(self, painter, option, widget=None):
        QGraphicsTextItem.paint(self, painter, option, widget)

        # Draw placeholder text if necessary
        if not (self.toPlainText() and self.toHtml()) and \
                self.__placeholderText and \
                not (self.hasFocus() and \
                     self.textInteractionFlags() & Qt.TextEditable):
            brect = self.boundingRect()
            painter.setFont(self.font())
            metrics = painter.fontMetrics()
            text = metrics.elidedText(self.__placeholderText, Qt.ElideRight,
                                      brect.width())
            color = self.defaultTextColor()
            color.setAlpha(min(color.alpha(), 150))
            painter.setPen(QPen(color))
            painter.drawText(brect, Qt.AlignTop | Qt.AlignLeft, text)
Example #52
0
	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
Example #53
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)
Example #54
0
class OWLegendTitle(QGraphicsObject):
    """
        A legend item that shows ``text`` with a bold font and no symbol.
    """
    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)

    def boundingRect(self):
        return self.text_item.boundingRect()

    def paint(self, painter, option, widget):
        pass
Example #55
0
 def __init__(self, text, x, y, align, bold=0, color=None, brushColor=None, size=None):
     orangeqt.PlotItem.__init__(self)
     self.setFlag(QGraphicsItem.ItemIgnoresTransformations, True)
     self._item = QGraphicsTextItem(text, parent=self)
     self._data_point = QPointF(x, y)
     f = self._item.font()
     f.setBold(bold)
     if size:
         f.setPointSize(size)
     self._item.setFont(f)
     self._item.setPos(x, y)