本文整理汇总了Python中nodebox.graphics.Transform.append方法的典型用法代码示例。如果您正苦于以下问题:Python Transform.append方法的具体用法?Python Transform.append怎么用?Python Transform.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nodebox.graphics.Transform
的用法示例。
在下文中一共展示了Transform.append方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_svg_attributes
# 需要导入模块: from nodebox.graphics import Transform [as 别名]
# 或者: from nodebox.graphics.Transform import append [as 别名]
def get_svg_attributes(node, parent_attributes={}):
if parent_attributes:
attributes = dict(parent_attributes)
else:
attributes = dict()
transform = parse_transform(node)
if transform and not transform.equals(Transform()):
if attributes.has_key("transform"):
t = Transform(attributes["transform"])
t.append(transform)
attributes["transform"] = t
else:
attributes["transform"] = transform
color_attrs = parse_color_info(node)
attributes.update(color_attrs)
return attributes
示例2: parse_transform
# 需要导入模块: from nodebox.graphics import Transform [as 别名]
# 或者: from nodebox.graphics.Transform import append [as 别名]
def parse_transform(e):
""" Attempts to extract a transform="matrix()|translate()|scale()|rotate()" attribute.
"""
from nodebox.graphics import Transform
def translate(s):
a = to_number_array(s)
tx = a[0]
ty = 0
if len(a) > 1:
ty = a[1]
return Transform.translated(tx, ty)
def scale(s):
a = to_number_array(s)
sx = a[0]
sy = sx
if len(a) > 1:
sy = a[1]
return Transform.scaled(sx, sy)
def rotate(s):
a = to_number_array(s)
r = a[0]
tx = 0
ty = 0
if len(a) > 1:
tx = a[1]
if len(a) > 2:
ty = a[2]
t = Transform()
t.translate(tx, ty)
t.rotate(r)
t.translate(-tx, -ty)
return t
def matrix(s):
m = to_number_array(s)
return Transform(*m)
types = {
"translate": translate,
"scale": scale,
"rotate": rotate,
"matrix": matrix
}
transforms = []
t = get_attribute(e, "transform", default="")
a = get_attribute(e, "id", None)
if t:
v = compress_spaces(t).lstrip().rstrip()
v = re.split("\s(?=[a-z])", v)
for el in v:
type = el.split("(")[0].lstrip().rstrip()
s = el.split("(")[1].replace(")", "")
transform = types[type](s)
transforms.append(transform)
transform = Transform()
if transforms:
for t in transforms:
transform.append(t)
return transform