Exemplo n.º 1
0
 def add_books(self):
     global books
     res = self.open_dialog_box()
     name = res[0].split('/')[-1]
     Dialog2 = QtWidgets.QDialog()
     ui = Ui_Dialog()
     ui.setupUi(Dialog2, path=res[0], name=name, add=1)
     Dialog2.show()
     s = Dialog2.exec_()
     if s == 1:
         if ui.data['path'] not in [i[1] for i in books]:
             books.append([
                 ui.data['name'], ui.data['path'], ui.data['tags'],
                 ui.data['notes']
             ])
             item = books[-1]
             newitem = QtWidgets.QListWidgetItem(
                 f"Name: {item[0]}\nPath: {item[1]}\nTags: {', '.join(item[2])}\nNotes: {item[3]}\n"
             )
             font = QtGui.QFont('Times', 12)
             font.setBold(True)
             font.setWeight(50)
             newitem.setFont(font)
             self.list_1.addItem(newitem)
             add_book(
                 conn,
                 Book(ui.data['name'], ui.data['path'], ', '.join(item[2]),
                      ui.data['notes']))
Exemplo n.º 2
0
    def button_clicked(self):
        Dialog = QtWidgets.QDialog()
        ui = Ui_Dialog()
        ui.setupUi(Dialog)
        Dialog.show()
        rsp = Dialog.exec_()

        if rsp == QtWidgets.QDialog.Accepted:
            self.label.setText("Ok Button Was Clicked")
        else:
            self.label.setText("Cancel Button Was Clicked")
Exemplo n.º 3
0
    def button_clicked(self):
        Dialog = QtWidgets.QDialog()
        ui = Ui_Dialog()
        ui.setupUi(Dialog)
        Dialog.show()
        #Dialog.exec_()
        rsp = Dialog.exec_()

        if rsp == QtWidgets.QDialog.Accepted:
            self.label.setText('Ok button was clicked')
        else:
            self.label.setText('Cancel button was clicked')
Exemplo n.º 4
0
 def __init__(self, parent=None):
     super(Main, self).__init__(parent)
     self.setupUi(self)
     self.progressBar.setValue(0.0)
     self.pushButton.clicked.connect(self.buttonClick)
     self.Signal_TrainFinished.connect(self.trainFinished)
     self.Signal_FinalTestFinished.connect(self.finalTestFinished)
     self.Dialog01 = Ui_Dialog(None,self.Signal_stopFinalTest)
     self.isTest = False
     self.th1 = None
     self.TESTCLASS = None
     self.Signal_stopFinalTest.connect(self.stopFinalTest)
Exemplo n.º 5
0
    def button_clicked(self):
        Dialog = QtWidgets.QDialog()
        ui = Ui_Dialog()
        ui.setupUi(Dialog)
        Dialog.show()
        #         Dialog.exec_()
        rsp = Dialog.exec_(
        )  # have to call exec_() otherwise dialog window closes immediately

        if rsp == QtWidgets.QDialog.Accepted:
            self.label.setText("Ok button was clicked")
        else:
            self.label.setText("Cancel button was clicked")
Exemplo n.º 6
0
    def button_clicked(self):
        Dialog = QtWidgets.QDialog()
        ui = Ui_Dialog()
        ui.setupUi(Dialog)
        Dialog.show()
        #Dialog.exec_()

        if rsp == QtWidgets.QDialog.Accepted:
        self.label.setText("Ok Button was Clicked")
        else:
        self.label.setText("Cancel Button was Clicked")

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.groupBox.setTitle(_translate("MainWindow", "Dialog"))
        self.pushButton.setText(_translate("MainWindow", "Call Dialog"))
Exemplo n.º 7
0
 def open_properties(self, item):
     global books
     lines = item.text().split('\n')
     final = []
     for index, i in enumerate(lines):
         lines[index] = i.strip()
         val = ' '.join(lines[index].split(' ')[1:])
         final.append(val)
     Dialog2 = QtWidgets.QDialog()
     ui = Ui_Dialog()
     ui.setupUi(Dialog2,
                path=final[1],
                name=final[0],
                tags=final[2],
                notes=final[3])
     Dialog2.show()
     s = Dialog2.exec_()
     if s == 1:
         if ui.data['delete'] is True:
             for index, i in enumerate(books):
                 if i[1] == final[1]:
                     ind = index
                     break
             delete_book(conn, books[ind][1])
             del books[ind]
             self.show_all()
         else:
             # Ok is clicked
             for index, i in enumerate(books):
                 if i[1] == final[1]:
                     ind = index
                     break
             books[index][0] = ui.data['name']
             books[index][1] = ui.data['path']
             books[index][2] = ui.data['tags']
             books[index][3] = ui.data['notes']
             edit_book(conn, 'name', books[index][0], books[index][1])
             edit_book(conn, 'tags', ', '.join(books[index][2]),
                       books[index][1])
             edit_book(conn, 'notes', books[index][3], books[index][1])
             self.show_all()
Exemplo n.º 8
0
 def button_clicked(self):
     Dialog = QtWidgets.QDialog()
     ui = Ui_Dialog()
     ui.setupUi(Dialog)
     Dialog.show()
     Dialog.exec_()
Exemplo n.º 9
0
def openDialog():
    Dialog = QtWidgets.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    MainWindow.close()
    Dialog.show()
Exemplo n.º 10
0
class Main(QtWidgets.QMainWindow,Ui_MainWindow):
    Signal_TrainFinished = pyqtSignal()
    Signal_FinalTestFinished = pyqtSignal(int, int)
    Signal_stopFinalTest = pyqtSignal()


    def __init__(self, parent=None):
        super(Main, self).__init__(parent)
        self.setupUi(self)
        self.progressBar.setValue(0.0)
        self.pushButton.clicked.connect(self.buttonClick)
        self.Signal_TrainFinished.connect(self.trainFinished)
        self.Signal_FinalTestFinished.connect(self.finalTestFinished)
        self.Dialog01 = Ui_Dialog(None,self.Signal_stopFinalTest)
        self.isTest = False
        self.th1 = None
        self.TESTCLASS = None
        self.Signal_stopFinalTest.connect(self.stopFinalTest)
        #self.Dialog01.show()


    def train(self):
        """ Training
        """
        self.textEdit.append('开始训练...')
        dataset = 'cus_mnist_2'
        # dataroot = './data/cus_mnist'
        dataroot = 'E:\ProjectSet\Pycharm\WAIBAO\cus_mnist2'
        opt = Options().parse(dataset,dataroot)
        opt.signal = self.Signal_TrainFinished
        opt.load_weights = False
        dataloader = load_data(opt)
        print(opt)

        # LOAD MODEL
        opt.showProcess = self.progressBar
        opt.showText = self.textEdit
        model = Ganomaly(opt, dataloader)
        model.train()

    def test(self):
        self.textEdit.append('开始测试,得出阈值...')

        """ Testing
        """
        dataset = 'cus_mnist'
        # dataroot = './data/cus_mnist'
        opt = Options().parse(dataset)
        opt.isTrain = False
        opt.load_weights = True

        ##
        # LOAD DATA
        dataloader = load_data(opt)
        print(opt)
        ##
        # LOAD MODEL
        opt.showProcess = self.progressBar
        opt.showText = self.textEdit
        model = Ganomaly(opt, dataloader)

        print(model.test())

    def buttonClick(self):
        print('****')
        if not self.isTest:
            self.Dialog01.show()
            #self.th1 = threading.Thread(target=Main.FinalTest, args=(self,))
            #self.th1.start()
            self.FinalTest()
            self.isTest = True

        print('//////')

    def FinalTest(self):
        self.Dialog01.textEdit.append('正在检测所有图片..')
        dataset = 'cus_mnist'
        dataroot = './data/cus_mnist'
        opt = Options().parse(dataset,dataroot)
        opt.isTrain = False
        opt.load_weights = True
        opt.signal = self.Signal_FinalTestFinished
        ##
        # LOAD DATA
        dataloader = load_data(opt)
        print(opt)
        ##
        # LOAD MODEL
        #opt.showProcess = self.progressBar
        #opt.showText = self.textEdit
        opt.showProcess = self.Dialog01.progressBar
        opt.showText = self.Dialog01.textEdit

        self.TESTCLASS = MyTest("测试模型", opt, dataloader)
        self.TESTCLASS.start()
        print('GOOD')





        # model = Ganomaly(opt, dataloader)
        # ##
        # # TRAIN MODEL
        # # model.train()
        # minVal = None
        # maxVal = None
        # threshold = None
        # with open(opt.dataroot + '/performance.txt', 'r+', encoding='utf-8') as f:
        #     res = f.readline()
        #     res = res.split('&')
        #     res = [float(i) for i in res]
        #     minVal = res[0]
        #     maxVal = res[1]
        #     threshold = res[2]
        #
        # model.FinalTest(minVal, maxVal, threshold)

    def stopFinalTest(self):
        if self.isTest:
            self.stop_thread(self.TESTCLASS)
            self.isTest = False
            print('已关闭进程')
            self.Dialog01.close()



    def btn_click_start_train(self): #开始训练模型
        pass


    def btn_click_start_test(self): #开始测试模型
        pass

    def trainFinished(self):
        print('训练完毕')


    def finalTestFinished(self, num_nor, num_abn):
        self.Dialog01.close()
        QMessageBox.information(self, "检测结果","本次共检测了{}张图片。\n其中判定正常图片有{}张, 判定为异常的图片有{}张。".format(num_abn+num_nor, num_nor, num_abn))


    def _async_raise(self, tid, exctype):
        """raises the exception, performs cleanup if needed"""
        tid = ctypes.c_long(tid)
        if not inspect.isclass(exctype):
            exctype = type(exctype)
        res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
        if res == 0:
            raise ValueError("invalid thread id")
        elif res != 1:
            # """if it returns a number greater than one, you're in trouble,
            # and you should call it again with exc=NULL to revert the effect"""
            ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None)
            raise SystemError("PyThreadState_SetAsyncExc failed")

    def stop_thread(self, thread1):
        self._async_raise(thread1.ident, SystemExit)