Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output widget custom export #2850

Open
casperdcl opened this issue Apr 15, 2020 · 0 comments
Open

Output widget custom export #2850

casperdcl opened this issue Apr 15, 2020 · 0 comments

Comments

@casperdcl
Copy link
Contributor

casperdcl commented Apr 15, 2020

Trying to make an output context widget exportable to pain-text. Overriding __repr__ doesn't work. Simple example:

# In [1]:
from ipywidgets import Output
from IPython import display as disp

class MyOutput(Output):
    def __init__(self):
        super(Output, self).__init__()
        self.last_display = "Nothing to display yet"
    def __repr__(self):
        return repr(self.last_display)

out1 = MyOutput()
disp.display(out1)  # display in `Out[1]`

# In [2]:
with out1:  # use `Out[1]`
    disp.clear_output(True)
    disp.display("Some text!")

This correctly displays 'Some text!' in Out[1], but when exported shows 'Nothing to display yet'. If __repr__ is not overridden, exported versions just show Output().

Any idea how to create an Output context with manually controlled export repr? Should we be using _repr_mimebundle_ from https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.display or https://ipypublish.readthedocs.io/en/latest/code_cells.html#object-output-formats ? Seems extreme and also doesn't seem to work for an Output context widget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant