import customtkinter as Ctk import platform from icons.icons import Icons import scripts.get_sys_info as system_code from scripts.ClosePopup import ClosePopup from scripts.settings import Settings from scripts.Converter import Converter from scripts.Labeling import Labeling from scripts.folder_mangement.OpenFolder import OpenFolder from scripts.folder_mangement.CreateFolder import CreateFolder from scripts.folder_mangement.SwitchFolder import SwitchFolder SELECTION_TEXT = "Select your Directory and your Export Directory" class App(Ctk.CTk): def __init__(self): super().__init__() system_code.load_json_file() self.icons = Icons(path=system_code.data_path) system_code.set_theme() self.my_font = Ctk.CTkFont(family="Berlin Sans FB", size=22) self.font_entry = Ctk.CTkFont(family="Berlin Sans FB", size=18) self.minsize(1000, 750) self.geometry(f"{system_code.window_width}x{system_code.window_height}") if platform.system() == "Windows": icon_path = self.icons.get_icon_path() self.iconbitmap(icon_path) self.after(1, self.wm_state, system_code.window_state) self.back_btn_image = self.icons.get_image("BackButton") self.title("MPENN") self.protocol('WM_DELETE_WINDOW', self.close_attempt) self.settings_frame = Settings(master=self) self.converter_frame = Converter(master=self) self.last_frame = None self.popup = None self.active_frame = None self.Switch_folder = None self.create_folder = None self.open_folder = None self.labeling = None self.current_labeling_frame = None self.last_opened_labeling_frame = None self.window_informaton_save = () # Top Menu # Widgets self.settings_btn = Ctk.CTkButton(self, text="Settings", width=100, command=self.open_settings, font=self.my_font) image = Ctk.CTkImage(self.back_btn_image, size=(50, 50)) self.back_btn = Ctk.CTkButton(self, text="", image=image,width=50, command=self.go_back, font=self.my_font) self.window_information = Ctk.CTkLabel(self, text="Choose if you want to convert or label DATA", width=100, font=self.my_font) # Alignment self.place_top_menu() self.show_main_menu() self.bind("", self.go_back) # Open Main UI initially def show_main_menu(self): self.window_information.configure(text="Choose if you want to convert or label DATA") self.buttons_frame = Ctk.CTkFrame(self) self.active_frame = self.buttons_frame # Main Menu self.convert_btn = Ctk.CTkButton(self.buttons_frame, text="Convert Videos\ninto IMG-Sequences", command=self.open_converter, width=64, font=self.my_font) self.label_btn = Ctk.CTkButton(self.buttons_frame, text="Label and\n manage Images", command=self.open_current_labeling_ui, width=64,font=self.my_font) # Main Menu self.active_frame.place( relx=0.5, rely=0.52,relwidth=0.95, relheight=0.85, anchor="center" ) self.convert_btn.place( relx=0.15, rely=0.5, anchor="w", relwidth=0.3, relheight=0.1 ) # Position the converter button to the left self.label_btn.place( relx=0.85, rely=0.5, anchor="e", relwidth=0.3, relheight=0.1 ) # Position the label button to the right def open_current_labeling_ui(self): self.active_frame.place_forget() if self.active_frame != self.buttons_frame: self.active_frame.disable_keybinding() if self.current_labeling_frame == None: self.window_information.configure(text=SELECTION_TEXT) self.Switch_folder = SwitchFolder(master=self, callback=self.open_labeling) self.current_labeling_frame = self.Switch_folder self.current_labeling_frame.place(relx=0.5, rely=0.52,relwidth=0.95, relheight=0.85, anchor="center") else: self.current_labeling_frame.place(relx=0.5, rely=0.52,relwidth=0.95, relheight=0.85, anchor="center") self.current_labeling_frame.enable_keybinding() self.active_frame = self.current_labeling_frame self.last_frame = self.buttons_frame def open_labeling(self, img_paths, output): self.last_opened_labeling_frame = self.current_labeling_frame self.last_frame = self.current_labeling_frame self.current_labeling_frame.place_forget() self.current_labeling_frame.disable_keybinding() self.labeling = Labeling(master=self, img_paths=img_paths, output_path=output, callback=self.open_folder_uis, window_information=self.change_window_information) self.current_labeling_frame = self.labeling self.active_frame = self.current_labeling_frame self.place_ui() def reopen_labeling(self, output): self.last_opened_labeling_frame = self.current_labeling_frame self.last_frame = self.current_labeling_frame self.current_labeling_frame.place_forget() self.current_labeling_frame.disable_keybinding() self.labeling.update_active_output_path(output) self.current_labeling_frame = self.labeling self.active_frame = self.current_labeling_frame self.place_ui() def open_folder_uis(self, output, variant): # variant: 0: CreateFolder 1: OpenFolder 3: SwitchFolder self.last_opened_labeling_frame = self.current_labeling_frame self.last_frame = self.current_labeling_frame self.current_labeling_frame.place_forget() self.current_labeling_frame.disable_keybinding() if variant == 0: self.window_information.configure(text="Create new folder in active directory") self.create_folder = CreateFolder(master=self,output_path=output, callback=self.reopen_labeling) self.current_labeling_frame = self.create_folder self.active_frame = self.current_labeling_frame elif variant == 1: self.window_information.configure(text="Select new folder in active directory") self.open_folder = OpenFolder(master=self, output_path=output, callback=self.reopen_labeling) self.current_labeling_frame = self.open_folder self.active_frame = self.current_labeling_frame else: self.window_information.configure(text=SELECTION_TEXT) self.current_labeling_frame = self.Switch_folder self.active_frame = self.current_labeling_frame self.place_ui() def open_settings(self): if self.active_frame == self.settings_frame: return elif self.active_frame == self.buttons_frame: self.last_frame = self.buttons_frame elif self.active_frame == self.converter_frame: self.last_frame = self.converter_frame elif self.active_frame == self.Switch_folder: self.last_frame = self.Switch_folder elif self.active_frame == self.labeling: self.last_frame = self.labeling elif self.active_frame == self.create_folder: self.last_frame = self.create_folder elif self.active_frame == self.open_folder: self.last_frame = self.open_folder self.active_frame.place_forget() if self.active_frame != self.buttons_frame: self.active_frame.disable_keybinding() self.window_information.configure(text="Settings") self.last_opened_labeling_frame = self.current_labeling_frame self.active_frame = self.settings_frame self.place_ui() def open_converter(self): self.window_information.configure(text=SELECTION_TEXT) self.last_frame = self.buttons_frame self.buttons_frame.place_forget() self.active_frame = self.converter_frame self.place_ui() def go_back(self, event = None): if self.active_frame == self.buttons_frame: return elif self.active_frame == self.settings_frame: system_code.save_setting_change() if self.last_frame != self.buttons_frame: self.active_frame.place_forget() self.active_frame.disable_keybinding() self.active_frame = self.last_frame self.last_frame = None self.place_ui() else: self.active_frame.place_forget() self.active_frame = self.buttons_frame self.place_ui() elif self.active_frame == self.Switch_folder: self.active_frame.place_forget() self.active_frame.disable_keybinding() self.active_frame = self.buttons_frame self.last_frame = None self.last_opened_labeling_frame = self.Switch_folder self.place_ui() elif self.active_frame == self.converter_frame: self.active_frame.place_forget() self.active_frame.disable_keybinding() self.active_frame = self.buttons_frame self.last_frame = None self.place_ui() elif self.active_frame == self.labeling: self.active_frame.place_forget() self.active_frame.disable_keybinding() self.active_frame = self.buttons_frame self.last_frame = None self.last_opened_labeling_frame = self.labeling self.place_ui() elif self.should_switch_to_labeling(): self.switch_to_labeling() def should_switch_to_labeling(self): return ( (self.open_folder is not None and self.open_folder.winfo_ismapped()) or (self.create_folder is not None and self.create_folder.winfo_ismapped()) or (self.Switch_folder is not None and self.Switch_folder.winfo_ismapped() and self.last_opened_labeling_frame == self.labeling) ) def switch_to_labeling(self): self.hide_and_prepare_last_labeling() self.change_window_information(None) self.active_frame.place_forget() self.active_frame.disable_keybinding() self.active_frame = self.labeling self.place_ui() def hide_and_prepare_last_labeling(self): if self.current_labeling_frame: self.current_labeling_frame.place_forget() self.current_labeling_frame.disable_keybinding() self.last_opened_labeling_frame = self.current_labeling_frame self.current_labeling_frame = self.labeling def change_window_information(self, value): if value is not None: self.window_informaton_save = value if self.current_labeling_frame == self.labeling: self.window_information.configure(text=f"{self.window_informaton_save[0]} from {self.window_informaton_save[1]} -> {self.window_informaton_save[2]}") def place_ui(self): self.active_frame.place(relx=0.5, rely=0.52,relwidth=0.95, relheight=0.85, anchor="center") if self.active_frame != self.buttons_frame: self.active_frame.enable_keybinding() def close_attempt(self): if self.settings_frame.winfo_ismapped() or self.converter_frame.winfo_ismapped(): self.popup = ClosePopup(master=self, callback=self.close_program) else: system_code.save_windows_information(self.geometry(),self.state()) self.close_program() def close_program(self): self.destroy() def place_top_menu(self): self.settings_btn.place( relx=0.015, y=35, anchor="w", relwidth=0.1, relheight=0.035 ) self.back_btn.place( relx=0.13, y=35, anchor="w", relwidth=0.035, relheight=0.035 ) self.window_information.place( relx=0.5, y=35, anchor="center", relwidth=0.6, relheight=0.095 ) if __name__ == '__main__': app = App() app.mainloop()