WeChatMsg/app/Ui/contact/contact.py

104 lines
3.3 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
2023-01-23 09:46:25 +08:00
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
2023-11-05 21:14:14 +08:00
import app.Ui.MyComponents.Button_Contact as MyLabel
2023-11-04 21:21:26 +08:00
from .contactInfo import ContactInfo
2023-01-23 09:46:25 +08:00
from .contactUi import *
2023-11-05 21:14:14 +08:00
from ... import person
from ...DataBase import data
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
self.showContact()
2023-01-23 09:46:25 +08:00
def showContact(self):
"""
2023-02-02 00:26:44 +08:00
显示联系人
2023-01-23 09:46:25 +08:00
:return:
"""
print('show')
if self.show_flag:
return
self.show_flag = True
rconversations = data.get_rconversation()
max_hight = max(len(rconversations) * 80, 680)
2023-04-05 00:01:06 +08:00
# 设置滚动区域的高度
2023-01-23 09:46:25 +08:00
self.scrollAreaWidgetContents.setGeometry(
QtCore.QRect(0, 0, 300, max_hight))
2023-04-05 00:01:06 +08:00
2023-01-23 09:46:25 +08:00
for i in range(len(rconversations)):
rconversation = rconversations[i]
username = rconversation[1]
2023-04-05 00:01:06 +08:00
# 创建联系人按钮对象
# 将实例化对象添加到self.contacts储存起来
# pushButton_2 = Contact(self.scrollAreaWidgetContents, i, rconversation)
pushButton_2 = MyLabel.ContactUi(self.scrollAreaWidgetContents, i, rconversation)
2023-01-23 09:46:25 +08:00
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
2023-11-05 21:14:14 +08:00
self.contactInfo[username] = ContactInfo(username, self.Me)
2023-11-04 21:21:26 +08:00
self.stackedWidget.addWidget(self.contactInfo[username])
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