WeChatMsg/app/Ui/contact/contact.py

117 lines
3.7 KiB
Python
Raw Normal View History

2023-01-23 09:46:25 +08:00
# -*- coding: utf-8 -*-
"""
2023-02-02 00:26:44 +08:00
@File : contact.py
2023-01-23 09:46:25 +08:00
@Author : Shuaikang Zhou
@Time : 2022/12/13 15:07
@IDE : Pycharm
@Version : Python3.10
@comment : ···
"""
from typing import Dict
from PyQt5 import QtCore
2023-01-23 09:46:25 +08:00
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
2023-11-15 20:54:27 +08:00
import app.components.Button_Contact as MyLabel
from app import person
from app.DataBase import data
from app.Ui.contact.contactInfo import ContactInfo
from app.Ui.contact.contactUi import Ui_Dialog
EMOTION = 1
ANALYSIS = 2
2023-01-23 09:46:25 +08:00
2023-02-02 00:26:44 +08:00
2023-04-05 01:50:58 +08:00
class StackedWidget():
def __init__(self):
pass
2023-01-23 09:46:25 +08:00
class ContactController(QWidget, Ui_Dialog):
exitSignal = pyqtSignal()
urlSignal = pyqtSignal(QUrl)
# username = ''
2023-11-05 21:14:14 +08:00
def __init__(self, Me: person.Me, parent=None):
2023-01-23 09:46:25 +08:00
super(ContactController, self).__init__(parent)
self.chatroomFlag = None
self.ta_avatar = None
self.setupUi(self)
self.Me = Me
self.contacts: Dict[str, MyLabel.ContactUi] = {}
2023-11-04 21:21:26 +08:00
self.contactInfo: Dict[str, ContactInfo] = {}
2023-01-23 09:46:25 +08:00
self.show_flag = False
self.last_talkerId = None
self.now_talkerId = None
2023-11-07 22:36:52 +08:00
# self.showContact()
self.show_thread = ShowContactThread()
self.show_thread.showSingal.connect(self.showContact)
self.show_thread.heightSingal.connect(self.setScreenAreaHeight)
self.show_thread.start()
2023-11-07 22:36:52 +08:00
def showContact(self, data_):
2023-01-23 09:46:25 +08:00
"""
2023-11-07 22:36:52 +08:00
data:Tuple[rconversation,index:int]
2023-02-02 00:26:44 +08:00
显示联系人
2023-01-23 09:46:25 +08:00
:return:
"""
2023-11-07 22:36:52 +08:00
rconversation, i = data_
username = rconversation[1]
# print(username)
pushButton_2 = MyLabel.ContactUi(self.scrollAreaWidgetContents, i, rconversation)
pushButton_2.setGeometry(QtCore.QRect(0, 80 * i, 300, 80))
pushButton_2.setLayoutDirection(QtCore.Qt.LeftToRight)
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.Me)
self.stackedWidget.addWidget(self.contactInfo[username])
2023-04-05 00:01:06 +08:00
2023-11-07 22:36:52 +08:00
def setScreenAreaHeight(self, height: int):
self.scrollAreaWidgetContents.setGeometry(
QtCore.QRect(0, 0, 300, height))
2023-01-23 09:46:25 +08:00
def Contact(self, talkerId):
"""
聊天界面 点击联系人头像时候显示聊天数据
:param talkerId:
:return:
"""
self.now_talkerId = talkerId
# 把当前按钮设置为灰色
if self.last_talkerId and self.last_talkerId != talkerId:
print('对方账号:', self.last_talkerId)
self.contacts[self.last_talkerId].setStyleSheet(
2023-04-05 00:01:06 +08:00
"QPushButton {background-color: rgb(220,220,220);}"
"QPushButton:hover{background-color: rgb(208,208,208);}\n"
2023-01-23 09:46:25 +08:00
)
self.last_talkerId = talkerId
self.contacts[talkerId].setStyleSheet(
"QPushButton {background-color: rgb(198,198,198);}"
"QPushButton:hover{background-color: rgb(209,209,209);}\n"
)
2023-11-04 21:21:26 +08:00
self.stackedWidget.setCurrentWidget(self.contactInfo[talkerId])
2023-11-05 21:14:14 +08:00
if '@chatroom' in talkerId:
self.chatroomFlag = True
else:
2023-11-05 21:14:14 +08:00
self.chatroomFlag = False
2023-11-07 22:36:52 +08:00
class ShowContactThread(QThread):
showSingal = pyqtSignal(tuple)
heightSingal = pyqtSignal(int)
def __init__(self):
super().__init__()
def run(self) -> None:
rconversations = data.get_rconversation()
max_height = max(len(rconversations) * 80, 680)
# 设置滚动区域的高度
self.heightSingal.emit(max_height)
for i in range(len(rconversations)):
self.showSingal.emit((rconversations[i], i))