Refacto QSS, add comments

This commit is contained in:
2026-03-19 12:38:15 +01:00
parent 1125e5ee10
commit 54aa7a50b2
5 changed files with 138 additions and 58 deletions

View File

@@ -20,9 +20,6 @@ class CustomMessageBox(QDialog):
self.setAttribute(Qt.WA_TranslucentBackground)
self.setMinimumWidth(400)
color_main = "#101624"
color_accent = "#248277" if icon_type == self.INFO else "#cf5b16"
# --- ANIMATION DE FONDU ---
self.setWindowOpacity(0)
self.fade_anim = QPropertyAnimation(self, b"windowOpacity")
@@ -33,16 +30,10 @@ class CustomMessageBox(QDialog):
# --- UI SETUP ---
self.container = QWidget(self)
self.container.setObjectName("MainContainer")
self.container.setStyleSheet(f"""
QWidget#MainContainer {{
background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
stop:0 {color_main}, stop:1 {color_accent});
border-radius: 15px;
border: 1px solid rgba(255, 255, 255, 0.1);
}}
QLabel {{ color: white; font-family: 'Segoe UI'; }}
""")
self.container.setObjectName("MsgBoxMainContainer")
# Utilisé dans le fichier QSS comme condition dynamique de style
self.container.setProperty("iconType", icon_type)
self.container.setProperty("buttonsType", buttons)
# LAYOUT PRINCIPAL DU CONTAINER (Marges à 0 pour coller le bouton au bord)
layout = QVBoxLayout(self.container)
@@ -55,28 +46,13 @@ class CustomMessageBox(QDialog):
title_bar_layout.setSpacing(0)
title_label = QLabel(title.upper())
title_label.setStyleSheet(
"font-weight: bold; font-size: 10px; color: rgba(255,255,255,0.7); letter-spacing: 1px;")
title_label.setObjectName("MsgBoxTitleLabel")
self.close_btn = QPushButton("")
self.close_btn.setObjectName("MsgBoxCloseButton")
self.close_btn.setFixedSize(45, 35)
self.close_btn.clicked.connect(self.reject)
self.close_btn.setCursor(Qt.PointingHandCursor)
self.close_btn.setStyleSheet("""
QPushButton {
background: transparent;
color: white;
border: none;
font-size: 14px;
/* Rayon identique au container (15px) pour épouser parfaitement le coin */
border-top-right-radius: 15px;
border-bottom-left-radius: 10px;
}
QPushButton:hover {
background-color: #e74c3c;
color: white;
}
""")
title_bar_layout.addWidget(title_label)
title_bar_layout.addStretch()
@@ -91,12 +67,12 @@ class CustomMessageBox(QDialog):
# Contenu central (Icône + Message)
content_layout = QHBoxLayout()
icon_label = QLabel()
icon_label.setObjectName("MsgBoxIconLabel")
icon_text = "" if icon_type == self.INFO else "⚠️"
icon_label.setText(icon_text)
icon_label.setStyleSheet("font-size: 35px; margin-right: 10px;")
msg_label = QLabel(message)
msg_label.setStyleSheet("font-size: 14px; color: #f0f0f0;")
msg_label.setObjectName("MsgBoxMessageLabel")
msg_label.setWordWrap(True)
content_layout.addWidget(icon_label)
@@ -108,24 +84,14 @@ class CustomMessageBox(QDialog):
btn_layout.setSpacing(10)
btn_layout.addStretch()
style_btn_base = """
QPushButton {
background: #2a313d; border-radius: 6px; color: white;
padding: 8px 20px; font-weight: bold; font-size: 12px;
border: 1px solid rgba(255,255,255,0.05);
}
QPushButton:hover { background: #363d4a; border: 1px solid white; }
"""
if buttons == self.OK_CANCEL:
self.btn_cancel = QPushButton("ANNULER")
self.btn_cancel.setStyleSheet(style_btn_base)
self.btn_cancel.setObjectName("MsgBoxCancelButton")
self.btn_cancel.clicked.connect(self.reject)
btn_layout.addWidget(self.btn_cancel)
self.btn_ok = QPushButton("COMPRIS")
style_btn_ok = style_btn_base.replace("#2a313d", "#248277")
self.btn_ok.setStyleSheet(style_btn_ok)
self.btn_ok.setObjectName("MsgBoxOkButton")
self.btn_ok.setCursor(Qt.PointingHandCursor)
self.btn_ok.clicked.connect(self.accept)
btn_layout.addWidget(self.btn_ok)

View File

@@ -13,6 +13,9 @@ class OAuthCallbackHandler(BaseHTTPRequestHandler):
code: str | None = None
def do_GET(self):
"""
callback pour discord auth
"""
if "/callback" in self.path:
query = self.path.split("?")[1]
params = dict(p.split("=") for p in query.split("&"))
@@ -25,11 +28,19 @@ class OAuthCallbackHandler(BaseHTTPRequestHandler):
# return discord application id (client id)
def get_discord_client_id() -> str:
"""
return discord application id
"""
return CLIENT_ID
# return discord user id
def get_discord_user_id() -> str:
# récupération des infos serveur lataupe
"""
Retourne l'id du compte discord de l'utilisateur via l'oauh discord.
"""
# récupération des infos serveur la tanière
# récupération d
session_id = GetServerTokenForDiscord.authenticate()
client_secret = GetServerTokenForDiscord.get_token(session_id)
@@ -44,7 +55,7 @@ def get_discord_user_id() -> str:
webbrowser.open(f"{auth_url}?{urlencode(params)}")
server = HTTPServer(("localhost", 5000), OAuthCallbackHandler)
# celle ligne cache le stderr output pour ne pas afficher l'url de callback dans la console
# la ligne suivante sert à cacher le stderr output pour ne pas afficher l'url de callback dans la console
# valable en debug mode
os.dup2(os.open(os.devnull, os.O_WRONLY), 2)
server.handle_request()

View File

@@ -1,30 +1,45 @@
import psutil
from pypresence import Presence
from pypresence.presence import Presence
from tools.get_server_token import GetServerTokenForDiscord
from config.constants import Urls
from tools.discord_oauth import CLIENT_ID
class DiscordToken:
"""
Décode le token discord
"""
@staticmethod
def decode_discord_token():
discord_token = GetServerTokenForDiscord.get_token(GetServerTokenForDiscord.authenticate(Urls.API_URL.value))
discord_token = GetServerTokenForDiscord.get_token(
GetServerTokenForDiscord.authenticate(Urls.API_URL.value)
)
return discord_token
class CheckDiscord:
class CheckDiscord:
@staticmethod
def isdiscordrunning() -> bool:
"""
Vérifie si Discord est en cours d'exécution sur l'ordinateur. (Vérifie aussi pour Linux)
"""
for process in psutil.process_iter(["name"]):
if (process.info["name"].lower() == "discord.exe" or
process.info["name"].lower() == "discordcanary.exe" or
process.info["name"].lower() == "discord" or
process.info["name"].lower() == "discord canary"):
if (
process.info["name"].lower() == "discord.exe"
or process.info["name"].lower() == "discordcanary.exe"
or process.info["name"].lower() == "discord"
or process.info["name"].lower() == "discord canary"
):
return True
return False
@staticmethod
def isuserconnected() -> bool:
"""
Vérifie si l'utilisateur Discord est connecté.
ne vérifie pas le user id discord.
"""
rpc = Presence(CLIENT_ID)
try:
rpc.connect()

View File

@@ -5,16 +5,16 @@ from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
API_URL = 'https://prod.la-taniere.fun:30121/'
from config.constants import Urls
class GetServerTokenForDiscord:
derived_key: bytes | None = None
@staticmethod
def authenticate(server = API_URL):
def authenticate(server = Urls.API_URL.value):
if server is None:
server = API_URL
server = Urls.API_URL.value
# ==========================
# Génération clé ECDH client
# ==========================
@@ -49,12 +49,12 @@ class GetServerTokenForDiscord:
return auth["session_id"]
@staticmethod
def get_token(session_id: bytes, server = API_URL):
def get_token(session_id: bytes, server = Urls.API_URL.value):
# ==========================
# DISCORD TOKEN
# ==========================
if server is None:
server = API_URL
server = Urls.API_URL.value
download = requests.post(server + "/api_v2/tkn_auth", verify=False, headers={
"x-session-id": session_id
}).json()

View File

@@ -209,3 +209,91 @@ QSlider::handle:horizontal:pressed {
background: #E65100;
border-radius: 8px;
}
/* ----------------------------------------------
Custom Message Box
----------------------------------------------*/
QWidget#MsgBoxMainContainer {
border-radius: 15px;
border: 1px solid rgba(255, 255, 255, 0.1);
}
QWidget#MsgBoxMainContainer[iconType="info"] {
background: qlineargradient(
x1: 0, y1: 0, x2: 1, y2: 1,
stop: 0 #101624,
stop: 1 #248277
);
}
QWidget#MsgBoxMainContainer[iconType="warning"] {
background: qlineargradient(
x1: 0, y1: 0, x2: 1, y2: 1,
stop: 0 #101624,
stop: 1 #cf5b16
);
}
QWidget#MsgBoxMainContainer QLabel,
QWidget#MsgBoxMainContainer QPushButton
{
color: white;
font-family: 'Segoe UI';
}
QPushButton#MsgBoxOkButton,
QPushButton#MsgBoxCancelButton {
border-radius: 6px;
/* color: white;*/
padding: 8px 20px;
font-weight: bold;
font-size: 12px;
border: 1px solid rgba(255,255,255,0.05);
}
QPushButton#MsgBoxOkButton {
background: #248277;
}
QPushButton#MsgBoxCancelButton {
background: #2a313d;
}
QPushButton#MsgBoxOkButton:hover,
QPushButton#MsgBoxCancelButton:hover{
background: #363d4a;
border: 1px solid white;
}
QPushButton#MsgBoxCloseButton {
background: transparent;
color: white;
border: none;
font-size: 14px;
/* Rayon identique au container (15px) pour épouser parfaitement le coin */
border-top-right-radius: 15px;
border-bottom-left-radius: 10px;
}
QPushButton#MsgBoxCloseButton:hover {
background-color: #e74c3c;
color: white;
}
QLabel#MsgBoxTitleLabel {
font-weight: bold;
font-size: 10px;
color: rgba(255,255,255,0.7);
letter-spacing: 1px;
}
QLabel#MsgBoxMessageLabel {
font-size: 14px;
color: #f0f0f0;
}
QLabel#MsgBoxIconLabel {
font-size: 35px;
margin-right: 10px;
}