changeset 197:2eb2bbf042b3

Inplement new State user input handling Use a three phase user input handling. 1. Allow to filter keys in input_filter 2. Redirect keys to a view to use existing widget functions 3. Act on user input in handle_input
author Björn Ricks <bjoern.ricks@intevation.de>
date Fri, 05 Apr 2013 19:14:03 +0200
parents 2c4cfc79632c
children 9f85ffa0a2f6
files getan/states.py
diffstat 1 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/getan/states.py	Fri Apr 05 19:01:54 2013 +0200
+++ b/getan/states.py	Fri Apr 05 19:14:03 2013 +0200
@@ -21,6 +21,18 @@
 logger = logging.getLogger()
 
 class State(object):
+    """ Represents a State of Getan
+
+    A State can be used to handle user input. The user input handling is done in
+    three phases. First it is possible to filter keys that shouldn't be passed
+    to a widget in input_filter. Afterwards it is possible to redirect a key to
+    a specific widget in keypress. In the third phase it is possible to act on
+    user input which isn't handled by a widget yet. The corresponing method is
+    handle_input.
+
+    Normally handle_input should be used to act on user input and change a
+    state.
+    """
 
     messages = {
     }
@@ -30,6 +42,25 @@
         self.view = view
         self.config = controller.get_config()
 
+    def input_filter(self, input, raw):
+        """Filters input that should not be passed to widget elements
+
+        By default no input is filtered and input is returned unchanged.
+        """
+        return input
+
+    def keypress(self, size, key):
+        """Redirects user input to the current view"""
+        self.view.keypress(size, key)
+
+    def handle_input(self, input):
+        """A derived State must implement handle_input"""
+        raise NotImplementedError()
+
+    def set_next_state(self, state):
+        """Sets the next state"""
+        self.controller.set_state(state)
+
     def msg(self, key):
         return self.messages[key]
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)