Skip to content

Commit 9dee212

Browse files
committed
Update main.py
can now save the destination path
1 parent 1adbe0e commit 9dee212

File tree

1 file changed

+60
-21
lines changed

1 file changed

+60
-21
lines changed

main.py

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(self, root):
3333
self.video_frame_after_id = None
3434
self.video_capture = None
3535
self.undo_info = None
36+
self.config_file = "fair_config.txt"
3637

3738
# Initialize logfile
3839
self.logfile = self.create_default_logfile()
@@ -49,6 +50,7 @@ def __init__(self, root):
4950
self.choose_file_messege()
5051
self.load_previews()
5152
self.last_folder_path = self.load_last_folder_path()
53+
self.load_destination_paths()
5254

5355
def create_default_logfile(self):
5456
default_logfile = f"move_log_{datetime.now().strftime('%Y%m%d%H%M%S')}.txt"
@@ -197,7 +199,7 @@ def show_log_context_menu(self, event):
197199

198200
def preview_image(self, file_path):
199201
preview_window = tk.Toplevel(self.root)
200-
preview_window.title("Image Preview")
202+
preview_window.title(os.path.basename(file_path))
201203
preview_window.geometry("800x600")
202204
preview_window.tk_setPalette(background='#F0F0F0')
203205

@@ -223,18 +225,32 @@ def resize_image(event):
223225
def show_move_details(self, source_path, destination_path):
224226
details_window = tk.Toplevel(self.root)
225227
details_window.title("Move Details")
226-
details_window.geometry("400x200")
228+
details_window.geometry("400x300")
227229
details_window.tk_setPalette(background='#F0F0F0')
228230

229231
details_frame = tk.Frame(details_window, bg='#F0F0F0')
230232
details_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
231233

232-
source_label = ttk.Label(details_frame, text=f"Source: {source_path}", wraplength=380, background='#F0F0F0')
234+
source_label = ttk.Label(details_frame, text=f"Source: {source_path}", wraplength=360, background='#F0F0F0')
233235
source_label.pack(pady=5)
234236

235-
destination_label = ttk.Label(details_frame, text=f"Destination: {destination_path}", wraplength=380, background='#F0F0F0')
237+
destination_label = ttk.Label(details_frame, text=f"Destination: {destination_path}", wraplength=360, background='#F0F0F0')
236238
destination_label.pack(pady=5)
237239

240+
file_size = os.path.getsize(destination_path)
241+
size_label = ttk.Label(details_frame, text=f"Size: {self.convert_bytes(file_size)}", wraplength=360, background='#F0F0F0')
242+
size_label.pack(pady=5)
243+
244+
modify_date = self.get_modify_date(destination_path)
245+
date_label = ttk.Label(details_frame, text=f"Last Modified: {modify_date}", wraplength=360, background='#F0F0F0')
246+
date_label.pack(pady=5)
247+
248+
if destination_path.lower().endswith(('.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.psd', '.svg', '.raw', '.heic', '.cr2', '.nef', '.orf', '.arw', '.rw2', '.dng', '.xcf', '.pcx')):
249+
img = Image.open(destination_path)
250+
resolution = f"Resolution: {img.width} x {img.height}"
251+
resolution_label = ttk.Label(details_frame, text=resolution, wraplength=360, background='#F0F0F0')
252+
resolution_label.pack(pady=5)
253+
238254
def choose_file_messege(self):
239255
self.photo_label.config(text="please choose folder...\n with photo, video, and music")
240256
self.index_label.config(text="0 / 0 photos")
@@ -278,12 +294,12 @@ def load_previews(self):
278294

279295
def load_last_folder_path(self):
280296
try:
281-
with open("last_folder.txt", "r") as file:
282-
folder_path = file.read().strip()
283-
print(f"Attempting to load folder: {folder_path}")
297+
with open(self.config_file, "r") as file:
298+
lines = file.readlines()
299+
folder_path = lines[0].strip() # First line is the last folder path
284300
self.load_folder_from_path(folder_path)
285301
return folder_path
286-
except FileNotFoundError:
302+
except (FileNotFoundError, IndexError):
287303
return os.path.expanduser("~")
288304

289305
def load_folder_from_path(self, folder_path):
@@ -309,20 +325,24 @@ def load_folder_from_path(self, folder_path):
309325
self.show_current_file()
310326

311327
def save_last_folder_path(self, folder_path):
312-
with open("last_folder.txt", "w") as file:
313-
file.write(folder_path)
328+
with open(self.config_file, "w") as file:
329+
file.write(folder_path + "\n") # First line is the last folder path
330+
for destination in self.destination_folders.keys():
331+
file.write(destination + "\n")
314332

315333
def set_destination(self, event=None):
316334
destination_folder = filedialog.askdirectory()
317335
if destination_folder:
318336
self.destination_folders[destination_folder] = []
319337
self.create_move_button(destination_folder, self.buat_move_button)
338+
self.save_last_folder_path(self.last_folder_path)
320339

321340
def add_destination(self):
322341
destination_folder = filedialog.askdirectory()
323342
if destination_folder:
324343
self.destination_folders[destination_folder] = []
325344
self.create_move_button(destination_folder, self.buat_move_button)
345+
self.save_last_folder_path(self.last_folder_path)
326346

327347
def create_move_button(self, destination_folder, parent_frame):
328348
button_frame = tk.Frame(parent_frame)
@@ -351,6 +371,7 @@ def remove_destination(self, destination_folder):
351371
key_label.destroy()
352372
del self.destination_folders[destination_folder]
353373
self.update_layout()
374+
self.save_last_folder_path(self.last_folder_path)
354375

355376
def update_layout(self):
356377
for i, folder in enumerate(self.destination_folders.keys()):
@@ -359,6 +380,24 @@ def update_layout(self):
359380
remove_button.grid(row=i, column=1, padx=2, pady=0, sticky=tk.E)
360381
key_label.grid(row=i, column=0, padx=0, pady=5, sticky=tk.E)
361382

383+
def save_last_folder_path(self, folder_path):
384+
self.last_folder_path = folder_path
385+
with open(self.config_file, "w") as file:
386+
file.write(folder_path + "\n") # First line is the last folder path
387+
for destination in self.destination_folders.keys():
388+
file.write(destination + "\n")
389+
390+
def load_destination_paths(self):
391+
try:
392+
with open(self.config_file, "r") as file:
393+
lines = file.readlines()[1:] # Skip the first line (last folder path)
394+
for line in lines:
395+
destination_folder = line.strip()
396+
self.destination_folders[destination_folder] = []
397+
self.create_move_button(destination_folder, self.buat_move_button)
398+
except FileNotFoundError:
399+
pass
400+
362401
@staticmethod
363402
def convert_bytes(size_bytes):
364403
if size_bytes == 0:
@@ -726,17 +765,17 @@ def zoom(self, event):
726765
self.show_current_file()
727766

728767
def select_logfile(self):
729-
logfile_path = filedialog.askopenfilename(
730-
defaultextension=".txt",
731-
filetypes=[("Text files", "*.txt"), ("All files", "*.*")],
732-
title="Select Logfile"
733-
)
734-
if logfile_path:
735-
self.logfile = logfile_path
736-
self.logfile_name_label.config(text=f"name: {os.path.basename(self.logfile)}")
737-
self.clear_log_area()
738-
self.load_log()
739-
self.use_last_logfile_button.config(state=tk.NORMAL)
768+
logfile_path = filedialog.askopenfilename(
769+
defaultextension=".txt",
770+
filetypes=[("Text files", "*.txt"), ("All files", "*.*")],
771+
title="Select Logfile"
772+
)
773+
if logfile_path:
774+
self.logfile = logfile_path
775+
self.logfile_name_label.config(text=f"name: {os.path.basename(self.logfile)}")
776+
self.clear_log_area()
777+
self.load_log()
778+
self.use_last_logfile_button.config(state=tk.NORMAL)
740779

741780
def use_last_logfile(self):
742781
log_files = [f for f in os.listdir() if f.startswith("move_log_") and f.endswith(".txt")]

0 commit comments

Comments
 (0)