mirror of
https://github.com/LC044/WeChatMsg
synced 2024-11-14 22:01:54 +08:00
聊天记录从后往前显示
This commit is contained in:
parent
fd8d0ed153
commit
c72b67f2a0
@ -4,8 +4,13 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="84e65474-7da9-466d-baf3-cc88dde3ffdd" name="变更" comment="将自己的wxid设置为配置文件">
|
||||
<change beforePath="$PROJECT_DIR$/app/DataBase/msg.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/DataBase/msg.py" afterDir="false" />
|
||||
<list default="true" id="84e65474-7da9-466d-baf3-cc88dde3ffdd" name="变更" comment="修改聊天记录显示顺序">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/DataBase/micro_msg.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/DataBase/micro_msg.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/components/bubble_message.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/components/bubble_message.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/ui_pc/chat/chat_info.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/ui_pc/chat/chat_info.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/ui_pc/chat/chat_window.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/ui_pc/chat/chat_window.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/ui_pc/contact/contact_window.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/ui_pc/contact/contact_window.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -252,8 +257,8 @@
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Python.main_pc" />
|
||||
<item itemvalue="Python.person" />
|
||||
<item itemvalue="Python.bubble_message" />
|
||||
<item itemvalue="Python.person" />
|
||||
<item itemvalue="Python.chat_info" />
|
||||
<item itemvalue="Python.msg" />
|
||||
</list>
|
||||
@ -271,13 +276,6 @@
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1672848140146</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00023" summary="readme">
|
||||
<created>1684599566617</created>
|
||||
<option name="number" value="00023" />
|
||||
<option name="presentableId" value="LOCAL-00023" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1684599566617</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00024" summary="readme">
|
||||
<created>1684599688133</created>
|
||||
<option name="number" value="00024" />
|
||||
@ -614,7 +612,14 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1700236486745</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="72" />
|
||||
<task id="LOCAL-00072" summary="修改聊天记录显示顺序">
|
||||
<created>1700236795662</created>
|
||||
<option name="number" value="00072" />
|
||||
<option name="presentableId" value="LOCAL-00072" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1700236795662</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="73" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="UnknownFeatures">
|
||||
@ -650,7 +655,6 @@
|
||||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="加快打开速度" />
|
||||
<MESSAGE value="修改导入路径,方便打包成exe" />
|
||||
<MESSAGE value="修改部分UI" />
|
||||
<MESSAGE value="上传html模板" />
|
||||
@ -675,7 +679,8 @@
|
||||
<MESSAGE value="修复聊天气泡不能更改大小的bug" />
|
||||
<MESSAGE value="更改头像显示" />
|
||||
<MESSAGE value="将自己的wxid设置为配置文件" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="将自己的wxid设置为配置文件" />
|
||||
<MESSAGE value="修改聊天记录显示顺序" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="修改聊天记录显示顺序" />
|
||||
<option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="true" />
|
||||
<option name="REFORMAT_BEFORE_PROJECT_COMMIT" value="true" />
|
||||
</component>
|
||||
|
@ -1,7 +1,8 @@
|
||||
import os.path
|
||||
import sqlite3
|
||||
import time
|
||||
import threading
|
||||
|
||||
lock = threading.Lock()
|
||||
DB = None
|
||||
cursor = None
|
||||
micromsg_path = "./app/Database/Msg/MicroMsg.db"
|
||||
@ -27,6 +28,7 @@ def is_database_exist():
|
||||
|
||||
def get_contact():
|
||||
try:
|
||||
lock.acquire(True)
|
||||
sql = '''select UserName,Alias,Type,Remark,NickName,PYInitial,RemarkPYInitial,ContactHeadImgUrl.smallHeadImgUrl,ContactHeadImgUrl.bigHeadImgUrl
|
||||
from Contact inner join ContactHeadImgUrl on Contact.UserName = ContactHeadImgUrl.usrName
|
||||
where Type=3 and Alias is not null
|
||||
@ -34,15 +36,8 @@ def get_contact():
|
||||
'''
|
||||
cursor.execute(sql)
|
||||
result = cursor.fetchall()
|
||||
except:
|
||||
time.sleep(0.2)
|
||||
sql = '''select UserName,Alias,Type,Remark,NickName,PYInitial,RemarkPYInitial,ContactHeadImgUrl.smallHeadImgUrl,ContactHeadImgUrl.bigHeadImgUrl
|
||||
from Contact inner join ContactHeadImgUrl on Contact.UserName = ContactHeadImgUrl.usrName
|
||||
where Type=3 and Alias is not null
|
||||
order by PYInitial
|
||||
'''
|
||||
cursor.execute(sql)
|
||||
result = cursor.fetchall()
|
||||
finally:
|
||||
lock.release()
|
||||
# DB.commit()
|
||||
return result
|
||||
|
||||
|
@ -250,12 +250,12 @@ class ScrollBar(QScrollBar):
|
||||
)
|
||||
|
||||
|
||||
class MyWidget(QWidget):
|
||||
class ChatWidget(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.resize(500, 200)
|
||||
txt = '''在工具中单击边缘可以添加黑点,单击可以删掉黑点,拖动可以调整黑点长度。勾选等选项可以查看内容、缩放等区域右侧可预览不同拉伸情况下的效果,拖动可以调整预览的拉伸比例'''
|
||||
avatar = '../data/icons/default_avatar.svg'
|
||||
avatar = './app/data/icons/default_avatar.svg'
|
||||
bubble_message = BubbleMessage(txt, avatar, Type=1, is_send=False)
|
||||
layout = QVBoxLayout()
|
||||
layout.setSpacing(0)
|
||||
@ -272,39 +272,52 @@ class MyWidget(QWidget):
|
||||
# 设置滚动区域的内容部署部件为前面生成的内容部署层部件
|
||||
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
|
||||
layout.addWidget(self.scrollArea)
|
||||
layout0 = QVBoxLayout()
|
||||
layout0.setSpacing(0)
|
||||
self.layout0 = QVBoxLayout()
|
||||
self.layout0.setSpacing(0)
|
||||
# self.layout0.addWidget(bubble_message)
|
||||
# self.scrollArea.setLayout(layout0)
|
||||
self.scrollAreaWidgetContents.setLayout(layout0)
|
||||
self.scrollAreaWidgetContents.setLayout(self.layout0)
|
||||
|
||||
time = Notice("2023-11-17 15:44")
|
||||
layout0.addWidget(time)
|
||||
txt = "你说啥"
|
||||
avatar_2 = '../data/icons/default_avatar.svg'
|
||||
bubble_message1 = BubbleMessage(txt, avatar_2, Type=1, is_send=True)
|
||||
layout0.addWidget(bubble_message)
|
||||
layout0.addWidget(bubble_message1)
|
||||
|
||||
bubble_message2 = BubbleMessage('', avatar_2, Type=1, is_send=True)
|
||||
layout0.addWidget(bubble_message2)
|
||||
txt = "我啥都没说"
|
||||
avatar0 = 'Data/fg1.png'
|
||||
# self.layout0.addWidget(time)
|
||||
# txt = "你说啥"
|
||||
# avatar_2 = '../data/icons/default_avatar.svg'
|
||||
# bubble_message1 = BubbleMessage(txt, avatar_2, Type=1, is_send=True)
|
||||
#
|
||||
# self.layout0.addWidget(bubble_message1)
|
||||
#
|
||||
# bubble_message2 = BubbleMessage('', avatar_2, Type=1, is_send=True)
|
||||
# self.layout0.addWidget(bubble_message2)
|
||||
# txt = "我啥都没说"
|
||||
# avatar0 = 'Data/fg1.png'
|
||||
bubble_message1 = BubbleMessage("D:\Project\Python\PyQt-master\QLabel\Data\\fg1.png", avatar, Type=3,
|
||||
is_send=False)
|
||||
layout0.addWidget(bubble_message1)
|
||||
self.layout0.addWidget(bubble_message1)
|
||||
|
||||
self.spacerItem = QSpacerItem(10, 10, QSizePolicy.Minimum, QSizePolicy.Expanding)
|
||||
layout0.addItem(self.spacerItem)
|
||||
self.layout0.addItem(self.spacerItem)
|
||||
# layout.setStretch(0, 1)
|
||||
self.setLayout(layout)
|
||||
|
||||
def add_message_item(self, bubble_message):
|
||||
self.layout0.addWidget(bubble_message)
|
||||
|
||||
def set_scroll_bar_last(self):
|
||||
self.scrollArea.verticalScrollBar().setValue(self.scrollArea.widget().height())
|
||||
|
||||
|
||||
class Test(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
layout = QVBoxLayout()
|
||||
self.resize(500, 600)
|
||||
w1 = MyWidget()
|
||||
w1 = ChatWidget()
|
||||
bm1 = BubbleMessage(
|
||||
'你好啊噜啦噜啦嘞绿噜啦噜啦嘞绿绿噜啦噜啦嘞绿绿绿噜啦噜啦嘞绿绿绿绿',
|
||||
"D:\Project\Python\PyQt-master\QLabel\Data\\fg1.png",
|
||||
Type=1,
|
||||
)
|
||||
w1.add_message_item(bm1)
|
||||
w2 = QLabel("nihao")
|
||||
layout.addWidget(w1)
|
||||
layout.addWidget(w2)
|
||||
|
@ -1,8 +1,8 @@
|
||||
from PyQt5.QtCore import QThread, pyqtSignal, Qt
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QSpacerItem, QSizePolicy, QLabel, QHBoxLayout
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QHBoxLayout
|
||||
|
||||
from app.DataBase import msg
|
||||
from app.components.bubble_message import BubbleMessage, ScrollBar, ScrollArea, ScrollAreaContent
|
||||
from app.components.bubble_message import BubbleMessage, ScrollBar, ScrollArea, ScrollAreaContent, ChatWidget
|
||||
from app.person import MePC
|
||||
|
||||
|
||||
@ -22,7 +22,11 @@ class ChatInfo(QWidget):
|
||||
|
||||
self.vBoxLayout = QVBoxLayout()
|
||||
self.vBoxLayout.setSpacing(0)
|
||||
# self.vBoxLayout.addLayout(self.hBoxLayout)
|
||||
self.vBoxLayout.addLayout(self.hBoxLayout)
|
||||
|
||||
self.chat_window = ChatWidget()
|
||||
self.vBoxLayout.addWidget(self.chat_window)
|
||||
return
|
||||
|
||||
self.scrollArea = ScrollArea()
|
||||
self.scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||
@ -30,7 +34,7 @@ class ChatInfo(QWidget):
|
||||
self.scrollArea.setVerticalScrollBar(scrollBar)
|
||||
|
||||
self.scrollAreaWidgetContents = ScrollAreaContent()
|
||||
self.scrollAreaWidgetContents.setMinimumSize(200, 10000)
|
||||
self.scrollAreaWidgetContents.setMinimumSize(200, 400)
|
||||
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
|
||||
|
||||
self.vBoxLayout.addWidget(self.scrollArea)
|
||||
@ -45,9 +49,10 @@ class ChatInfo(QWidget):
|
||||
self.show_chat_thread.start()
|
||||
|
||||
def show_finish(self, ok):
|
||||
self.spacerItem = QSpacerItem(10, 10, QSizePolicy.Minimum, QSizePolicy.Expanding)
|
||||
self.scroolAreaLayout.addItem(self.spacerItem)
|
||||
# self.spacerItem = QSpacerItem(10, 10, QSizePolicy.Minimum, QSizePolicy.Expanding)
|
||||
# self.scroolAreaLayout.addItem(self.spacerItem)
|
||||
self.setLayout(self.vBoxLayout)
|
||||
self.chat_window.set_scroll_bar_last()
|
||||
|
||||
def show_chat(self, message):
|
||||
try:
|
||||
@ -64,7 +69,8 @@ class ChatInfo(QWidget):
|
||||
is_send
|
||||
)
|
||||
# print(str_content)
|
||||
self.scroolAreaLayout.addWidget(bubble_message)
|
||||
# self.scroolAreaLayout.addWidget(bubble_message)
|
||||
self.chat_window.add_message_item(bubble_message)
|
||||
except:
|
||||
print(message)
|
||||
|
||||
|
@ -58,7 +58,6 @@ class ChatWindow(QWidget, Ui_Form):
|
||||
self.show_chats()
|
||||
|
||||
def init_ui(self):
|
||||
|
||||
search_action = QAction(self.lineEdit)
|
||||
search_action.setIcon(Icon.Search_Icon)
|
||||
self.lineEdit.addAction(search_action, QLineEdit.LeadingPosition)
|
||||
@ -82,7 +81,7 @@ class ChatWindow(QWidget, Ui_Form):
|
||||
self.ok_flag = True
|
||||
|
||||
def show_chat(self, contact):
|
||||
contact_item = ContactQListWidgetItem(contact.nickName, contact.smallHeadImgUrl, contact.smallHeadImgBLOG)
|
||||
contact_item = ContactQListWidgetItem(contact.remark, contact.smallHeadImgUrl, contact.smallHeadImgBLOG)
|
||||
self.listWidget.addItem(contact_item)
|
||||
self.listWidget.setItemWidget(contact_item, contact_item.widget)
|
||||
chat_info_window = ChatInfo(contact)
|
||||
|
@ -80,7 +80,7 @@ class ContactWindow(QWidget, Ui_Form):
|
||||
self.ok_flag = True
|
||||
|
||||
def show_contact(self, contact):
|
||||
contact_item = ContactQListWidgetItem(contact.nickName, contact.smallHeadImgUrl, contact.smallHeadImgBLOG)
|
||||
contact_item = ContactQListWidgetItem(contact.remark, contact.smallHeadImgUrl, contact.smallHeadImgBLOG)
|
||||
self.listWidget.addItem(contact_item)
|
||||
self.listWidget.setItemWidget(contact_item, contact_item.widget)
|
||||
contact_info_window = ContactInfo(contact)
|
||||
|
Loading…
Reference in New Issue
Block a user