本文整理汇总了Python中PyQt5.QtGui.QTransform.fromTranslate方法的典型用法代码示例。如果您正苦于以下问题:Python QTransform.fromTranslate方法的具体用法?Python QTransform.fromTranslate怎么用?Python QTransform.fromTranslate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QTransform
的用法示例。
在下文中一共展示了QTransform.fromTranslate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ParseTransformAttrib
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import fromTranslate [as 别名]
def ParseTransformAttrib(s):
# where s is an SVG transform attribute such as "translate(-2,1) matrix(0 1 2 3 4 5)"
# return a list of QTransforms
xforms = []
s = s.lower()
while s:
s = re.sub(r'^\s+,?\s+', '', s) # remove leading WS,WS
m = re.match(r'\s*(\w+)\s*\(((\s*[0-9e.+-]+\s*,?)+)\)', s) # match identifier(numbers) clause
if m:
values = SplitFloatValues(m.group(2))
if m.group(1) == 'translate':
if len(values) == 1: values.append(0)
xforms.append( QTransform.fromTranslate(*values) )
elif m.group(1) == 'scale':
if len(values) == 1: values.append(values[0])
xforms.append( QTransform.fromScale(*values) )
elif m.group(1) == 'rotate':
xforms.append( QTransform().rotate(values[0]) ) # TODO: handle cx,cy values
elif m.group(1) == 'matrix':
logger.trace('matrix({}): m.group(2) = {}', values, m.group(2))
xforms.append( QTransform( values[0], values[1], 0
, values[2], values[3], 0
, values[4], values[5], 1) )
# TODO: handle skewX and skewY
else: logger.warning('unrecognized transform: {}', m.group())
s = s[m.end()+1:]
else:
if s: logger.warning('unparsed transform: {}', s)
break
return xforms
示例2: _fetch_tile_layer
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import fromTranslate [as 别名]
def _fetch_tile_layer(self, timestamp, ims, transform, tile_nr, stack_id, ims_req, cache):
"""
Fetch a single tile from a layer (ImageSource).
Parameters
----------
timestamp
The timestamp at which ims_req was created
ims
The layer (image source) we're fetching from
transform
The transform to apply to the fetched data, before storing it in the cache
tile_nr
The ID of the fetched tile
stack_id
The stack ID of the tile we're fetching (e.g. which T-slice and Z-slice this tile belongs to)
ims_req
A request object (e.g. GrayscaleImageRequest) with a wait() method that produces an item of
the appropriate type for the layer (i.e. either a QImage or a QGraphicsItem)
cache
The value of self._cache at the time the ims_req was created.
(The cache can be replaced occasionally. See TileProvider._onSizeChanged().)
"""
try:
try:
with cache:
layerTimestamp = cache.layerTimestamp(stack_id, ims, tile_nr)
except KeyError:
# May not be a timestamp yet (especially when prefetching)
layerTimestamp = 0
tile_rect = QRectF(self.tiling.imageRects[tile_nr])
if timestamp > layerTimestamp:
img = ims_req.wait()
if isinstance(img, QImage):
img = img.transformed(transform)
elif isinstance(img, QGraphicsItem):
# FIXME: It *seems* like applying the same transform to QImages and QGraphicsItems
# makes sense here, but for some strange reason it isn't right.
# For QGraphicsItems, it seems obvious that this is the correct transform.
# I do not understand the formula that produces 'transform', which is used for QImage tiles.
img.setTransform(QTransform.fromTranslate(tile_rect.left(), tile_rect.top()), combine=True)
img.setTransform(self.tiling.data2scene, combine=True)
else:
assert False, "Unexpected image type: {}".format(type(img))
with cache:
try:
cache.updateTileIfNecessary(stack_id, ims, tile_nr, timestamp, img)
except KeyError:
pass
if stack_id == self._current_stack_id and cache is self._cache:
self.sceneRectChanged.emit(tile_rect)
except BaseException:
sys.excepthook(*sys.exc_info())
示例3: timerEvent
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import fromTranslate [as 别名]
def timerEvent(self, event):
axelDistance = 54.0
wheelsAngleRads = (self.wheelsAngle * math.pi) / 180
turnDistance = math.cos(wheelsAngleRads) * axelDistance * 2
turnRateRads = wheelsAngleRads / turnDistance
turnRate = (turnRateRads * 180) / math.pi
rotation = self.speed * turnRate
self.setTransform(QTransform().rotate(rotation), True)
self.setTransform(QTransform.fromTranslate(0, -self.speed), True)
self.update()
示例4: objectTransform
# 需要导入模块: from PyQt5.QtGui import QTransform [as 别名]
# 或者: from PyQt5.QtGui.QTransform import fromTranslate [as 别名]
def objectTransform(object, renderer):
transform = QTransform()
if (object.rotation() != 0):
pos = renderer.pixelToScreenCoords_(object.position())
transform = rotateAt(pos, object.rotation())
offset = object.objectGroup().offset()
if not offset.isNull():
transform *= QTransform.fromTranslate(offset.x(), offset.y())
return transform