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: self.get_widgets()[next_widget_num] is None #161

Closed voryzen closed 2 years ago

voryzen commented 2 years ago

Updated to v0.1.4

Shifting focus through widgets, first cycle is fine, however py_cui program crashes and returns this error upon the second cycle.

self.get_widgets()[next_widget_num] is None.

Terminal shows this after crash

 File "/usr/lib/python3.9/site-packages/py_cui/__init__.py", line 316, in start
    curses.wrapper(self._draw)
  File "/usr/lib/python3.9/curses/__init__.py", line 94, in wrapper
    return func(stdscr, *args, **kwds)
  File "/usr/lib/python3.9/site-packages/py_cui/__init__.py", line 1679, in _draw
    self._cycle_widgets()
  File "/usr/lib/python3.9/site-packages/py_cui/__init__.py", line 1123, in _cycle_widgets
    if self.get_widgets()[next_widget_num] is None:

Any ideas? @PabloLec

PabloLec commented 2 years ago

I can't reproduce this behavior. Using v0.1.4 I can use the example scripts without any exception.

Could you also paste the error type? You just provided the traceback. And do you have any code to be tested? In order to reproduce the error.

voryzen commented 2 years ago

the only error output I get is: KeyError: 5

I am getting this error, when I run my own local program that I'm building with py_cui.

Its local code, not a program installed with pip

I set a cycle widget key in my program, maybe that's where it is coming from. aka. root.set_widget_cycle_key(forward_cycle_key=py_cui.keys.KEY_TAB, reverse_cycle_key=None)

PabloLec commented 2 years ago

Ok, root.set_widget_cycle_key(forward_cycle_key=py_cui.keys.KEY_TAB, reverse_cycle_key=None) helped me to reproduce the behavior. That was indeed a bug, just pushed a PR to fix it :wink:

voryzen commented 2 years ago

Awesome @PabloLec Terrific work

Does this fix #121 ?

PabloLec commented 2 years ago

Awesome @PabloLec Terrific work

Does this fix #121 ?

Yes indeed! I didn't see that issue. Good call, I'll add it in the PR.

voryzen commented 2 years ago

Thanks.

What about #116 ?

It may not be fixed, but it's certainly related

PabloLec commented 2 years ago

Thanks.

What about #116 ?

It may not be fixed, but it certainly related

Not this one :smile: This one should be closed by the way as it was resolved by #125 When cycling through widgets, status_bar get refreshed at some point which is expected behavior. Here, the user set status_bar to None in order to hide it. That caused an exception obviously.

125 introduced two new methods for status_bar, .show() and .hide() which will avoid the need to unset it. So now I guess raising an exception when status_bar is None is acceptable as there is no reason it should be.

voryzen commented 2 years ago

Ahh, right. Thanks for the info. It is helpful; I haven't coded with python before now

PabloLec commented 2 years ago

Great to begin with a TUI :smiley: I also created my first open-source Python project that way.

voryzen commented 2 years ago

That's cool.

I'm almost finished my first iteration with this project. I just need to work out how to 'turn off' the CUI temporarily, and I'll be able to finish it and push.

I won't say much more here, I'm trying not to hijack the thread