Mercurial > getan
changeset 94:159a1ef0fd7c
Add new state to select projects with keys larger then one
Introduce a new SelectProjectState which records the key sequence and
return the project if a corresponding key was found. It's possible to
go back to the ProjectPausedState with ESC.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Wed, 31 Aug 2011 15:43:12 +0200 |
parents | bcf914880f80 |
children | 19e9d76a10fb |
files | getan/states.py |
diffstat | 1 files changed, 34 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/getan/states.py Wed Aug 31 15:41:13 2011 +0200 +++ b/getan/states.py Wed Aug 31 15:43:12 2011 +0200 @@ -82,13 +82,7 @@ else: if len(key) > 0: - proj = self.controller.project_by_key(key[0]) - if proj: - self.view.select_project(proj) - self.controller.start_project(self.view.item_in_focus()) - self.controller.update_entries( - self.view.item_in_focus()) - return RunningProjectsState(self.controller, self.view, proj) + return SelectProjectState(self.controller, self.view, key[0]) return self @@ -97,6 +91,39 @@ self.controller.start_project(proj) return RunningProjectsState(self.controller, self.view, proj) +class SelectProjectState(State): + + + def __init__(self, controller, view, key): + super(SelectProjectState, self).__init__(controller, view) + self.proj_keys = key + self.set_footer_text() + + def reset(self): + self.view.set_footer_text("", "entry_footer") + + def set_footer_text(self): + self.view.set_footer_text("Selecting project from key: %s" % self.proj_keys, "running") + + def keypress(self, key): + if 'esc' in key: + self.reset() + return PausedProjectsState(self.controller, self.view) + + else: + if len(key) > 0: + self.proj_keys += key[0] + self.set_footer_text() + proj = self.controller.project_by_key(self.proj_keys) + if proj: + self.reset() + self.view.select_project(proj) + self.controller.start_project(self.view.item_in_focus()) + self.controller.update_entries( + self.view.item_in_focus()) + return RunningProjectsState(self.controller, self.view, proj) + return self + class ExitState(ProjectState): messages = { 'quit' : _(" Really quit? (y/n)"),