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


Python StringElem.insert_between方法代码示例

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


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

示例1: TextBox

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

#.........这里部分代码省略.........
            else:
                self.refresh_cursor_pos = self.elem.gui_info.tree_to_gui_index(start_offset)

        if index is None:
            index = start_offset

        if deleted:
            self.elem.prune()
            self.emit(
                'text-deleted', deleted, parent, index,
                self.buffer.props.cursor_position, self.elem
            )

    def _on_insert_text(self, buffer, iter, ins_text, length):
        if self.elem is None:
            return

        ins_text = data.forceunicode(ins_text[:length])
        buff_offset = iter.get_offset()
        gui_info = self.elem.gui_info
        left = gui_info.elem_at_offset(buff_offset-1)
        right = gui_info.elem_at_offset(buff_offset)

        #logging.debug('"%s[[%s]]%s" | elem=%s[%d] | left=%s right=%s' % (
        #    buffer.get_text(buffer.get_start_iter(), iter),
        #    ins_text,
        #    buffer.get_text(iter, buffer.get_end_iter()),
        #    repr(self.elem), buff_offset,
        #    repr(left), repr(right)
        #))

        succeeded = False
        if not (left is None and right is None) and (left is not right or not unicode(left)):
            succeeded = self.elem.insert_between(left, right, ins_text)
            #logging.debug('self.elem.insert_between(%s, %s, "%s"): %s' % (repr(left), repr(right), ins_text, succeeded))
        if not succeeded and left is not None and left is right and left.isleaf():
            # This block handles the special case where a the cursor is just
            # inside a leaf element with a closing widget. In this case both
            # left and right will point to the element in question, but it
            # need not be empty to be a leaf. Because the cursor is still
            # "inside" the element, we want to append to this leaf in stead
            # of after it, which is what StringElem.insert() will do, seeing
            # as the position before and after the widget is the same to in
            # the context of StringElem.
            anchor = iter.get_child_anchor()
            if anchor:
                widgets = anchor.get_widgets()
                left_widgets = left.gui_info.widgets
                if len(widgets) > 0 and len(left_widgets) > 1 and \
                        widgets[0] is left_widgets[1] and \
                        iter.get_offset() == self.elem.gui_info.length() - 1:
                    succeeded = left.insert(len(left), ins_text)
                    #logging.debug('%s.insert(len(%s), "%s")' % (repr(left), repr(left), ins_text))
        if not succeeded:
            offset = gui_info.gui_to_tree_index(buff_offset)
            succeeded = self.elem.insert(offset, ins_text)
            #logging.debug('self.elem.insert(%d, "%s"): %s' % (offset, ins_text, succeeded))

        if succeeded:
            self.elem.prune()
            cursor_pos = self.refresh_cursor_pos
            if cursor_pos < 0:
                cursor_pos = self.buffer.props.cursor_position
            cursor_pos += len(ins_text)
            self.refresh_cursor_pos = cursor_pos
            #logging.debug('text-inserted: %[email protected]%d of %s' % (ins_text, iter.get_offset(), repr(self.elem)))
开发者ID:martinproject,项目名称:virtaal,代码行数:70,代码来源:textbox.py


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