本文整理汇总了Python中pymei.MeiElement.setAttributes方法的典型用法代码示例。如果您正苦于以下问题:Python MeiElement.setAttributes方法的具体用法?Python MeiElement.setAttributes怎么用?Python MeiElement.setAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymei.MeiElement
的用法示例。
在下文中一共展示了MeiElement.setAttributes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: neumify
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import setAttributes [as 别名]
def neumify(self, ids, type_id, liquescence, head_shapes, ulx, uly, lrx, lry):
'''
Neumify a group of neumes (with provided ids)
and give it the given neume name. Also update
bounding box information.
'''
# get neume name and variant from type id
type_split = type_id.split(".")
if type_split[-1].isdigit():
type_split.pop()
if len(type_split) == 1:
attrs = [MeiAttribute("name", type_split[0])]
else:
variant = " ".join(type_split[1:])
attrs = [MeiAttribute("name", type_split[0]), MeiAttribute("variant", variant)]
'''
# need to determine how to encode these different types of liquescence in the MEI document
if liquescence:
if liquescence == "alt":
attrs.append(MeiAttribute("variant", "liquescence"))
elif liquescence == "aug":
attrs.append(MeiAttribute("variant", "liquescence_aug"))
elif liquescence == "dim":
attrs.append(MeiAttribute("variant", "liquescence_dim"))
'''
new_neume = MeiElement("neume")
new_neume.setAttributes(attrs)
ncs = []
cur_nc = None
iNote = 0
for id in ids:
ref_neume = self.mei.getElementById(str(id))
if ref_neume:
# get underlying notes
notes = ref_neume.getDescendantsByName("note")
for n in notes:
head = str(head_shapes[iNote])
# check if a new nc must be opened
if head == 'punctum' and cur_nc != 'punctum':
ncs.append(MeiElement("nc"))
cur_nc = head
elif head == 'punctum_inclinatum' and cur_nc != 'punctum_inclinatum':
new_nc = MeiElement("nc")
new_nc.addAttribute("inclinatum", "true")
ncs.append(new_nc)
cur_nc = head
elif head == 'punctum_inclinatum_parvum' and cur_nc != 'punctum_inclinatum_parvum':
new_nc = MeiElement("nc")
new_nc.addAttribute("inclinatum", "true")
new_nc.addAttribute("deminutus", "true")
ncs.append(new_nc)
cur_nc = head
elif head == 'quilisma' and cur_nc != 'quilisma':
new_nc = MeiElement("nc")
new_nc.addAttribute("quilisma", "true")
ncs.append(new_nc)
cur_nc = head
elif cur_nc is None:
ncs.append(MeiElement("nc"))
cur_nc = 'punctum'
ncs[-1].addChild(n)
iNote += 1
new_neume.setChildren(ncs)
# insert the new neume
before = self.mei.getElementById(ids[0])
parent = before.getParent()
if before and parent:
parent.addChildBefore(before, new_neume)
# remove the old neumes from the mei document
for id in ids:
neume = self.mei.getElementById(str(id))
if neume:
# remove facs data
facs = neume.getAttribute("facs")
if facs:
facsid = facs.value
# Remove the zone if it exists
zone = self.mei.getElementById(str(facsid))
if zone and zone.name == "zone":
zone.parent.removeChild(zone)
# now remove the neume
neume.parent.removeChild(neume)
# update bounding box data
self.update_or_add_zone(new_neume, ulx, uly, lrx, lry)
result = {"id": new_neume.getId()}
return result