euporie: Exception 'TextArea' object has no attribute 'preferred_width'

Trying to use the inline plotting, I’m using kitty.

Here’s the code:

% matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()

This will immediately exit to the terminal and print the following strace

  File "/Users/yingzhu/miniconda3/envs/python38/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 716, in write_to_screen
    c.write_to_screen(
  File "/Users/yingzhu/miniconda3/envs/python38/lib/python3.8/site-packages/euporie/scroll.py", line 115, in write_to_screen
    self.to_draw = self.arrange_children(write_position)
  File "/Users/yingzhu/miniconda3/envs/python38/lib/python3.8/site-packages/euporie/scroll.py", line 426, in arrange_children
    size = self.get_child_size(i, refresh=True)
  File "/Users/yingzhu/miniconda3/envs/python38/lib/python3.8/site-packages/euporie/scroll.py", line 392, in get_child_size
    size = container.preferred_height(
  File "/Users/yingzhu/miniconda3/envs/python38/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 795, in preferred_height
    return self.content.preferred_height(width, max_available_height)
  File "/Users/yingzhu/miniconda3/envs/python38/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 325, in preferred_height
    dimensions = [
  File "/Users/yingzhu/miniconda3/envs/python38/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 326, in <listcomp>
    c.preferred_height(width, max_available_height) for c in self._all_children
  File "/Users/yingzhu/miniconda3/envs/python38/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 2625, in preferred_height
    return self.content.preferred_height(width, max_available_height)
  File "/Users/yingzhu/miniconda3/envs/python38/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 571, in preferred_height
    sizes = self._divide_widths(width)
  File "/Users/yingzhu/miniconda3/envs/python38/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 632, in _divide_widths
    dimensions = [c.preferred_width(width) for c in children]
  File "/Users/yingzhu/miniconda3/envs/python38/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 632, in <listcomp>
    dimensions = [c.preferred_width(width) for c in children]
  File "/Users/yingzhu/miniconda3/envs/python38/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 316, in preferred_width
    dimensions = [c.preferred_width(max_available_width) for c in self.children]
  File "/Users/yingzhu/miniconda3/envs/python38/lib/python3.8/site-packages/prompt_toolkit/layout/containers.py", line 316, in <listcomp>
    dimensions = [c.preferred_width(max_available_width) for c in self.children]
  File "/Users/yingzhu/miniconda3/envs/python38/lib/python3.8/site-packages/euporie/output.py", line 124, in preferred_width
    return self.content.preferred_width(*args, **kwargs)

Exception 'TextArea' object has no attribute 'preferred_width'

Some setup info:

❯ kitty --version
kitty 0.19.3 created by Kovid Goyal
❯ pip list | rg prompt-toolkit
prompt-toolkit                3.0.18
❯ pip list | rg matplot
matplotlib                    3.4.2
matplotlib-inline             0.1.2
❯ uname -a
Darwin MacBook-Air-4 20.3.0 Darwin Kernel Version 20.3.0: Mon Dec  7 22:03:58 PST 2020; root:xnu-7195.80.16.111.1~1/RELEASE_ARM64_T8101 arm64
❯ pip list | rg euporie
euporie                       0.1.9
❯ pip list | rg ipython
ipython                       7.16.0
ipython-genutils              0.2.0
ptipython                     1.0.1
❯ python --version
Python 3.8.6

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 23 (8 by maintainers)

Most upvoted comments

The “colinear!” text you are seeing is OS-level standard error output from the kernel (reportlab prints directly to stderr in it’s c-extensions - see here).

The same thing happens with JupyterLab - output is printed to the terminal where the kernel was started rather than being displayed in the notebook:

image

There is an old IPython issue about this I remember from years ago: https://github.com/ipython/ipython/issues/1230

The issue mentions a nice IPython extension wurlitzer you can use to work around this:

image

Interesting. Feels like we’re getting closer!

The kitty graphics protocol allows you to do more complex things with images then sixel graphics, such as hide & show, duplicate, and move images. Currently I’m not making full use of it’s capabilities - I’m just clearing all images from a notebook and re-drawing them every time the display is drawn.

I’m already aware of some issues with with the way I implemented this (one is that images are cleared per notebook, which means that if you have multiple notebooks, only the images from one notebook will be displayed). I suspect the problem you are having may be related.

Rewriting the euporie’s kitty graphics code so images are shown, hidden, and moved without re-drawing them is on my to-do list.