Hello all,
I have been doing some work on my HTML editor lately, and I have come to a (what seams like a) dead end.
The file its self is about 3.7kb smaller than my text editor, ProssesIT, and yet it fails to run any where near as smoothly.
When I open it up, my whole computer starts to lag, and there is a massive delay in when i type anything into it.
Then, when I type in "<" to see if its working, the whole thing crashes and I have to force quit the aplication.
This is not a result of having to many threads, because i looked up the python maximum thread limit on google, and it said that the maximum is 1021, while I only have 5 going at one time. (6 if you count the mainloop)
here is the code:
from Tkinter import *
import threading
import webbrowser
import random
import tkColorChooser as tcc
import tkFileDialog as tfd
import tkMessageBox as tmb
root = Tk()
root.title("htmIT")
text = Text(root, font=('Liberation Serif', 14))
casevar = IntVar()
class Find(threading.Thread): #thanks to www.java2s.com (HEAVALY MODIFIED)
def run(self):
variables.entryText = edit.get()
while True:
if edit.get() != variables.entryText:
text.tag_remove('found', '1.0', END)
variables.entryText = edit.get()
if variables.entryText:
idx = '1.0'
while True:
try:
idx = text.search(variables.entryText, idx, nocase=casevar.get(), stopindex=SEL_LAST)
except TclError:
idx = text.search(variables.entryText, idx, nocase=casevar.get(), stopindex=END)
if not idx: break
lastidx = '%s+%dc' % (idx, len(variables.entryText)) #
text.tag_add('found', idx, lastidx) #
idx = lastidx #
text.tag_config('found', background='#0000F0') #
class TagApply(threading.Thread):
def run(self):
while True:
try:
genTag()
text.tag_add(variables.tagList[variables.tagNum], variables.idx2, variables.lastidx2)
text.tag_config(variables.tagList[variables.tagNum], background='blue')
variables.tagNum += 1
except AttributeError:
pass
class AutoSave(threading.Thread):
def run(slef):
while True:
try:
variables.autoSave = text.get(1.0, END)
except:
break
class TagTo1(threading.Thread):
def run(self):
variables.tag1 = '<'
while True:
genTag()
if variables.tag1:
variables.idx2 = '1.0'
while True:
variables.idx2 = text.search(variables.tag1, variables.idx2, stopindex=END)
if not variables.idx2: break
variables.lastidx2 = '%s+%dc' % (variables.idx2, len(variables.idx2))
text.tag_add(variables.tagList[variables.tagNum], variables.idx2, variables.lastidx2)
variables.idx2 = variables.lastidx2
text.tag_config(variables.tagList[variables.tagNum], background='blue')
variables.tagNum += 1
class TagFrom1(threading.Thread):
def run(self):
variables.tag2 = '>'
while True:
genTag()
if variables.tag2:
variables.idx = '1.0'
while True:
variables.idx = text.search(variables.tag2, variables.idx, stopindex=END)
if not variables.idx: break
variables.lastidx = '%s+%dc' % (variables.idx, len(variables.idx))
text.tag_add(variables.tagList[variables.tagNum], variables.idx, variables.lastidx)
variables.idx = variables.lastidx
text.tag_config(variables.tagList[variables.tagNum], background='blue')
variables.tagNum += 1
class Variables:
pass
variables = Variables()
variables.autoSave = ''
variables.tagList = []
variables.tagNum = 0
def getNums():
h = text.get(1.0, END).split('\n')
#blue
for row in range(1, len(h)):
print 'HHHHH'
for column in range(1, len(h[row])):
if text.get('%s.%s' %(row, column-1), '%s.%s' %(row, column)) == '<':
print 1
variables.startPoint = '%s.%s' %(row, column)
elif text.get('%s.%s' %(row, column-1), '%s.%s' %(row, column)) == '>':
variables.endPoint = '%s.%s' %(row, column)
print 2
else:
print 3
variables.endPoint = 0.0
variables.startPoint = 0.0
def new():
if tmb.askyesno('Are you sure?', 'All unsaved work will be lost'):
text.delete(1.0, END)
def saveAsFile():
try:
tfd.asksaveasfile().write(text.get(1.0, END))
except AttributeError:
pass
variables.saved = text.get(1.0, END)
def openFile():
if tmb.askyesno('Are you sure?', 'All unsaved work will be lost'):
text.delete(1.0, END)
text.insert(END, tfd.askopenfile().read())
def afterQuit():
if variables.saved != variables.autoSave:
if not tmb.askyesno('You havent saved', 'Quit without saving?'):
tfd.asksaveasfile().write(variables.autoSave)
def genTag():
ns = ''
for x in range(6): #digits
ns += random.choice('a b c d e f g h i f k l m n o p q r s t u v w x y z'.split())
variables.tagList.append(ns)
def pexit():
if tmb.askyesno('Save?', 'Would you like to save before you exit?'):
saveAsFile()
root.destroy()
def showContact():
contact = Tk()
contact.title('Contact me')
Label(contact, text=' ').grid()
Label(contact, text='Please E-Mail me any feedback, or question you').grid()
Label(contact, text='may have, at this E-mail adress:').grid()
mail = Entry(contact, width=21)
mail.insert(END, 'itai_likes_pie@hotmail.com')
mail.grid()
Button(contact, text='Close', command=contact.destroy).grid()
Label (contact, text=' ').grid()
menu = Menu(root)
root.config(menu=menu)
filemenu = Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New", command=new)
filemenu.add_command(label="Open", command=openFile)
filemenu.add_command(label="Save As", command=saveAsFile)
filemenu.add_separator()
filemenu.add_command(label='Undo', command=text.edit_undo)
filemenu.add_command(label='Redo', command=text.edit_redo)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=pexit)
Label(root, text='Text to find:').grid(columnspan=2)
edit = Entry(root, bg='white', width=30)
edit.grid(row=0, column=1, columnspan=2)
case = Checkbutton(root, text='Case sensative off', variable=casevar)
case.grid(row=0, column=2, columnspan=2)
scrl = Scrollbar(root, command=text.yview, width=30)
text.config(yscrollcommand=scrl.set, bg='white', maxundo=100)
text.grid(columnspan=3)
scrl.grid(row=1, column=3, columnspan=1, sticky='ns')
TagFrom1().start()
TagTo1().start()
TagApply().start()
AutoSave().start()
Find().start()
root.mainloop()
pexit()
I was just wandering if any one knows why this is happening?
Thanks, The-IT