From 6b6e287b58c34cb52fb082c0cbd8204c250a6cf5 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 3 Aug 2010 11:04:52 -0400 Subject: [PATCH] Fix PointRequest and improve command line handling of selection and point requests. --- hooke/interaction.py | 3 ++- hooke/ui/commandline.py | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/hooke/interaction.py b/hooke/interaction.py index 35492a7..f5c39bf 100644 --- a/hooke/interaction.py +++ b/hooke/interaction.py @@ -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): diff --git a/hooke/ui/commandline.py b/hooke/ui/commandline.py index c601ddc..132d657 100644 --- a/hooke/ui/commandline.py +++ b/hooke/ui/commandline.py @@ -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) -- 2.26.2