craml/apps.py

203 lines
6.9 KiB
Python
Raw Normal View History

2024-05-06 02:27:06 +08:00
from PySide2.QtCore import QObject
from module import *
window_title_apps_name = "CRA-SERVER CLIENT"
2024-05-17 13:13:58 +08:00
client_version = "v1.0.0"
2024-05-06 02:27:06 +08:00
login_headers = {"Content-Type": "application/json"}
login_user_key = "f0649fc2aeb411eda71f00163e095b49"
aotu_user_url = f"https://auth.mc-user.com:233/{login_user_key}/"
2024-05-20 16:23:36 +08:00
cra_mc_server_api = "https://craapi.xfcloud.org/api/"
cra_mc_api_id = "IAts0Hp2MbUGw"
server_ip_list_dict = "info/servers"
2024-05-06 02:27:06 +08:00
2024-05-07 00:59:50 +08:00
reload_password_page = "https://login.mc-user.com:233/account/login"
register_web_page = "https://login.mc-user.com:233/f0649fc2aeb411eda71f00163e095b49/register"
2024-05-07 00:44:15 +08:00
2024-05-06 02:27:06 +08:00
login_json_file = "config_app/login_user.json"
window_size_int = (950, 560)
style_qss_stylesheet_body_file_dir = "style/style.qss"
@staticmethod
def readQSS(style: str):
with open(file=style, mode='r', encoding="UTF-8") as f:
return f.read()
def sqlite_shell(sql_db: str, sql_code: str):
sqlite_connect = sqlite3.connect(sql_db)
sqlite_cursor = sqlite_connect.cursor()
sqlite_cursor.execute(sql_code)
print_sql = sqlite_cursor.fetchall()
sqlite_cursor.close()
sqlite_connect.commit()
sqlite_connect.close()
return print_sql
class Message_ok(QMessageBox):
def __init__(self, message: str):
super().__init__()
self.draggable = False
self.offset = None
self.setWindowFlags(Qt.FramelessWindowHint)
self.setWindowTitle(window_title_apps_name)
self.setText(message)
self.setStandardButtons(QMessageBox.Ok)
button_yes = self.button(QMessageBox.Ok)
button_yes.setText("好的")
self.exec_()
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
class Message_yes_no(QMessageBox):
def __init__(self, message: str):
super().__init__()
self.draggable = False
self.offset = None
self.setWindowFlags(Qt.FramelessWindowHint)
self.setWindowTitle(window_title_apps_name)
self.setText(message)
self.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
self.button_yes = self.button(QMessageBox.Yes)
self.button_yes.setText("确定")
button_no = self.button(QMessageBox.No)
button_no.setText("取消")
self.exec_()
def value(self):
if self.clickedButton() == self.button_yes:
return True
return False
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
class Thread_appcode_login_user(QThread):
data_th = Signal(dict)
def __init__(self):
super(Thread_appcode_login_user, self).__init__()
def run(self):
data = dict()
code = int(0)
2024-05-17 13:13:58 +08:00
ping_server = os.system("ping www.baidu.com -n 3")
if ping_server == 1:
2024-05-06 02:27:06 +08:00
data = dict()
code = int(2)
data_config = {
"data_config": data,
"code": code
}
return self.data_th.emit(data_config)
with open(file=login_json_file, mode='r', encoding="UTF-8", newline='') as f_read:
login_json_user = json.load(f_read)
login_user = {
"accessToken": login_json_user.get("accessToken"),
"clientToken": login_json_user.get("clientToken")
}
json_login_crauser = requests.post(url=aotu_user_url + "authserver/validate", headers=login_headers, json=login_user)
if json_login_crauser.status_code != 204:
ref_login_key = requests.post(url=aotu_user_url + "authserver/refresh", headers=login_headers, json=login_user)
if ref_login_key.status_code != 204:
data = dict()
code = int(1)
data_config = {
"data_config": data,
"code": code
}
return self.data_th.emit(data_config)
url_https_mc_login_json = requests.post(url=aotu_user_url + "authserver/refresh", headers=login_headers, json=login_user)
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=login_json_file, mode='w', encoding="UTF-8", newline='') as dump_f:
json.dump(data_login_file, dump_f)
2024-05-20 16:23:36 +08:00
req_server_list_api = requests.get(url=cra_mc_server_api + server_ip_list_dict, headers=login_headers)
server_list_json_dict: dict = [req_server_list_api.json()[cra_mc_api_id]]
2024-05-17 13:13:58 +08:00
server_list_json_ = server_list_json_dict
server_list0 = list()
for i_server in server_list_json_:
server_list1 = [
2024-05-20 16:23:36 +08:00
i_server.get("servername")
2024-05-17 13:13:58 +08:00
]
server_list0.append(server_list1)
for i_image_content_for in server_list_json_:
2024-05-20 16:23:36 +08:00
req_image = requests.get(url=i_image_content_for.get("logourl")).content
2024-05-17 13:13:58 +08:00
i_image_content_for.update({"image": req_image})
2024-05-06 02:27:06 +08:00
data = {
"name": login_json_user.get("name"),
2024-05-17 13:13:58 +08:00
"server_list": server_list_json_,
"server_id_list": server_list0
2024-05-06 02:27:06 +08:00
}
data_config = {
"data_config": data,
"code": code
}
return self.data_th.emit(data_config)
class customQListWidgetItem(QListWidgetItem):
def __init__(self, image, names: str, tests: str):
super().__init__()
self.item_widget = QWidget()
images = QImage.fromData(image)
image = QLabel()
image.setPixmap(QPixmap.fromImage(images).scaled(144, 60))
name = QLabel()
name.setText(str(names))
test = QLabel()
test.setText(str(tests))
vbox_server_test = QVBoxLayout()
vbox_server_test.addWidget(name, alignment=Qt.AlignLeft | Qt.AlignTop)
vbox_server_test.addWidget(test, alignment=Qt.AlignTop | Qt.AlignLeft)
hb_box = QHBoxLayout()
hb_box.setSpacing(10)
hb_box.setContentsMargins(0, 0, 0, 0)
hb_box.addWidget(image, alignment=Qt.AlignLeft | Qt.AlignLeft)
hb_box.addLayout(vbox_server_test)
hb_box.addStretch(1)
self.item_widget.setLayout(hb_box)
self.setSizeHint(self.item_widget.sizeHint())