125 lines
4.5 KiB
Python
125 lines
4.5 KiB
Python
import customtkinter as Ctk
|
|
import os
|
|
import scripts.get_sys_info as system_code
|
|
from ..SaveData import SaveData
|
|
from tkinter import filedialog
|
|
|
|
|
|
FONT = "Berlin Sans FB"
|
|
|
|
class SwitchFolder(Ctk.CTkFrame):
|
|
def __init__(self,master, callback, **kwargs):
|
|
super().__init__(master, **kwargs)
|
|
system_code.load_json_file()
|
|
self.data_saver = SaveData()
|
|
self.my_font = Ctk.CTkFont(family=FONT, size=22)
|
|
self.callback = callback
|
|
self.error_txt = ""
|
|
self.input_path = None
|
|
self.output_path = None
|
|
self.img_paths = None
|
|
|
|
self.create_selection()
|
|
|
|
def enable_keybinding(self):
|
|
self.master.bind("<Return>", self.open_labeling, add="+")
|
|
|
|
|
|
def disable_keybinding(self):
|
|
self.master.unbind("<Return>")
|
|
|
|
# the selection part
|
|
def create_selection(self):
|
|
# input
|
|
self.input_entry = Ctk.CTkEntry(self, placeholder_text="Input folder path", width=100, font=self.my_font)
|
|
self.input_btn = Ctk.CTkButton(self, text="Browse", width=100, command=self.get_folder_path, font=self.my_font)
|
|
# output
|
|
self.output_entry = Ctk.CTkEntry(self, placeholder_text="Output folder path", width=100, font=self.my_font)
|
|
self.output_btn = Ctk.CTkButton(self, text="Browse", width=100, command=self.get_project_path, font=self.my_font)
|
|
# start
|
|
self.start_btn = Ctk.CTkButton(self, text="Start", width=100, command=self.open_labeling, font=self.my_font)
|
|
self.error_label = Ctk.CTkLabel(self, text=self.error_txt, width=100, font=self.my_font)
|
|
self.place_label_selection()
|
|
|
|
def open_labeling(self, value = None):
|
|
source_path = self.input_entry.get()
|
|
self.output_path = self.output_entry.get()
|
|
if not os.path.exists(source_path):
|
|
self.error_txt = "Source Folder could not be found"
|
|
self.error_label.configure(text=self.error_txt)
|
|
elif not os.path.exists(self.output_path):
|
|
self.error_txt = "Output Folder could not be found"
|
|
self.error_label.configure(text=self.error_txt)
|
|
else:
|
|
self.data_saver.search_in_folder(self.output_path)
|
|
self.img_paths = self.load_images_into_array(source_path)
|
|
self.give_back()
|
|
|
|
def load_images_into_array(self, folder_path):
|
|
image_paths = []
|
|
for filename in os.listdir(folder_path):
|
|
if filename.endswith(system_code.img_format_options):
|
|
img_path = os.path.join(folder_path, filename)
|
|
image_paths.append(img_path)
|
|
return image_paths
|
|
|
|
def get_folder_path(self):
|
|
file_path = filedialog.askdirectory()
|
|
self.input_entry.delete(0, Ctk.END) # Delete any existing text in the Entry widget
|
|
self.input_entry.insert(0, file_path) # Insert the new text
|
|
|
|
def get_project_path(self):
|
|
video_path = filedialog.askdirectory()
|
|
self.output_entry.delete(0, Ctk.END) # Delete any existing text in the Entry widget
|
|
self.output_entry.insert(0, video_path) # Insert the new text
|
|
|
|
def give_back(self):
|
|
self.callback(self.img_paths, self.output_path)
|
|
|
|
def place_label_selection(self):
|
|
# output placing
|
|
self.input_entry.place(
|
|
relx=0.10,
|
|
rely=0.4,
|
|
anchor="w",
|
|
relwidth=0.5,
|
|
relheight=0.06
|
|
) # Position the converter button to the left
|
|
self.input_btn.place(
|
|
relx=0.90,
|
|
rely=0.4,
|
|
anchor="e",
|
|
relwidth=0.2,
|
|
relheight=0.06
|
|
) # Position the converter button to the left
|
|
|
|
# output placing
|
|
self.output_entry.place(
|
|
relx=0.10,
|
|
rely=0.5,
|
|
anchor="w",
|
|
relwidth=0.5,
|
|
relheight=0.06
|
|
) # Position the converter button to the left
|
|
self.output_btn.place(
|
|
relx=0.90,
|
|
rely=0.5,
|
|
anchor="e",
|
|
relwidth=0.2,
|
|
relheight=0.06
|
|
) # Position the converter button to the left
|
|
# button row
|
|
self.start_btn.place(
|
|
relx=0.5,
|
|
rely=0.6,
|
|
anchor="center",
|
|
relwidth=0.8,
|
|
relheight=0.06
|
|
) # Position the converter button to the left
|
|
self.error_label.place(
|
|
relx=0.5,
|
|
rely=0.7,
|
|
anchor="center",
|
|
relwidth=0.8,
|
|
relheight=0.06
|
|
) # Position the converter button to the left |