changeset 167:be9acb00cd97

Update project selection Allow to select single letter projects directly.
author Björn Ricks <bjoern.ricks@intevation.de>
date Thu, 06 Dec 2012 15:44:04 +0100
parents eead2420b8bc
children 75fef53ebc36
files getan/states.py
diffstat 1 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/getan/states.py	Thu Dec 06 15:30:49 2012 +0100
+++ b/getan/states.py	Thu Dec 06 15:44:04 2012 +0100
@@ -91,7 +91,7 @@
 
         else:
             if len(key) > 0 and len(key[0]) == 1:
-                select_proj = SelectProjectState(self.controller, self.view, key[0])
+                select_proj = SelectProjectState(self.controller, self.view)
                 return select_proj.keypress(key)
         return self
 
@@ -103,9 +103,9 @@
 
 class SelectProjectState(State):
 
-    def __init__(self, controller, view, key):
+    def __init__(self, controller, view):
         super(SelectProjectState, self).__init__(controller, view)
-        self.proj_keys = key
+        self.proj_keys = ""
         self.set_footer_text()
 
     def reset(self):
@@ -115,7 +115,7 @@
         self.view.set_footer_text("Selecting project from key: %s" % self.proj_keys, "running")
 
     def check_key(self, key):
-        return len(self.controller.find_projects_by_key(key)) > 0
+        return len(self.controller.find_projects_by_key(key))
 
     def select_project(self):
         proj = self.controller.project_by_key(self.proj_keys)
@@ -139,15 +139,20 @@
                 self.proj_keys = self.proj_keys[:-1]
                 self.set_footer_text()
             return self
+
         if keys.get_enter() in key:
             return self.select_project()
+
         else:
             if len(key) > 0 and len(key[0]) == 1:
                 proj_key = self.proj_keys + key[0]
-                if self.check_key(proj_key):
+                num = self.check_key(proj_key)
+                if num > 0:
                     self.proj_keys += key[0]
                     self.set_footer_text()
-                    return self.select_project()
+                    if num == 1:
+                        # run project directly
+                        return self.select_project()
         return self
 
 class ExitState(ProjectState):
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)