用户管理(未完成)

This commit is contained in:
冯佳
2025-09-13 17:03:22 +08:00
parent 621c107be1
commit f12a289c57
5 changed files with 292 additions and 22 deletions

View File

@ -11,7 +11,7 @@ from PyQt5.QtWidgets import (
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
QLabel, QPushButton, QComboBox, QTextEdit, QFileDialog, QMessageBox,
QGroupBox, QGridLayout, QDialog, QFormLayout, QSpinBox, QCheckBox,
QLineEdit, QTableWidget, QTableWidgetItem,QDialogButtonBox,QShortcut
QLineEdit, QTableWidget, QTableWidgetItem,QDialogButtonBox,QShortcut, QHeaderView
)
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
@ -30,7 +30,7 @@ from Shared_CODE.FaceRecognitionProtocol import (
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
ui_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../Shared_UI'))
users_ui_file_path = os.path.join(ui_path, "users.ui")
users_ui_file_path = os.path.join(ui_path, "DialogUsers.ui")
CSV_FILE = os.path.join(ui_path, "users.csv")
# -------------------- CSV 工具 --------------------"
@ -79,6 +79,32 @@ class UserManageDialog(QDialog):
self.btn_del_all.clicked.connect(self.delete_all_users)
self.refresh()
header = self.table.horizontalHeader()
# 用户ID列固定宽度
self.table.setColumnWidth(0, 100)
# 用户名列自适应内容
header.setSectionResizeMode(1, QHeaderView.ResizeToContents)
# 注册时间列填充剩余空间
header.setSectionResizeMode(2, QHeaderView.Stretch)
self.message_timer = QTimer()
self.message_timer.timeout.connect(self.close_dialog_timeout)
self.setWindowTitle("消息提示")
self.setWindowFlag(Qt.FramelessWindowHint)
button_box : QDialogButtonBox = self.buttonBox
ok_button = button_box.button(QDialogButtonBox.Ok)
if ok_button:
ok_button.setText('确定')
else:
button_box.addButton(QDialogButtonBox.Ok)
#定义4个快捷键, Key_Enter, Key_Escape经常被各类程序模块使用, 用Key_End, 与Key_Home来代替
QShortcut(QKeySequence(Qt.Key_PageDown), self, activated=self.key_enter_process)
QShortcut(QKeySequence(Qt.Key_PageUp), self, activated=self.key_escape_process)
QShortcut(QKeySequence(Qt.Key_End), self, activated=self.key_enter_process)
QShortcut(QKeySequence(Qt.Key_Home), self, activated=self.key_escape_process)
QShortcut(QKeySequence(Qt.Key_Return), self, activated=self.key_enter_process) # 普通回车
def refresh(self):
users = load_users()
@ -114,6 +140,22 @@ class UserManageDialog(QDialog):
self.refresh()
QMessageBox.information(self, "提示", "已请求删除所有用户并清空本地记录")
def key_enter_process(self):
button_box : QDialogButtonBox = self.buttonBox
select_button = button_box.button(QDialogButtonBox.Ok)
if select_button:
select_button.click()
def key_escape_process(self):
button_box : QDialogButtonBox = self.buttonBox
select_button = button_box.button(QDialogButtonBox.Cancel)
if select_button:
select_button.click()
#消息超时
def close_dialog_timeout(self):
self.key_enter_process()
if __name__ == '__main__':
app = QApplication(sys.argv)
dialog = UserManageDialog()