Пример #1
0
 def test_options(self):
     menu = Menu([
             Option('le first caption', callback=lambda: 7),
             Option('le second caption', value=18),
             Option('le third caption'),
         ])
     with override_readline('1'):
         self.assertEqual(menu.select(), 7)
     with override_readline('2'):
         self.assertEqual(menu.select(), 18)
     with override_readline('3'):
         self.assertIsNone(menu.select())
Пример #2
0
 def test_invalid(self):
     def callback():
         callback.called = True
     callback.called = False
     menu = Menu([
             Option('le caption', callback=callback),
             Option('le exit', value=42),
             Option('le other caption', callback=callback),
         ])
     with override_readline(('0', '-2', '2')):
         self.assertEqual(menu.select(), 42)
         self.assertFalse(callback.called)
     with override_readline(('6', '4', '2')):
         self.assertEqual(menu.select(), 42)
         self.assertFalse(callback.called)
Пример #3
0
def search_user():
    print "Searching for an existing person"
    name = raw_input("  Name pattern: ")
    if not name:
        print "Invalid name, aborting"

    session = Session()
    results = (
            session.query(models.Person)
                    .filter(models.Person.name.like(name))
                    .all())

    menu = Menu(
            [Option("%s" % p.name, value=i)
             for i, p in enumerate(results)] +
            [Option("Abort", value='exit')])
    choice = menu.select()
    if choice == 'exit':
        return
    edit_user(results[choice])