支持查找功能

This commit is contained in:
shuaikangzhou 2023-11-19 23:27:34 +08:00
parent 1995011f13
commit d6bac1628f
12 changed files with 128 additions and 136 deletions

View File

@ -4,11 +4,18 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="84e65474-7da9-466d-baf3-cc88dde3ffdd" name="变更" comment="修复时间插入位置">
<list default="true" id="84e65474-7da9-466d-baf3-cc88dde3ffdd" name="变更" comment="修复第一次启动的显示问题">
<change afterPath="$PROJECT_DIR$/app/util/search.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/DataBase/misc.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/DataBase/misc.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/ui_pc/mainview.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/ui_pc/mainview.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/readme.md" beforeDir="false" afterPath="$PROJECT_DIR$/readme.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/TEST/mainwindow.ui" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/app/ui_pc/chat/chatUi.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/ui_pc/chat/chatUi.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/ui_pc/chat/chatUi.ui" beforeDir="false" afterPath="$PROJECT_DIR$/app/ui_pc/chat/chatUi.ui" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/ui_pc/chat/chat_window.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/ui_pc/chat/chat_window.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/ui_pc/contact/contactUi.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/ui_pc/contact/contactUi.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/ui_pc/contact/contactUi.ui" beforeDir="false" afterPath="$PROJECT_DIR$/app/ui_pc/contact/contactUi.ui" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/ui_pc/contact/contact_window.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/ui_pc/contact/contact_window.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/doc/images/chat_.png" beforeDir="false" afterPath="$PROJECT_DIR$/doc/images/chat_.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/requirements.txt" beforeDir="false" afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -94,7 +101,7 @@
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"last_opened_file_path": "D:/Program Files/Python310/Scripts/pyuic5.exe",
"settings.editor.selected.configurable": "editor.preferences.tabs"
"settings.editor.selected.configurable": "preferences.lookFeel"
}
}]]></component>
<component name="RecentsManager">
@ -210,7 +217,7 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="person" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<configuration name="test (1)" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="WeChatMsg" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
@ -218,14 +225,14 @@
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/app" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/app/person.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="true" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
@ -255,10 +262,10 @@
<recent_temporary>
<list>
<item itemvalue="Python.main_pc" />
<item itemvalue="Python.test (1)" />
<item itemvalue="Python.bubble_message" />
<item itemvalue="Python.test" />
<item itemvalue="Python.msg" />
<item itemvalue="Python.person" />
</list>
</recent_temporary>
</component>
@ -274,13 +281,6 @@
<option name="presentableId" value="Default" />
<updated>1672848140146</updated>
</task>
<task id="LOCAL-00031" summary="增加群二维码">
<created>1698248457797</created>
<option name="number" value="00031" />
<option name="presentableId" value="LOCAL-00031" />
<option name="project" value="LOCAL" />
<updated>1698248457797</updated>
</task>
<task id="LOCAL-00032" summary="支持导出csv格式聊天记录">
<created>1698331547560</created>
<option name="number" value="00032" />
@ -617,7 +617,14 @@
<option name="project" value="LOCAL" />
<updated>1700309638496</updated>
</task>
<option name="localTasksCounter" value="80" />
<task id="LOCAL-00080" summary="修复第一次启动的显示问题">
<created>1700373695942</created>
<option name="number" value="00080" />
<option name="presentableId" value="LOCAL-00080" />
<option name="project" value="LOCAL" />
<updated>1700373695942</updated>
</task>
<option name="localTasksCounter" value="81" />
<servers />
</component>
<component name="UnknownFeatures">
@ -653,7 +660,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="增加导航按钮效果" />
<MESSAGE value="新增PC数据库解密" />
<MESSAGE value="main首次加载解密界面" />
<MESSAGE value="增加日志模块" />
@ -678,7 +684,8 @@
<MESSAGE value="新版本更新" />
<MESSAGE value="update readme" />
<MESSAGE value="修复时间插入位置" />
<option name="LAST_COMMIT_MESSAGE" value="修复时间插入位置" />
<MESSAGE value="修复第一次启动的显示问题" />
<option name="LAST_COMMIT_MESSAGE" value="修复第一次启动的显示问题" />
<option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="true" />
<option name="REFORMAT_BEFORE_PROJECT_COMMIT" value="true" />
</component>

View File

@ -1,103 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>30</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item row="0" column="4">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>29</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="menu">
<property name="title">
<string>你好</string>
</property>
</widget>
<widget class="QMenu" name="menuOK">
<property name="title">
<string>OK</string>
</property>
</widget>
<addaction name="menu"/>
<addaction name="menuOK"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -1,7 +1,8 @@
version = '0.2.2'
version = '0.2.3'
contact = '474379264'
description = [
'1. 支持获取个人信息\n',
'2. 支持显示聊天界面\n',
'3. 支持导出scv格式的聊天记录\n',
'4. 查找联系人\n',
]

View File

@ -17,9 +17,10 @@ class Ui_Form(object):
Form.resize(840, 752)
Form.setStyleSheet("background: rgb(240, 240, 240);")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(Form)
self.horizontalLayout_2.setSpacing(6)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setSpacing(0)
self.verticalLayout_2.setSpacing(6)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
@ -33,14 +34,19 @@ class Ui_Form(object):
self.lineEdit.setMinimumSize(QtCore.QSize(200, 30))
self.lineEdit.setMaximumSize(QtCore.QSize(200, 16777215))
self.lineEdit.setStyleSheet("background:transparent;\n"
" border-width:0;\n"
" border-style:outset;\n"
" background-color:rgb(226,226,226);\n"
"border-radius:5px;\n"
"border-top: 0px solid #b2e281;\n"
"border-bottom: 0px solid #b2e281;\n"
"border-right: 0px solid #b2e281;\n"
"border-left: 0px solid #b2e281;\n"
"border-style:outset;\n"
"background-color:rgb(226,226,226);\n"
" ")
self.lineEdit.setCursorMoveStyle(QtCore.Qt.VisualMoveStyle)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout.addWidget(self.lineEdit)
self.label_2 = QtWidgets.QLabel(Form)
self.label_2.setMinimumSize(QtCore.QSize(30, 0))
self.label_2.setText("")
self.label_2.setObjectName("label_2")
self.horizontalLayout.addWidget(self.label_2)

View File

@ -17,10 +17,13 @@
<string notr="true">background: rgb(240, 240, 240);</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1">
<property name="spacing">
<number>6</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,1">
<property name="spacing">
<number>0</number>
<number>6</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
@ -49,7 +52,11 @@
</property>
<property name="styleSheet">
<string notr="true">background:transparent;
border-width:0;
border-radius:5px;
border-top: 0px solid #b2e281;
border-bottom: 0px solid #b2e281;
border-right: 0px solid #b2e281;
border-left: 0px solid #b2e281;
border-style:outset;
background-color:rgb(226,226,226);
</string>
@ -61,6 +68,12 @@
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
<width>30</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>

View File

@ -4,6 +4,7 @@ from PyQt5.QtWidgets import QWidget, QMessageBox, QAction, QLineEdit
from app.DataBase import micro_msg, misc
from app.components import ContactQListWidgetItem
from app.person import ContactPC
from app.util import search
from .chatUi import Ui_Form
from .chat_info import ChatInfo
from ..Icon import Icon
@ -54,6 +55,7 @@ class ChatWindow(QWidget, Ui_Form):
self.setupUi(self)
self.ok_flag = False
self.setStyleSheet(Stylesheet)
self.contacts = [[], []]
self.init_ui()
self.show_chats()
@ -61,6 +63,7 @@ class ChatWindow(QWidget, Ui_Form):
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()
self.listWidget.currentRowChanged.connect(self.setCurrentIndex)
self.listWidget.setCurrentRow(0)
@ -80,7 +83,23 @@ class ChatWindow(QWidget, Ui_Form):
self.show_thread.start()
self.ok_flag = True
def search_contact(self):
content = self.lineEdit.text()
if not content:
return
index = self.search_contact_index(content)
self.select_contact_by_index(index)
def search_contact_index(self, content: str) -> int:
return search.search_by_content(content, self.contacts)
def select_contact_by_index(self, index):
self.stackedWidget.setCurrentIndex(index)
self.listWidget.setCurrentRow(index)
def show_chat(self, contact):
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)

View File

@ -19,7 +19,7 @@ class Ui_Form(object):
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(Form)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setSpacing(0)
self.verticalLayout_2.setSpacing(6)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
@ -33,13 +33,20 @@ class Ui_Form(object):
self.lineEdit.setMinimumSize(QtCore.QSize(200, 30))
self.lineEdit.setMaximumSize(QtCore.QSize(200, 16777215))
self.lineEdit.setStyleSheet("background:transparent;\n"
"border-width:0;\n"
"border-radius:5px;\n"
"border-top: 0px solid #b2e281;\n"
"border-bottom: 0px solid #b2e281;\n"
"border-right: 0px solid #b2e281;\n"
"border-left: 0px solid #b2e281;\n"
"border-style:outset;\n"
"background-color:rgb(226,226,226);")
"background-color:rgb(226,226,226);\n"
" ")
self.lineEdit.setCursorMoveStyle(QtCore.Qt.VisualMoveStyle)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout.addWidget(self.lineEdit)
self.label_2 = QtWidgets.QLabel(Form)
self.label_2.setMinimumSize(QtCore.QSize(30, 0))
self.label_2.setMaximumSize(QtCore.QSize(30, 16777215))
self.label_2.setText("")
self.label_2.setObjectName("label_2")
self.horizontalLayout.addWidget(self.label_2)

View File

@ -20,7 +20,7 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,1">
<property name="spacing">
<number>0</number>
<number>6</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
@ -49,7 +49,11 @@
</property>
<property name="styleSheet">
<string notr="true">background:transparent;
border-width:0;
border-radius:5px;
border-top: 0px solid #b2e281;
border-bottom: 0px solid #b2e281;
border-right: 0px solid #b2e281;
border-left: 0px solid #b2e281;
border-style:outset;
background-color:rgb(226,226,226);
</string>
@ -61,6 +65,18 @@
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
<width>30</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>

View File

@ -7,6 +7,7 @@ from app.person import ContactPC
from .contactInfo import ContactInfo
from .contactUi import Ui_Form
from ..Icon import Icon
from ...util import search
# 美化样式表
Stylesheet = """
@ -55,12 +56,14 @@ class ContactWindow(QWidget, Ui_Form):
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()
self.listWidget.currentRowChanged.connect(self.setCurrentIndex)
self.listWidget.setCurrentRow(0)
@ -79,7 +82,16 @@ class ContactWindow(QWidget, Ui_Form):
self.show_thread.start()
self.ok_flag = True
def show_contact(self, contact):
def search_contact(self):
keyword = self.lineEdit.text()
if keyword:
index = search.search_by_content(keyword, self.contacts)
self.listWidget.setCurrentRow(index)
self.stackedWidget.setCurrentIndex(index)
def show_contact(self, contact: ContactPC):
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)

14
app/util/search.py Normal file
View File

@ -0,0 +1,14 @@
from typing import List
from fuzzywuzzy import process
def search_by_content(key, choices: List[List]):
result = []
for i, choice in enumerate(choices):
res = process.extractOne(key, choice)
result.append((res, i))
result.sort(key=lambda x: x[0][1], reverse=True)
k = result[0][1]
item = result[0][0][0]
return choices[k].index(item)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.