本文整理汇总了Python中lexer.Lexer.dispense方法的典型用法代码示例。如果您正苦于以下问题:Python Lexer.dispense方法的具体用法?Python Lexer.dispense怎么用?Python Lexer.dispense使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lexer.Lexer
的用法示例。
在下文中一共展示了Lexer.dispense方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EnhancedTextBox
# 需要导入模块: from lexer import Lexer [as 别名]
# 或者: from lexer.Lexer import dispense [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
#.........这里部分代码省略.........