diff --git a/TEST.py b/TEST.py
index f31af6c..5088990 100644
--- a/TEST.py
+++ b/TEST.py
@@ -1,94 +1,45 @@
-# -*- coding: utf-8 -*-
-"""
-Created on Sat May 9 17:14:37 2020
+class img_viewed(QWidget):
-@author: Giyn
-"""
+ def __init__(self, parent=None):
+ super(img_viewed, self).__init__(parent)
+ self.parent = parent
+ self.width = 960
+ self.height = 500
-import sys
-from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QTextBrowser, QVBoxLayout, QHBoxLayout, QMessageBox
-from PyQt5.QtGui import QIcon
+ self.scroll_ares_images = QScrollArea(self)
+ self.scroll_ares_images.setWidgetResizable(True)
+
+ self.scrollAreaWidgetContents = QWidget(self)
+ self.scrollAreaWidgetContents.setObjectName('scrollAreaWidgetContends')
+
+ # 进行网络布局
+ self.gridLayout = QGridLayout(self.scrollAreaWidgetContents)
+ self.scroll_ares_images.setWidget(self.scrollAreaWidgetContents)
+
+ self.scroll_ares_images.setGeometry(20, 50, self.width, self.height)
+ self.vertocal1 = QVBoxLayout()
+
+ # self.meanbar = QMenu(self)
+ # self.meanbar.addMenu('&菜单')
+ # self.openAct = self.meanbar.addAction('&Open',self.open)
+ # self.startAct =self.meanbar.addAction('&start',self.start_img_viewer)
+ self.open_file_pushbutton = QPushButton(self)
+ self.open_file_pushbutton.setGeometry(150, 10, 100, 30)
+ self.open_file_pushbutton.setObjectName('open_pushbutton')
+ self.open_file_pushbutton.setText('打开文件夹...')
+ self.open_file_pushbutton.clicked.connect(self.open)
+
+ self.start_file_pushbutton = QPushButton(self)
+ self.start_file_pushbutton.setGeometry(750, 10, 100, 30)
+ self.start_file_pushbutton.setObjectName('start_pushbutton')
+ self.start_file_pushbutton.setText('开始')
+ self.start_file_pushbutton.clicked.connect(self.start_img_viewer)
+
+ self.vertocal1.addWidget(self.scroll_ares_images)
-class Simple_Window(QWidget):
- def __init__(self):
- super(Simple_Window, self).__init__() # 使用super函数可以实现子类使用父类的方法
- self.setWindowTitle("记事本")
- self.setWindowIcon(QIcon('NoteBook.png')) # 设置窗口图标
- self.resize(412, 412)
- self.text_browser = QTextBrowser(self) # 实例化一个QTextBrowser对象
- # self.text_browser.setText("
Hello World!
") # 设置编辑框初始化时显示的文本
- # self.text_browser.setReadOnly(False) # 调用setReadOnly方法并传入False参数即可编辑文本浏览框(编辑框也可以变成只读)
-
- self.save_button = QPushButton("Save", self)
- self.clear_button = QPushButton("Clear", self)
- self.add_button = QPushButton("Add", self)
-
- self.save_button.clicked.connect(lambda: self.button_slot(self.save_button))
- self.clear_button.clicked.connect(lambda: self.button_slot(self.clear_button))
- self.add_button.clicked.connect(self.add_text)
-
- self.h_layout = QHBoxLayout()
- self.v_layout = QVBoxLayout()
-
- self.h_layout.addWidget(self.save_button)
- self.h_layout.addWidget(self.clear_button)
- self.h_layout.addWidget(self.add_button)
- self.v_layout.addWidget(self.text_browser)
- self.v_layout.addLayout(self.h_layout)
-
- self.setLayout(self.v_layout)
-
- def button_slot(self, button):
- if button == self.save_button:
- choice = QMessageBox.question(self, "Question", "Do you want to save it?", QMessageBox.Yes | QMessageBox.No)
- if choice == QMessageBox.Yes:
- with open('Second text.txt', 'w') as f:
- f.write(self.text_browser.toPlainText())
- self.close()
- elif choice == QMessageBox.No:
- self.close()
- elif button == self.clear_button:
- self.text_browser.clear()
-
- def add_text(self):
- # self.text_browser.append("Hello World!
") # 调用append方法可以向文本浏览框中添加文本
- html = """
-
-
- 我要抢楼
-
-
-

-
- """
- self.text_browser.insertHtml(html)
-
-
-if __name__ == "__main__":
+if __name__ == '__main__':
app = QApplication(sys.argv)
- window = Simple_Window()
- window.show()
- sys.exit(app.exec())
+ windo = img_viewed()
+ windo.show()
+ sys.exit(app.exec_())
diff --git a/app/DataBase/data.py b/app/DataBase/data.py
index 34c09c8..f2d8ae1 100644
--- a/app/DataBase/data.py
+++ b/app/DataBase/data.py
@@ -121,7 +121,11 @@ def get_conRemark(username):
else:
return result[1]
-
+def get_nickname(username):
+ sql = 'select nickname,alias from rcontact where username=?'
+ cursor.execute(sql, [username])
+ result = cursor.fetchone()
+ return result
def avatar_md5(wxid):
m = hashlib.md5()
# 参数必须是byte类型,否则报Unicode-objects must be encoded before hashing错误
@@ -178,20 +182,31 @@ def download_emoji(imgPath, url):
f.write(resp.content)
return imgPath
-
+def get_chatroom_displayname(chatroom,username):
+ sql = 'select memberlist,displayname from chatroom where chatroomname =?'
+ cursor.execute(sql,[chatroom])
+ result = cursor.fetchone()
+ wxids = result[0].split(';')
+ names = result[1].split('、')
+ id = wxids.index(username)
+ print(result[0])
+ print(wxids)
+ for i in wxids:
+ print(get_conRemark(i))
+ return names[id]
+def get_contacts():
+ sql = '''
+ select * from rcontact
+ where type=3 or type = 333
+ '''
+ cursor.execute(sql)
+ result = cursor.fetchall()
+ return result
if __name__ == '__main__':
# rconversation = get_rconversation()
# for i in rconversation:
# print(i)
- timestamp2str(1632219794000)
- conremark = get_conRemark('wxid_q3ozn70pweud22')
- print(conremark)
- print(get_avator('wxid_q3ozn70pweud22'))
- me = get_myinfo()
- print(me.__dict__)
- # r = get_message('wxid_78ka0n92rzzj22', 0)
- # r.reverse()
- # for i in r:
- # print(i)
- # print(len(r), type(r))
- print(get_emoji('f5f8a6116e177937ca9795c47f10113d'))
+ contacts = get_contacts()
+ for contact in contacts:
+ print(contact)
+
diff --git a/app/Ui/chat/chat.py b/app/Ui/chat/chat.py
index 2721174..601cdc3 100644
--- a/app/Ui/chat/chat.py
+++ b/app/Ui/chat/chat.py
@@ -12,21 +12,25 @@ import socket # 导入socket模块
import datetime
import json
import time
+
+import xmltodict
from PIL import Image
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from .chatUi import *
from ...DataBase import data
-
+from ...ImageBox.ui import MainDemo
class ChatController(QWidget, Ui_Dialog):
exitSignal = pyqtSignal()
+ urlSignal = pyqtSignal(QUrl)
# username = ''
def __init__(self, Me, parent=None):
super(ChatController, self).__init__(parent)
+ self.chatroomFlag = None
self.ta_avatar = None
self.setupUi(self)
self.setWindowTitle('WeChat')
@@ -50,6 +54,12 @@ class ChatController(QWidget, Ui_Dialog):
self.showChat()
def initui(self):
+ self.qurl = QUrl('baidu.com')
+ # self.urlSignal.connect(self.hyperlink)
+ self.message.setOpenLinks(False)
+ self.message.setOpenExternalLinks(False)
+ # self.message.anchorClicked(self.hyperlink())
+ self.message.anchorClicked.connect(self.hyperlink)
with open('./wechat.html', 'r', encoding='utf-8') as f:
self.message.setHtml(f.read())
self.textEdit = myTextEdit(self.frame)
@@ -87,10 +97,9 @@ class ChatController(QWidget, Ui_Dialog):
def showChat(self):
"""
- 显示聊天界面
+ 显示联系人界面
:return:
"""
- print('show')
if self.show_flag:
return
self.show_flag = True
@@ -133,6 +142,10 @@ class ChatController(QWidget, Ui_Dialog):
self.message.clear()
self.message.append(talkerId)
self.ta_username = talkerId
+ if '@chatroom' in talkerId:
+ self.chatroomFlag = True
+ else:
+ self.chatroomFlag = False
self.ta_avatar = data.get_avator(talkerId)
self.textEdit.setFocus()
self.Thread.ta_u = talkerId
@@ -213,20 +226,58 @@ class ChatController(QWidget, Ui_Dialog):
self.check_time(msg_time)
if msgType == '1':
+ # return
self.show_text(isSend, content)
elif msgType == '3':
- self.show_img(isSend, imgPath)
+ # return
+ self.show_img(isSend, imgPath, content)
elif msgType == '47':
- self.show_emoji(isSend, imgPath)
- # quit()
+ # return
+ self.show_emoji(isSend, imgPath, content)
+ elif msgType == '268445456':
+ self.show_recall_information(content)
+ elif msgType == '922746929':
+ self.pat_a_pat(content)
# self.message.moveCursor(self.message.textCursor().End)
- def show_emoji(self, isSend, imagePath):
+ def pat_a_pat(self, content):
+ pat_data = xmltodict.parse(content)
+ pat_data = pat_data['msg']['appmsg']['patMsg']['records']['record']
+ fromUser = pat_data['fromUser']
+ pattedUser = pat_data['pattedUser']
+ template = pat_data['template']
+ template = ''.join(template.split('${pattedusername@textstatusicon}'))
+ template = ''.join(template.split('${fromusername@textstatusicon}'))
+ template = template.replace(f'${{{fromUser}}}', data.get_conRemark(fromUser))
+ template = template.replace(f'${{{pattedUser}}}', data.get_conRemark(pattedUser))
+ print(template)
+ html = '''
+ ''' % template
+ self.message.insertHtml(html)
+
+ def show_recall_information(self, content):
+ html = '''
+ ''' % content
+ self.message.insertHtml(html)
+
+ def show_emoji(self, isSend, imagePath, content):
imgPath = data.get_emoji(imagePath)
image = Image.open(imgPath)
imagePixmap = image.size # 宽高像素
# 设置最大宽度
- if imagePixmap[0]<150:
+ if imagePixmap[0] < 150:
size = ""
else:
size = '''height="150" width="150"'''
@@ -234,38 +285,82 @@ class ChatController(QWidget, Ui_Dialog):
|
- '''.format(imgPath,size)
+ '''.format(imgPath, size)
style = 'vertical-align: top'
if isSend:
self.right(html, style=style)
else:
+ if self.chatroomFlag:
+ username = content.split(':')[0]
+ self.chatroom_left(html, username=username, style=style)
self.left(html, style=style)
- def show_img(self, isSend, imgPath):
+ def show_img(self, isSend, imgPath, content):
'THUMBNAIL_DIRPATH://th_29cd0f0ca87652943be9ede365aabeaa'
imgPath = imgPath.split('th_')[1]
imgPath = f'./app/data/image2/{imgPath[0:2]}/{imgPath[2:4]}/th_{imgPath}'
html = '''
-  |
- ''' % imgPath
+
+
+
+
+ |
+ ''' % (imgPath,imgPath)
style = 'vertical-align: top'
if isSend:
self.right(html, style=style)
else:
- self.left(html, style=style)
+ if self.chatroomFlag:
+ username = content.split(':')[0]
+ self.chatroom_left(html, username=username, style=style)
+ else:
+ self.left(html, style=style)
def show_text(self, isSend, content):
-
if isSend:
html = '''
%s |
- ''' % (content)
+ ''' % content
self.right(html)
else:
- html = '''
- %s |
- ''' % (content)
- self.left(html)
+ if self.chatroomFlag:
+ # print(content)
+ 'wxid_mv4jjhc0w0w521:'
+ username = content.split(':')[0]
+ msg = ''.join(content.split(':')[1:])
+ # avatar = data.get_avator(username)
+ html = '''
+
+ %s
+ |
+ ''' % (msg)
+ # self.left(html, avatar=avatar)
+ self.chatroom_left(html, username=username)
+ else:
+ html = '''
+ %s |
+ ''' % (content)
+ self.left(html)
+ def clearImagePath(self,imgpath):
+ path = imgpath.split('/')
+ newPath = '/'.join(path[:-1])+'/'+path[-1][3:]+'.jpg'
+ if os.path.exists(newPath):
+ return newPath
+ newPath = '/'.join(path[:-1]) + '/' + path[-1][3:] + '.png'
+ if os.path.exists(newPath):
+ return newPath
+ newPath = '/'.join(path[:-1]) + '/' + path[-1]+ 'hd'
+ if os.path.exists(newPath):
+ return newPath
+ return imgpath
+ def hyperlink(self, url:QUrl):
+ path = self.clearImagePath(url.path())
+ print(url.path(),path)
+ self.imagebox = MainDemo()
+ self.imagebox.show()
+ self.imagebox.box.set_image(path)
+
+
def right(self, content, style='vertical-align: middle'):
html = '''
@@ -286,21 +381,75 @@ class ChatController(QWidget, Ui_Dialog):
# print(html)
self.message.insertHtml(html)
- def left(self, content, style='vertical-align: middle'):
+ def left(self, content, avatar=None, style='vertical-align: middle'):
+ if not avatar:
+ avatar = self.ta_avatar
+ if self.chatroomFlag == 5:
+ try:
+ username, msg = content.split('\n')
+ avatar = data.get_avator(username)
+ html = '''
+
+
+
+
+ |
+  |
+ : |
+ : |
+
+
+ |
+ : |
+ %s
+
+
+
+
+ ''' % (style, avatar, msg)
+ except:
+ return
+ else:
+ html = '''
+
+
+
+
+ |
+  |
+ : |
+ %s
+
+
+
+
+ ''' % (style, avatar, content)
+ self.message.insertHtml(html)
+
+ def chatroom_left(self, content, username, style='vertical-align: middle'):
+ # if username:
+ avatar = data.get_avator(username)
+ # conRemark = data.get_conRemark(username)
+ conRemark = data.get_conRemark(username)
html = '''
-
-
-
-
- |
-  |
- : |
- %s
-
-
-
-
- ''' % (style, self.ta_avatar, content)
+
+
+
+
+ |
+  |
+ |
+ %s |
+
+
+ |
+ : |
+ %s
+
+
+
+
+ ''' % (style, avatar, conRemark, content)
self.message.insertHtml(html)
def destroy_me(self):
diff --git a/app/Ui/mainview.py b/app/Ui/mainview.py
index 3253391..440cb40 100644
--- a/app/Ui/mainview.py
+++ b/app/Ui/mainview.py
@@ -17,6 +17,7 @@ from PyQt5.QtGui import *
from .mainviewUi import *
from app.DataBase import data
from .chat import chat
+from .contact import contact
class MainWinController(QMainWindow, Ui_Dialog):
@@ -31,7 +32,8 @@ class MainWinController(QMainWindow, Ui_Dialog):
self.Me = data.get_myinfo()
self.chatView = chat.ChatController(self.Me, parent=self.frame_main)
self.chatView.setVisible(False)
-
+ self.contactView = contact.ContactController(self.Me, parent=self.frame_main)
+ self.contactView.setVisible(False)
self.btn_chat.clicked.connect(self.chat_view) # 聊天按钮
self.btn_contact.clicked.connect(self.contact_view)
self.btn_myinfo.clicked.connect(self.myInfo)
@@ -40,9 +42,11 @@ class MainWinController(QMainWindow, Ui_Dialog):
self.btn_about.setContextMenuPolicy(Qt.CustomContextMenu)
self.btn_about.customContextMenuRequested.connect(self.create_rightmenu) # 连接到菜单显示函数
self.last_btn = None
+ self.lastView = None
self.show_avatar()
# 创建右键菜单函数
+
def create_rightmenu(self):
# 菜单对象
self.groupBox_menu = QMenu(self)
@@ -59,6 +63,7 @@ class MainWinController(QMainWindow, Ui_Dialog):
# self.actionB.triggered.connect(self.button_2)
self.groupBox_menu.popup(QCursor.pos()) # 声明当鼠标在groupBox控件上右击时,在鼠标位置显示右键菜单 ,exec_,popup两个都可以,
+
def show_avatar(self):
avatar = data.get_avator(self.Me.username)
pixmap = QPixmap(avatar).scaled(80, 80) # 按指定路径找到图片
@@ -83,6 +88,8 @@ class MainWinController(QMainWindow, Ui_Dialog):
self.last_btn.setStyleSheet("QPushButton {background-color: rgb(240,240,240);}"
"QPushButton:hover{background-color: rgb(209,209,209);}\n")
self.last_btn = self.btn_contact
+ self.setviewVisible(self.contactView)
+ self.contactView.showContact()
def myInfo(self):
self.now_btn = self.btn_myinfo
@@ -95,10 +102,11 @@ class MainWinController(QMainWindow, Ui_Dialog):
def about(self):
QMessageBox.about(self, "关于",
- "关于作者\n姓名:周帅康\n学号:2020303457"
+ "关于作者\n姓名:周帅康\n联系方式:863909694"
)
def setviewVisible(self, view):
view.setVisible(True)
- if view != self.chatView:
- self.chatView.setVisible(False)
+ if view != self.lastView and self.lastView:
+ self.lastView.setVisible(False)
+ self.lastView = view
diff --git a/app/__init__.py b/app/__init__.py
index 2def13e..06b23c9 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -7,3 +7,35 @@
@Version : Python3.10
@comment : ···
"""
+Type = {
+ '1': '文字',
+ '3': '图片',
+ '43': '视频',
+ '-1879048185': '微信运动排行榜',
+ '5': '',
+ '47': '表情包',
+ '268445456': '撤回的消息',
+ '34': '语音',
+ '419430449': '转账',
+ '50': '语音电话',
+ '100001': '领取红包',
+ '10000': '消息已发出,但被对方拒收了。',
+ '822083633': '回复消息',
+ '922746929': '拍一拍',
+ '1090519089': '发送文件',
+ '318767153': '付款成功',
+ '436207665': '发红包',
+}
+'''
+wxid_ewi8gfgpp0eu22:
+
+
+
+
+
+'''
+'''
+
+'''
diff --git a/test.html b/test.html
index be4bce4..72ff00f 100644
--- a/test.html
+++ b/test.html
@@ -18,22 +18,74 @@
- %s 13245: |
+
+ %s 13245:
+ |
+ |
+
+
+
+
+
+ |
+ ADC |
+
>
+
+
+ %s 13245:
+ |
|
-  |
+
|
+
+ 我是标题
+
+
+ 英雄 |
+ 性别 |
+ 职业 |
+
+
+
+
+
+ 亚索 |
+ 男 |
+ 中单 |
+
+
+ 卡莎 |
+ 女 |
+ ADC |
+
+
+ 寒冰 |
+ 女 |
+
+
+
+