Exemple #1
0
 def test_action_is_callback(self):
     km = KeyMap()
     km.bind(key='a',
             action=lambda widget: widget.set_text('foo'))
     widget = km.wrap(Text)('Test Text')
     widget.keypress((80,), 'a')
     self.assertEqual(widget.text, 'foo')
Exemple #2
0
 def test_key_translation(self):
     km = KeyMap()
     km.bind(key='a',
             action=lambda widget: widget.set_text('Key pressed: a'))
     km.bind(key='b', action=Key('a'))
     widget = km.wrap(Text)('Test Text')
     widget.keypress((80,), 'b')
     self.assertEqual(widget.text, 'Key pressed: a')
Exemple #3
0
    def test_default_callback(self):
        def cb(action, widget):
            widget.set_text(action)

        self.km = KeyMap(callback=cb)
        self.km.bind(key='a', action='foo')
        widget = self.km.wrap(urwid.Text)('Test Text')
        widget.keypress((80,), 'a')
        self.assertEqual(widget.text, 'foo')
Exemple #4
0
    def test_widget_callback(self):
        def cb(action, widget):
            widget.set_text(action)

        km = KeyMap()
        km.bind(key='a', action='foo')
        widget = km.wrap(Text, callback=cb)('Test Text')
        widget.keypress((80,), 'a')
        self.assertEqual(widget.text, 'foo')
Exemple #5
0
    def test_widget_callback_overrides_default_callback(self):
        def default_cb(action, widget):
            widget.set_text(action)

        def widget_cb(action, widget):
            widget.set_text(action.upper())

        self.km = KeyMap(callback=default_cb)
        self.km.bind(key='a', action='foo')
        widget = self.km.wrap(urwid.Text, callback=widget_cb)('Test Text')
        widget.keypress((80,), 'a')
        self.assertEqual(widget.text, 'FOO')
Exemple #6
0
    def test_mkkey(self):
        km = KeyMap()
        self.assertEqual(km.mkkey(Key('x')), Key('x'))
        self.assertEqual(km.mkkey(KeyChain('1', '2', '3')),
                                  KeyChain('1', '2', '3'))

        self.assertEqual(km.mkkey('x'), Key('x'))
        self.assertEqual(km.mkkey('x y z'), KeyChain('x', 'y', 'z'))
        self.assertEqual(km.mkkey('x+y+z'), KeyChain('x', 'y', 'z'))
        self.assertEqual(km.mkkey('x +'), KeyChain('x', '+'))
        self.assertEqual(km.mkkey('+ x'), KeyChain('+', 'x'))
        self.assertEqual(km.mkkey('x y +'), KeyChain('x', 'y', '+'))
        self.assertEqual(km.mkkey('+ y z'), KeyChain('+', 'y', 'z'))
        self.assertEqual(km.mkkey('+ + +'), KeyChain('+', '+', '+'))
Exemple #7
0
    def setUp(self):
        self.km = KeyMap(callback=self.handle_action)
        self.km.on_keychain(self.handle_keychain_changed)
        self.last_action = None
        self.action_widget = None
        self.action_counter = 0
        self.active_keychains = set()

        # Create a Pile of two ListBoxes with some Text items
        def mk_item(widgetcls, i, context):
            return self.km.wrap(widgetcls,
                                context=context)('%s: %s' % (context, i))

        self.listw1 = self.km.wrap(urwid.ListBox, context='list1')(
            urwid.SimpleFocusListWalker([
                mk_item(urwid.Text, i, context='item1') for i in range(1, 10)
            ]))
        self.listw2 = self.km.wrap(urwid.ListBox, context='list2')(
            urwid.SimpleFocusListWalker([
                mk_item(urwid.Edit, i, context='item2')
                for i in range(100, 1000, 100)
            ]))
        self.mainw = self.km.wrap(urwid.Pile,
                                  context='main')([self.listw1, self.listw2])

        self.km.bind('A', 'A in main', context='main')
        self.km.bind('B', 'B in main', context='main')
        self.km.bind('1 2 A', '12A in main', context='main')
        self.km.bind('1 2 B', '12B in main', context='main')

        self.km.bind('C', 'C in list1', context='list1')
        self.km.bind('D', 'D in list1', context='list1')
        self.km.bind('2 3 A', '23A in list1', context='list1')
        self.km.bind('2 3 B', '23B in list1', context='list1')

        self.km.bind('C', 'C in list2', context='list2')
        self.km.bind('D', 'D in list2', context='list2')
        self.km.bind('2 3 A', '23A in list2', context='list2')
        self.km.bind('2 3 B', '23B in list2', context='list2')

        self.km.bind('E', 'E in item1', context='item1')
        self.km.bind('F', 'F in item1', context='item1')
        self.km.bind('3 4 A', '34A in item1', context='item1')
        self.km.bind('3 4 B', '34B in item1', context='item1')

        self.km.bind('E', 'E in item2', context='item2')
        self.km.bind('F', 'F in item2', context='item2')
        self.km.bind('3 4 A', '34A in item2', context='item2')
        self.km.bind('3 4 B', '34B in item2', context='item2')
Exemple #8
0
 def setUp(self):
     self.km = KeyMap(callback=self.handle_action)
     self.widget = self.km.wrap(urwid.Edit)('', 'Original Text')
     self.km.on_keychain(self.handle_keychain_changed)
     self._action_counter = 0
Exemple #9
0
 def setUp(self):
     self.km = KeyMap()
Exemple #10
0
 def setUp(self):
     self.keymap = KeyMap()
Exemple #11
0
 def setUp(self):
     self.km = KeyMap(callback=self.handle_action)
     self.widget = self.km.wrap(Text)('Test Text')
     self.widgetA = self.km.wrap(Text, context='A')('Test Text A')
     self.widgetB = self.km.wrap(Text, context='B')('Test Text B')
     self._action_counter = 0