peterbrittain / asciimatics

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations
Apache License 2.0
3.62k stars 237 forks source link

KeyError while trying to run `samples/images.py` #319

Closed pritam-dey3 closed 3 years ago

pritam-dey3 commented 3 years ago
Traceback (most recent call last):
  File "ascii.py", line 47, in <module>
    Screen.wrapper(demo)
  File "E:\programms\python\python_code_jam\experiments\venv\lib\site-packages\asciimatics\screen.py", line 1395, in wrapper
    return func(screen)
  File "ascii.py", line 41, in demo
    screen.play(scenes, stop_on_resize=True)
  File "E:\programms\python\python_code_jam\experiments\venv\lib\site-packages\asciimatics\screen.py", line 1566, in play
    self.draw_next_frame(repeat=repeat)
  File "E:\programms\python\python_code_jam\experiments\venv\lib\site-packages\asciimatics\screen.py", line 1679, in draw_next_frame
    self.refresh()
  File "E:\programms\python\python_code_jam\experiments\venv\lib\site-packages\asciimatics\screen.py", line 1427, in refresh
    self._change_colours(new_cell[1], new_cell[2], new_cell[3])
  File "E:\programms\python\python_code_jam\experiments\venv\lib\site-packages\asciimatics\screen.py", line 2137, in _change_colours
    self._COLOURS[colour] + self._BG_COLOURS[bg])
KeyError: 16

This error is occurring both for python.png and grumpy_cat.jpg

To Reproduce Run samples/images.py

System details (please complete the following information):

peterbrittain commented 3 years ago

Works fine for me... I suspect that this is something to do with your Python installation. What are you running and how did you get it?

peterbrittain commented 3 years ago

Thinking about it some more... You are clearly using a Windows system based on the code in the stack trace, but to hit that error, something must have erroneously passed in the wrong number of supported colours to the renderers.

Are you running with the sample and asciimatics code completely unchanged, or have you made some tweaks for your ascii.py application?

pritam-dey3 commented 3 years ago

I just copy pasted the code. I did try to remove parts of it after getting error. The only thing changed is black formatting the code maybe. I am using python 3.8.6 in a virtual environment and windows terminal.

peterbrittain commented 3 years ago

Well... Something's not right here. The Windows Screen only ever sets colours to 8, so it won't ever use colour 16. Can you show me your changes please?

peterbrittain commented 3 years ago

Can you also try running this code?

from asciimatics.screen import Screen

screen = Screen.open()
screen.close()

print(type(screen))
print(screen.colours)
peterbrittain commented 3 years ago

Any progress? I assume silence means it's working now... Will close in a few days if there's no update.

peterbrittain commented 3 years ago

I'm assuming this fixed it, so am closing. Feel free to get back in touch if you still have a problem.