From 32880031cfba4a22fcae0a0dc1f874de49132351 Mon Sep 17 00:00:00 2001 From: oysteini Date: Sat, 8 May 2010 21:54:58 +0000 Subject: [PATCH] =?UTF-8?q?Begrensning=20av=20antall=20s=C3=B8keresultater?= =?UTF-8?q?=20som=20vises.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- text_based.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/text_based.py b/text_based.py index 1cfbc1f..d679847 100644 --- a/text_based.py +++ b/text_based.py @@ -154,6 +154,10 @@ class Menu(): return self.item_value(item_i) class Selector(Menu): + def __init__(self, name, items=[], prompt='select> ', + return_index=True, exit_msg=None): + Menu.__init__(self, name, items, prompt, return_index, exit_msg) + def print_header(self): print self.name @@ -294,7 +298,7 @@ class ShowUserMenu(Menu): user = self.input_user('User name or card number> ') print 'User name: %s' % user.name print 'Card number: %s' % user.card - print 'Credit: %s' % user.credit + print 'Credit: %s kr' % user.credit self.print_transactions(user) self.pause() @@ -503,8 +507,16 @@ def search_ui2(search_str, result, thing, session): if confirm(msg): return result[0] return None - selector = Selector('%d %ss matching "%s":' % (len(result), thing, search_str), - items=result, + limit = 9 + if len(result) > limit: + select_header = '%d %ss matching "%s"; showing first %d' % \ + (len(result), thing, search_str, limit) + select_items = result[:limit] + else: + select_header = '%d %ss matching "%s"' % \ + (len(result), thing, search_str) + select_items = result + selector = Selector(select_header, items=select_items, return_index=False) return selector.execute()