first commit
This commit is contained in:
commit
9a61d20a57
89
.gitignore
vendored
Normal file
89
.gitignore
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
# Fichiers système
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
desktop.ini
|
||||
|
||||
# Dossiers de build et distributions
|
||||
/build/
|
||||
/dist/
|
||||
/out/
|
||||
/release/
|
||||
*.exe
|
||||
*.msi
|
||||
*.dmg
|
||||
*.pkg
|
||||
*.app
|
||||
|
||||
# Fichiers d'environnement et de configuration
|
||||
.env
|
||||
.env.local
|
||||
.env.development
|
||||
.env.test
|
||||
.env.production
|
||||
LINenv*/
|
||||
WINenv*/
|
||||
MACenv*/
|
||||
|
||||
# Fichiers de dépendances
|
||||
/node_modules/
|
||||
/.pnp/
|
||||
.pnp.js
|
||||
/vendor/
|
||||
/packages/
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
*.so
|
||||
.Python
|
||||
|
||||
# Logs et bases de données
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
*.sqlite
|
||||
*.db
|
||||
|
||||
# Fichiers d'IDE et d'éditeurs
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
*.sublime-workspace
|
||||
*.sublime-project
|
||||
.vs/
|
||||
*.user
|
||||
*.userosscache
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
# Fichiers temporaires
|
||||
/tmp/
|
||||
/temp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*~
|
||||
|
||||
# Fichiers spécifiques à l'application
|
||||
# Ne pas ignorer le fichier config.json
|
||||
!config.json
|
||||
|
||||
# Dossier de cache
|
||||
.cache/
|
||||
.parcel-cache/
|
||||
|
||||
# Fichiers de couverture de test
|
||||
coverage/
|
||||
.nyc_output/
|
||||
.coverage
|
||||
htmlcov/
|
||||
|
||||
# Autres
|
||||
.vercel
|
||||
.next
|
||||
.nuxt
|
||||
.serverless/
|
||||
|
67
BUILD.spec
Normal file
67
BUILD.spec
Normal file
@ -0,0 +1,67 @@
|
||||
# -*- mode: python ; coding: utf-8 -*-
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
# Load config.json
|
||||
config_path = Path("config.json")
|
||||
with config_path.open("r", encoding="utf-8") as f:
|
||||
config = json.load(f)
|
||||
|
||||
# Extract values
|
||||
version = config.get("app_version", "0.0.0")
|
||||
arch = config.get("architecture", "x64")
|
||||
python_version = config.get("python_version", "3.x")
|
||||
os = config.get("app_os", "Windows")
|
||||
name = config.get("app_name", "Application")
|
||||
|
||||
# Construct dynamic name
|
||||
name = f"{name}-{os}-{arch}-v{version}"
|
||||
|
||||
# Optional icon path (can still be overridden via environment if needed)
|
||||
from os import getenv
|
||||
icon = getenv("ICON_PATH", "")
|
||||
|
||||
# Data files to bundle
|
||||
datas = [
|
||||
("data/assets/*", "data/assets/"),
|
||||
("data/", "data/")
|
||||
]
|
||||
binaries = []
|
||||
|
||||
a = Analysis(
|
||||
["main.py"],
|
||||
pathex=[],
|
||||
binaries=binaries,
|
||||
datas=datas,
|
||||
hiddenimports=[],
|
||||
hookspath=[],
|
||||
hooksconfig={},
|
||||
runtime_hooks=[],
|
||||
excludes=[],
|
||||
noarchive=False,
|
||||
optimize=0,
|
||||
)
|
||||
|
||||
pyz = PYZ(a.pure)
|
||||
|
||||
exe = EXE(
|
||||
pyz,
|
||||
a.scripts,
|
||||
a.binaries,
|
||||
a.datas,
|
||||
[],
|
||||
name=name,
|
||||
icon=icon if icon else None,
|
||||
debug=False,
|
||||
bootloader_ignore_signals=False,
|
||||
strip=False,
|
||||
upx=True,
|
||||
upx_exclude=[],
|
||||
runtime_tmpdir=None,
|
||||
console=False,
|
||||
disable_windowed_traceback=False,
|
||||
argv_emulation=False,
|
||||
target_arch=None,
|
||||
codesign_identity=None,
|
||||
entitlements_file=None,
|
||||
)
|
9
LICENSE
Normal file
9
LICENSE
Normal file
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 LouisMazin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
39
app/core/language_manager.py
Normal file
39
app/core/language_manager.py
Normal file
@ -0,0 +1,39 @@
|
||||
from json import JSONDecodeError, load
|
||||
from os import listdir, path
|
||||
from typing import Dict
|
||||
import app.utils.paths as paths
|
||||
|
||||
class LanguageManager:
|
||||
"""
|
||||
Gère les traductions pour l'application.
|
||||
Charge les fichiers JSON de langue dans data/lang/, permet
|
||||
de changer la langue courante, et récupérer des textes traduits.
|
||||
"""
|
||||
def __init__(self, settings_manager) -> None:
|
||||
self.translations: Dict[str, Dict[str, str]] = {}
|
||||
self.settings_manager = settings_manager
|
||||
|
||||
self.load_all_translations()
|
||||
|
||||
def load_all_translations(self) -> None:
|
||||
"""
|
||||
Charge tous les fichiers JSON dans data/lang/ comme dictionnaires.
|
||||
"""
|
||||
lang_dir = paths.get_lang_path()
|
||||
|
||||
for filename in listdir(lang_dir):
|
||||
if filename.endswith(".json"):
|
||||
lang_code = filename[:-5] # strip .json
|
||||
file_path = path.join(lang_dir, filename)
|
||||
try:
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
self.translations[lang_code] = load(f)
|
||||
except JSONDecodeError as e:
|
||||
pass
|
||||
|
||||
def get_text(self, key: str) -> str:
|
||||
"""
|
||||
Retourne le texte traduit correspondant à la clé dans la langue courante.
|
||||
Si la clé n'existe pas, retourne la clé elle-même.
|
||||
"""
|
||||
return self.translations.get(self.settings_manager.get_language(), {}).get(key, key)
|
32
app/core/main_manager.py
Normal file
32
app/core/main_manager.py
Normal file
@ -0,0 +1,32 @@
|
||||
from app.core.observer_manager import ObserverManager, NotificationType
|
||||
from app.core.language_manager import LanguageManager
|
||||
from app.core.theme_manager import ThemeManager
|
||||
from app.core.settings_manager import SettingsManager
|
||||
|
||||
class MainManager:
|
||||
_instance = None
|
||||
def __init__(self):
|
||||
if MainManager._instance is not None:
|
||||
raise Exception("This class is a singleton!")
|
||||
else:
|
||||
MainManager._instance = self
|
||||
self.observer_manager = ObserverManager()
|
||||
self.theme_manager = ThemeManager()
|
||||
self.settings_manager = SettingsManager(self.observer_manager,self.theme_manager)
|
||||
self.language_manager = LanguageManager(self.settings_manager)
|
||||
|
||||
def get_observer_manager(self):
|
||||
return self.observer_manager
|
||||
def get_theme_manager(self):
|
||||
return self.theme_manager
|
||||
def get_settings_manager(self):
|
||||
return self.settings_manager
|
||||
def get_language_manager(self):
|
||||
return self.language_manager
|
||||
|
||||
@classmethod
|
||||
def get_instance(cls):
|
||||
if cls._instance is None:
|
||||
cls._instance = cls()
|
||||
return cls._instance
|
||||
|
39
app/core/observer_manager.py
Normal file
39
app/core/observer_manager.py
Normal file
@ -0,0 +1,39 @@
|
||||
from typing import Callable, Dict, List, Any
|
||||
|
||||
class NotificationType:
|
||||
THEME = 0
|
||||
LANGUAGE = 1
|
||||
|
||||
class ObserverManager:
|
||||
"""
|
||||
Gestionnaire d'observateurs pour gérer les événements et notifier les abonnés.
|
||||
Chaque événement est identifié par une clé (string), et les abonnés sont des callbacks.
|
||||
"""
|
||||
def __init__(self):
|
||||
self.observers: Dict[str, List[Callable[[Any], None]]] = {}
|
||||
|
||||
def subscribe(self, event: str, callback: Callable[[Any], None]) -> None:
|
||||
"""
|
||||
Ajoute un callback à la liste des abonnés pour l'événement donné.
|
||||
"""
|
||||
if event not in self.observers:
|
||||
self.observers[event] = []
|
||||
if callback not in self.observers[event]:
|
||||
self.observers[event].append(callback)
|
||||
|
||||
def unsubscribe(self, event: str, callback: Callable[[Any], None]) -> None:
|
||||
"""
|
||||
Retire un callback de la liste des abonnés pour l'événement donné.
|
||||
"""
|
||||
if event in self.observers and callback in self.observers[event]:
|
||||
self.observers[event].remove(callback)
|
||||
if not self.observers[event]:
|
||||
del self.observers[event]
|
||||
|
||||
def notify(self, event: NotificationType) -> None:
|
||||
"""
|
||||
Notifie tous les abonnés de l'événement donné, en leur passant la donnée.
|
||||
"""
|
||||
if event in self.observers:
|
||||
for callback in self.observers[event]:
|
||||
callback()
|
76
app/core/settings_manager.py
Normal file
76
app/core/settings_manager.py
Normal file
@ -0,0 +1,76 @@
|
||||
from PyQt6.QtCore import QSettings
|
||||
from app.core.observer_manager import NotificationType
|
||||
from os import path
|
||||
import app.utils.paths as paths
|
||||
import json
|
||||
|
||||
class SettingsManager:
|
||||
"""
|
||||
Gestion des paramètres utilisateurs avec sauvegarde persistante via QSettings.
|
||||
Notifie les changements via ObserverManager.
|
||||
"""
|
||||
def __init__(self, observer_manager, theme_manager):
|
||||
self.observer_manager = observer_manager
|
||||
self.theme_manager = theme_manager
|
||||
|
||||
# Load default settings from JSON file
|
||||
defaults_path = path.join(paths.get_data_dir(), "others", "defaults_settings.json")
|
||||
with open(defaults_path, 'r', encoding='utf-8') as f:
|
||||
self.default_settings = json.load(f)
|
||||
|
||||
config_path = path.join(paths.get_current_dir(), "config.json")
|
||||
with open(config_path, 'r', encoding='utf-8') as f:
|
||||
self.config = json.load(f)
|
||||
|
||||
self.settings = QSettings(path.join(paths.get_user_data_dir(self.get_config("app_name")), self.get_config("app_name") + ".ini"), QSettings.Format.IniFormat)
|
||||
|
||||
self.theme_manager.set_theme(self.get_theme())
|
||||
|
||||
# Config
|
||||
def get_config(self, key: str):
|
||||
return self.config.get(key, None)
|
||||
|
||||
# Theme
|
||||
def get_theme(self) -> str:
|
||||
return self.settings.value("theme", self.default_settings.get("theme"))
|
||||
|
||||
def set_theme(self, mode: str) -> None:
|
||||
if mode != self.get_theme():
|
||||
self.settings.setValue("theme", mode)
|
||||
self.theme_manager.set_theme(mode)
|
||||
self.observer_manager.notify(NotificationType.THEME)
|
||||
|
||||
# Language
|
||||
def get_language(self) -> str:
|
||||
return self.settings.value("lang", self.default_settings.get("lang"))
|
||||
|
||||
def set_language(self, lang_code: str) -> None:
|
||||
if lang_code != self.get_language():
|
||||
self.settings.setValue("lang", lang_code)
|
||||
self.observer_manager.notify(NotificationType.LANGUAGE)
|
||||
|
||||
# Window size and fullscreen
|
||||
def get_window_size(self) -> dict:
|
||||
return self.settings.value("window_size", self.default_settings.get("window_size"))
|
||||
|
||||
def set_window_size(self, width: int, height: int) -> None:
|
||||
current_size = self.get_window_size()
|
||||
if current_size["width"] != width or current_size["height"] != height:
|
||||
new_size = {"width": width, "height": height}
|
||||
self.settings.setValue("window_size", new_size)
|
||||
|
||||
def get_fullscreen(self) -> bool:
|
||||
return self.settings.value("fullscreen", self.default_settings.get("fullscreen"))
|
||||
|
||||
def set_fullscreen(self, fullscreen: bool, width: int, height: int):
|
||||
self.settings.setValue("fullscreen", fullscreen)
|
||||
self.settings.setValue("fullscreen_size", {"width": width, "height": height})
|
||||
|
||||
def get_fullscreen_size(self) -> dict:
|
||||
return self.settings.value("fullscreen_size", self.default_settings.get("fullscreen_size"))
|
||||
|
||||
def set_fullscreen_size(self, width: int, height: int) -> None:
|
||||
current_size = self.get_fullscreen_size()
|
||||
if current_size["width"] != width or current_size["height"] != height:
|
||||
new_size = {"width": width, "height": height}
|
||||
self.settings.setValue("fullscreen_size", new_size)
|
147
app/core/theme_manager.py
Normal file
147
app/core/theme_manager.py
Normal file
@ -0,0 +1,147 @@
|
||||
import app.utils.paths as paths
|
||||
import os, json
|
||||
|
||||
class Theme:
|
||||
def __init__(self, name: str, colors: dict):
|
||||
self.name = name
|
||||
self.colors = colors
|
||||
|
||||
def get_color(self, element: str) -> str:
|
||||
return self.colors.get(element, "#FFFFFF")
|
||||
|
||||
class ThemeManager:
|
||||
|
||||
def __init__(self):
|
||||
theme_path = os.path.join(paths.get_data_dir(), "themes")
|
||||
self.themes = []
|
||||
for theme_file in os.listdir(theme_path):
|
||||
if theme_file.endswith(".json"):
|
||||
with open(os.path.join(theme_path, theme_file), 'r', encoding='utf-8') as f:
|
||||
theme_data = json.load(f)
|
||||
theme = Theme(theme_data["theme_name"], theme_data["colors"])
|
||||
self.themes.append(theme)
|
||||
self.current_theme = self.themes[0]
|
||||
|
||||
def set_theme(self, theme: str) -> None:
|
||||
if theme != self.current_theme.name:
|
||||
self.current_theme = next((t for t in self.themes if t.name == theme), self.current_theme)
|
||||
|
||||
def get_theme(self) -> str:
|
||||
return self.current_theme
|
||||
|
||||
def get_sheet(self) -> str:
|
||||
return f"""
|
||||
QWidget {{
|
||||
background-color: {self.current_theme.get_color("background")};
|
||||
color: {self.current_theme.get_color("font_color")};
|
||||
}}
|
||||
QPushButton {{
|
||||
background-color: #0A84FF;
|
||||
color: {self.current_theme.get_color("font_color")};
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
}}
|
||||
QPushButton:hover {{
|
||||
background-color: #007AFF;
|
||||
}}
|
||||
QLineEdit {{
|
||||
border: 1px solid #3C3C3E;
|
||||
border-radius: 8px;
|
||||
padding: 10px;
|
||||
font-size: 14px;
|
||||
background-color: {self.current_theme.get_color("background2")};
|
||||
color: {self.current_theme.get_color("font_color")};
|
||||
}}
|
||||
QLabel {{
|
||||
color: {self.current_theme.get_color("font_color")};
|
||||
}}
|
||||
QProgressBar {{
|
||||
border: 1px solid #3C3C3E;
|
||||
border-radius: 5px;
|
||||
background-color: {self.current_theme.get_color("background2")};
|
||||
text-align: center;
|
||||
color: {self.current_theme.get_color("font_color")};
|
||||
}}
|
||||
QProgressBar::chunk {{
|
||||
background-color: #0A84FF;
|
||||
border-radius: 3px;
|
||||
}}
|
||||
QFrame {{
|
||||
background-color: {self.current_theme.get_color("background2")};
|
||||
border: none;
|
||||
}}
|
||||
QFrame#indicator_bar {{
|
||||
background-color: #0A84FF;
|
||||
}}
|
||||
QScrollBar:vertical {{
|
||||
border: none;
|
||||
background: #E0E0E0;
|
||||
width: 8px;
|
||||
margin: 0px;
|
||||
}}
|
||||
QScrollBar::handle:vertical {{
|
||||
background: #0A84FF;
|
||||
border-radius: 4px;
|
||||
min-height: 20px;
|
||||
}}
|
||||
QScrollBar::handle:vertical:hover {{
|
||||
background: #3B9CFF;
|
||||
}}
|
||||
QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {{
|
||||
border: none;
|
||||
background: none;
|
||||
height: 0px;
|
||||
}}
|
||||
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {{
|
||||
background: none;
|
||||
}}
|
||||
#drag_area {{
|
||||
border: 2px dashed #3498db; border-radius: 10px;
|
||||
}}
|
||||
QSlider::groove:horizontal {{
|
||||
border: 1px solid #3a9bdc;
|
||||
height: 10px;
|
||||
background: transparent;
|
||||
border-radius: 5px;
|
||||
}}
|
||||
QSlider::sub-page:horizontal {{
|
||||
background: #3a9bdc;
|
||||
border-radius: 5px;
|
||||
}}
|
||||
QSlider::add-page:horizontal {{
|
||||
background: {self.current_theme.get_color("background3")};
|
||||
border-radius: 5px;
|
||||
}}
|
||||
QSlider::handle:horizontal {{
|
||||
background: white;
|
||||
border: 2px solid #3a9bdc;
|
||||
width: 14px;
|
||||
margin: -4px 0;
|
||||
border-radius: 7px;
|
||||
}}
|
||||
QComboBox {{
|
||||
padding: 5px;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
min-height: 30px;
|
||||
}}
|
||||
QComboBox QAbstractItemView {{
|
||||
border-radius: 8px;
|
||||
padding: 0px;
|
||||
}}
|
||||
QComboBox QAbstractItemView::item {{
|
||||
padding: 12px 15px;
|
||||
border: none;
|
||||
margin: 0px;
|
||||
min-height: 20px;
|
||||
}}
|
||||
QComboBox QAbstractItemView::item:hover {{
|
||||
background-color: {self.current_theme.get_color("background3")};
|
||||
color: {self.current_theme.get_color("font_color")};
|
||||
}}
|
||||
QComboBox QAbstractItemView::item:selected {{
|
||||
color: {self.current_theme.get_color("font_color")};
|
||||
}}
|
||||
"""
|
43
app/ui/main_window.py
Normal file
43
app/ui/main_window.py
Normal file
@ -0,0 +1,43 @@
|
||||
from PyQt6.QtWidgets import QMainWindow
|
||||
from PyQt6.QtGui import QIcon
|
||||
from PyQt6.QtWidgets import QApplication
|
||||
from app.core.main_manager import MainManager, NotificationType
|
||||
from app.ui.widgets.tabs_widget import TabsWidget, MenuDirection, ButtonPosition, BorderSide
|
||||
from app.ui.windows.settings_window import SettingsWindow
|
||||
import app.utils.paths as paths
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.main_manager = MainManager()
|
||||
self.language_manager = self.main_manager.get_language_manager()
|
||||
self.theme_manager = self.main_manager.get_theme_manager()
|
||||
self.settings_manager = self.main_manager.get_settings_manager()
|
||||
self.observer_manager = self.main_manager.get_observer_manager()
|
||||
self.observer_manager.subscribe(NotificationType.THEME, self.update_theme)
|
||||
|
||||
# Configurer la fenêtre avant de créer les widgets
|
||||
app = QApplication.instance()
|
||||
self.settings_manager.dpi = app.primaryScreen().devicePixelRatio()
|
||||
size = app.primaryScreen().size()
|
||||
self.settings_manager.minScreenSize = min(size.height(),size.width())
|
||||
configWidth = int(self.settings_manager.get_fullscreen_size()["width"] if self.settings_manager.get_fullscreen() else self.settings_manager.get_window_size()["width"] /self.settings_manager.dpi)
|
||||
configHeight = int(self.settings_manager.get_fullscreen_size()["height"] if self.settings_manager.get_fullscreen() else self.settings_manager.get_window_size()["height"] /self.settings_manager.dpi)
|
||||
self.setMinimumSize(600, 400)
|
||||
self.resize(configWidth, configHeight)
|
||||
self.setWindowTitle(self.settings_manager.get_config("app_name"))
|
||||
self.setStyleSheet(self.theme_manager.get_sheet())
|
||||
self.setWindowIcon(QIcon(paths.get_asset_path("icon")))
|
||||
self.setup_ui()
|
||||
|
||||
def setup_ui(self):
|
||||
self.side_menu = TabsWidget(self,MenuDirection.HORIZONTAL,70,None,10,1,BorderSide.TOP)
|
||||
|
||||
self.settings_window = SettingsWindow(self)
|
||||
self.side_menu.add_widget(self.settings_window,"",paths.get_asset_svg_path("settings"), position=ButtonPosition.CENTER)
|
||||
|
||||
self.setCentralWidget(self.side_menu)
|
||||
|
||||
def update_theme(self):
|
||||
self.setStyleSheet(self.theme_manager.get_sheet())
|
477
app/ui/widgets/tabs_widget.py
Normal file
477
app/ui/widgets/tabs_widget.py
Normal file
@ -0,0 +1,477 @@
|
||||
from PyQt6.QtWidgets import QLayout, QWidget, QHBoxLayout, QVBoxLayout, QPushButton, QStackedWidget, QSizePolicy, QSpacerItem
|
||||
from PyQt6.QtGui import QIcon
|
||||
from PyQt6.QtCore import QSize
|
||||
from enum import Enum
|
||||
from app.core.main_manager import MainManager, NotificationType
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
class MenuDirection(Enum):
|
||||
HORIZONTAL = 0
|
||||
VERTICAL = 1
|
||||
|
||||
class ButtonPosition(Enum):
|
||||
START = 0 # Au début (aligné à gauche/haut)
|
||||
END = 1 # À la fin (aligné à droite/bas)
|
||||
CENTER = 2 # Au centre
|
||||
AFTER = 3 # Après un bouton spécifique
|
||||
|
||||
class BorderSide(Enum):
|
||||
LEFT = "left"
|
||||
RIGHT = "right"
|
||||
TOP = "top"
|
||||
BOTTOM = "bottom"
|
||||
NONE = None
|
||||
|
||||
class TabsWidget(QWidget):
|
||||
def __init__(self, parent=None, direction=MenuDirection.VERTICAL, menu_width=80, onTabChange=None, spacing=10, button_size_ratio=0.8, border_side=BorderSide.LEFT):
|
||||
super().__init__(parent)
|
||||
self.main_manager = MainManager.get_instance()
|
||||
self.theme_manager = self.main_manager.get_theme_manager()
|
||||
self.observer_manager = self.main_manager.get_observer_manager()
|
||||
self.observer_manager.subscribe(NotificationType.THEME, self.set_theme)
|
||||
self.direction = direction
|
||||
self.menu_width = menu_width
|
||||
self.button_size_ratio = button_size_ratio # Default ratio for button size relative to menu width
|
||||
self.onTabChange = onTabChange
|
||||
self.border_side = border_side # Store border side preference
|
||||
self.buttons = []
|
||||
self.widgets = []
|
||||
self.button_positions = []
|
||||
self.button_size_ratios = [] # Individual ratios for each button
|
||||
|
||||
# Track alignment zones
|
||||
self.start_buttons = []
|
||||
self.center_buttons = []
|
||||
self.end_buttons = []
|
||||
|
||||
# Icon Colors
|
||||
self.selected_icon_color = self.theme_manager.current_theme.get_color("selected_icon")
|
||||
self.unselected_icon_color = self.theme_manager.current_theme.get_color("unselected_icon")
|
||||
self.selected_border_icon_color = self.theme_manager.current_theme.get_color("selected_border_icon")
|
||||
self.hover_icon_color = self.theme_manager.current_theme.get_color("hover_icon")
|
||||
|
||||
# Spacer items for alignment
|
||||
self.left_spacer = None
|
||||
self.center_spacer = None
|
||||
self.right_spacer = None
|
||||
self.spacing = spacing
|
||||
self._setup_ui()
|
||||
|
||||
def _setup_ui(self):
|
||||
"""Setup the main layout based on direction"""
|
||||
if self.direction == MenuDirection.HORIZONTAL:
|
||||
self.main_layout = QVBoxLayout(self)
|
||||
self.button_layout = QHBoxLayout()
|
||||
else: # VERTICAL
|
||||
self.main_layout = QHBoxLayout(self)
|
||||
self.button_layout = QVBoxLayout()
|
||||
|
||||
# Remove all spacing and margins
|
||||
self.main_layout.setSpacing(0)
|
||||
self.main_layout.setContentsMargins(0, 0, 0, 0)
|
||||
self.button_layout.setSpacing(self.spacing)
|
||||
self.button_layout.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
self.stacked_widget = QStackedWidget()
|
||||
# Create button container widget
|
||||
self.button_container = QWidget()
|
||||
self.button_container.setLayout(self.button_layout)
|
||||
|
||||
# Remove all margins from button container
|
||||
self.button_container.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
# Set minimum size for button container to prevent shrinking
|
||||
if self.direction == MenuDirection.VERTICAL:
|
||||
self.button_container.setMaximumWidth(self.menu_width)
|
||||
self.button_container.setMinimumWidth(self.menu_width)
|
||||
self.button_container.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Expanding)
|
||||
else:
|
||||
self.button_container.setMinimumHeight(self.menu_width)
|
||||
self.button_container.setMaximumHeight(self.menu_width)
|
||||
self.button_container.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
|
||||
|
||||
# Initialize spacers for alignment zones
|
||||
self._setup_alignment_zones()
|
||||
|
||||
# Add widgets to main layout based on direction
|
||||
if self.direction == MenuDirection.HORIZONTAL:
|
||||
self.main_layout.addWidget(self.button_container)
|
||||
self.main_layout.addWidget(self.stacked_widget)
|
||||
else: # VERTICAL
|
||||
self.main_layout.addWidget(self.button_container)
|
||||
self.main_layout.addWidget(self.stacked_widget)
|
||||
|
||||
self.setLayout(self.main_layout)
|
||||
|
||||
def _setup_alignment_zones(self):
|
||||
"""Setup spacers to create alignment zones"""
|
||||
# Create spacers
|
||||
if self.direction == MenuDirection.HORIZONTAL:
|
||||
self.left_spacer = QSpacerItem(0, 0, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)
|
||||
self.center_spacer = QSpacerItem(0, 0, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)
|
||||
else:
|
||||
self.left_spacer = QSpacerItem(0, 0, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding)
|
||||
self.center_spacer = QSpacerItem(0, 0, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding)
|
||||
|
||||
# Add spacers to layout (no right spacer so END buttons stick to edge)
|
||||
self.button_layout.addSpacerItem(self.left_spacer) # Before center
|
||||
self.button_layout.addSpacerItem(self.center_spacer) # After center
|
||||
# Removed right_spacer so END buttons are at the edge
|
||||
|
||||
# Add a widget on the menu, just the widget, with position
|
||||
def add_random_widget(self, widget, position=ButtonPosition.END):
|
||||
"""Add a widget directly to the menu at the specified position"""
|
||||
if isinstance(widget, QLayout):
|
||||
# If it's a layout, wrap it in a container widget
|
||||
container_widget = QWidget()
|
||||
container_widget.setLayout(widget)
|
||||
container_widget.setContentsMargins(0, 0, 0, 0)
|
||||
self._insert_widget_with_alignment(container_widget, position)
|
||||
return container_widget
|
||||
else:
|
||||
# If it's already a widget, insert it directly
|
||||
self._insert_widget_with_alignment(widget, position)
|
||||
return widget
|
||||
|
||||
def add_random_layout(self, layout, position=ButtonPosition.END):
|
||||
"""Add a layout at the specified position in the button layout"""
|
||||
# Create a container widget for the layout
|
||||
container_widget = QWidget()
|
||||
container_widget.setLayout(layout)
|
||||
container_widget.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
# Insert the container widget at the specified position
|
||||
self._insert_widget_with_alignment(container_widget, position)
|
||||
return container_widget
|
||||
|
||||
def _insert_widget_with_alignment(self, widget, position):
|
||||
"""Insert any widget at the specified position with proper visual alignment"""
|
||||
if position == ButtonPosition.START:
|
||||
# Insert at the beginning (before left spacer)
|
||||
self.button_layout.insertWidget(0, widget)
|
||||
|
||||
elif position == ButtonPosition.CENTER:
|
||||
# Insert in center zone (after left spacer, before center spacer)
|
||||
center_start_index = self._get_spacer_index(self.left_spacer) + 1
|
||||
insert_index = center_start_index + len(self.center_buttons)
|
||||
self.button_layout.insertWidget(insert_index, widget)
|
||||
|
||||
elif position == ButtonPosition.END:
|
||||
# Insert in end zone (after center spacer, at the end)
|
||||
end_start_index = self._get_spacer_index(self.center_spacer) + 1
|
||||
insert_index = end_start_index + len(self.end_buttons)
|
||||
self.button_layout.insertWidget(insert_index, widget)
|
||||
|
||||
def add_widget(self, widget, button_text, icon_path=None, position=ButtonPosition.END, after_button_index=None, button_size_ratio=None):
|
||||
"""Add a widget with its corresponding button at specified position"""
|
||||
# Store original icon path for theme updates
|
||||
if not hasattr(self, '_original_icon_paths'):
|
||||
self._original_icon_paths = []
|
||||
|
||||
# Create button
|
||||
if icon_path:
|
||||
colored_icon = self.apply_color_to_svg_icon(icon_path, self.unselected_icon_color)
|
||||
button = QPushButton(colored_icon, button_text)
|
||||
self._original_icon_paths.append(icon_path)
|
||||
else:
|
||||
button = QPushButton(button_text)
|
||||
self._original_icon_paths.append(None)
|
||||
|
||||
button.setObjectName("menu_button")
|
||||
button.setCheckable(True)
|
||||
|
||||
# Store button size ratio (use provided ratio or default)
|
||||
ratio = button_size_ratio if button_size_ratio is not None else self.button_size_ratio
|
||||
self.button_size_ratios.append(ratio)
|
||||
|
||||
# Make button square with specified ratio
|
||||
self._style_square_button(button)
|
||||
|
||||
# Add to collections first
|
||||
widget_index = len(self.widgets)
|
||||
self.buttons.append(button)
|
||||
self.widgets.append(widget)
|
||||
self.button_positions.append(position)
|
||||
|
||||
# Connect button to switch function
|
||||
button.clicked.connect(lambda checked, idx=widget_index: self.switch_to_tab(idx))
|
||||
|
||||
# Add widget to stacked widget
|
||||
self.stacked_widget.addWidget(widget)
|
||||
|
||||
# Insert button at specified position with proper alignment
|
||||
self._insert_button_with_alignment(button, position, after_button_index)
|
||||
|
||||
# Select first tab by default
|
||||
if len(self.buttons) == 1:
|
||||
self.switch_to_tab(0)
|
||||
|
||||
return widget_index
|
||||
|
||||
def _style_square_button(self, button):
|
||||
# Set size policy
|
||||
button.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)
|
||||
|
||||
# Create border style based on border_side setting
|
||||
border_style = self._get_border_style()
|
||||
button.setStyleSheet(border_style)
|
||||
|
||||
# Install event filter for hover detection
|
||||
button.installEventFilter(self)
|
||||
|
||||
# Calculate initial size (will be updated in resizeEvent)
|
||||
self._update_button_size(button)
|
||||
|
||||
# Store reference for resize updates
|
||||
if not hasattr(self, '_square_buttons'):
|
||||
self._square_buttons = []
|
||||
self._square_buttons.append(button)
|
||||
|
||||
def eventFilter(self, obj : QPushButton, event):
|
||||
"""Handle hover events for buttons"""
|
||||
if obj in self.buttons:
|
||||
if event.type() == event.Type.Enter:
|
||||
# Mouse entered button
|
||||
obj.setIcon(self.apply_color_to_svg_icon(self._original_icon_paths[self.buttons.index(obj)],self.hover_icon_color))
|
||||
elif event.type() == event.Type.Leave:
|
||||
# Mouse left button
|
||||
obj.setIcon(self.apply_color_to_svg_icon(self._original_icon_paths[self.buttons.index(obj)],self.unselected_icon_color if not obj.isChecked() else self.selected_icon_color))
|
||||
|
||||
return super().eventFilter(obj, event)
|
||||
|
||||
def _get_border_style(self):
|
||||
"""Generate CSS border style based on border_side setting"""
|
||||
if self.border_side == BorderSide.NONE or self.border_side is None:
|
||||
return f"""
|
||||
QPushButton {{
|
||||
border-radius: 0px;
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
}}
|
||||
QPushButton[selected="true"] {{
|
||||
border-radius: 0px;
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
}}
|
||||
"""
|
||||
|
||||
return f"""
|
||||
QPushButton {{
|
||||
border-radius: 0px;
|
||||
background-color: transparent;
|
||||
border-{self.border_side.value}: 3px solid transparent;
|
||||
}}
|
||||
QPushButton[selected="true"] {{
|
||||
border-radius: 0px;
|
||||
background-color: transparent;
|
||||
border-{self.border_side.value}: 3px solid {self.selected_border_icon_color};
|
||||
}}
|
||||
"""
|
||||
|
||||
def _update_button_size(self, button):
|
||||
"""Update button size based on menu width and button's individual ratio"""
|
||||
# Find the button's index to get its specific ratio
|
||||
button_index = -1
|
||||
for i, btn in enumerate(self.buttons):
|
||||
if btn == button:
|
||||
button_index = i
|
||||
break
|
||||
|
||||
if button_index == -1:
|
||||
return # Button not found
|
||||
|
||||
# Get the specific ratio for this button
|
||||
ratio = self.button_size_ratios[button_index] if button_index < len(self.button_size_ratios) else self.button_size_ratio
|
||||
|
||||
button_size = int(self.menu_width * ratio)
|
||||
button.setFixedSize(QSize(button_size, button_size))
|
||||
# Set proportional icon size
|
||||
icon_size = int(button_size * 0.6)
|
||||
button.setIconSize(QSize(icon_size, icon_size))
|
||||
|
||||
def _update_all_button_sizes(self):
|
||||
"""Update all button sizes when container is resized"""
|
||||
if hasattr(self, '_square_buttons'):
|
||||
for button in self._square_buttons:
|
||||
if button.parent(): # Check if button still exists
|
||||
self._update_button_size(button)
|
||||
|
||||
def showEvent(self, event):
|
||||
"""Handle show event to set initial button sizes"""
|
||||
super().showEvent(event)
|
||||
# Update button sizes when widget is first shown
|
||||
self._update_all_button_sizes()
|
||||
|
||||
def _insert_button_with_alignment(self, button, position, after_button_index=None):
|
||||
"""Insert button at the specified position with proper visual alignment"""
|
||||
if position == ButtonPosition.START:
|
||||
# Insert at the beginning (before left spacer)
|
||||
self.button_layout.insertWidget(0, button)
|
||||
self.start_buttons.append(button)
|
||||
|
||||
elif position == ButtonPosition.CENTER:
|
||||
# Insert in center zone (after left spacer, before center spacer)
|
||||
center_start_index = self._get_spacer_index(self.left_spacer) + 1
|
||||
insert_index = center_start_index + len(self.center_buttons)
|
||||
self.button_layout.insertWidget(insert_index, button)
|
||||
self.center_buttons.append(button)
|
||||
|
||||
elif position == ButtonPosition.END:
|
||||
# Insert in end zone (after center spacer, at the end)
|
||||
end_start_index = self._get_spacer_index(self.center_spacer) + 1
|
||||
insert_index = end_start_index + len(self.end_buttons)
|
||||
self.button_layout.insertWidget(insert_index, button)
|
||||
self.end_buttons.append(button)
|
||||
|
||||
elif position == ButtonPosition.AFTER and after_button_index is not None:
|
||||
if 0 <= after_button_index < len(self.buttons) - 1:
|
||||
target_button = self.buttons[after_button_index]
|
||||
target_position = self.button_positions[after_button_index]
|
||||
|
||||
# Find the target button's layout index
|
||||
target_layout_index = -1
|
||||
for i in range(self.button_layout.count()):
|
||||
item = self.button_layout.itemAt(i)
|
||||
if item.widget() == target_button:
|
||||
target_layout_index = i
|
||||
break
|
||||
|
||||
if target_layout_index != -1:
|
||||
self.button_layout.insertWidget(target_layout_index + 1, button)
|
||||
|
||||
# Add to the same alignment zone as target
|
||||
if target_position == ButtonPosition.START:
|
||||
self.start_buttons.append(button)
|
||||
elif target_position == ButtonPosition.CENTER:
|
||||
self.center_buttons.append(button)
|
||||
elif target_position == ButtonPosition.END:
|
||||
self.end_buttons.append(button)
|
||||
else:
|
||||
# Fallback to END position
|
||||
self._insert_button_with_alignment(button, ButtonPosition.END)
|
||||
|
||||
def _get_spacer_index(self, spacer_item):
|
||||
"""Get the index of a spacer item in the layout"""
|
||||
for i in range(self.button_layout.count()):
|
||||
if self.button_layout.itemAt(i).spacerItem() == spacer_item:
|
||||
return i
|
||||
return -1
|
||||
|
||||
def set_button_size_ratio(self, ratio, button_index=None):
|
||||
"""Set the button size ratio globally or for a specific button"""
|
||||
if button_index is not None:
|
||||
# Set ratio for specific button
|
||||
if 0 <= button_index < len(self.button_size_ratios):
|
||||
self.button_size_ratios[button_index] = ratio
|
||||
if button_index < len(self.buttons):
|
||||
self._update_button_size(self.buttons[button_index])
|
||||
else:
|
||||
# Set global ratio
|
||||
self.button_size_ratio = ratio
|
||||
# Update all buttons that don't have individual ratios
|
||||
for i in range(len(self.buttons)):
|
||||
if i >= len(self.button_size_ratios):
|
||||
self.button_size_ratios.append(ratio)
|
||||
else:
|
||||
self.button_size_ratios[i] = ratio
|
||||
self._update_all_button_sizes()
|
||||
|
||||
def switch_to_tab(self, index):
|
||||
"""Switch to the specified tab (only for widgets, not simple buttons)"""
|
||||
if 0 <= index < len(self.buttons) and self.widgets[index] is not None:
|
||||
old_index = self.stacked_widget.currentIndex()
|
||||
|
||||
# Update button states and apply theme colors
|
||||
for i, button in enumerate(self.buttons):
|
||||
# Only handle tab-like behavior for buttons with widgets
|
||||
if self.widgets[i] is not None:
|
||||
is_selected = (i == index)
|
||||
button.setChecked(is_selected)
|
||||
|
||||
# Update icon color based on selection
|
||||
if hasattr(self, '_original_icon_paths') and i < len(self._original_icon_paths):
|
||||
icon_path = self._original_icon_paths[i]
|
||||
if icon_path:
|
||||
color = (self.selected_icon_color if is_selected
|
||||
else self.unselected_icon_color)
|
||||
colored_icon = self.apply_color_to_svg_icon(icon_path, color)
|
||||
button.setIcon(colored_icon)
|
||||
|
||||
# Update button property for styling
|
||||
button.setProperty("selected", is_selected)
|
||||
button.style().unpolish(button)
|
||||
button.style().polish(button)
|
||||
|
||||
# Switch stacked widget
|
||||
self.stacked_widget.setCurrentIndex(index)
|
||||
|
||||
# Call the callback if provided and index actually changed
|
||||
if self.onTabChange and old_index != index:
|
||||
try:
|
||||
self.onTabChange(index)
|
||||
except Exception as e:
|
||||
print(f"Error in onTabChange callback: {e}")
|
||||
|
||||
def set_theme(self):
|
||||
self.selected_icon_color = self.theme_manager.current_theme.get_color("selected_icon")
|
||||
self.unselected_icon_color = self.theme_manager.current_theme.get_color("unselected_icon")
|
||||
self.selected_border_icon_color = self.theme_manager.current_theme.get_color("selected_border_icon")
|
||||
self.hover_icon_color = self.theme_manager.current_theme.get_color("hover_icon")
|
||||
# Apply theme to all buttons
|
||||
for i, button in enumerate(self.buttons):
|
||||
# Check if button is currently selected
|
||||
is_selected = button.isChecked()
|
||||
|
||||
# Update button stylesheet with current theme colors
|
||||
border_style = self._get_border_style()
|
||||
button.setStyleSheet(border_style)
|
||||
|
||||
# Get original icon if it exists
|
||||
original_icon = button.icon()
|
||||
if not original_icon.isNull():
|
||||
# Apply color to SVG and create new icon
|
||||
if hasattr(self, '_original_icon_paths') and i < len(self._original_icon_paths):
|
||||
icon_path = self._original_icon_paths[i]
|
||||
if icon_path:
|
||||
# Choose color based on selection state
|
||||
color = self.selected_icon_color if is_selected else self.unselected_icon_color
|
||||
|
||||
# Apply color to SVG and create new QIcon
|
||||
colored_icon = self.apply_color_to_svg_icon(icon_path, color)
|
||||
button.setIcon(colored_icon)
|
||||
|
||||
# Apply button styling based on selection state
|
||||
button.setProperty("selected", is_selected)
|
||||
|
||||
# Force style update
|
||||
button.style().unpolish(button)
|
||||
button.style().polish(button)
|
||||
|
||||
def apply_color_to_svg_icon(self, icon_path, color) -> QIcon:
|
||||
|
||||
# Define namespace mapping (based on your SVG)
|
||||
ns = {'ns0': 'http://www.w3.org/2000/svg'}
|
||||
|
||||
# Parse the SVG file
|
||||
tree = ET.parse(icon_path)
|
||||
root = tree.getroot()
|
||||
|
||||
# Change the fill attribute on the root <svg> element
|
||||
root.attrib['fill'] = color
|
||||
root.attrib['stroke'] = color
|
||||
# Optionally, change fill for all <path> elements as well
|
||||
for path in root.findall('.//ns0:path', ns):
|
||||
path.attrib['fill'] = color
|
||||
path.attrib['stroke'] = color
|
||||
|
||||
# Save the modified SVG
|
||||
tree.write(icon_path)
|
||||
return QIcon(icon_path)
|
||||
|
||||
def update_buttons_size(self, size):
|
||||
"""Update all buttons to a specific pixel size (overrides ratio-based sizing)"""
|
||||
for button in self.buttons:
|
||||
button.setFixedSize(size, size)
|
||||
# Update icon size proportionally
|
||||
icon_size = max(int(size * 0.6), 12)
|
||||
button.setIconSize(QSize(icon_size, icon_size))
|
89
app/ui/windows/settings_window.py
Normal file
89
app/ui/windows/settings_window.py
Normal file
@ -0,0 +1,89 @@
|
||||
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QComboBox, QLabel, QHBoxLayout, QSizePolicy
|
||||
from PyQt6.QtCore import Qt
|
||||
from app.core.main_manager import MainManager, NotificationType
|
||||
|
||||
class SettingsWindow(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.main_manager = MainManager.get_instance()
|
||||
self.language_manager = self.main_manager.get_language_manager()
|
||||
self.settings_manager = self.main_manager.get_settings_manager()
|
||||
|
||||
self.observer_manager = self.main_manager.get_observer_manager()
|
||||
self.observer_manager.subscribe(NotificationType.LANGUAGE, self.update_language)
|
||||
|
||||
self.setup_ui()
|
||||
|
||||
def setup_ui(self):
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setAlignment(Qt.AlignmentFlag.AlignTop)
|
||||
layout.setSpacing(20)
|
||||
layout.setContentsMargins(20, 20, 20, 20)
|
||||
|
||||
self.language_layout = QHBoxLayout()
|
||||
# Paramètres de langue
|
||||
self.languageLabel = QLabel(self.language_manager.get_text("language"),self)
|
||||
self.languageLabel.setFixedWidth(120) # Largeur fixe pour l'alignement
|
||||
self.language_layout.addWidget(self.languageLabel)
|
||||
|
||||
self.languageCombo = self.createLanguageSelector()
|
||||
self.language_layout.addWidget(self.languageCombo)
|
||||
|
||||
layout.addLayout(self.language_layout)
|
||||
|
||||
# Paramètres de thème
|
||||
|
||||
self.theme_layout = QHBoxLayout()
|
||||
|
||||
self.themeLabel = QLabel(self.language_manager.get_text("theme"), self)
|
||||
self.themeLabel.setFixedWidth(120) # Même largeur fixe pour l'alignement
|
||||
self.theme_layout.addWidget(self.themeLabel)
|
||||
|
||||
self.themeCombo = self.createThemeSelector()
|
||||
self.theme_layout.addWidget(self.themeCombo)
|
||||
|
||||
layout.addLayout(self.theme_layout)
|
||||
|
||||
layout.addStretch()
|
||||
|
||||
def createLanguageSelector(self):
|
||||
combo = QComboBox()
|
||||
# Ajouter toutes les langues disponibles
|
||||
for langCode, langData in self.language_manager.translations.items():
|
||||
combo.addItem(langData["lang_name"], langCode)
|
||||
|
||||
# Sélectionner la langue actuelle
|
||||
currentIndex = combo.findData(self.settings_manager.get_language())
|
||||
combo.setCurrentIndex(currentIndex)
|
||||
combo.currentIndexChanged.connect(self.change_language)
|
||||
|
||||
return combo
|
||||
|
||||
def createThemeSelector(self):
|
||||
combo = QComboBox()
|
||||
|
||||
# Ajouter les options de thème
|
||||
combo.addItem(self.language_manager.get_text("light_theme"), "light")
|
||||
combo.addItem(self.language_manager.get_text("dark_theme"), "dark")
|
||||
|
||||
# Sélectionner le thème actuel
|
||||
currentIndex = combo.findData(self.settings_manager.get_theme())
|
||||
combo.setCurrentIndex(currentIndex)
|
||||
combo.currentIndexChanged.connect(self.change_theme)
|
||||
|
||||
return combo
|
||||
|
||||
def change_language(self, index):
|
||||
self.settings_manager.set_language(self.languageCombo.itemData(index))
|
||||
|
||||
def change_theme(self, index):
|
||||
theme = self.themeCombo.itemData(index)
|
||||
self.settings_manager.set_theme(theme)
|
||||
|
||||
def update_language(self):
|
||||
self.languageLabel.setText(self.language_manager.get_text("language"))
|
||||
self.themeLabel.setText(self.language_manager.get_text("theme"))
|
||||
|
||||
# Mettre à jour les textes dans la combo de thème
|
||||
for i in range(self.themeCombo.count()):
|
||||
self.themeCombo.setItemText(i, self.language_manager.get_text(self.themeCombo.itemData(i)+ "_theme"))
|
59
app/utils/paths.py
Normal file
59
app/utils/paths.py
Normal file
@ -0,0 +1,59 @@
|
||||
from os import path, getenv, mkdir
|
||||
import sys
|
||||
from platform import system
|
||||
from pathlib import Path
|
||||
|
||||
def resource_path(relative_path: str) -> Path:
|
||||
"""
|
||||
Get absolute path to resource, works for dev and for PyInstaller bundle.
|
||||
|
||||
PyInstaller stores bundled files in _MEIPASS folder.
|
||||
"""
|
||||
try:
|
||||
base_path = Path(sys._MEIPASS) # PyInstaller temp folder
|
||||
except AttributeError:
|
||||
base_path = Path(__file__).parent.parent.parent # Dev environment: source/ folder
|
||||
|
||||
return path.join(base_path, relative_path)
|
||||
|
||||
def get_data_dir() -> Path:
|
||||
return resource_path("data")
|
||||
|
||||
def get_lang_path() -> Path:
|
||||
return path.join(get_data_dir(), "lang")
|
||||
|
||||
def get_asset_path(asset: str) -> Path:
|
||||
return path.join(get_data_dir(), "assets", f"{asset}.png")
|
||||
|
||||
def get_asset_svg_path(asset: str) -> Path:
|
||||
return path.join(get_data_dir(), "assets", f"{asset}.svg")
|
||||
|
||||
def get_user_data_dir(app_name: str) -> Path:
|
||||
home = Path.home()
|
||||
os = system()
|
||||
|
||||
if os == "Windows":
|
||||
appdata = getenv('APPDATA')
|
||||
if appdata:
|
||||
user_data_path = path.join(Path(appdata), app_name)
|
||||
else:
|
||||
user_data_path = path.join(home, "AppData", "Roaming", app_name)
|
||||
elif os == "Darwin":
|
||||
user_data_path = path.join(home, "Library", "Application Support", app_name)
|
||||
else:
|
||||
user_data_path = path.join(home, ".local", "share", app_name)
|
||||
|
||||
if not path.exists(user_data_path):
|
||||
mkdir(user_data_path)
|
||||
return user_data_path
|
||||
|
||||
def get_current_dir() -> Path:
|
||||
"""
|
||||
Return the directory where the exe or main script is located.
|
||||
"""
|
||||
if getattr(sys, 'frozen', False):
|
||||
# If the application is frozen (PyInstaller)
|
||||
return str(Path(sys.executable).parent)
|
||||
else:
|
||||
# If running in a normal Python environment
|
||||
return str(Path(__file__).parent.parent.parent)
|
10
config.json
Normal file
10
config.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"app_name": "Application",
|
||||
"python_version": "3.11.7",
|
||||
"app_os": "Windows",
|
||||
"app_version": "1.0.0",
|
||||
"architecture": "x64",
|
||||
"icon_path": "data/assets/icon.ico",
|
||||
"main_script": "main.py",
|
||||
"python_path": "C:/Logiciels/Python/x64/3.11.7/python.exe"
|
||||
}
|
BIN
data/assets/icon.ico
Normal file
BIN
data/assets/icon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
BIN
data/assets/icon.png
Normal file
BIN
data/assets/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
1
data/assets/settings.svg
Normal file
1
data/assets/settings.svg
Normal file
@ -0,0 +1 @@
|
||||
<ns0:svg xmlns:ns0="http://www.w3.org/2000/svg" viewBox="0 0 50 50" width="100px" height="100px" fill="#000000" stroke="#000000"><ns0:path d="M 22.205078 2 A 1.0001 1.0001 0 0 0 21.21875 2.8378906 L 20.246094 8.7929688 C 19.076509 9.1331971 17.961243 9.5922728 16.910156 10.164062 L 11.996094 6.6542969 A 1.0001 1.0001 0 0 0 10.708984 6.7597656 L 6.8183594 10.646484 A 1.0001 1.0001 0 0 0 6.7070312 11.927734 L 10.164062 16.873047 C 9.583454 17.930271 9.1142098 19.051824 8.765625 20.232422 L 2.8359375 21.21875 A 1.0001 1.0001 0 0 0 2.0019531 22.205078 L 2.0019531 27.705078 A 1.0001 1.0001 0 0 0 2.8261719 28.691406 L 8.7597656 29.742188 C 9.1064607 30.920739 9.5727226 32.043065 10.154297 33.101562 L 6.6542969 37.998047 A 1.0001 1.0001 0 0 0 6.7597656 39.285156 L 10.648438 43.175781 A 1.0001 1.0001 0 0 0 11.927734 43.289062 L 16.882812 39.820312 C 17.936999 40.39548 19.054994 40.857928 20.228516 41.201172 L 21.21875 47.164062 A 1.0001 1.0001 0 0 0 22.205078 48 L 27.705078 48 A 1.0001 1.0001 0 0 0 28.691406 47.173828 L 29.751953 41.1875 C 30.920633 40.838997 32.033372 40.369697 33.082031 39.791016 L 38.070312 43.291016 A 1.0001 1.0001 0 0 0 39.351562 43.179688 L 43.240234 39.287109 A 1.0001 1.0001 0 0 0 43.34375 37.996094 L 39.787109 33.058594 C 40.355783 32.014958 40.813915 30.908875 41.154297 29.748047 L 47.171875 28.693359 A 1.0001 1.0001 0 0 0 47.998047 27.707031 L 47.998047 22.207031 A 1.0001 1.0001 0 0 0 47.160156 21.220703 L 41.152344 20.238281 C 40.80968 19.078827 40.350281 17.974723 39.78125 16.931641 L 43.289062 11.933594 A 1.0001 1.0001 0 0 0 43.177734 10.652344 L 39.287109 6.7636719 A 1.0001 1.0001 0 0 0 37.996094 6.6601562 L 33.072266 10.201172 C 32.023186 9.6248101 30.909713 9.1579916 29.738281 8.8125 L 28.691406 2.828125 A 1.0001 1.0001 0 0 0 27.705078 2 L 22.205078 2 z M 23.056641 4 L 26.865234 4 L 27.861328 9.6855469 A 1.0001 1.0001 0 0 0 28.603516 10.484375 C 30.066026 10.848832 31.439607 11.426549 32.693359 12.185547 A 1.0001 1.0001 0 0 0 33.794922 12.142578 L 38.474609 8.7792969 L 41.167969 11.472656 L 37.835938 16.220703 A 1.0001 1.0001 0 0 0 37.796875 17.310547 C 38.548366 18.561471 39.118333 19.926379 39.482422 21.380859 A 1.0001 1.0001 0 0 0 40.291016 22.125 L 45.998047 23.058594 L 45.998047 26.867188 L 40.279297 27.871094 A 1.0001 1.0001 0 0 0 39.482422 28.617188 C 39.122545 30.069817 38.552234 31.434687 37.800781 32.685547 A 1.0001 1.0001 0 0 0 37.845703 33.785156 L 41.224609 38.474609 L 38.53125 41.169922 L 33.791016 37.84375 A 1.0001 1.0001 0 0 0 32.697266 37.808594 C 31.44975 38.567585 30.074755 39.148028 28.617188 39.517578 A 1.0001 1.0001 0 0 0 27.876953 40.3125 L 26.867188 46 L 23.052734 46 L 22.111328 40.337891 A 1.0001 1.0001 0 0 0 21.365234 39.53125 C 19.90185 39.170557 18.522094 38.59371 17.259766 37.835938 A 1.0001 1.0001 0 0 0 16.171875 37.875 L 11.46875 41.169922 L 8.7734375 38.470703 L 12.097656 33.824219 A 1.0001 1.0001 0 0 0 12.138672 32.724609 C 11.372652 31.458855 10.793319 30.079213 10.427734 28.609375 A 1.0001 1.0001 0 0 0 9.6328125 27.867188 L 4.0019531 26.867188 L 4.0019531 23.052734 L 9.6289062 22.117188 A 1.0001 1.0001 0 0 0 10.435547 21.373047 C 10.804273 19.898143 11.383325 18.518729 12.146484 17.255859 A 1.0001 1.0001 0 0 0 12.111328 16.164062 L 8.8261719 11.46875 L 11.523438 8.7734375 L 16.185547 12.105469 A 1.0001 1.0001 0 0 0 17.28125 12.148438 C 18.536908 11.394293 19.919867 10.822081 21.384766 10.462891 A 1.0001 1.0001 0 0 0 22.132812 9.6523438 L 23.056641 4 z M 25 17 C 20.593567 17 17 20.593567 17 25 C 17 29.406433 20.593567 33 25 33 C 29.406433 33 33 29.406433 33 25 C 33 20.593567 29.406433 17 25 17 z M 25 19 C 28.325553 19 31 21.674447 31 25 C 31 28.325553 28.325553 31 25 31 C 21.674447 31 19 28.325553 19 25 C 19 21.674447 21.674447 19 25 19 z" fill="#000000" stroke="#000000" /></ns0:svg>
|
10
data/lang/en.json
Normal file
10
data/lang/en.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"lang_name": "English",
|
||||
"yes": "Yes",
|
||||
"no": "No",
|
||||
"language": "Language :",
|
||||
"settings": "Settings",
|
||||
"theme": "Theme :",
|
||||
"dark_theme": "Dark Theme",
|
||||
"light_theme": "Light Theme"
|
||||
}
|
10
data/lang/fr.json
Normal file
10
data/lang/fr.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"lang_name": "Français",
|
||||
"yes": "Oui",
|
||||
"no": "Non",
|
||||
"language": "Langue :",
|
||||
"settings": "Paramètres",
|
||||
"theme": "Thème :",
|
||||
"dark_theme": "Thème Sombre",
|
||||
"light_theme": "Thème Clair"
|
||||
}
|
7
data/others/defaults_settings.json
Normal file
7
data/others/defaults_settings.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"theme": "dark",
|
||||
"lang": "fr",
|
||||
"window_size": {"width": 1000, "height": 600},
|
||||
"fullscreen": true,
|
||||
"fullscreen_size": {"width": 1000, "height": 600}
|
||||
}
|
13
data/themes/dark.json
Normal file
13
data/themes/dark.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"theme_name": "dark",
|
||||
"colors": {
|
||||
"background": "#212121",
|
||||
"background2": "#2C2C2E",
|
||||
"background3": "#4A4A4A",
|
||||
"font_color": "#D1D1D6",
|
||||
"selected_icon": "#D1D1D6",
|
||||
"unselected_icon": "#4A4A4A",
|
||||
"selected_border_icon": "#D1D1D6",
|
||||
"hover_icon": "#D1D1D6"
|
||||
}
|
||||
}
|
13
data/themes/light.json
Normal file
13
data/themes/light.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"theme_name": "light",
|
||||
"colors": {
|
||||
"background": "#FFFFFF",
|
||||
"background2": "#F5F5F5",
|
||||
"background3": "#E0E0E0",
|
||||
"font_color": "#000000",
|
||||
"selected_icon": "#000000",
|
||||
"unselected_icon": "#5D5A5A",
|
||||
"selected_border_icon": "#000000",
|
||||
"hover_icon": "#000000"
|
||||
}
|
||||
}
|
14
main.py
Normal file
14
main.py
Normal file
@ -0,0 +1,14 @@
|
||||
import sys
|
||||
from PyQt6.QtWidgets import QApplication
|
||||
from app.ui.main_window import MainWindow
|
||||
|
||||
def main():
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
window = MainWindow()
|
||||
|
||||
window.show()
|
||||
return app.exec()
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
PyQt6
|
||||
pyinstaller
|
50
tools/build.bat
Normal file
50
tools/build.bat
Normal file
@ -0,0 +1,50 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
REM === PATH SETUP ===
|
||||
set PARENT_DIR=%~dp0..
|
||||
set CONFIG_FILE=%PARENT_DIR%\config.json
|
||||
|
||||
REM === Extract values from config.json ===
|
||||
for /f "delims=" %%i in ('powershell -NoProfile -Command ^
|
||||
"Get-Content '%CONFIG_FILE%' | ConvertFrom-Json | Select-Object -ExpandProperty python_version"') do set PYTHON_VERSION=%%i
|
||||
for /f "delims=" %%i in ('powershell -NoProfile -Command ^
|
||||
"Get-Content '%CONFIG_FILE%' | ConvertFrom-Json | Select-Object -ExpandProperty icon_path"') do set ICON_PATH=%%i
|
||||
for /f "delims=" %%i in ('powershell -NoProfile -Command ^
|
||||
"Get-Content '%CONFIG_FILE%' | ConvertFrom-Json | Select-Object -ExpandProperty app_name"') do set APP_NAME=%%i
|
||||
for /f "delims=" %%i in ('powershell -NoProfile -Command ^
|
||||
"Get-Content '%CONFIG_FILE%' | ConvertFrom-Json | Select-Object -ExpandProperty architecture"') do set ARCHITECTURE=%%i
|
||||
for /f "delims=" %%i in ('powershell -NoProfile -Command ^
|
||||
"Get-Content '%CONFIG_FILE%' | ConvertFrom-Json | Select-Object -ExpandProperty python_path"') do set SYSTEM_PYTHON=%%i
|
||||
|
||||
set VENV_PATH=%PARENT_DIR%\WINenv_%ARCHITECTURE%
|
||||
set EXE_NAME=%APP_NAME%-Windows-%ARCHITECTURE%
|
||||
set PYTHON_IN_VENV=%VENV_PATH%\Scripts\python.exe
|
||||
|
||||
REM === Verify Python existence ===
|
||||
if not exist "%SYSTEM_PYTHON%" (
|
||||
echo [ERROR] Python not found at: %SYSTEM_PYTHON%
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM === Check if virtual environment exists ===
|
||||
if not exist "%VENV_PATH%\Scripts\activate.bat" (
|
||||
echo [INFO] Virtual environment not found. Creating...
|
||||
"%SYSTEM_PYTHON%" -m venv "%VENV_PATH%"
|
||||
"%PYTHON_IN_VENV%" -m pip install --upgrade pip
|
||||
"%PYTHON_IN_VENV%" -m pip install -r "%PARENT_DIR%\requirements.txt"
|
||||
) else (
|
||||
echo [INFO] Virtual environment found.
|
||||
)
|
||||
|
||||
REM === Run PyInstaller ===
|
||||
"%PYTHON_IN_VENV%" -m PyInstaller ^
|
||||
--distpath "%PARENT_DIR%\build" ^
|
||||
--workpath "%PARENT_DIR%\dist" ^
|
||||
--clean ^
|
||||
"%PARENT_DIR%\BUILD.spec"
|
||||
|
||||
REM === Clean build cache ===
|
||||
rmdir /s /q "%PARENT_DIR%\dist"
|
||||
|
||||
endlocal
|
49
tools/open.bat
Normal file
49
tools/open.bat
Normal file
@ -0,0 +1,49 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
REM Set file paths
|
||||
set ROOT_DIR=%~dp0..
|
||||
set CONFIG_FILE=%ROOT_DIR%\config.json
|
||||
set REQUIREMENTS=%ROOT_DIR%\requirements.txt
|
||||
|
||||
REM Extract config.json fields using PowerShell
|
||||
for /f "delims=" %%i in ('powershell -NoProfile -Command ^
|
||||
"Get-Content '%CONFIG_FILE%' | ConvertFrom-Json | Select-Object -ExpandProperty python_version"') do set PYTHON_VERSION=%%i
|
||||
|
||||
for /f "delims=" %%i in ('powershell -NoProfile -Command ^
|
||||
"Get-Content '%CONFIG_FILE%' | ConvertFrom-Json | Select-Object -ExpandProperty architecture"') do set ARCHITECTURE=%%i
|
||||
|
||||
for /f "delims=" %%i in ('powershell -NoProfile -Command ^
|
||||
"Get-Content '%CONFIG_FILE%' | ConvertFrom-Json | Select-Object -ExpandProperty python_path"') do set PYTHON_EXEC=%%i
|
||||
|
||||
REM Construct python executable path
|
||||
set ENV_NAME=WINenv_%ARCHITECTURE%
|
||||
set ENV_PATH=%ROOT_DIR%\%ENV_NAME%
|
||||
|
||||
if not exist "%PYTHON_EXEC%" (
|
||||
echo [ERROR] Python introuvable à: %PYTHON_EXEC%
|
||||
echo Veuillez vérifier votre config.json ou le dossier d'installation.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Show config info
|
||||
echo [INFO] Configuration :
|
||||
echo Python: %PYTHON_EXEC%
|
||||
echo Env: %ENV_NAME%
|
||||
|
||||
REM Check if virtual environment exists
|
||||
if not exist "%ENV_PATH%\Scripts" (
|
||||
echo [INFO] Environnement virtuel introuvable, création...
|
||||
"%PYTHON_EXEC%" -m venv "%ENV_PATH%"
|
||||
echo [INFO] Installation des dépendances...
|
||||
"%ENV_PATH%\Scripts\python" -m pip install --upgrade pip
|
||||
"%ENV_PATH%\Scripts\pip" install -r "%REQUIREMENTS%"
|
||||
) else (
|
||||
echo [INFO] Environnement virtuel trouvé.
|
||||
)
|
||||
REM Activate and launch VS Code
|
||||
echo [INFO] Lancement de VS Code...
|
||||
call "%ENV_PATH%/Scripts/activate.bat"
|
||||
start code "%ROOT_DIR%"
|
||||
|
||||
exit /b 0
|
Loading…
x
Reference in New Issue
Block a user