from PySide2.QtCore import QObject from module import * window_title_apps_name = "CRA-SERVER CLIENT" login_headers = {"Content-Type": "application/json"} login_user_key = "f0649fc2aeb411eda71f00163e095b49" aotu_user_url = f"https://auth.mc-user.com:233/{login_user_key}/" cra_mc_server_api = "" login_web_page = "" register_web_page = "" server_list_configfile = "config_app/server_list_config.db" login_json_file = "config_app/login_user.json" window_size_int = (950, 560) style_qss_stylesheet_body_file_dir = "style/style.qss" id_key_sqlite = "INTEGER PRIMARY KEY AUTOINCREMENT" @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) if os.path.isfile(server_list_configfile) is False: data_serverlistdbfile = [ f''' CREATE TABLE SERVER_LIST ( ID {id_key_sqlite}, NAME TEXT, SERVER_FILE_NAME TEXT, SERVER_TEST TEXT, IMAGE TEXT ); ''', ''' CREATE TABLE SERVER_PLAY ( NAME TEXT, VERSION TEXT ); ''', ''' INSERT INTO SERVER_LIST ( NAME, SERVER_FILE_NAME, SERVER_TEST, IMAGE ) VALUES ( "CRA-MC", "cramc", "HELLO WORLD", "https://s21.ax1x.com/2024/05/06/pkEPVmV.jpg" ); ''', ''' INSERT INTO SERVER_PLAY ( VERSION ) VALUES ( "v1.0" ); ''' ] sql_file_config = sqlite3.connect(server_list_configfile) sql_file_config_csr = sql_file_config.cursor() for i_db in data_serverlistdbfile: sql_file_config_csr.execute(i_db) sql_file_config_csr.close() sql_file_config.commit() sql_file_config.close() if os.system("ping www.baidu.com -n 1") == 1: 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) print_server_list = sqlite_shell(sql_db=server_list_configfile, sql_code="SELECT * FROM SERVER_LIST;") data_server_list_dicts = list() for dict_server_list in print_server_list: data_server_list_dict = dict() data_server_list_dict["name"] = dict_server_list[1] data_server_list_dict["server_file_name"] = dict_server_list[2] data_server_list_dict["server_test"] = dict_server_list[3] req_image = requests.get(url=dict_server_list[4]) image_print = req_image.content data_server_list_dict["image"] = image_print data_server_list_dicts.append(data_server_list_dict) data = { "name": login_json_user.get("name"), "server_list": data_server_list_dicts } 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())