2023-12-13 22:12:50 +08:00
|
|
|
from PyQt5.QtCore import QThread, pyqtSignal
|
|
|
|
from PyQt5.QtWidgets import QWidget, QMessageBox, QAction, QLineEdit
|
|
|
|
|
|
|
|
from app.DataBase import micro_msg_db, misc_db
|
2023-12-14 22:24:35 +08:00
|
|
|
from app.components import ContactQListWidgetItem, ScrollBar
|
2023-12-30 19:26:24 +08:00
|
|
|
from app.person import Contact
|
2023-12-13 22:12:50 +08:00
|
|
|
from app.ui.Icon import Icon
|
|
|
|
from .contactInfo import ContactInfo
|
|
|
|
from .contactUi import Ui_Form
|
2024-01-03 20:40:04 +08:00
|
|
|
from ...DataBase.hard_link import decodeExtraBuf
|
2023-12-13 22:12:50 +08:00
|
|
|
from ...util import search
|
|
|
|
|
|
|
|
# 美化样式表
|
|
|
|
Stylesheet = """
|
|
|
|
QPushButton{
|
|
|
|
background-color: transparent;
|
|
|
|
}
|
|
|
|
QPushButton:hover {
|
|
|
|
background-color: lightgray;
|
|
|
|
}
|
|
|
|
/*去掉item虚线边框*/
|
|
|
|
QListWidget, QListView, QTreeWidget, QTreeView {
|
|
|
|
outline: 0px;
|
|
|
|
border:none;
|
|
|
|
}
|
|
|
|
/*设置左侧选项的最小最大宽度,文字颜色和背景颜色*/
|
|
|
|
QListWidget {
|
|
|
|
min-width: 250px;
|
|
|
|
max-width: 250px;
|
|
|
|
min-height: 80px;
|
|
|
|
max-height: 1200px;
|
|
|
|
color: black;
|
|
|
|
border:none;
|
|
|
|
}
|
|
|
|
QListWidget::item{
|
|
|
|
height:60px;
|
|
|
|
width:250px;
|
|
|
|
}
|
|
|
|
/*被选中时的背景颜色和左边框颜色*/
|
|
|
|
QListWidget::item:selected {
|
2023-12-14 22:24:35 +08:00
|
|
|
background: rgb(230, 235, 240);
|
2023-12-13 22:12:50 +08:00
|
|
|
border-left:none;
|
|
|
|
color: black;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
/*鼠标悬停颜色*/
|
|
|
|
HistoryPanel::item:hover {
|
|
|
|
background: rgb(52, 52, 52);
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class ContactWindow(QWidget, Ui_Form):
|
|
|
|
load_finish_signal = pyqtSignal(bool)
|
|
|
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
super().__init__(parent)
|
2023-12-14 22:24:35 +08:00
|
|
|
self.now_index = 0
|
2023-12-13 22:12:50 +08:00
|
|
|
self.show_thread = None
|
|
|
|
self.setupUi(self)
|
|
|
|
self.ok_flag = False
|
|
|
|
self.setStyleSheet(Stylesheet)
|
|
|
|
self.init_ui()
|
|
|
|
self.contacts = [[], []]
|
|
|
|
self.show_contacts()
|
|
|
|
|
|
|
|
def init_ui(self):
|
|
|
|
search_action = QAction(self.lineEdit)
|
|
|
|
search_action.setIcon(Icon.Search_Icon)
|
|
|
|
self.lineEdit.addAction(search_action, QLineEdit.LeadingPosition)
|
|
|
|
self.lineEdit.returnPressed.connect(self.search_contact)
|
|
|
|
self.listWidget.clear()
|
2023-12-14 22:24:35 +08:00
|
|
|
self.listWidget.setVerticalScrollBar(ScrollBar())
|
2023-12-13 22:12:50 +08:00
|
|
|
self.listWidget.currentRowChanged.connect(self.setCurrentIndex)
|
|
|
|
self.listWidget.setCurrentRow(0)
|
|
|
|
self.stackedWidget.setCurrentIndex(0)
|
|
|
|
|
|
|
|
def show_contacts(self):
|
2023-12-30 19:26:24 +08:00
|
|
|
"""
|
|
|
|
创建一个子线程来获取联系人并通过信号传递联系人信息
|
|
|
|
@return:
|
|
|
|
"""
|
2023-12-13 22:12:50 +08:00
|
|
|
# return
|
|
|
|
if self.ok_flag:
|
|
|
|
return
|
|
|
|
micro_msg_db.init_database()
|
|
|
|
if not micro_msg_db.open_flag:
|
|
|
|
QMessageBox.critical(self, "错误", "数据库不存在\n请先解密数据库")
|
|
|
|
self.show_thread = ShowThread()
|
|
|
|
self.show_thread.showSingal.connect(self.show_contact)
|
|
|
|
self.show_thread.load_finish_signal.connect(self.load_finish_signal)
|
|
|
|
self.show_thread.start()
|
|
|
|
return
|
|
|
|
|
|
|
|
self.show_thread = ShowContactThread()
|
|
|
|
self.show_thread.showSingal.connect(self.show_contact)
|
|
|
|
self.show_thread.load_finish_signal.connect(self.load_finish_signal)
|
|
|
|
self.show_thread.start()
|
|
|
|
self.ok_flag = True
|
|
|
|
|
|
|
|
def search_contact(self):
|
2023-12-30 19:26:24 +08:00
|
|
|
"""
|
|
|
|
搜索联系人
|
|
|
|
@return:
|
|
|
|
"""
|
2023-12-13 22:12:50 +08:00
|
|
|
keyword = self.lineEdit.text()
|
|
|
|
if keyword:
|
|
|
|
index = search.search_by_content(keyword, self.contacts)
|
|
|
|
self.listWidget.setCurrentRow(index)
|
|
|
|
self.stackedWidget.setCurrentIndex(index)
|
|
|
|
|
2023-12-30 19:26:24 +08:00
|
|
|
def show_contact(self, contact: Contact):
|
|
|
|
"""
|
|
|
|
显示联系人
|
|
|
|
@param contact:联系人对象
|
|
|
|
@return:
|
|
|
|
"""
|
2023-12-13 22:12:50 +08:00
|
|
|
self.contacts[0].append(contact.remark)
|
|
|
|
self.contacts[1].append(contact.nickName)
|
|
|
|
contact_item = ContactQListWidgetItem(contact.remark, contact.smallHeadImgUrl, contact.smallHeadImgBLOG)
|
|
|
|
self.listWidget.addItem(contact_item)
|
|
|
|
self.listWidget.setItemWidget(contact_item, contact_item.widget)
|
|
|
|
contact_info_window = ContactInfo(contact)
|
|
|
|
self.stackedWidget.addWidget(contact_info_window)
|
|
|
|
|
|
|
|
def setCurrentIndex(self, row):
|
|
|
|
# print(row)
|
2023-12-14 22:24:35 +08:00
|
|
|
item = self.listWidget.item(self.now_index)
|
|
|
|
item.dis_select()
|
|
|
|
self.stackedWidget.setCurrentIndex(row)
|
|
|
|
item = self.listWidget.item(row)
|
|
|
|
item.select()
|
|
|
|
self.now_index = row
|
2023-12-13 22:12:50 +08:00
|
|
|
self.stackedWidget.setCurrentIndex(row)
|
|
|
|
|
|
|
|
|
|
|
|
class ShowContactThread(QThread):
|
2023-12-30 19:26:24 +08:00
|
|
|
showSingal = pyqtSignal(Contact)
|
2023-12-13 22:12:50 +08:00
|
|
|
load_finish_signal = pyqtSignal(bool)
|
|
|
|
|
|
|
|
# heightSingal = pyqtSignal(int)
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
def run(self) -> None:
|
|
|
|
contact_info_lists = micro_msg_db.get_contact()
|
|
|
|
for contact_info_list in contact_info_lists:
|
2024-01-03 20:40:04 +08:00
|
|
|
# UserName, Alias,Type,Remark,NickName,PYInitial,RemarkPYInitial,ContactHeadImgUrl.smallHeadImgUrl,ContactHeadImgUrl,bigHeadImgUrl,ExtraBuf
|
|
|
|
detail = decodeExtraBuf(contact_info_list[9])
|
2023-12-13 22:12:50 +08:00
|
|
|
contact_info = {
|
|
|
|
'UserName': contact_info_list[0],
|
|
|
|
'Alias': contact_info_list[1],
|
|
|
|
'Type': contact_info_list[2],
|
|
|
|
'Remark': contact_info_list[3],
|
|
|
|
'NickName': contact_info_list[4],
|
2024-01-03 20:40:04 +08:00
|
|
|
'smallHeadImgUrl': contact_info_list[7],
|
|
|
|
'detail': detail,
|
|
|
|
'label_name': contact_info_list[10],
|
2023-12-13 22:12:50 +08:00
|
|
|
}
|
2023-12-30 19:26:24 +08:00
|
|
|
contact = Contact(contact_info)
|
2023-12-13 22:12:50 +08:00
|
|
|
contact.smallHeadImgBLOG = misc_db.get_avatar_buffer(contact.wxid)
|
|
|
|
contact.set_avatar(contact.smallHeadImgBLOG)
|
|
|
|
self.showSingal.emit(contact)
|
|
|
|
# pprint(contact.__dict__)
|
|
|
|
self.load_finish_signal.emit(True)
|
|
|
|
|
|
|
|
|
|
|
|
class ShowThread(QThread):
|
2023-12-30 19:26:24 +08:00
|
|
|
showSingal = pyqtSignal(Contact)
|
2023-12-13 22:12:50 +08:00
|
|
|
load_finish_signal = pyqtSignal(bool)
|
|
|
|
|
|
|
|
# heightSingal = pyqtSignal(int)
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
def run(self) -> None:
|
|
|
|
QThread.sleep(1)
|
|
|
|
self.load_finish_signal.emit(True)
|