Ejemplo n.º 1
0
    def checkAnswers(self):
        xbmc.executebuiltin("ActivateWindow(busydialog)")
        numQuestions = len(self.questions)
        if numQuestions > 8:
            numQuestions = 8

        numCorrectAnswers = 0
        # Read the answers that are populated
        for i in range(0, numQuestions):
            editControl = self.getControl(FilmWiseViewer.EDIT_BOX_IDS[i])
            enteredAnswer = editControl.getText()
            tag = self.questions[i]['name']
            if (enteredAnswer is not None) and len(enteredAnswer) > 0:
                answers = {tag: enteredAnswer}

                correctAnswers = 0
                # Check if this answer is already in the correct answers list
                if self.correctUserAnswers.get(tag, '') == enteredAnswer:
                    correctAnswers = 1
                else:
                    # Now make the request to check the answers
                    filmWise = FilmWiseCore()
                    correctAnswers = filmWise.checkAnswer(self.form, self.redirect, answers)
                    del filmWise

                isCorrect = False
                if correctAnswers > 0:
                    isCorrect = True
                    numCorrectAnswers = numCorrectAnswers + 1
                    self.correctUserAnswers[tag] = enteredAnswer

                self._setCorrectFlag(i, isCorrect)
                # Save the answer to the database
                if self.quizNum > 0:
                    self.database.addAnswer(self.quizNum, tag, enteredAnswer, isCorrect)
            else:
                self._setCorrectFlag(i)
                # No answer entered for this one, so clear any DB entry
                if self.quizNum > 0:
                    self.database.deleteAnswer(self.quizNum, tag)

        # Now set the score total
        self._setScore(numCorrectAnswers, numQuestions)

        xbmc.executebuiltin("Dialog.Close(busydialog)")
Ejemplo n.º 2
0
    def showSolution(self):
        xbmc.executebuiltin("ActivateWindow(busydialog)")
        # Make sure there is a solution
        if self.solution in [None, ""]:
            return

        # Make the request to get the full solution
        filmWise = FilmWiseCore()
        solutionDetails = filmWise.getSolution(self.solution)
        del filmWise

        if len(solutionDetails) > 0:
            # Set all the images for the quiz
            for i in range(0, 8):
                img = self.questions[i].get('image', None)
                if img is None:
                    continue
                else:
                    solutionImg = img.replace('.jpg', 'a.jpg')
                    log("showSolution: Solution Img = %s" % solutionImg)
                editControl = self.getControl(FilmWiseViewer.EDIT_BOX_IDS[i])
                answer = solutionDetails.get(solutionImg, '')
                log("showSolution: Answer Is %s" % answer)
                editControl.setText(answer)

                # Also need to replace the images
                if answer not in [None, ""]:
                    imageControl = self.getControl(FilmWiseViewer.IMAGE_IDS[i])
                    imageControl.setImage(solutionImg)

        # Disable the buttons, the only option when you have seen the solution is close
        checkControl = self.getControl(FilmWiseViewer.CHECK_BUTTON)
        checkControl.setVisible(False)
        solutionControl = self.getControl(FilmWiseViewer.SOLUTION_BUTTON)
        solutionControl.setVisible(False)

        # We actually leave the tick flag as it was so the user can see if they
        # had it correct
        xbmc.executebuiltin("Dialog.Close(busydialog)")