mirror of
https://github.com/3minbe/DBC_Converter.git
synced 2026-05-17 01:23:58 +09:00
99 lines
3.4 KiB
Python
99 lines
3.4 KiB
Python
import tkinter as tk
|
|
from tkinter import filedialog, messagebox
|
|
import os
|
|
import json
|
|
import datetime
|
|
|
|
config_file = "config.json"
|
|
|
|
def load_last_path():
|
|
if os.path.exists(config_file):
|
|
with open(config_file, "r") as f:
|
|
config = json.load(f)
|
|
return config.get("last_path", os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop'))
|
|
return os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')
|
|
|
|
def save_last_path(path):
|
|
with open(config_file, "w") as f:
|
|
json.dump({"last_path": path}, f)
|
|
|
|
last_path = load_last_path()
|
|
|
|
def on_open():
|
|
global last_path
|
|
file_paths = filedialog.askopenfilenames(
|
|
initialdir=last_path,
|
|
filetypes=[("DBC files", "*.dbc"), ("All files", "*.*")]
|
|
)
|
|
if file_paths:
|
|
last_path = os.path.dirname(file_paths[0])
|
|
save_last_path(last_path)
|
|
|
|
existing_files = [chk.cget("text") for chk in file_listbox_inner.winfo_children() if isinstance(chk, tk.Checkbutton)]
|
|
|
|
for file_path in file_paths:
|
|
file_name = os.path.basename(file_path)
|
|
if file_name in existing_files:
|
|
messagebox.showwarning("경고", f"동일한 파일이 존재합니다 \n\n {file_name}")
|
|
else:
|
|
var = tk.BooleanVar()
|
|
chk = tk.Checkbutton(file_listbox_inner, text=file_name, variable=var, anchor='w', bg=file_listbox.cget("bg"))
|
|
chk.var = var
|
|
chk.pack(anchor='w', fill=tk.X, padx=5, pady=2)
|
|
separator = tk.Frame(file_listbox_inner, height=1, bg="gray", width=760)
|
|
separator.pack(fill=tk.X, padx=5, pady=2)
|
|
|
|
setList(file_paths, file_listbox_inner)
|
|
|
|
def setList(file_paths, tree):
|
|
for file_path in file_paths:
|
|
dir, file = os.path.split(file_path)
|
|
fsize = os.path.getsize(file_path)
|
|
mtime = os.path.getmtime(file_path)
|
|
mtimestamp = datetime.datetime.fromtimestamp(int(mtime))
|
|
|
|
tree.insert('', 'end', values=(file, file, dir, str(fsize), str(mtimestamp)))
|
|
|
|
def on_exit():
|
|
root.destroy()
|
|
|
|
root = tk.Tk()
|
|
root.title("DBC to C Converter")
|
|
root.geometry("1000x800") # 창 크기 설정
|
|
|
|
# ...existing code...
|
|
|
|
top_frame = tk.Frame(root)
|
|
top_frame.pack(side=tk.TOP, anchor="ne")
|
|
|
|
convert_button = tk.Button(top_frame, text="변환")
|
|
convert_button.pack(side=tk.RIGHT)
|
|
|
|
exit_button = tk.Button(top_frame, text="종료", command=on_exit)
|
|
exit_button.pack(side=tk.RIGHT)
|
|
|
|
middle_frame = tk.Frame(root)
|
|
middle_frame.pack(expand=True)
|
|
|
|
file_listbox = tk.Canvas(middle_frame, width=780, bd=2, relief=tk.SOLID)
|
|
file_listbox.pack(side=tk.LEFT, fill=tk.Y, expand=False, padx=10, pady=10)
|
|
|
|
file_listbox_inner = tk.Frame(file_listbox, padx=5, pady=5, bg=file_listbox.cget("bg"))
|
|
file_listbox.create_window((0, 0), window=file_listbox_inner, anchor='nw')
|
|
|
|
# 기본 구분선 추가
|
|
separator = tk.Frame(file_listbox_inner, height=1, bg="gray", width=780)
|
|
separator.pack(fill=tk.X, padx=5, pady=2)
|
|
|
|
scrollbar_listbox = tk.Scrollbar(middle_frame, orient=tk.HORIZONTAL, command=file_listbox.xview)
|
|
scrollbar_listbox.pack(side=tk.BOTTOM, fill=tk.X)
|
|
scrollbar_listbox.config(width=20) # 스크롤바 너비 설정
|
|
file_listbox.config(xscrollcommand=scrollbar_listbox.set)
|
|
|
|
open_button = tk.Button(middle_frame, text="추가", command=on_open)
|
|
open_button.pack(side=tk.LEFT)
|
|
|
|
# ...existing code...
|
|
|
|
root.mainloop()
|