diff options
author | Michael Stone <michael@laptop.org> | 2011-01-08 04:34:41 (GMT) |
---|---|---|
committer | Michael Stone <michael@laptop.org> | 2011-01-08 04:34:41 (GMT) |
commit | 6bd55792759f3249e5092eb8cabeda543ca332d0 (patch) | |
tree | 57daccf23fe2bfeb0354b4ebe589f2a433b2c0b8 | |
parent | 66d5809b1542fdbbd65928d7e209c305c4e0e08c (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() |