Permalink
Browse files

fallback to shorter error if there are no enough parts

  • Loading branch information...
1 parent ce69910 commit 63e0840e4934d850e0f379a2c706b1d2df1013af @baverman committed Feb 4, 2011
Showing with 24 additions and 4 deletions.
  1. +3 −0 typetrainer/generator.py
  2. +13 −1 typetrainer/tutors/common.py
  3. +8 −3 typetrainer/ui/main.py
View
@@ -84,6 +84,9 @@ def make_choicer(self):
return ch
+ def count(self, part):
+ return sum(1 if part in p else 0 for p in self.parts)
+
def choice(self, rnd):
if not self.choicer:
self.choicer = self.make_choicer()
@@ -72,4 +72,16 @@ def strip_non_word_chars(self, string):
if c in self.word_chars:
result += c
- return result
+ return result
+
+ def get_available_parts_for(self, key):
+ result = total = 0
+ for p in self.other.values():
+ result += p.count(key)
+ total += len(p.parts)
+
+ for p in self.first.values():
+ result += p.count(key)
+ total += len(p.parts)
+
+ return result / float(total)
View
@@ -112,9 +112,14 @@ def on_type_entry_activate(self, *args):
errors += 1
err = self.get_error(self.typed_chars)
- if err:
- self.filler.change_distribution(err, 0.8, True)
- self.retype_lb.set_text(err)
+ while err:
+ volume = self.filler.get_available_parts_for(err)
+ if volume > 0.005:
+ self.filler.change_distribution(err, 0.8, True)
+ self.retype_lb.set_text(err)
+ break
+
+ err = err[1:]
else:
self.filler.reset_distribution()
self.retype_lb.set_text('')

0 comments on commit 63e0840

Please sign in to comment.