Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys shutil,os,time
- from os.path import expanduser
- import app_interface as mainApp #Program main window
- import tkinter as tk
- import tkinter.constants as constants
- import tkinter.filedialog as filediag
- from tkinter.scrolledtext import ScrolledText
- version='1.0.0'
- # Subclass ScrolledText
- class ScrolledTextOut(ScrolledText):
- def write(self, s):
- self.insert(tk.CURRENT, s)
- self.see(tk.END)
- def flush(self):
- pass
- class App():
- def __init__(self):
- self.root = tk.Tk()
- self.root.wm_title("Folder Sort")
- global version
- button_opt = {'fill': constants.BOTH, 'padx': 15, 'pady': 15}
- # Text
- self.l1 = tk.Label(self.root,text="Folder Sort",font=("Helvetica", 16))
- self.l1.pack(**button_opt)
- self.l2 = tk.Label(self.root,text="Version "+version,font=("Helvetica", 12))
- self.l2.pack(**button_opt)
- # Browse Button
- self.browse=tk.Button(self.root, text='Select Directory', command=self.askdirectory)
- self.browse.pack(**button_opt)
- # Browse Button options
- self.dir_opt = options = {}
- options['initialdir'] = 'C:\\'
- options['mustexist'] = False
- options['parent'] = self.root
- options['title'] = 'Select Directory to Sort'
- #Quit Button
- self.button = tk.Button(self.root, text = 'Close', command=self.quit)
- self.button.pack(**button_opt)
- # Text Widget
- self.txt = ScrolledTextOut(self.root, undo=True)
- self.txt['font'] = ('consolas', '12')
- self.txt.pack(**button_opt)
- self.txt.insert(tk.INSERT, "Welcome to Folder Sort Version %s\nSelect a directory to Proceed...\n"%version)
- #Disable scrolledtext
- self.txt.configure(state='disabled')
- #expand=False, fill='both'
- #Start the frame
- self.root.mainloop()
- #Quit Application
- def quit(self):
- self.root.destroy()
- mainApp.main()
- #Directory Button Function
- def askdirectory(self): #open the file
- directory = filediag.askdirectory()
- self.FolderSort(directory)
- #Folder Sort Program
- def FolderSort(self,path):
- #Redirect all print statements to GUI
- sys.stdout = self.txt
- #Reenable scrolledtext
- self.txt.configure(state='normal')
- #MAIN CODE WITH LOTS OF PRINT STATEMENTS
- #Sorting is done, show success message
- print("\nSorting Complete.")
- print("Sorted",sortedfiles,"files in",elapsed,"seconds.")
- #Now that processing is done, disable scrolledtext again
- self.txt.configure(state='disabled')
- #END OF FOLDER SORT FUNCTION
- #Call the app
- if __name__ == '__main__':
- app = App()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement