用户管理(未完成)

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

@ -940,10 +940,11 @@ class UIFrameWork(QMainWindow, class_comm_mqtt_interface):
def do_enroll_itg_single(self): def do_enroll_itg_single(self):
dlg = EnrollItgSingleDialog(self) admin_val = 0
if dlg.exec_() == QDialog.Accepted: uname = " "
admin_val, uname, face_dir, timeout_val, itg_val = dlg.values() face_dir = 31
self.last_enroll_name = uname timeout_val = system_parameter().get_verify_timeout()
itg_val = 0
self.send(build_enroll_itg_single(admin_val, uname, face_dir, timeout_val, itg_val)) self.send(build_enroll_itg_single(admin_val, uname, face_dir, timeout_val, itg_val))
def do_manage_users(self): def do_manage_users(self):
@ -958,9 +959,9 @@ class UIFrameWork(QMainWindow, class_comm_mqtt_interface):
self.video_worker.stop() self.video_worker.stop()
self.video_worker.wait(300) self.video_worker.wait(300)
self.video_worker = None self.video_worker = None
self.video_label.setText("未打开") # self.video_label.setText("未打开")
self.video_label.setPixmap(QPixmap()) # self.video_label.setPixmap(QPixmap())
self.btn_video.setText("打开视频")
self.log("[INFO] 视频已关闭") self.log("[INFO] 视频已关闭")
inform_box : DialogInform = DialogInform() inform_box : DialogInform = DialogInform()
inform_box.information("提示", "视频已关闭") inform_box.information("提示", "视频已关闭")
@ -971,9 +972,8 @@ class UIFrameWork(QMainWindow, class_comm_mqtt_interface):
self.video_worker = VideoWorker(cam_index=0, target_size=self.video_label.size()) self.video_worker = VideoWorker(cam_index=0, target_size=self.video_label.size())
self.video_worker.pixmap_ready.connect(self.video_label.setPixmap) self.video_worker.pixmap_ready.connect(self.video_label.setPixmap)
self.video_worker.log_message.connect(self.log) # self.video_worker.log_message.connect(self.log)
self.video_worker.start() self.video_worker.start()
self.btn_video.setText("关闭视频")
self.log("[INFO] 正在打开视频") self.log("[INFO] 正在打开视频")
inform_box : DialogInform = DialogInform() inform_box : DialogInform = DialogInform()
inform_box.information("提示", "正在打开视频") inform_box.information("提示", "正在打开视频")

View File

@ -11,7 +11,7 @@ from PyQt5.QtWidgets import (
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
QLabel, QPushButton, QComboBox, QTextEdit, QFileDialog, QMessageBox, QLabel, QPushButton, QComboBox, QTextEdit, QFileDialog, QMessageBox,
QGroupBox, QGridLayout, QDialog, QFormLayout, QSpinBox, QCheckBox, 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__), '..'))) 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__), '../..'))) 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')) 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_FILE = os.path.join(ui_path, "users.csv")
# -------------------- CSV 工具 --------------------" # -------------------- CSV 工具 --------------------"
@ -79,6 +79,32 @@ class UserManageDialog(QDialog):
self.btn_del_all.clicked.connect(self.delete_all_users) self.btn_del_all.clicked.connect(self.delete_all_users)
self.refresh() 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): def refresh(self):
users = load_users() users = load_users()
@ -114,6 +140,22 @@ class UserManageDialog(QDialog):
self.refresh() self.refresh()
QMessageBox.information(self, "提示", "已请求删除所有用户并清空本地记录") 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__': if __name__ == '__main__':
app = QApplication(sys.argv) app = QApplication(sys.argv)
dialog = UserManageDialog() dialog = UserManageDialog()

View File

@ -0,0 +1,187 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogInform</class>
<widget class="QDialog" name="DialogInform">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>632</width>
<height>483</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">border:none;
background-color: rgba(0, 0, 0, 0);</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>200</x>
<y>270</y>
<width>381</width>
<height>31</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::NoButton</set>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>90</x>
<y>0</y>
<width>411</width>
<height>51</height>
</rect>
</property>
<property name="font">
<font>
<family>Microsoft YaHei UI</family>
<pointsize>16</pointsize>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgba(85, 170, 127,0);
color: rgb(255, 170, 0);
font: 16pt &quot;Microsoft YaHei UI&quot;;</string>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QTableWidget" name="table">
<property name="geometry">
<rect>
<x>60</x>
<y>70</y>
<width>521</width>
<height>295</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);</string>
</property>
<column>
<property name="text">
<string>用户ID</string>
</property>
</column>
<column>
<property name="text">
<string>用户名</string>
</property>
</column>
<column>
<property name="text">
<string>注册时间</string>
</property>
</column>
</widget>
<widget class="QPushButton" name="btn_del_all">
<property name="geometry">
<rect>
<x>388</x>
<y>430</y>
<width>106</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>删除所有用户</string>
</property>
</widget>
<widget class="QPushButton" name="btn_delete">
<property name="geometry">
<rect>
<x>50</x>
<y>430</y>
<width>107</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>删除选中用户</string>
</property>
</widget>
<widget class="QPushButton" name="btn_refresh">
<property name="geometry">
<rect>
<x>163</x>
<y>430</y>
<width>106</width>
<height>23</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(0, 0, 0);</string>
</property>
<property name="text">
<string>刷新</string>
</property>
</widget>
<widget class="QPushButton" name="btn_get">
<property name="geometry">
<rect>
<x>275</x>
<y>430</y>
<width>107</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>获取设备用户列表</string>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DialogInform</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DialogInform</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -2,30 +2,71 @@
<ui version="4.0"> <ui version="4.0">
<class>UserManageDialog</class> <class>UserManageDialog</class>
<widget class="QDialog" name="UserManageDialog"> <widget class="QDialog" name="UserManageDialog">
<property name="windowTitle"><string>用户管理</string></property> <property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>464</width>
<height>344</height>
</rect>
</property>
<property name="windowTitle">
<string>用户管理</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QTableWidget" name="table"> <widget class="QTableWidget" name="table">
<column> <column>
<property name="text"><string>用户ID</string></property> <property name="text">
<string>用户ID</string>
</property>
</column> </column>
<column> <column>
<property name="text"><string>用户名</string></property> <property name="text">
<string>用户名</string>
</property>
</column> </column>
<column> <column>
<property name="text"><string>注册时间</string></property> <property name="text">
<string>注册时间</string>
</property>
</column> </column>
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="layout_btns"> <layout class="QHBoxLayout" name="layout_btns">
<item><widget class="QPushButton" name="btn_delete"><property name="text"><string>删除选中用户</string></property></widget></item> <item>
<item><widget class="QPushButton" name="btn_refresh"><property name="text"><string>刷新</string></property></widget></item> <widget class="QPushButton" name="btn_delete">
<item><widget class="QPushButton" name="btn_get"><property name="text"><string>获取设备用户列表</string></property></widget></item> <property name="text">
<item><widget class="QPushButton" name="btn_del_all"><property name="text"><string>删除所有用户</string></property></widget></item> <string>删除选中用户</string>
<item><spacer name="spacer"><property name="orientation"><enum>Qt::Horizontal</enum></property></spacer></item> </property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_refresh">
<property name="text">
<string>刷新</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_get">
<property name="text">
<string>获取设备用户列表</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_del_all">
<property name="text">
<string>删除所有用户</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
</widget> </widget>
<resources/>
<connections/>
</ui> </ui>

View File

@ -2,5 +2,5 @@
language = zh_CN language = zh_CN
blanking_time = 360 blanking_time = 360
password = 2008 password = 2008
facerecognition_timeout = 20 facerecognition_timeout = 10