From e180e58d0f81dcee778ca914d5ca56cab8e85ab5 Mon Sep 17 00:00:00 2001 From: shuaikangzhou <863909694@qq.com> Date: Thu, 16 Nov 2023 00:13:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=AF=86=E5=90=8E=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E8=81=94=E7=B3=BB=E4=BA=BA=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 28 +++++++++++++++------------- app/DataBase/micro_msg.py | 10 ++++++++++ app/ui_pc/contact/contact_window.py | 5 +++++ app/ui_pc/mainview.py | 7 ++++--- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3d29d56..f9c3bb3 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,8 +4,10 @@ - @@ -654,7 +655,8 @@ - diff --git a/app/DataBase/micro_msg.py b/app/DataBase/micro_msg.py index 9a99a2c..f437fad 100644 --- a/app/DataBase/micro_msg.py +++ b/app/DataBase/micro_msg.py @@ -10,6 +10,16 @@ if os.path.exists(micromsg_path): cursor = DB.cursor() +def init_database(): + global DB + global cursor + if not DB: + if os.path.exists(micromsg_path): + DB = sqlite3.connect(micromsg_path, check_same_thread=False) + # '''创建游标''' + cursor = DB.cursor() + + def is_database_exist(): return os.path.exists(micromsg_path) diff --git a/app/ui_pc/contact/contact_window.py b/app/ui_pc/contact/contact_window.py index 7ee62ec..4a0ea48 100644 --- a/app/ui_pc/contact/contact_window.py +++ b/app/ui_pc/contact/contact_window.py @@ -49,6 +49,7 @@ class ContactWindow(QWidget, Ui_Form): super().__init__(parent) self.show_thread = None self.setupUi(self) + self.ok_flag = False self.setStyleSheet(Stylesheet) self.init_ui() self.show_contacts() @@ -60,12 +61,16 @@ class ContactWindow(QWidget, Ui_Form): self.stackedWidget.setCurrentIndex(0) def show_contacts(self): + if self.ok_flag: + return + micro_msg.init_database() if not micro_msg.is_database_exist(): QMessageBox.critical(self, "错误", "数据库不存在\n请先解密数据库") return self.show_thread = ShowContactThread() self.show_thread.showSingal.connect(self.show_contact) self.show_thread.start() + self.ok_flag = True def show_contact(self, contact): contact_item = ContactQListWidgetItem(contact.nickName, contact.smallHeadImgUrl, contact.smallHeadImgBLOG) diff --git a/app/ui_pc/mainview.py b/app/ui_pc/mainview.py index 5d73691..7fc8ac4 100644 --- a/app/ui_pc/mainview.py +++ b/app/ui_pc/mainview.py @@ -85,8 +85,8 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow): label.setStyleSheet('background: rgb(%d, %d, %d);margin: 50px;' % ( randint(0, 255), randint(0, 255), randint(0, 255))) self.stackedWidget.addWidget(label) - contact_window = ContactWindow() - self.stackedWidget.addWidget(contact_window) + self.contact_window = ContactWindow() + self.stackedWidget.addWidget(self.contact_window) label = QLabel('我是页面', self) label.setAlignment(Qt.AlignCenter) # 设置label的背景颜色(这里随机) @@ -99,7 +99,8 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow): self.stackedWidget.setCurrentIndex(3) def setCurrentIndex(self, row): - print(row) + if row == 1: + self.contact_window.show_contacts() self.stackedWidget.setCurrentIndex(row) def about(self):