paths.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import os
  2. import sys
  3. import ctypes
  4. # ==========================================================
  5. # Gestion universelle des chemins (Python + PyInstaller)
  6. # ==========================================================
  7. def get_base_path() -> str:
  8. """ Retourne la racine du projet (ALIG_Project) """
  9. if getattr(sys, 'frozen', False):
  10. return sys._MEIPASS
  11. return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  12. BASE_DIR = get_base_path()
  13. ASSETS_DIR = os.path.join(BASE_DIR, "assets")
  14. # ==========================================================
  15. # GESTION DU DOSSIER THUMBNAILS (Ecriture)
  16. # ==========================================================
  17. if getattr(sys, 'frozen', False):
  18. # En mode .exe, on crée Thumbnails à côté de l'exécutable (et pas dans le dossier temporaire)
  19. EXE_DIR = os.path.dirname(sys.executable)
  20. THUMBNAILS_DIR = os.path.join(EXE_DIR, "assets", "Thumbnails")
  21. else:
  22. # En mode développement
  23. THUMBNAILS_DIR = os.path.join(ASSETS_DIR, "Thumbnails")
  24. # Création automatique du répertoire Thumbnails si absent
  25. if not os.path.exists(THUMBNAILS_DIR):
  26. try:
  27. os.makedirs(THUMBNAILS_DIR, exist_ok=True)
  28. except Exception as e:
  29. print(f"Impossible de créer le dossier Thumbnails : {e}")
  30. # ==========================================================
  31. # CHEMINS DES RESSOURCES (Strings uniquement)
  32. # ==========================================================
  33. LOGO_ALIG = os.path.join(ASSETS_DIR, "logo_alig.ico")
  34. # --- SVG (Icônes UI) ---
  35. # On utilise un dictionnaire pour centraliser, c'est plus propre
  36. SVG_ICONS = {
  37. "HOME": os.path.join(ASSETS_DIR, "home.svg"),
  38. "RASTER": os.path.join(ASSETS_DIR, "raster.svg"),
  39. "DITHER": os.path.join(ASSETS_DIR, "dither.svg"),
  40. "INFILL": os.path.join(ASSETS_DIR, "vectorinfill.svg"),
  41. "GCODE": os.path.join(ASSETS_DIR, "loupe.svg"),
  42. "LATENCY": os.path.join(ASSETS_DIR, "latency_calibration.svg"),
  43. "LINESTEP": os.path.join(ASSETS_DIR, "linestep_calibration.svg"),
  44. "OVERSCAN": os.path.join(ASSETS_DIR, "overscan_calibration.svg"),
  45. "POWER": os.path.join(ASSETS_DIR, "power_calibration.svg"),
  46. "ARROW_DOWN": os.path.join(ASSETS_DIR, "arrow_down.svg"),
  47. "CIRCLE": os.path.join(ASSETS_DIR, "circle.svg"),
  48. "GEAR": os.path.join(ASSETS_DIR, "gear.svg"),
  49. "PLAY": os.path.join(ASSETS_DIR, "play.svg"),
  50. "REWIND": os.path.join(ASSETS_DIR, "rewind.svg"),
  51. "SKIPTOEND": os.path.join(ASSETS_DIR, "skiptoend.svg"),
  52. "PAUSE": os.path.join(ASSETS_DIR, "pause.svg"),
  53. "RERUN": os.path.join(ASSETS_DIR, "rerun.svg"),
  54. "FIT": os.path.join(ASSETS_DIR, "fit.svg"),
  55. }
  56. # --- PNG (Images d'explications / Previews) ---
  57. EXPLAIN_PNG = {
  58. "LATENCY_DARK": os.path.join(ASSETS_DIR, "latency_calibration_explain_white.png"),
  59. "LINESTEP_DARK": os.path.join(ASSETS_DIR, "linestep_explain_white.png"),
  60. "POWER_DARK": os.path.join(ASSETS_DIR, "power_explain_white.png"),
  61. "LATENCY_LIGHT": os.path.join(ASSETS_DIR, "latency_calibration_explain_black.png"),
  62. "LINESTEP_LIGHT": os.path.join(ASSETS_DIR, "linestep_explain_black.png"),
  63. "POWER_LIGHT": os.path.join(ASSETS_DIR, "power_explain_black.png"),
  64. }
  65. # ==========================================================
  66. # VÉRIFICATION DES ASSETS
  67. # ==========================================================
  68. def check_assets():
  69. """ Vérifie la présence des fichiers critiques au démarrage """
  70. missing = []
  71. # 1. Vérifier tous les SVG
  72. for name, path in SVG_ICONS.items():
  73. if not os.path.exists(path):
  74. missing.append(f"Icône SVG: {name} ({os.path.basename(path)})")
  75. # 2. Vérifier tous les PNG d'explication
  76. for name, path in EXPLAIN_PNG.items():
  77. if not os.path.exists(path):
  78. missing.append(f"Image PNG: {name} ({os.path.basename(path)})")
  79. # 3. Vérifier les ressources isolées (Logo, etc.)
  80. if not os.path.exists(LOGO_ALIG):
  81. missing.append("Icône de l'application (logo_alig.ico)")
  82. if missing:
  83. msg = "Certains fichiers ressources sont introuvables :\n\n" + "\n".join(missing)
  84. # MessageBoxW pour une alerte Windows native avant même que l'interface ne charge
  85. ctypes.windll.user32.MessageBoxW(0, msg, "Erreur de Ressources", 0x10)