Skip to content

Commit

Permalink
重构一些class,删除一些不必要的文件
Browse files Browse the repository at this point in the history
  • Loading branch information
LC044 committed Oct 31, 2023
1 parent 3fb4e81 commit 2472d3b
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 7,453 deletions.
24 changes: 16 additions & 8 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/DataBase/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ def is_db_exist() -> bool:
cursor.execute(sql)
result = cursor.fetchone()
me = Me(result[2])
return True
except Exception as e:
return False
return True
return False


def init_database():
Expand Down Expand Up @@ -211,7 +212,7 @@ def avatar_md5(wxid):

def get_avator(wxid):
if wxid == None:
return
return './app/data/icons/default_avatar.svg'
wxid = str(wxid)
avatar = avatar_md5(wxid)
avatar_path = r"./app/data/avatar/"
Expand Down
65 changes: 33 additions & 32 deletions app/Ui/MyComponents/Contact.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
from datetime import datetime

from PyQt5 import QtWidgets
from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5.QtCore import *
from PyQt5.QtGui import *

import app.DataBase.data as data
from app.person import Contact

class Contact(QtWidgets.QPushButton):

class ContactUi(QtWidgets.QPushButton):
"""
联系人类,继承自pyqt的按钮,里面封装了联系人头像等标签
"""
usernameSingal = pyqtSignal(str)

def __init__(self, Ui, id=None, contact=None):
super(Contact, self).__init__(Ui)
def __init__(self, Ui, id=None, rconversation=None):
super(ContactUi, self).__init__(Ui)
self.contact: Contact = Contact(rconversation[1])
self.init_ui(Ui)
self.msgCount = rconversation[0]
self.username = rconversation[1]
self.conversationTime = rconversation[6]
self.msgType = rconversation[7]
self.digest = rconversation[8]
hasTrunc = rconversation[10]
attrflag = rconversation[11]
if hasTrunc == 0:
if attrflag == 0:
self.digest = '[动画表情]'
elif attrflag == 67108864:
try:
remark = data.get_conRemark(rconversation[9])
msg = self.digest.split(':')[1].strip('\n').strip()
self.digest = f'{remark}:{msg}'
except Exception as e:
pass
else:
pass
self.show_info(id)

def init_ui(self, Ui):
self.layoutWidget = QtWidgets.QWidget(Ui)
self.layoutWidget.setObjectName("layoutWidget")
self.gridLayout1 = QtWidgets.QGridLayout(self.layoutWidget)
Expand Down Expand Up @@ -62,37 +88,12 @@ def __init__(self, Ui, id=None, contact=None):
"QPushButton {background-color: rgb(220,220,220);}"
"QPushButton:hover{background-color: rgb(208,208,208);}\n"
)
self.msgCount = contact[0]
self.username = contact[1]
self.conversationTime = contact[6]
self.msgType = contact[7]
self.digest = contact[8]
hasTrunc = contact[10]
attrflag = contact[11]
if hasTrunc == 0:
if attrflag == 0:
self.digest = '[动画表情]'
elif attrflag == 67108864:
try:
remark = data.get_conRemark(contact[9])
msg = self.digest.split(':')[1].strip('\n').strip()
self.digest = f'{remark}:{msg}'
except Exception as e:
pass
else:
pass
self.show_info(id)

def show_info(self, id):
self.avatar = data.get_avator(self.username)
# print(avatar)
self.conRemark = data.get_conRemark(self.username)
self.nickname, self.alias = data.get_nickname(self.username)
time = datetime.now().strftime("%m-%d %H:%M")
msg = '还没说话'
pixmap = QPixmap(self.avatar).scaled(60, 60) # 按指定路径找到图片
self.label_avatar.setPixmap(pixmap) # 在label上显示图片
self.label_remark.setText(self.conRemark)
self.label_avatar.setPixmap(self.contact.avatar) # 在label上显示图片
self.label_remark.setText(self.contact.conRemark)
self.label_msg.setText(self.digest)
self.label_time.setText(data.timestamp2str(self.conversationTime)[2:])

Expand Down
115 changes: 9 additions & 106 deletions app/Ui/contact/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
@Version : Python3.10
@comment : ···
"""
import datetime
from typing import Dict

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

import app.Ui.MyComponents.Contact as MyLabel
from .analysis import analysis
from .contactUi import *
from .emotion import emotion
Expand Down Expand Up @@ -48,7 +49,7 @@ def __init__(self, Me, parent=None):
self.initui()
self.Me = Me
self.Thread = ChatMsg(self.Me.username, None)
self.contacts = {}
self.contacts: Dict[str, MyLabel.ContactUi] = {}
self.last_btn = None
self.chat_flag = True
self.show_flag = False
Expand Down Expand Up @@ -120,7 +121,8 @@ def showContact(self):
username = rconversation[1]
# 创建联系人按钮对象
# 将实例化对象添加到self.contacts储存起来
pushButton_2 = Contact(self.scrollAreaWidgetContents, i, rconversation)
# pushButton_2 = Contact(self.scrollAreaWidgetContents, i, rconversation)
pushButton_2 = MyLabel.ContactUi(self.scrollAreaWidgetContents, i, rconversation)
pushButton_2.setGeometry(QtCore.QRect(0, 80 * i, 300, 80))
pushButton_2.setLayoutDirection(QtCore.Qt.LeftToRight)
pushButton_2.clicked.connect(pushButton_2.show_msg)
Expand Down Expand Up @@ -149,19 +151,18 @@ def Contact(self, talkerId):
"QPushButton:hover{background-color: rgb(209,209,209);}\n"
)
# 设置联系人的基本信息
conRemark = self.contacts[talkerId].conRemark
nickname = self.contacts[talkerId].nickname
alias = self.contacts[talkerId].alias
conRemark = self.contacts[talkerId].contact.conRemark
nickname = self.contacts[talkerId].contact.nickname
alias = self.contacts[talkerId].contact.alias

self.label_remark.setText(conRemark)
self.ta_username = talkerId
if '@chatroom' in talkerId:
self.chatroomFlag = True
else:
self.chatroomFlag = False
self.ta_avatar = self.contacts[talkerId].avatar
self.userinfo.l_remark.setText(conRemark)
pixmap = QPixmap(self.ta_avatar).scaled(60, 60) # 按指定路径找到图片
pixmap = self.contacts[talkerId].contact.avatar
self.userinfo.l_avatar.setPixmap(pixmap)
self.userinfo.l_nickname.setText(f'昵称:{nickname}')
self.userinfo.l_username.setText(f'微信号:{alias}')
Expand Down Expand Up @@ -291,104 +292,6 @@ def back(self):
self.setViewVisible(self.now_talkerId)


class Contact(QtWidgets.QPushButton):
"""
联系人类,继承自pyqt的按钮,里面封装了联系人头像等标签
"""
usernameSingal = pyqtSignal(str)

def __init__(self, Ui, id=None, contact=None):
super(Contact, self).__init__(Ui)
self.layoutWidget = QtWidgets.QWidget(Ui)
self.layoutWidget.setObjectName("layoutWidget")
self.gridLayout1 = QtWidgets.QGridLayout(self.layoutWidget)
self.gridLayout1.setSizeConstraint(QtWidgets.QLayout.SetMaximumSize)
self.gridLayout1.setContentsMargins(10, 10, 10, 10)
self.gridLayout1.setSpacing(10)
self.gridLayout1.setObjectName("gridLayout1")
self.label_time = QtWidgets.QLabel(self.layoutWidget)
font = QtGui.QFont()
font.setPointSize(8)
self.label_time.setFont(font)
self.label_time.setLayoutDirection(QtCore.Qt.RightToLeft)
self.label_time.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_time.setObjectName("label_time")
self.gridLayout1.addWidget(self.label_time, 0, 2, 1, 1)
self.label_remark = QtWidgets.QLabel(self.layoutWidget)
font = QtGui.QFont()
font.setFamily("Adobe 黑体 Std R")
font.setPointSize(10)
self.label_remark.setFont(font)
self.label_remark.setObjectName("label_remark")
self.gridLayout1.addWidget(self.label_remark, 0, 1, 1, 1)
self.label_msg = QtWidgets.QLabel(self.layoutWidget)
font = QtGui.QFont()
font.setPointSize(8)
self.label_msg.setFont(font)
self.label_msg.setObjectName("label_msg")
self.gridLayout1.addWidget(self.label_msg, 1, 1, 1, 2)
self.label_avatar = QtWidgets.QLabel(self.layoutWidget)
self.label_avatar.setMinimumSize(QtCore.QSize(60, 60))
self.label_avatar.setMaximumSize(QtCore.QSize(60, 60))
self.label_avatar.setLayoutDirection(QtCore.Qt.RightToLeft)
self.label_avatar.setAutoFillBackground(False)
self.label_avatar.setStyleSheet("background-color: #ffffff;")
self.label_avatar.setInputMethodHints(QtCore.Qt.ImhNone)
self.label_avatar.setFrameShape(QtWidgets.QFrame.NoFrame)
self.label_avatar.setFrameShadow(QtWidgets.QFrame.Plain)
self.label_avatar.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
self.label_avatar.setObjectName("label_avatar")
self.gridLayout1.addWidget(self.label_avatar, 0, 0, 2, 1)
self.gridLayout1.setColumnStretch(0, 1)
self.gridLayout1.setColumnStretch(1, 6)
self.gridLayout1.setRowStretch(0, 5)
self.gridLayout1.setRowStretch(1, 3)
self.setLayout(self.gridLayout1)
self.setStyleSheet(
"QPushButton {background-color: rgb(220,220,220);}"
"QPushButton:hover{background-color: rgb(208,208,208);}\n"
)
self.msgCount = contact[0]
self.username = contact[1]
self.conversationTime = contact[6]
self.msgType = contact[7]
self.digest = contact[8]
hasTrunc = contact[10]
attrflag = contact[11]
if hasTrunc == 0:
if attrflag == 0:
self.digest = '[动画表情]'
elif attrflag == 67108864:
try:
remark = data.get_conRemark(contact[9])
msg = self.digest.split(':')[1].strip('\n').strip()
self.digest = f'{remark}:{msg}'
except Exception as e:
# print(self.digest)
# print(e)
pass
else:
pass
self.show_info(id)

def show_info(self, id):

self.avatar = data.get_avator(self.username)
# print(avatar)
self.conRemark = data.get_conRemark(self.username)
self.nickname, self.alias = data.get_nickname(self.username)
time = datetime.datetime.now().strftime("%m-%d %H:%M")
msg = '还没说话'
pixmap = QPixmap(self.avatar).scaled(60, 60) # 按指定路径找到图片
self.label_avatar.setPixmap(pixmap) # 在label上显示图片
self.label_remark.setText(self.conRemark)
self.label_msg.setText(self.digest)
self.label_time.setText(data.timestamp2str(self.conversationTime)[2:])

def show_msg(self):
self.usernameSingal.emit(self.username)


class ChatMsg(QThread):
"""
发送信息线程
Expand Down
23 changes: 22 additions & 1 deletion app/person.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
from PyQt5.QtGui import QPixmap

import app.DataBase.data as data


class Person:
def __init__(self, wxid: str):
self.wxid = wxid
self.username = data.get_conRemark(wxid)
self.conRemark = data.get_conRemark(wxid)
self.nickname, self.alias = data.get_nickname(wxid)
self.avatar_path = data.get_avator(wxid)
self.avatar = QPixmap(self.avatar_path).scaled(60, 60)


class Me(Person):
def __init__(self, wxid: str):
super(Me, self).__init__(wxid)
self.city = None
self.province = None


class Contact(Person):
def __init__(self, wxid: str):
super(Contact, self).__init__(wxid)


class Group(Person):
def __init__(self, wxid: str):
super(Group, self).__init__(wxid)
Binary file removed sqlcipher-3.0.1/bin/sqlcipher-shell32-debug.exe
Binary file not shown.
Binary file removed sqlcipher-3.0.1/bin/sqlcipher-shell32-debug.pdb
Binary file not shown.
Binary file removed sqlcipher-3.0.1/bin/sqlcipher-shell64-debug.exe
Binary file not shown.
Binary file removed sqlcipher-3.0.1/bin/sqlcipher-shell64-debug.pdb
Binary file not shown.
Binary file removed sqlcipher-3.0.1/lib/sqlcipher32-debug.lib
Binary file not shown.
Binary file removed sqlcipher-3.0.1/lib/sqlcipher32-debug.pdb
Binary file not shown.
Binary file removed sqlcipher-3.0.1/lib/sqlcipher32.lib
Binary file not shown.
Binary file removed sqlcipher-3.0.1/lib/sqlcipher32.pdb
Binary file not shown.
Binary file removed sqlcipher-3.0.1/lib/sqlcipher64-debug.lib
Binary file not shown.
Binary file removed sqlcipher-3.0.1/lib/sqlcipher64-debug.pdb
Binary file not shown.
Binary file removed sqlcipher-3.0.1/lib/sqlcipher64.lib
Binary file not shown.
Binary file removed sqlcipher-3.0.1/lib/sqlcipher64.pdb
Binary file not shown.
Loading

0 comments on commit 2472d3b

Please sign in to comment.