bczsalba / pytermgui

Python TUI framework with mouse support, modular widget system, customizable and rapid terminal markup language and more!
https://ptg.bczsalba.com
MIT License
2.21k stars 54 forks source link

input_field.py: IndexError: list index out of range #72

Closed senyai closed 2 years ago

senyai commented 2 years ago

Let's use example from the README.md

import pytermgui as ptg

with ptg.WindowManager() as manager:
    demo = ptg.Window(
        ptg.Label("[210 bold]Hello world!"),
        ptg.Label(),
        ptg.InputField(prompt="Who are you?"),
        ptg.Label(),
        ptg.Button("Submit!")
    )

    manager.add(demo)
    manager.run()

After running this script with python 3.10.5 and pytermgui 6.4.0 I see this image:

image

which is far off image

After seeing this image, one can write a lot of A into the input box.

image

Then clicking invisible [ Submit! ] button will trigger IndexError:

  File "/home/senyai/projects/pyminimg/cyclops_go.py", line 341, in <module>
    manager.run()
  File "/home/senyai/.local/lib/python3.10/site-packages/pytermgui/window_manager/manager.py", line 197, in run
    self._run_input_loop()
  File "/home/senyai/.local/lib/python3.10/site-packages/pytermgui/window_manager/manager.py", line 143, in _run_input_loop
    self.process_mouse(key)
  File "/home/senyai/.local/lib/python3.10/site-packages/pytermgui/window_manager/manager.py", line 515, in process_mouse
    window.handle_mouse(event)
  File "/home/senyai/.local/lib/python3.10/site-packages/pytermgui/widgets/containers.py", line 796, in handle_mouse
    handled = widget.handle_mouse(event)
  File "/home/senyai/.local/lib/python3.10/site-packages/pytermgui/widgets/input_field.py", line 317, in handle_mouse
    line = self._lines[y_offset]
IndexError: list index out of range

I tried gnome-terminal and alacritty which gave me same error and visuals. Hope it help.

bczsalba commented 2 years ago

Hey there! Sorry about the long delay, had some things life to handle and I got a bit wrapped up in the new TIM implementation.

The IndexError issue is something I've run into but I haven't isolated before this issue. It should be relatively easy to fix. The inaccuracy in the README stems from me forgetting to implement a prompt parameter into the new InputField, which once again will be fixed relatively soon.

This work is planned after the next release at the moment, but it might come before if things work out differently. The tim-v3 branch has gotten very large in terms of API changes and new functionality, so it makes things easier if I focus on that area for now.

bczsalba commented 2 years ago

Should be fixed now! Could you please confirm it works on the latest commit?

P.S. Thank you for the code example, it made debugging way easier!

senyai commented 2 years ago

Back from vacation. pytermgui is uninstallable (in fedora):

python -m pip install pytermgui -U
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pytermgui in /home/senyai/.local/lib/python3.10/site-packages (6.4.0)
Collecting pytermgui
  Using cached PyTermGUI-7.1.0.tar.gz (18.4 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
  WARNING: Generating metadata for package pytermgui produced metadata for project name unknown. Fix your #egg=pytermgui fragments.
WARNING: Discarding https://files.pythonhosted.org/packages/97/45/53ea7da6c280c6555671c34dbf289c14444bf3741b5b3ee0a08ec546824e/PyTermGUI-7.1.0.tar.gz#sha256=1bd01209d5ed223748b704d5cddef404d10744125dbdfc63f06d17589d547ba6 (from https://pypi.org/simple/pytermgui/) (requires-python:>=3.8). Requested unknown from https://files.pythonhosted.org/packages/97/45/53ea7da6c280c6555671c34dbf289c14444bf3741b5b3ee0a08ec546824e/PyTermGUI-7.1.0.tar.gz#sha256=1bd01209d5ed223748b704d5cddef404d10744125dbdfc63f06d17589d547ba6 has inconsistent name: filename has 'pytermgui', but metadata has 'unknown'
  Using cached PyTermGUI-7.0.0.tar.gz (18.4 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
  WARNING: Generating metadata for package pytermgui produced metadata for project name unknown. Fix your #egg=pytermgui fragments.
WARNING: Discarding https://files.pythonhosted.org/packages/2e/22/0f3f99568aabec709154e7061111257e664bf4fcae49d32162c2d7bbf808/PyTermGUI-7.0.0.tar.gz#sha256=ef7fd086694cb108eb5bea5475d58a35bc9df22d0802c032d6b5d1fccc8febc8 (from https://pypi.org/simple/pytermgui/) (requires-python:>=3.8). Requested unknown from https://files.pythonhosted.org/packages/2e/22/0f3f99568aabec709154e7061111257e664bf4fcae49d32162c2d7bbf808/PyTermGUI-7.0.0.tar.gz#sha256=ef7fd086694cb108eb5bea5475d58a35bc9df22d0802c032d6b5d1fccc8febc8 has inconsistent name: filename has 'pytermgui', but metadata has 'unknown'
bczsalba commented 2 years ago

That's super odd. What version of pip are you using?

senyai commented 2 years ago

It's 21.3.1 in fedora. I tried pip 22.2 but nothing changed. I've never seen an error like this.

bczsalba commented 2 years ago

Have you tried running pip cache purge before installation? Maybe something got corrupted on the way.

senyai commented 2 years ago

No. Will try tomorrow.

senyai commented 2 years ago

Nope image I was able to install latest PyTermGUI on Ubuntu machine and there's no IndexError there. Let's leave Fix your #egg=pytermgui fragments till someone else encounters it, might be something Fedora specific.

bczsalba commented 2 years ago

I haven't seen it either, but it likely is something to do with the new build system. I have a change reversal (going from PyTermGUI -> pytermgui for the package [not module] name) that might target it, so if it's okay with you I might ping you here when that is released.

Thanks for (both) report(s)!

senyai commented 2 years ago

It worked!

python -m pip install PyTermGUI --user
Collecting PyTermGUI
  Downloading pytermgui-7.2.0-py3-none-any.whl (172 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 172.7/172.7 kB 2.6 MB/s eta 0:00:00
Requirement already satisfied: typing-extensions in /usr/lib/python3.10/site-packages (from PyTermGUI) (3.10.0.2)
Installing collected packages: PyTermGUI
Successfully installed PyTermGUI-7.2.0

[notice] A new release of pip available: 22.2 -> 22.2.2
[notice] To update, run: python -m pip install --upgrade pip
bczsalba commented 2 years ago

Nice! Something was wring with the setuptools way of building from pyproject.toml, but Hatch seems to have fixed that.