Advertisement
Guest User

Untitled

a guest
Nov 25th, 2016
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.76 KB | None | 0 0
  1. import sys shutil,os,time
  2. from os.path import expanduser
  3. import app_interface as mainApp #Program main window
  4. import tkinter as tk
  5. import tkinter.constants as constants
  6. import tkinter.filedialog as filediag
  7. from tkinter.scrolledtext import ScrolledText
  8.  
  9. version='1.0.0'
  10.  
  11.  
  12. # Subclass ScrolledText
  13. class ScrolledTextOut(ScrolledText):
  14.  
  15.     def write(self, s):
  16.         self.insert(tk.CURRENT, s)
  17.         self.see(tk.END)
  18.  
  19.     def flush(self):
  20.         pass
  21.  
  22.  
  23. class App():
  24.    
  25.     def __init__(self):
  26.         self.root = tk.Tk()
  27.         self.root.wm_title("Folder Sort")
  28.         global version
  29.         button_opt = {'fill': constants.BOTH, 'padx': 15, 'pady': 15}
  30.         # Text
  31.         self.l1 = tk.Label(self.root,text="Folder Sort",font=("Helvetica", 16))
  32.         self.l1.pack(**button_opt)
  33.         self.l2 = tk.Label(self.root,text="Version "+version,font=("Helvetica", 12))
  34.         self.l2.pack(**button_opt)
  35.         # Browse Button
  36.         self.browse=tk.Button(self.root, text='Select Directory', command=self.askdirectory)
  37.         self.browse.pack(**button_opt)
  38.         # Browse Button options
  39.         self.dir_opt = options = {}
  40.         options['initialdir'] = 'C:\\'
  41.         options['mustexist'] = False
  42.         options['parent'] = self.root
  43.         options['title'] = 'Select Directory to Sort'
  44.         #Quit Button
  45.         self.button = tk.Button(self.root, text = 'Close', command=self.quit)
  46.         self.button.pack(**button_opt)
  47.  
  48.         # Text Widget
  49.         self.txt = ScrolledTextOut(self.root, undo=True)
  50.         self.txt['font'] = ('consolas', '12')
  51.         self.txt.pack(**button_opt)
  52.         self.txt.insert(tk.INSERT, "Welcome to Folder Sort Version %s\nSelect a directory to Proceed...\n"%version)
  53.         #Disable scrolledtext
  54.         self.txt.configure(state='disabled')
  55.         #expand=False, fill='both'
  56.         #Start the frame
  57.         self.root.mainloop()
  58.  
  59.     #Quit Application
  60.     def quit(self):
  61.         self.root.destroy()
  62.         mainApp.main()
  63.  
  64.    #Directory Button Function
  65.     def askdirectory(self): #open the file  
  66.         directory = filediag.askdirectory()
  67.         self.FolderSort(directory)
  68.  
  69.    #Folder Sort Program
  70.     def FolderSort(self,path):
  71.         #Redirect all print statements to GUI
  72.         sys.stdout = self.txt
  73.         #Reenable scrolledtext
  74.         self.txt.configure(state='normal')
  75.  
  76.         #MAIN CODE WITH LOTS OF PRINT STATEMENTS
  77.  
  78.         #Sorting is done, show success message
  79.         print("\nSorting Complete.")
  80.         print("Sorted",sortedfiles,"files in",elapsed,"seconds.")
  81.         #Now that processing is done, disable scrolledtext again
  82.         self.txt.configure(state='disabled')
  83.         #END OF FOLDER SORT FUNCTION
  84.  
  85.  
  86. #Call the app
  87. if __name__ == '__main__':
  88.     app = App()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement