craml/main.py
2024-05-07 00:44:15 +08:00

284 lines
11 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from PySide2.QtGui import QCloseEvent
from module import *
class Login_Window_app(QWidget):
def __init__(self):
super().__init__()
self.run_myapp()
self.run_app()
def run_app(self):
self.setWindowTitle(apps.window_title_apps_name)
self.setWindowFlags(Qt.FramelessWindowHint)
self.setFixedSize(250, 110)
hbox = QHBoxLayout()
self.title = QLabel(text="正在启动 CRA-SERVER CLIENT")
self.title.setStyleSheet("font-size: 15px;")
hbox.addWidget(self.title, alignment=Qt.AlignCenter | Qt.AlignCenter)
self.setLayout(hbox)
def run_myapp(self):
self.th_start_config = apps.Thread_appcode_login_user()
self.th_start_config.data_th.connect(self.run_th_app)
self.th_start_config.start()
return None
def run_th_app(self, data_config: dict):
self.destroy()
if data_config.get("code") == 2:
apps.Message_ok(message="网络出问题了,请检查完网络连接再来哦主人")
return sys.exit(0)
if data_config.get("code") != 1:
self.start_cramc_server_client_myapp = My_APP_Window(data=data_config.get("data_config"), code=data_config.get("code"))
self.start_cramc_server_client_myapp.show()
return None
apps.Message_ok(message="CRA-USER已过期请重新登录")
self.login_user_window = Login_users_window_app()
self.login_user_window.show()
return None
def closeEvent(self, event: QCloseEvent) -> None:
self.destroy()
return sys.exit(0)
class Login_users_window_app(QWidget):
def __init__(self):
super().__init__()
self.setWindowFlags(Qt.FramelessWindowHint)
self.setFixedSize(apps.window_size_int[0], apps.window_size_int[1])
self.setWindowTitle(apps.window_title_apps_name + " - 登录")
self.draggable = False
self.offset = None
window_box = QGridLayout()
title_hbox = QHBoxLayout()
title_hbox.addWidget(QLabel(apps.window_title_apps_name), alignment=Qt.AlignLeft | Qt.AlignTop)
close_app_button = QToolButton()
close_app_button.setIcon(QIcon("style/exit.png"))
close_app_button.clicked.connect(self.close_apps_button_ttols)
title_hbox.addWidget(close_app_button, alignment=Qt.AlignRight | Qt.AlignTop)
login_user_box_hbox = QVBoxLayout()
login_user_box_hbox.setContentsMargins(250, 0, 250, 0)
login_user_box = QGridLayout()
login_user_box.setSpacing(15)
login_user_box.addWidget(QLabel(text="用户名:"), 0, 0, alignment=Qt.AlignTop)
self.username = QLineEdit()
login_user_box.addWidget(self.username, 0, 1, alignment=Qt.AlignTop)
login_user_box.addWidget(QLabel(text="密码:"), 1, 0, alignment=Qt.AlignTop)
self.password = QLineEdit()
self.password.setEchoMode(QLineEdit.Password)
login_user_box.addWidget(self.password, 1, 1, alignment=Qt.AlignTop)
login_user_button = QPushButton(text="登录")
login_user_button.clicked.connect(self.login_users_mcgames)
login_user_box.addWidget(login_user_button, 2, 0, 1, 0)
register_user = QToolButton(text="注册")
reload_password = QToolButton(text="忘记密码?")
login_user_box.addWidget(register_user, 3, 0, alignment=Qt.AlignTop | Qt.AlignLeft)
login_user_box.addWidget(reload_password, 3, 1, alignment=Qt.AlignTop | Qt.AlignRight)
login_user_box_hbox.addLayout(login_user_box)
window_box.addLayout(title_hbox, 0, 0, alignment=Qt.AlignTop)
window_box.addLayout(login_user_box_hbox, 1, 0, alignment=Qt.AlignTop | Qt.AlignCenter)
self.setLayout(window_box)
def login_users_mcgames(self):
if self.username.text() == "" or self.password.text() == "":
return apps.Message_ok(message="请填写完整的账号信息用户名和密码")
login_json = {
"username": self.username.text(),
"password": self.password.text()
}
url_https_mc_login = requests.post(url=apps.aotu_user_url + "authserver/authenticate", headers=apps.login_headers, json=login_json)
url_https_mc_login_json = url_https_mc_login.json()
if url_https_mc_login_json.get("error") == "ForbiddenOperationException":
return apps.Message_ok(message=url_https_mc_login_json.get("errorMessage"))
data_login_file = {
"accessToken": url_https_mc_login_json.get("accessToken"),
"clientToken": url_https_mc_login_json.get("clientToken"),
"id": url_https_mc_login_json["selectedProfile"]["id"],
"name": url_https_mc_login_json["selectedProfile"]["name"]
}
with open(file=apps.login_json_file, mode='w', encoding="UTF-8", newline='') as f_write:
json.dump(data_login_file, f_write)
self.destroy()
self.login_user_window = Login_Window_app()
self.login_user_window.show()
return None
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = True
self.offset = event.pos()
def mouseMoveEvent(self, event):
if self.draggable:
self.move(event.globalPos() - self.offset)
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = False
def closeEvent(self, event: QCloseEvent) -> None:
self.destroy()
return sys.exit(0)
def close_apps_button_ttols(self):
self.destroy()
return sys.exit(0)
class My_APP_Window(QTabWidget):
def __init__(self, data: dict, code: int):
super().__init__()
self.data = data
self.code = code
self.server_list_dict = self.data.get("server_list")
self.setWindowFlags(Qt.FramelessWindowHint)
self.setFixedSize(apps.window_size_int[0], apps.window_size_int[1])
self.setWindowTitle(apps.window_title_apps_name)
self.draggable = False
self.offset = None
self.run_my_gui()
def run_my_gui(self):
gui_box_grid = QGridLayout()
gui_box_grid.setColumnMinimumWidth(0, 0)
title_name = QLabel(text=apps.window_title_apps_name)
gui_box_grid.addWidget(title_name, 0, 0, alignment=Qt.AlignTop | Qt.AlignLeft)
zxh_button = QToolButton()
zxh_button.setIcon(QIcon("style/zxh.png"))
zxh_button.clicked.connect(self.zxh_apps)
exit_button = QToolButton()
exit_button.setIcon(QIcon("style/exit.png"))
exit_button.clicked.connect(self.exit_window_apps)
window_header_gridbox = QHBoxLayout()
window_header_gridbox.setContentsMargins(0, 0, 0, 0)
window_header_gridbox.addStretch(0)
window_header_gridbox.addWidget(zxh_button, alignment=Qt.AlignTop | Qt.AlignRight)
window_header_gridbox.addWidget(exit_button, alignment=Qt.AlignTop | Qt.AlignRight)
gui_box_grid.addLayout(window_header_gridbox, 0, 1)
self.index_home = QWidget()
self.craserver_client_settings = Craserver_client_settings()
self.craserver_client_game_settings = QWidget()
self.craserver_client_user_settings = QWidget()
self.header_tab = QTabWidget()
self.header_tab.setContentsMargins(0, 0, 0, 0)
self.header_tab.addTab(self.index_home, "主页")
self.header_tab.addTab(self.craserver_client_settings, "管理")
self.header_tab.addTab(self.craserver_client_game_settings, "设置")
self.header_tab.addTab(self.craserver_client_user_settings, "CRA-USER")
gui_box_grid.addWidget(self.header_tab, 1, 0, 1, 0)
self.setLayout(gui_box_grid)
self.index_home_page()
self.craserver_client_game_settings_page()
self.craserver_client_user_settings_page()
def craserver_client_user_settings_page(self):
pass
def craserver_client_game_settings_page(self):
pass
def index_home_page(self):
index_home_grid_box = QGridLayout()
self.server_list = QListWidget()
self.start_game_button = QPushButton(text="启动CRA-SERVER")
self.start_game_button.clicked.connect(self.start_games_apps)
self.start_game_button.setFixedSize(200, 55)
index_home_grid_box.addWidget(self.server_list, 0, 0)
index_home_grid_box.addWidget(self.start_game_button, 1, 0, alignment=Qt.AlignRight | Qt.AlignBottom)
for i_server_list in self.server_list_dict:
item = apps.customQListWidgetItem(image=i_server_list.get("image"), names=i_server_list.get("name"), tests=i_server_list.get("server_test"))
self.server_list.addItem(item)
self.server_list.setItemWidget(item, item.item_widget)
self.index_home.setLayout(index_home_grid_box)
def start_games_apps(self):
if self.server_list.currentRow() == -1:
return apps.Message_ok(message="请先选择需要加入的服务器")
return None
def zxh_apps(self):
return self.showMinimized()
def exit_window_apps(self):
self.destroy()
return sys.exit(0)
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = True
self.offset = event.pos()
def mouseMoveEvent(self, event):
if self.draggable:
self.move(event.globalPos() - self.offset)
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = False
def closeEvent(self, event: QCloseEvent) -> None:
self.destroy()
return sys.exit(0)
class Craserver_client_settings(QTabWidget):
def __init__(self):
super().__init__()
self.mods_settings = QWidget()
self.sh_settings = QWidget()
self.addTab(self.mods_settings, "MODS列表")
self.addTab(self.sh_settings, "光影管理")
self.mods_settings_page()
self.sh_settings_page()
def mods_settings_page(self):
pass
def sh_settings_page(self):
pass
if __name__ == '__main__':
is_json_none = False
QGuiApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough
)
QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
app = QApplication()
if os.path.exists("config_app") is False:
os.mkdir("config_app")
if os.path.isfile(apps.login_json_file) is False:
window = Login_users_window_app()
if os.path.isfile(apps.login_json_file) is True:
with open(file=apps.login_json_file, mode='r', encoding="UTF-8", newline='') as f_read:
json_test = json.load(f_read)
is_json_none = all(json_test)
if is_json_none is False:
window = Login_users_window_app()
if os.path.isfile(apps.login_json_file) is True & is_json_none is True:
window = Login_Window_app()
window.show()
sys.exit(app.exec_())