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


Python StringElem.elem_offset方法代码示例

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


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

示例1: TextBox

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

#.........这里部分代码省略.........
        if self.placeables_controller is not None and \
                self.undo_controller is not None:
            main_controller.disconnect(self.__controller_connect_id)

    def _on_begin_user_action(self, buffer):
        if not self.undo_controller:
            # Maybe not ready yet, so we'll loose a bit of undo data
            return
        if not self.undo_controller.model.recording:
            self.undo_controller.record_start()

    def _on_end_user_action(self, buffer):
        if not self.undo_controller:
            return
        if self.undo_controller.model.recording:
            self.undo_controller.record_stop()
        self.refresh()

    def _on_delete_range(self, buffer, start_iter, end_iter):
        if self.elem is None:
            return

        cursor_pos = self.refresh_cursor_pos
        if cursor_pos < 0:
            cursor_pos = self.buffer.props.cursor_position

        start_offset = start_iter.get_offset()
        end_offset = end_iter.get_offset()

        start_elem = self.elem.gui_info.elem_at_offset(start_offset)
        if start_elem is None:
            return
        start_elem_len = start_elem.gui_info.length()
        start_elem_offset = self.elem.gui_info.index(start_elem)

        end_elem = self.elem.gui_info.elem_at_offset(end_offset)
        if end_elem is not None:
            # end_elem can be None if end_offset == self.elem.gui_info.length()
            end_elem_len = end_elem.gui_info.length()
            end_elem_offset = self.elem.gui_info.index(end_elem)
        else:
            end_elem_len = 0
            end_elem_offset = self.elem.gui_info.length()

        #logging.debug('pre-checks: %s[%d:%d]' % (repr(self.elem), start_offset, end_offset))
        #logging.debug('start_elem_offset= %d\tend_elem_offset= %d' % (start_elem_offset, end_elem_offset))
        #logging.debug('start_elem_len   = %d\tend_elem_len   = %d' % (start_elem_len, end_elem_len))
        #logging.debug('start_offset     = %d\tend_offset     = %d' % (start_offset, end_offset))

        # Per definition of a selection, cursor_pos must be at either
        # start_offset or end_offset
        key_is_delete = cursor_pos == start_offset
        done = False

        deleted, parent, index = None, None, None

        if abs(start_offset - end_offset) == 1:
            position = None
            #################################
            #  Placeable:  |<<|content|>>|  #
            #  Cursor:     a  b       c  d  #
            #===============================#
            #           Editable            #
            #===============================#
            #   |  Backspace  |  Delete     #
            #---|-------------|-------------#
开发者ID:martinproject,项目名称:virtaal,代码行数:70,代码来源:textbox.py


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