示例#1
0
    def __init__(self, parent = None, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)
        self.setupUi(self)

        data = readjson("data/suiji_set.json")
        if len(data) == 0:
            self.lineEdit_num_1.setText("0")
            self.lineEdit_num_2.setText("0")
            self.lineEdit_num_3.setText("0")
            self.lineEdit_num_4.setText("0")
            self.lineEdit_num_5.setText("0")
            self.lineEdit_val_1.setText("1")
            self.lineEdit_val_2.setText("1")
            self.lineEdit_val_3.setText("1")
            self.lineEdit_val_4.setText("1")
            self.lineEdit_val_5.setText("1")
        else:
            self.lineEdit_num_1.setText(str(data[0][0]))
            self.lineEdit_num_2.setText(str(data[0][1]))
            self.lineEdit_num_3.setText(str(data[0][2]))
            self.lineEdit_num_4.setText(str(data[0][3]))
            self.lineEdit_num_5.setText(str(data[0][4]))
            self.lineEdit_val_1.setText(str(data[1][0]))
            self.lineEdit_val_2.setText(str(data[1][1]))
            self.lineEdit_val_3.setText(str(data[1][2]))
            self.lineEdit_val_4.setText(str(data[1][3]))
            self.lineEdit_val_5.setText(str(data[1][4]))
示例#2
0
    def initUi(self):

        # 设置当前用户显示
        self.label_2.setText("当前用户:"+self.currentusername)

        # 获取试卷信息,添加到listWidget
        self.users = readjson("data/userinfo.json")
        if len(self.users) == 0:
            self.users = {}

        self.model = QStandardItemModel()
        self.model.setHorizontalHeaderLabels(["用户名", "姓名", "性别", "一级单位", "二级单位", "三级单位", "注册时间", "用户权限"])

        # 添加数据
        for user in self.users:
            li = []
            q1 = QStandardItem(user)
            q1.setTextAlignment(Qt.AlignCenter)  # 设置单元格居中显示
            li.append(q1)
            for i in range(7):
                x = self.users[user][i+1]
                m = QStandardItem(x)
                m.setTextAlignment(Qt.AlignCenter)  # 设置单元格居中显示
                li.append(m)
            self.model.appendRow(li)
        self.tableView.setModel(self.model)
        self.tableView.horizontalHeader().setStretchLastSection(True)
        self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows)  # 设置表格的选取方式是行选取
示例#3
0
 def dan1_changed(self, text):
     self.units = readjson("data/unitsinfo.json")
     if text in self.units.keys():
         units2 = self.units[text].keys()
         if len(units2) > 0 :
             self.comboBox_2.clear()
             self.comboBox_2.addItems(units2)
     else:
         self.comboBox_2.clear()
示例#4
0
    def initUi(self):
        # 初始化tableview
        self.list_model = QStandardItemModel()
        self.list_model.setHorizontalHeaderLabels([
            "用户名", "姓名", "一级单位", "二级单位", "三级单位", "试卷名称", "考试时间", "考试时长", "用时",
            "题目数量", "总分", "得分", "考试类别"
        ])
        data = readjson("data/test_resualt_all.json")

        if len(data) > 0:
            # 添加数据
            for key in data:
                a, b = key.split("-")
                li = []
                account = data[key][0]
                li.append(account)
                d_temp = readjson("data/userinfo.json")
                if account in d_temp:
                    li += [d_temp[account][1]] + d_temp[account][3:6]
                else:
                    li += ["", "", "", ""]
                li += [b, a] + data[key][1:3]
                tmp1, tmp2 = data[key][4:6]
                nums, vals = 0, 0
                for i in range(5):
                    nums += tmp1[i]
                    vals += tmp1[i] * tmp2[i]
                li += [nums, vals] + [data[key][3]] + [data[key][-1]]

                ls_q = []
                for x in li:
                    q1 = QStandardItem(str(x))
                    q1.setTextAlignment(Qt.AlignCenter)  # 设置单元格居中显示
                    ls_q.append(q1)

                self.list_model.appendRow(ls_q)
            self.tableView.setModel(self.list_model)
            self.tableView.horizontalHeader().setStretchLastSection(True)
            # self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
            self.tableView.setSelectionBehavior(
                QAbstractItemView.SelectRows)  # 设置表格
示例#5
0
    def addusertotable(self, list_user):
        # list_user=['name', 'p', '丁莉莉', '男', '1', '22', '333', '202005161734']
        users = readjson("data/userinfo.json")
        if len(users) == 0:
            users = {}
        if list_user[0] in users:
            QMessageBox.about(self, "提示", "用户已存在!")
        else:
            users[list_user[0]] = list_user[1:] + ["一般用户"]
        writejson("data/userinfo.json", users)
        self.user_changed_singal.emit()

        self.initUi()
示例#6
0
    def __init__(self, parent=None, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)
        self.setAttribute(Qt.WA_StyledBackground, True)
        self.setupUi(self)
        self.setWindowTitle("登录")

        # 设置动画背景
        movie = QMovie(":/login/images/login_background1.gif")
        self.label_login_background.setMovie(movie)
        movie.setScaledSize(QSize(500, 180))
        movie.setSpeed(6)
        movie.start()

        # 设置下拉框信息,添加用户图标
        usr_info = readjson("data/userinfo.json")
        if len(usr_info) == 0:
            usr_info = {}
        self.comboBox.addItems(list(usr_info.keys()))
        for i in range(len(usr_info)):
            self.comboBox.setItemIcon(i, QIcon(":/login/images/login3.png"))
        self.comboBox.setMaxVisibleItems(5)

        # 初始化登录相关信息
        login_info = readjson("data/autologin.json")
        if len(login_info) > 0:  # 如果存在
            self.comboBox.setCurrentText(login_info[0])
            if login_info[3] == True:  # 记住密码
                self.lineEdit.setText(login_info[1])
                self.checkBox_2.setChecked(login_info[3])
            if login_info[2] == True:  # 自动登录
                self.checkBox.setChecked(login_info[2])

                # 延迟3秒后自动登录
                # todo 等待3秒后,如果用户没有操作,自动登录,由于这里初始化未绑定槽,所以直接调用不行
                self.time = QTimer(self)
                self.time.setInterval(5000)
                self.time.timeout.connect(self.auto_click)
                self.time.start()
示例#7
0
    def initUi(self):

        self.tiku = readjson("data/tiku.json")
        if len(self.tiku) == 0:
            self.tiku = {}
            QMessageBox.about(self, "提示", "请先导入题库!")
            self.pushButton_2.setEnabled(False)

        # 题库信息整理,长度统一
        length_row = 0
        sheet_list = []
        for x in self.tiku:
            length_row = max(length_row, len(self.tiku[x]))
            sheet_list.append(self.tiku[x])

        # 将题库补全,长度统一
        for i in range(len(sheet_list)):
            if len(sheet_list[i]) < length_row:
                sheet_len = len(sheet_list[i])
                for j in range(length_row - sheet_len):
                    sheet_list[i].insert(len(sheet_list[i]) - 2, "")

        # 插入表头信息
        first_row = ["适用人员", "适用单位", "题目", "题型"]
        i = 1
        for m in range(4, length_row - 2):
            first_row.append("选项" + str(i))
            i += 1
        first_row.append("答案")
        first_row.append("备注")

        self.model = QStandardItemModel()
        self.model.setHorizontalHeaderLabels(first_row)

        # 添加数据
        for item in sheet_list:
            li = []
            for v in item:
                q1 = QStandardItem(str(v))
                q1.setTextAlignment(Qt.AlignCenter)  # 设置单元格居中显示
                li.append(q1)
            self.model.appendRow(li)
        self.tableView.setModel(self.model)
        self.tableView.horizontalHeader().setStretchLastSection(True)
        self.tableView.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)
        self.tableView.setSelectionBehavior(
            QAbstractItemView.SelectRows)  # 设置表格的选取方式是行选取
示例#8
0
 def initUi(self):
     self.units = readjson("data/unitsinfo.json")
     for key in self.units:
         self.comboBox.addItem(str(key))
示例#9
0
    def init(self):
        # 获取试卷信息,添加到listWidget
        self.shijuan = readjson("data/shijuan_all.json")
        if self.shijuan == "":
            self.shijuan = {}
        names = list(self.shijuan.keys())
        if len(names) == 0:
            QMessageBox.about(self, "提示", "试卷信息为空,请先添加试卷!")
            self.flage = 1
            # self.close()            # todo 注意,由于此时主体功能已经初始化完毕,父程序中调用open函数在close函数后面,所以这里没有效果。
            return

        # 显示默认试卷
        # d = readjson("data/defaulttest.json")
        # if len(d) > 0:
        #     self.label_2.setText("默认试卷:" + str(list(d.keys())[0]))
        # else:
        #     self.label_2.setText("默认试卷:无")

        # 设置数据模型
        if len(self.shijuan[names[0]]) > 0:
            self.model = QStandardItemModel()
            self.model.setHorizontalHeaderLabels(
                ["序号", "试卷名称", "创建时间", "适用范围", "适用单位", "时长", "题目数", "总分"])
            for i in range(len(self.shijuan)):
                q1 = QStandardItem(str(i + 1))
                q1.setTextAlignment(Qt.AlignCenter)  # 设置单元格居中显示

                a, b = str(names[i]).split("-")
                q2, q3 = QStandardItem(b), QStandardItem(a)
                q2.setTextAlignment(Qt.AlignCenter)
                q3.setTextAlignment(Qt.AlignCenter)

                val = self.shijuan[names[i]][3].values()
                if len(val) > 0:
                    c, d = list(val)[0][:2]
                else:
                    c, d = "", ""
                q4, q5 = QStandardItem(c), QStandardItem(d)
                q4.setTextAlignment(Qt.AlignCenter)
                q5.setTextAlignment(Qt.AlignCenter)

                e = self.shijuan[names[i]][0]  # 时长
                q6 = QStandardItem(e)
                q6.setTextAlignment(Qt.AlignCenter)

                f = self.shijuan[names[i]][1]
                g = self.shijuan[names[i]][2]
                nums, scores = 0, 0
                for j in range(5):
                    nums += f[j]
                    scores += f[j] * g[j]
                q7, q8 = QStandardItem(str(nums)), QStandardItem(str(scores))
                q7.setTextAlignment(Qt.AlignCenter)
                q8.setTextAlignment(Qt.AlignCenter)

                self.model.appendRow([q1, q2, q3, q4, q5, q6, q7, q8])

            # 绑定数据模型
            self.tableView.setModel(self.model)

            # 表格显示设置
            self.tableView.setShowGrid(True)  # 显示网格线
            self.tableView.horizontalHeader().setStretchLastSection(
                True)  # 水平方向表格拉伸满
            # self.tableView.setColumnWidth(0, 50)                                          # 设置列宽,此处设置拉伸,无效
            self.tableView.horizontalHeader().setSectionResizeMode(
                QHeaderView.Stretch)  # 水平方向,表格大小拓展到适当的尺寸
            self.tableView.verticalHeader().setVisible(False)  # 隐藏第一列
            self.tableView.setSelectionBehavior(
                QAbstractItemView.SelectRows)  # 设置表格的选取方式是行选取
            self.tableView.setSelectionMode(
                QAbstractItemView.SingleSelection)  # 设置选取方式为单个选取