diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index cacb730..7303246 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,11 +4,17 @@
-
-
-
+
+
+
+
-
+
+
+
+
+
+
@@ -71,7 +77,7 @@
-
+
@@ -179,8 +185,8 @@
-
+
@@ -479,7 +485,14 @@
1699025065814
-
+
+ 1699026207401
+
+
+
+ 1699026207401
+
+
@@ -532,13 +545,13 @@
-
-
+
+
diff --git a/app/DataBase/data.py b/app/DataBase/data.py
index 99b9fb5..c0d356d 100644
--- a/app/DataBase/data.py
+++ b/app/DataBase/data.py
@@ -10,6 +10,7 @@
import hashlib
import os
import sqlite3
+import threading
import time
import requests
@@ -18,7 +19,7 @@ from app import person
DB = None
cursor = None
-
+lock = threading.Lock()
Type = {
1: '文本内容',
2: '位置信息',
@@ -187,14 +188,29 @@ def timestamp2str(timestamp):
def get_conRemark(username):
- sql = 'select conRemark,nickname from rcontact where username=?'
- cursor.execute(sql, [username])
- result = cursor.fetchone()
- if result:
- if result[0]:
- return result[0]
- else:
- return result[1]
+ try:
+ lock.acquire(True)
+ sql = 'select conRemark,nickname from rcontact where username=?'
+ cursor.execute(sql, [username])
+ result = cursor.fetchone()
+ if result:
+ if result[0]:
+ return result[0]
+ else:
+ return result[1]
+ except:
+ time.sleep(0.1)
+ sql = 'select conRemark,nickname from rcontact where username=?'
+ cursor.execute(sql, [username])
+ result = cursor.fetchone()
+ if result:
+ if result[0]:
+ return result[0]
+ else:
+ return result[1]
+ finally:
+ lock.release()
+
return False
diff --git a/app/Ui/contact/analysis/analysis.py b/app/Ui/contact/analysis/analysis.py
index 0a62545..1c1d5c4 100644
--- a/app/Ui/contact/analysis/analysis.py
+++ b/app/Ui/contact/analysis/analysis.py
@@ -23,9 +23,7 @@ class AnalysisController(QWidget):
self.center()
self.setAttribute(Qt.WA_AttributeCount)
self.label_01()
- self.Thread = LoadData(username)
- self.Thread.okSignal.connect(self.initUI)
- self.Thread.start()
+ self.isStart = False
def center(self): # 定义一个函数使得窗口居中显示
# 获取屏幕坐标系
@@ -128,6 +126,13 @@ class AnalysisController(QWidget):
# palette.setColor(self.backgroundRole(), QColor(192, 253, 123)) # 设置背景颜色
self.setPalette(palette)
+ def start(self):
+ if not self.isStart:
+ self.Thread = LoadData(self.ta_username)
+ self.Thread.okSignal.connect(self.initUI)
+ self.Thread.start()
+ self.isStart = True
+
class LoadData(QThread):
"""
diff --git a/app/Ui/contact/contact.py b/app/Ui/contact/contact.py
index 3d32be3..04865fa 100644
--- a/app/Ui/contact/contact.py
+++ b/app/Ui/contact/contact.py
@@ -15,6 +15,7 @@ from PyQt5.QtWidgets import *
import app.Ui.MyComponents.Contact as MyLabel
from .analysis import analysis
+from .contactInfo import ContactInfo
from .contactUi import *
from .emotion import emotion
from .report import report
@@ -50,6 +51,7 @@ class ContactController(QWidget, Ui_Dialog):
self.Me = Me
self.Thread = ChatMsg(self.Me.wxid, None)
self.contacts: Dict[str, MyLabel.ContactUi] = {}
+ self.contactInfo: Dict[str, ContactInfo] = {}
self.last_btn = None
self.chat_flag = True
self.show_flag = False
@@ -64,21 +66,13 @@ class ContactController(QWidget, Ui_Dialog):
self.view_analysis = {}
self.showContact()
- self.now_btn = self.userinfo
+ # self.now_btn = self.userinfo
+ self.now_btn = None
self.last_btn = None
def initui(self):
- # 槽函数连接
- self.btn_back.clicked.connect(self.back)
- # self.btn_output.clicked.connect(self.output)
- self.btn_analysis.clicked.connect(self.analysis)
- self.btn_emotion.clicked.connect(self.emotionale_Analysis)
- self.btn_report.clicked.connect(self.annual_report)
-
+ return
self.lay0 = QVBoxLayout()
- # self.widget.setLayout(self.lay0)
- # self.widget.setStyleSheet('''QWidget{background-color:rgb(255, 255, 255);}''')
- # self.stackedWidget.setStyleSheet('''QWidget{background-color:rgb(240, 240, 240);}''')
self.stackedWidget.setStyleSheet('''QWidget{background-color:rgb(255, 255, 255);}''')
self.frame = QtWidgets.QFrame()
self.frame.setObjectName("frame")
@@ -87,19 +81,6 @@ class ContactController(QWidget, Ui_Dialog):
self.userinfo.progressBar.setVisible(False)
self.stackedWidget.addWidget(self.frame)
# self.lay0.addWidget(self.frame)
- menu = QMenu(self)
- self.toDocxAct = QAction(QIcon('app/data/icons/word.svg'), '导出Docx', self)
- self.toCSVAct = QAction(QIcon('app/data/icons/csv.svg'), '导出CSV', self)
- self.toHtmlAct = QAction(QIcon('app/data/icons/html.svg'), '导出HTML', self)
- self.toolButton_output.setPopupMode(QToolButton.MenuButtonPopup)
- menu.addAction(self.toDocxAct)
- menu.addAction(self.toCSVAct)
- menu.addAction(self.toHtmlAct)
- self.toolButton_output.setMenu(menu)
- # self.toolButton_output.addSeparator()
- self.toHtmlAct.triggered.connect(self.output)
- self.toDocxAct.triggered.connect(self.output)
- self.toCSVAct.triggered.connect(self.output)
def showContact(self):
"""
@@ -128,6 +109,8 @@ class ContactController(QWidget, Ui_Dialog):
pushButton_2.clicked.connect(pushButton_2.show_msg)
pushButton_2.usernameSingal.connect(self.Contact)
self.contacts[username] = pushButton_2
+ self.contactInfo[username] = ContactInfo(username)
+ self.stackedWidget.addWidget(self.contactInfo[username])
def Contact(self, talkerId):
"""
@@ -137,7 +120,7 @@ class ContactController(QWidget, Ui_Dialog):
"""
self.now_talkerId = talkerId
# self.frame.setVisible(True)
- self.setViewVisible(self.now_talkerId)
+ # self.setViewVisible(self.now_talkerId)
# 把当前按钮设置为灰色
if self.last_talkerId and self.last_talkerId != talkerId:
print('对方账号:', self.last_talkerId)
@@ -150,23 +133,24 @@ class ContactController(QWidget, Ui_Dialog):
"QPushButton {background-color: rgb(198,198,198);}"
"QPushButton:hover{background-color: rgb(209,209,209);}\n"
)
- # 设置联系人的基本信息
- conRemark = self.contacts[talkerId].contact.conRemark
- nickname = self.contacts[talkerId].contact.nickname
- alias = self.contacts[talkerId].contact.alias
-
- self.label_remark.setText(conRemark)
- self.ta_username = talkerId
- if '@chatroom' in talkerId:
- self.chatroomFlag = True
- else:
- self.chatroomFlag = False
- self.userinfo.l_remark.setText(conRemark)
- pixmap = self.contacts[talkerId].contact.avatar
- self.userinfo.l_avatar.setPixmap(pixmap)
- self.userinfo.l_nickname.setText(f'昵称:{nickname}')
- self.userinfo.l_username.setText(f'微信号:{alias}')
- self.userinfo.lineEdit.setText(conRemark)
+ self.stackedWidget.setCurrentWidget(self.contactInfo[talkerId])
+ # # 设置联系人的基本信息
+ # conRemark = self.contacts[talkerId].contact.conRemark
+ # nickname = self.contacts[talkerId].contact.nickname
+ # alias = self.contacts[talkerId].contact.alias
+ #
+ # self.label_remark.setText(conRemark)
+ # self.ta_username = talkerId
+ # if '@chatroom' in talkerId:
+ # self.chatroomFlag = True
+ # else:
+ # self.chatroomFlag = False
+ # self.userinfo.l_remark.setText(conRemark)
+ # pixmap = self.contacts[talkerId].contact.avatar
+ # self.userinfo.l_avatar.setPixmap(pixmap)
+ # self.userinfo.l_nickname.setText(f'昵称:{nickname}')
+ # self.userinfo.l_username.setText(f'微信号:{alias}')
+ # self.userinfo.lineEdit.setText(conRemark)
def output(self):
"""
diff --git a/app/Ui/contact/contactInfo.py b/app/Ui/contact/contactInfo.py
new file mode 100644
index 0000000..6e413da
--- /dev/null
+++ b/app/Ui/contact/contactInfo.py
@@ -0,0 +1,61 @@
+from PyQt5.QtCore import *
+from PyQt5.QtGui import *
+from PyQt5.QtWidgets import *
+
+from app.person import Contact
+from .analysis import analysis
+from .contactInfoUi import Ui_Form
+from .emotion import emotion
+from .userinfo import userinfo
+
+
+class ContactInfo(QWidget, Ui_Form):
+ exitSignal = pyqtSignal()
+ urlSignal = pyqtSignal(QUrl)
+
+ # username = ''
+ def __init__(self, wxid, parent=None):
+ super(ContactInfo, self).__init__(parent)
+ self.setupUi(self)
+ self.contact = Contact(wxid)
+ self.view_userinfo = userinfo.UserinfoController(self.contact)
+ self.view_analysis = analysis.AnalysisController(wxid)
+ self.view_emotion = emotion.EmotionController(wxid)
+ self.btn_analysis.clicked.connect(self.analysis)
+ self.init_ui()
+
+ def init_ui(self):
+ self.label_remark.setText(self.contact.conRemark)
+ self.stackedWidget.addWidget(self.view_userinfo)
+ self.stackedWidget.addWidget(self.view_analysis)
+ self.stackedWidget.addWidget(self.view_emotion)
+ self.stackedWidget.setCurrentWidget(self.view_userinfo)
+ menu = QMenu(self)
+ self.toDocxAct = QAction(QIcon('app/data/icons/word.svg'), '导出Docx', self)
+ self.toCSVAct = QAction(QIcon('app/data/icons/csv.svg'), '导出CSV', self)
+ self.toHtmlAct = QAction(QIcon('app/data/icons/html.svg'), '导出HTML', self)
+ self.toolButton_output.setPopupMode(QToolButton.MenuButtonPopup)
+ menu.addAction(self.toDocxAct)
+ menu.addAction(self.toCSVAct)
+ menu.addAction(self.toHtmlAct)
+ self.toolButton_output.setMenu(menu)
+ # self.toolButton_output.addSeparator()
+ self.toHtmlAct.triggered.connect(self.output)
+ self.toDocxAct.triggered.connect(self.output)
+ self.toCSVAct.triggered.connect(self.output)
+
+ def analysis(self):
+ self.stackedWidget.setCurrentWidget(self.view_analysis)
+ # 判断talkerId是否已经分析过了
+ # 是:则清空其他界面,直接显示该界面
+ # 否:清空其他界面,创建用户界面并显示
+ if 'room' in self.contact.wxid:
+ QMessageBox.warning(
+ self, '警告',
+ '暂不支持群组'
+ )
+ return
+ self.view_analysis.start()
+
+ def output(self):
+ return
diff --git a/app/Ui/contact/contactInfoUi.py b/app/Ui/contact/contactInfoUi.py
new file mode 100644
index 0000000..a47d7e5
--- /dev/null
+++ b/app/Ui/contact/contactInfoUi.py
@@ -0,0 +1,74 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file 'contactInfoUi.ui'
+#
+# Created by: PyQt5 UI code generator 5.15.7
+#
+# WARNING: Any manual changes made to this file will be lost when pyuic5 is
+# run again. Do not edit this file unless you know what you are doing.
+
+
+from PyQt5 import QtCore, QtGui, QtWidgets
+
+
+class Ui_Form(object):
+ def setupUi(self, Form):
+ Form.setObjectName("Form")
+ Form.resize(817, 748)
+ self.horizontalLayout = QtWidgets.QHBoxLayout(Form)
+ self.horizontalLayout.setObjectName("horizontalLayout")
+ self.frame = QtWidgets.QFrame(Form)
+ self.frame.setFrameShape(QtWidgets.QFrame.NoFrame)
+ self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
+ self.frame.setObjectName("frame")
+ self.verticalLayout = QtWidgets.QVBoxLayout(self.frame)
+ self.verticalLayout.setObjectName("verticalLayout")
+ self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
+ self.horizontalLayout_3.setSpacing(0)
+ self.horizontalLayout_3.setObjectName("horizontalLayout_3")
+ self.label_remark = QtWidgets.QLabel(self.frame)
+ self.label_remark.setMaximumSize(QtCore.QSize(16777215, 100))
+ font = QtGui.QFont()
+ font.setPointSize(12)
+ self.label_remark.setFont(font)
+ self.label_remark.setText("")
+ self.label_remark.setObjectName("label_remark")
+ self.horizontalLayout_3.addWidget(self.label_remark)
+ self.btn_analysis = QtWidgets.QPushButton(self.frame)
+ self.btn_analysis.setObjectName("btn_analysis")
+ self.horizontalLayout_3.addWidget(self.btn_analysis)
+ self.btn_emotion = QtWidgets.QPushButton(self.frame)
+ self.btn_emotion.setObjectName("btn_emotion")
+ self.horizontalLayout_3.addWidget(self.btn_emotion)
+ self.btn_report = QtWidgets.QPushButton(self.frame)
+ self.btn_report.setObjectName("btn_report")
+ self.horizontalLayout_3.addWidget(self.btn_report)
+ self.toolButton_output = QtWidgets.QToolButton(self.frame)
+ self.toolButton_output.setObjectName("toolButton_output")
+ self.horizontalLayout_3.addWidget(self.toolButton_output)
+ self.btn_back = QtWidgets.QPushButton(self.frame)
+ self.btn_back.setObjectName("btn_back")
+ self.horizontalLayout_3.addWidget(self.btn_back)
+ self.verticalLayout.addLayout(self.horizontalLayout_3)
+ self.stackedWidget = QtWidgets.QStackedWidget(self.frame)
+ self.stackedWidget.setObjectName("stackedWidget")
+ self.page_3 = QtWidgets.QWidget()
+ self.page_3.setObjectName("page_3")
+ self.stackedWidget.addWidget(self.page_3)
+ self.page_4 = QtWidgets.QWidget()
+ self.page_4.setObjectName("page_4")
+ self.stackedWidget.addWidget(self.page_4)
+ self.verticalLayout.addWidget(self.stackedWidget)
+ self.horizontalLayout.addWidget(self.frame)
+
+ self.retranslateUi(Form)
+ QtCore.QMetaObject.connectSlotsByName(Form)
+
+ def retranslateUi(self, Form):
+ _translate = QtCore.QCoreApplication.translate
+ Form.setWindowTitle(_translate("Form", "Form"))
+ self.btn_analysis.setText(_translate("Form", "统计信息"))
+ self.btn_emotion.setText(_translate("Form", "情感分析"))
+ self.btn_report.setText(_translate("Form", "生成年度报告"))
+ self.toolButton_output.setText(_translate("Form", "导出聊天记录"))
+ self.btn_back.setText(_translate("Form", "退出"))
diff --git a/app/Ui/contact/contactInfoUi.ui b/app/Ui/contact/contactInfoUi.ui
new file mode 100644
index 0000000..d143fac
--- /dev/null
+++ b/app/Ui/contact/contactInfoUi.ui
@@ -0,0 +1,99 @@
+
+
+ Form
+
+
+
+ 0
+ 0
+ 817
+ 748
+
+
+
+ Form
+
+
+ -
+
+
+ QFrame::NoFrame
+
+
+ QFrame::Raised
+
+
+
-
+
+
+ 0
+
+
-
+
+
+
+ 16777215
+ 100
+
+
+
+
+ 12
+
+
+
+
+
+
+
+ -
+
+
+ 统计信息
+
+
+
+ -
+
+
+ 情感分析
+
+
+
+ -
+
+
+ 生成年度报告
+
+
+
+ -
+
+
+ 导出聊天记录
+
+
+
+ -
+
+
+ 退出
+
+
+
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/Ui/contact/contactUi.py b/app/Ui/contact/contactUi.py
index 697e563..1b0840b 100644
--- a/app/Ui/contact/contactUi.py
+++ b/app/Ui/contact/contactUi.py
@@ -57,49 +57,15 @@ class Ui_Dialog(object):
self.label.setObjectName("label")
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.horizontalLayout_2.addWidget(self.scrollArea)
- self.frame = QtWidgets.QFrame(self.frame_2)
- self.frame.setFrameShape(QtWidgets.QFrame.NoFrame)
- self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
- self.frame.setObjectName("frame")
- self.verticalLayout = QtWidgets.QVBoxLayout(self.frame)
- self.verticalLayout.setObjectName("verticalLayout")
- self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
- self.horizontalLayout_3.setSpacing(0)
- self.horizontalLayout_3.setObjectName("horizontalLayout_3")
- self.label_remark = QtWidgets.QLabel(self.frame)
- self.label_remark.setMaximumSize(QtCore.QSize(16777215, 100))
- font = QtGui.QFont()
- font.setPointSize(12)
- self.label_remark.setFont(font)
- self.label_remark.setText("")
- self.label_remark.setObjectName("label_remark")
- self.horizontalLayout_3.addWidget(self.label_remark)
- self.btn_analysis = QtWidgets.QPushButton(self.frame)
- self.btn_analysis.setObjectName("btn_analysis")
- self.horizontalLayout_3.addWidget(self.btn_analysis)
- self.btn_emotion = QtWidgets.QPushButton(self.frame)
- self.btn_emotion.setObjectName("btn_emotion")
- self.horizontalLayout_3.addWidget(self.btn_emotion)
- self.btn_report = QtWidgets.QPushButton(self.frame)
- self.btn_report.setObjectName("btn_report")
- self.horizontalLayout_3.addWidget(self.btn_report)
- self.toolButton_output = QtWidgets.QToolButton(self.frame)
- self.toolButton_output.setObjectName("toolButton_output")
- self.horizontalLayout_3.addWidget(self.toolButton_output)
- self.btn_back = QtWidgets.QPushButton(self.frame)
- self.btn_back.setObjectName("btn_back")
- self.horizontalLayout_3.addWidget(self.btn_back)
- self.verticalLayout.addLayout(self.horizontalLayout_3)
- self.stackedWidget = QtWidgets.QStackedWidget(self.frame)
+ self.stackedWidget = QtWidgets.QStackedWidget(self.frame_2)
self.stackedWidget.setObjectName("stackedWidget")
- self.page_3 = QtWidgets.QWidget()
- self.page_3.setObjectName("page_3")
- self.stackedWidget.addWidget(self.page_3)
- self.page_4 = QtWidgets.QWidget()
- self.page_4.setObjectName("page_4")
- self.stackedWidget.addWidget(self.page_4)
- self.verticalLayout.addWidget(self.stackedWidget)
- self.horizontalLayout_2.addWidget(self.frame)
+ self.page = QtWidgets.QWidget()
+ self.page.setObjectName("page")
+ self.stackedWidget.addWidget(self.page)
+ self.page_2 = QtWidgets.QWidget()
+ self.page_2.setObjectName("page_2")
+ self.stackedWidget.addWidget(self.page_2)
+ self.horizontalLayout_2.addWidget(self.stackedWidget)
self.horizontalLayout.addWidget(self.frame_2)
self.retranslateUi(Dialog)
@@ -109,8 +75,3 @@ class Ui_Dialog(object):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label.setText(_translate("Dialog", "TextLabel"))
- self.btn_analysis.setText(_translate("Dialog", "统计信息"))
- self.btn_emotion.setText(_translate("Dialog", "情感分析"))
- self.btn_report.setText(_translate("Dialog", "生成年度报告"))
- self.toolButton_output.setText(_translate("Dialog", "导出聊天记录"))
- self.btn_back.setText(_translate("Dialog", "退出"))
diff --git a/app/Ui/contact/contactUi.ui b/app/Ui/contact/contactUi.ui
index 77e1ac4..4ee4718 100644
--- a/app/Ui/contact/contactUi.ui
+++ b/app/Ui/contact/contactUi.ui
@@ -151,81 +151,9 @@
-
-
-
- QFrame::NoFrame
-
-
- QFrame::Raised
-
-
-
-
-
-
- 0
-
-
-
-
-
-
- 16777215
- 100
-
-
-
-
- 12
-
-
-
-
-
-
-
- -
-
-
- 统计信息
-
-
-
- -
-
-
- 情感分析
-
-
-
- -
-
-
- 生成年度报告
-
-
-
- -
-
-
- 导出聊天记录
-
-
-
- -
-
-
- 退出
-
-
-
-
-
- -
-
-
-
-
-
-
+
+
+
diff --git a/app/Ui/contact/emotion/emotion.py b/app/Ui/contact/emotion/emotion.py
index e7c6a9e..41d35a7 100644
--- a/app/Ui/contact/emotion/emotion.py
+++ b/app/Ui/contact/emotion/emotion.py
@@ -93,10 +93,6 @@ class EmotionController(QWidget, emotionUi.Ui_Dialog):
# 加载动画
self.center()
self.label_01()
- # 防止卡死,新建线程处理数据
- self.Thread = LoadData(username)
- self.Thread.okSignal.connect(self.initUI)
- self.Thread.start()
def center(self): # 定义一个函数使得窗口居中显示
# 获取屏幕坐标系
@@ -142,6 +138,12 @@ class EmotionController(QWidget, emotionUi.Ui_Dialog):
# palette.setColor(self.backgroundRole(), QColor(192, 253, 123)) # 设置背景颜色
self.setPalette(palette)
+ def start(self):
+ # 防止卡死,新建线程处理数据
+ self.Thread = LoadData(self.ta_username)
+ self.Thread.okSignal.connect(self.initUI)
+ self.Thread.start()
+
class LoadData(QThread):
"""
diff --git a/app/Ui/contact/userinfo/userinfo.py b/app/Ui/contact/userinfo/userinfo.py
new file mode 100644
index 0000000..1fc78c4
--- /dev/null
+++ b/app/Ui/contact/userinfo/userinfo.py
@@ -0,0 +1,15 @@
+from PyQt5.QtWidgets import *
+
+from app.person import Contact
+from .userinfoUi import Ui_Frame
+
+
+class UserinfoController(QWidget, Ui_Frame):
+ def __init__(self, contact: Contact, parent=None):
+ super().__init__(parent)
+ self.setupUi(self)
+ self.l_remark.setText(contact.conRemark)
+ self.l_avatar.setPixmap(contact.avatar)
+ self.l_nickname.setText(f'昵称:{contact.nickname}')
+ self.l_username.setText(f'微信号:{contact.alias}')
+ self.lineEdit.setText(contact.conRemark)