当前位置: 首页>>代码示例>>Python>>正文


Python StringElem.find方法代码示例

本文整理汇总了Python中translate.storage.placeables.StringElem.find方法的典型用法代码示例。如果您正苦于以下问题:Python StringElem.find方法的具体用法?Python StringElem.find怎么用?Python StringElem.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在translate.storage.placeables.StringElem的用法示例。


在下文中一共展示了StringElem.find方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TextBox

# 需要导入模块: from translate.storage.placeables import StringElem [as 别名]
# 或者: from translate.storage.placeables.StringElem import find [as 别名]

#.........这里部分代码省略.........

        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']
        self.apply_gui_info(self.elem, include_subtree=False)
        self.apply_gui_info(self.elem)
        self.apply_gui_info(elem, include_subtree=False)
        cursor_offset = self.elem.find(self.selected_elem) + len(self.selected_elem)
        self.place_cursor(cursor_offset)
        self.emit('element-selected', self.selected_elem)

    def show_suggestion(self, suggestion=None):
        if isinstance(suggestion, dict):
            self.suggestion = suggestion
        if self.suggestion is None:
            return
        iters = (self.buffer.get_iter_at_offset(self.suggestion['offset']),)
        self.buffer.handler_block_by_func(self._on_insert_text)
        self.buffer.insert(iters[0], self.suggestion['text'])
        self.buffer.handler_unblock_by_func(self._on_insert_text)
        iters = (
            self.buffer.get_iter_at_offset(self.suggestion['offset']),
            self.buffer.get_iter_at_offset(
                self.suggestion['offset'] + len(self.suggestion['text'])
            )
        )
        self.buffer.select_range(*iters)

    def suggestion_is_visible(self):
        """Checks whether the current text suggestion is visible."""
        selection = self.buffer.get_selection_bounds()
        if not selection or self.suggestion is None:
            return False
        start_offset = selection[0].get_offset()
        text = self.buffer.get_text(*selection)
        return self.suggestion['text'] and \
                self.suggestion['text'] == text and \
                self.suggestion['offset'] >= 0 and \
                self.suggestion['offset'] == start_offset
开发者ID:martinproject,项目名称:virtaal,代码行数:69,代码来源:textbox.py


注:本文中的translate.storage.placeables.StringElem.find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。