当前位置: 首页>>代码示例>>Python>>正文


Python QTransform.map方法代码示例

本文整理汇总了Python中PyQt4.QtGui.QTransform.map方法的典型用法代码示例。如果您正苦于以下问题:Python QTransform.map方法的具体用法?Python QTransform.map怎么用?Python QTransform.map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtGui.QTransform的用法示例。


在下文中一共展示了QTransform.map方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mappedPolygon

# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import map [as 别名]
 def mappedPolygon( self, polygon, path = None, percent = 0.5 ):
     """
     Maps the inputed polygon to the inputed path \
     used when drawing items along the path.  If no \
     specific path is supplied, then this object's own \
     path will be used.  It will rotate and move the \
     polygon according to the inputed percentage.
     
     :param      polygon     <QPolygonF>
     :param      path        <QPainterPath>
     :param      percent     <float>
     
     :return     <QPolygonF> mapped_poly
     """
     translatePerc   = percent
     anglePerc       = percent
     
     # we don't want to allow the angle percentage greater than 0.85
     # or less than 0.05 or we won't get a good rotation angle
     if ( 0.95 <= anglePerc ):
         anglePerc = 0.98
     elif ( anglePerc <= 0.05 ):
         anglePerc = 0.05
     
     if ( not path ):
         path = self.path()
     if ( not (path and path.length()) ):
         return QPolygonF()
     
     # transform the polygon to the path
     point   = path.pointAtPercent(translatePerc)
     angle   = path.angleAtPercent(anglePerc)
     
     # rotate about the 0 axis
     transform   = QTransform().rotate(-angle)
     polygon     = transform.map(polygon)
     
     # move to the translation point
     transform   = QTransform().translate(point.x(), point.y())
     
     # create the rotated polygon
     mapped_poly = transform.map(polygon)
     self._polygons.append(mapped_poly)
     
     return mapped_poly
开发者ID:satishgoda,项目名称:DPS_PIPELINE,代码行数:47,代码来源:xnodeconnection.py

示例2: _updateLayout

# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import map [as 别名]
    def _updateLayout(self):
        rect = self.geometry()
        n = len(self._items)
        if not n:
            return

        regions = venn_diagram(n, shape=self.shapeType)

        # The y axis in Qt points downward
        transform = QTransform().scale(1, -1)
        regions = list(map(transform.map, regions))

        union_brect = reduce(QRectF.united,
                             (path.boundingRect() for path in regions))

        scalex = rect.width() / union_brect.width()
        scaley = rect.height() / union_brect.height()
        scale = min(scalex, scaley)

        transform = QTransform().scale(scale, scale)

        regions = [transform.map(path) for path in regions]

        center = rect.width() / 2, rect.height() / 2
        for item, path in zip(self.items(), regions):
            item.setPath(path)
            item.setPos(*center)

        intersections = venn_intersections(regions)
        assert len(intersections) == 2 ** n
        assert len(self.vennareas()) == 2 ** n

        anchors = [(0, 0)] + subset_anchors(self._items)

        anchor_transform = QTransform().scale(rect.width(), -rect.height())
        for i, area in enumerate(self.vennareas()):
            area.setPath(intersections[setkey(i, n)])
            area.setPos(*center)
            x, y = anchors[i]
            anchor = anchor_transform.map(QPointF(x, y))
            area.setTextAnchor(anchor)
            area.setZValue(30)

        self._updateTextAnchors()
开发者ID:PythonCharmers,项目名称:orange3,代码行数:46,代码来源:owvenndiagram.py

示例3: ellipse_path

# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import map [as 别名]
def ellipse_path(center, a, b, rotation=0):
    if not isinstance(center, QPointF):
        center = QPointF(*center)

    brect = QRectF(-a, -b, 2 * a, 2 * b)

    path = QPainterPath()
    path.addEllipse(brect)

    if rotation != 0:
        transform = QTransform().rotate(rotation)
        path = transform.map(path)

    path.translate(center)
    return path
开发者ID:PythonCharmers,项目名称:orange3,代码行数:17,代码来源:owvenndiagram.py

示例4: _define_symbols

# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import map [as 别名]
def _define_symbols():
    """
    Add symbol ? to ScatterPlotItemSymbols,
    reflect the triangle to point upwards
    """
    symbols = pyqtgraph.graphicsItems.ScatterPlotItem.Symbols
    path = QPainterPath()
    path.addEllipse(QRectF(-0.35, -0.35, 0.7, 0.7))
    path.moveTo(-0.5, 0.5)
    path.lineTo(0.5, -0.5)
    path.moveTo(-0.5, -0.5)
    path.lineTo(0.5, 0.5)
    symbols["?"] = path

    tr = QTransform()
    tr.rotate(180)
    symbols['t'] = tr.map(symbols['t'])
开发者ID:JingqinGao,项目名称:orange3,代码行数:19,代码来源:owscatterplotgraph.py

示例5: overlay_for

# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import map [as 别名]
    def overlay_for(pt1, pt2, frequency):
        # Construct the line-geometry, we'll use this to construct the ellipsoid
        line = QLineF(pt1, pt2)

        # Determine the radius for the ellipsoid
        radius = fresnel_radius(line.length(), frequency)

        # Draw the ellipsoid
        zone = QPainterPath()
        zone.addEllipse(QPointF(0., 0.), line.length() / 2, radius)

        # Rotate the ellipsoid - same angle as the line
        transform = QTransform()
        transform.rotate(-line.angle())
        zone = transform.map(zone)

        # Center the zone over the line
        lc = QRectF(pt1, pt2).center()
        zc = zone.boundingRect().center()
        zone.translate(lc.x() - zc.x(), lc.y() - zc.y())

        return line, zone
开发者ID:JamesFysh,项目名称:eleview,代码行数:24,代码来源:ElevationScene.py

示例6: run_loader

# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import map [as 别名]
    def run_loader(self):
        filename = self.result
        try:
            self.retryObject = None
# First, prepare the data by getting the images and computing how big they
# should be
            f = open(filename)
            first_line = f.readline()
            f.close()
            if first_line.startswith("TRKR_VERSION"):
                result = Result(None)
                result.load(self.result, **self._loading_arguments)
                result_type = "Growth"
            else:
                result = TrackingData()
                result.load(self.result, **self._loading_arguments)
                result_type = "Data"
            self.result = result
            self.result_type = result_type
            if result_type == "Data":
                data = result
                images = data.images_name
                if data.cells:
                    self.has_cells = True
                    self.has_walls = True
                else:
                    self.has_cells = False
                    self.has_walls = False
                self.has_points = bool(data.cell_points)
            else:
                data = result.data
                images = result.images
                self.has_cells = False
                self.has_walls = False
                self.has_points = False
            self.images = images
            cache = image_cache.cache
            self.update_nb_images(len(result))
            bbox = QRectF()
            ms = data.minScale()
            for i in range(len(result)):
                img_name = images[i]
                img_data = data[img_name]
                img = cache.image(data.image_path(img_name))
                matrix = QTransform()
                matrix = img_data.matrix()
                sc = QTransform()
                sc.scale(1.0/ms, 1.0/ms)
                matrix *= sc
                r = QRectF(img.rect())
                rbox = matrix.map(QPolygonF(r)).boundingRect()
                bbox |= rbox
                log_debug("Image '%s':\n\tSize = %gx%g\n\tTransformed = %gx%g %+g %+g\n\tGlobal bbox = %gx%g %+g %+g\n" %
                             (img_name, r.width(), r.height(), rbox.width(), rbox.height(), rbox.left(), rbox.top(),
                              bbox.width(), bbox.height(), bbox.left(), bbox.top()))
                log_debug("Matrix:\n%g\t%g\t%g\n%g\t%g\t%g\n" %
                            (matrix.m11(), matrix.m12(), matrix.dx(), matrix.m21(), matrix.m22(), matrix.dy()))
                if result_type == "Growth":
                    if result.cells[i]:
                        self.has_cells = True
                    if result.walls[i]:
                        self.has_walls = True
                    self.has_points = bool(result.data.cell_points)
                self.nextImage()
            translate = bbox.topLeft()
            translate *= -1
            self.translate = translate
            size = bbox.size().toSize()
            self.img_size = size
            self._crop = QRect(QPoint(0,0), size)
            self.finished()
            self._loading_arguments = {} # All done, we don't need that anymore
        except RetryTrackingDataException as ex:
            ex.filename = filename
            self.retryObject = ex
            self.finished()
            return
        except Exception as ex:
            _, _, exceptionTraceback = sys.exc_info()
            self.abort(ex, traceback=exceptionTraceback)
            raise
开发者ID:PierreBdR,项目名称:point_tracker,代码行数:83,代码来源:plottingdlg.py

示例7: paintEvent

# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import map [as 别名]
    def paintEvent(self, event):
        painter = QPainter(self)
        width = self.width()
        height = self.height()

        if DEBUG:
            painter.fillRect(0, 0, width, height, Qt.blue)
        else:
            painter.fillRect(event.rect(), self.plot.canvas_color)

        y_min_scale = self.plot.y_scale.value_min
        y_max_scale = self.plot.y_scale.value_max

        factor_x = float(width) / self.plot.history_length_x
        factor_y = float(height - 1) / max(
            y_max_scale - y_min_scale, EPSILON
        )  # -1 to accommodate the 1px width of the curve

        if self.plot.x_min != None and self.plot.x_max != None:
            x_min = self.plot.x_min
            x_max = self.plot.x_max

            if self.plot.curve_start == "left":
                curve_x_offset = 0
            else:
                curve_x_offset = round((self.plot.history_length_x - (x_max - x_min)) * factor_x)

            transform = QTransform()

            transform.translate(
                curve_x_offset, height - 1 + self.plot.curve_y_offset
            )  # -1 to accommodate the 1px width of the curve
            transform.scale(factor_x, -factor_y)
            transform.translate(-x_min, -y_min_scale)

            if self.plot.curve_motion_granularity > 1:
                self.plot.partial_update_width = math.ceil(transform.map(QLineF(0, 0, 1.5, 0)).length())
                inverted_event_rect = transform.inverted()[0].mapRect(QRectF(event.rect()))

            painter.save()
            painter.setTransform(transform)

            for c in range(len(self.plot.curves_x)):
                if not self.plot.curves_visible[c]:
                    continue

                curve_x = self.plot.curves_x[c]
                curve_y = self.plot.curves_y[c]
                path = QPainterPath()
                lineTo = path.lineTo

                if self.plot.curve_motion_granularity > 1:
                    start = max(min(bisect.bisect_left(curve_x, inverted_event_rect.left()), len(curve_x) - 1) - 1, 0)
                else:
                    start = 0

                path.moveTo(curve_x[start], curve_y[start])

                for i in xrange(start + 1, len(curve_x)):
                    lineTo(curve_x[i], curve_y[i])

                painter.setPen(self.plot.configs[c][1])
                painter.drawPath(path)

            painter.restore()
开发者ID:Tinkerforge,项目名称:brickv,代码行数:67,代码来源:plot_widget.py

示例8: TrackingScene

# 需要导入模块: from PyQt4.QtGui import QTransform [as 别名]
# 或者: from PyQt4.QtGui.QTransform import map [as 别名]

#.........这里部分代码省略.........
        self.min_scale = 1.0
        self.scale = (1.0, 1.0)
        data_manager.pointsAdded.connect(self.addPoints)
        data_manager.pointsMoved.connect(self.movePoints)
        data_manager.pointsDeleted.connect(self.delPoints)
        data_manager.dataChanged.connect(self.dataChanged)
        data_manager.imageMoved.connect(self.moveImage)
        data_manager.cellsAdded.connect(self.addCells)
        data_manager.cellsRemoved.connect(self.removeCells)
        data_manager.cellsChanged.connect(self.changeCells)

    def moveImage(self, image_name, scale, pos, angle):
        if image_name == self.image_name:
            self.setImageMove(scale, pos, angle)
            self.updateElements()
            self.invalidate()
            self.update()

    def updateElements(self):
        for pt in self.items():
            pt.scale = self.img_scale
            pt.setGeometry()

    def setImageMove(self, scale, pos, angle):
        log_debug("New scale = %s" % (scale,))
        self.scale = scale
        self.min_scale = self.data_manager.minScale()
        self.img_scale = (scale[0]/self.min_scale, scale[1]/self.min_scale)
        back_matrix = QTransform()
        back_matrix.scale(*self.img_scale)
        back_matrix.translate(pos.x(), pos.y())
        back_matrix.rotate(angle)
        self.back_matrix = back_matrix
        rect = back_matrix.mapRect(QRectF(self.background_image.rect()))
        inv, ok = back_matrix.inverted()
        if not ok:
            raise ValueError("The movement is not invertible !?!")
        self.invert_back_matrix = inv
        self.real_scene_rect = rect

    @property
    def real_scene_rect(self):
        '''Real size of the scene'''
        return self._real_scene_rect

    @real_scene_rect.setter
    def real_scene_rect(self, value):
        if self._real_scene_rect != value:
            self._real_scene_rect = value
            self.realSceneSizeChanged.emit()

    def changeImage(self, image_path):
        log_debug("Changed image to {0}".format(image_path))
        if image_path is None:
            image_path = self.image_path
        if image_path is None:
            return
        image_name = image_path.basename()
        self.image_name = image_name
        self.current_data = self.data_manager[image_name]
        current_data = self.current_data
        self.clearItems()
        self.image_path = image_path
        img = image_cache.cache.image(image_path)
        self.background_image = img
        pos = current_data.shift[0]
开发者ID:PierreBdR,项目名称:point_tracker,代码行数:70,代码来源:tracking_scene.py


注:本文中的PyQt4.QtGui.QTransform.map方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。