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


Python Percolator.insertfilter方法代码示例

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


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

示例1: TicText

# 需要导入模块: from idlelib.Percolator import Percolator [as 别名]
# 或者: from idlelib.Percolator.Percolator import insertfilter [as 别名]
class TicText(Text):
    def __init__(self, parent, spell=None, **kw):
        Text.__init__(self, parent, wrap="word",
                      font="Times 14", takefocus=True, **kw)
        self.tg_regexp = re.compile("<[^>]*>")
        self.bind("<Control-c>", self.copy)
        self.bind("<Control-x>", self.cut)
        self.bind("<Return>", self.newline)
        self.tag_configure("h1", font="Times 16 bold", relief="raised")
        self.tag_configure("highlight", background="yellow", relief="raised")
        self.tag_configure("html_tag", foreground="blue")
        if spell:
            r, self.wd = pipe()
            self.rd, w = pipe()
            args = spell.split()
            self.sp = Popen(args, stdin=r, stdout=w)

            self.tag_configure("misspelled", foreground="red", underline=True)
            self.bind("<space>", self.Spellcheck)
        self.percolator = Percolator(self)
        self.percolator.insertfilter(HtmlColorDelegator())

    def copy(self, event=None):
        self.clipboard_clear()
        text = self.get("sel.first", "sel.last")
        self.clipboard_append(text)

    def cut(self, event):
        self.copy()
        self.delete("sel.first", "sel.last")

    def Spellcheck(self, event):
        """Spellcheck the word preceeding the insertion point"""
        index = self.search(r"\s", "insert", backwards=True, regexp=True)
        if index == "":
            index = "1.0"
        else:
            index = self.index("%s+1c" % index)
        word = self.get(index, "insert")
        write(self.wd, (word + "\n").encode())
        sleep(.01)
        spell = read(self.rd, 0x0fffffff)
        rm = len([None for i in spell.splitlines()
                  if i[:1] == b"#"])
        if not rm:
            self.tag_remove("misspelled", index, "%s+%dc" % (index, len(word)))
        else:
            self.tag_add("misspelled", index, "%s+%dc" % (index, len(word)))

    def highlight(self, regexp):
        text = self.get("1.0", "end")
        for m in re.finditer(regexp, text, re.I):
            self.tag_add("highlight", "1.0+%dc" % m.start(),
                         "1.0+%dc" % m.end())

    def newline(self, evt):
        self.insert("insert", "<br/>")
开发者ID:Lysovenko,项目名称:OTRS_US,代码行数:59,代码来源:ttext.py

示例2: main

# 需要导入模块: from idlelib.Percolator import Percolator [as 别名]
# 或者: from idlelib.Percolator.Percolator import insertfilter [as 别名]
def main():
    from idlelib.Percolator import Percolator
    root = Tk()
    root.wm_protocol("WM_DELETE_WINDOW", root.quit)
    text = Text(background="white")
    text.pack(expand=1, fill="both")
    text.focus_set()
    p = Percolator(text)
    d = ColorDelegator()
    p.insertfilter(d)
    root.mainloop()
开发者ID:AndyPanda95,项目名称:python-for-android,代码行数:13,代码来源:ColorDelegator.py

示例3: main

# 需要导入模块: from idlelib.Percolator import Percolator [as 别名]
# 或者: from idlelib.Percolator.Percolator import insertfilter [as 别名]
def main():
    from idlelib.Percolator import Percolator
    root = Tk()
    root.wm_protocol('WM_DELETE_WINDOW', root.quit)
    text = Text()
    text.pack()
    text.focus_set()
    p = Percolator(text)
    d = UndoDelegator()
    p.insertfilter(d)
    root.mainloop()
开发者ID:webiumsk,项目名称:WOT-0.9.15-CT,代码行数:13,代码来源:undodelegator.py

示例4: _color_delegator

# 需要导入模块: from idlelib.Percolator import Percolator [as 别名]
# 或者: from idlelib.Percolator.Percolator import insertfilter [as 别名]
def _color_delegator(parent):
    from idlelib.Percolator import Percolator
    root = Tk()
    root.title("Test ColorDelegator")
    width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
    root.geometry("+%d+%d"%(x, y + 150))
    source = "if somename: x = 'abc' # comment\nprint"
    text = Text(root, background="white")
    text.insert("insert", source)
    text.pack(expand=1, fill="both")
    p = Percolator(text)
    d = ColorDelegator()
    p.insertfilter(d)
    root.mainloop()
开发者ID:5outh,项目名称:Databases-Fall2014,代码行数:16,代码来源:ColorDelegator.py

示例5: _color_delegator

# 需要导入模块: from idlelib.Percolator import Percolator [as 别名]
# 或者: from idlelib.Percolator.Percolator import insertfilter [as 别名]
def _color_delegator(parent):  # htest #
    from Tkinter import Toplevel, Text
    from idlelib.Percolator import Percolator

    top = Toplevel(parent)
    top.title("Test ColorDelegator")
    top.geometry("200x100+%d+%d" % (parent.winfo_rootx() + 200,
                  parent.winfo_rooty() + 150))
    source = "if somename: x = 'abc' # comment\nprint\n"
    text = Text(top, background="white")
    text.pack(expand=1, fill="both")
    text.insert("insert", source)
    text.focus_set()

    p = Percolator(text)
    d = ColorDelegator('.py')
    p.insertfilter(d)
开发者ID:rsk0315,项目名称:papyrus,代码行数:19,代码来源:ColorDelegator.py

示例6: makewidgets

# 需要导入模块: from idlelib.Percolator import Percolator [as 别名]
# 或者: from idlelib.Percolator.Percolator import insertfilter [as 别名]
 def makewidgets(self):
     sbar = Scrollbar(self)
     text = Text2(self, relief=SUNKEN)
     text.focus_set()
     p = Percolator(text)
     d = ColorDelegator()
     p.insertfilter(d)
     sbar.config(command=text.yview)
     text.config(yscrollcommand=sbar.set)
     sbar.pack(side=RIGHT, fill=Y)
     text.pack(side=LEFT, expand=YES, fill=BOTH)
     self.text = text
     self.copy = text.copy
     self.paste = text.paste
     self.delete = text.delete
     self.cut = text.cut
     self.highlight = text.higlight
开发者ID:afranck64,项目名称:PySam,代码行数:19,代码来源:ColoredText.py

示例7: _undo_delegator

# 需要导入模块: from idlelib.Percolator import Percolator [as 别名]
# 或者: from idlelib.Percolator.Percolator import insertfilter [as 别名]
def _undo_delegator(parent):  # htest #
    import re
    import tkinter as tk
    from idlelib.Percolator import Percolator
    undowin = tk.Toplevel()
    undowin.title("Test UndoDelegator")
    width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
    undowin.geometry("+%d+%d"%(x, y + 150))

    text = Text(undowin, height=10)
    text.pack()
    text.focus_set()
    p = Percolator(text)
    d = UndoDelegator()
    p.insertfilter(d)

    undo = Button(undowin, text="Undo", command=lambda:d.undo_event(None))
    undo.pack(side='left')
    redo = Button(undowin, text="Redo", command=lambda:d.redo_event(None))
    redo.pack(side='left')
    dump = Button(undowin, text="Dump", command=lambda:d.dump_event(None))
    dump.pack(side='left')
开发者ID:AndreLouisCaron,项目名称:cpython,代码行数:24,代码来源:UndoDelegator.py

示例8: _undo_delegator

# 需要导入模块: from idlelib.Percolator import Percolator [as 别名]
# 或者: from idlelib.Percolator.Percolator import insertfilter [as 别名]
def _undo_delegator(parent):
    from idlelib.Percolator import Percolator
    root = Tk()
    root.title("Test UndoDelegator")
    width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
    root.geometry("+%d+%d"%(x, y + 150))

    text = Text(root)
    text.config(height=10)
    text.pack()
    text.focus_set()
    p = Percolator(text)
    d = UndoDelegator()
    p.insertfilter(d)

    undo = Button(root, text="Undo", command=lambda:d.undo_event(None))
    undo.pack(side='left')
    redo = Button(root, text="Redo", command=lambda:d.redo_event(None))
    redo.pack(side='left')
    dump = Button(root, text="Dump", command=lambda:d.dump_event(None))
    dump.pack(side='left')

    root.mainloop()
开发者ID:billtsay,项目名称:win-demo-opcua,代码行数:25,代码来源:UndoDelegator.py

示例9: ConsoleText

# 需要导入模块: from idlelib.Percolator import Percolator [as 别名]
# 或者: from idlelib.Percolator.Percolator import insertfilter [as 别名]
class ConsoleText(ScrolledText):
    class StreamObserver(object):
        def __init__(self, console_text):
            self.__console_text  = console_text
        def update(self, stream_type, content):
            self.__console_text.write(stream_type, content)
    
    def __init__(self, *args, **kwargs):
        super(ConsoleText, self).__init__(*args, **kwargs)
        # The shared queue of the PRODUCER-CONSUMER model.
        self.__queue    = Queue.Queue()
        self.text['wrap']   = 'word'
        self.text.tag_configure('STDOUT',   foreground='black')
        self.text.tag_configure('STDERR',   foreground='red')
        self.text.tag_configure('TIP', foreground='forestgreen')
        self.text.tag_configure('HISTORY',   foreground='purple')
        self.text.tag_configure('RETVAL',    foreground='orange')
        
        self.text.bind('<KeyPress>', self.on_key_press)

        
        # Experimenting with idlelib.AutoComplete
        #############################################################
        self.indent_width    = 4
        self.tab_width       = 4
        self.context_use_ps1    = '>>> '
        self.__auto_complete = AutoComplete(self)  
        #############################################################
                
        # Syntax highlight is implemented by idlelib
        #############################################################                
        self.percolator = Percolator(self.text)
        self.color_delegator = ColorDelegator()
        self.percolator.insertfilter(self.color_delegator)   
        #############################################################                        
        self.prompt_symbol = '>>> '    
        
        
    def update_content(self, tag, content):
        r, c    = self.get_cursor_pos(END)
        start   = 'end-5c'
        stop    = 'end-1c'
        if self.text.get(start, stop) == '>>> ' or self.text.get(start, stop) == '... ':
            self.text.delete(start, stop)

        # Record the position of the END before inserting anything.
        start    = self.text.index(END)

        self.text.insert(END, content, tag)

        # Remove unnecessary highlighting
        for tag in self.color_delegator.tagdefs:
            self.text.tag_remove(tag, start, "end")            
        self.text.insert(END, self.prompt_symbol)                
        # Remove unnecessary highlighting
        self.text.tag_remove("TODO", "1.0", END)
        self.text.tag_add("SYNC", "1.0", END)                                
        self.text.see(END)                        

    def on_key_press(self, evt, code_list=[]):     
        # Experimenting with idlelib's AutoComplete
        ##############################################################
        keysym = evt.keysym        
        if self.__auto_complete.autocompletewindow and \
                self.__auto_complete.autocompletewindow.is_active():
            if self.__auto_complete.autocompletewindow.keypress_event(evt) == 'break':
                return 'break'
            else:
                if keysym == 'Tab':
                    return 'break'
            
        if evt.keysym == 'Tab':
            return self.__auto_complete.autocomplete_event(evt)
        ##############################################################
        # if evt.keycode not in range(16, 19) and evt.keycode not in range(33, 41):
        if evt.keysym not in ('Alt_L', 'Alt_R', 'Control_L', 'Control_R', 'Shift_L', 'Shift_R',  'KP_Prior', 'KP_Next', 'KP_Home', 'KP_End', 'KP_Left', 'KP_Right', 'KP_Up', 'KP_Down', 'Left', 'Right', 'Up', 'Down', 'Home', 'End', 'Next', 'Prior'):
            r, c    = self.get_cursor_pos()
            prompt  = self.text.get(auto_subs('$r.0'), auto_subs('$r.4'))
            if prompt != '>>> ' and prompt != '... ':
                return 'break'
            if evt.keysym=='BackSpace' and c <= 4:
                return 'break'
            if c < 4:
                return 'break'
            rend, cend  = self.get_cursor_pos('end-1c')
            if r < rend:
                return 'break'                
            if evt.keysym == 'Return': # Return
                app = Application.instance
                code = self.text.get(auto_subs('$r.4'), auto_subs('$r.end'))
                try:
                    stripped_code     = code.strip()
                    if stripped_code and stripped_code[0] == '!':
                        # Execute a system command
                        app.execute(code)
                        self.prompt_symbol   = '>>> '
                        self.update_content(tag='', content='\n')
                        return 'break'
                    if stripped_code == '':
                        code = '\n'.join(code_list)
#.........这里部分代码省略.........
开发者ID:VanDeng95,项目名称:WaveSyn,代码行数:103,代码来源:application.py

示例10: PercolatorTest

# 需要导入模块: from idlelib.Percolator import Percolator [as 别名]
# 或者: from idlelib.Percolator.Percolator import insertfilter [as 别名]
class PercolatorTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.root = Tk()
        cls.text = Text(cls.root)

    @classmethod
    def tearDownClass(cls):
        del cls.text
        cls.root.destroy()
        del cls.root

    def setUp(self):
        self.percolator = Percolator(self.text)
        self.filter_one = MyFilter()
        self.filter_two = MyFilter()
        self.percolator.insertfilter(self.filter_one)
        self.percolator.insertfilter(self.filter_two)

    def tearDown(self):
        self.percolator.close()
        self.text.delete('1.0', END)

    def test_insertfilter(self):
        self.assertIsNotNone(self.filter_one.delegate)
        self.assertEqual(self.percolator.top, self.filter_two)
        self.assertEqual(self.filter_two.delegate, self.filter_one)
        self.assertEqual(self.filter_one.delegate, self.percolator.bottom)

    def test_removefilter(self):
        filter_three = MyFilter()
        self.percolator.removefilter(self.filter_two)
        self.assertEqual(self.percolator.top, self.filter_one)
        self.assertIsNone(self.filter_two.delegate)

        filter_three = MyFilter()
        self.percolator.insertfilter(self.filter_two)
        self.percolator.insertfilter(filter_three)
        self.percolator.removefilter(self.filter_one)
        self.assertEqual(self.percolator.top, filter_three)
        self.assertEqual(filter_three.delegate, self.filter_two)
        self.assertEqual(self.filter_two.delegate, self.percolator.bottom)
        self.assertIsNone(self.filter_one.delegate)

    def test_insert(self):
        self.text.insert('insert', 'foo')
        self.assertEqual(self.text.get('1.0', END), 'foo\n')
        self.assertTupleEqual(self.filter_one.insert_called_with,
                              ('insert', 'foo', None))

    def test_modify_insert(self):
        self.filter_one.insert = self.filter_one.uppercase_insert
        self.text.insert('insert', 'bAr')
        self.assertEqual(self.text.get('1.0', END), 'BAR\n')

    def test_modify_chain_insert(self):
        filter_three = MyFilter()
        self.percolator.insertfilter(filter_three)
        self.filter_two.insert = self.filter_two.uppercase_insert
        self.filter_one.insert = self.filter_one.lowercase_insert
        self.text.insert('insert', 'BaR')
        self.assertEqual(self.text.get('1.0', END), 'bar\n')

    def test_dont_insert(self):
        self.filter_one.insert = self.filter_one.dont_insert
        self.text.insert('insert', 'foo bar')
        self.assertEqual(self.text.get('1.0', END), '\n')
        self.filter_one.insert = self.filter_one.dont_insert
        self.text.insert('insert', 'foo bar')
        self.assertEqual(self.text.get('1.0', END), '\n')

    def test_without_filter(self):
        self.text.insert('insert', 'hello')
        self.assertEqual(self.text.get('1.0', 'end'), 'hello\n')

    def test_delete(self):
        self.text.insert('insert', 'foo')
        self.text.delete('1.0', '1.2')
        self.assertEqual(self.text.get('1.0', END), 'o\n')
        self.assertTupleEqual(self.filter_one.delete_called_with,
                              ('1.0', '1.2'))
开发者ID:Logotrop,项目名称:trida,代码行数:84,代码来源:test_percolator.py


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