Skip to content

Commit b7d1779

Browse files
committed
fixed confirm/cancel buttons on windows
1 parent fc87a9f commit b7d1779

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

lib/gui/terminal.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ def confirmation(self, message, event):
4141
root = context.get_root()
4242

4343
cancel_img_tk = ImageTk.PhotoImage(cancel_image_resized)
44-
self.cancel_container = tk.Frame(self, bd=0) # Cancel button container
44+
self.cancel_container = tk.Frame(self, bd=0, bg="#323232") # Cancel button container
4545
self.cancel_container.place(x=width - 139, y=height - 22, anchor="nw")
4646
cancel_img = tk.Label(self.cancel_container, image=cancel_img_tk, bg="#323232")
4747
cancel_img.pack(side="left")
4848
cancel_text = tk.Label(self.cancel_container, text="Cancel", font=("Arial", 12), fg="#7c6f64",bg="#323232")
4949
cancel_text.pack(side="left")
5050

5151
confirm_img_tk = ImageTk.PhotoImage(confirm_image_resized)
52-
self.confirm_container = tk.Frame(self, bd=0) # Confirm button container
52+
self.confirm_container = tk.Frame(self, bd=0, bg="#323232") # Confirm button container
5353
confirm_img = tk.Label(self.confirm_container, image=confirm_img_tk, bg="#323232")
5454
confirm_img.pack(side="left")
5555
confirm_text = tk.Label(self.confirm_container, text="Confirm", font=("Arial", 12), fg="#7c6f64",bg="#323232")
@@ -69,7 +69,9 @@ def confirmation(self, message, event):
6969

7070
# Activate keyboard click events [Cancel (B) / Confirm (A)]
7171
root.bind("<b>", lambda e: self._on_cancel())
72+
root.bind("<B>", lambda e: self._on_cancel())
7273
root.bind("<a>", lambda e: self._on_confirm(event))
74+
root.bind("<A>", lambda e: self._on_confirm(event))
7375

7476
# Set up file drop handling for drag-and-drop event
7577
_setup_file_drop(self,event)
@@ -119,7 +121,9 @@ def destroy_elements(self):
119121
# Unbind keyboard keys (Cancel - 'B' and Confirm - 'A')
120122
root = context.get_root()
121123
root.unbind("<b>")
124+
root.unbind("<B>")
122125
root.unbind("<a>")
126+
root.unbind("<A>")
123127
root.unbind("<Return>")
124128

125129
# Unbind <<Drop>> event from root widget to disable drop functionality
@@ -235,7 +239,7 @@ def recreate_terminal(self):
235239
root = context.get_root()
236240

237241
# Custom canvas creation (using TerminalCanvas subclass)
238-
terminal_canvas = TerminalCanvas(root, height=155)
242+
terminal_canvas = TerminalCanvas(root, height=155, bg="#323232")
239243

240244
# Pack the terminal to the top or bottom as needed
241245
terminal_canvas.pack(fill="both", expand=True, side="top", pady=2)

lib/sd_card.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,6 @@ def on_volume_name_enter(volume_name):
255255
messagebox.showerror("Error", "Volume name cannot be empty!")
256256
return
257257
volume_name = volume_name.upper() # Converti il nome in maiuscolo per evitare errori
258-
identifier = get_disk_identifier(volume_name)
259-
260-
if not identifier:
261-
messagebox.showerror("Error", "Unable to get disk identifier.")
262-
return
263258

264259
# Crea lo script di formattazione
265260
script = f"""
@@ -270,19 +265,35 @@ def on_volume_name_enter(volume_name):
270265

271266
try:
272267
# Scrivi ed esegui lo script diskpart
273-
with open("format_script.txt", "w") as script_file:
268+
script_path = os.path.abspath("format_script.txt")
269+
with open(script_path, "w") as script_file:
274270
script_file.write(script)
275271

276-
# Esegui diskpart
277-
result = subprocess.run("diskpart /s format_script.txt", check=True, shell=True, capture_output=True, text=True)
272+
# Esegui diskpart con un metodo che nasconde la finestra
273+
startupinfo = subprocess.STARTUPINFO()
274+
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
275+
276+
result = subprocess.run(
277+
["diskpart", "/s", script_path],
278+
capture_output=True,
279+
text=True,
280+
startupinfo=startupinfo
281+
)
278282

279283
# Debug: stampa l'output di diskpart
280284
print(f"Diskpart Output (stdout): {result.stdout}")
281285
print(f"Diskpart Output (stderr): {result.stderr}")
282286

283-
os.remove("format_script.txt")
287+
if result.returncode != 0:
288+
raise subprocess.CalledProcessError(result.returncode, "diskpart", result.stdout, result.stderr)
289+
290+
os.remove(script_path) # Rimuovi il file temporaneo dello script
291+
284292
display.message(f"Formatting completed!\nYour SD card has been formatted with the name '{volume_name}'!")
285293

294+
# Aggiorna la lista dei dispositivi SD
295+
refresh_sd_devices(sd_selector[0], sd_selector[1], sd_path[0])
296+
286297
# Chiamata al callback
287298
try:
288299
callback_thread = threading.Thread(target=callback)
@@ -295,6 +306,10 @@ def on_volume_name_enter(volume_name):
295306
messagebox.showerror("Error", f"Error while formatting: {e}")
296307
print(f"Error while formatting: {e}")
297308
return False
309+
except Exception as e:
310+
messagebox.showerror("Error", f"Unexpected error: {e}")
311+
print(f"Unexpected error: {e}")
312+
return False
298313

299314
# Chiedi all'utente di inserire un nome valido per il volume
300315
display.user_input("Enter the name for your new volume:", on_volume_name_enter)

0 commit comments

Comments
 (0)