Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
added a source and destination button
  • Loading branch information
KoukatsuMahoutsukai committed Jun 13, 2023
1 parent 84174a7 commit fa22c14
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,24 @@ def __init__(self, master):
self.master = master
master.title("Kenshi WorkshopMod Folders Renamer")

self.select_button = tk.Button(master, text="Select Folder", command=self.select_folder, padx=10, pady=5)
self.select_button.place(relx=0.5, rely=0.4, anchor="center")
self.folder_path = None
self.destination_path = None

self.select_button = tk.Button(master, text="Select Source Folder", command=self.select_folder, padx=10, pady=5)
self.select_button.place(relx=0.5, rely=0.32, anchor="center")

self.destination_button = tk.Button(master, text="Select Destination Folder", command=self.select_destination, padx=10, pady=5)
self.destination_button.place(relx=0.5, rely=0.64, anchor="center")

self.var1 = tk.IntVar()
self.c1 = tk.Checkbutton(master, text='Destination same as source',variable=self.var1, onvalue=1, offvalue=0, command=self.on_checkbutton_change)
self.c1.place(relx=0.5, rely=0.48, anchor="center")

self.run_button = tk.Button(master, text="Run", command=self.run_script, padx=10, pady=5)
self.run_button.place(relx=0.4, rely=0.82, anchor="center")

self.quit_button = tk.Button(master, text="Quit", command=master.quit, padx=10, pady=5)
self.quit_button.place(relx=0.5, rely=0.7, anchor="center")
self.quit_button.place(relx=0.6, rely=0.82, anchor="center")

self.link_label = tk.Label(self.master, text="Concept Art by Sergey Musin", fg="blue", cursor="hand2")
self.link_label.pack(side="bottom", anchor="se", padx=0, pady=0)
Expand All @@ -25,15 +38,27 @@ def __init__(self, master):

# messagebox.showinfo("Warning", "Dont run the Renamer on the steam workshop folder directly!")

def on_checkbutton_change(self):
if self.var1.get() == 1:
self.destination_button.config(state=tk.DISABLED)
else:
self.destination_button.config(state=tk.NORMAL)

def select_folder(self):
self.folder_path = filedialog.askdirectory()
self.run_script()

def select_destination(self):
self.destination_path = filedialog.askdirectory()

def run_script(self):
forbidden = ['system32', '233860']
skipped_folders = []
renamed_folders = []
scroll_box = scrolledtext.ScrolledText(width=30, height=10)
if self.folder_path is None:
messagebox.showinfo("Error 404", "No folder selected")
if (self.destination_path is None) or (self.var1.get() == 1):
self.destination_path = self.folder_path

for folder_name in os.listdir(self.folder_path):
folder_path = os.path.join(self.folder_path, folder_name)
Expand All @@ -59,7 +84,8 @@ def run_script(self):
# Create new folder then Move all files to the new folder
mod_file_name = mod_files[0]
new_folder_name = mod_file_name.rsplit('.mod', 1)[0]
new_folder_path = os.path.join(self.folder_path, new_folder_name)
###!!!!!!!!!!!!
new_folder_path = os.path.join(self.destination_path, new_folder_name)
if os.path.exists(new_folder_path):
skipped_folders.append(folder_name + " (folder exists)")
continue
Expand Down

0 comments on commit fa22c14

Please sign in to comment.