Files
PyQt6_LaTaniere/mainwindow.py
2026-03-05 11:05:38 +01:00

125 lines
4.0 KiB
Python

import sys
import os
from PyQt6 import QtGui, QtWidgets
from PyQt6 import uic
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QFontDatabase, QFont, QColor
from PyQt6.QtWidgets import QApplication, QMainWindow
from win11toast import toast, notify
from slidergroovecolorstyle import ThinSubPageLineStyle, ThinAddPageLineStyle
# Compile resources.qrc into resources_rc.py
# rcc -g python resources.qrc -o resources_rc.py
import resources # This is generated from the .qrc file # noqa: F401
# À placer tout en haut, avant les imports PyQt6 si possible
if sys.platform.startswith('linux'):
os.environ["QT_QPA_PLATFORM"] = "xcb"
# Remove this into final release
from fake_patch_notes import patch_note
NO_STAFF = True
def load_custom_font():
# Load font from Qt resource
font_id = QFontDatabase.addApplicationFont(":/assets/Avocado-Cake-Demo.otf")
if font_id == -1:
raise RuntimeError("Failed to load font from resources.")
# Get the family name of the loaded font
font_families = QFontDatabase.applicationFontFamilies(font_id)
if not font_families:
raise RuntimeError("No font families found in the loaded font.")
return font_families[0]
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Remove the title bar and window frame
self.setWindowFlags(Qt.WindowType.FramelessWindowHint |Qt.WindowType.Window)
# Optional: Make background transparent (if you want rounded corners, etc.)
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
# Track mouse position for dragging
self._drag_pos = None
# Load font family from resource
font_family = load_custom_font()
uic.loadUi("mainwindow.ui", self)
# Adjust UI
self.maintitle_label.setFont(QFont(font_family, 38))
self.subtitle_label.setStyleSheet("color: rgb(163, 177, 198)")
#self.horizontalSlider.setStyle(ThinAddPageLineStyle(app.style(), QColor("#2196F3")))
if NO_STAFF :
self.staff_btn.hide()
self.spacer_substitution.hide()
self.info_text.setMarkdown(patch_note)
# Find the button by its objectName in Qt Designer
# Example: objectName = "close_btn"
self.close_btn.clicked.connect(self.close_link)
self.minimize_btn.clicked.connect(self.minimize_link)
self.connexion_btn.clicked.connect(self.connexion_btn_link)
def close_link(self):
sys.exit(app.exec())
def minimize_link(self):
# Minimize the application
self.setWindowState(Qt.WindowState.WindowMinimized)
# Mouse press event to start dragging
def mousePressEvent(self, event):
if event.button() == Qt.MouseButton.LeftButton:
self._drag_pos = event.globalPosition().toPoint() - self.frameGeometry().topLeft()
event.accept()
# Mouse move event to drag window
def mouseMoveEvent(self, event):
if event.buttons() == Qt.MouseButton.LeftButton and self._drag_pos is not None:
self.move(event.globalPosition().toPoint() - self._drag_pos)
event.accept()
# Mouse release event to stop dragging
def mouseReleaseEvent(self, event):
self._drag_pos = None
event.accept()
def connexion_btn_link(self):
icon = {
'src': ':/assets/background.png',
'placement': 'appLogoOverride'
}
buttons = [
{'activationType': 'protocol', 'arguments': '', 'content': 'Entrer en jeu'},
]
toast('C\'est enfin à ton tour d\'entrer en jeu! 🎮🐍', app_id='LaTanière Launcher',buttons=buttons)
if __name__ == "__main__":
app = QApplication(sys.argv)
with open('styles.qss', 'r') as f:
style = f.read()
# Set the stylesheet of the application
app.setStyleSheet(style)
# Load and set the global font
custom_font = QFont(load_custom_font(), 16)
if custom_font:
app.setFont(custom_font)
window = MainWindow()
window.show()
sys.exit(app.exec())