Permalink
Browse files

combo box to allow selection of tutor stat

  • Loading branch information...
1 parent b44be91 commit 4b011861c892c4a14003eaadbd8117ccc1e59631 @baverman committed Feb 11, 2011
Showing with 40 additions and 5 deletions.
  1. +5 −1 typetrainer/ui/main.py
  2. +1 −0 typetrainer/ui/stat.glade
  3. +34 −4 typetrainer/ui/stat.py
View
@@ -323,5 +323,9 @@ def update_title(self):
def on_stat_activate(self, item):
from .stat import StatWindow
- window = StatWindow(self.window, self.stat)
+ tutor = self.filler.name
+ if tutor not in available_tutors:
+ tutor = 'en.basic'
+
+ window = StatWindow(self.window, self.stat, tutor)
window.window.show_all()
@@ -40,6 +40,7 @@
<property name="width_request">200</property>
<property name="visible">True</property>
<property name="model">tutor_ls</property>
+ <signal name="changed" handler="on_tutor_cb_changed"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
View
@@ -1,9 +1,10 @@
+import os, os.path
from datetime import datetime
+import math
import gtk
-import math
-from . import BuilderAware
+from . import BuilderAware, idle, refresh_gui
from ..util import join_to_file_dir
def median(values):
@@ -141,7 +142,7 @@ def draw_label(self, cr, label, x, y, w, h, xalign, yalign):
class StatWindow(BuilderAware):
"""glade-file: stat.glade"""
- def __init__(self, parent, stat):
+ def __init__(self, parent, stat, tutor):
BuilderAware.__init__(self, join_to_file_dir(__file__, 'stat.glade'))
self.stat = stat
@@ -151,7 +152,36 @@ def __init__(self, parent, stat):
self.drawer = StatDrawer()
self.frame.add(self.drawer)
+ self.tutor = tutor
self.acc_adj.value = 97
+ idle(self.fill_tutor_cb)
def on_acc_adj_value_changed(self, adj):
- self.drawer.set_data(self.stat.get('en.basic', adj.value))
+ self.refresh()
+
+ def refresh(self):
+ self.drawer.set_data(self.stat.get(self.tutor, self.acc_adj.value))
+
+ def fill_tutor_cb(self):
+ root = self.stat.root
+ for name in os.listdir(root):
+ fname = os.path.join(root, name)
+ try:
+ with open(fname) as f:
+ tname = f.readline().strip()
+ if fname == self.stat.get_filename(tname):
+ self.tutor_ls.append((fname, tname))
+ except IOError:
+ pass
+
+ refresh_gui()
+
+ for i, (fname, tname) in enumerate(self.tutor_ls):
+ if tname == self.tutor:
+ self.tutor_cb.set_active(i)
+
+ def on_tutor_cb_changed(self, cb):
+ it = cb.get_active_iter()
+ if it:
+ self.tutor = self.tutor_ls.get_value(it, 1)
+ self.refresh()

0 comments on commit 4b01186

Please sign in to comment.