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


Python Document.read方法代码示例

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


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

示例1: CodeTools

# 需要导入模块: from document import Document [as 别名]
# 或者: from document.Document import read [as 别名]
class CodeTools(object):

    def __init__(self, window):
        self.document = Document(window.get_active_document())
        self.view = View(window.get_active_view())
        self.start = None
        self.end = None
        self.lines = 0
        self.text = ""
        self.selection = 0
        self._initialize_text()

    def _initialize_text(self):
        self._get_code_selection()
        self.current_start_offset = self.start.get_offset()
        self.current_start_line_offset = self.start.get_line_offset()
        self.current_end_offset = self.end.get_offset()
        self.current_insert_offset = self.document.get_insert_offset()
        self._get_selection_character_count()
        self._define_selection_block()
        self.view.move_to_end_of_selection_block(self.document, self.end.get_line())
        self.text = self.document.read(self.start, self.end)

    def _get_code_selection(self):
        selection = self.document.get_selection()
        insert = self.document.get_insert() 
        (self.start, self.end) = selection or (insert, insert.copy())
        return (self.start, self.end)

    def _get_selection_character_count(self):
        self.selection = math.fabs(self.current_end_offset - self.current_start_offset)
        return self.selection
  
    def _define_selection_block(self):        
        self.lines = self.end.get_line()-self.start.get_line()
        self.start.set_line_offset(0)
        if not self.end.ends_line():
            self.end.forward_to_line_end()

    def select_and_delete(self):
        self.view.select_by_offsets(
            self.start.get_offset(),
            self.document.get_insert_offset(),
            self.end.get_offset()
        )
        self.document.delete()

    def comment_text(self):
        self.select_and_delete()
        code_comment = CodeComment(self.document, self.text)
        code_comment.analyze_comment_tags()
        code_comment.verify_commenting()
        code_comment.do_comment_or_uncomment()
        (self.current_start_offset, self.selection) = code_comment.calculate_new_position_values(self.current_start_offset, self.selection)
        self.text = code_comment.change_text()

    def copy_text_to_clipboard(self):
        clipboard = gtk.clipboard_get()
        clipboard.set_text(self.text)
        clipboard.store()

    def erase_line(self, down):
        self.select_and_delete()
        end_line = self.document.get_insert().copy()
        end_line.set_line_offset(0)
        end_line.forward_line()
        self.document.delete(self.document.get_insert(), end_line)
        self.view.move_line_cursor(1  if down else -1, select=False)
        
    def __enter__(self):
        self.document.begin_user_action()
        return self

    def __exit__(self, type, value, traceback):
        self.document.end_user_action()
开发者ID:JoaoFelipe,项目名称:GetBeans--gedit-plugin-,代码行数:77,代码来源:code_tools.py


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