changeset 54:d747563dff03

add create project related states create a project by pressing 'a' in the main menu
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 04 Apr 2011 12:25:26 +0200
parents 1d63ab21b8af
children 1f7c9371b648
files getan/states.py
diffstat 1 files changed, 92 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/getan/states.py	Mon Apr 04 12:23:55 2011 +0200
+++ b/getan/states.py	Mon Apr 04 12:25:26 2011 +0200
@@ -63,6 +63,9 @@
         if 'enter' in key:
             return self.select()
 
+        if 'a' in key:
+            return AddProjectNameState(self.controller, self.view)
+
         if 'esc' in key:
             return ExitState(self.controller, self.view)
 
@@ -91,7 +94,6 @@
         self.controller.start_project(self.view.item_in_focus())
         return RunningProjectsState(self.controller, self.view)
 
-
 class ExitState(ProjectState):
     messages = {
         'quit'  : _(" Really quit? (y/n)"),
@@ -438,3 +440,92 @@
                 self.view.set_footer_text(self.msg('really'), 'question')
 
         return self
+
+class CreateProjectState(HandleUserInputState):
+
+    messages = {
+            'choose_proj': _(' Choose a project.'),
+            }
+
+    def __init__(self, controller, view):
+        super(CreateProjectState, self).__init__(controller, view, None,
+                controller.view.view.get_footer())
+
+    def exit(self):
+        self.controller.view.set_footer_text(self.msg('choose_proj'), 'question')
+        return PausedProjectsState(self.controller, self.view)
+
+class AddProjectNameState(CreateProjectState):
+    messages = {
+        'choose_proj': _(' Choose a project.'),
+        'proj_name': _('Insert new project name: '),
+    }
+
+    def __init__(self, controller, view):
+        controller.view.set_footer_text(self.msg('proj_name'),
+                                             'question', 1)
+        super(AddProjectNameState, self).__init__(controller, view)
+        self.view.frame.set_focus('footer')
+
+    def enter(self):
+        project = self.footer.get_edit_text()
+        if project == '':
+            return self
+        return AddProjectKeyState(self.controller, self.view, project)
+
+
+class AddProjectKeyState(CreateProjectState):
+
+    messages = {
+        'proj_name': _('Insert new project name: '),
+        'proj_key': _('Insert key for new project: '),
+    }
+
+    def __init__(self, controller, view, project):
+        controller.view.set_footer_text(self.msg('proj_key'),
+                                             'question', 1)
+        super(AddProjectKeyState, self).__init__(controller, view)
+        self.view.frame.set_focus('footer')
+        self.project = project
+
+    def keypress(self, key):
+        logger.debug("HandleUserInputState: handle key '%r'" % key)
+        pos = self.footer.edit_pos
+
+        if 'esc' in key:
+            return self.exit()
+        elif 'enter' in key:
+            return self.enter()
+        elif len(key) >= 1 and len(key[0]) == 1:
+            self.footer.set_edit_pos(pos)
+            self.footer.set_edit_text(key[0])
+            return self
+
+    def enter(self):
+        key = self.footer.get_edit_text()
+        if key == '':
+            return self
+        return AddProjectDescriptionState(self.controller, self.view,
+                self.project, key)
+
+class AddProjectDescriptionState(CreateProjectState):
+    messages = {
+        'proj_description': _('Insert a description for project: '),
+        'choose_proj': _(" Choose a project.")
+        }
+
+    def __init__(self, controller, view, project, key):
+        controller.view.set_footer_text(self.msg('proj_description'),
+                                             'question', 1)
+        super(AddProjectDescriptionState, self).__init__(controller, view)
+        self.view.frame.set_focus('footer')
+        self.project = project
+        self.key = key
+
+    def enter(self):
+        description = self.footer.get_edit_text()
+        if description == '':
+            return self
+        self.controller.add_project(self.key, description)
+        self.controller.view.set_footer_text(self.msg('choose_proj'), 'question')
+        return PausedProjectsState(self.controller, self.view)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)