2026-07-10 23:27:21 +08:00
|
|
|
import logging
|
2026-07-11 01:19:36 +08:00
|
|
|
from pathlib import Path
|
2026-07-10 20:57:31 +08:00
|
|
|
|
2026-07-14 01:13:36 +08:00
|
|
|
from PySide6.QtGui import QIcon, Qt, QImage, QPixmap
|
2026-07-14 01:17:37 +08:00
|
|
|
from PySide6.QtWidgets import QApplication, QMainWindow, QLabel, QVBoxLayout, QWidget, QPushButton
|
2026-07-11 01:19:36 +08:00
|
|
|
|
2026-07-10 23:27:21 +08:00
|
|
|
from core_lib.qt.hack import move_window_to_center
|
2026-07-12 00:06:11 +08:00
|
|
|
from dialog.test import TestDialog
|
2026-07-10 20:57:31 +08:00
|
|
|
|
2026-07-14 01:13:36 +08:00
|
|
|
LAUNCHER_VERSION = "alpha_0.0.1"
|
|
|
|
|
MAIN_REPO_URL = "https://repo.weispace.net/wei/Launcher/"
|
|
|
|
|
|
2026-07-10 20:57:31 +08:00
|
|
|
class Launcher(QApplication):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__()
|
2026-07-12 00:06:11 +08:00
|
|
|
# Window config
|
2026-07-10 20:57:31 +08:00
|
|
|
self.setApplicationName("TestLauncher")
|
|
|
|
|
self.main_window = QMainWindow()
|
|
|
|
|
self.main_window.setGeometry(0, 0, 800, 600)
|
|
|
|
|
move_window_to_center(self.main_window)
|
|
|
|
|
|
2026-07-12 00:06:11 +08:00
|
|
|
# logger
|
2026-07-10 23:27:21 +08:00
|
|
|
self.logger = logging.getLogger("Launcher.MainWindow")
|
|
|
|
|
|
2026-07-12 00:06:11 +08:00
|
|
|
# dirs
|
|
|
|
|
self.program_dir = Path(__file__).parent
|
|
|
|
|
self.work_dir = Path.cwd()
|
2026-07-10 23:27:21 +08:00
|
|
|
|
2026-07-12 00:06:11 +08:00
|
|
|
# test page
|
|
|
|
|
self.test_dialog = TestDialog(self, self.main_window)
|
2026-07-11 01:19:36 +08:00
|
|
|
|
2026-07-14 01:13:36 +08:00
|
|
|
# Set icon
|
|
|
|
|
if self.icon_path.exists():
|
|
|
|
|
self.setWindowIcon(QIcon(self.icon_path.as_posix()))
|
|
|
|
|
else:
|
|
|
|
|
self.logger.error("No icon found.")
|
|
|
|
|
|
|
|
|
|
self.central = QWidget()
|
|
|
|
|
|
|
|
|
|
# center message (will be deleted if launcher finished development)
|
|
|
|
|
content = """Still digging!"""
|
|
|
|
|
message = "If you found that something might be a issue. You can report it to the main repo! Any suggestion are welcome."
|
|
|
|
|
self.icon_label = QLabel()
|
|
|
|
|
self.icon_label.setObjectName("icon_label")
|
|
|
|
|
self.dev_info_box = QLabel(content)
|
|
|
|
|
self.dev_info_box.setObjectName("dev_info_box")
|
|
|
|
|
self.dev_info_2 = QLabel(message)
|
|
|
|
|
self.dev_info_2.setObjectName("dev_info_message")
|
|
|
|
|
self.version_label = QLabel("Current version: {}".format(self.launcher_version))
|
|
|
|
|
self.version_label.setObjectName("version_label")
|
|
|
|
|
self.repo_url_label = QLabel(f"<a href=\"{MAIN_REPO_URL}\">Main repo</a>")
|
|
|
|
|
self.repo_url_label.setObjectName("repo_url_label")
|
|
|
|
|
self.repo_url_label.setOpenExternalLinks(True)
|
|
|
|
|
self.main_layout = QVBoxLayout(self.central)
|
|
|
|
|
|
|
|
|
|
if Path(self.resources_dir, "pictures", "in_progress.png").exists():
|
|
|
|
|
image = QPixmap(Path(self.resources_dir, "pictures", "in_progress.png"))
|
|
|
|
|
self.icon_label.setPixmap(image.scaled(300, 300))
|
|
|
|
|
else:
|
|
|
|
|
self.icon_label.setText("Ouch. The icon is missing.")
|
|
|
|
|
|
2026-07-14 01:17:37 +08:00
|
|
|
self.open_test_window = QPushButton("Open test")
|
|
|
|
|
self.open_test_window.clicked.connect(lambda : self.test_dialog.show())
|
|
|
|
|
self.open_test_window.setObjectName("open_test_window")
|
|
|
|
|
|
2026-07-14 01:13:36 +08:00
|
|
|
self.main_layout.addStretch()
|
|
|
|
|
self.main_layout.addWidget(self.icon_label, alignment=Qt.AlignmentFlag.AlignCenter)
|
|
|
|
|
self.main_layout.addWidget(self.dev_info_box, alignment=Qt.AlignmentFlag.AlignHCenter)
|
|
|
|
|
self.main_layout.addWidget(self.dev_info_2, alignment=Qt.AlignmentFlag.AlignHCenter)
|
|
|
|
|
self.main_layout.addWidget(self.version_label, alignment=Qt.AlignmentFlag.AlignHCenter)
|
|
|
|
|
self.main_layout.addWidget(self.repo_url_label, alignment=Qt.AlignmentFlag.AlignHCenter)
|
|
|
|
|
self.main_layout.addStretch()
|
2026-07-14 01:17:37 +08:00
|
|
|
self.main_layout.addWidget(self.open_test_window, alignment=Qt.AlignmentFlag.AlignRight)
|
2026-07-14 01:13:36 +08:00
|
|
|
|
|
|
|
|
self.main_window.setCentralWidget(self.central)
|
|
|
|
|
|
|
|
|
|
self.setStyleSheet("""
|
|
|
|
|
QLabel#dev_info_box {
|
|
|
|
|
font-size: 20pt;
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLabel#dev_info_message {
|
|
|
|
|
font-size: 10pt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLabel#version_label, QLabel#version_label {
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLabel#icon_label {
|
|
|
|
|
border-radius: 20px;
|
|
|
|
|
}
|
2026-07-14 01:17:37 +08:00
|
|
|
|
|
|
|
|
QPushButton#open_test_window {
|
|
|
|
|
padding: 10px;
|
|
|
|
|
}
|
2026-07-14 01:13:36 +08:00
|
|
|
""")
|
2026-07-11 01:19:36 +08:00
|
|
|
|
2026-07-12 00:06:11 +08:00
|
|
|
def exec(self):
|
|
|
|
|
self.main_window.show()
|
2026-07-14 01:13:36 +08:00
|
|
|
self.test_dialog.show()
|
2026-07-12 00:06:11 +08:00
|
|
|
self.exec_()
|
2026-07-11 01:19:36 +08:00
|
|
|
|
2026-07-12 00:06:11 +08:00
|
|
|
@property
|
|
|
|
|
def temp_dir(self):
|
|
|
|
|
return self.work_dir / "temp"
|
2026-07-11 01:19:36 +08:00
|
|
|
|
2026-07-12 00:06:11 +08:00
|
|
|
@property
|
|
|
|
|
def config_dir(self):
|
|
|
|
|
return self.work_dir / "config"
|
2026-07-11 01:19:36 +08:00
|
|
|
|
2026-07-12 00:06:11 +08:00
|
|
|
@property
|
|
|
|
|
def data_dir(self):
|
|
|
|
|
return self.work_dir / "data"
|
2026-07-11 01:19:36 +08:00
|
|
|
|
2026-07-12 00:06:11 +08:00
|
|
|
@property
|
|
|
|
|
def log_dir(self):
|
2026-07-14 01:13:36 +08:00
|
|
|
return self.work_dir / "log"
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def resources_dir(self):
|
|
|
|
|
return self.program_dir / "resources"
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def icon_path(self):
|
|
|
|
|
return self.resources_dir / "icons" / "icon.png"
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def launcher_version(self):
|
|
|
|
|
return LAUNCHER_VERSION
|