jwlodek / py_cui

A python library for intuitively creating CUI/TUI interfaces with widgets, inspired by gocui.
https://jwlodek.github.io/py_cui-docs
BSD 3-Clause "New" or "Revised" License
759 stars 42 forks source link

Error when running .clear() on text_block #174

Closed SnakesAndLadders closed 2 years ago

SnakesAndLadders commented 2 years ago

When a text block is scrolled past the first page of text and then a .clear() is run on that widget you get a 'list index out of range' error.

To Reproduce Steps to reproduce the behavior:

  1. Create a text_block widget
  2. Write more than one 'page' of text that requires scrolling to move to the bottom
  3. try to move to another widget and run a .clear() on the text_block

Output

Traceback (most recent call last):  
  File "newsfeeds.py", line 143, in <module>  
    root.start()  
  File "/usr/local/lib/python3.7/site-packages/py_cui/__init__.py", line 316, in start  
    curses.wrapper(self._draw)  
  File "/usr/local/Cellar/python@3.7/3.7.12_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/curses/__init__.py", line 102, in wrapper  
    return func(stdscr, *args, **kwds)  
  File "/usr/local/lib/python3.7/site-packages/py_cui/__init__.py", line 1689, in _draw  
    self._draw_widgets()  
  File "/usr/local/lib/python3.7/site-packages/py_cui/__init__.py", line 1465, in _draw_widgets  
    widget._draw()  
  File "/usr/local/lib/python3.7/site-packages/py_cui/widgets.py", line 933, in _draw  
    render_text = self._text_lines[line_counter]  
IndexError: list index out of range  

Expected behavior The text_block should be cleared of contents.

*Environment:*

msr8 commented 2 years ago

Happening the same with me

Version Info

OS: MacOS 10.15.2 Library Version: py-cui==0.1.4 Python Version: Python 3.9.6

EDIT: Fixed it by using text_block.set_text('') instead of text_block.clear()

SnakesAndLadders commented 2 years ago

Yes that is how I got around the issue as well. It is a an effective work-around.

jwlodek commented 2 years ago

Thanks for the report! I believe I have fixed this with: 9084422ab44793e77a39e97840c84b96d76526f6. The fix will be included in the next release of the library