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


Python Lexer.insert方法代码示例

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


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

示例1: EnhancedTextBox

# 需要导入模块: from lexer import Lexer [as 别名]
# 或者: from lexer.Lexer import insert [as 别名]
class EnhancedTextBox(tk.Text):
    lexer = None
    
    def __init__(self, master=None, lex=None,**kw):
        tk.Text.__init__(self,master,**kw)
        self.lexer = Lexer(lex)
        
    def clear(self):
        self.delete(1.0, tk.END)
        
    def displayFile(self, file):
        """Given a file opened for reading, will 
        display the contents on the screen."""
        
        self.clear()
        
        for line in file:
            self.lexer.insert(line)
            while(self.lexer.ready()):
                line,color = self.lexer.dispense()
                self.insert(tk.END, line)
    
    def write(self,output):
        """Going to attempt writing the whole file in one
        shot. Is this a good idea? Only time will tell..."""
        
        block = self.get(1.0, tk.END)
        #get rid of trailing newline from string conversion
        block = block[:len(block) - 1]
        output.write(block)
        #Flush is important - small files will never write
        #to disk without it
        output.flush()
        
    def getCharWordCount(self):
        block = self.get(1.0, tk.END)
        c = len(block) - 1
        block = block.split()
        w = len(block)
        return (w,c)
        
    def setFont(self, f):
        self.configure(font=f)
        
    def copy(self, event=None):
        self.clipboard_clear()
        text = self.get("sel.first", "sel.last")
        self.clipboard_append(text)
    
    def cut(self, event=None):
        self.copy()
        self.delete("sel.first", "sel.last")

    def paste(self, event=None):
        text = self.selection_get(selection='CLIPBOARD')
        self.insert('insert', text)
        
    def getCursorPos(self):
        return self.index('insert').split('.')
        
    def totalLines(self):
        #get the index of the last character, split it on '.' to get
        #the line number, then return the int of the first index. The
        #minus one is because of the way the index works
        return int(self.index(tk.END).split(".")[0]) - 1
        
    def magicTab(self,spaces=4,delete=False):
        line, column = self.getCursorPos()
        index = "%s.0" % str(line)
        if(delete):
            if(spaces <= -1):
                if(self.get(index) == "\t"):
                    self.delete(index)
            else:
                endindex = "%s.%s" % (line, str(spaces))
                text = self.get(index,endindex)
                if(text == ' ' * spaces):
                    self.delete(index,endindex)
                elif(text[0] == ' '):
                    range = 0;
                    while(range < len(text) and text[range] == ' '):
                        range = range + 1
                    endindex = "%s.%s" % (line,str(range))
                    self.delete(index,endindex)
        else:
            #shift the whole line over one tab, regardless of 
            #where the cursor is in the line
            if(spaces <= -1):
                self.insert(index, '\t')
            else:
                self.insert(index, ' ' * spaces)
        
    def insertTab(self,spaces):
        if(spaces <= -1):
            self.insert(self.index('insert'),'\t')
        else:
            self.insert(self.index('insert'),' ' * spaces)
        
    def getIndent(self,line):
        index = "%s.0" % line
#.........这里部分代码省略.........
开发者ID:nerdcorerising,项目名称:PyEdit,代码行数:103,代码来源:textbox.py


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