Skip to content

Commit

Permalink
修改部分UI
Browse files Browse the repository at this point in the history
  • Loading branch information
LC044 committed Oct 29, 2023
1 parent e870aa4 commit bb267c3
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 49 deletions.
66 changes: 44 additions & 22 deletions .idea/workspace.xml

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

33 changes: 31 additions & 2 deletions app/DataBase/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,54 @@ def __init__(self, username):
self.province = None


def is_db_exist() -> bool:
"""
判断数据库是否正常使用
"""
global DB
global cursor
if DB and cursor:
try:
sql = 'select * from userinfo where id=2'
cursor.execute(sql)
result = cursor.fetchone()
me = Me(result[2])
except Exception as e:
return False
return True


def init_database():
global DB
global cursor
if os.path.exists('./app/DataBase/Msg.db'):
DB = sqlite3.connect("./app/DataBase/Msg.db", check_same_thread=False)
# '''创建游标'''
cursor = DB.cursor()
if os.path.exists('./Msg.db'):
DB = sqlite3.connect("./Msg.db", check_same_thread=False)
# '''创建游标'''
cursor = DB.cursor()


def decrypt(db, key):
if not key:
print('缺少数据库密钥')
return False
if not db:
print('没有数据库文件')
return False
if os.path.exists('./app/DataBase/Msg.db'):
print('/app/DataBase/Msg.db 已经存在')
return True
cmd = './sqlcipher-3.0.1/bin/sqlcipher-shell32.exe'
print(os.path.abspath('.'))
param = f"""
PRAGMA key = '{key}';
PRAGMA cipher_migrate;
ATTACH DATABASE './app/DataBase/Msg.db' AS Msg KEY '';
SELECT sqlcipher_export('Msg');
DETACH DATABASE Msg;
"""

with open('./app/data/config.txt', 'w') as f:
f.write(param)
p = os.system(f"{os.path.abspath('.')}{cmd} {db} < ./app/data/config.txt")
Expand Down
6 changes: 6 additions & 0 deletions app/Ui/ICON.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from PyQt5.QtGui import QIcon


class Icon:
MainWindow = QIcon('./app/data/icons/logo.svg')
Default_avatar = QIcon('./app/data/icons/default_avatar.svg')
100 changes: 100 additions & 0 deletions app/Ui/MyComponents/Contact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from datetime import datetime

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


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:
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_msg.setText(self.digest)
self.label_time.setText(data.timestamp2str(self.conversationTime)[2:])

def show_msg(self):
self.usernameSingal.emit(self.username)
1 change: 1 addition & 0 deletions app/Ui/MyComponents/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import Contact
6 changes: 4 additions & 2 deletions app/Ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
@Version : Python3.10
@comment : ···
"""
from . import mainview
# 文件__init__.py
# from login import login
from . import mainwindow
from . import mainview
from .ICON import Icon
from .MyComponents import *
from .decrypt import decrypt

# __all__ = ["decrypt", 'mainview']
__all__ = ["decrypt", 'mainview', 'Contact', 'Icon']
6 changes: 2 additions & 4 deletions app/Ui/contact/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, Me, parent=None):
self.ta_avatar = None
self.setupUi(self)
self.setWindowTitle('WeChat')
self.setWindowIcon(QIcon('./app/data/icon.png'))
self.setWindowIcon(QIcon('./app/data/icons/logo.svg'))
# self.setStyleSheet('''QWidget{background-color:rgb(255, 255, 255);}''')
self.initui()
self.Me = Me
Expand Down Expand Up @@ -199,11 +199,9 @@ def hide_progress_bar(self, int):
reply = QMessageBox(self)
reply.setIcon(QMessageBox.Information)
reply.setWindowTitle('OK')
reply.setText("导出聊天记录成功")
reply.setText(f"导出聊天记录成功\n在.\\data\\目录下")
reply.addButton("确认", QMessageBox.AcceptRole)
reply.addButton("取消", QMessageBox.RejectRole)
# reply.addButton("忽略", QMessageBox.DestructiveRole)
print(reply)
api = reply.exec_()
self.userinfo.progressBar.setVisible(False)

Expand Down
Loading

0 comments on commit bb267c3

Please sign in to comment.