Ran update-copyright.py
[hooke.git] / hooke / interaction.py
index b0055e7c4a0568b09de08a2c6769daff17803776..4477b583e705e701cd30edbb6d7be568115985a6 100644 (file)
@@ -1,4 +1,19 @@
-# Copyright
+# Copyright (C) 2010-2012 W. Trevor King <wking@tremily.us>
+#
+# This file is part of Hooke.
+#
+# Hooke is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
+#
+# Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with Hooke.  If not, see <http://www.gnu.org/licenses/>.
 
 """The `interaction` module provides :class:`Request`,
 :class:`Response`, an related classes for handling user interaction
@@ -43,19 +58,25 @@ class Interaction (object):
 
 class Request (Interaction):
     """Command engine requests for information from the UI.
+
+    >>> r = Request('test', 'Does response_class work?')
+    >>> r.response_class()    
+    <class 'hooke.interaction.Response'>
     """
-    def __init__(self, type, response_class,
-                 msg, default=None, validator=None):
+    def __init__(self, type, msg, default=None, validator=None):
         super(Request, self).__init__(type)
-        self.response_class = response_class
         self.msg = msg
         self.default = default
         self.validator = validator
 
+    def response_class(self):
+        class_name = self.__class__.__name__.replace('Request', 'Response')
+        return globals()[class_name]
+
     def response(self, value):
         if self.validator != None:
             self.validator(value)
-        return self.response_class(value)
+        return self.response_class()(value)
 
 class Response (Interaction):
     """UI response to a :class:`Request`.
@@ -64,10 +85,18 @@ class Response (Interaction):
         super(Response, self).__init__(type)
         self.value = value
 
+class EOFResponse (Response):
+    """End of user input.
+
+    After this point, no more user interaction is possible.
+    """
+    def __init__(self):
+        super(EOFResponse, self).__init__('EOF', None)
+
 class BooleanRequest (Request):
     def __init__(self, msg, default=None):
         super(BooleanRequest, self).__init__(
-            'boolean', BooleanResponse, msg, default,
+            'boolean', msg, default,
             validator = InList([True, False, default]))
 
 class BooleanResponse (Response):
@@ -76,8 +105,7 @@ class BooleanResponse (Response):
 
 class StringRequest (Request):
     def __init__(self, msg, default=None):
-        super(StringRequest, self).__init__(
-            'string', StringResponse, msg, default)
+        super(StringRequest, self).__init__('string', msg, default)
 
 class StringResponse (Response):
     def __init__(self, value):
@@ -85,8 +113,7 @@ class StringResponse (Response):
 
 class FloatRequest (Request):
     def __init__(self, msg, default=None):
-        super(FloatRequest, self).__init__(
-            'float', FloatResponse, msg, default)
+        super(FloatRequest, self).__init__('float', msg, default)
 
 class FloatResponse (Response):
     def __init__(self, value):
@@ -94,8 +121,7 @@ class FloatResponse (Response):
 
 class SelectionRequest (Request):
     def __init__(self, msg, default=None, options=[]):
-        super(SelectionRequest, self).__init__(
-            'selection', SelectionResponse, msg, default)
+        super(SelectionRequest, self).__init__('selection', msg, default)
         self.options = options
 
 class SelectionResponse (Response):
@@ -104,9 +130,9 @@ class SelectionResponse (Response):
 
 class PointRequest (Request):
     def __init__(self, msg, curve, block=0, default=None):
-        super(PointRequest, self).__init__(
-            'point', PointResponse, msg, default)
-        self.options = options
+        super(PointRequest, self).__init__('point', msg, default)
+        self.curve = curve
+        self.block = block
 
 class PointResponse (Response):
     def __init__(self, value):