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 0000000..d16f272
Binary files /dev/null and b/app/data/icons/404.png differ
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')