Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 43 additions & 13 deletions Editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from tkSimpleDialog import *
from tkFileDialog import *
from tkMessageBox import *

class QuitMe(Frame):
def __init__(self, parent=None):
Frame.__init__(self, parent)
Expand Down Expand Up @@ -49,10 +48,16 @@ def __init__(self, parent=None, file=None):
Button(frm, text='Paste', command=self.onPaste).pack(side=LEFT)
Button(frm, text='Find', command=self.onFind).pack(side=LEFT)
QuitMe(frm).pack(side=LEFT)
Button(frm, text='+', command=self.up).pack(side=LEFT)
Button(frm, text='-', command=self.down).pack(side=LEFT)
ScrolledText.__init__(self, parent, file=file)
self.text.config(font=('courier', 9, 'normal'))
self.text.config(font=('consolas', 14, 'normal'))
def onSave(self):
filename = asksaveasfilename()
self.file_opt = options = {}
options['filetypes'] = [('text files', '.txt'), ('all files', '.*')]
options['initialfile'] = 'textfile.txt'
options['parent'] = root
filename = asksaveasfilename(**self.file_opt)
if filename:
alltext = self.gettext()
open(filename, 'w').write(alltext)
Expand All @@ -61,27 +66,52 @@ def onCut(self):
self.text.delete(SEL_FIRST, SEL_LAST)
self.clipboard_clear()
self.clipboard_append(text)
def up(self):
size2 = self.text.config()["font"][4].split(" ")
size = int(size2[1])
self.text.config(font=('consolas', size + 1, 'normal'))
def down(self):
dsize2 = self.text.config()["font"][4].split(" ")
dsize = int(dsize2[1])
self.text.config(font=('consolas', dsize - 1, 'normal'))
def onPaste(self):
try:
text = self.selection_get(selection='CLIPBOARD')
self.text.insert(INSERT, text)
except TclError:
pass
def onFind(self):
target = askstring('SimpleEditor', 'Search String?')
print "1"
target = askstring('Find', 'Find: ')
if target:
print "2"
where = self.text.search(target, INSERT, END)
if where:
print where
pastit = where + ('+%dc' % len(target))
#self.text.tag_remove(SEL, '1.0', END)
self.text.tag_add(SEL, where, pastit)
self.text.mark_set(INSERT, pastit)
self.text.see(INSERT)
self.text.focus()
#if where:
print "3"
print where
pastit = where + ('+%dc' % len(target))
self.text.tag_remove(SEL, '1.0', END)
self.text.tag_add(SEL, where, pastit)
self.text.mark_set(INSERT, pastit)
self.text.see(INSERT)
self.text.focus()

#if there are no cmdline arguments, open a new file.
#if there are no cmdline arguments, open a new file.
if len(sys.argv) > 1:
root = Tk()
root.attributes('-zoomed', True)
#root.iconbitmap("main.gif")
root.resizable(0, 0)
root.title("Text Editor")
img = Image("photo", file="main.gif")
root.tk.call('wm','iconphoto',root._w,img)
SimpleEditor(file=sys.argv[1]).mainloop()
else:
root = Tk()
root.attributes('-zoomed', True)
#root.iconbitmap("main.gif")
root.resizable(0, 0)
root.title("Text Editor")
img = Image("photo", file="main.gif")
root.tk.call('wm','iconphoto',root._w,img)
SimpleEditor().mainloop()