本文整理汇总了Python中translate.storage.placeables.StringElem.prune方法的典型用法代码示例。如果您正苦于以下问题:Python StringElem.prune方法的具体用法?Python StringElem.prune怎么用?Python StringElem.prune使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类translate.storage.placeables.StringElem
的用法示例。
在下文中一共展示了StringElem.prune方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: xml_to_strelem
# 需要导入模块: from translate.storage.placeables import StringElem [as 别名]
# 或者: from translate.storage.placeables.StringElem import prune [as 别名]
def xml_to_strelem(dom_node, xml_space="preserve"):
if dom_node is None:
return StringElem()
if isinstance(dom_node, basestring):
dom_node = etree.fromstring(dom_node)
normalize_xml_space(dom_node, xml_space, remove_start=True)
result = StringElem()
if dom_node.text:
result.sub.append(StringElem(unicode(dom_node.text)))
for child_dom_node in dom_node:
result.sub.append(make_placeable(child_dom_node, xml_space))
if child_dom_node.tail:
result.sub.append(StringElem(unicode(child_dom_node.tail)))
result.prune()
return result
示例2: test_prune
# 需要导入模块: from translate.storage.placeables import StringElem [as 别名]
# 或者: from translate.storage.placeables.StringElem import prune [as 别名]
def test_prune(self):
elem = StringElem(u'foo')
child = StringElem(u'bar')
elem.sub.append(child)
elem.prune()
assert elem == StringElem(u'foobar')
示例3: TextBox
# 需要导入模块: from translate.storage.placeables import StringElem [as 别名]
# 或者: from translate.storage.placeables.StringElem import prune [as 别名]
#.........这里部分代码省略.........
while gtk.events_pending():
gtk.main_iteration()
cursor_pos = self.buffer.props.cursor_position
widget = elem.gui_info.get_insert_widget()
if widget:
def show_widget():
cursor_iter = self.buffer.get_iter_at_offset(cursor_pos)
anchor = self.buffer.create_child_anchor(cursor_iter)
# It is necessary to recreate cursor_iter becuase, for some inexplicable reason,
# the Gtk guys thought it acceptable to have create_child_anchor() above CHANGE
# THE PARAMETER ITER'S VALUE! But only in some cases, while the moon is 73.8% full
# and it's after 16:33. Documenting this is obviously also too much to ask.
# Nevermind the fact that there isn't simply a gtk.TextBuffer.remove_anchor() method
# or something similar. Why would you want to remove anything from a TextView that
# you have added anyway!?
# It's crap like this that'll make me ditch Gtk.
cursor_iter = self.buffer.get_iter_at_offset(cursor_pos)
self.add_child_at_anchor(widget, anchor)
widget.show_all()
if callable(getattr(widget, 'inserted', None)):
widget.inserted(cursor_iter, anchor)
# show_widget() must be deferred until the refresh() following this
# signal's completion. Otherwise the changes made by show_widget()
# and those made by the refresh() will wage war on each other and
# leave Virtaal as one of the casualties thereof.
self.refresh_actions.append(show_widget)
else:
translation = elem.translate()
if isinstance(translation, StringElem):
self.add_default_gui_info(translation)
insert_offset = self.elem.gui_info.gui_to_tree_index(cursor_pos)
self.elem.insert(insert_offset, translation)
self.elem.prune()
self.emit('text-inserted', translation, cursor_pos, self.elem)
if hasattr(translation, 'gui_info'):
cursor_pos += translation.gui_info.length()
else:
cursor_pos += len(translation)
else:
self.buffer.insert_at_cursor(translation)
cursor_pos += len(translation)
self.refresh_cursor_pos = cursor_pos
self.refresh()
def move_elem_selection(self, offset):
direction = offset/abs(offset) # Reduce offset to one of -1, 0 or 1
st_index = self.selector_textboxes.index(self.selector_textbox)
st_len = len(self.selector_textboxes)
if self.selector_textbox.selected_elem_index is None:
if offset <= 0:
if offset < 0 and st_len > 1:
self.selector_textbox = self.selector_textboxes[(st_index + direction) % st_len]
self.selector_textbox.select_elem(offset=offset)
else:
self.selector_textbox.select_elem(offset=offset-1)
else:
self.selector_textbox.select_elem(offset=self.selector_textbox.selected_elem_index + offset)
if self.selector_textbox.selected_elem_index is None and direction >= 0:
self.selector_textbox = self.selector_textboxes[(st_index + direction) % st_len]
self.__color_selector_textboxes()