20
20
from SaveState_gui import MainWindow # , ENGLISH_TRANSLATOR, CURRENT_TRANSLATOR # Importa da SaveState_gui
21
21
from SaveState_gui import SHARED_MEM_KEY , LOCAL_SERVER_NAME # Importa costanti
22
22
23
+ # --- NUOVO IMPORT ---
24
+ try :
25
+ import pyi_splash # type: ignore # Questo modulo esiste solo quando l'app è pacchettizzata con PyInstaller
26
+ except ImportError :
27
+ pyi_splash = None # Imposta a None se non trovato (es. quando non si esegue da bundle)
28
+ # --- FINE NUOVO IMPORT ---
29
+
23
30
# --- Helper Function for Cleanup ---
24
31
def cleanup_instance_lock (local_server , shared_memory ):
25
32
"""Closes the local server and releases the shared memory."""
@@ -172,30 +179,30 @@ def cleanup_instance_lock(local_server, shared_memory):
172
179
173
180
# === Splash Screen ===
174
181
# Only show splash screen if running as a bundled executable
175
- if getattr (sys , 'frozen' , False ):
176
- logging .debug ("Creating and showing splash screen (frozen app)..." )
177
- try :
178
- splash_image_path_relative = "SplashScreen/splash.png"
179
- splash_image_path_absolute = resource_path (splash_image_path_relative )
180
- logging .info (f"Attempting to load splash image from: { splash_image_path_absolute } " ) # Log del percorso calcolato
181
-
182
- splash_pixmap = QPixmap (splash_image_path_absolute )
183
- if splash_pixmap .isNull ():
184
- logging .warning (f"QSplashScreen: Failed to load pixmap from { splash_image_path_absolute } . Image might be missing, corrupt, or path incorrect in bundle." )
185
- else :
186
- logging .info (f"QSplashScreen: Pixmap loaded successfully from { splash_image_path_absolute } ." )
187
- splash = QSplashScreen (splash_pixmap )
188
- splash .setMask (splash_pixmap .mask ()) # Per trasparenza, se l'immagine ha un canale alpha
189
- splash .show ()
190
- # Show initial message IMMEDIATELY after showing splash
191
- splash .showMessage ("Inizializzazione applicazione..." , Qt .AlignmentFlag .AlignBottom | Qt .AlignmentFlag .AlignCenter , Qt .GlobalColor .white )
192
- app .processEvents () # Force display of splash screen NOW
193
- logging .debug ("QSplashScreen: Splash screen shown." )
194
- except Exception as e_splash_load :
195
- logging .error (f"QSplashScreen: Error during splash screen loading/showing: { e_splash_load } " , exc_info = True )
196
- # Non fatale, l'app può continuare senza splash
197
- else :
198
- logging .debug ("Skipping splash screen (not a frozen app)." )
182
+ # if getattr(sys, 'frozen', False):
183
+ # logging.debug("Creating and showing splash screen (frozen app)...")
184
+ # try:
185
+ # splash_image_path_relative = "SplashScreen/splash.png"
186
+ # splash_image_path_absolute = resource_path(splash_image_path_relative)
187
+ # logging.info(f"Attempting to load splash image from: {splash_image_path_absolute}") # Log del percorso calcolato
188
+
189
+ # splash_pixmap = QPixmap(splash_image_path_absolute)
190
+ # if splash_pixmap.isNull():
191
+ # logging.warning(f"QSplashScreen: Failed to load pixmap from {splash_image_path_absolute}. Image might be missing, corrupt, or path incorrect in bundle.")
192
+ # else:
193
+ # logging.info(f"QSplashScreen: Pixmap loaded successfully from {splash_image_path_absolute}.")
194
+ # # splash = QSplashScreen(splash_pixmap)
195
+ # # splash.setMask(splash_pixmap.mask()) # Per trasparenza, se l'immagine ha un canale alpha
196
+ # # splash.show()
197
+ # # # Show initial message IMMEDIATELY after showing splash
198
+ # # splash.showMessage("Inizializzazione applicazione...", Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignCenter, Qt.GlobalColor.white)
199
+ # # app.processEvents() # Force display of splash screen NOW
200
+ # # logging.debug("QSplashScreen: Splash screen shown.")
201
+ # except Exception as e_splash_load:
202
+ # logging.error(f"QSplashScreen: Error during splash screen loading/showing: {e_splash_load}", exc_info=True)
203
+ # # Non fatale, l'app può continuare senza splash
204
+ # else:
205
+ # logging.debug("Skipping splash screen (not a frozen app).")
199
206
# === Fine Splash Screen ===
200
207
201
208
except Exception as e_app_init :
@@ -215,7 +222,7 @@ def cleanup_instance_lock(local_server, shared_memory):
215
222
if not shared_memory .attach ():
216
223
logging .critical (f"Failed to attach to own shared memory: { shared_memory .errorString ()} " )
217
224
# Non possiamo continuare senza memoria condivisa
218
- if splash : splash .close () # Close splash before exit
225
+ # if splash: splash.close() # Close splash before exit
219
226
sys .exit (1 )
220
227
221
228
# Crea server locale per ricevere segnali da altre istanze
@@ -229,7 +236,7 @@ def cleanup_instance_lock(local_server, shared_memory):
229
236
logging .error (f"Unable to start local server '{ LOCAL_SERVER_NAME } ': { local_server .errorString ()} " )
230
237
# Pulisci la memoria condivisa prima di uscire
231
238
cleanup_instance_lock (local_server , shared_memory )
232
- if splash : splash .close () # Close splash before exit
239
+ # if splash: splash.close() # Close splash before exit
233
240
sys .exit (1 ) # Esci se il server non parte
234
241
else :
235
242
logging .info (f"Local server listening on: { local_server .fullServerName ()} " )
@@ -243,18 +250,18 @@ def cleanup_instance_lock(local_server, shared_memory):
243
250
app .aboutToQuit .connect (lambda : cleanup_instance_lock (local_server , shared_memory ))
244
251
245
252
# --- Caricamento Impostazioni (senza applicazione traduttore qui) ---
246
- if splash : # Aggiorna messaggio se lo splash è attivo
247
- splash .showMessage ("Caricamento impostazioni..." , Qt .AlignmentFlag .AlignBottom | Qt .AlignmentFlag .AlignCenter , Qt .GlobalColor .white )
248
- app .processEvents ()
253
+ # if splash: # Aggiorna messaggio se lo splash è attivo
254
+ # splash.showMessage("Caricamento impostazioni...", Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignCenter, Qt.GlobalColor.white)
255
+ # app.processEvents()
249
256
logging .info ("Loading settings..." )
250
257
current_settings , is_first_launch = settings_manager .load_settings ()
251
258
logging .info ("Settings loaded." )
252
259
# --- Fine Caricamento Impostazioni ---
253
260
254
261
# --- Creazione Finestra Principale e gestione primo avvio ---
255
- if splash : # Aggiorna messaggio
256
- splash .showMessage ("Creazione interfaccia utente..." , Qt .AlignmentFlag .AlignBottom | Qt .AlignmentFlag .AlignCenter , Qt .GlobalColor .white )
257
- app .processEvents ()
262
+ # if splash: # Aggiorna messaggio
263
+ # splash.showMessage("Creazione interfaccia utente...", Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignCenter, Qt.GlobalColor.white)
264
+ # app.processEvents()
258
265
# Crea la finestra principale, passando gli handler log
259
266
# qt_log_handler è già definito sopra
260
267
# console_handler è definito sopra
@@ -272,9 +279,9 @@ def cleanup_instance_lock(local_server, shared_memory):
272
279
273
280
274
281
if is_first_launch :
275
- if splash : # Aggiorna messaggio
276
- splash .showMessage ("Configurazione iniziale..." , Qt .AlignmentFlag .AlignBottom | Qt .AlignmentFlag .AlignCenter , Qt .GlobalColor .white )
277
- app .processEvents ()
282
+ # if splash: # Aggiorna messaggio
283
+ # splash.showMessage("Configurazione iniziale...", Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignCenter, Qt.GlobalColor.white)
284
+ # app.processEvents()
278
285
logging .info ("First launch detected, showing settings dialog." )
279
286
# Importa SettingsDialog qui per evitare dipendenze circolari a livello di modulo
280
287
from dialogs .settings_dialog import SettingsDialog
@@ -316,22 +323,23 @@ def cleanup_instance_lock(local_server, shared_memory):
316
323
317
324
window .show ()
318
325
logging .info ("Starting Qt application event loop..." )
319
- if splash : # Chiudi lo splash ora che la finestra è mostrata
320
- splash .finish (window )
321
- logging .debug ("Splash screen finished." )
326
+ if pyi_splash :
327
+ logging .debug ("Closing PyInstaller splash screen..." )
328
+ pyi_splash .close ()
329
+ logging .debug ("Splash screen close command sent." )
322
330
exit_code = app .exec () # Avvia loop eventi GUI
323
331
logging .info (f"Qt application event loop finished with exit code: { exit_code } " )
324
332
325
333
except ImportError as e_imp :
326
334
logging .critical (f"Import error during GUI setup: { e_imp } " , exc_info = True )
327
335
# Prova a chiudere lo splash se esiste
328
- if splash : splash .close ()
336
+ # if splash: splash.close()
329
337
QMessageBox .critical (None , "Errore Import" , f"Errore critico: libreria mancante.\\ n{ e_imp } \\ nL'applicazione non può avviarsi." )
330
338
exit_code = 1
331
339
except Exception as e_gui_init : # Cattura altri errori during l'init della GUI
332
340
logging .critical (f"Fatal error during GUI initialization: { e_gui_init } " , exc_info = True )
333
341
# Prova a chiudere lo splash se esiste
334
- if splash : splash .close ()
342
+ # if splash: splash.close()
335
343
# Prova a mostrare un messaggio di errore base se possibile
336
344
try :
337
345
QMessageBox .critical (None , "Errore Avvio" , f"Errore fatale during l'inizializzazione della GUI:\\ n{ e_gui_init } " )
0 commit comments