WeChatMsg/app/Ui/contact/analysis/analysis.py

159 lines
5.7 KiB
Python
Raw Normal View History

2023-02-02 00:26:44 +08:00
import sys
2023-01-31 20:43:40 +08:00
from PyQt5.QtCore import *
from PyQt5.QtGui import *
2023-03-31 11:15:44 +08:00
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import *
QCoreApplication.setAttribute(Qt.AA_UseSoftwareOpenGL)
2023-01-31 20:43:40 +08:00
from . import charts
class AnalysisController(QWidget):
def __init__(self, username, parent=None):
super().__init__(parent)
2023-01-31 20:43:40 +08:00
self.ta_username = username
2023-04-05 00:01:06 +08:00
# self.setWindowTitle('数据分析')
# self.setWindowIcon(QIcon('./app/data/icon.png'))
2023-02-02 00:26:44 +08:00
# self.setWindowFlag(Qt.FramelessWindowHint)
self.setStyleSheet('''QWidget{background-color:rgb(255, 255, 255);}''')
2023-03-31 11:15:44 +08:00
# self.setBackground()
# self.resize(400, 300)
2023-02-02 00:26:44 +08:00
self.center()
self.setAttribute(Qt.WA_AttributeCount)
self.label_01()
self.Thread = LoadData(username)
self.Thread.okSignal.connect(self.initUI)
self.Thread.start()
def center(self): # 定义一个函数使得窗口居中显示
# 获取屏幕坐标系
screen = QDesktopWidget().screenGeometry()
# 获取窗口坐标系
size = self.geometry()
newLeft = (screen.width() - size.width()) / 2
newTop = (screen.height() - size.height()) / 2
self.move(int(newLeft), int(newTop))
def label_01(self):
self.label = QLabel(self)
2023-04-05 00:01:06 +08:00
size = self.geometry()
self.label.setGeometry(size.width() // 2, self.height() // 2, 100, 100)
2023-02-02 00:26:44 +08:00
self.label.setToolTip("这是一个标签")
self.m_movie()
def m_movie(self):
movie = QMovie("./app/data/bg.gif")
self.label.setMovie(movie)
movie.start()
2023-01-31 20:43:40 +08:00
def initUI(self):
2023-02-02 00:26:44 +08:00
self.label.setVisible(False)
2023-04-24 11:04:08 +08:00
# self.setStyleSheet('''QWidget{background-color:rgb(240, 240, 240);}''')
2023-04-05 00:01:06 +08:00
main_box = QVBoxLayout(self)
2023-04-05 13:02:25 +08:00
main_box.setContentsMargins(0, 0, 0, 0)
main_box.setSpacing(0)
2023-04-05 00:01:06 +08:00
2023-01-31 20:43:40 +08:00
self.browser1 = QWebEngineView()
2023-03-31 11:15:44 +08:00
self.browser1.load(QUrl('file:///data/聊天统计/title.html'))
2023-04-05 13:02:25 +08:00
self.browser1.setMinimumSize(810, 60)
self.browser1.setStyleSheet('''QWidget{background-color:rgb(240, 240, 240);}''')
2023-01-31 20:43:40 +08:00
self.browser2 = QWebEngineView()
self.browser2.load(QUrl('file:///data/聊天统计/wordcloud.html'))
2023-04-05 13:02:25 +08:00
self.browser2.setStyleSheet('''QWidget{background-color:rgb(240, 240, 240);}''')
# self.browser2.setMinimumWidth(810)
self.browser2.setMinimumSize(810, 810)
2023-01-31 20:43:40 +08:00
self.browser3 = QWebEngineView()
2023-03-31 11:15:44 +08:00
self.browser3.load(QUrl('file:///data/聊天统计/time.html'))
2023-04-05 13:02:25 +08:00
self.browser3.setMaximumSize(810, 100)
self.browser3.adjustSize()
2023-01-31 20:43:40 +08:00
self.browser4 = QWebEngineView()
self.browser4.load(QUrl('http://www.baidu.com'))
2023-04-05 13:02:25 +08:00
self.browser4.resize(800, 600)
2023-01-31 20:43:40 +08:00
self.browser5 = QWebEngineView()
2023-03-31 11:15:44 +08:00
self.browser5.load(QUrl('file:///data/聊天统计/chat_session.html'))
2023-04-05 13:02:25 +08:00
# self.browser5.adjustSize()
# self.browser5.resize(800, 600)
2023-01-31 20:43:40 +08:00
self.browser6 = QWebEngineView()
2023-03-31 11:15:44 +08:00
self.browser6.load(QUrl('file:///data/聊天统计/sports.html'))
2023-01-31 20:43:40 +08:00
self.browser7 = QWebEngineView()
self.browser7.load(QUrl('file:///data/聊天统计/month_num.html'))
self.browser8 = QWebEngineView()
self.browser8.load(QUrl('file:///data/聊天统计/calendar.html'))
self.browser9 = QWebEngineView()
self.browser9.load(QUrl('file:///data/聊天统计/msg_type_rate.html'))
self.browser10 = QWebEngineView()
self.browser10.load(QUrl('file:///data/聊天统计/send_recv_rate.html'))
2023-04-05 01:50:58 +08:00
self.browser10.adjustSize()
# self.browser10.
2023-04-05 00:01:06 +08:00
main_box.addWidget(self.browser1)
2023-04-05 13:02:25 +08:00
self.scrollArea = QScrollArea()
2023-04-05 01:50:58 +08:00
self.scrollArea.setEnabled(True)
self.scrollArea.adjustSize()
2023-04-05 13:02:25 +08:00
2023-04-05 01:50:58 +08:00
scrollAreaContent = QWidget(self.scrollArea)
2023-04-05 13:02:25 +08:00
scrollAreaContent.setStyleSheet('''QWidget{background-color:rgb(240, 240, 240);}''')
Vlayout2 = QVBoxLayout()
Vlayout2.setContentsMargins(0, 0, 0, 0)
Vlayout2.setSpacing(0)
2023-04-05 00:01:06 +08:00
2023-04-05 13:02:25 +08:00
Vlayout2.addWidget(self.browser3)
Vlayout2.addWidget(self.browser2)
Vlayout2.addWidget(self.browser8)
Vlayout2.addWidget(self.browser6)
Vlayout2.addWidget(self.browser5)
Vlayout2.addWidget(self.browser7)
Vlayout2.addWidget(self.browser9)
Vlayout2.addWidget(self.browser10)
2023-04-05 00:01:06 +08:00
scrollAreaContent.setLayout(Vlayout2)
2023-04-05 13:02:25 +08:00
self.scrollArea.setWidget(scrollAreaContent)
2023-04-05 01:50:58 +08:00
main_box.addWidget(self.scrollArea)
2023-04-05 00:01:06 +08:00
main_box.setStretch(0, 1)
main_box.setStretch(1, 10)
2023-01-31 20:43:40 +08:00
self.setLayout(main_box)
def setBackground(self):
palette = QPalette()
pix = QPixmap("./app/data/bg.png")
pix = pix.scaled(self.width(), self.height(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation) # 自适应图片大小
palette.setBrush(self.backgroundRole(), QBrush(pix)) # 设置背景图片
# palette.setColor(self.backgroundRole(), QColor(192, 253, 123)) # 设置背景颜色
self.setPalette(palette)
2023-02-02 00:26:44 +08:00
class LoadData(QThread):
"""
发送信息线程
"""
okSignal = pyqtSignal(int)
2023-03-31 11:15:44 +08:00
def __init__(self, ta_u, parent=None):
2023-02-02 00:26:44 +08:00
super().__init__(parent)
self.ta_username = ta_u
def run(self):
2023-03-31 11:15:44 +08:00
charts.chat_start_endTime(self.ta_username)
charts.title(self.ta_username)
2023-02-02 00:26:44 +08:00
charts.send_recv_rate(self.ta_username)
charts.message_word_cloud(self.ta_username)
charts.msg_type_rate(self.ta_username)
charts.calendar_chart(self.ta_username)
charts.month_num(self.ta_username)
2023-03-31 11:15:44 +08:00
charts.sport(self.ta_username)
charts.chat_session(self.ta_username)
2023-02-02 00:26:44 +08:00
self.okSignal.emit(10)
2023-01-31 20:43:40 +08:00
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MainWindow()
sys.exit(app.exec_())