Refacto QSS, add comments
This commit is contained in:
@@ -20,9 +20,6 @@ class CustomMessageBox(QDialog):
|
|||||||
self.setAttribute(Qt.WA_TranslucentBackground)
|
self.setAttribute(Qt.WA_TranslucentBackground)
|
||||||
self.setMinimumWidth(400)
|
self.setMinimumWidth(400)
|
||||||
|
|
||||||
color_main = "#101624"
|
|
||||||
color_accent = "#248277" if icon_type == self.INFO else "#cf5b16"
|
|
||||||
|
|
||||||
# --- ANIMATION DE FONDU ---
|
# --- ANIMATION DE FONDU ---
|
||||||
self.setWindowOpacity(0)
|
self.setWindowOpacity(0)
|
||||||
self.fade_anim = QPropertyAnimation(self, b"windowOpacity")
|
self.fade_anim = QPropertyAnimation(self, b"windowOpacity")
|
||||||
@@ -33,16 +30,10 @@ class CustomMessageBox(QDialog):
|
|||||||
|
|
||||||
# --- UI SETUP ---
|
# --- UI SETUP ---
|
||||||
self.container = QWidget(self)
|
self.container = QWidget(self)
|
||||||
self.container.setObjectName("MainContainer")
|
self.container.setObjectName("MsgBoxMainContainer")
|
||||||
self.container.setStyleSheet(f"""
|
# Utilisé dans le fichier QSS comme condition dynamique de style
|
||||||
QWidget#MainContainer {{
|
self.container.setProperty("iconType", icon_type)
|
||||||
background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
|
self.container.setProperty("buttonsType", buttons)
|
||||||
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'; }}
|
|
||||||
""")
|
|
||||||
|
|
||||||
# LAYOUT PRINCIPAL DU CONTAINER (Marges à 0 pour coller le bouton au bord)
|
# LAYOUT PRINCIPAL DU CONTAINER (Marges à 0 pour coller le bouton au bord)
|
||||||
layout = QVBoxLayout(self.container)
|
layout = QVBoxLayout(self.container)
|
||||||
@@ -55,28 +46,13 @@ class CustomMessageBox(QDialog):
|
|||||||
title_bar_layout.setSpacing(0)
|
title_bar_layout.setSpacing(0)
|
||||||
|
|
||||||
title_label = QLabel(title.upper())
|
title_label = QLabel(title.upper())
|
||||||
title_label.setStyleSheet(
|
title_label.setObjectName("MsgBoxTitleLabel")
|
||||||
"font-weight: bold; font-size: 10px; color: rgba(255,255,255,0.7); letter-spacing: 1px;")
|
|
||||||
|
|
||||||
self.close_btn = QPushButton("✕")
|
self.close_btn = QPushButton("✕")
|
||||||
|
self.close_btn.setObjectName("MsgBoxCloseButton")
|
||||||
self.close_btn.setFixedSize(45, 35)
|
self.close_btn.setFixedSize(45, 35)
|
||||||
self.close_btn.clicked.connect(self.reject)
|
self.close_btn.clicked.connect(self.reject)
|
||||||
self.close_btn.setCursor(Qt.PointingHandCursor)
|
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.addWidget(title_label)
|
||||||
title_bar_layout.addStretch()
|
title_bar_layout.addStretch()
|
||||||
@@ -91,12 +67,12 @@ class CustomMessageBox(QDialog):
|
|||||||
# Contenu central (Icône + Message)
|
# Contenu central (Icône + Message)
|
||||||
content_layout = QHBoxLayout()
|
content_layout = QHBoxLayout()
|
||||||
icon_label = QLabel()
|
icon_label = QLabel()
|
||||||
|
icon_label.setObjectName("MsgBoxIconLabel")
|
||||||
icon_text = "ℹ️" if icon_type == self.INFO else "⚠️"
|
icon_text = "ℹ️" if icon_type == self.INFO else "⚠️"
|
||||||
icon_label.setText(icon_text)
|
icon_label.setText(icon_text)
|
||||||
icon_label.setStyleSheet("font-size: 35px; margin-right: 10px;")
|
|
||||||
|
|
||||||
msg_label = QLabel(message)
|
msg_label = QLabel(message)
|
||||||
msg_label.setStyleSheet("font-size: 14px; color: #f0f0f0;")
|
msg_label.setObjectName("MsgBoxMessageLabel")
|
||||||
msg_label.setWordWrap(True)
|
msg_label.setWordWrap(True)
|
||||||
|
|
||||||
content_layout.addWidget(icon_label)
|
content_layout.addWidget(icon_label)
|
||||||
@@ -108,24 +84,14 @@ class CustomMessageBox(QDialog):
|
|||||||
btn_layout.setSpacing(10)
|
btn_layout.setSpacing(10)
|
||||||
btn_layout.addStretch()
|
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:
|
if buttons == self.OK_CANCEL:
|
||||||
self.btn_cancel = QPushButton("ANNULER")
|
self.btn_cancel = QPushButton("ANNULER")
|
||||||
self.btn_cancel.setStyleSheet(style_btn_base)
|
self.btn_cancel.setObjectName("MsgBoxCancelButton")
|
||||||
self.btn_cancel.clicked.connect(self.reject)
|
self.btn_cancel.clicked.connect(self.reject)
|
||||||
btn_layout.addWidget(self.btn_cancel)
|
btn_layout.addWidget(self.btn_cancel)
|
||||||
|
|
||||||
self.btn_ok = QPushButton("COMPRIS")
|
self.btn_ok = QPushButton("COMPRIS")
|
||||||
style_btn_ok = style_btn_base.replace("#2a313d", "#248277")
|
self.btn_ok.setObjectName("MsgBoxOkButton")
|
||||||
self.btn_ok.setStyleSheet(style_btn_ok)
|
|
||||||
self.btn_ok.setCursor(Qt.PointingHandCursor)
|
self.btn_ok.setCursor(Qt.PointingHandCursor)
|
||||||
self.btn_ok.clicked.connect(self.accept)
|
self.btn_ok.clicked.connect(self.accept)
|
||||||
btn_layout.addWidget(self.btn_ok)
|
btn_layout.addWidget(self.btn_ok)
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ class OAuthCallbackHandler(BaseHTTPRequestHandler):
|
|||||||
code: str | None = None
|
code: str | None = None
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
|
"""
|
||||||
|
callback pour discord auth
|
||||||
|
"""
|
||||||
if "/callback" in self.path:
|
if "/callback" in self.path:
|
||||||
query = self.path.split("?")[1]
|
query = self.path.split("?")[1]
|
||||||
params = dict(p.split("=") for p in query.split("&"))
|
params = dict(p.split("=") for p in query.split("&"))
|
||||||
@@ -25,11 +28,19 @@ class OAuthCallbackHandler(BaseHTTPRequestHandler):
|
|||||||
|
|
||||||
# return discord application id (client id)
|
# return discord application id (client id)
|
||||||
def get_discord_client_id() -> str:
|
def get_discord_client_id() -> str:
|
||||||
|
"""
|
||||||
|
return discord application id
|
||||||
|
"""
|
||||||
return CLIENT_ID
|
return CLIENT_ID
|
||||||
|
|
||||||
# return discord user id
|
# return discord user id
|
||||||
def get_discord_user_id() -> str:
|
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()
|
session_id = GetServerTokenForDiscord.authenticate()
|
||||||
client_secret = GetServerTokenForDiscord.get_token(session_id)
|
client_secret = GetServerTokenForDiscord.get_token(session_id)
|
||||||
|
|
||||||
@@ -44,7 +55,7 @@ def get_discord_user_id() -> str:
|
|||||||
webbrowser.open(f"{auth_url}?{urlencode(params)}")
|
webbrowser.open(f"{auth_url}?{urlencode(params)}")
|
||||||
|
|
||||||
server = HTTPServer(("localhost", 5000), OAuthCallbackHandler)
|
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
|
# valable en debug mode
|
||||||
os.dup2(os.open(os.devnull, os.O_WRONLY), 2)
|
os.dup2(os.open(os.devnull, os.O_WRONLY), 2)
|
||||||
server.handle_request()
|
server.handle_request()
|
||||||
|
|||||||
@@ -1,30 +1,45 @@
|
|||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
from pypresence import Presence
|
from pypresence.presence import Presence
|
||||||
from tools.get_server_token import GetServerTokenForDiscord
|
from tools.get_server_token import GetServerTokenForDiscord
|
||||||
from config.constants import Urls
|
from config.constants import Urls
|
||||||
from tools.discord_oauth import CLIENT_ID
|
from tools.discord_oauth import CLIENT_ID
|
||||||
|
|
||||||
|
|
||||||
class DiscordToken:
|
class DiscordToken:
|
||||||
|
"""
|
||||||
|
Décode le token discord
|
||||||
|
"""
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def decode_discord_token():
|
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
|
return discord_token
|
||||||
|
|
||||||
class CheckDiscord:
|
|
||||||
|
|
||||||
|
class CheckDiscord:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def isdiscordrunning() -> bool:
|
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"]):
|
for process in psutil.process_iter(["name"]):
|
||||||
if (process.info["name"].lower() == "discord.exe" or
|
if (
|
||||||
process.info["name"].lower() == "discordcanary.exe" or
|
process.info["name"].lower() == "discord.exe"
|
||||||
process.info["name"].lower() == "discord" or
|
or process.info["name"].lower() == "discordcanary.exe"
|
||||||
process.info["name"].lower() == "discord canary"):
|
or process.info["name"].lower() == "discord"
|
||||||
|
or process.info["name"].lower() == "discord canary"
|
||||||
|
):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def isuserconnected() -> bool:
|
def isuserconnected() -> bool:
|
||||||
|
"""
|
||||||
|
Vérifie si l'utilisateur Discord est connecté.
|
||||||
|
⚠️ne vérifie pas le user id discord.
|
||||||
|
"""
|
||||||
rpc = Presence(CLIENT_ID)
|
rpc = Presence(CLIENT_ID)
|
||||||
try:
|
try:
|
||||||
rpc.connect()
|
rpc.connect()
|
||||||
|
|||||||
@@ -5,16 +5,16 @@ from cryptography.hazmat.primitives.asymmetric import ec
|
|||||||
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
|
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
|
||||||
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
||||||
|
|
||||||
API_URL = 'https://prod.la-taniere.fun:30121/'
|
from config.constants import Urls
|
||||||
|
|
||||||
class GetServerTokenForDiscord:
|
class GetServerTokenForDiscord:
|
||||||
derived_key: bytes | None = None
|
derived_key: bytes | None = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def authenticate(server = API_URL):
|
def authenticate(server = Urls.API_URL.value):
|
||||||
|
|
||||||
if server is None:
|
if server is None:
|
||||||
server = API_URL
|
server = Urls.API_URL.value
|
||||||
# ==========================
|
# ==========================
|
||||||
# Génération clé ECDH client
|
# Génération clé ECDH client
|
||||||
# ==========================
|
# ==========================
|
||||||
@@ -49,12 +49,12 @@ class GetServerTokenForDiscord:
|
|||||||
return auth["session_id"]
|
return auth["session_id"]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_token(session_id: bytes, server = API_URL):
|
def get_token(session_id: bytes, server = Urls.API_URL.value):
|
||||||
# ==========================
|
# ==========================
|
||||||
# DISCORD TOKEN
|
# DISCORD TOKEN
|
||||||
# ==========================
|
# ==========================
|
||||||
if server is None:
|
if server is None:
|
||||||
server = API_URL
|
server = Urls.API_URL.value
|
||||||
download = requests.post(server + "/api_v2/tkn_auth", verify=False, headers={
|
download = requests.post(server + "/api_v2/tkn_auth", verify=False, headers={
|
||||||
"x-session-id": session_id
|
"x-session-id": session_id
|
||||||
}).json()
|
}).json()
|
||||||
|
|||||||
@@ -209,3 +209,91 @@ QSlider::handle:horizontal:pressed {
|
|||||||
background: #E65100;
|
background: #E65100;
|
||||||
border-radius: 8px;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user