Beispiel #1
0
    def __init__(self, scene, x, y, w, h):

        self.w = w
        self.h = h

        super(LabelItem, self).__init__(scene, x, y)

        self.message = None
        self.temp_msgs = []

        rospack = rospkg.RosPack()
        self.icons_path = rospack.get_path('art_projected_gui') + '/icons/'

        self.icons = {}
        self.icons[NotifyUserRequest.INFO] = QtSvg.QGraphicsSvgItem(
            self.icons_path + 'Antu_dialog-information.svg', self)
        self.icons[NotifyUserRequest.WARN] = QtSvg.QGraphicsSvgItem(
            self.icons_path + 'Antu_dialog-warning.svg', self)
        self.icons[NotifyUserRequest.ERROR] = QtSvg.QGraphicsSvgItem(
            self.icons_path + 'Antu_emblem-important.svg', self)
        self.icons[NotifyUserRequest.YES_NO_QUESTION] = QtSvg.QGraphicsSvgItem(
            self.icons_path + 'Antu_dialog-question.svg', self)

        s = self.m2pix(self.h)
        for k, v in self.icons.iteritems():

            v.setScale(s / v.boundingRect().height())
            v.setPos(0, 0)
            v.setVisible(False)

        self.timer = rospy.Timer(rospy.Duration(0.5), self.timer_cb)
        self.setCacheMode(QtGui.QGraphicsItem.ItemCoordinateCache)
        self.setZValue(200)
Beispiel #2
0
 def infr_flag(self, time, rule):
     # To align the flag's pointer correctly, subtract 25 from the
     # desired minute
     xform = QtGui.QTransform()
     if rule == "hgv":
         flag = QtSvg.QGraphicsSvgItem('./icons/drive_infr.svg')
         flag.setTransform(xform.translate((time - 25), -20))
     else:
         flag = QtSvg.QGraphicsSvgItem('./icons/wtd_infr.svg')
         flag.setTransform(xform.translate((time - 25), 45))
     self.addItem(flag)
     self.flag_list.append(flag)
Beispiel #3
0
def show_tree(t, layout=None, tree_style=None):
    """ Interactively shows a tree."""
    scene, img = init_scene(t, layout, tree_style)
    tree_item, n2i, n2f = render(t, img)
    scene.init_data(t, img, n2i, n2f)

    tree_item.setParentItem(scene.master_item)
    scene.addItem(scene.master_item)

    size = tree_item.rect()
    w, h = size.width(), size.height()

    svg = QtSvg.QSvgGenerator()
    svg.setFileName("test.svg")
    svg.setSize(QtCore.QSize(w, h))
    svg.setViewBox(size)

    pp = QtGui.QPainter()
    pp.begin(svg)
    #pp.setRenderHint(QtGui.QPainter.Antialiasing)
    #pp.setRenderHint(QtGui.QPainter.TextAntialiasing)
    #pp.setRenderHint(QtGui.QPainter.SmoothPixmapTransform)
    scene.render(pp, tree_item.rect(), tree_item.rect(),
                 QtCore.Qt.KeepAspectRatio)
    pp.end()

    img = QtSvg.QGraphicsSvgItem("test.svg")
    #img.setParentItem(scene.master_item)
    #scene.removeItem(tree_item)
    #tree_item.setVisible(False)

    mainapp = _GUI(scene)
    mainapp.show()
    _QApp.exec_()
Beispiel #4
0
    def initItems(self):
        darkGray = QtGui.QColor(64, 64, 64)
        boundingRect = QRectF(0, 0, 10, 10)
        self.graphicsView.setBackgroundBrush(QtGui.QBrush(Qt.darkGray))
        scene = self.graphicsView.scene()
        scene.clearSelection(
        )  #scene.clear()!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        self.svgItem = QtSvg.QGraphicsSvgItem()
        self.svgItem.setFlags(QtGui.QGraphicsItem.ItemClipsToShape)
        #        self.svgItem.setCacheMode(QtGui.QGraphicsItem.NoCache)
        self.svgItem.setZValue(0)

        self.shadowItem = QtGui.QGraphicsRectItem(
            boundingRect.adjusted(-1, -1, 2, 2))
        self.shadowItem.setBrush(QtGui.QBrush(darkGray))
        self.shadowItem.setPen(QtGui.QPen(darkGray))
        self.shadowItem.setZValue(-2)
        self.shadowItem.setPos(4, 4)

        self.frameItem = QtGui.QGraphicsRectItem(
            boundingRect.adjusted(-1, -1, 2, 2))
        self.frameItem.setBrush(QtGui.QBrush(Qt.white))
        self.frameItem.setPen(QtGui.QPen(darkGray))
        self.frameItem.setZValue(-1)
        self.frameItem.setPos(-1, -1)

        scene.addItem(self.shadowItem)
        scene.addItem(self.frameItem)
        scene.addItem(self.svgItem)
        scene.setSceneRect(boundingRect.adjusted(-3, -3, 10, 10))
Beispiel #5
0
    def __init__(self, rads=0, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.checkerboard = array([[0, 255, 255, 255], [255, 0, 255, 255],
                                   [0, 255, 0, 255], [255, 0, 255, 0],
                                   [0, 255, 0, 255], [255, 0, 255, 255],
                                   [0, 255, 255, 255]])

        im = Image.fromarray(self.checkerboard)
        im.save('arrow.png')

        self.scene = QtGui.QGraphicsScene()
        self.head = QtSvg.QGraphicsSvgItem("checkered_arrow_3_op.svg")
        trans = QtGui.QTransform()
        trans.translate(-self.head.boundingRect().width() / 2,
                        -self.head.boundingRect().height() / 2)
        self.head.setTransform(trans)

        self.type = 0
        self.size = 170
        self.color = None
        self.frequency = 10
        self.rads = rads
        self.timer = QtCore.QTimer()
        self.pixmap = None
        self.pixmap_black = None
        self.pixmap_green = None
        self.point = QPointF(0.0, 0.0)

        QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"),
                               self.changeColor)
Beispiel #6
0
    def __init__(self, parent=None):
        super(self.__class__, self).__init__(parent)
        self.setupUi(self)

        self.graphicsViewBoard = myqgraph.ItaloGraphicsView(self.centralwidget)
        self.add_board_to_ui()

        self.start_in = None
        self.finish_in = None

        self.engine = chess.uci.popen_engine("models/stockfish-8-linux/Linux/stockfish_8_x64")
        self.engine.uci()

        self.board = chess.Board()
        self.board_svg = chess.svg.board(self.board)
        self.scene = QGraphicsScene(self.graphicsViewBoard)
        self.graphicsViewBoard.setScene(self.scene)
        self.item = QtSvg.QGraphicsSvgItem('tmp.svg')

        self.btn_connections()

        self.command = None

        self.btn_computer_move.setVisible(False)
        self.do_iniciar()
Beispiel #7
0
 def svgdraw(self):  # instance
     scene = QtGui.QGraphicsScene()
     self.ui.graphicsView.setScene(scene)
     br = QtSvg.QGraphicsSvgItem("/Users/Regina/Desktop/tmp1.svg")
     # text = QtSvg.QGraphicsSvgItem("/Users/Regina/Documents/Pázmány/Onallo_labor/Project/Python/What'sWrong_SVG/szoveg.svg")
     scene.addItem(br)
     self.ui.graphicsView.show()
Beispiel #8
0
    def __init__(self, scene, x, y, w, h, fn, fixed=False):

        self.img = None
        self.w = 0
        self.h = 0

        super(IconItem, self).__init__(scene, x, y)

        self.icon = QtSvg.QGraphicsSvgItem(fn, self)

        self.setCacheMode(QtGui.QGraphicsItem.ItemCoordinateCache)
        self.setZValue(100)

        self.fixed = fixed
        self.setFlag(QtGui.QGraphicsItem.ItemIsMovable, True)
        self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable, True)

        self.w = self.m2pix(w)
        self.h = self.m2pix(h)

        self.icon.setScale(
            min(
                self.boundingRect().height() /
                self.icon.boundingRect().height(),
                self.boundingRect().width() /
                self.icon.boundingRect().width()))
Beispiel #9
0
    def openFileIMG(self, img_file):

        s = self.scene()

        if self.backgroundItem:
            drawBackground = self.backgroundItem.isVisible()
        else:
            drawBackground = True

        if self.outlineItem:
            drawOutline = self.outlineItem.isVisible()
        else:
            drawOutline = True

        if self.TraceImage:
            drawOutline = self.outlineItem.isVisible()
        else:
            drawOutline = True

        s.clear()
        img = QtGui.QPixmap(img_file)
        self.TraceImage = QtGui.QGraphicsPixmapItem(img)
        self.TraceImage.setFlags(QtGui.QGraphicsItem.ItemClipsToShape)
        self.TraceImage.setCacheMode(QtGui.QGraphicsItem.NoCache)
        self.TraceImage.setZValue(1)

        effect = QtGui.QGraphicsOpacityEffect(self)
        self.TraceImage.setGraphicsEffect(effect)
        self.setOpacity(self.opacity)
        self.TraceImage.setZValue(1)

        self.svgItem = QtSvg.QGraphicsSvgItem()
        self.svgItem.setFlags(QtGui.QGraphicsItem.ItemClipsToShape)
        self.svgItem.setCacheMode(QtGui.QGraphicsItem.NoCache)
        self.svgItem.setZValue(0)

        self.backgroundItem = QtGui.QGraphicsRectItem(
            self.TraceImage.boundingRect())
        self.backgroundItem.setBrush(QtCore.Qt.white)
        self.backgroundItem.setPen(QtGui.QPen(QtCore.Qt.NoPen))
        self.backgroundItem.setVisible(drawBackground)
        self.backgroundItem.setZValue(-1)

        self.outlineItem = QtGui.QGraphicsRectItem(
            self.TraceImage.boundingRect())
        outline = QtGui.QPen(QtCore.Qt.darkGray, 1.5, QtCore.Qt.SolidLine)
        outline.setCosmetic(True)
        self.outlineItem.setPen(outline)
        self.outlineItem.setBrush(QtGui.QBrush(QtCore.Qt.NoBrush))
        self.outlineItem.setVisible(drawOutline)
        self.outlineItem.setZValue(2)

        s.addItem(self.backgroundItem)
        s.addItem(self.svgItem)
        s.addItem(self.TraceImage)
        s.addItem(self.outlineItem)

        s.setSceneRect(self.outlineItem.boundingRect().adjusted(
            -10, -10, 10, 10))
Beispiel #10
0
    def __init__(self, robot, rend):
        self.pos = 15, 15
        self.ang = 0
        self.scale = 1
        self.cx, self.cy = 15, 15

        GraphicsItem.__init__(self)

        self.item = QtSvg.QGraphicsSvgItem(robot.item)
        self.item.setSharedRenderer(rend)
        self.item.setElementId('turret')
        self.set_transform()
Beispiel #11
0
    def draw_arrow(self):

        self.scene.setBackgroundBrush(
            QtGui.QBrush(QtCore.Qt.white, QtCore.Qt.SolidPattern))

        arrow = QtSvg.QGraphicsSvgItem("checkered_arrow_3.svg")
        trans = QtGui.QTransform()
        trans.rotateRadians(self.rads)
        trans.translate(-arrow.boundingRect().width() / 2,
                        -arrow.boundingRect().height() / 2)
        arrow.setTransform(trans)
        self.scene.addItem(arrow)
 def _updateContent(self, fname):
     imagefile, comment = self.getDiagram(fname, engine[self._engine])
     svg = QtSvg.QGraphicsSvgItem(imagefile)
     scale = min(self._diagram.width() / svg.boundingRect().width(),
                 self._diagram.height() / svg.boundingRect().height())
     svg.scale(scale, scale)
     scene = QtGui.QGraphicsScene(self)
     scene.addItem(svg)
     self._diagram.setScene(scene)
     self._content.setText(comment)
     self.window().setWindowTitle(fname + ".gv with engine " +
                                  engine[self._engine] + ")")
Beispiel #13
0
    def update_board(self):
        if self.start_in is None:
            self.board_svg = chess.svg.board(self.board, size=400)
        else:
            self.board_svg = chess.svg.board(self.board, size=400,
                                             arrows=[(chess.SQUARE_NAMES.index(self.start_in),
                                                      chess.SQUARE_NAMES.index(self.start_in))])
        with open('tmp.svg', 'w') as temp_file:
            temp_file.write(self.board_svg)

        if len(self.scene.items()) > 0:
            self.scene.removeItem(self.scene.items()[0])
        self.item = QtSvg.QGraphicsSvgItem('tmp.svg')
        self.scene.addItem(self.item)
Beispiel #14
0
    def openFile(self, svg_file, reset_scale=True):
        if not svg_file.exists():
            return

        s = self.scene()

        if self.backgroundItem:
            drawBackground = self.backgroundItem.isVisible()
        else:
            drawBackground = False

        if self.outlineItem:
            drawOutline = self.outlineItem.isVisible()
        else:
            drawOutline = True

        s.clear()
        if reset_scale:
            self.resetTransform()

        self.svgItem = QtSvg.QGraphicsSvgItem(svg_file.fileName())
        self.svgItem.setFlags(QtGui.QGraphicsItem.ItemClipsToShape)
        self.svgItem.setCacheMode(QtGui.QGraphicsItem.NoCache)
        self.svgItem.setZValue(0)

        self.backgroundItem = QtGui.QGraphicsRectItem(
            self.svgItem.boundingRect())
        self.backgroundItem.setBrush(QtCore.Qt.white)
        self.backgroundItem.setPen(QtGui.QPen(QtCore.Qt.NoPen))
        self.backgroundItem.setVisible(drawBackground)
        self.backgroundItem.setZValue(-1)

        self.outlineItem = QtGui.QGraphicsRectItem(self.svgItem.boundingRect())
        outline = QtGui.QPen(QtCore.Qt.black, 2, QtCore.Qt.DashLine)
        outline.setCosmetic(True)
        self.outlineItem.setPen(outline)
        self.outlineItem.setBrush(QtGui.QBrush(QtCore.Qt.NoBrush))
        self.outlineItem.setVisible(drawOutline)
        self.outlineItem.setZValue(1)

        s.addItem(self.backgroundItem)
        s.addItem(self.svgItem)
        s.addItem(self.outlineItem)

        s.setSceneRect(self.outlineItem.boundingRect().adjusted(
            -10, -10, 10, 10))
Beispiel #15
0
    def __init__(self, pos, ang, rend):
        Robot.nrobots += 1

        self.pos = tl(pos)
        self.ang = ang
        self.scale = 1
        self.cx, self.cy = 15, 15

        GraphicsItem.__init__(self)

        imageid = 'r{0:02d}'.format(Robot.nrobots)
        self.item = QtSvg.QGraphicsSvgItem(self)
        self.item.setSharedRenderer(rend)
        self.item.setElementId(imageid)

        self.turr = Turret(self, rend)

        self.set_transform()
    def open_file(self, filename):
        svg_file = QtCore.QFile(filename)

        if not svg_file.exists():
            return

        s = self.scene()

        s.clear()
        self.resetTransform()

        self.svgItem = QtSvg.QGraphicsSvgItem(svg_file.fileName())
        self.svgItem.setFlags(QtGui.QGraphicsItem.ItemClipsToShape)
        self.svgItem.setCacheMode(QtGui.QGraphicsItem.NoCache)
        self.svgItem.setZValue(0)

        s.addItem(self.svgItem)

        s.setSceneRect(self.svgItem.boundingRect().adjusted(-10, -10, 10, 10))
Beispiel #17
0
    def updateNLPGraphics(self):
        filtered = self.filterInstance()
        self._SVGScene = Scene(width=800)

        renderer = self._renderers[filtered.renderType]

        dim = renderer.render(filtered, self._SVGScene)

        self._SVGScene = Scene(width=dim[0], height=dim[1])

        renderer.render(filtered, self._SVGScene)
        self._SVGScene.write_svg("tmp.svg")
        path = os.path.abspath("tmp.svg")

        scene = QtGui.QGraphicsScene()
        self._ui.graphicsView.setScene(scene)
        br = QtSvg.QGraphicsSvgItem(path)
        scene.addItem(br)
        self._ui.graphicsView.show()
        self.fireChanged()
    def wiring_graph(self):
        if self._wiring:
            self._wiring.hide()
            self._wiring.close()
            self._wiring = False
        # Temp file
        svg_filename = render_wiring(self.remObj.wiring())

        # Scene
        scene = QtGui.QGraphicsScene()
        view = QtGui.QGraphicsView()
        view.setScene(scene)
        svg = QtSvg.QGraphicsSvgItem(svg_filename)
        scene.addItem(svg)
        # Display widget
        wg = QtGui.QWidget()
        lay = QtGui.QVBoxLayout()
        wg.setLayout(lay)
        lay.addWidget(view)
        wg.show()
        self._wiring = wg
        # Cleanup
        os.remove(svg_filename)
Beispiel #19
0
    def clear_board(self):
        """Clear and prepare board for animation"""

        scene = self.scene()
        scene.clear()
        self.resetTransform()

        self.xml_stream_reader = QtCore.QXmlStreamReader()
        if self.frame_template:
            self.xml_stream_reader = QtCore.QXmlStreamReader(
                self.frame_template)

        self.svg_renderer = QtSvg.QSvgRenderer(self.xml_stream_reader)
        self.svg_item = QtSvg.QGraphicsSvgItem()
        self.svg_item.setSharedRenderer(self.svg_renderer)
        self.svg_item.setFlags(QtGui.QGraphicsItem.ItemClipsToShape)
        self.svg_item.setCacheMode(QtGui.QGraphicsItem.NoCache)
        self.svg_item.setZValue(0)

        scene.addItem(self.svg_item)

        scene.setSceneRect(self.svg_item.boundingRect().adjusted(
            -10, -10, 10, 10))
Beispiel #20
0
 def show_fullscreen_svg(self, path):
     """:param path: path to an svg file"""
     from PyQt4 import QtSvg
     item = QtSvg.QGraphicsSvgItem(path)
     self.show_fullscreen_item(item)
    def drawMap(self):
        self.scene.clear()

        font = QtGui.QFont('Times', 8, QtGui.QFont.Bold);

        # svg = QtSvg.QGraphicsSvgItem('electrodes.svg')
        #
        #        painter = QtGui.QPainter(self.pixmap)
        #
        #        QtSvg.QGraphicsSvgItem.paint(svg, painter, QtGui.QStyleOptionGraphicsItem())
        #
        #        for item in svg.childItems():
        #            print item.elementId()
        #            QtSvg.QGraphicsSvgItem.paint(item, painter, QtGui.QStyleOptionGraphicsItem())

        # Background
        for i in range(8):
            line = QtSvg.QGraphicsSvgItem()
            line.setSharedRenderer(self.renderer)
            line.setElementId('line' + str(i))
            br = self.renderer.boundsOnElement('line' + str(i))
            qtr = QtGui.QTransform()
            qtr.translate(br.x(), br.y())

            line.setTransform(qtr)

            #QtSvg.QGraphicsSvgItem.paint(line, painter, QtGui.QStyleOptionGraphicsItem()) 
            self.scene.addItem(line)
            #self.renderer.render(painter,line.boundingRect()); 

        # Electrodes
        for electrode, quality in zip(self.electrode_names, self.electrode_quality):
            elec_circle = QtSvg.QGraphicsSvgItem()
            elec_circle.setSharedRenderer(self.renderer)
            elec_circle.setElementId(electrode + '_circle')
            br = self.renderer.boundsOnElement(electrode + '_circle')
            #qtr = QtGui.QTransform()
            #qtr.translate(br.x(), br.y())
            #elec_circle.setTransform(qtr)

            elec_bg = QtGui.QGraphicsEllipseItem(br)
            elec_bg.setBrush(QtGui.QBrush(QtGui.QColor(255, 255, 255)))

            elec_color = QtGui.QGraphicsEllipseItem(br)
            elec_color.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0), 2))

            if quality == 0:
                color = QtGui.QColor(255, 0, 0, 128)
            elif quality == 1:
                color = QtGui.QColor(255, 255, 0, 128)
            elif quality == 2:
                color = QtGui.QColor(0, 255, 0, 128)
            else:
                color = QtGui.QColor(255, 153, 0, 128)

            elec_color.setBrush(QtGui.QBrush(color))

            elec_text = QtGui.QGraphicsTextItem()
            elec_text.setFont(font)
            elec_text.setPlainText(electrode)
            x = br.x() + br.width() / 2 - elec_text.boundingRect().width() / 2
            y = br.y() + br.height() / 2 - elec_text.boundingRect().height() / 2
            elec_text.setPos(x, y)

            self.scene.addItem(elec_bg)
            self.scene.addItem(elec_color)
            #self.scene.addItem(elec_circle)
            self.scene.addItem(elec_text)