예제 #1
0
파일: simulator_qt.py 프로젝트: amin10/datk
 def point(scene, x, y, color='black', fill='black', diam=10, toolTip=None):
    item = QGraphicsEllipseItem(x-diam/2, y-diam/2, diam, diam)
    brush = QBrush(QColor(color), style=Qt.SolidPattern)
    item.setBrush(brush)
    if toolTip:
       item.setToolTip(toolTip)
    scene.addItem(item)
예제 #2
0
class GPendulum(Graphics.Items.ItemGroupBase):
    def _setup(self):
        self.rod = QGraphicsLineItem(QLineF(0, 0, 0, 100))
        p = QPen(QColor(100, 100, 100))
        p.setWidth(5)
        self.rod.setPen(p)
        self.rod.setToolTip('This is the rod of the pendulum')
        self.ball = QGraphicsEllipseItem(QRectF(-20, 80, 40, 40))
        b = QBrush(Qt.SolidPattern)
        b.setColor(QColor(0, 255, 0))
        self.ball.setBrush(b)
        self.ball.setToolTip('This is the ball of the pendulum where the mass is concentrated')
        self.addToGroup(self.rod)
        self.addToGroup(self.ball)
        self.setFlags(QGraphicsItem.ItemIsSelectable)

    def setProperties(self, q):
        self.properties = q

    def contextMenuEvent(self, e):
        e.accept()
        m = QMenu()
        p = m.addAction("Properties")
        a = m.exec_(e.screenPos())
        if a == p:
            dlg = SimTools.RichTypes.Qt4Widgets.SimpleRichTypesDialog(mainWin, 'Pendulum properties',
                text='Change physical properties', scrolling=False)
            dlg.addRichTypes(self.properties)
            dlg.exec_()
예제 #3
0
 def __init__(self, *args):
     QGraphicsView.__init__(self, *args)
     self.move(20, 240)
     self.outerD = 125
     self.innerD = 35
     self.innerRange = 48
     self.inputRange = 256
     self.thresh = 3
     self.padding = 40
     self.marginTop = 10
     self.worker = QSixAxisThread()
     self.worker.valueUpdated.connect(self.moveJoysticks)
     self.worker.start()
     self.setContentsMargins(0, 0, 0, 0)
     self.setMaximumHeight(180)
     self.setMaximumWidth(420)
     self.setMinimumHeight(240)
     self.setMinimumWidth(300)
     self.adjustSize()
     self.scene = QGraphicsScene(self)
     self.outerCircle1 = QGraphicsEllipseItem(0, self.marginTop, self.outerD, self.outerD)
     self.outerCircle1.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
     self.outerCircle1.setBrush(Qt.gray)
     self.innerCircle1 = QGraphicsEllipseItem(self.outerD / 2 - self.innerD / 2, self.outerD / 2 - self.innerD / 2 + self.marginTop, self.innerD, self.innerD)
     self.innerCircle1.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
     self.innerCircle1.setBrush(Qt.lightGray)
     self.scene.addItem(self.outerCircle1)
     self.scene.addItem(self.innerCircle1)
     self.outerCircle2 = QGraphicsEllipseItem(self.outerD + self.padding, self.marginTop, self.outerD, self.outerD)
     self.outerCircle2.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
     self.outerCircle2.setBrush(Qt.gray)
     self.innerCircle2 = QGraphicsEllipseItem(self.outerD + self.padding + self.outerD / 2 - self.innerD / 2, self.outerD / 2 - self.innerD / 2 + self.marginTop, self.innerD, self.innerD)
     self.innerCircle2.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
     self.innerCircle2.setBrush(Qt.lightGray)
     self.scene.addItem(self.outerCircle2)
     self.scene.addItem(self.innerCircle2)
     self.setScene(self.scene)
     self.setStyleSheet('background-color:transparent; border-width: 0px; border: 0px;')
     self.currentX = 0
     self.currentY = 0
     self.currentA = 0
     self.currentZ = 0
     self.psBtn = QPixmap(os.getcwd() + '/../icons/bt_PS.png')
     self.psBtn = self.psBtn.scaled(50, 50, Qt.KeepAspectRatio)
     self.psItem = QGraphicsPixmapItem(self.psBtn)
     self.psItem.setOffset(QPointF(self.outerD - 4, 0))
     self.effect = QGraphicsDropShadowEffect()
     self.effect.setOffset(0, 0)
     self.effect.setBlurRadius(20)
     self.effect.setColor(Qt.green)
     self.psItem.setGraphicsEffect(self.effect)
     self.scene.addItem(self.psItem)
     self.tl2 = QTimeLine(10000)
     self.tl2.setFrameRange(0, 10000)
     self.c = QGraphicsItemAnimation()
     self.c.setItem(self.psItem)
     self.c.setTimeLine(self.tl2)
     self.tl2.connect(self.tl2, SIGNAL('frameChanged(int)'), self.updateEffect)
     self.effectd = 3
     self.tl2.start()
예제 #4
0
 def __init__(self, *args):
     QGraphicsView.__init__(self, *args)
     self.outerD = 125
     self.innerD = 25
     self.innerRange = 50
     self.inputRange = 256
     self.thresh = 3
     self.worker = JoystickThread()
     self.worker.valueUpdated.connect(self.moveJoystick)
     self.worker.start()
     self.move(30, 100)
     self.setContentsMargins(0, 0, 0, 0)
     self.setMaximumHeight(140)
     self.setMaximumWidth(140)
     self.adjustSize()
     self.scene = QGraphicsScene(self)
     self.outerCircle = QGraphicsEllipseItem(0, 0, self.outerD, self.outerD)
     self.outerCircle.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
     self.outerCircle.setBrush(Qt.gray)
     self.innerCircle = QGraphicsEllipseItem(self.outerD / 2 - self.innerD / 2, self.outerD / 2 - self.innerD / 2, self.innerD, self.innerD)
     self.innerCircle.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
     self.innerCircle.setBrush(Qt.lightGray)
     self.scene.addItem(self.outerCircle)
     self.scene.addItem(self.innerCircle)
     self.setScene(self.scene)
     self.setStyleSheet('background-color:transparent;color:red')
     self.currentX = 0
     self.currentY = 0
예제 #5
0
 def __init__(self, *args):
     QGraphicsEllipseItem.__init__(self, *args)
     self.setRect(-3, -3, 6, 6)
     self.setPen(QPen(Qt.NoPen))
     self.normalBrush = QBrush(QColor("#9CACB4"))
     self.hoverBrush = QBrush(QColor("#7D7D7D"))
     self.setBrush(self.normalBrush)
     self.__hover = False
예제 #6
0
 def __init__(self, *args):
     QGraphicsEllipseItem.__init__(self, *args)
     self.setRect(-3, -3, 6, 6)
     self.setPen(QPen(Qt.NoPen))
     self.normalBrush = QBrush(QColor("#9CACB4"))
     self.hoverBrush = QBrush(QColor("#7D7D7D"))
     self.setBrush(self.normalBrush)
     self.__hover = False
예제 #7
0
파일: pieitem.py 프로젝트: maximerobin/Ufwi
 def __init__(self, rect, type):
     QGraphicsEllipseItem.__init__(self, rect)
     self._color = None
     self._darkColor = None
     self._pos = None
     self._startAngle = None
     self._spanAngle = None
     self._value = None
     self._type = type
예제 #8
0
파일: owtools.py 프로젝트: waqarini/orange3
 def __init__(self,
              pen=QPen(Qt.black),
              brush=QBrush(Qt.NoBrush),
              xCenter=0.0,
              yCenter=0.0,
              radius=1.0):
     OWCurve.__init__(self)
     self._item = QGraphicsEllipseItem(self)
     self.center = xCenter, yCenter
     self.radius = radius
     self._rect = QRectF(xCenter - radius, yCenter - radius, 2 * radius,
                         2 * radius)
     self.set_pen(pen)
     self.set_brush(brush)
예제 #9
0
파일: board.py 프로젝트: jsj2008/kdegames
 def __init__(self, name, tileset, roundsFinished=0, parent = None):
     """generate new wind tile"""
     if not len(WINDPIXMAPS):
         WINDPIXMAPS[('E', False)] = None # avoid recursion
         self.genWINDPIXMAPS()
     QGraphicsEllipseItem.__init__(self)
     if parent:
         self.setParentItem(parent)
     self.name = name
     self.face = QGraphicsSvgItem()
     self.face.setParentItem(self)
     self.prevailing = None
     self.setWind(name, roundsFinished)
     self.tileset = tileset
     self.__sizeFace()
예제 #10
0
 def __init__(self, name, tileset, roundsFinished=0, parent = None):
     """generate new wind tile"""
     if not len(WINDPIXMAPS):
         WINDPIXMAPS[('E', False)] = None # avoid recursion
         self.genWINDPIXMAPS()
     QGraphicsEllipseItem.__init__(self)
     if parent:
         self.setParentItem(parent)
     self.name = name
     self.face = QGraphicsSvgItem()
     self.face.setParentItem(self)
     self.prevailing = None
     self.setWind(name, roundsFinished)
     self.tileset = tileset
     self.__sizeFace()
예제 #11
0
 def __init__(self, outer, inner, 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.outer = outer
     self.inner = inner
     self.innerRange = 48
     self.inputRange = 256
     self.thresh = 5
     self.outerCircle = QGraphicsEllipseItem(self.getX(), self.getY(), self.outer, self.outer)
     self.outerCircle.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
     self.outerCircle.setBrush(Qt.gray)
     self.innerCircle = QGraphicsEllipseItem(self.getX() + self.outer / 2 - self.inner / 2, self.getY() + self.outer / 2 - self.inner / 2, self.inner, self.inner)
     self.innerCircle.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
     self.innerCircle.setBrush(Qt.lightGray)
     self.currentX = 0
     self.currentY = 0
     self.items = [self.outerCircle, self.innerCircle]
예제 #12
0
    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
예제 #13
0
    def __init__(self, radius, parent=None):
        QGraphicsEllipseItem.__init__(self, QRectF(-radius, -radius, radius*2.0, radius*2.0), parent=parent)

        self._pen = QPen(QColor('#000000'))
        self._pen.setWidth(1)
        self.setPen(self._pen)

        self._hoverPen = QPen(QColor('#000000'))
        self._hoverPen.setWidth(2)

        brush = QBrush(QColor('#FF9966'))
        self.setBrush(brush)

        self._isSelected = False
        self._isHover = False

        self.setAcceptHoverEvents(True)
예제 #14
0
    def __init__(self, longitude, latitude, pixmap, scene, parent=None):
        """Constructor.

        Args:
            longitude(float): Longitude of the origin of the pixmap.
            latitude(float): Latitude of the center of the pixmap.
            pixmap(QPixmap): Pixmap.
            scene(MapGraphicsScene): Scene the item belongs to.
            parent(QGraphicsItem): Parent item.
        """
        QGraphicsEllipseItem.__init__(self, parent=parent, scene=scene)

        self._lon = longitude
        self._lat = latitude
        self.setPixmap(pixmap)

        self.updatePosition(scene)
예제 #15
0
    def __init__(self, longitude, latitude, pixmap, scene, parent=None):
        """Constructor.

        Args:
            longitude(float): Longitude of the origin of the pixmap.
            latitude(float): Latitude of the center of the pixmap.
            pixmap(QPixmap): Pixmap.
            scene(MapGraphicsScene): Scene the item belongs to.
            parent(QGraphicsItem): Parent item.
        """
        QGraphicsEllipseItem.__init__(self, parent=parent, scene=scene)

        self._lon = longitude
        self._lat = latitude
        self.setPixmap(pixmap)

        self.updatePosition(scene)
예제 #16
0
파일: owtools.py 프로젝트: kereturn/orange3
 def __init__(self, pen=QPen(Qt.black), brush=QBrush(Qt.NoBrush), xCenter=0.0, yCenter=0.0, radius=1.0):
     OWCurve.__init__(self)
     self._item = QGraphicsEllipseItem(self)
     self.center = xCenter, yCenter
     self.radius = radius
     self._rect = QRectF(xCenter - radius, yCenter - radius, 2 * radius, 2 * radius)
     self.set_pen(pen)
     self.set_brush(brush)
예제 #17
0
    def __init__(self, p0, p1, parent=None):
        QGraphicsPathItem.__init__(self, parent=parent)

        self._p0 = p0
        self._p1 = p1

        self._startPoint = QGraphicsEllipseItem(-3, -3, 6, 6, parent=self)
        self._startPoint.setPos(p0)
        self._endPoint = QGraphicsEllipseItem(-3, -3, 6, 6, parent=self)
        self._endPoint.setVisible(False)

        brush = QBrush(QColor(Qt.black))
        self._startPoint.setBrush(brush)
        self._endPoint.setBrush(brush)

        pen = QPen(brush, 2.0)
        self.setPen(pen)
예제 #18
0
   def _finish_select_area(self):
       self.unregister_handler(self.home_map_scene,
                               QEvent.GraphicsSceneMouseRelease)
       self.unregister_handler(self.home_map_scene,
                               QEvent.KeyRelease)        
       item = None
       for id,it in self.current_op_stat['items'].items() : 
           print "%d,%s" % (id,HMItem.repr(it))       
           p = it.polygon().first()        
           item = None
       
       self.current_op = ''
       self.current_op_stat = None        
 
       el_it = QGraphicsEllipseItem(p.x()-2,p.y()-2,4,4)
       
       HMItem.module(el_it,self.__class__.__name__)
       HMItem.type(el_it,HMItem.ARTIFACT)
       HMItem.level(el_it, -1)
       
       el_it.setPen(QPen(Qt.blue,
                         1, 
                         Qt.SolidLine, 
                         Qt.RoundCap, 
                         Qt.RoundJoin))
       
       el_it.setBrush(QBrush(Qt.blue))
       el_it.setZValue(1)
       self.home_map_scene.addItem(el_it)
예제 #19
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
예제 #20
0
    def test_anchoritem(self):
        anchoritem = NodeAnchorItem(None)
        self.scene.addItem(anchoritem)

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

        anchoritem.setAnchorPath(path)

        anchor = AnchorPoint()
        anchoritem.addAnchor(anchor)

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

        anchor.scenePositionChanged.connect(ellipse1.setPos)

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

        anchor1 = AnchorPoint()
        anchoritem.addAnchor(anchor1)

        anchor1.scenePositionChanged.connect(ellipse2.setPos)

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

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

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

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

        advance()

        self.app.exec_()
예제 #21
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
예제 #22
0
 def __init__(self, *args):
     QGraphicsView.__init__(self, *args)
     self.outerD = 125
     self.innerD = 35
     self.innerRange = 48
     self.inputRange = 256
     self.thresh = 3
     self.padding = 40
     self.worker = QSixAxisThread()
     self.worker.valueUpdated.connect(self.moveJoysticks)
     self.worker.start()
     self.move(2, 100)
     self.setContentsMargins(0, 0, 0, 0)
     self.setMaximumHeight(180)
     self.setMaximumWidth(420)
     self.setMinimumHeight(140)
     self.setMinimumWidth(300)
     self.adjustSize()
     self.scene = QGraphicsScene(self)
     self.outerCircle1 = QGraphicsEllipseItem(0, 0, self.outerD, self.outerD)
     self.outerCircle1.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
     self.outerCircle1.setBrush(Qt.gray)
     self.innerCircle1 = QGraphicsEllipseItem(self.outerD / 2 - self.innerD / 2, self.outerD / 2 - self.innerD / 2, self.innerD, self.innerD)
     self.innerCircle1.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
     self.innerCircle1.setBrush(Qt.lightGray)
     self.scene.addItem(self.outerCircle1)
     self.scene.addItem(self.innerCircle1)
     self.outerCircle2 = QGraphicsEllipseItem(self.outerD + self.padding, 0, self.outerD, self.outerD)
     self.outerCircle2.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
     self.outerCircle2.setBrush(Qt.gray)
     self.innerCircle2 = QGraphicsEllipseItem(self.outerD + self.padding + self.outerD / 2 - self.innerD / 2, self.outerD / 2 - self.innerD / 2, self.innerD, self.innerD)
     self.innerCircle2.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
     self.innerCircle2.setBrush(Qt.lightGray)
     self.scene.addItem(self.outerCircle2)
     self.scene.addItem(self.innerCircle2)
     self.setScene(self.scene)
     self.setStyleSheet('background-color:transparent;')
     self.currentX = 0
     self.currentY = 0
     self.currentA = 0
     self.currentZ = 0
     self.test = QGraphicsItem(self.outerCircle2)
예제 #23
0
def bgc_name_face(node, *args, **kargs):
    """
    This is the item generator. It must receive a node object, and
    returns a Qt4 graphics item that can be used as a node face.
    """
    # Receive an arbitrary number of arguments, in this case width and
    # Height of the faces and the information about the BGC
    width = args[0]
    height = args[1]
    # Add the popup
    interactive_face = InteractiveItem("Class : {}\nRelated MIBiG : {}\nCluster family : {}".format(args[2], args[4], args[3]), 0, 0, width, height)
    # Keep a link within the item to access node info
    interactive_face.node = node
    # Remove border around the masterItem
    interactive_face.setPen(QPen(QtCore.Qt.NoPen))
    # Add ellipse around text
    ellipse = QGraphicsEllipseItem(interactive_face.rect())
    ellipse.setParentItem(interactive_face)
    # Change ellipse color
    ellipse.setBrush(QBrush(QColor(args[6])))
    # Add node name within the ellipse
    text = QGraphicsTextItem(args[5])
    text.setTextWidth(50)
    text.setParentItem(ellipse)
    # Center text according to masterItem size
    text_width = text.boundingRect().width()
    text_height = text.boundingRect().height()
    center = interactive_face.boundingRect().center()
    text.setPos(center.x()-text_width/2, center.y()-text_height/2)
    return interactive_face
예제 #24
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
예제 #25
0
class SingleJoystickView(QGraphicsView):

    def __init__(self, *args):
        QGraphicsView.__init__(self, *args)
        self.outerD = 125
        self.innerD = 25
        self.innerRange = 50
        self.inputRange = 256
        self.thresh = 3
        self.worker = JoystickThread()
        self.worker.valueUpdated.connect(self.moveJoystick)
        self.worker.start()
        self.move(30, 100)
        self.setContentsMargins(0, 0, 0, 0)
        self.setMaximumHeight(140)
        self.setMaximumWidth(140)
        self.adjustSize()
        self.scene = QGraphicsScene(self)
        self.outerCircle = QGraphicsEllipseItem(0, 0, self.outerD, self.outerD)
        self.outerCircle.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
        self.outerCircle.setBrush(Qt.gray)
        self.innerCircle = QGraphicsEllipseItem(self.outerD / 2 - self.innerD / 2, self.outerD / 2 - self.innerD / 2, self.innerD, self.innerD)
        self.innerCircle.setPen(QPen(QColor(Qt.darkGray), 1, Qt.SolidLine))
        self.innerCircle.setBrush(Qt.lightGray)
        self.scene.addItem(self.outerCircle)
        self.scene.addItem(self.innerCircle)
        self.setScene(self.scene)
        self.setStyleSheet('background-color:transparent;color:red')
        self.currentX = 0
        self.currentY = 0

    def moveJoystick(self, x, y):
        x2 = x * self.innerRange / self.inputRange - self.innerRange / 2
        y2 = y * self.innerRange / self.inputRange - self.innerRange / 2
        if -self.thresh <= x2 <= self.thresh:
            x2 = 0
        if -self.thresh <= y2 <= self.thresh:
            y2 = 0
        self.tl = QTimeLine(10)
        self.tl.setFrameRange(0, 10)
        self.a = QGraphicsItemAnimation()
        self.a.setItem(self.innerCircle)
        self.a.setTimeLine(self.tl)
        self.a.setPosAt(0, QPointF(self.currentX, self.currentY))
        self.a.setTranslationAt(1, x2, y2)
        self.currentX = x2
        self.currentY = y2
        self.tl.start()
        print 'x:%d y:%d' % (x2, y2)
예제 #26
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
예제 #27
0
 def _setup(self):
     self.rod = QGraphicsLineItem(QLineF(0, 0, 0, 100))
     p = QPen(QColor(100, 100, 100))
     p.setWidth(5)
     self.rod.setPen(p)
     self.rod.setToolTip('This is the rod of the pendulum')
     self.ball = QGraphicsEllipseItem(QRectF(-20, 80, 40, 40))
     b = QBrush(Qt.SolidPattern)
     b.setColor(QColor(0, 255, 0))
     self.ball.setBrush(b)
     self.ball.setToolTip('This is the ball of the pendulum where the mass is concentrated')
     self.addToGroup(self.rod)
     self.addToGroup(self.ball)
     self.setFlags(QGraphicsItem.ItemIsSelectable)
예제 #28
0
    def __init__(self, longitude, latitude, radius, scene, parent=None):
        """Constructor.

        Args:
            longitude(float): Longitude of the center of the circle.
            latitude(float): Latitude of the center of the circle.
            radius(float): Radius of the circle in pixels.
            scene(MapGraphicsScene): Scene to which the circle belongs.
            parent(QGraphicsItem): Parent item, default None.

        Note:
            The management of the parent item is work in progress.
        """
        QGraphicsEllipseItem.__init__(self, parent=parent, scene=scene)

        self._lon = longitude
        self._lat = latitude
        self._radius = radius

        d = self._radius * 2
        self.setRect(0, 0, d, d)

        self.updatePosition(scene)
예제 #29
0
    def __init__(self, longitude, latitude, radius, scene, parent=None):
        """Constructor.

        Args:
            longitude(float): Longitude of the center of the circle.
            latitude(float): Latitude of the center of the circle.
            radius(float): Radius of the circle in pixels.
            scene(MapGraphicsScene): Scene to which the circle belongs.
            parent(QGraphicsItem): Parent item, default None.

        Note:
            The management of the parent item is work in progress.
        """
        QGraphicsEllipseItem.__init__(self, parent=parent, scene=scene)

        self._lon = longitude
        self._lat = latitude
        self._radius = radius

        d = self._radius * 2
        self.setRect(0, 0, d, d)

        self.updatePosition(scene)
예제 #30
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
예제 #31
0
    def __init__(self, name, radius, parent=None):
        QGraphicsEllipseItem.__init__(self, QRectF(-radius, -radius, radius*2.0, radius*2.0), parent=parent)

        self._name = name

        pfname = parent.fullname()
        if pfname is not None:
            self._fullname = pfname + ':' + name
        else:
            self._fullname = parent.name() + ':' + name

        pen = QPen(QColor('#000000'))
        pen.setWidth(3)
        self.setPen(pen)

        brush = QBrush(QColor('#000000'))
        self.setBrush(brush)

        self.setToolTip(name)

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

        self._isDraggingLine = False
예제 #32
0
 def __init__(self, parent = None):
     super(AxisScene, self).__init__(parent)
     self.guidePen = QPen(QColor("blue"),1)
     self.dot = QGraphicsEllipseItem(-10, -10, 20, 20)
     self.dot.setPos(QPointF(0,0))
     self.dot.setPen(QPen(QColor("red"), 4))
     self.dot.setBrush(QColor("black"))
     self.lastPos = {}
     self.lastPos['x'] = 0
     self.lastPos['y'] = 0
     self.grid = False
     self.gridPen = QPen(QColor("blue"), 2)
     self.pathItem = QGraphicsPathItem()
     self.pathItem.setPen(QPen(QColor("red"), 1, Qt.DotLine))
     self.path = None
     self.xAxis = "Select Axis..."
     self.yAxis = self.xAxis
     self.addItem(self.dot)
예제 #33
0
 def _update_add_area(self,event):
     p = event.scenePos()
     self.current_op_stat['points'].append(p)
     
     el_it = QGraphicsEllipseItem(p.x()-2,p.y()-2,4,4)
     
     HMItem.module(el_it,self.__class__.__name__)
     HMItem.type(el_it,HMItem.OUTLINE_POINT)
     HMItem.level(el_it, -1)
     el_it.setPen(QPen(Qt.black,
                       1, 
                       Qt.SolidLine, 
                       Qt.RoundCap, 
                       Qt.RoundJoin))
     el_it.setBrush(QBrush(Qt.Dense4Pattern))
     el_it.setZValue(1)
     self.home_map_scene.addItem(el_it)
예제 #34
0
파일: owtools.py 프로젝트: waqarini/orange3
class CircleCurve(OWCurve):
    """
        Displays a circle on the plot

        :param pen: The pen used to draw the outline of the circle
        :type pen: QPen

        :param brush: The brush used to paint the inside of the circle
        :type brush: QBrush

        :param xCenter: The x coordinate of the circle's center
        :type xCenter: float

        :param yCenter: The y coordinate of the circle's center
        :type yCenter: float

        :param radius: The circle's radius
        :type radius: float
    """
    def __init__(self,
                 pen=QPen(Qt.black),
                 brush=QBrush(Qt.NoBrush),
                 xCenter=0.0,
                 yCenter=0.0,
                 radius=1.0):
        OWCurve.__init__(self)
        self._item = QGraphicsEllipseItem(self)
        self.center = xCenter, yCenter
        self.radius = radius
        self._rect = QRectF(xCenter - radius, yCenter - radius, 2 * radius,
                            2 * radius)
        self.set_pen(pen)
        self.set_brush(brush)

    def update_properties(self):
        self._item.setRect(self.graph_transform().mapRect(self.data_rect()))
        self._item.setPen(self.pen())
        self._item.setBrush(self.brush())

    def data_rect(self):
        x, y = self.center
        r = self.radius
        return QRectF(x - r, y - r, 2 * r, 2 * r)
예제 #35
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
예제 #36
0
파일: owtools.py 프로젝트: kereturn/orange3
class CircleCurve(OWCurve):
    """
        Displays a circle on the plot

        :param pen: The pen used to draw the outline of the circle
        :type pen: QPen

        :param brush: The brush used to paint the inside of the circle
        :type brush: QBrush

        :param xCenter: The x coordinate of the circle's center
        :type xCenter: float

        :param yCenter: The y coordinate of the circle's center
        :type yCenter: float

        :param radius: The circle's radius
        :type radius: float
    """

    def __init__(self, pen=QPen(Qt.black), brush=QBrush(Qt.NoBrush), xCenter=0.0, yCenter=0.0, radius=1.0):
        OWCurve.__init__(self)
        self._item = QGraphicsEllipseItem(self)
        self.center = xCenter, yCenter
        self.radius = radius
        self._rect = QRectF(xCenter - radius, yCenter - radius, 2 * radius, 2 * radius)
        self.set_pen(pen)
        self.set_brush(brush)

    def update_properties(self):
        self._item.setRect(self.graph_transform().mapRect(self.data_rect()))
        self._item.setPen(self.pen())
        self._item.setBrush(self.brush())

    def data_rect(self):
        x, y = self.center
        r = self.radius
        return QRectF(x - r, y - r, 2 * r, 2 * r)
예제 #37
0
class DraggedLineItem(QGraphicsPathItem):

    def __init__(self, p0, p1, parent=None):
        QGraphicsPathItem.__init__(self, parent=parent)

        self._p0 = p0
        self._p1 = p1

        self._startPoint = QGraphicsEllipseItem(-3, -3, 6, 6, parent=self)
        self._startPoint.setPos(p0)
        self._endPoint = QGraphicsEllipseItem(-3, -3, 6, 6, parent=self)
        self._endPoint.setVisible(False)

        brush = QBrush(QColor(Qt.black))
        self._startPoint.setBrush(brush)
        self._endPoint.setBrush(brush)

        pen = QPen(brush, 2.0)
        self.setPen(pen)

    def showEndpoint(self, show):
        self._endPoint.setVisible(show)

    def setEndpoint(self, pos):
        self._p1 = pos
        self._endPoint.setPos(pos)
        self._updatePath()

    def _updatePath(self):
        p0 = self._p0
        p1 = self._p1

        path = QPainterPath()
        path.moveTo(p0)
        dx = p1.x() - p0.x()
        x0 = p0.x() + 0.7 * dx
        x1 = p1.x() - 0.7 * dx
        path.cubicTo(QPointF(x0, p0.y()), QPointF(x1, p1.y()), p1)
        self.setPath(path)
예제 #38
0
 def __init__(self, *args):
     QGraphicsEllipseItem.__init__(self, *args)
     self.setRect(-3.5, -3.5, 7., 7.)
     self.setPen(QPen(Qt.NoPen))
     self.setBrush(QBrush(QColor("#9CACB4")))
     self.__hover = False
예제 #39
0
파일: ui.py 프로젝트: jlowenz/pyimgann
 def item(self):
     if self.item_ is None:
         num_pts = len(self.pts_)
         if num_pts == 1:
             # draw a point          
             item = QGraphicsEllipseItem(self.pts_[0][0]-self.radius_,
                                         self.pts_[0][1]-self.radius_,
                                         2*self.radius_,
                                         2*self.radius_)
             item.setBrush(self.qcolor)
         elif num_pts == 2:
             item = QGraphicsLineItem(self.pts_[0][0], self.pts_[0][1],
                                      self.pts_[1][0], self.pts_[1][1])
         else:
             poly = QPolygonF()
             for p in self.pts_:
                 poly.append(QPointF(p[0],p[1]))
             item = QGraphicsPolygonItem(poly)
         item.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable)
         item.setPen(self.qcolor)
         item.setEnabled(True)
         item.setActive(True)
         self.item_ = item
     return self.item_
예제 #40
0
	def __init__(self, world):

		QGraphicsPolygonItem.__init__(self)
		
		#############################
		### Build graph
		#############################

		graph = pydot.Dot()
		graph.set_node_defaults(color = 'red', fontcolor = 'red', label = '\<orphan\>')
		graph.set('overlap', 'prism')
		
		# build adjacency graph from world
		for area in world.areas:
		
			# create node for each room
			node = pydot.Node(area.id)
			node.set( 'label', area.name )
			if area == world.player.currentArea:
				node.set( 'color', 'blue' )
				node.set( 'fontcolor', 'blue' )
			else:
				node.set( 'color', 'black' )
				node.set( 'fontcolor', 'black' )

			graph.add_node(node)

			# link to adjacent rooms
			for feature in area.features:
				for action in feature.actions:
					finalEvent = None
					for event in action.events:
						if type(event) == events.PlayerMoveEvent:
							finalEvent = pydot.Edge( src=area.id, dst=event.properties['destination'] )

					if finalEvent is not None:
						graph.add_edge( finalEvent )
	
		################################
		### Generate SVG from graph
		################################

		ps = graph.create_svg(prog='neato')

		#########################################
		### Build graphics items from SVG
		#########################################

		# build xml tree
		ns = {'svg': 'http://www.w3.org/2000/svg'}
		doc = ET.fromstring(ps)

		# grab the root node properties
		rootNode = doc.xpath('/svg:svg/svg:g[1]', namespaces=ns)[0]
		polygon = rootNode.xpath('./svg:polygon', namespaces=ns)[0]
		pointStr = polygon.xpath('./@points', namespaces=ns)[0]
		penColor = QString(polygon.xpath('./@stroke', namespaces=ns)[0])
		fillColor = QString(polygon.xpath('./@fill', namespaces=ns)[0])

		# parse root polygon path
		path = QPolygonF()
		for pair in pointStr.split(' '):
			dims = pair.split(',')
			point = QPointF( float(dims[0]), float(dims[1]) )
			path.append(point)
		self.setPolygon(path)

		# fill in root node colors
		if QColor.isValidColor(penColor):
			self.setPen( QColor(penColor) )
		if QColor.isValidColor(fillColor):
			self.setBrush( QColor(fillColor) )

		# build each graph node
		for xmlNode in rootNode.xpath('./svg:g', namespaces=ns):

			group = QGraphicsRectItem(self)
			group.setPen( Qt.transparent )
			group.setBrush( Qt.transparent )


			if xmlNode.attrib['class'] == 'node':

				# find the area object
				name = xmlNode.xpath('./svg:title', namespaces=ns)[0].text
				group.setData( 0, QString(world.areas[world.areaLookup[name]].id) )
				
				# get the ellipse info
				ellipseNode = xmlNode.xpath('./svg:ellipse', namespaces=ns)[0]
				elProps = { k: float(ellipseNode.attrib[k]) for k in ['cx', 'cy', 'rx', 'ry']}
				rect = QRectF( elProps['cx']-elProps['rx'], elProps['cy']-elProps['ry'], 2*elProps['rx'], 2*elProps['ry'])
				penColor = QString(ellipseNode.attrib['stroke'])
				ellipseItem = QGraphicsEllipseItem(rect, group)
				if QColor.isValidColor(penColor):
					ellipseItem.setPen( QColor(penColor) )

				# get the text info
				textNode = xmlNode.xpath('./svg:text', namespaces=ns)[0]
				text = textNode.text
				textItem = QGraphicsTextItem(text, group)
				penColor = textNode.attrib.get('fill', 'black')
				nodePoint = QPointF(float(textNode.attrib['x']), float(textNode.attrib['y']))
				textItem.setPos( nodePoint - textItem.boundingRect().center() + QPointF(0.0,-4.0))
				if QColor.isValidColor(penColor):
					textItem.setDefaultTextColor( QColor(penColor) )

				group.setRect( ellipseItem.boundingRect() )
				group.setFlags( QGraphicsRectItem.ItemIsSelectable )

			elif xmlNode.attrib['class'] == 'edge':

 				# parse the line portion of the arrow
 				line = xmlNode.xpath('./svg:path', namespaces=ns)[0]
				path = QPainterPath()

				# pull info from xml file
				linePath = line.attrib['d']
				lineColor = line.attrib['stroke']
					
				# parse path coords
				points = re.findall( '(-?\d+\.\d+),(-?\d+\.\d+)', linePath )
				if len(points) != 4:
					continue
				startPoint = QPointF( float(points[0][0]), float(points[0][1]) )
				path.moveTo(startPoint)
				curvePoints = []
				for pointCoord in points[1:]:
					curvePoints.append( QPointF(float(pointCoord[0]), float(pointCoord[1])) )
				path.cubicTo( curvePoints[0], curvePoints[1], curvePoints[2] )

				# construct path item
				pathItem = QGraphicsPathItem(path, group)
				if QColor.isValidColor(lineColor):
					pathItem.setPen( QColor(lineColor) )

				polyNode = xmlNode.xpath('./svg:polygon', namespaces=ns)[0]

				# pull info from xml file
				pointStr = polyNode.xpath('./@points', namespaces=ns)[0]
				penColor = QString(polyNode.xpath('./@stroke', namespaces=ns)[0])
				fillColor = QString(polyNode.xpath('./@fill', namespaces=ns)[0])

				# parse polygon path
				path = QPolygonF()
				for pair in pointStr.split(' '):
					dims = pair.split(',')
					point = QPointF( float(dims[0]), float(dims[1]) )
					path.append(point)

				# construct polygon item
				polygonItem = QGraphicsPolygonItem(path, group)
				if QColor.isValidColor(penColor):
					polygonItem.setPen( QColor(penColor) )
				if QColor.isValidColor(fillColor):
					polygonItem.setBrush( QColor(fillColor) )

				group.setRect( pathItem.boundingRect() and polygonItem.boundingRect() )
예제 #41
0
 def hoverEnterEvent(self, event):
     QGraphicsEllipseItem.hoverEnterEvent(self, event)
     event.accept()
     self.setIsHover(True)
예제 #42
0
 def constructPieChart(self, distrib, numbs):
     pie = QGraphicsItemGroup()
     totArc = 0
     for j, num, dist in reversed(
             list(zip(list(range(len(numbs))), numbs, distrib))):
         arc = QGraphicsEllipseItem(-self.pieWidth / 2, -self.pieWidth / 2,
                                    self.pieWidth, self.pieHeight)
         arc.setPen(QPen(QColor(0, 0, 0), 1, Qt.SolidLine))
         arc.setBrush(QBrush(self.discPalette[j]))
         arc.setToolTip(
             "%s: %.3f" %
             (self.attributes[self.selectedAttributes[j]][0], num) +
             (" (%2.1f%%)" %
              (dist / self.barHeight * 100) if self.normalize else ""))
         arc.setStartAngle(totArc)
         arc.setSpanAngle(dist * 2880 / self.barHeight)
         pie.addToGroup(arc)
         totArc += dist * 2880 / self.barHeight
     return pie
예제 #43
0
 def hoverLeaveEvent(self, event):
     QGraphicsEllipseItem.hoverLeaveEvent(self, event)
     event.accept()
     self.setIsHover(False)