Skip to content

Commit

Permalink
加快打开速度
Browse files Browse the repository at this point in the history
  • Loading branch information
LC044 committed Nov 7, 2023
1 parent c8194fe commit bb692bb
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 36 deletions.
27 changes: 17 additions & 10 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 37 additions & 25 deletions app/Ui/contact/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,33 @@ def __init__(self, Me: person.Me, parent=None):
self.show_flag = False
self.last_talkerId = None
self.now_talkerId = None
self.showContact()
# self.showContact()
self.show_thread = ShowContactThread()
self.show_thread.showSingal.connect(self.showContact)
self.show_thread.heightSingal.connect(self.setScreenAreaHeight)
self.show_thread.start()

def showContact(self):
def showContact(self, data_):
"""
data:Tuple[rconversation,index:int]
显示联系人
:return:
"""
print('show')
if self.show_flag:
return
self.show_flag = True
rconversations = data.get_rconversation()
max_hight = max(len(rconversations) * 80, 680)
# 设置滚动区域的高度
self.scrollAreaWidgetContents.setGeometry(
QtCore.QRect(0, 0, 300, max_hight))
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])

for i in range(len(rconversations)):
rconversation = rconversations[i]
username = rconversation[1]
# 创建联系人按钮对象
# 将实例化对象添加到self.contacts储存起来
# pushButton_2 = Contact(self.scrollAreaWidgetContents, i, rconversation)
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])
def setScreenAreaHeight(self, height: int):
self.scrollAreaWidgetContents.setGeometry(
QtCore.QRect(0, 0, 300, height))

def Contact(self, talkerId):
"""
Expand All @@ -101,3 +97,19 @@ def Contact(self, talkerId):
self.chatroomFlag = True
else:
self.chatroomFlag = False


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))
1 change: 0 additions & 1 deletion app/Ui/mainview.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def contact_view(self):
"QPushButton:hover{background-color: rgb(209,209,209);}\n")
self.last_btn = self.btn_contact
self.stackedWidget.setCurrentIndex(1)
self.contactView.showContact()

def myInfo(self):
"""
Expand Down
4 changes: 4 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import time

from PyQt5.QtWidgets import *

Expand Down Expand Up @@ -42,12 +43,15 @@ def loadMainWinView(self, username=None):
:return:
"""
username = ''
start = time.time()
self.viewMainWIn = mainview.MainWinController(username=username)
self.viewMainWIn.setWindowTitle("Chat")
# print(username)
self.viewMainWIn.username = username
# self.viewMainWIn.exitSignal.connect(self.loadDecryptView) # 不需要回到登录界面可以省略
self.viewMainWIn.show()
end = time.time()
print('ok', end - start)
# self.viewMainWIn.signUp()


Expand Down

0 comments on commit bb692bb

Please sign in to comment.