Code some ui and fix parse library will throw exception sometimes.
This commit is contained in:
+108
-22
@@ -1,38 +1,124 @@
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtCore import Qt, QSize
|
||||
from PySide6.QtGui import QPixmap
|
||||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QLabel
|
||||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QLabel, QListWidget, QPushButton, QHBoxLayout, QListWidgetItem, \
|
||||
QMenu
|
||||
|
||||
|
||||
class AccountWidget(QWidget):
|
||||
def __init__(self, account_name, account_head: QPixmap, login_status, parent=None,
|
||||
/, delete_account_callback=None, check_account_callback=None, switch_account_callback=None):
|
||||
QWidget.__init__(self, parent)
|
||||
|
||||
self.layout = QHBoxLayout(self)
|
||||
|
||||
self.head_icon_label = QLabel()
|
||||
self.head_icon_label.setObjectName("HeadIcon")
|
||||
self.head_icon_label.setPixmap(account_head)
|
||||
|
||||
self.account_name = QLabel(account_name)
|
||||
|
||||
self.status_label = QLabel(login_status)
|
||||
|
||||
self.layout.addWidget(self.head_icon_label)
|
||||
self.layout.addWidget(self.account_name)
|
||||
self.layout.addStretch()
|
||||
self.layout.addWidget(self.status_label)
|
||||
|
||||
self.delete_account_callback = delete_account_callback
|
||||
self.check_account_callback = check_account_callback
|
||||
self.switch_account_callback = switch_account_callback
|
||||
|
||||
self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
||||
self.customContextMenuRequested.connect(self.show_right_click_menu)
|
||||
|
||||
def show_right_click_menu(self, position):
|
||||
context_menu = QMenu(self)
|
||||
|
||||
switch_acc_action = context_menu.addAction("Switch to this account")
|
||||
check_log_stat_action = context_menu.addAction("Check login status")
|
||||
|
||||
context_menu.addSeparator()
|
||||
|
||||
delete_account_action = context_menu.addAction("Delete account")
|
||||
|
||||
global_position = self.mapToGlobal(position)
|
||||
|
||||
selected_action = context_menu.exec(global_position)
|
||||
|
||||
if selected_action == delete_account_action:
|
||||
# handle callback here
|
||||
if callable(self.delete_account_callback): self.delete_account_callback()
|
||||
elif selected_action == check_log_stat_action and callable(self.check_account_callback): self.check_account_callback()
|
||||
elif selected_action == switch_acc_action and callable(self.switch_account_callback): self.switch_account_callback()
|
||||
|
||||
class AccountPage(QWidget):
|
||||
def __init__(self, app, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
self.app = app
|
||||
|
||||
self.layout = QVBoxLayout()
|
||||
self.layout = QHBoxLayout()
|
||||
|
||||
# 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")
|
||||
# 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.layout.addStretch()
|
||||
# self.layout.addWidget(self.icon_label, alignment=Qt.AlignmentFlag.AlignCenter)
|
||||
# self.layout.addWidget(self.dev_info_box, alignment=Qt.AlignmentFlag.AlignHCenter)
|
||||
# self.layout.addWidget(self.dev_info_2, alignment=Qt.AlignmentFlag.AlignHCenter)
|
||||
# self.layout.addStretch()
|
||||
#
|
||||
# if Path(self.app.resources_dir, "pictures", "in_progress.png").exists():
|
||||
# image = QPixmap(Path(self.app.resources_dir, "pictures", "in_progress.png"))
|
||||
# self.icon_label.setPixmap(image.scaled(300, 300))
|
||||
# else:
|
||||
# self.icon_label.setText("Ouch. The icon is missing.")
|
||||
#
|
||||
# self.setLayout(self.layout)
|
||||
# self.app.apply_qss(Path("main.qss"), self.setStyleSheet)
|
||||
|
||||
self.layout.addStretch()
|
||||
self.layout.addWidget(self.icon_label, alignment=Qt.AlignmentFlag.AlignCenter)
|
||||
self.layout.addWidget(self.dev_info_box, alignment=Qt.AlignmentFlag.AlignHCenter)
|
||||
self.layout.addWidget(self.dev_info_2, alignment=Qt.AlignmentFlag.AlignHCenter)
|
||||
self.layout.addStretch()
|
||||
self.main_layout = QVBoxLayout()
|
||||
self.right_layout = QVBoxLayout()
|
||||
|
||||
if Path(self.app.resources_dir, "pictures", "in_progress.png").exists():
|
||||
image = QPixmap(Path(self.app.resources_dir, "pictures", "in_progress.png"))
|
||||
self.icon_label.setPixmap(image.scaled(300, 300))
|
||||
else:
|
||||
self.icon_label.setText("Ouch. The icon is missing.")
|
||||
self.account_list = QListWidget(self)
|
||||
|
||||
self.add_account_button = QPushButton("Add Account")
|
||||
self.refresh_button = QPushButton("Refresh all")
|
||||
self.delete_all_button = QPushButton("Delete All")
|
||||
|
||||
self.main_layout.addWidget(self.account_list)
|
||||
self.right_layout.addWidget(self.add_account_button)
|
||||
self.right_layout.addWidget(self.refresh_button)
|
||||
self.right_layout.addWidget(self.delete_all_button)
|
||||
self.right_layout.addStretch()
|
||||
|
||||
self.layout.addLayout(self.main_layout)
|
||||
self.layout.addLayout(self.right_layout)
|
||||
|
||||
self.setLayout(self.layout)
|
||||
self.app.apply_qss(Path("main.qss"), self.setStyleSheet)
|
||||
|
||||
self.test()
|
||||
|
||||
def test(self):
|
||||
head_icon = self.app.get_icon(Path(self.app.icon_dir, "head.png"))
|
||||
for i in range(1, 11):
|
||||
name = f"Player_{i}"
|
||||
head_pixmap = head_icon.pixmap(QSize(50, 50))
|
||||
list_item = QListWidgetItem()
|
||||
|
||||
def delete():
|
||||
self.account_list.removeItemWidget(list_item)
|
||||
item = AccountWidget(name, head_pixmap, self, delete_account_callback=delete)
|
||||
list_item.setSizeHint(item.sizeHint())
|
||||
self.account_list.addItem(list_item)
|
||||
self.account_list.setItemWidget(list_item, item)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6 import QtGui
|
||||
from PySide6.QtCore import QSize
|
||||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QComboBox, QListWidget, QPushButton, QLabel, QHBoxLayout
|
||||
|
||||
from core_lib.launcher.object import Launcher as LauncherObject
|
||||
|
||||
class CreateProfile(QWidget):
|
||||
def __init__(self, launcher: "LauncherObject",parent=None):
|
||||
super(CreateProfile, self).__init__(parent)
|
||||
self.app = launcher
|
||||
|
||||
self.layout = QHBoxLayout()
|
||||
|
||||
self.main_layout = QVBoxLayout()
|
||||
self.right_layout = QVBoxLayout()
|
||||
self.operate_layout = QHBoxLayout()
|
||||
|
||||
# Some items
|
||||
self.version_type_label = QLabel("Version Type")
|
||||
self.version_type_dropdown = QComboBox()
|
||||
self.version_type_dropdown.setObjectName("Dropdown")
|
||||
|
||||
self.mod_loader_icon_label = QLabel()
|
||||
icon = self.app.get_icon(Path(self.app.icon_dir, "mod_loader_temp.png"))
|
||||
pixmap = icon.pixmap(QSize(100, 100))
|
||||
self.mod_loader_icon_label.setPixmap(pixmap)
|
||||
self.mod_loader_label = QLabel("Mod Loader")
|
||||
self.mod_loader_dropdown = QComboBox()
|
||||
self.mod_loader_dropdown.setObjectName("Dropdown")
|
||||
|
||||
self.version_list_type_label = QLabel("Version: Vanilla")
|
||||
self.version_list_label = QLabel("Select a version to continue:")
|
||||
self.version_list = QListWidget()
|
||||
self.version_list.setObjectName("ListWidget")
|
||||
|
||||
self.create_profile = QPushButton("Create Profile")
|
||||
self.create_profile.setObjectName("Button")
|
||||
|
||||
self.refresh_button = QPushButton("Refresh")
|
||||
self.refresh_button.setObjectName("Button")
|
||||
|
||||
self.main_layout.addWidget(self.version_list_label)
|
||||
self.main_layout.addWidget(self.version_list)
|
||||
self.operate_layout.addWidget(self.version_list_type_label)
|
||||
self.operate_layout.addStretch()
|
||||
self.operate_layout.addWidget(self.refresh_button)
|
||||
self.operate_layout.addWidget(self.create_profile)
|
||||
|
||||
self.main_layout.addLayout(self.operate_layout)
|
||||
|
||||
self.right_layout.addWidget(self.mod_loader_icon_label)
|
||||
self.right_layout.addWidget(self.mod_loader_label)
|
||||
self.right_layout.addWidget(self.mod_loader_dropdown)
|
||||
self.right_layout.addWidget(self.version_type_label)
|
||||
self.right_layout.addWidget(self.version_type_dropdown)
|
||||
self.right_layout.addStretch()
|
||||
self.right_layout.setContentsMargins(0, 20, 0, 0)
|
||||
|
||||
self.setLayout(self.layout)
|
||||
self.layout.addLayout(self.main_layout)
|
||||
self.layout.addLayout(self.right_layout)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user