Skip to content

Reconnect the 'modified' signal after setting a new ListBox.body - #474

Merged
penguinolog merged 1 commit into
urwid:masterfrom
exquo:listbox-set-body
Mar 29, 2023
Merged

penguinolog merged 1 commit into
urwid:masterfrom
exquo:listbox-set-body

Conversation

@exquo

@exquo exquo commented Apr 20, 2021

Copy link
Copy Markdown
Contributor

Ensure that the cached canvas is marked invalidated when a newly set ListBox.body is modified at runtime.

Fixes #428

Checklist
  • I've ensured that similar functionality has not already been implemented
  • I've ensured that similar functionality has not earlier been proposed and declined
  • I've branched off the master or python-dual-support branch
  • I've merged fresh upstream into my branch recently
  • I've ran tox successfully in local environment
  • I've included docstrings and/or documentation and/or examples for my code (if this is a new feature)
Description:

Currently, ListBox listens to modified events from the ListWalker set as its body only on initialization. If a new ListWalker is assigned to ListBox.body later, the signals from it would be ignored.

Ensure that the cached canvas is marked invalidated when a newly set ListBox.body is modified at runtime.

Fixes urwid#428


class ListBoxSetBodyTest(unittest.TestCase):
def test_signal_connected(self):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit more paranoid validation can be used, but current is already validating issue fix

class ListBoxSetBodyTest(unittest.TestCase):
    def test_signal_connected(self):
        lb = urwid.ListBox([])
        modified_callbacks = lb.body._urwid_signals['modified']
        self.assertEqual(1, len(modified_callbacks))
        callback = modified_callbacks[0][1]
        self.assertEqual(lb._invalidate, callback, "Initial callback was not assigned")

        lb.body = urwid.SimpleListWalker([])
        new_modified_callbacks = lb.body._urwid_signals['modified']
        self.assertEqual(1, len(new_modified_callbacks), "Unexpected amount of callbacks for new body")
        new_callback = new_modified_callbacks[0][1]
        self.assertEqual(lb._invalidate, new_callback, "Callback was not updated")

        self.assertEqual(callback, new_callback)

@penguinolog
penguinolog merged commit ab23c8b into urwid:master Mar 29, 2023
@exquo

exquo commented Apr 2, 2023

Copy link
Copy Markdown
Contributor Author

🎉

@exquo
exquo deleted the listbox-set-body branch April 2, 2023 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After ListBox._set_body(): ListBox is not updated when body is modified

2 participants