From 230866953cf01715f5850a6b9c368cfca8e11bc8 Mon Sep 17 00:00:00 2001 From: niefia <99533148+niefia@users.noreply.github.com> Date: Sat, 4 Mar 2023 10:17:53 +0000 Subject: [PATCH] Added GUI Added Completely reworked GUI Split the main function into multiple so progress bar can be updated between functions easier Changed error reporting so that try is run for functions instead of inside the function, also results in popup box. --- BFS.py | 2 +- generate.py | 507 ++++++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 65 +++++-- uictk.py | 196 ++++++++++++++++++++ 4 files changed, 754 insertions(+), 16 deletions(-) create mode 100644 generate.py create mode 100644 uictk.py diff --git a/BFS.py b/BFS.py index 4c3ac70..8aa95a7 100644 --- a/BFS.py +++ b/BFS.py @@ -65,7 +65,7 @@ def bfs_distance(combined_data_file, cells_data_file, output_file): percent_done = int(progress_bar_length * progress / 100) percent_left = progress_bar_length - percent_done progress_bar = "[" + "#" * percent_done + " " * percent_left + "]" - print(f"\r{progress_bar} {progress}%", end='', flush=True) + #print(f"\r{progress_bar} {progress}%", end='', flush=True) # Create a DataFrame to store the results output_data = pd.DataFrame(list(cost_so_far.items()), columns=["id", "distance"]) diff --git a/generate.py b/generate.py new file mode 100644 index 0000000..6e6b4d1 --- /dev/null +++ b/generate.py @@ -0,0 +1,507 @@ +import bookmark +import religion +import spreadsheets +import rasterMaps +import BFS +import os +import modFiles +import culture +import sys +import character +import localization +import openpyxl +import pandas as pd +import xlwt +import hextorgb +import modFiles + + +def runGenUI(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir): + try: + + #SET DIRECTORY VARIABLESself.chargen_combobox.get() + + # set gamedir to be the game subfolder of installdir + #gamedir = os.path.join(installdir, 'game') + + #output_dir = os.path.join(modpath,modname) + + print(gamedir) + print(output_dir) + # Create output directory if it doesn't exist + + if not os.path.exists(output_dir): + os.makedirs(output_dir) + + modFiles.modFile(modname, output_dir, modpath) + + + #CREATES DIRECTORIES + + # Create "map_data" subfolder + map_data_dir = os.path.join(output_dir, "map_data") + if not os.path.exists(map_data_dir): + os.makedirs(map_data_dir) + + # Create "map_data" subfolder + map_data_dir = os.path.join(output_dir, "_mapFiller") + if not os.path.exists(map_data_dir): + os.makedirs(map_data_dir) + + # Create "gfx/map/terrain/" subfolder + map_data_dir = os.path.join(output_dir, "gfx/map/terrain/") + if not os.path.exists(map_data_dir): + os.makedirs(map_data_dir) + + # Create "gfx/map/terrain/" subfolder + map_data_dir = os.path.join(output_dir, "gfx/map/terrain/") + if not os.path.exists(map_data_dir): + os.makedirs(map_data_dir) + + + #RUN SPREADSHEET GENERATORS + + # Remove emoji from JSON file + spreadsheets.remove_emoji_from_json(os.path.join(modpath, "input.json"), + os.path.join(output_dir, "noemoji.json")) + print("Emoji data removed from json") + + + # Assign colors to Baronies in GeoJSON file + spreadsheets.colorRandom(os.path.join(modpath, "input.geojson"), os.path.join(output_dir, "output.geojson")) + print("Colors Assigned to Baronies for Cells method") + + # Convert JSON to Excel spreadsheet + spreadsheets.json_to_sheet(os.path.join(output_dir, "noemoji.json"), os.path.join(output_dir, "combined_data.xlsx")) + print("Json extracted") + + # Convert GeoJSON to Excel spreadsheet + spreadsheets.cells_geojson_to_sheet(os.path.join(output_dir, "output.geojson"), + os.path.join(output_dir, "cellsData.xlsx")) + print("Geojson extracted") + + # Correct cell names in Excel spreadsheet + spreadsheets.nameCorrector(os.path.join(output_dir, "cellsData.xlsx"), + os.path.join(output_dir, "combined_data.xlsx"), + os.path.join(output_dir, "updated_file.xlsx")) + print("Geojson data updated with Json names") + + # Generate ProvinceDef.xlsx file for Cells + spreadsheets.provinceDefCells(os.path.join(output_dir, "updated_file.xlsx"), + os.path.join(output_dir, "_mapFiller/provinceDef.xlsx")) + print("Generate ProvinceDef.xlsx file for Cells") + + #DATA TO RASTERIZED IMAGE + + + #heightmap scaling methods + if scaling_method == 1: + rasterMaps.heightmap(os.path.join(output_dir, "output.geojson"), + os.path.join(output_dir, "map_data", "heightmap.png"), scaling_factor) + print("Generating Heightmap") + elif scaling_method == 2: + rasterMaps.heightmapAutoScaledfunc(os.path.join(output_dir, "output.geojson"), + os.path.join(output_dir, "map_data", "heightmap.png")) + print("Generating Auto-Scaled Heightmap") + else: + print("Invalid scaling method") + + + + + + # Generate provinces image + rasterMaps.provincesCells(os.path.join(output_dir, "output.geojson"), + os.path.join(output_dir, "map_data", "provinces.png"), scaling_factor) + print("Generating Cells provinces") + + + + # Generate biomes images + + if scaling_method == 1: + rasterMaps.biomes(os.path.join(output_dir, "output.geojson"), os.path.join(output_dir, "gfx", "map", "terrain"), + scaling_factor) + print("Generated Biomes") + elif scaling_method == 2: + rasterMaps.biomesAutoScaled(os.path.join(output_dir, "output.geojson"), + os.path.join(output_dir, "gfx", "map", "terrain")) + print("Generated Auto-Scaled Biomes") + else: + print("Invalid scaling method") + + + + + + + + + #Rename biome files to CK3 texture names using the json data + modFiles.biomeWrite(os.path.join(output_dir, 'noemoji.json'), + os.path.join(output_dir, 'biomes.xlsx'), + os.path.join(output_dir, 'gfx/map/terrain')) + + + input_zip_file = os.path.join(modpath, "tcs.zip") + # Call the extract_zip_file function + modFiles.extract_zip_file(input_zip_file, output_dir) + + + + #Runs Religion Generator + + religion.familyGen(os.path.join(output_dir, "combined_data.xlsx"),os.path.join(output_dir, "common/religion/religion_families")) + religion.religionChildren(os.path.join(output_dir, "combined_data.xlsx"), + os.path.join(output_dir, "religionChildren.xlsx")) + religion.relGenChil(os.path.join(output_dir, "religionChildren.xlsx"), + os.path.join(output_dir, "religionChildren_cName.xlsx")) + religion.religionGen(os.path.join(output_dir, "religionChildren_cName.xlsx"), + os.path.join(output_dir, "common/religion/religions")) + + #Runs Culture Generator + + culture.heritage_gen(os.path.join(output_dir, 'combined_data.xlsx'), os.path.join(output_dir, 'common/culture/pillars')) + + culture.culture_gen(os.path.join(output_dir, "combined_data.xlsx"),os.path.join(output_dir, 'common/culture/cultures')) + + + #BFS Functions + print("Breadth First search started, this generates Baronies from cells and may take some time to run") + # Run Breadth First search to generate Baronies + BFS.bfs_distance(os.path.join(output_dir, "combined_data.xlsx"), os.path.join(output_dir, "cellsData.xlsx"), + os.path.join(output_dir, "BFSoutput.xlsx")) + print("") + print("Breadth First search Complete") + + # Assign unique color to Baronies + BFS.colorRandomBFS(os.path.join(output_dir, "BFSoutput.xlsx")) + print("Assigning unique color to Baronies") + + + + + if scaling_method == 1: + # Generate BFS provinces image + BFS.provinceMapBFS(os.path.join(output_dir, "BFSoutput.xlsx"), scaling_factor, + os.path.join(output_dir, "map_data", "provinces.png")) + print("Generating BFS provinces") + elif scaling_method == 2: + rasterMaps.provinceMapBFSAutoScaled(os.path.join(output_dir, "BFSoutput.xlsx"), + os.path.join(output_dir, "map_data", "provinces.png")) + + + + + + + + + #BFSProvDef + + BFS.extractBFS(os.path.join(output_dir, "BFSoutput.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xlsx")) + + BFS.BaronyId(os.path.join(output_dir, "combined_data.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xlsx")) + BFS.ProvData(os.path.join(output_dir,"updated_file.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xlsx")) + BFS.cOrder(os.path.join(output_dir,"_mapFiller/provinceDef.xlsx")) + BFS.finalorder(os.path.join(output_dir,"_mapFiller/provinceDef.xlsx")) + BFS.convert_xlsx_to_xls(os.path.join(output_dir, "_mapFiller/provinceDef.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xls")) + + # Get output directory path from user input + print("Automatic Map Filler Running") + config_file_path = os.path.join(mapfilldir, "config.properties") + print(config_file_path) + moddir = output_dir + + modFiles.modify_config(moddir, gamedir, config_file_path) + + jar_path = os.path.join(mapfilldir, "CK3Tools.jar") + cwd = mapfilldir + modFiles.run_jar(jar_path, cwd) + + localization.religionLoc(output_dir) + + + if CharGen_response.lower() == "yes": + print("Character Generation running:") + character.rulerGenXL(os.path.join(output_dir, "combined_data.xlsx"),os.path.join(output_dir, "characters.xlsx")) + character.rulerWrite(os.path.join(output_dir, "characters.xlsx"),os.path.join(output_dir, "history/characters/")) + character.modHistory(os.path.join(output_dir, "characters.xlsx"),os.path.join(output_dir, "history/titles/")) + bookmark.bm_groups(output_dir) + bookmark.bm_generator(output_dir, 3) + + + elif CharGen_response.lower() == "no": + print("Shattered World Mode.") + else: + print("Invalid response. Please enter 'yes' or 'no'.") + + + + + + except Exception as e: + print(f"An error occurred: {e}") + # Wait for user input before closing + input("Press Enter to exit...") + sys.exit(1) # exit with an error code + + + + + +def runGenExcel(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir): + + + if not os.path.exists(output_dir): + os.makedirs(output_dir) + + modFiles.modFile(modname, output_dir, modpath) + #CREATES DIRECTORIES + + # Create "map_data" subfolder + map_data_dir = os.path.join(output_dir, "map_data") + if not os.path.exists(map_data_dir): + os.makedirs(map_data_dir) + + # Create "map_data" subfolder + map_data_dir = os.path.join(output_dir, "_mapFiller") + if not os.path.exists(map_data_dir): + os.makedirs(map_data_dir) + + # Create "gfx/map/terrain/" subfolder + map_data_dir = os.path.join(output_dir, "gfx/map/terrain/") + if not os.path.exists(map_data_dir): + os.makedirs(map_data_dir) + + # Create "gfx/map/terrain/" subfolder + map_data_dir = os.path.join(output_dir, "gfx/map/terrain/") + if not os.path.exists(map_data_dir): + os.makedirs(map_data_dir) + + + #RUN SPREADSHEET GENERATORS + + # Remove emoji from JSON file + spreadsheets.remove_emoji_from_json(os.path.join(modpath, "input.json"), + os.path.join(output_dir, "noemoji.json")) + print("Emoji data removed from json") + + + # Assign colors to Baronies in GeoJSON file + spreadsheets.colorRandom(os.path.join(modpath, "input.geojson"), os.path.join(output_dir, "output.geojson")) + print("Colors Assigned to Baronies for Cells method") + + # Convert JSON to Excel spreadsheet + spreadsheets.json_to_sheet(os.path.join(output_dir, "noemoji.json"), os.path.join(output_dir, "combined_data.xlsx")) + print("Json extracted") + + # Convert GeoJSON to Excel spreadsheet + spreadsheets.cells_geojson_to_sheet(os.path.join(output_dir, "output.geojson"), + os.path.join(output_dir, "cellsData.xlsx")) + print("Geojson extracted") + + # Correct cell names in Excel spreadsheet + spreadsheets.nameCorrector(os.path.join(output_dir, "cellsData.xlsx"), + os.path.join(output_dir, "combined_data.xlsx"), + os.path.join(output_dir, "updated_file.xlsx")) + print("Geojson data updated with Json names") + + # Generate ProvinceDef.xlsx file for Cells + spreadsheets.provinceDefCells(os.path.join(output_dir, "updated_file.xlsx"), + os.path.join(output_dir, "_mapFiller/provinceDef.xlsx")) + print("Generate ProvinceDef.xlsx file for Cells") + + + + + + +def runGenRaster(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir): + + + #DATA TO RASTERIZED IMAGE + + + #heightmap scaling methods + if scaling_method == 1: + rasterMaps.heightmap(os.path.join(output_dir, "output.geojson"), + os.path.join(output_dir, "map_data", "heightmap.png"), scaling_factor) + print("Generating Heightmap") + elif scaling_method == 2: + rasterMaps.heightmapAutoScaledfunc(os.path.join(output_dir, "output.geojson"), + os.path.join(output_dir, "map_data", "heightmap.png")) + print("Generating Auto-Scaled Heightmap") + else: + print("Invalid scaling method") + + + # Generate provinces image + rasterMaps.provincesCells(os.path.join(output_dir, "output.geojson"), + os.path.join(output_dir, "map_data", "provinces.png"), scaling_factor) + print("Generating Cells provinces") + + + + # Generate biomes images + + if scaling_method == 1: + rasterMaps.biomes(os.path.join(output_dir, "output.geojson"), os.path.join(output_dir, "gfx", "map", "terrain"), + scaling_factor) + print("Generated Biomes") + elif scaling_method == 2: + rasterMaps.biomesAutoScaled(os.path.join(output_dir, "output.geojson"), + os.path.join(output_dir, "gfx", "map", "terrain")) + print("Generated Auto-Scaled Biomes") + else: + print("Invalid scaling method") + + + #Rename biome files to CK3 texture names using the json data + modFiles.biomeWrite(os.path.join(output_dir, 'noemoji.json'), + os.path.join(output_dir, 'biomes.xlsx'), + os.path.join(output_dir, 'gfx/map/terrain')) + + + input_zip_file = os.path.join(modpath, "tcs.zip") + # Call the extract_zip_file function + modFiles.extract_zip_file(input_zip_file, output_dir) + + + + + +def runGenRelCult(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir): + + + + input_zip_file = os.path.join(modpath, "tcs.zip") + # Call the extract_zip_file function + modFiles.extract_zip_file(input_zip_file, output_dir) + + + + #Runs Religion Generator + + religion.familyGen(os.path.join(output_dir, "combined_data.xlsx"),os.path.join(output_dir, "common/religion/religion_families")) + religion.religionChildren(os.path.join(output_dir, "combined_data.xlsx"), + os.path.join(output_dir, "religionChildren.xlsx")) + religion.relGenChil(os.path.join(output_dir, "religionChildren.xlsx"), + os.path.join(output_dir, "religionChildren_cName.xlsx")) + religion.religionGen(os.path.join(output_dir, "religionChildren_cName.xlsx"), + os.path.join(output_dir, "common/religion/religions")) + + #Runs Culture Generator + + culture.heritage_gen(os.path.join(output_dir, 'combined_data.xlsx'), os.path.join(output_dir, 'common/culture/pillars')) + + culture.culture_gen(os.path.join(output_dir, "combined_data.xlsx"),os.path.join(output_dir, 'common/culture/cultures')) + + + + + + + +def runGenBFS(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir): + + + #BFS Functions + print("Breadth First search started, this generates Baronies from cells and may take some time to run") + # Run Breadth First search to generate Baronies + BFS.bfs_distance(os.path.join(output_dir, "combined_data.xlsx"), os.path.join(output_dir, "cellsData.xlsx"), + os.path.join(output_dir, "BFSoutput.xlsx")) + print("") + print("Breadth First search Complete") + + # Assign unique color to Baronies + BFS.colorRandomBFS(os.path.join(output_dir, "BFSoutput.xlsx")) + print("Assigning unique color to Baronies") + + + if scaling_method == 1: + # Generate BFS provinces image + BFS.provinceMapBFS(os.path.join(output_dir, "BFSoutput.xlsx"), scaling_factor, + os.path.join(output_dir, "map_data", "provinces.png")) + print("Generating BFS provinces") + elif scaling_method == 2: + rasterMaps.provinceMapBFSAutoScaled(os.path.join(output_dir, "BFSoutput.xlsx"), + os.path.join(output_dir, "map_data", "provinces.png")) + + + #BFSProvDef + + BFS.extractBFS(os.path.join(output_dir, "BFSoutput.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xlsx")) + + BFS.BaronyId(os.path.join(output_dir, "combined_data.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xlsx")) + BFS.ProvData(os.path.join(output_dir,"updated_file.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xlsx")) + BFS.cOrder(os.path.join(output_dir,"_mapFiller/provinceDef.xlsx")) + BFS.finalorder(os.path.join(output_dir,"_mapFiller/provinceDef.xlsx")) + BFS.convert_xlsx_to_xls(os.path.join(output_dir, "_mapFiller/provinceDef.xlsx"), os.path.join(output_dir, "_mapFiller/provinceDef.xls")) + + + + + +def runMapFill(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir): + + # Get output directory path from user input + print("Automatic Map Filler Running") + config_file_path = os.path.join(mapfilldir, "config.properties") + print(config_file_path) + moddir = output_dir + + modFiles.modify_config(moddir, gamedir, config_file_path) + + jar_path = os.path.join(mapfilldir, "CK3Tools.jar") + cwd = mapfilldir + modFiles.run_jar(jar_path, cwd) + + localization.religionLoc(output_dir) + + + + + + +def runCharBook(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response, gamedir,output_dir): + + + localization.religionLoc(output_dir) + + if CharGen_response.lower() == "yes": + print("Character Generation running:") + character.rulerGenXL(os.path.join(output_dir, "combined_data.xlsx"), + os.path.join(output_dir, "characters.xlsx")) + character.rulerWrite(os.path.join(output_dir, "characters.xlsx"), + os.path.join(output_dir, "history/characters/")) + character.modHistory(os.path.join(output_dir, "characters.xlsx"), + os.path.join(output_dir, "history/titles/")) + bookmark.bm_groups(output_dir) + bookmark.bm_generator(output_dir, 3) + + + elif CharGen_response.lower() == "no": + print("Shattered World Mode.") + else: + print("Invalid response. Please enter 'yes' or 'no'.") + + + + + + + + + + +def printValues(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir): + print("Modpath: ", modpath) + print("mapfilldir: ", mapfilldir) + print("installdir: ", installdir) + print("scaling_method: ", scaling_method) + print("scaling_factor: ", scaling_factor) + print("modname: ", modname) + print("CharGen_response: ", CharGen_response) + print("Gamedir:",gamedir) + print("output_dir:",output_dir) diff --git a/main.py b/main.py index b8ab8f1..8d9b154 100644 --- a/main.py +++ b/main.py @@ -14,25 +14,30 @@ import sys import character import localization - - -#scaling_method = input("1,2 {1=Manual Scale 2=Auto Scale}:") +import uictk +import customtkinter scaling_method = 2 scaling_factor = 35 +modpath = ("") +modname = ("") +mapfilldir = ("") +installdir = ("") +CharGen_response = ("") -print("Scaling Method 1 = Manual Scaling Scaling Method 2 = Auto-Scaling") -scaling_method = int(input("Scaling Method: ")) +#print("Scaling Method 1 = Manual Scaling Scaling Method 2 = Auto-Scaling") -if scaling_method == 1: - print("Manual Scaling Method Selected") - scaling_factor == input("Enter Scaling Factor: ") -elif scaling_method ==2: - print("Auto-Scaling Selected") -else: - print("Invalid Scaling Method") - exit() +#scaling_method = int(input("Scaling Method: ")) + +#if scaling_method == 1: + #print("Manual Scaling Method Selected") + #scaling_factor == input("Enter Scaling Factor: ") +#elif scaling_method ==2: + #print("Auto-Scaling Selected") +#else: + #print("Invalid Scaling Method") + #exit() #print("Scaling Factor Determines map size, Try 50 to start with") @@ -287,7 +292,37 @@ def runGen(): -runGen() +#runGen() +import bookmark +import modFiles +import religion +import spreadsheets +import rasterMaps +import BFS +import hextorgb +import os +import modFiles +import openpyxl +import pandas as pd +import xlwt +import culture +import sys +import character +import localization +import uictk +import customtkinter +import sys +sys.stdout = open("log.txt", "w") + +if __name__ == "__main__": + root = customtkinter.CTk + app = uictk.App() + app.mainloop() + sys.stdout.close() + + + + # Wait for user input before closing -input("Press Enter to exit...") \ No newline at end of file +#input("Press Enter to exit...") \ No newline at end of file diff --git a/uictk.py b/uictk.py new file mode 100644 index 0000000..d110dd9 --- /dev/null +++ b/uictk.py @@ -0,0 +1,196 @@ +import customtkinter +import tkinter as tk +from tkinter import filedialog +import tkinter +import generate +from tkinter import messagebox +import os +import time +import threading +import sys + +class MyTabView(customtkinter.CTkTabview): + + + def run_converter(self): + self.progressbar.set(0.1) + self.get_dirs_button.configure(state="disabled") + + # Call the generator function here + modpath = self.path_text_boxes[0].get() + mapfilldir = self.path_text_boxes[1].get() + installdir = self.path_text_boxes[2].get() + scaling_method_str = self.scaling_method_combobox.get() + scaling_factor = self.scaling_factor_entry.get() + modname = self.modname_entry.get() + generate_characters = self.chargen_combobox.get() + CharGen_response = generate_characters.lower() + + scaling_factor = int(scaling_factor) + if scaling_method_str == "Manual Scaling": + scaling_method = 1 + else: + scaling_method = 2 + + + gamedir = os.path.join(installdir, 'game') + output_dir = os.path.join(modpath, modname) + try: + + generate.printValues(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir) + # Update the progress bar + self.progressbar.set(0.12) + generate.runGenExcel(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir) + + self.progressbar.set(0.3) + generate.runGenRaster(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir) + self.progressbar.set(0.35) + time.sleep(1) + generate.runGenRelCult(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir) + self.progressbar.set(0.4) + time.sleep(1) + generate.runGenBFS(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir) + self.progressbar.set(0.7) + generate.runMapFill(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir) + self.progressbar.set(0.9) + generate.runCharBook(modpath, mapfilldir, installdir, scaling_method, scaling_factor, modname, CharGen_response,gamedir,output_dir) + self.progressbar.set(1.0) + except Exception as e: + print(f"An error occurred, please report the log.txt file if this error is unexpected: {e}") + self.get_dirs_button.configure(state="normal") + messagebox.showinfo("Error", "An error occurred, Please check the log.txt file if this error is unexpected!") + # Wait for user input before closing + input("Press Enter to exit...") + sys.exit(1) # exit with an error code + + + messagebox.showinfo("Conversion Complete", "The conversion process is complete!") + self.get_dirs_button.configure(state="normal") + + + def run_conv_thread(self): + # Create a new thread to run the function + thread = threading.Thread(target=self.run_converter) + thread.start() + + + def browse_directory(self, row): + # Get the text box associated with the browse button + text_box = self.path_text_boxes[row] + + # Open the directory selection dialog + directory = filedialog.askdirectory() + + # If a directory was selected, update the text box + if directory: + text_box.delete(0, tk.END) + text_box.insert(0, directory) + + + + def __init__(self, master, **kwargs): + super().__init__(master, **kwargs) + + # create tabs + self.add("Paths") + self.add("Options") + self.add("Convert") + + # add widgets on tabs + self.label = customtkinter.CTkLabel(master=self.tab("Paths"), text="hello") + self.label.grid(row=0, column=0, padx=20, pady=10,sticky=tkinter.E) + + ### DIRECTORIES ### + + self.path_labels = ["Crusader Kings III Mod Directory:", "Map Filler Directory:", + "Crusader Kings III Install Directory:"] + self.path_text_boxes = [] + self.browse_buttons = [] + + for row, label in enumerate(self.path_labels): + # Create the label + label_widget = customtkinter.CTkLabel(master=self.tab("Paths"), text=label) + label_widget.grid(row=row, column=0, sticky="w", padx=5, pady=5) + + # Create the text box + text_box_widget = customtkinter.CTkEntry(master=self.tab("Paths"), width=600) + text_box_widget.grid(row=row, column=1, sticky="we", padx=5, pady=5) + self.path_text_boxes.append(text_box_widget) + + # Create the browse button + browse_button_widget = customtkinter.CTkButton(master=self.tab("Paths"), text="Browse", + command=lambda row=row: self.browse_directory(row)) + browse_button_widget.grid(row=row, column=2, sticky="e", padx=5, pady=5) + self.browse_buttons.append(browse_button_widget) + + + + # Options tab + + + self.scaling_method_label = customtkinter.CTkLabel(master=self.tab("Options"), text="Select scaling method:") + self.scaling_method_label.grid(row=0, column=0, padx=20, pady=10) + self.scaling_method_label.pack() + + + + self.scaling_method_options = ["Manual Scaling", "Auto-Scaling"] + self.scaling_method_combobox = customtkinter.CTkComboBox(master=self.tab("Options"), values=self.scaling_method_options) + self.scaling_method_combobox.pack() + + self.scaling_factor_label = customtkinter.CTkLabel(master=self.tab("Options"),text="Enter Scaling Factor (only used for Manual Scaling):") + self.scaling_factor_label.pack() + + + self.scaling_factor_entry = customtkinter.CTkEntry(master=self.tab("Options")) + self.scaling_factor_entry.insert(0, "50") + self.scaling_factor_entry.pack() + + self.modname_label = customtkinter.CTkLabel(master=self.tab("Options"), text="Mod Name:") + self.modname_label.pack() + + self.modname_entry = customtkinter.CTkEntry(master=self.tab("Options")) + self.modname_entry.insert(0, "Conversion") + self.modname_entry.pack() + + self.chargen_label = customtkinter.CTkLabel(master=self.tab("Options"), text="Generate characters to hold the state level titles?") + self.chargen_label.pack() + + self.chargen_var = tk.StringVar(value="No") + self.chargen_options = ["Yes", "No"] + self.chargen_combobox = customtkinter.CTkComboBox(master=self.tab("Options"), values=self.chargen_options) + self.chargen_combobox.pack() + + + #options c1 + #self.labelc1 = customtkinter.CTkLabel(master=self.tab("Options"), text="hello") + #self.labelc1.grid(row=0, column=1, padx=20, pady=10) + + + + #CONVERT TAB + + # Create the set values button + self.get_dirs_button = customtkinter.CTkButton(master=self.tab("Convert"), text="Run Converter", command=self.run_conv_thread) + self.get_dirs_button.pack() + + self.progressbar = customtkinter.CTkProgressBar(master=self.tab("Convert")) + self.progressbar.pack(padx=20, pady=10) + self.progressbar.set(0.0) + + + +class App(customtkinter.CTk): + def __init__(self): + super().__init__() + customtkinter.set_appearance_mode("dark") + self.minsize(1100, 400) + self.title("CK3 Map Generation Tool") + self.tab_view = MyTabView(master=self,width = 1200, height = 400) + + self.tab_view.grid(row=0, column=0, padx=20, pady=20, sticky="nsew") + self.tab_view.grid_rowconfigure(3, weight=1) + + +#app = App() +#app.mainloop() \ No newline at end of file