From 01a4733b55d1f37992537b712d68543592b65ff5 Mon Sep 17 00:00:00 2001
From: shuaikangzhou <863909694@qq.com>
Date: Mon, 20 Nov 2023 23:08:10 +0800
Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E8=81=8A=E5=A4=A9=E5=9B=BE?=
=?UTF-8?q?=E7=89=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/workspace.xml | 41 +++++++++++++++----------------
app/DataBase/hard_link.py | 8 +++---
app/components/bubble_message.py | 28 +++++++++++++--------
app/data/icons/404.png | Bin 0 -> 1994 bytes
app/ui_pc/Icon.py | 1 +
app/ui_pc/chat/chat_info.py | 22 +++++++++++++++--
app/ui_pc/mainview.py | 1 -
app/util/__init__.py | 1 +
app/util/path.py | 11 +++++++++
9 files changed, 75 insertions(+), 38 deletions(-)
create mode 100644 app/data/icons/404.png
create mode 100644 app/util/path.py
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index ab978f1..4978b11 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,16 +4,15 @@
-
-
+
+
-
-
-
+
+
+
+
-
-
-
+
@@ -122,7 +121,7 @@
-
+
@@ -251,10 +250,10 @@
-
-
+
+
@@ -271,13 +270,6 @@
1672848140146
-
- 1698681328723
-
-
-
- 1698681328723
-
1698765961025
@@ -614,7 +606,14 @@
1700478493497
-
+
+ 1700490633275
+
+
+
+ 1700490633275
+
+
@@ -650,7 +649,6 @@
-
@@ -675,7 +673,8 @@
-
+
+
diff --git a/app/DataBase/hard_link.py b/app/DataBase/hard_link.py
index 448199f..34236ec 100644
--- a/app/DataBase/hard_link.py
+++ b/app/DataBase/hard_link.py
@@ -8,7 +8,7 @@ lock = threading.Lock()
DB = None
cursor = None
db_path = "./app/Database/Msg/HardLinkImage.db"
-root_path = '/MsgAttach/'
+root_path = 'FileStorage/MsgAttach/'
if os.path.exists(db_path):
DB = sqlite3.connect(db_path, check_same_thread=False)
# '''创建游标'''
@@ -47,16 +47,16 @@ def get_md5_from_xml(content):
root = ET.fromstring(content)
# 提取md5的值
md5_value = root.find(".//img").get("md5")
- print(md5_value)
+ # print(md5_value)
return md5_value
-def get_image(content, thumb=True):
+def get_image(content, thumb=False):
md5 = get_md5_from_xml(content)
# md5 = 'bc37a58c32cb203ee9ac587b068e5853'
result = get_image_by_md5(binascii.unhexlify(md5))
if result:
- print(result)
+ # print(result)
dir1 = result[3]
dir2 = result[4]
data_image = result[2]
diff --git a/app/components/bubble_message.py b/app/components/bubble_message.py
index 7c982c3..fc26e4b 100644
--- a/app/components/bubble_message.py
+++ b/app/components/bubble_message.py
@@ -8,7 +8,7 @@ from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout, QSizePolicy, QVBoxLayo
class MessageType:
Text = 1
- Image = 2
+ Image = 3
class TextMessage(QLabel):
@@ -104,20 +104,28 @@ class OpenImageThread(QThread):
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)
self.image = QLabel(self)
- if isinstance(avatar, str):
- self.setPixmap(QPixmap(avatar))
- self.image_path = avatar
- elif isinstance(avatar, QPixmap):
- self.setPixmap(avatar)
- self.setMaximumWidth(480)
- self.setMaximumHeight(720)
- self.setScaledContents(True)
+
+ if isinstance(image, str):
+ self.setPixmap(QPixmap(image))
+ self.image_path = image
+ elif isinstance(image, QPixmap):
+ self.setPixmap(image)
+ if image_link:
+ self.image_path = image_link
+ self.setMaximumWidth(max_width)
+ self.setMaximumHeight(max_height)
+ # self.setScaledContents(True)
def mousePressEvent(self, event):
if event.buttons() == Qt.LeftButton: # 左键按下
+ print('打开图像', self.image_path)
self.open_image_thread = OpenImageThread(self.image_path)
self.open_image_thread.start()
diff --git a/app/data/icons/404.png b/app/data/icons/404.png
new file mode 100644
index 0000000000000000000000000000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%VW>8
zU$|)9wD1;L;1&40s?36a>v#5Q8h(A4Hd!gM$jxtALJyu!jj;65{G?1VGCdn?=)1W;
z_}JBM-HOs2i5XtjJj=J$O=rjQhQ2d8ie-e-i=gIv-bpuF9`^w2ef`ic|7hF6em$ZGWhL@8ti{{^@F5=JL}PRLVQ0
z$BS}SdQCF6fnzXWbTEAo)T^{I{xVR(ftmE6@#NdNmzkeU%CsjZquexEVdT
z_dA^zPjq+R6sGOC>@`h$F`)@XP2@4E0CX0XVTLH{y6I46u7PqYQ4Td!i`oZy!W`iSt=Qfb2b$(Own9RyT^Zs~7^HiRYxg!sit4
zOJ01IL|$@CFw~0EsE+ete3`Js`Y=M74rRNKG$yvvu&LYwL9UK|vf(?sXGk{UD|-vEC;~<4L}A|R%NwY?W*lQ{|#xRl8mu(&SSHI?aPiGB(r9(
zkd5)VU&)AX|2#jE+hYNOcxKA7@1bP0n+C-m!-BS)2$v`yfJ0btG#U*qZCII4-!`R{
zEJaX*tq=nUO1Q*gxjh6rlW+K~keZ!eRRslDf^+0+^*Aw65Ak;-moGZJAtNjX(d)X>
zg^-p)Wf;$#KEMH#*-#HZgQD}N+>-8R9e1fF)Hi$8;Q&_ZwLlB%
z-n}1;Ffn_xb#}tehYlZh?HNwmk7o{RG4H(OirAbeu02g8-)?&}(3R|xCY}Yr**V+R
ITl**f4|^-6F#rGn
literal 0
HcmV?d00001
diff --git a/app/ui_pc/Icon.py b/app/ui_pc/Icon.py
index 88a0f0e..9a569b1 100644
--- a/app/ui_pc/Icon.py
+++ b/app/ui_pc/Icon.py
@@ -3,6 +3,7 @@ from PyQt5.QtGui import QIcon
class Icon:
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')
Default_avatar = QIcon(Default_avatar_path)
Output = QIcon('./app/data/icons/output.svg')
diff --git a/app/ui_pc/chat/chat_info.py b/app/ui_pc/chat/chat_info.py
index 96b3d0b..d5a7958 100644
--- a/app/ui_pc/chat/chat_info.py
+++ b/app/ui_pc/chat/chat_info.py
@@ -1,9 +1,12 @@
+import traceback
+
from PyQt5.QtCore import QThread, pyqtSignal
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.person import MePC
+from app.util import get_abs_path
class ChatInfo(QWidget):
@@ -84,7 +87,7 @@ class ChatInfo(QWidget):
is_send = message[4]
avatar = MePC().avatar if is_send else self.contact.avatar
timestamp = message[5]
- if type_ == 1 or type_ == 3:
+ if type_ == 1:
if self.is_5_min(timestamp):
time_message = Notice(self.last_str_time)
self.last_str_time = str_time
@@ -96,8 +99,23 @@ class ChatInfo(QWidget):
is_send
)
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:
print(message)
+ traceback.print_exc()
class ShowChatThread(QThread):
diff --git a/app/ui_pc/mainview.py b/app/ui_pc/mainview.py
index cf2005b..3448422 100644
--- a/app/ui_pc/mainview.py
+++ b/app/ui_pc/mainview.py
@@ -89,7 +89,6 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow):
me.name = dic.get('name')
me.mobile = dic.get('mobile')
me.wx_dir = dic.get('wx_dir')
-
self.set_my_info(wxid)
else:
QMessageBox.information(
diff --git a/app/util/__init__.py b/app/util/__init__.py
index e69de29..ed49344 100644
--- a/app/util/__init__.py
+++ b/app/util/__init__.py
@@ -0,0 +1 @@
+from .path import get_abs_path
diff --git a/app/util/path.py b/app/util/path.py
new file mode 100644
index 0000000..ab32b28
--- /dev/null
+++ b/app/util/path.py
@@ -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')