From: W. Trevor King Date: Thu, 7 Feb 2013 03:09:06 +0000 (-0500) Subject: ui: Remove UserInterface.display_results() X-Git-Tag: v0.4~15 X-Git-Url: http://git.tremily.us/?p=quizzer.git;a=commitdiff_plain;h=58ec908f6d312a44fe37b037e736b7f6a1797c81 ui: Remove UserInterface.display_results() Having quizzer.cli.main() calling ui.display_results() does not translate well to an HTML-based UI. CommandLineInterface now displays results as part of its .run() implementation. --- diff --git a/quizzer/cli.py b/quizzer/cli.py index cc4880c..e0d0ced 100644 --- a/quizzer/cli.py +++ b/quizzer/cli.py @@ -90,4 +90,3 @@ def main(): ui.run() finally: ui.answers.save() - ui.display_results() diff --git a/quizzer/ui/__init__.py b/quizzer/ui/__init__.py index 4b39468..0db903c 100644 --- a/quizzer/ui/__init__.py +++ b/quizzer/ui/__init__.py @@ -32,9 +32,6 @@ class UserInterface (object): def run(self): raise NotImplementedError() - def display_results(self): - raise NotImplementedError() - def get_question(self): if self.stack: return self.stack.pop(0) diff --git a/quizzer/ui/cli.py b/quizzer/ui/cli.py index 464faec..473b34d 100644 --- a/quizzer/ui/cli.py +++ b/quizzer/ui/cli.py @@ -181,21 +181,21 @@ class CommandLineInterface (UserInterface): } def run(self): - if not self.stack: - return - cmd = QuestionCommandLine(ui=self) - cmd.cmdloop() - print() + if self.stack: + cmd = QuestionCommandLine(ui=self) + cmd.cmdloop() + print() + self._display_results() - def display_results(self): + def _display_results(self): print(_colorize(self.colors['result'], 'results:')) for question in self.quiz: if question.id in self.answers: - self.display_result(question=question) + self._display_result(question=question) print() - self.display_totals() + self._display_totals() - def display_result(self, question): + def _display_result(self, question): answers = self.answers.get(question.id, []) print('question:') print(' {}'.format( @@ -218,7 +218,7 @@ class CommandLineInterface (UserInterface): print(' you answered: {}'.format(ans)) print(' which was: {}'.format(correct)) - def display_totals(self): + def _display_totals(self): answered = self.answers.get_answered(questions=self.quiz) correctly_answered = self.answers.get_correctly_answered( questions=self.quiz)