示例#1
0
 def intrinsicSize(self, doc, posInDocument, tformat):
     pic = tformat.property(MainWindow.QCPData)
     if pic == None:
         print("Plot is empty")
         return QSizeF(10, 10)
     size = QSizeF(pic.boundingRect().size())
     return size
示例#2
0
    def aboutUpdateDocumentGeometry(self):
        # Very important function
        # Determines the size of the document using the page metrics
        # TODO To adjust the width in non-paged mode, change the default self.width()
        # below to the desired width...
        documentSize = QSizeF(self.width() - self.verticalScrollBar().width(),
                              -1)
        if (self.m_usePageMode):
            # This condition ensures that only the width and height in paged mode is adjusted
            pageWidth = self.m_pageMetrics.pxPageSize().width()
            pageHeight = self.m_pageMetrics.pxPageSize().height()
            documentSize = QSizeF(pageWidth, pageHeight)

        # Update document size
        if (self.document().pageSize() != documentSize):
            self.document().setPageSize(documentSize)

        # At the same time, set the indents
        # ... remove the document
        if (self.document().documentMargin() != 0):
            self.document().setDocumentMargin(0)

        # ... and adjust the document fields
        rootFrameMargins = self.m_pageMetrics.pxPageMargins()
        rootFrameFormat = self.document().rootFrame().frameFormat()
        if (rootFrameFormat.leftMargin() != rootFrameMargins.left()
                or rootFrameFormat.topMargin() != rootFrameMargins.top()
                or rootFrameFormat.rightMargin() != rootFrameMargins.right() or
                rootFrameFormat.bottomMargin() != rootFrameMargins.bottom()):
            rootFrameFormat.setLeftMargin(rootFrameMargins.left())
            rootFrameFormat.setTopMargin(rootFrameMargins.top())
            rootFrameFormat.setRightMargin(rootFrameMargins.right())
            rootFrameFormat.setBottomMargin(rootFrameMargins.bottom())
            self.document().rootFrame().setFrameFormat(rootFrameFormat)
示例#3
0
文件: _View.py 项目: kurtu5/Labeler
 def __init__(self, pixmap, filename, index, parent=None):
     super().__init__(parent)
     #            self.rect = rect
     self.pixmap = pixmap
     self.filename = filename
     self.index = index
     self.setMinimumSize(QSizeF(self.pixmap.size()))
     self.setMaximumSize(QSizeF(self.pixmap.size()))
     defaultFont = QFont("default/font-family")
     self.label_font = defaultFont
示例#4
0
	def update(self, _pageFormat, _mmPageMargins=QMarginsF()):
		self.m_pageFormat = _pageFormat

		self.m_mmPageSize = QPageSize(self.m_pageFormat).rect(QPageSize.Millimeter).size()
		self.m_mmPageMargins = _mmPageMargins

		# Calculate values in pixels
		x = True; y = False
		self.m_pxPageSize = QSizeF(self.mmToPx(self.m_mmPageSize.width(), x), self.mmToPx(self.m_mmPageSize.height(), y))
		self.m_pxPageMargins = QMarginsF(self.mmToPx(self.m_mmPageMargins.left(), x), self.mmToPx(self.m_mmPageMargins.top(), y), self.mmToPx(self.m_mmPageMargins.right(), x), self.mmToPx(self.m_mmPageMargins.bottom(), y))
示例#5
0
    def testIt(self):
        scene = QGraphicsScene()

        minSize = QSizeF(30, 100)
        prefSize = QSizeF(210, 100)
        maxSize = QSizeF(300, 100)

        a = createItem(minSize, prefSize, maxSize, "A")
        b = createItem(minSize, prefSize, maxSize, "B")
        c = createItem(minSize, prefSize, maxSize, "C")
        d = createItem(minSize, prefSize, maxSize, "D")

        view = QGraphicsView(scene)
        view.show()
        self.app.exec_()
    def event(self, event):
        if event.type() == QEvent.TouchBegin or event.type(
        ) == QEvent.TouchUpdate or event.type() == QEvent.TouchEnd:
            touchPoints = event.touchPoints()
            for touchPoint in touchPoints:
                if touchPoint.state() == Qt.TouchPointStationary:
                    continue
                else:
                    rect = touchPoint.rect()
                    if rect.isEmpty():
                        diameter = 50 * touchPoint.pressure()
                        rect.setSize(QSizeF(diameter, diameter))

                    painter = QPainter(self.image)
                    painter.setPen(Qt.NoPen)
                    painter.setBrush(self.myPenColors[touchPoint.id() %
                                                      len(self.myPenColors)])
                    painter.drawEllipse(rect)
                    painter.end()

                    self.modified = True
                    rad = 2
                    self.update(rect.toRect().adjusted(-rad, -rad, +rad, +rad))

        else:
            return super(ScribbleArea, self).event(event)
        return True
示例#7
0
 def new_page(self, width, height):
     size = QSizeF(as_mm(width), as_mm(height))
     self.writer.setPageSizeMM(size)
     if self.painter is None:
         self.painter = QPainter(self.writer)
     else:
         self.writer.newPage()
示例#8
0
    def __init__(self, page_width, page_height, crop_margin_width=0 * mm):
        self.page_width = page_width
        self.page_height = page_height
        self.margin_width = crop_margin_width
        self.include_crop_marks = bool(crop_margin_width)

        QApplication(['my-q-application'])
        f = QFontDatabase.addApplicationFont(
            '../../fonts/OldStandard-Regular.ttf')
        f = QFontDatabase.addApplicationFont('OldStandard-Italic.ttf')
        f = QFontDatabase.addApplicationFont('OldStandard-Bold.ttf')
        f = QFontDatabase.addApplicationFont('fonts/Inconsolata-Regular.ttf')
        f = QFontDatabase.addApplicationFont('fonts/UbuntuMono-R.ttf')
        f = QFontDatabase.addApplicationFont('../../fonts/GenBasB.ttf')
        f = QFontDatabase.addApplicationFont('../../fonts/GenBasR.ttf')
        #f = QFontDatabase.addApplicationFont('../../fonts/Inconsolata-Regular.ttf')
        # print(f)
        names = QFontDatabase.applicationFontFamilies(f)
        # print(names)
        self.writer = QPdfWriter('book.pdf')
        size = QSizeF(as_mm(2 * crop_margin_width + page_width),
                      as_mm(2 * crop_margin_width + page_height))
        print(size)
        self.writer.setPageSizeMM(size)
        margins = QMarginsF(as_mm(crop_margin_width), as_mm(crop_margin_width),
                            as_mm(crop_margin_width), as_mm(crop_margin_width))
        print(margins)
        self.writer.setPageMargins(margins, QPageLayout.Millimeter)
        self.painter = QPainter(self.writer)
        if self.include_crop_marks:
            self.draw_crop_marks()
示例#9
0
    def ScalePicture(self):
        rect = QRectF(self.graphicsItem.pos(), QSizeF(self.pixMap.size()))
        unity = self.graphicsView.transform().mapRect(QRectF(0, 0, 1, 1))
        width = unity.width()
        height = unity.height()
        if width <= 0 or height <= 0:
            return
        self.graphicsView.scale(1 / width, 1 / height)
        viewRect = self.graphicsView.viewport().rect()
        sceneRect = self.graphicsView.transform().mapRect(rect)
        if sceneRect.width() <= 0 or sceneRect.height() <= 0:
            return
        x_ratio = viewRect.width() / sceneRect.width()
        y_ratio = viewRect.height() / sceneRect.height()
        x_ratio = y_ratio = min(x_ratio, y_ratio)

        self.graphicsView.scale(x_ratio, y_ratio)
        # if self.readImg.isStripModel:
        #     height2 = self.pixMap.size().height() / 2
        #     height3 = self.graphicsView.size().height()/2
        #     height3 = height3/x_ratio
        #     p = self.graphicsItem.pos()
        #     self.graphicsItem.setPos(p.x(), p.y()+height2-height3)
        self.graphicsView.centerOn(rect.center())

        for _ in range(abs(self.scaleCnt)):
            if self.scaleCnt > 0:
                self.graphicsView.scale(1.1, 1.1)
            else:
                self.graphicsView.scale(1 / 1.1, 1 / 1.1)
示例#10
0
    def build_invoice(self, data):
        document = QTextDocument()
        self.setDocument(document)
        document.setPageSize(QSizeF(self.doc_width, self.doc_height))
        document.setDefaultFont(font)
        cursor = QTextCursor(document)
        cursor.insertText(f"Customer Name: {data['c_name']}\n")
        cursor.insertText(f"Customer Address: {data['c_addr']}\n")
        cursor.insertText(f"Date: {data['i_date']}\n")
        cursor.insertText(f"Total Due: {data['total_due']}\n")
# +        
        return document                                                         # +++
示例#11
0
    def __init__(self,
                 label,
                 indices,
                 pos,
                 length,
                 height,
                 label_width,
                 frame_width,
                 color,
                 parent=None):
        super(TimeLine, self).__init__(parent)
        self._pos = pos
        self._length = length
        self._height = height
        self.label = label
        self._label_width = label_width
        self._indices = indices
        self.frame_width = frame_width

        size = QSizeF()
        size.setHeight(self._height)
        size.setWidth(self._length)
        self._bounding_rect = QRectF()
        self._bounding_rect.setX(self._pos.x())
        self._bounding_rect.setY(self._pos.y())
        self._bounding_rect.setSize(size)
        self._tpos = QPointF(pos)
        self._tpos.setY(pos.y() + self._height)
        self.color = QColor()
        self.color.setRed(color[0] * 255)
        self.color.setGreen(color[1] * 255)
        self.color.setBlue(color[2] * 255)
        self.color.setAlpha(255)
示例#12
0
    def drawArc(self, painter, line):
        topLeftPoint = self.calculatePerpendicularPoint(
            self.fromPoint, 50, line)
        arcRect = QRectF(topLeftPoint, QSizeF(line.length(), 100))
        if self._fromNode is self._toNode:
            spanAngle = -360
        else:
            spanAngle = -180

        path = QPainterPath()
        path.arcMoveTo(arcRect, spanAngle)
        path.arcTo(arcRect, -180, spanAngle)
        painter.drawPath(path)
示例#13
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setFlag(self.ItemIsMovable)
        self.setFlag(self.ItemIsSelectable)

        # Default size and text
        self._size = QSizeF(0, 115)

        self._body_item = QGraphicsPathItem(self)
        self._title_item = TextLineItem("Node", self)
        self._divider = QGraphicsLineItem(self)
        self._description_item = TextRectItem("No description", self)

        # Inputs and outputs
        self.inputs = []
        self.outputs = []
        self.messages = SortedList(key=lambda item: item.severity())

        self._config_widget = None

        # Set proper style and color for the item
        self.styleChange()
        self.paletteChange()
示例#14
0
    def __init__(self, pmConfig: PMConfig,
                 streamConfiguration: StreamConfiguration, widgetWidth: int,
                 widgetHeigth: int):
        super(ChannelPlayerWidget, self).__init__()
        self.pmConfig = pmConfig
        self.streamConfiguration = streamConfiguration
        self.widgetWidth = widgetWidth
        self.widgetHeight = widgetHeigth

        self.setSize(QSizeF(self.widgetWidth, self.widgetHeight))
        self.setAspectRatioMode(Qt.AspectRatioMode.IgnoreAspectRatio)
        self.currentPlayer = StreamPlayer(self.streamConfiguration,
                                          parentWidget=self)
        self.scene().addWidget()
示例#15
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
     if event.button() == Qt.LeftButton and \
             event.modifiers() & Qt.ControlModifier:
         tabIndex = self.tabWidget.currentIndex()
         tabName = self.tabWidget.tabText(tabIndex)
         rowIndex = self.tabWidget.getCurrentTableModel().rowCount(
             QModelIndex())
         label = self.comboBox.currentText()
         box = QRectF(event.buttonDownScenePos(Qt.LeftButton), QSizeF(1, 1))
         color = self.tabWidget.color_map(tabIndex)[label]
         rect = self.addBox(tabIndex, tabName, rowIndex, self.page, label,
                            box, color)
         rect.handleSelected = 4
         self.signalHandler.boxCreated.emit(rect)
     super().mousePressEvent(event)
示例#16
0
文件: _View.py 项目: kurtu5/Labeler
    def paint(self, painter, *args, **kwargs):
        #            print('Paint Called')
        #            painter.drawRect(self.rect)
        painter.drawPixmap(0, 0, self.pixmap)
        #            self.label_font.setColor(QColor("red"))
        width = self.pixmap.size().width()
        # Any width below key is size
        font_step_size = {
            40: 2,
            60: 4,
            80: 6,
            100: 8,
            140: 10,
            160: 12,
            180: 14,
            200: 16
        }
        for w, s in font_step_size.items():
            pixel_size = s
            if width < w:
                break


#            print("width,pixelsize", width,pixel_size)
# 212 = 20  31=6
        self.label_font.setPixelSize(pixel_size)
        painter.setFont(self.label_font)
        #            painter.setPen(QColor("red"))
        painter.drawText(1,
                         self.pixmap.size().height() + pixel_size,
                         self.filename)
        size = QSizeF(self.pixmap.size())
        textsize = QSizeF(0, pixel_size)
        newsize = size + textsize
        self.setMaximumSize(newsize)
        self.setMinimumSize(newsize)
示例#17
0
    def zoom(self, p_abs, p_mapped, angle):
        by = 0
        velocity = 2 * (1 / self.current_scale) + 0.5
        if velocity > 3:
            velocity = 3

        direction = ''
        if angle > 0:
            by = 1 + (angle / 360 * 0.1 * velocity)
            direction = 'in'
        elif angle < 0:
            by = 1 - (-angle / 360 * 0.1 * velocity)
            direction = 'out'
        else:
            by = 1

        scene_rect_width = self.mapFromScene(
            self.sceneRect()).boundingRect().width()
        scene_rect_height = self.mapFromScene(
            self.sceneRect()).boundingRect().height()

        if direction == 'in':
            if self.current_scale * by < 3:
                self.scale(by, by)
                self.current_scale *= by
        elif direction == 'out':
            if scene_rect_width * by >= self.viewport().size().width(
            ) and scene_rect_height * by >= self.viewport().size().height():
                self.scale(by, by)
                self.current_scale *= by

        w = self.viewport().width()
        h = self.viewport().height()
        wf = self.mapToScene(QPoint(w - 1, 0)).x() - self.mapToScene(
            QPoint(0, 0)).x()
        hf = self.mapToScene(QPoint(0, h - 1)).y() - self.mapToScene(
            QPoint(0, 0)).y()
        lf = p_mapped.x() - p_abs.x() * wf / w
        tf = p_mapped.y() - p_abs.y() * hf / h

        self.ensureVisible(lf, tf, wf, hf, 0, 0)

        target_rect = QRectF(QPointF(lf, tf), QSizeF(wf, hf))
        self.total_scale_div = target_rect.width() / self.viewport().width()

        self.ensureVisible(target_rect, 0, 0)
示例#18
0
    def test_print(self, mocker, active_window):
        size = QSizeF(100, 100)
        printer = mocker.create_autospec(QPrinter)
        printer.pageRect.return_value.size.return_value = size
        doc = mocker.create_autospec(QTextDocument, instance=True)
        mocker.patch("src.main_window.QTextDocument").return_value = doc

        active_window.print(printer)

        printer.setPageSize.assert_called_once_with(QPrinter.A4)
        printer.setPageMargins.assert_called_once_with(5, 5, 5, 5,
                                                       QPrinter.Millimeter)
        printer.setResolution.assert_called_once_with(96)

        doc.setHtml.assert_called_once_with("Lorem ipsum")
        doc.setPageSize.assert_called_once_with(size)
        doc.print_.assert_called_once_with(printer)
示例#19
0
    def create_frame_indicator(self):
        size = QSizeF()
        height = 100
        size.setHeight(height)
        size.setWidth(self.label_height)
        self.frame_indicator = FrameIndicator(size, self.frame_width,
                                              self.label_width, 0)
        self._label_scene.addItem(self.frame_indicator)

        self.edit_start_frame_indicator = FrameIndicator(
            size, self.frame_width, self.label_width, 0, blue)
        self._label_scene.addItem(self.edit_start_frame_indicator)
示例#20
0
 def export(self, filename):
     self.printer = QPrinter()
     self.printer.setOutputFormat(QPrinter.PdfFormat)
     self.printer.setOutputFileName(filename)
     self.printer.setPageMargins(QMarginsF(0, 0, 0, 0))
     self.printer.setResolution(96)
     self.printer.setFullPage(True)
     pages = self.document['pages']
     if pages:
         page = pages[0]
         self.printer.setPageSizeMM(QSizeF(page.width / mm, page.height / mm))
     self.painter = QPainter()
     self.painter.begin(self.printer)
     self._isFirstPage = True
     for page in pages:
         self.exportPage(page)
         self._isFirstPage = False
     self.painter.end()
示例#21
0
    def styleChange(self):
        self.prepareGeometryChange()
        style = self.style()

        # Size and Frame
        frame_width = style.pixelMetric(Style.NodeWidth)
        self._size.setWidth(frame_width)
        self._body_item.setPen(style.framePen(self.palette()))

        path = QPainterPath()
        path.addRoundedRect(QRectF(QPointF(), self.size()),
                            style.pixelMetric(Style.NodeFrameCornerRadius),
                            style.pixelMetric(Style.NodeFrameCornerRadius))
        self._body_item.setPath(path)

        # Title item
        title_font = style.font(Style.NodeTitleFont)
        title_metrics = QFontMetricsF(title_font)

        padding = style.pixelMetric(Style.NodeFrameTextPadding)

        self._title_item.setFont(title_font)
        self._title_item.setPos(padding, padding)
        self._title_item.moveBy(0, title_metrics.capHeight())
        self._title_item.setMaximumWidth(frame_width - padding * 2)

        # Divider item
        div_margin = style.pixelMetric(Style.NodeDividerTextMargin)
        div_voffset = padding + title_metrics.capHeight(
        ) + title_metrics.descent() + div_margin

        self._divider.setLine(0, div_voffset, frame_width, div_voffset)
        self._divider.setPen(style.framePen(self.palette()))

        # Description item
        self._description_item.setFont(style.font(Style.NodeDescriptionFont))
        self._description_item.setPos(padding, div_voffset + div_margin)
        self._description_item.setFrame(
            QRectF(
                QPointF(0, 0),
                QSizeF(
                    px(frame_width) - padding * 2,
                    (px(self.size().height()) - padding) -
                    (div_voffset + padding))))
示例#22
0
    def _draw_text_helper(painter, point, text, flags):
        # We want an arbitrarily large size, so that we don't have to worry about text being cut off
        size = 1000000.0
        new_x = point.x()
        new_y = point.y() - size

        if flags & Qt.AlignHCenter:
            new_x -= size / 2.0
        elif flags & Qt.AlignRight:
            new_x += size / 2.0
        if flags & Qt.AlignVCenter:
            new_y += size / 2.0
        elif flags & Qt.AlignTop:
            new_y += size
        else:
            flags |= Qt.AlignBottom

        rect = QRectF(QPointF(new_x, new_y), QSizeF(size, size))
        painter.drawText(rect, flags, text)
示例#23
0
class Pin(QGraphicsEllipseItem):
    _SIZE = QSizeF(10, 10)

    def __init__(self, element, path):
        super().__init__(element)
        self.path = path

        self.setPen(QPen(Qt.black, 2))
        self.setBrush(Qt.white)
        self.setRect(QRectF(QPoint(), self._SIZE))

        self.setFlag(QGraphicsItem.ItemIsSelectable)

        def _update_pin():
            lit = element.simulator.get_pin_value(path) > 0
            self.setBrush(Qt.green if lit else Qt.white)
            self.update()

        element.simulator.observe(path, _update_pin)
示例#24
0
 def getSizeFromCmnd(self, sizeinfo):
     '''
     Returns a QSizeF based on the information in the dictionary
     sizeinfo.  Recognized keys are "width" and "height", and
     correspond to those float values in the QSizeF.  Values not
     given in sizeinfo are assigned as zero in the returned QSizeF.
     '''
     myrect = QSizeF(0.0, 0.0)
     try:
         myrect.setWidth(float(sizeinfo["width"]))
     except KeyError:
         pass
     try:
         myrect.setHeight(float(sizeinfo["height"]))
     except KeyError:
         pass
     return myrect
示例#25
0
    def print_to_pdf(
        self,
        path,
        paper_size=(8.5, 11.0),
        paper_margins=(0, 0, 0, 0),
        paper_units=None,
        zoom_factor=1.0,
    ):
        """Saves page as a pdf file.

        See qt4 QPrinter documentation for more detailed explanations
        of options.

        :param path: The destination path.
        :param paper_size: A 2-tuple indicating size of page to print to.
        :param paper_margins: A 4-tuple indicating size of each margin.
        :param paper_units: Units for pager_size, pager_margins.
        :param zoom_factor: Scale the output content.
        """
        assert len(paper_size) == 2
        assert len(paper_margins) == 4

        if paper_units is None:
            paper_units = QPrinter.Inch

        printer = QPrinter(mode=QPrinter.ScreenResolution)
        printer.setOutputFormat(QPrinter.PdfFormat)
        printer.setPaperSize(QSizeF(*paper_size), paper_units)
        printer.setPageMargins(*(paper_margins + (paper_units,)))
        if paper_margins != (0, 0, 0, 0):
            printer.setFullPage(True)
        printer.setOutputFileName(path)
        if self.webview is None:
            self.webview = QWebView()
            self.webview.setPage(self.page)
        self.webview.setZoomFactor(zoom_factor)
        self.webview.print_(printer)
示例#26
0
 def open(self):
     self.videoPath = QFileDialog.getOpenFileName(self, "请选择视频文件", None, "MP4格式 (*.mp4);;所有文件(*.*)")[0]
     if self.videoPath:
         cmd = ['utils/ffmpeg.exe', '-i', self.videoPath]
         p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
         p.wait()
         for l in p.stdout.readlines():
             l = l.decode('utf8')
             if 'Duration' in l:
                 self.duration = calSubTime(l.split(' ')[3][:-1])
             if 'Stream' in l and 'DAR' in l:
                 self.videoWidth, self.videoHeight = map(int, l.split(' [')[0].split(' ')[-1].split('x'))
                 args = l.split(',')
                 for cnt, arg in enumerate(args):
                     if 'kb' in arg:
                         self.bitrate = int(arg.split('kb')[0])
                         self.fps = int(args[cnt + 1].split('fps')[0])
                         break
                 break
         self.initProcess.show()
         self.subtitle.cellChanged.disconnect(self.subEdit)
         self.subtitle.setRowCount(self.duration // self.globalInterval + 1)
         self.subtitle.setVerticalHeaderLabels([cnt2Time2(i, self.globalInterval) for i in range(self.subtitle.rowCount())])
         self.subtitle.cellChanged.connect(self.subEdit)
         self.initProcess.hide()
         url = QUrl.fromLocalFile(self.videoPath)
         self.stack.setCurrentIndex(1)
         self.playerWidget.setSize(QSizeF(1280, 720))
         self.player.setMedia(url)
         self.playStatus = True
         self.videoSlider.setEnabled(True)
         self.mediaPlay()
         self.timer.start()
         self.timer.timeout.connect(self.timeOut)
         self.subTimer.start()
         self.subTimer.timeout.connect(self.subTimeOut)
示例#27
0
    def paint(self, painter, option, widget):
        pen = QPen()
        pen.setColor(QColor(150, 150, 150))
        pen.setWidth(1)
        painter.setPen(pen)

        if not self._fromNode() or not self._toNode():
            return

        line = QLineF(self.fromPoint, self.toPoint)
        if line.length() == 0.0:
            return

        # self.drawArc(painter, line)
        topLeftPoint = self.calculatePerpendicularPoint(
            self.fromPoint, 50, line)
        arcRect = QRectF(topLeftPoint, QSizeF(line.length(), 100))
        if self._fromNode is self._toNode:
            spanAngle = -360
        else:
            spanAngle = -180
        # painter.drawArc(arcRect, 0, spanAngle)

        colliding = self.collidingItems()
        if len(colliding) > 0:
            line.setP1(line.p1() + QPointF(10, 10))
            line.setP2(line.p2() + QPointF(10, 10))
            line.translate(10, 10)
        painter.drawLine(line)

        midpoint = QPointF(line.center().x(), line.center().y())
        labelCenterPoint = self.calculatePerpendicularPoint(midpoint, 75, line)
        self.labelBox.setPos(labelCenterPoint)

        angle = math.acos(line.dx() / line.length())
        self.drawArrowHead(painter, angle, line.p2())
示例#28
0
    def getObjectInteraction(self, persons, objects, interaction, d):

        # print("getObjectInteration")
        plt.close('all')

        polylines_object = []
        polylines_interacting = []

        for o in objects:
            obj = Object(o.x / 1000., o.z / 1000., o.angle, o.space)
            # print("OBJETO")
            ##para dibujarlo
            if d:
                plt.figure('ObjectSpace')
                rect = plt.Rectangle((obj.x - 0.25, obj.y - 0.25),
                                     0.5,
                                     0.5,
                                     fill=False)

                plt.gca().add_patch(rect)
                x_aux = obj.x + 0.25 * cos(pi / 2 - obj.th)
                y_aux = obj.y + 0.25 * sin(pi / 2 - obj.th)
                heading = plt.Line2D((obj.x, x_aux), (obj.y, y_aux),
                                     lw=1,
                                     color='k')
                plt.gca().add_line(heading)

            w = 1.0
            # print (obj.x,obj.y)
            ##para calcular el rectangulo
            s = QRectF(QPointF(0, 0), QSizeF(w, obj.sp))

            # if (d):
            #     plt.plot (s.bottomLeft().x(),s.bottomLeft().y(),"go")
            #     plt.plot(s.bottomRight().x(), s.bottomRight().y(), "ro")
            #     plt.plot(s.topRight().x(), s.topRight().y(), "yo")
            #     plt.plot(s.topLeft().x(), s.topLeft().y(), "bo")

            space = QPolygonF()
            space.append(s.topLeft())
            space.append(s.topRight())
            space.append(
                QPointF(s.bottomRight().x() + obj.sp / 4,
                        s.bottomRight().y()))
            space.append(
                QPointF(s.bottomLeft().x() - obj.sp / 4,
                        s.bottomLeft().y()))

            t = QTransform()
            t.translate(-w / 2, 0)
            space = t.map(space)
            t = QTransform()
            t.rotateRadians(-obj.th)
            space = t.map(space)

            t = QTransform()
            t.translate(obj.x, obj.y)
            space = t.map(space)

            # points = []
            # for x in xrange(space.count()-1):
            #     point = space.value(x)
            #     print ("valor", point)
            #     points.append([point.x(),point.y()])
            #     plt.plot(point.x(),point.y(),"go")

            polyline = []

            for x in range(space.count()):
                point = space.value(x)
                if (d):
                    plt.plot(point.x(), point.y(), "go")

                p = SNGPoint2D()
                p.x = point.x()
                p.z = point.y()
                polyline.append([p.x, p.z])

            polylines_object.append(polyline)

            for p in persons:
                pn = Person(p.x, p.z, p.angle)
                # print("PERSONA", persons.index(p)+1)
                if d:
                    body = plt.Circle((pn.x, pn.y), radius=0.3, fill=False)
                    plt.gca().add_patch(body)

                    x_aux = pn.x + 0.30 * cos(pi / 2 - pn.th)
                    y_aux = pn.y + 0.30 * sin(pi / 2 - pn.th)
                    heading = plt.Line2D((pn.x, x_aux), (pn.y, y_aux),
                                         lw=1,
                                         color='k')
                    plt.gca().add_line(heading)
                    plt.axis('equal')

                ##CHECKING THE ORIENTATION
                print("obj.angle", obj.th, "person.angle", pn.th)
                a = abs(obj.th - abs(pn.th - math.pi))
                if a < math.radians(45):
                    checkangle = True
                else:
                    checkangle = False

                ##CHECKING IF THE PERSON IS INSIDE THE POLYGON
                if space.containsPoint(QPointF(pn.x, pn.y),
                                       Qt.OddEvenFill):  # and checkangle:
                    print("DENTROOOOO Y MIRANDO")
                    if not polyline in polylines_interacting:
                        polylines_interacting.append(polyline)

        if d:
            for ps in polylines_interacting:
                #  plt.figure()
                for p in ps:
                    plt.plot(p.x, p.z, "ro")
                    plt.axis('equal')
                    plt.xlabel('X')
                    plt.ylabel('Y')
            plt.show()
        plt.show()

        if (interaction):
            return polylines_interacting
        else:
            return polylines_object
示例#29
0
 def imageSize(self):
     """ Get image size (width as the largest dimension). """
     if not self._initialIntrinsics:
         return QSizeF(0, 0)
     return QSizeF(self._initialIntrinsics.width.value,
                   self._initialIntrinsics.height.value)
示例#30
0
 def orientedImageSize(self):
     """ Get image size taking into account its orientation. """
     if self.orientation in (6, 8):
         return QSizeF(self.imageSize.height(), self.imageSize.width())
     else:
         return self.imageSize
示例#31
0
 def testQSizeFToTuple(self):
     s = QSizeF(1, 2)
     self.assertEqual((1, 2), s.toTuple())