示例#1
0
 def onQuizGen(self):
     if not utils.ensureClassExists():
         utils.errorBox("Please create at least one class first.",
                 "No Classes")
         return False
     qw = ui.quizgen.QuizWindow(self, self.config, self.databaseConfig)
     qw.exec_()
示例#2
0
 def onManual(self):
     manualLoc = "docs/manual.html"
     if os.path.isfile(manualLoc):
         QDesktopServices.openUrl(QtCore.QUrl(manualLoc))
     else:
         utils.errorBox("Could not locate the manual! Please report this " \
                        "error to the developer.", "File not found")
示例#3
0
 def onBackupDB(self):
     copyto = QFileDialog.getSaveFileName(caption="Save Backup As",
             filter="Quiz Databases (*.db);;All files (*)")
     copyto = unicode(copyto)
     if not copyto: # canceled
         return
     copyto = utils.forceExtension(copyto, 'db')
     if copyto is None:
         # see docstring of forceExtension
         return
     db.database.inter.close() # make sure everything's been saved
     try:
         shutil.copyfile(self.dbpath, copyto)
     except shutil.Error:
         utils.errorBox("You cannot back up a file to itself! " \
                        "(But nice try...)", "Backup failed")
     except IOError:
         utils.errorBox("Backup failed. Please be sure that the " \
                        "destination is writeable and not full and " \
                        "that you have permission to access it.",
                        "Backup failed")
     else:
         utils.informationBox("Backup successful.", "Success")
     finally:
         self._connectDb(self.dbpath) # reconnect
示例#4
0
    def onImportResults(self):
        fname = QFileDialog.getOpenFileName(caption="Import Results",
                                            filter="HTML files (*.html)")
        if not fname:
            return
        with open(fname) as f:
            html = f.read()
        responses = db.results.parseHtmlString(html)
        for resp in responses:
            try:
                db.results.writeResults(resp, self._currentClass(),
                                        self._currentZid())
            except db.results.WrongQuizError as e:
                utils.errorBox(unicode(e))
                return False
            except db.results.MissingStudentError as e:
                db.results.delResults(self._currentZid())
                extra = " The student ID numbers in the students dialog for"\
                        " this class must match the ID numbers in"\
                        " TurningPoint so that CQM can match responses with"\
                        " students. No results have been imported; please"\
                        " check and correct the list, then try importing again."
                utils.errorBox(unicode(e) + extra)
                return False

        obj = self.tableModel.getObj(self.form.tableView.currentIndex())
        obj.rewriteResultsFlag(1)  # results imported, not yet sent
        self.checkButtonEnablement()
        return True
示例#5
0
    def onGenerate(self):
        sq = self.quiz
        sq.setNewQuestions(self.form.newSpin.value())
        sq.setRevQuestions(self.form.revSpin.value())
        if not self.quiz.isSetUp():
            utils.errorBox("Quiz settings have not been made yet!")
            return

        prevText = self.quiz.generate()
        if not (sq.useNewNum or sq.useRevNum):
            topText = "This quiz is blank. Please add some questions and try again."
        else:
            topText = "This quiz contains %i new question%s and %i review%s.\n"
            topText += "New questions are from %s %s."
            sns, n = sq.getSetNames()
            topText = topText % (sq.useNewNum, 's' if sq.useNewNum != 1 else '',
                                 sq.useRevNum, 's' if sq.useRevNum != 1 else '',
                                 'the following sets:' if n != 1 else 'the set',
                                 sns)

        prevText = '\n\n'.join([topText, prevText])
        d = PreviewDialog(self, self.config, self.dbConfig)
        d.setText(prevText)
        d.exec_()

        #### maybe make this a return val later? not sure
        if self.previewResult:
            QDialog.accept(self)
示例#6
0
 def onValueRejected(self, errorMsg):
     utils.errorBox(errorMsg, "Invalid entry")