Replace .config rather than reconstructing plugins, drivers, and UIs.
[hooke.git] / hooke / interaction.py
index 778a0d693afc3c6e7204171a5cbd879627abe288..f5c39bfd724002fd887cf24465ef3dbfbb8edde5 100644 (file)
@@ -2,15 +2,15 @@
 #
 # This file is part of Hooke.
 #
 #
 # 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 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.
+# 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
 #
 # You should have received a copy of the GNU Lesser General Public
 # License along with Hooke.  If not, see
@@ -59,19 +59,25 @@ class Interaction (object):
 
 class Request (Interaction):
     """Command engine requests for information from the UI.
 
 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)
         super(Request, self).__init__(type)
-        self.response_class = response_class
         self.msg = msg
         self.default = default
         self.validator = validator
 
         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)
     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`.
 
 class Response (Interaction):
     """UI response to a :class:`Request`.
@@ -83,7 +89,7 @@ class Response (Interaction):
 class BooleanRequest (Request):
     def __init__(self, msg, default=None):
         super(BooleanRequest, self).__init__(
 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):
             validator = InList([True, False, default]))
 
 class BooleanResponse (Response):
@@ -92,8 +98,7 @@ class BooleanResponse (Response):
 
 class StringRequest (Request):
     def __init__(self, msg, default=None):
 
 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):
 
 class StringResponse (Response):
     def __init__(self, value):
@@ -101,8 +106,7 @@ class StringResponse (Response):
 
 class FloatRequest (Request):
     def __init__(self, msg, default=None):
 
 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):
 
 class FloatResponse (Response):
     def __init__(self, value):
@@ -110,8 +114,7 @@ class FloatResponse (Response):
 
 class SelectionRequest (Request):
     def __init__(self, msg, default=None, options=[]):
 
 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):
         self.options = options
 
 class SelectionResponse (Response):
@@ -120,9 +123,9 @@ class SelectionResponse (Response):
 
 class PointRequest (Request):
     def __init__(self, msg, curve, block=0, default=None):
 
 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):
 
 class PointResponse (Response):
     def __init__(self, value):