Esempio n. 1
0
class MainWindowUIClass(Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.fileReader = FileReader()
        self.hasOutput = False

    def setupUi(self, MW):
        super().setupUi(MW)

    def refreshAll(self):
        selectedFileName = self.fileReader.getFileName()
        links.append(selectedFileName)
        self.lstbox.index += 1
        onlyFileName = selectedFileName.split("/")[-1]
        linkNames.append(str(self.lstbox.index) + ". " + onlyFileName)
        self.lstbox.addItem(str(self.lstbox.index) + ". " + onlyFileName)

    # slot
    def exportSlot(self):
        if self.hasOutput:
            self.exportSelection = exportSelectWidget(self)
            self.exportSelection.show()
        else:
            global messageType
            messageType = 2
            self.systemMessage = PopUpMessageBox()

    # slot
    def importFileSlot(self):
        options = QtWidgets.QFileDialog.Options()
        fileName, _ = QtWidgets.QFileDialog.getOpenFileName(
            None, "File Broswer", "", "JSON Files (*.json)", options=options)
        if fileName:
            self.fileReader.setFileName(fileName)
            self.refreshAll()

    # slot
    def importDirectorySlot(self):
        getExistingDirectory = QFileDialog.getExistingDirectory
        fileName = getExistingDirectory(None, 'Folder Broswer', "")
        if fileName:
            self.fileReader.setFileName(fileName)
            self.refreshAll()

    # slot
    def readFileSlot(self):
        self.message.setText("")
        global messageType
        self.path = QListWidgetItem(self.lstbox.currentItem()).text()
        self.showProgress = PopUpProgressBar()
        if self.path != '':
            self.showProgress.show()
            index = linkNames.index(self.path)
            self.parseData = Parser(str(links[index]))
            pickleName = self.parseData.parse(self.showProgress)
            self.testing = Testing(pickleName)
            self.results = self.testing.analyse(self.showProgress)
            self.outputResult = list()
            for result in self.results:
                self.outputResult.append(result[:-1])
            self.dataFrame = pd.DataFrame(
                self.outputResult, columns=['File', 'Confidence', 'Motion'])
            print(self.dataFrame)
            self.text = ""
            for result in self.results:
                self.text = result[0] + " is " + result[1] + "% " + result[2]
                self.textbox.addItem(self.text)
            self.showProgress.close()
            if self.text == "":
                messageType = 1
                self.systemMessage = PopUpMessageBox()
            else:
                self.hasOutput = True
        else:
            messageType = 2
            self.systemMessage = PopUpMessageBox()

    # slot
    def animationSlot(self):
        try:
            self.message.setText("")
            self.selectedAnimation = QListWidgetItem(
                self.textbox.currentItem()).text().split(" is")[0]
            for result in self.results:
                if result[0] == self.selectedAnimation:
                    self.selectedAnimation = result[3]
                    break
            motion = pickle.load(open(self.selectedAnimation, "rb"))

            v = Viewport(disable_mouse=True, w=700, h=600)
            v.objects.clear()
            v.add_object(
                Mesh(name="cube",
                     primitive_type="skeleton",
                     pos=[-2.5, 0, -5],
                     color=(255, 0, 0),
                     segments=10))
            frame = 0
            frames = 0
            while True:
                v.objects[0].set_skeleton_state(motion[frame % len(motion)], 0,
                                                0, 0)
                v.update(draw_f=True, draw_e=True, draw_v=True)
                if frames % 7 == 0:
                    frame += 1
                frames += 1

        except (FileNotFoundError, IOError, AttributeError):
            global messageType
            messageType = 3
            self.systemMessage = PopUpMessageBox()
        except:
            pass