Fix PointRequest and improve command line handling of selection and point requests.
authorW. Trevor King <wking@drexel.edu>
Tue, 3 Aug 2010 15:04:52 +0000 (11:04 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 3 Aug 2010 15:04:52 +0000 (11:04 -0400)
hooke/interaction.py
hooke/ui/commandline.py

index 35492a79f351a43f21fc5c08eab03c46ed87bb60..f5c39bfd724002fd887cf24465ef3dbfbb8edde5 100644 (file)
@@ -124,7 +124,8 @@ class SelectionResponse (Response):
 class PointRequest (Request):
     def __init__(self, msg, curve, block=0, default=None):
         super(PointRequest, self).__init__('point', msg, default)
-        self.options = options
+        self.curve = curve
+        self.block = block
 
 class PointResponse (Response):
     def __init__(self, value):
index c601ddcc27e9f2bb6568274508503142567bbe7c..132d65785cefa3850a4a9e1cd6e5984d6e427b8e 100644 (file)
@@ -217,12 +217,17 @@ class DoCommand (CommandMethod):
         return msg.msg + d
 
     def _string_request_parser(self, msg, response):
+        response = response.strip()
+        if response == '':
+            return msg.default
         return response.strip()
 
     def _float_request_prompt(self, msg):
         return self._string_request_prompt(msg)
 
     def _float_request_parser(self, msg, resposne):
+        if response.strip() == '':
+            return msg.default
         return float(response)
 
     def _selection_request_prompt(self, msg):
@@ -234,9 +239,29 @@ class DoCommand (CommandMethod):
             prompt = '? '
         else:
             prompt = '? [%d] ' % msg.default
-        return '\n'.join([msg,options,prompt])
+        return '\n'.join([msg.msg,options,prompt])
     
     def _selection_request_parser(self, msg, response):
+        if response.strip() == '':
+            return msg.default
+        return int(response)
+
+    def _point_request_prompt(self, msg):
+        block = msg.curve.data[msg.block]
+        block_info = ('(curve: %s, block: %s, %d points)'
+                      % (msg.curve.name,
+                         block.info['name'],
+                         block.shape[0]))
+
+        if msg.default == None:
+            prompt = '? '
+        else:
+            prompt = '? [%d] ' % msg.default
+        return ' '.join([msg.msg,block_info,prompt])
+    
+    def _point_request_parser(self, msg, response):
+        if response.strip() == '':
+            return msg.default
         return int(response)