Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.88 KB | None | 0 0
  1. """ Sims 4 Backup Tool """
  2. from tkinter import *
  3. from tkinter import messagebox
  4. from distutils.dir_util import copy_tree
  5. import os
  6. import sys
  7. import shutil
  8. import datetime
  9.  
  10. #Create and name window
  11. root = Tk()
  12. root.title("Sims 4 Backup Tool")
  13.  
  14. #Title header
  15. title = Label(root, text="Sims 4 Backup Tool")
  16. title.pack()
  17.  
  18. pathToSimsFolder = os.path.expanduser("~\\Documents\\Electronic Arts\\The Sims 4\\")
  19.  
  20. #Get current date function
  21. def getDate():
  22.     date = datetime.date.today().strftime("%d-%m-%Y")
  23.     return date
  24.  
  25. #Check if folder exists
  26. def createFolder():
  27.     if os.path.exists(getDate()) == False:
  28.         os.mkdir(getDate())
  29.  
  30. #Create folder function
  31. def createSubFolder(name):
  32.     if os.path.exists(str(getDate())+"/"+name):
  33.         shutil.rmtree(str(getDate())+"/"+name)
  34.        
  35.     os.mkdir(str(getDate())+"/"+name)
  36.  
  37. #Backup Selection function
  38. def backupSelection():
  39.     """
  40.     This function is called when the 'Backup Selection' button is pressed.
  41.     It decides which boxes are ticked and runs their corrosponding function.
  42.     """
  43.    
  44.     createFolder()
  45.    
  46.     if savesSelected.get() == 1:
  47.         backupSaves()
  48.    
  49.     if modsSelected.get() == 1:
  50.         backupMods()
  51.    
  52.     if traySelected.get() == 1:
  53.         backupTray()
  54.        
  55.     if screenshotsSelected.get() == 1:
  56.         backupScreenshots()
  57.    
  58.     if videosSelected.get() == 1:
  59.         backupVideos()
  60.        
  61.     if musicSelected.get() == 1:
  62.         backupMusic()
  63.    
  64.     if savesSelected.get() == 0 and modsSelected.get() == 0 and traySelected.get() == 0 and videosSelected.get() == 0 and screenshotsSelected.get() == 0 and musicSelected.get() == 0:
  65.         messagebox.showerror("Error", "Please select at least one option!")
  66.  
  67. #Alert function
  68. def alert():
  69.     """
  70.     This function is called when a checkbox is ticked.
  71.     It returns a list of the current status of all five checkboxes to the console.
  72.     """
  73.     print("Saves: %s\nMods: %s\nTray: %s\nScreenshots: %s\nVideos: %s\n" % (savesSelected.get(), modsSelected.get(), traySelected.get(), screenshotsSelected.get(), videosSelected.get()))
  74.  
  75. #Backup Saves function
  76. def backupSaves():
  77.     print("Backing up Saves!")
  78.     createSubFolder("saves")
  79.     try:
  80.         copy_tree(pathToSimsFolder+"saves", getDate()+"\\saves")
  81.     except:
  82.         messagebox.showerror("Error", "Unable to copy saves file!")
  83.    
  84.    
  85. #Backup Mods function
  86. def backupMods():
  87.     print("Backing up Mods!")
  88.     createSubFolder("Mods")
  89.     try:
  90.         copy_tree(pathToSimsFolder+"Mods", getDate()+"\\Mods")
  91.     except:
  92.         messagebox.showerror("Error", "Unable to copy mods file!")
  93.    
  94. #Backup Tray function
  95. def backupTray():
  96.     print("Backing up Tray!")
  97.     createSubFolder("Tray")
  98.     try:
  99.         copy_tree(pathToSimsFolder+"Tray", getDate()+"\\Tray")
  100.     except:
  101.         messagebox.showerror("Error", "Unable to copy tray file!")
  102.    
  103. #Backup Screenshots function
  104. def backupScreenshots():
  105.     print("Backing up Screenshots!")
  106.     createSubFolder("screenshots")
  107.     try:
  108.         copy_tree(pathToSimsFolder+"Screenshots", getDate()+"\\Screenshots")
  109.     except:
  110.         messagebox.showerror("Error", "Unable to copy screenshots file!")
  111.    
  112. #Backup Videos function
  113. def backupVideos():
  114.     print("Backing up Videos!")
  115.     createSubFolder("Recorded Videos")
  116.     try:
  117.         copy_tree(pathToSimsFolder+"Recorded Videos", getDate()+"\\Recorded Videos")
  118.     except:
  119.         messagebox.showerror("Error", "Unable to copy videos file!")   
  120.  
  121. #Backup Music function
  122. def backupMusic():
  123.     print("Backing up Custom Music!")
  124.     createSubFolder("Custom Music")
  125.     try:
  126.         copy_tree(pathToSimsFolder+"Custom Music", getDate()+"\\Custom Music")
  127.     except:
  128.         messagebox.showerror("Error", "Unable to copy custom music file!") 
  129.  
  130. #Tickbox variables
  131. savesSelected       = IntVar()
  132. modsSelected        = IntVar()
  133. traySelected        = IntVar()
  134. screenshotsSelected = IntVar()
  135. videosSelected      = IntVar()
  136. musicSelected       = IntVar()
  137.  
  138. #Frame to contain options
  139. optionFrame = Frame(root)
  140. optionFrame.pack()
  141.  
  142. #Saves Option
  143. savesOptionCheck = Checkbutton(optionFrame, text = "Saves", variable = savesSelected, command = alert)
  144. savesOptionCheck.grid(column=0, row=0)
  145.  
  146. #Mods Option
  147. modsOptionCheck = Checkbutton(optionFrame, text = "Mods", variable = modsSelected, command = alert)
  148. modsOptionCheck.grid(column=0, row=1)
  149.  
  150. #Tray Option
  151. trayOptionCheck = Checkbutton(optionFrame, text = "Tray", variable = traySelected, command = alert)
  152. trayOptionCheck.grid(column=0, row=2)
  153.  
  154. #Screenshots Option
  155. screenshotsOptionCheck  = Checkbutton(optionFrame, text = "Screenshots", variable = screenshotsSelected, command = alert)
  156. screenshotsOptionCheck.grid(column=0, row=3)
  157.  
  158. #Videos Option
  159. videosOptionCheck   = Checkbutton(optionFrame, text = "Videos", variable = videosSelected, command = alert)
  160. videosOptionCheck.grid(column=0, row=4)
  161.  
  162. #Music Option
  163. musicOptionCheck    = Checkbutton(optionFrame, text = "Custom Music", variable = musicSelected, command = alert)
  164. musicOptionCheck.grid(column=0, row=5)
  165.  
  166. #Backup Button
  167. backupButton = Button(text="Backup Selection", command=backupSelection)
  168. backupButton.pack()
  169.  
  170. #Run GUI
  171. root.mainloop()
  172. """
  173. I love you Hazel!! xx
  174. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement