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

Basic widget button to display text on press does not work #1994

Closed
IanMatthewHuff opened this issue Apr 17, 2020 · 9 comments
Closed

Basic widget button to display text on press does not work #1994

IanMatthewHuff opened this issue Apr 17, 2020 · 9 comments
Assignees

Comments

@IanMatthewHuff
Copy link
Member

btn = widgets.Button(description='Medium')
display(btn)
def btn_eventhandler(obj):
print('Hello from the {} button!'.format(obj.description))
btn.on_click(btn_eventhandler)

image

In VSCode pressing the button does nothing.

image

@greazer
Copy link
Member

greazer commented Apr 17, 2020

Another example

from ipywidgets import widgets
lbl1 = widgets.Label('')
display(lbl1)
txt1 = widgets.Text()
txt1

Note that the label will not display unless it's not empty.

@rchiodo
Copy link
Contributor

rchiodo commented Apr 18, 2020

Root cause is how output is wrapped in jupyter. We don't do this wrapping.

Essentially all io_pub messages are routed to an output wrapper during widget creation.

In this code here (inside the widget manager that jupyter has):

setViewOptions(options) {
        var options = options || {};
        if (!options.output && options.parent) {
            // use the parent output if we don't have one
            options.output = options.parent.options.output;
        }
        if (options.output) {
            options.iopub_callbacks = {
                output: options.output.handle_output.bind(options.output),
                clear_output: options.output.handle_clear_output.bind(options.output)
            }
        }
        return options;
    };

We might be able to do something similar were we remap all output etc to a custom output widget we stick below everything else?

@jasongrout
Copy link

jasongrout commented Apr 20, 2020

Note that classic Notebook and JupyterLab handle this differently. When a widget view generates a comm message that causes output:

  • classic Jupyter Notebook appends the output to the output of the cell which contained the view
  • JupyterLab logs the output in its log console (new in JupyterLab 1.2)

There has been quite a bit of discussion about these behaviors: jupyter-widgets/ipywidgets#2380, sagemathinc/cocalc#3854

@rchiodo
Copy link
Contributor

rchiodo commented Apr 20, 2020

Thanks @jasongrout, I'm thinking we'll probably not fix this before we ship.

@jasongrout
Copy link

jasongrout commented Apr 20, 2020

Until JupyterLab 1.2, we silently discarded such output messages, and we had lots of complaints. One particular problem is that it discards not only print messages, but also error messages, so debugging a callback that throws an error becomes hard.

A workaround for users is to use an Output widget to capture output.

@jasongrout
Copy link

jasongrout commented Apr 20, 2020

I thought vscode had logging capabilities already built in? It may be useful to surface uncaptured output somewhere so the user at least sees error messages, etc. For example, here is where we send them to the jlab log console: https://github.com/jupyter-widgets/ipywidgets/blob/master/packages/jupyterlab-manager/src/plugin.ts#L181-L199

@rchiodo
Copy link
Contributor

rchiodo commented Apr 20, 2020

Thanks. That would likely be a good workaround for now. We do log a lot of stuff to our developer console though. We'd likely have to put this somewhere else.

I'm thinking the 'jupyter' output tab might be a good spot.

@rchiodo rchiodo self-assigned this Apr 21, 2020
@IanMatthewHuff
Copy link
Member Author

@rchiodo Should this be validated? I validated the workaround here. But that's just a workaround. Are we ever looking at supporting this? Or should I just close the item?
image.png

@rchiodo
Copy link
Contributor

rchiodo commented Apr 24, 2020

Yeah that was our decision. We can't fix this without doing the same thing jupyter notebooks do. Jupyter labs is not going to support this either.

@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2020
@microsoft microsoft unlocked this conversation Nov 13, 2020
@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Nov 13, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants