-
Notifications
You must be signed in to change notification settings - Fork 0
/
delfacewindow.py
75 lines (67 loc) · 2.93 KB
/
delfacewindow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#删除人脸信息
import sqlite3
import requests
from PyQt5.QtWidgets import QDialog
from delface import Ui_Dialog
#创建一个delfacewindow类,QDialog不能省略(不知道具体是做什么的)
class delfacewindow(Ui_Dialog,QDialog):
#初始化函数,用户组列表和用户显示是在初始化函数中实现的,需要从主窗口传过来一个用户组列表(list)。
def __init__(self,list,accesstoken,parent=None):
self.accesstoken = accesstoken
super(delfacewindow,self).__init__(parent)
self.setupUi(self)
# 把组信息显示在列表框中.
self.show_list(list)
self.pushButton_3.clicked.connect(self.show_userlist)
self.pushButton.clicked.connect(self.get_data_close)
self.pushButton_2.clicked.connect(self.close_window)
# 把组信息显示在列表框中
def show_list(self, list):
for l in list:
self.listWidget.addItem(l)
#根据选择的用户组,显示对应的用户列表
def show_userlist(self):
#得到用户组列表的id
self.group_id = self.listWidget.currentItem().text()
#根据用户组的id获取用户列表
list_user = self.getuserslist(self.group_id,self.accesstoken)
#先清除之前画面的内容
self.listWidget_2.clear()
# 得到用户列表后显示到界面中
for i in range(len(list_user)):
#根据学生学号找到学生,并将学号和姓名显示到界面上
table = self.group_id+'_student'
conn = sqlite3.connect('my.db')
c = conn.cursor()
cursor = c.execute("select name,id from '"+table+"' where id = '" + list_user[i] + "'")
#cursor = c.execute("select name from student_1 where id = ?",123)
#print(c.fetchall())
for l in cursor:
name = str(l[0])
id = str(l[1])
self.listWidget_2.addItem(id+' '+name)
# 获取用户列表,需要传一个用户组过来
def getuserslist(self, group,accesstoken):
request_url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/group/getusers"
params = {
"group_id": group
}
access_token = accesstoken
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/json'}
response = requests.post(request_url, data=params, headers=headers)
if response:
data = response.json()
user_id = data['result']['user_id_list']
return user_id
# 确定按钮功能
def get_data_close(self):
self.group_id = self.listWidget.currentItem().text()
self.user_id = self.listWidget_2.currentItem().text()
#点击确定后关闭窗口
#accept()函数返回值是1
self.accept()
#取消按钮功能
def close_window(self):
#reject()函数的返回值是0
self.reject()