From: W. Trevor King Date: Tue, 3 Aug 2010 15:04:52 +0000 (-0400) Subject: Fix PointRequest and improve command line handling of selection and point requests. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ca8b1f45e3e1f6a6183ceb0165ee61b71f6fe66c;p=hooke.git Fix PointRequest and improve command line handling of selection and point requests. --- 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)