diff options
author | Michael Stone <michael@laptop.org> | 2011-01-08 04:34:41 (GMT) |
---|---|---|
committer | Michael Stone <michael@laptop.org> | 2011-01-08 06:35:15 (GMT) |
commit | a30795526be81086d8e20a31f51df37a876266ba (patch) | |
tree | 2bdd2d9afda8714d106e605c1962a5dda95ecb10 | |
parent | a9ff4c6e46313808172d6d1d7707fd010bd61f2f (diff) |
Fix period-bounding.
-rw-r--r-- | arithmetic.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/arithmetic.py b/arithmetic.py index 654a2e6..11758eb 100644 --- a/arithmetic.py +++ b/arithmetic.py @@ -136,8 +136,6 @@ class ArithmeticActivity(groupthink.sugar_tools.GroupActivity): try: period = self.cloud.periodentry.get_text() period = int(period) - if period < 2 or period > 60: - raise ValueError("bad period") except: period = 10 return period @@ -232,6 +230,7 @@ class ArithmeticActivity(groupthink.sugar_tools.GroupActivity): self.cloud.periodentry.modify_font(pango.FontDescription("Mono 14")) self.cloud.periodentry.set_text(str(self.period)) self.cloud.periodentry.set_width_chars(2) + self.cloud.periodentry.connect("changed", self._period_cb) # Puzzle generators self.cloud.puzzles = groupthink.AddOnlySet() @@ -383,6 +382,15 @@ class ArithmeticActivity(groupthink.sugar_tools.GroupActivity): self.decisionentry.set_text("Not correct: invalid input") # Callbacks. + def _period_cb(self, _): + try: + period = self.cloud.periodentry.get_text() + period = int(period) + if period < 1: self.cloud.periodentry.set_text("10") + elif period > 99: self.cloud.periodentry.set_text("60") + except: + pass + def answer_cb(self, answer, incorrect=False): self.solve(answer, incorrect) @@ -423,6 +431,9 @@ class ArithmeticActivity(groupthink.sugar_tools.GroupActivity): self.answerentry.set_text("") self.decisionentry.set_text("") + if self.cloud.periodentry.get_text() != str(self.secondsleft): + self.cloud.periodentry.set_text(str(self.period)) + def easy_cb(self, toggled): self.DIFFICULTY_EASY = toggled.get_active() self.answerentry.grab_focus() |