Skip to content

Commit

Permalink
mainwindows文件修正
Browse files Browse the repository at this point in the history
  • Loading branch information
LC044 committed May 22, 2023
1 parent 5b0eb32 commit 01f16c1
Show file tree
Hide file tree
Showing 9 changed files with 644 additions and 0 deletions.
140 changes: 140 additions & 0 deletions app/Ui/chat/form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'form.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(878, 720)
self.horizontalLayout = QtWidgets.QHBoxLayout(Form)
self.horizontalLayout.setObjectName("horizontalLayout")
self.scrollArea_2 = QtWidgets.QScrollArea(Form)
self.scrollArea_2.setEnabled(True)
self.scrollArea_2.setMaximumSize(QtCore.QSize(325, 150000))
self.scrollArea_2.setAutoFillBackground(False)
self.scrollArea_2.setFrameShape(QtWidgets.QFrame.WinPanel)
self.scrollArea_2.setFrameShadow(QtWidgets.QFrame.Raised)
self.scrollArea_2.setMidLineWidth(0)
self.scrollArea_2.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.scrollArea_2.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.scrollArea_2.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContentsOnFirstShow)
self.scrollArea_2.setWidgetResizable(False)
self.scrollArea_2.setObjectName("scrollArea_2")
self.scrollAreaWidgetContents_2 = QtWidgets.QWidget()
self.scrollAreaWidgetContents_2.setGeometry(QtCore.QRect(0, 0, 300, 12000))
self.scrollAreaWidgetContents_2.setObjectName("scrollAreaWidgetContents_2")
self.pushButton_3 = QtWidgets.QPushButton(self.scrollAreaWidgetContents_2)
self.pushButton_3.setGeometry(QtCore.QRect(0, 0, 300, 80))
self.pushButton_3.setLayoutDirection(QtCore.Qt.LeftToRight)
self.pushButton_3.setAutoFillBackground(False)
self.pushButton_3.setText("")
self.pushButton_3.setIconSize(QtCore.QSize(80, 80))
self.pushButton_3.setObjectName("pushButton_3")
self.label_2 = QtWidgets.QLabel(self.scrollAreaWidgetContents_2)
self.label_2.setGeometry(QtCore.QRect(220, 10, 72, 15))
self.label_2.setObjectName("label_2")
self.scrollArea_2.setWidget(self.scrollAreaWidgetContents_2)
self.horizontalLayout.addWidget(self.scrollArea_2)
self.frame_2 = QtWidgets.QFrame(Form)
self.frame_2.setMinimumSize(QtCore.QSize(500, 500))
self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_2.setObjectName("frame_2")
self.verticalLayout = QtWidgets.QVBoxLayout(self.frame_2)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.label_remark_2 = QtWidgets.QLabel(self.frame_2)
font = QtGui.QFont()
font.setPointSize(12)
self.label_remark_2.setFont(font)
self.label_remark_2.setText("")
self.label_remark_2.setObjectName("label_remark_2")
self.horizontalLayout_3.addWidget(self.label_remark_2)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem)
self.toolButton_2 = QtWidgets.QToolButton(self.frame_2)
self.toolButton_2.setObjectName("toolButton_2")
self.horizontalLayout_3.addWidget(self.toolButton_2)
self.verticalLayout.addLayout(self.horizontalLayout_3)
self.line_4 = QtWidgets.QFrame(self.frame_2)
self.line_4.setLineWidth(6)
self.line_4.setFrameShape(QtWidgets.QFrame.VLine)
self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_4.setObjectName("line_4")
self.verticalLayout.addWidget(self.line_4)
self.line_5 = QtWidgets.QFrame(self.frame_2)
self.line_5.setFrameShape(QtWidgets.QFrame.HLine)
self.line_5.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_5.setObjectName("line_5")
self.verticalLayout.addWidget(self.line_5)
self.message_2 = QtWidgets.QTextBrowser(self.frame_2)
self.message_2.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
self.message_2.setStyleSheet("background-color: #F5F5F5;")
self.message_2.setObjectName("message_2")
self.verticalLayout.addWidget(self.message_2)
self.textEdit_2 = QtWidgets.QTextEdit(self.frame_2)
font = QtGui.QFont()
font.setPointSize(15)
self.textEdit_2.setFont(font)
self.textEdit_2.setTabStopWidth(80)
self.textEdit_2.setCursorWidth(1)
self.textEdit_2.setObjectName("textEdit_2")
self.verticalLayout.addWidget(self.textEdit_2)
self.line_6 = QtWidgets.QFrame(self.frame_2)
self.line_6.setFrameShape(QtWidgets.QFrame.HLine)
self.line_6.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_6.setObjectName("line_6")
self.verticalLayout.addWidget(self.line_6)
self.btn_sendMsg_2 = QtWidgets.QPushButton(self.frame_2)
font = QtGui.QFont()
font.setFamily("黑体")
font.setPointSize(15)
font.setBold(False)
font.setWeight(50)
self.btn_sendMsg_2.setFont(font)
self.btn_sendMsg_2.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
self.btn_sendMsg_2.setMouseTracking(False)
self.btn_sendMsg_2.setAutoFillBackground(False)
self.btn_sendMsg_2.setStyleSheet("QPushButton {\n"
" background-color: #f0f0f0;\n"
" \n"
" padding: 10px;\n"
" color:rgb(5,180,104);\n"
"}")
self.btn_sendMsg_2.setIconSize(QtCore.QSize(40, 40))
self.btn_sendMsg_2.setCheckable(False)
self.btn_sendMsg_2.setAutoDefault(True)
self.btn_sendMsg_2.setObjectName("btn_sendMsg_2")
self.verticalLayout.addWidget(self.btn_sendMsg_2)
self.verticalLayout.setStretch(0, 1)
self.verticalLayout.setStretch(2, 3)
self.verticalLayout.setStretch(3, 20)
self.verticalLayout.setStretch(4, 1)
self.verticalLayout.setStretch(6, 1)
self.horizontalLayout.addWidget(self.frame_2)

self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)

def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.label_2.setText(_translate("Form", "TextLabel"))
self.toolButton_2.setText(_translate("Form", "..."))
self.textEdit_2.setHtml(_translate("Form",
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'SimSun\'; font-size:15pt; font-weight:400; font-style:normal;\">\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>"))
self.btn_sendMsg_2.setText(_translate("Form", "发送"))
Binary file added app/Ui/chat/myinfo.zip
Binary file not shown.
Binary file added app/Ui/contact/analysis/charts - 副本.zip
Binary file not shown.
164 changes: 164 additions & 0 deletions app/Ui/contact/emotion/emotion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import numpy as np
import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Line

from ....DataBase import data


def load_data(wxid):
message_data = data.get_text_by_num(wxid, 1)
df = pd.DataFrame(message_data, columns=['message', 'date'])
# print(df)
d = df.groupby('date')
for key, value in d:
yield key, value['message'].values


import snownlp


def emotion_analysis(wxid):
dates = []
emotions = []
for date, messages in load_data(wxid):
dates.append(date)
s = 0
for msg in messages:
val = snownlp.SnowNLP(msg).sentiments
s += val
emotions.append(s / len(messages))
emotions = np.array(emotions)
emotions = np.around(emotions, 3) * 100
return dates, emotions


def plot_emotion(wxid):
"""
画图
"""
datas, emotions = emotion_analysis(wxid) # 获取数据
max_ = max(emotions)
min_ = min(emotions)
c = (
Line()
.add_xaxis(
xaxis_data=datas,
)
.add_yaxis(
series_name="情感趋势",
is_smooth=True,
y_axis=emotions,
markpoint_opts=opts.MarkPointOpts(
data=[
opts.MarkPointItem(type_="max", name="最大值", value=int(max_ * 100) / 100),
opts.MarkPointItem(type_="min", name="最小值", value=int(min_ * 100) / 100),
]
),
markline_opts=opts.MarkLineOpts(
data=[opts.MarkLineItem(type_="average", name="平均值")]
),
)
.set_global_opts(
yaxis_opts=opts.AxisOpts(
max_=max_,
min_=min_,
),
xaxis_opts=opts.AxisOpts(
type_='time'
),
axispointer_opts=opts.AxisPointerOpts(
is_show=True, link=[{"xAxisIndex": "all"}]
),
)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.render("./data/聊天统计/emotion_chart.html")
)


from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import *

from . import emotionUi


class EmotionController(QWidget, emotionUi.Ui_Dialog):
def __init__(self, username, parent=None):
super().__init__(parent)
self.ta_username = username

# self.setStyleSheet('''QWidget{background-color:rgb(240, 240, 240);}''')
# 加载动画
self.center()
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):
w = self.size().width()
h = self.size().height()
self.label = QLabel(self)
self.label.setGeometry(w // 2, h // 2, 100, 100)
self.label.setToolTip("这是一个标签")
self.m_movie()

def m_movie(self):
movie = QMovie("./app/data/bg.gif")
self.label.setMovie(movie)
movie.start()

def initUI(self):
self.label.setVisible(False)
# self.setStyleSheet('''QWidget{background-color:rgb(244, 244, 244);}''')
main_box = QHBoxLayout(self)
self.browser1 = QWebEngineView()
self.browser1.load(QUrl('file:///data/聊天统计/emotion_chart.html'))
# self.browser1.setStyleSheet('''QWidget{background-color:rgb(240, 240, 240);}''')

splitter1 = QSplitter(Qt.Vertical)

splitter1.addWidget(self.browser1)
main_box.addWidget(splitter1)
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)


class LoadData(QThread):
"""
发送信息线程
"""
okSignal = pyqtSignal(int)

def __init__(self, ta_u, parent=None):
super().__init__(parent)
self.ta_username = ta_u

def run(self):
plot_emotion(self.ta_username)
self.okSignal.emit(10)


if __name__ == '__main__':
# wxid = 'wxid_8piw6sb4hvfm22'
wxid = 'wxid_wt2vsktnu4z022'
load_data(wxid)
24 changes: 24 additions & 0 deletions app/Ui/contact/emotion/emotionUi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'emotionUi.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


class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)

self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)

def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
Loading

0 comments on commit 01f16c1

Please sign in to comment.