Skip to content

Instantly share code, notes, and snippets.

@jamesadney
Created September 16, 2011 00:42
Show Gist options
  • Save jamesadney/1220895 to your computer and use it in GitHub Desktop.
Save jamesadney/1220895 to your computer and use it in GitHub Desktop.
Simple tkinter script to open file and convert line endings to Windows style (CRLF)
#!/usr/bin/python
import os
#TODO: What happens if script is imported as module?
WORKING_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
from Tkinter import *
import tkFileDialog
class Application(Frame):
def _fix_file(self, filename):
f = open(filename, 'rU')
t = f.read()
t = t.replace('\n', '\r\n')
f.close()
f = open(filename, 'w')
print repr(t)
f.write(t)
f.close()
def add_files(self):
files = tkFileDialog.askopenfilenames(initialdir=WORKING_DIRECTORY)
fixed = []
for f in files:
self._fix_file(f)
fixed.append(f)
label = Label(self, text=('\n'.join(fixed)))
label.pack(fill=X, expand=1)
def __init__(self, master=None):
Frame.__init__(self, master)
master.title('eSIS to EasyGradePro')
self['relief'] = RIDGE
self['borderwidth'] = 2
self.pack(fill=BOTH,expand=1)
header = Label(self, text=('Fixed Files:\n\n'))
header.pack()
add_files_btn = Button(main,
text='Fix more files',
command=self.add_files)
add_files_btn.pack({'side' : 'left'})
close_btn = Button(main, text='Close', command=self.quit)
close_btn.pack({'side' : 'right'})
self.add_files()
if __name__ == '__main__':
main = Tk()
app = Application(master=main)
app.mainloop()
main.destroy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment