Permalink
Browse files

store last used tutor for file

  • Loading branch information...
1 parent f45d6df commit a33423487444a02340bc0bd1d5154f4e4e26778f @baverman committed Jan 31, 2011
Showing with 32 additions and 10 deletions.
  1. +19 −2 typetrainer/config.py
  2. +1 −1 typetrainer/run.py
  3. +12 −7 typetrainer/ui/main.py
View
@@ -16,7 +16,10 @@ class Config(PySettings):
RECENT_FILES = None
RECENT_FILES_DOC = 'Last opened file list'
- def add_recent_file(self, filename, limit=5):
+ FILE2TUTOR = None
+ FILE2TUTOR_DOC = 'Map which stores last tutor used for file'
+
+ def _add_recent_file(self, filename, limit=5):
if 'RECENT_FILES' not in self:
rf = self['RECENT_FILES'] = []
else:
@@ -28,4 +31,18 @@ def add_recent_file(self, filename, limit=5):
pass
rf.insert(0, filename)
- rf[:] = rf[:limit]
+ rf[:] = rf[:limit]
+
+ def _set_tutor_for_file(self, filename, tutor):
+ if 'FILE2TUTOR' not in self:
+ f2t = self['FILE2TUTOR'] = {}
+ else:
+ f2t = self['FILE2TUTOR']
+
+ f2t[filename] = tutor
+
+ def _get_tutor_for_file(self, filename, default):
+ if 'FILE2TUTOR' in self:
+ return self['FILE2TUTOR'].get(filename, default)
+
+ return default
View
@@ -24,7 +24,7 @@ def run():
from typetrainer.tutors import get_filler
try:
filler = get_filler(config['TUTOR'], config['FILE'])
- config.add_recent_file(config['FILE'])
+ config._add_recent_file(config['FILE'])
except ImportError:
parser.error(_("Can't find [%s] tutor") % config['TUTOR'])
except IOError:
View
@@ -254,11 +254,8 @@ def on_open_file_activate(self, item):
response = dialog.run()
if response == gtk.RESPONSE_OK:
- tutor = self.filler.name
- if tutor not in available_tutors:
- tutor = 'en.basic'
-
- idle(self.update_filler, tutor, dialog.get_filename())
+ idle(self.update_filler, self.get_tutor_for_file(dialog.get_filename()),
+ dialog.get_filename())
dialog.destroy()
@@ -268,18 +265,26 @@ def update_filler(self, tutor, filename):
self.filler = get_filler(tutor, filename)
self.fill()
- self.config.add_recent_file(filename)
+ self.config._add_recent_file(filename)
self.update_title()
self.config['TUTOR'] = tutor
self.config['FILE'] = filename
+ def get_tutor_for_file(self, filename):
+ tutor = self.filler.name
+ if tutor not in available_tutors:
+ tutor = 'en.basic'
+
+ return self.config._get_tutor_for_file(filename, tutor)
+
def on_tutor_activate(self, item, tutor):
if item.get_active():
+ self.config._set_tutor_for_file(self.filler.filename, tutor)
idle(self.update_filler, tutor, self.filler.filename)
def on_filename_activate(self, item, filename):
- idle(self.update_filler, self.filler.name, filename)
+ idle(self.update_filler, self.get_tutor_for_file(filename), filename)
def on_keyboard_activate(self, item, kbd):
if item.get_active():

0 comments on commit a334234

Please sign in to comment.