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


Python Document.delete方法代码示例

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


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

示例1: TestDocument

# 需要导入模块: from document import Document [as 别名]
# 或者: from document.Document import delete [as 别名]
class TestDocument(unittest.TestCase):
    def setUp(self):
        self.d = Document()
        self.d.insert("a")

    def test_cursor(self):
        self.assertEqual(self.d.cursor.position, 1)
        self.d.save("tst")
        try:
            remove("tst")
        except OSError:
            pass
        self.d.cursor.back()
        self.d.delete()
        self.assertEqual(self.d.cursor.position, 0)

    def test_multiple_chars_and_escape(self):
        self.d.cursor.home()
        self.d.delete()
        string = ["h", "e", "l", "l", "o", "\n", "w", "o", "r", "l", "d", "!"]
        for i in string:
            self.d.insert(i)
        self.assertEqual(self.d.string, "hello\nworld!")

    def test_string_property(self):
        self.assertEqual(self.d.string, "a")
开发者ID:jainarchita,项目名称:60-days-of-python,代码行数:28,代码来源:test_document.py

示例2: CodeTools

# 需要导入模块: from document import Document [as 别名]
# 或者: from document.Document import delete [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.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。