From 2714ca65776db58f941b6301859cfbef75b4f435 Mon Sep 17 00:00:00 2001 From: shuaikangzhou <863909694@qq.com> Date: Sat, 18 Nov 2023 20:13:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=8F=92=E5=85=A5=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 53 ++++++++++++++++++------------------- app/ui_pc/chat/chat_info.py | 7 +++-- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index df4ef8fc..d1636c28 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,10 +4,9 @@ - @@ -676,7 +677,8 @@ - diff --git a/app/DataBase/misc.py b/app/DataBase/misc.py index c5d885f7..ad0ede2c 100644 --- a/app/DataBase/misc.py +++ b/app/DataBase/misc.py @@ -13,6 +13,16 @@ cursor = DB.cursor() +def init_database(): + global DB + global cursor + if not DB: + if os.path.exists(misc_path): + DB = sqlite3.connect(misc_path, check_same_thread=False) + # '''创建游标''' + cursor = DB.cursor() + + def get_avatar_buffer(userName): sql = ''' select smallHeadBuf @@ -21,7 +31,12 @@ def get_avatar_buffer(userName): ''' try: lock.acquire(True) - cursor.execute(sql, [userName]) + try: + cursor.execute(sql, [userName]) + except AttributeError: + init_database() + finally: + cursor.execute(sql, [userName]) result = cursor.fetchall() # print(result[0][0]) if result: diff --git a/app/ui_pc/mainview.py b/app/ui_pc/mainview.py index 290bb47d..48262814 100644 --- a/app/ui_pc/mainview.py +++ b/app/ui_pc/mainview.py @@ -8,6 +8,7 @@ @comment : 主窗口 """ import json +import os.path from random import randint from PyQt5.QtCore import * @@ -72,24 +73,31 @@ def __init__(self, username, parent=None): self.setStyleSheet(Stylesheet) self.listWidget.clear() self.resize(QSize(800, 600)) - # self.stackedWidget = QtWidgets.QStackedWidget(self.centralwidget) self.action_desc.triggered.connect(self.about) self.load_data() self.init_ui() self.load_num = 0 def load_data(self): - with open('./app/data/info.json', 'r', encoding='utf-8') as f: - dic = json.loads(f.read()) - wxid = dic.get('wxid') - if wxid: - me = MePC() - self.set_my_info(wxid) + if os.path.exists('./app/data/info.json'): + with open('./app/data/info.json', 'r', encoding='utf-8') as f: + dic = json.loads(f.read()) + wxid = dic.get('wxid') + if wxid: + me = MePC() + self.set_my_info(wxid) + else: + QMessageBox.information( + self, + '温馨提示', + '点击 工具->获取信息 重启后可以显示本人头像哦' + ) def init_ui(self): # self.movie = QMovie("./app/data/loading.gif") self.label = QLabel(self) self.label.setGeometry(0, 0, self.width(), self.height()) + self.label.setVisible(False) # self.label.setMovie(self.movie) # self.movie.start() self.listWidget.currentRowChanged.connect(self.setCurrentIndex) @@ -105,6 +113,7 @@ def init_ui(self): self.listWidget.setCurrentRow(0) self.stackedWidget.setCurrentIndex(0) chat_window = ChatWindow() + # chat_window = QWidget() self.stackedWidget.addWidget(chat_window) contact_window = ContactWindow() self.stackedWidget.addWidget(contact_window) @@ -117,7 +126,7 @@ def init_ui(self): self.stackedWidget.addWidget(label) tool_window.load_finish_signal.connect(self.loading) contact_window.load_finish_signal.connect(self.loading) - chat_window.load_finish_signal.connect(self.loading) + # chat_window.load_finish_signal.connect(self.loading) # self.load_window_thread = LoadWindowThread(self.stackedWidget) # self.load_window_thread.okSignal.connect(self.stop_loading) # self.load_window_thread.start() @@ -126,6 +135,8 @@ def setCurrentIndex(self, row): self.stackedWidget.setCurrentIndex(row) if row == 2: self.stackedWidget.currentWidget().show_contacts() + if row == 1: + self.stackedWidget.currentWidget().show_chats() def setWindow(self, window): try: @@ -136,7 +147,10 @@ def setWindow(self, window): def set_my_info(self, wxid): self.avatar = QPixmap() - img_bytes = misc.get_avatar_buffer(wxid) + try: + img_bytes = misc.get_avatar_buffer(wxid) + except AttributeError: + return if img_bytes[:4] == b'\x89PNG': self.avatar.loadFromData(img_bytes, format='PNG') else: @@ -157,6 +171,7 @@ def stop_loading(self, a0): def loading(self, a0): self.load_num += 1 + self.label.setVisible(False) # print('加载一个了') if self.load_num == 2: # print('ok了') diff --git a/app/ui_pc/mainwindow.py b/app/ui_pc/mainwindow.py index 9347ae11..9c19217f 100644 --- a/app/ui_pc/mainwindow.py +++ b/app/ui_pc/mainwindow.py @@ -16,30 +16,31 @@ def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(1280, 779) MainWindow.setStyleSheet("\n" - "/*去掉item虚线边框*/\n" - "QListWidget, QListView, QTreeWidget, QTreeView {\n" - " outline: 0px;\n" - "}\n" - "/*设置左侧选项的最小最大宽度,文字颜色和背景颜色*/\n" - "QListWidget {\n" - " min-width: 120px;\n" - " max-width: 120px;\n" - " color: black;\n" - " background: white;\n" - " border:none;\n" - "}\n" - "QListWidget::item{\n" - " height:80;\n" - "}\n" - "/*被选中时的背景颜色和左边框颜色*/\n" - "QListWidget::item:selected {\n" - " background: rgb(204, 204, 204);\n" - " border-left: 4px solid rgb(9, 187, 7);\n" - "}\n" - "/*鼠标悬停颜色*/\n" - "HistoryPanel::item:hover {\n" - " background: rgb(52, 52, 52);\n" - "}") + " /*去掉item虚线边框*/\n" + " QListWidget, QListView, QTreeWidget, QTreeView {\n" + " outline: 0px;\n" + " }\n" + " /*设置左侧选项的最小最大宽度,文字颜色和背景颜色*/\n" + " QListWidget {\n" + " min-width: 120px;\n" + " max-width: 120px;\n" + " color: black;\n" + " background: white;\n" + " border:none;\n" + " }\n" + " QListWidget::item{\n" + " height:80;\n" + " }\n" + " /*被选中时的背景颜色和左边框颜色*/\n" + " QListWidget::item:selected {\n" + " background: rgb(204, 204, 204);\n" + " border-left: 4px solid rgb(9, 187, 7);\n" + " }\n" + " /*鼠标悬停颜色*/\n" + " HistoryPanel::item:hover {\n" + " background: rgb(52, 52, 52);\n" + " }\n" + " ") self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.horizontalLayout = QtWidgets.QHBoxLayout(self.centralwidget) @@ -58,6 +59,11 @@ def setupUi(self, MainWindow): self.myavatar.setObjectName("myavatar") self.listWidget = QtWidgets.QListWidget(self.frame_info) self.listWidget.setGeometry(QtCore.QRect(0, 230, 120, 331)) + self.listWidget.setMinimumSize(QtCore.QSize(120, 0)) + self.listWidget.setMaximumSize(QtCore.QSize(120, 16777215)) + self.listWidget.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) + self.listWidget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) + self.listWidget.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustIgnored) self.listWidget.setObjectName("listWidget") item = QtWidgets.QListWidgetItem() self.listWidget.addItem(item) @@ -93,6 +99,8 @@ def setupUi(self, MainWindow): self.menu_2.setObjectName("menu_2") self.menu_about = QtWidgets.QMenu(self.menubar) self.menu_about.setObjectName("menu_about") + self.menu_3 = QtWidgets.QMenu(self.menubar) + self.menu_3.setObjectName("menu_3") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") @@ -118,6 +126,7 @@ def setupUi(self, MainWindow): self.menubar.addAction(self.menu.menuAction()) self.menubar.addAction(self.menu_2.menuAction()) self.menubar.addAction(self.menu_about.menuAction()) + self.menubar.addAction(self.menu_3.menuAction()) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) @@ -143,6 +152,7 @@ def retranslateUi(self, MainWindow): self.menu.setTitle(_translate("MainWindow", "编辑")) self.menu_2.setTitle(_translate("MainWindow", "帮助")) self.menu_about.setTitle(_translate("MainWindow", "关于")) + self.menu_3.setTitle(_translate("MainWindow", "不显示或者显示异常请重启应用")) self.action_3.setText(_translate("MainWindow", "保存")) self.action_4.setText(_translate("MainWindow", "退出")) self.action.setText(_translate("MainWindow", "关于")) diff --git a/app/ui_pc/mainwindow.ui b/app/ui_pc/mainwindow.ui index 3bbcb763..7d5485dc 100644 --- a/app/ui_pc/mainwindow.ui +++ b/app/ui_pc/mainwindow.ui @@ -99,19 +99,19 @@ 0 230 - 80 + 120 331 - 80 + 120 0 - 80 + 120 16777215 @@ -205,10 +205,16 @@ + + + 不显示或者显示异常请重启应用 + + + diff --git a/readme.md b/readme.md index d9a17ce5..290ded6d 100644 --- a/readme.md +++ b/readme.md @@ -34,7 +34,7 @@ 大家有任何想法、建议或bug可以群里反馈给我 - +[//]: # () ## 效果