-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
206 lines (159 loc) · 6.52 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import tkinter as tk
from tkinter import ttk, filedialog, messagebox
from scripts import rom_file_organizer, sd_card_formatter
import platform
import sys
import os
def organize_files(operation):
folder_path = path_label.cget("text")
if operation == "generate_m3u":
success, message = rom_file_organizer.generate_m3u_playlist_from_CHD(
folder_path
)
elif operation == "revert":
success, message = rom_file_organizer.move_CHD_to_root_folder_delete_m3u_files(
folder_path
)
if success:
messagebox.showinfo("Completed", message)
else:
messagebox.showerror("Error", message)
def browse_directory():
folder_path = filedialog.askdirectory()
if folder_path:
path_label.config(text=folder_path)
path_label_sd_card.config(text=folder_path) # Add this line to update the path_label_sd_card text
organize_button1.config(state=tk.NORMAL)
organize_button2.config(state=tk.NORMAL)
setup_sd_card_button_garlic.config(state=tk.NORMAL)
setup_sd_card_button_batocera.config(state=tk.NORMAL)
def on_click(app_name):
app_title.config(text=app_name)
update_right_frame(app_name)
def update_right_frame(app_name):
if app_name == "Organize CHD Files":
chd_frame.grid(column=1, row=1, rowspan=2, sticky=(tk.W, tk.E, tk.N, tk.S))
sd_card_frame.grid_remove()
elif app_name == "Setup ROM SD Card":
chd_frame.grid_remove()
sd_card_frame.grid(column=1, row=1, rowspan=2, sticky=(tk.W, tk.E, tk.N, tk.S))
else:
chd_frame.grid_remove()
sd_card_frame.grid_remove()
def setup_sd_card(os):
folder_path = path_label.cget("text")
success, message = sd_card_formatter.create_rom_folders(folder_path, os)
if success:
messagebox.showinfo("Completed", message)
else:
messagebox.showerror("Error", message)
def calculate_pixel_width(lst):
padding = 0
# Determine the default font on the current OS
os_name = platform.system()
if os_name == "Windows":
font_name = "Segoe UI"
font_size = 9 # Default font size on Windows
elif os_name == "Darwin":
font_name = "Helvetica"
font_size = 13 # Default font size on macOS
else:
font_name = "DejaVu Sans" # Assuming a Linux-like OS
font_size = 10 # Default font size on Linux
# Create a Tkinter window and a Text widget to set the default font
root = tk.Tk()
root.withdraw()
text = tk.Text(root, font=(font_name, font_size))
# Find the longest string in the list
longest_str = max(lst, key=len)
# Set the contents of the Text widget to the longest string
text.insert("1.0", longest_str)
# Resize the Text widget to fit its contents
text.update_idletasks()
text_width = text.winfo_width()
text_height = text.winfo_height()
text.config(width=text_width, height=text_height)
# Calculate the pixel width of the Text widget
pixel_width = text_width - 4 # Subtract 4 pixels for the widget border
# Return the pixel width as an integer
return int(pixel_width) + padding
window = tk.Tk()
window.title("RG35XX Roms Manager")
# window.geometry("500x100")
window.minsize(500, 100)
window.maxsize(500, 100)
try:
# PyInstaller creates a temp folder and stores the path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
icon_path = os.path.join(base_path, "media", "icon.gif")
window.iconphoto(True, tk.PhotoImage(file=icon_path))
left_frame = ttk.Frame(window, relief="groove", borderwidth=2)
left_frame.grid(column=0, row=0, sticky=(tk.W, tk.E, tk.N, tk.S))
left_frame_title = ttk.Label(left_frame, text="Applications")
left_frame_title.grid(column=0, row=0)
application_names = ["Organize CHD Files", "Setup ROM SD Card"] # , "Application 3"]
apps_listbox = tk.Listbox(left_frame, height=len(application_names), width=calculate_pixel_width(application_names))
for i, application_name in enumerate(application_names):
apps_listbox.insert(i, application_name)
apps_listbox.bind(
"<<ListboxSelect>>",
lambda event: on_click(apps_listbox.get(apps_listbox.curselection())),
)
apps_listbox.grid(column=0, row=1)
right_frame = ttk.Frame(window, relief="groove", borderwidth=1)
right_frame.grid(column=1, row=0, sticky=(tk.W, tk.E, tk.N, tk.S))
app_title = ttk.Label(right_frame, text="")
app_title.grid(column=0, row=0, columnspan=2, sticky=(tk.W, tk.E))
chd_frame = ttk.Frame(right_frame)
chd_frame.columnconfigure(1, weight=1)
browse_button = ttk.Button(chd_frame, text="Browse", command=browse_directory)
browse_button.grid(column=0, row=1, sticky=(tk.W, tk.E))
path_label = ttk.Label(chd_frame, text="")
path_label.grid(column=1, row=1, sticky=(tk.W, tk.E))
organize_button1 = ttk.Button(
chd_frame,
text="Generate M3U Playlists",
state=tk.DISABLED,
command=lambda: organize_files("generate_m3u"),
)
organize_button1.grid(column=0, row=2, sticky=(tk.W, tk.E))
organize_button2 = ttk.Button(
chd_frame,
text="Revert to Single Folder",
state=tk.DISABLED,
command=lambda: organize_files("revert"),
)
organize_button2.grid(column=1, row=2, sticky=(tk.W, tk.E))
window.columnconfigure(0, weight=0, minsize=150) # Set minsize=200 for the left frame
window.columnconfigure(1, weight=1)
window.rowconfigure(0, weight=1)
chd_frame.columnconfigure(1, weight=1)
chd_frame.rowconfigure(1, weight=1)
sd_card_frame = ttk.Frame(right_frame)
sd_card_frame.columnconfigure(1, weight=1)
browse_button_sd_card = ttk.Button(sd_card_frame, text="Browse", command=browse_directory)
browse_button_sd_card.grid(column=0, row=1, sticky=(tk.W, tk.E))
path_label_sd_card = ttk.Label(sd_card_frame, text="")
path_label_sd_card.grid(column=1, row=1, columnspan=2, sticky=(tk.W, tk.E)) # Add columnspan=2
setup_sd_card_button_garlic = ttk.Button(
sd_card_frame,
text="Create Folders for Garlic OS",
state=tk.DISABLED,
command=lambda: setup_sd_card("Garlic")
)
setup_sd_card_button_garlic.grid(column=0, row=2, sticky=(tk.W, tk.E))
setup_sd_card_button_batocera = ttk.Button(
sd_card_frame,
text="Create Folders for Batocera",
state=tk.DISABLED,
command=lambda: setup_sd_card("Batocera")
)
setup_sd_card_button_batocera.grid(column=1, row=2, sticky=(tk.W, tk.E)) # Change column from 2 to 1
sd_card_frame.grid_remove() # Hide frame by default
chd_frame.grid_remove() # Hide frame
# Uncomment the line below to start the application with the first app selected by default
apps_listbox.selection_set(0)
on_click(application_names[0])
window.mainloop()