Widgets - Autodisplay of widgets on console return
Create a widget in the Positron console, like so:
from ipyleaflet import Map, Marker
center = (52.204793, 360.121558)
m = Map(center=center, zoom=15)
marker = Marker(location=center, draggable=False)
m.add(marker);
m
This will return m, which just prints the object as a string, which is not very useful for widget objects. In Jupyter, if m is a widget type object and the last value in a cell, it will automatically call the display method under the hood display(m) and display the object. In Positron, the user has to explicitly call display(m) in order to view the object in the Plots pane. We should add a hook to automatically call display when the return type for a console chunk of code is isinstance(x, ipywidgets.Widget). We should not call display when the object is assigned to a variable rather than explicitly printed/returned.
Essentially, in the above example, whether the final line is m or display(m), it should behave identically.
I'm surprised we didn't get this for free e.g. our plot hook seems to get called if I do:
import numpy as np, matplotlib.pyplot as plt, pandas as pd
df = pd.DataFrame(np.random.randn(100, 3))
fig, ax = plt.subplots()
df.plot(ax=ax)
and then run just fig.
Would be good to look into the ipython/ipykernel code to see where they do the automatic display so we hook into it at the right level.
Unfortunately, I am seeing:
Error loading renderer 'positron-ipywidgets'
Failed to fetch dynamically imported module: https://file+.vscode-resource.vscode-cdn.net/Applications/Positron.app/Contents/Resources/app/extensions/positron-ipywidgets/renderer/media/index.js
If I check that path:
ls /Applications/Positron.app/Contents/Resources/app/extensions/positron-ipywidgets/renderer/
package.json src tsconfig.json yarn.lock
Verified Fixed
Positron Version(s) : 2024.08.0-24
OS Version : OSX
Test scenario(s)
this only works in the console
from ipyleaflet import Map, Marker center = (52.204793, 360.121558)
m = Map(center=center, zoom=15)
marker = Marker(location=center, draggable=False) m.add(marker);
m
Link(s) to TestRail test cases run or created: N/A