显示聊天图片

This commit is contained in:
shuaikangzhou 2023-11-20 23:08:10 +08:00
parent 8851406708
commit 01a4733b55
9 changed files with 75 additions and 38 deletions

View File

@ -4,16 +4,15 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="84e65474-7da9-466d-baf3-cc88dde3ffdd" name="变更" comment="文字消息设置圆角"> <list default="true" id="84e65474-7da9-466d-baf3-cc88dde3ffdd" name="变更" comment="更新wx选择的路径">
<change afterPath="$PROJECT_DIR$/app/DataBase/hard_link.py" afterDir="false" /> <change afterPath="$PROJECT_DIR$/app/util/path.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/DataBase/output_pc.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/DataBase/output_pc.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/app/DataBase/hard_link.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/DataBase/hard_link.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/decrypt/get_wx_info.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/decrypt/get_wx_info.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/person.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/person.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/app/ui_pc/Icon.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/ui_pc/Icon.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/mainview.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/ui_pc/mainview.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/app/ui_pc/mainview.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/ui_pc/mainview.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/ui_pc/tool/pc_decrypt/pc_decrypt.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/ui_pc/tool/pc_decrypt/pc_decrypt.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/app/util/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/util/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/doc/电脑端使用教程.md" beforeDir="false" afterPath="$PROJECT_DIR$/doc/电脑端使用教程.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/readme.md" beforeDir="false" afterPath="$PROJECT_DIR$/readme.md" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -122,7 +121,7 @@
<recent name="D:\Project\PythonProject\WeChatMsg\app\Ui" /> <recent name="D:\Project\PythonProject\WeChatMsg\app\Ui" />
</key> </key>
</component> </component>
<component name="RunManager" selected="Python.decrypt_window"> <component name="RunManager" selected="Python.main_pc">
<configuration name="decrypt_window" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="decrypt_window" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="WeChatMsg" /> <module name="WeChatMsg" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
@ -251,10 +250,10 @@
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Python.decrypt_window" />
<item itemvalue="Python.main_pc" /> <item itemvalue="Python.main_pc" />
<item itemvalue="Python.hard_link" />
<item itemvalue="Python.test" /> <item itemvalue="Python.test" />
<item itemvalue="Python.hard_link" />
<item itemvalue="Python.decrypt_window" />
<item itemvalue="Python.main" /> <item itemvalue="Python.main" />
</list> </list>
</recent_temporary> </recent_temporary>
@ -271,13 +270,6 @@
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1672848140146</updated> <updated>1672848140146</updated>
</task> </task>
<task id="LOCAL-00035" summary="update readme">
<created>1698681328723</created>
<option name="number" value="00035" />
<option name="presentableId" value="LOCAL-00035" />
<option name="project" value="LOCAL" />
<updated>1698681328723</updated>
</task>
<task id="LOCAL-00036" summary="重构一些class删除一些不必要的文件"> <task id="LOCAL-00036" summary="重构一些class删除一些不必要的文件">
<created>1698765961025</created> <created>1698765961025</created>
<option name="number" value="00036" /> <option name="number" value="00036" />
@ -614,7 +606,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1700478493497</updated> <updated>1700478493497</updated>
</task> </task>
<option name="localTasksCounter" value="84" /> <task id="LOCAL-00084" summary="更新wx选择的路径">
<created>1700490633275</created>
<option name="number" value="00084" />
<option name="presentableId" value="LOCAL-00084" />
<option name="project" value="LOCAL" />
<updated>1700490633275</updated>
</task>
<option name="localTasksCounter" value="85" />
<servers /> <servers />
</component> </component>
<component name="UnknownFeatures"> <component name="UnknownFeatures">
@ -650,7 +649,6 @@
</option> </option>
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value="增加PC端微信解密条件的判断" />
<MESSAGE value="删除多余的Word文件" /> <MESSAGE value="删除多余的Word文件" />
<MESSAGE value="修复无法查找wxid的bug" /> <MESSAGE value="修复无法查找wxid的bug" />
<MESSAGE value="修改UI" /> <MESSAGE value="修改UI" />
@ -675,7 +673,8 @@
<MESSAGE value="支持查找功能" /> <MESSAGE value="支持查找功能" />
<MESSAGE value="修复修改wixd的bug" /> <MESSAGE value="修复修改wixd的bug" />
<MESSAGE value="文字消息设置圆角" /> <MESSAGE value="文字消息设置圆角" />
<option name="LAST_COMMIT_MESSAGE" value="文字消息设置圆角" /> <MESSAGE value="更新wx选择的路径" />
<option name="LAST_COMMIT_MESSAGE" value="更新wx选择的路径" />
<option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="true" /> <option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="true" />
<option name="REFORMAT_BEFORE_PROJECT_COMMIT" value="true" /> <option name="REFORMAT_BEFORE_PROJECT_COMMIT" value="true" />
</component> </component>

View File

@ -8,7 +8,7 @@ lock = threading.Lock()
DB = None DB = None
cursor = None cursor = None
db_path = "./app/Database/Msg/HardLinkImage.db" db_path = "./app/Database/Msg/HardLinkImage.db"
root_path = '/MsgAttach/' root_path = 'FileStorage/MsgAttach/'
if os.path.exists(db_path): if os.path.exists(db_path):
DB = sqlite3.connect(db_path, check_same_thread=False) DB = sqlite3.connect(db_path, check_same_thread=False)
# '''创建游标''' # '''创建游标'''
@ -47,16 +47,16 @@ def get_md5_from_xml(content):
root = ET.fromstring(content) root = ET.fromstring(content)
# 提取md5的值 # 提取md5的值
md5_value = root.find(".//img").get("md5") md5_value = root.find(".//img").get("md5")
print(md5_value) # print(md5_value)
return md5_value return md5_value
def get_image(content, thumb=True): def get_image(content, thumb=False):
md5 = get_md5_from_xml(content) md5 = get_md5_from_xml(content)
# md5 = 'bc37a58c32cb203ee9ac587b068e5853' # md5 = 'bc37a58c32cb203ee9ac587b068e5853'
result = get_image_by_md5(binascii.unhexlify(md5)) result = get_image_by_md5(binascii.unhexlify(md5))
if result: if result:
print(result) # print(result)
dir1 = result[3] dir1 = result[3]
dir2 = result[4] dir2 = result[4]
data_image = result[2] data_image = result[2]

View File

@ -8,7 +8,7 @@ from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout, QSizePolicy, QVBoxLayo
class MessageType: class MessageType:
Text = 1 Text = 1
Image = 2 Image = 3
class TextMessage(QLabel): class TextMessage(QLabel):
@ -104,20 +104,28 @@ class OpenImageThread(QThread):
class ImageMessage(QLabel): class ImageMessage(QLabel):
def __init__(self, avatar, parent=None): def __init__(self, image, image_link='', max_width=480, max_height=720, parent=None):
"""
param:image 图像路径或者QPixmap对象
param:image_link='' 点击图像打开的文件路径
"""
super().__init__(parent) super().__init__(parent)
self.image = QLabel(self) self.image = QLabel(self)
if isinstance(avatar, str):
self.setPixmap(QPixmap(avatar)) if isinstance(image, str):
self.image_path = avatar self.setPixmap(QPixmap(image))
elif isinstance(avatar, QPixmap): self.image_path = image
self.setPixmap(avatar) elif isinstance(image, QPixmap):
self.setMaximumWidth(480) self.setPixmap(image)
self.setMaximumHeight(720) if image_link:
self.setScaledContents(True) self.image_path = image_link
self.setMaximumWidth(max_width)
self.setMaximumHeight(max_height)
# self.setScaledContents(True)
def mousePressEvent(self, event): def mousePressEvent(self, event):
if event.buttons() == Qt.LeftButton: # 左键按下 if event.buttons() == Qt.LeftButton: # 左键按下
print('打开图像', self.image_path)
self.open_image_thread = OpenImageThread(self.image_path) self.open_image_thread = OpenImageThread(self.image_path)
self.open_image_thread.start() self.open_image_thread.start()

BIN
app/data/icons/404.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -3,6 +3,7 @@ from PyQt5.QtGui import QIcon
class Icon: class Icon:
Default_avatar_path = './app/data/icons/default_avatar.svg' Default_avatar_path = './app/data/icons/default_avatar.svg'
Default_image_path = './app/data/icons/404.png'
MainWindow_Icon = QIcon('./app/data/icons/logo.svg') MainWindow_Icon = QIcon('./app/data/icons/logo.svg')
Default_avatar = QIcon(Default_avatar_path) Default_avatar = QIcon(Default_avatar_path)
Output = QIcon('./app/data/icons/output.svg') Output = QIcon('./app/data/icons/output.svg')

View File

@ -1,9 +1,12 @@
import traceback
from PyQt5.QtCore import QThread, pyqtSignal from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QHBoxLayout from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QHBoxLayout
from app.DataBase import msg from app.DataBase import msg, hard_link
from app.components.bubble_message import BubbleMessage, ChatWidget, Notice from app.components.bubble_message import BubbleMessage, ChatWidget, Notice
from app.person import MePC from app.person import MePC
from app.util import get_abs_path
class ChatInfo(QWidget): class ChatInfo(QWidget):
@ -84,7 +87,7 @@ class ChatInfo(QWidget):
is_send = message[4] is_send = message[4]
avatar = MePC().avatar if is_send else self.contact.avatar avatar = MePC().avatar if is_send else self.contact.avatar
timestamp = message[5] timestamp = message[5]
if type_ == 1 or type_ == 3: if type_ == 1:
if self.is_5_min(timestamp): if self.is_5_min(timestamp):
time_message = Notice(self.last_str_time) time_message = Notice(self.last_str_time)
self.last_str_time = str_time self.last_str_time = str_time
@ -96,8 +99,23 @@ class ChatInfo(QWidget):
is_send is_send
) )
self.chat_window.add_message_item(bubble_message, 0) self.chat_window.add_message_item(bubble_message, 0)
elif type_ == 3:
if self.is_5_min(timestamp):
time_message = Notice(self.last_str_time)
self.last_str_time = str_time
self.chat_window.add_message_item(time_message, 0)
image_path = hard_link.get_image(content=str_content, thumb=False)
image_path = get_abs_path(image_path)
bubble_message = BubbleMessage(
image_path,
avatar,
type_,
is_send
)
self.chat_window.add_message_item(bubble_message, 0)
except: except:
print(message) print(message)
traceback.print_exc()
class ShowChatThread(QThread): class ShowChatThread(QThread):

View File

@ -89,7 +89,6 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow):
me.name = dic.get('name') me.name = dic.get('name')
me.mobile = dic.get('mobile') me.mobile = dic.get('mobile')
me.wx_dir = dic.get('wx_dir') me.wx_dir = dic.get('wx_dir')
self.set_my_info(wxid) self.set_my_info(wxid)
else: else:
QMessageBox.information( QMessageBox.information(

View File

@ -0,0 +1 @@
from .path import get_abs_path

11
app/util/path.py Normal file
View File

@ -0,0 +1,11 @@
import os
from app.person import MePC
def get_abs_path(path):
return os.path.join(os.getcwd(), 'app/data/icons/404.png')
if path:
return os.path.join(MePC().wx_dir, path)
else:
return os.path.join(os.getcwd(), 'app/data/icons/404.png')