from PySide2.QtCore import QObject from module import * window_title_apps_name = "CRA-SERVER CLIENT" client_version = "v1.0.0" 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 = "https://craapi.xfcloud.org/api/" cra_mc_api_id = "IAts0Hp2MbUGw" server_ip_list_dict = "info/servers" reload_password_page = "https://login.mc-user.com:233/account/login" register_web_page = "https://login.mc-user.com:233/f0649fc2aeb411eda71f00163e095b49/register" login_json_file = "config_app/login_user.json" favorite_file_sqlite = "config_app/favorite.db" 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): try: data = dict() code = int(0) ping_server = os.system("ping www.baidu.com -n 3") if ping_server == 1: data = dict() code = int(2) data_config = { "data_config": data, "code": code } return self.data_th.emit(data_config) if os.path.isfile(favorite_file_sqlite) is False: sqlite_list_code = [ ''' CREATE TABLE Favorite_table ( ID INTEGER PRIMARY KEY AUTOINCREMENT, SERVERNAME TEXT, SERVER_TEST TEXT, IMAGE TEXT, SERVER_FILE_NAME TEXT ); ''' ] sql = sqlite3.connect(favorite_file_sqlite) csr = sql.cursor() for sqlite_play_i in sqlite_list_code: csr.execute(sqlite_play_i) csr.close() sql.commit() sql.close() 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) 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]] server_list_json_ = server_list_json_dict server_list0 = list() for i_server in server_list_json_: server_list1 = [ i_server.get("servername") ] server_list0.append(server_list1) for i_image_content_for in server_list_json_: req_image = requests.get(url=i_image_content_for.get("logourl")).content i_image_content_for.update({"image": req_image}) data = { "name": login_json_user.get("name"), "server_list": server_list_json_, "server_id_list": server_list0 } data_config = { "data_config": data, "code": code } return self.data_th.emit(data_config) except Exception as error: data = { "error": str(error) } code = int(9) data_configs = { "data_config": data, "code": code } return self.data_th.emit(data_configs) 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())