本文整理汇总了Python中translate.storage.placeables.StringElem.depth_first方法的典型用法代码示例。如果您正苦于以下问题:Python StringElem.depth_first方法的具体用法?Python StringElem.depth_first怎么用?Python StringElem.depth_first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类translate.storage.placeables.StringElem
的用法示例。
在下文中一共展示了StringElem.depth_first方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TextBox
# 需要导入模块: from translate.storage.placeables import StringElem [as 别名]
# 或者: from translate.storage.placeables.StringElem import depth_first [as 别名]
#.........这里部分代码省略.........
if preserve_selection and selection:
self.buffer.select_range(
self.buffer.get_iter_at_offset(selection[0]),
self.buffer.get_iter_at_offset(selection[1]),
)
elif self.refresh_cursor_pos >= 0:
self.place_cursor(self.refresh_cursor_pos)
self.refresh_cursor_pos = -1
for action in self.refresh_actions:
if callable(action):
action()
self.refresh_actions = []
self.emit('refreshed', self.elem)
def select_elem(self, elem=None, offset=None):
if elem is not None and offset is not None:
raise ValueError('Only one of "elem" or "offset" may be specified.')
if elem is None and offset is None:
# Clear current selection
#logging.debug('Clearing selected placeable from %s' % (repr(self)))
if self.selected_elem is not None:
#logging.debug('Selected item *was* %s' % (repr(self.selected_elem)))
self.selected_elem.gui_info = None
self.add_default_gui_info(self.selected_elem)
self.selected_elem = None
self.selected_elem_index = None
self.emit('element-selected', self.selected_elem)
return
filtered_elems = [e for e in self.elem.depth_first() if e.__class__ not in self.unselectables]
if not filtered_elems:
return
if elem is None and offset is not None:
if self.selected_elem_index is not None and not (0 <= offset < len(filtered_elems)):
# Clear selection when we go past the first or last placeable
self.select_elem(None)
self.apply_gui_info(self.elem)
return
return self.select_elem(elem=filtered_elems[offset % len(filtered_elems)])
if elem not in filtered_elems:
return
# Reset the default tag for the previously selected element
if self.selected_elem is not None:
self.selected_elem.gui_info = None
self.add_default_gui_info(self.selected_elem)
i = 0
for fe in filtered_elems:
if fe is elem:
break
i += 1
self.selected_elem_index = i
self.selected_elem = elem
#logging.debug('Selected element: %s (%s)' % (repr(self.selected_elem), unicode(self.selected_elem)))
if not hasattr(elem, 'gui_info') or not elem.gui_info:
elem.gui_info = placeablesguiinfo.StringElemGUI(elem, self, fg=current_theme['selected_placeable_fg'], bg=current_theme['selected_placeable_bg'])
else:
elem.gui_info.fg = current_theme['selected_placeable_fg']
elem.gui_info.bg = current_theme['selected_placeable_bg']