本文整理汇总了Python中ScrolledText.index方法的典型用法代码示例。如果您正苦于以下问题:Python ScrolledText.index方法的具体用法?Python ScrolledText.index怎么用?Python ScrolledText.index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScrolledText
的用法示例。
在下文中一共展示了ScrolledText.index方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MemoPadFrame
# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import index [as 别名]
class MemoPadFrame( Frame ):
def __init__(self, master=None):
Frame.__init__(self, master)
# Modelの初期化
self.version = (0, 2, 5)
self.memos = MemoPad()
self.memos.addObserver(self)
# change-logger のバインド
self.changeLogger = ChangeLogger()
self.memos.addObserver( self.changeLogger )
# View-Controller の初期化
self.master.title( 'MemoPad %d.%d.%d' % self.version )
self.make_listPanel(self)
self.make_editAria(self)
self.pack(fill=BOTH)
# データの復帰
self.memos.loadImage()
def bye():
self.saveMemo() # 現在編集中のメモをセーブ
self.memos.saveImage()
print 'bye'
self.master.destroy()
self.master.protocol('WM_DELETE_WINDOW', bye )
def make_listPanel(self, parent):
frm = Frame(parent)
# リストの生成・配置
def changeTarget(evt):
try: index = int(self.memoList.curselection()[0])
except: index = None
self.saveMemo()
if index != None: self.selectMemo( index )
self.memoList = ScrolledListbox(frm,
selectmode=BROWSE,
width=72,
height=7 )
self.memoList.bind("<ButtonRelease>", changeTarget )
self.memoList.bind('<B1-Motion>', changeTarget )
self.memoList.pack(side=LEFT, fill=BOTH)
# ボタンの作成
btnfrm = Frame(frm)
def appendMemo():
self.saveMemo()
self.memos.appendMemo()
Button( btnfrm,
text='new',
command=appendMemo ).pack(side=TOP, fill=X)
def deleteMemo():
self.saveMemo()
self.memos.removeMemo()
Button( btnfrm,
text='delete',
command=deleteMemo ).pack(side=TOP, fill=X)
btnfrm.pack(side=LEFT)
frm.pack(side=TOP, fill=X)
def make_editAria(self, parent):
self.text = ScrolledText( parent )
self.text.pack(side=TOP, fill=BOTH)
def updateTitle(evt):
'''実験コード。まだ
改行や行末改行の削除に弱いです
'''
# print self.text.index('1.end')
# print self.text.index(INSERT)
if self.text.index(INSERT).split('.')[0] == '1': # 1行目
itemnum = self.memos.getSelectedIndex()
self.memoList.delete(itemnum)
self.memoList.insert(itemnum,
"%s | %s" % (self.memos[itemnum].getDatetime().strftime("%Y-%m-%d %H:%M"),
u'%s%s%s' % ( self.text.get('1.0', INSERT),
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import index [as 别名]
#.........这里部分代码省略.........
rtimg = Tkinter.PhotoImage(file="target.gif")
self.rti = Tkinter.Label(master, image = rtimg)
self.rti.image=rtimg
self.rti.grid(row=5, column=2, columnspan=1, padx=5, pady=5)
'''
# User credentials field
cred_label_text = ['Server IP: ','Username: ','Password: ']
self.cred_text = []
self.cred_label = []
credpane = []
for i in range(0,3):
credpane.append(Tkinter.PanedWindow())
self.cred_label.append(Tkinter.Label(master, text=cred_label_text[i]))
self.cred_text.append((Tkinter.Entry(master,width=50)))
credpane[i].add(self.cred_label[i])
credpane[i].add(self.cred_text[i])
credpane[i].grid(row=5+i, column=1, columnspan=1, padx=5, pady=5, sticky=Tkinter.E)
self.cred_but = Tkinter.Button(master, text='Login', command=self.loginWithCred)
self.cred_but.grid(row=8, column=1, columnspan=1, padx=5, pady=5)
# Add more GUI stuff here
def processIncoming(self):
"""
Handle all the messages currently in the queue (if any).
"""
#self.counter = 0
#self.queue.put('asdas')
while self.queue.qsize():
try:
self.msg = str(self.queue.get(0)) + '\n'
# Check contents of message and do what it says
# As a test, we simply print it
self.tele.insert('end', self.msg)
if(float(self.tele.index('end')) > 11.0):
self.tele.delete('1.0','end')
self.msg2 = self.queue2.get(0) + '\n'
#print self.msg2
if(self.msg2.find('Target') == 0):
#self.targetpics[self.counter] = self.msg2
self.targetpics.append(self.msg2)
#self.counter += 1
else:
self.rt.insert('end', self.msg2)
except Queue.Empty:
pass
def getObstacles(self):
# GET obstacles request
c = pycurl.Curl()
buffer = StringIO()
c.setopt(pycurl.URL, interop_api_url+'obstacles')
c.setopt(pycurl.WRITEDATA, buffer)
c.setopt(pycurl.COOKIEFILE, 'sessionid.txt')
c.perform()
obstacles_json = json.loads(buffer.getvalue())
print("\n\n" + "====Obstacles====")
obstacles = json.dumps(obstacles_json, sort_keys=True,indent=4, separators=(',', ': '))
print obstacles
self.obs.insert('end', obstacles)
def nextPic(self):
if(self.currentImage < len(self.targetpics) - 1):
示例3: TextEditor
# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import index [as 别名]
#.........这里部分代码省略.........
return float(similarity)/len(currentWord)<=.5,similarity
def cleanWord(self, word):
# cleans a word by removing all not (char or numbers)
processedWord = ""
for c in word:
if(c in string.ascii_uppercase or
c in string.ascii_lowercase or
c in "1234567890"):
processedWord += c
return processedWord
def sortSuggestionDict(self):
# sorts suggestion dictionary
self.suggestionDict = sorted(self.suggestionDict.items(),
key=operator.itemgetter(1))
def findMatchesToWord(self, currentWord):
# checks words in current text and adds them to suggestionDict
# based on whether they are similar or not
if(currentWord == ""): return []
listOfWords = self.currentText.split()
for word in listOfWords:
word = self.cleanWord(word)
if word!= currentWord[:-1]:
similar = self.wordsAreSimilar(currentWord, word)
if(similar[0] and word not in self.suggestionDict):
self.suggestionDict[word] = similar[1]
self.sortSuggestionDict
return self.suggestionDict
def getCurrentWord(self):
# gets current word user is typing
word = self.textWidget.get(self.textWidget.index("insert wordstart"),
self.textWidget.index("insert wordend"))
if(word == "\n" or word == " "):
word = self.textWidget.get(
self.textWidget.index("insert -1c wordstart"),
self.textWidget.index("insert wordend"))
word = word.replace("\n","")
return word
def openFile(self):
# opens a file, also detects whether it is
# a program or not
self.initProgrammingModeAttributes()
path = tkFileDialog.askopenfilename()
if(path):
self.currentFilePath = path
self.currentFile = os.path.basename(path)
self.currentText = TextEditor.readFile(path)
self.textWidget.delete(1.0,END)
self.textWidget.insert(1.0,self.currentText)
self.fileExtension = os.path.splitext(path)[1]
self.root.wm_title(self.currentFile)
if(self.fileExtension != ".txt" and
pygments.lexers.guess_lexer_for_filename(
"example%s"%self.fileExtension,[])):
self.programmingMode = True
self.lexer = pygments.lexers.guess_lexer_for_filename(
"example%s"%self.fileExtension,[])
self.highlightText()
def saveFile(self):
if(self.currentFilePath):
TextEditor.writeFile(self.currentFilePath, self.currentText)
示例4: __init__
# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import index [as 别名]
#.........这里部分代码省略.........
def goto_line(self):
lineno = tkSimpleDialog.askinteger('Textee', 'Goto line:')
if lineno > 0:
self.editor.mark_set(INSERT, lineno + 0.0) #convert to float
self.editor.see(INSERT)
self.editor.focus_set()
def toggle_theme(self):
if self.theme == 'light':
self.editor.config(bg='black', fg='white', insertbackground='white',highlightcolor='black')
self.editor.frame.config(bg='black')
# theme for misspelled words
self.editor.tag_configure("misspelled", foreground="red", underline=True)
self.theme = 'dark'
else:
self.editor.config(bg='white', fg='black', insertbackground='black',highlightcolor='white')
self.editor.frame.config(bg='white')
# theme for misspelled words
self.editor.tag_configure("misspelled", foreground="red", underline=True)
self.theme = 'light'
def toggle_wrap(self):
# self.editor.cget('wrap') # gets the config value
if not self.options.wrap.get():
self.editor.config(wrap='none')
else:
self.editor.config(wrap='word')
def find(self):
find_text = tkSimpleDialog.askstring("Textee", "Enter text to search", initialvalue=self.find_text)
if find_text:
if find_text == self.find_text:
start_pos = self.editor.search(find_text, self.editor.index('insert'), stopindex=END, nocase=True)
else:
start_pos = self.editor.search(find_text, '1.0', stopindex=END, nocase=True)
self.find_text = find_text
if(start_pos):
end_pos = '%s+%sc' % (start_pos, len(self.find_text))
self.editor.tag_add(SEL, start_pos, end_pos)
self.editor.mark_set(INSERT, end_pos) # mark the cursor to end of find text to start editing
self.editor.see(INSERT) # bing the cursor position in the viewport incase of long text causinng scrollbar
self.editor.focus_set() # strangely tkinter doesnt return focus after prompt
else:
tkMessageBox.showinfo("Textee", "No morw matches found")
else:
self.editor.focus_set() # strangely tkinter doesnt return focus after prompt
def find_and_replace(self):
#show the custom dialog
self.find_and_replace_dialog = TexteeFindAndReplaceDialog(self.master)
if self.find_and_replace_dialog.find_text:
start_pos = self.editor.search(self.find_and_replace_dialog.find_text, '1.0', stopindex=END, nocase=True)
# lazy recursive replace for all the matched elements, no need to parse whole dataset again and again
while start_pos:
self.editor.delete(start_pos, '%s+%sc' % (start_pos, len(self.find_and_replace_dialog.find_text)))
self.editor.insert(start_pos, self.find_and_replace_dialog.replace_with)
# break after first replace if replace all flag is off
if not self.find_and_replace_dialog.replace_all:
break
start_pos = self.editor.search(self.find_and_replace_dialog.find_text, '%s+%sc' % (start_pos, len(self.find_and_replace_dialog.replace_with)), stopindex=END, nocase=True)
def select_font(self):
self.font_dialog = TexteeFontDialog(self.master)