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

Add support for theming of IPyWidgets #7161

Open
rebornix opened this issue Aug 16, 2021 · 22 comments
Open

Add support for theming of IPyWidgets #7161

rebornix opened this issue Aug 16, 2021 · 22 comments
Assignees
Labels
feature-request Request for new features or functionality ipywidgets Rendering, loading, saving, anything to do with IPyWidgets
Milestone

Comments

@rebornix
Copy link
Member

Environment data

  • VS Code version: 1.60-Insiders
  • Jupyter Extension version (available under the Extensions sidebar): 2021.8.2027072902

image

@rebornix rebornix added the bug Issue identified by VS Code Team member as probable bug label Aug 16, 2021
@DavidKutu DavidKutu added the ipywidgets Rendering, loading, saving, anything to do with IPyWidgets label Aug 16, 2021
@DonJayamanne
Copy link
Contributor

DonJayamanne commented Aug 18, 2021

We hardcode the background, as IPYWidgets doesn't understand VS Code themes.
& it defaults to white backgrounds in jupyter & jupyter lab,
If we want to fix this, we need to get our support of ipywidgets to understand vscode themes (fonts, etc).

Changing to a feature requiest.

@DonJayamanne DonJayamanne added enhancement and removed bug Issue identified by VS Code Team member as probable bug labels Aug 18, 2021
@UncleHoo

This comment was marked as resolved.

@DonJayamanne

This comment was marked as resolved.

@martinRenou
Copy link

I believe this can be achieved by making a bridge from the vscode theme (CSS variables?) to the jupyterlab theme.

ipywidgets (and other libraries for Jupyter) use the JupyterLab CSS variables for respecting the theme.

It might just be a matter of defining the needed CSS variables using the current VSCode theme.

@chandradharkoneti

This comment was marked as resolved.

@DonJayamanne

This comment was marked as resolved.

@DonJayamanne

This comment was marked as resolved.

@chandradharkoneti
Copy link

For anyone interested:
I have found a hacky sacky solution.

Make sure VS Code is closed(at least no jupyter related things should be running on it[ I personally closed it completely and reopened it for editing the below file]).

Open file explorer, go to:

C:\Users\<your_username_here>\.vscode\extensions\ms-toolsai.jupyter-2022.4.1021342353\out\webviews\webview-side\ipywidgetsRenderer

Open the ipywidgetsRenderer.js file (using notepad++ or notepad or even VSCode(before letting any jupyter stuff run)) and

wherever you see cell-output-ipywidget-background followed by background: white, replace white with black.

Now the problem is solved. Enjoy :)

@DonJayamanne DonJayamanne changed the title ipywidget background doesn't respect theme Add support for theming of IPyWidgets Oct 2, 2022
@yusisc
Copy link

yusisc commented Nov 15, 2022

@chandradharkoneti
This method works good. But, the text color of additional information is black, too.
Is there a way to make the texts be brighter ?

2022-11-15_235300

@starball5
Copy link

Related Stack Overflow question: How can I get rid of or recolour the background of ipywidgets frames in a Jupyter Notebook in VS Code?

Other issue tickets that look related: #10609 and #9403

@npulidomateo
Copy link

wherever you see cell-output-ipywidget-background followed by background: white, replace white with black.

tansparent also works. Nice if you like to change to a light color scheme in less dark situations.

@kylemcdonald
Copy link

@chandradharkoneti This method works good. But, the text color of additional information is black, too. Is there a way to make the texts be brighter ?

Here is a hack for making the print statements readable:

css_widget = widgets.HTML("""
<style>
.cell-output-ipywidget-background {
   background-color: transparent !important;
}
.cell-output-ipywidget-background pre {
   color: white !important;
}
</style>
""")
display(css_widget)

@Shisoik
Copy link

Shisoik commented Jul 2, 2023

I added following HTML cell that makes background transparent and binds widgets' foreground text colour and size to that of the active VSCode editor theme.

%%html
<style>
.cell-output-ipywidget-background {
    background-color: transparent !important;
}
:root {
    --jp-widgets-color: var(--vscode-editor-foreground);
    --jp-widgets-font-size: var(--vscode-editor-font-size);
}  
</style>

@tianfanghan
Copy link

Is there a way to just get rid of the frame it self? Just set margin or padding or box to zero?

@alex180500
Copy link

Is there a way to just get rid of the frame it self? Just set margin or padding or box to zero?

Yes I would really like this!

@Jnorm911
Copy link

Jnorm911 commented Mar 1, 2024

bump.

@flying-sheep
Copy link

flying-sheep commented Jul 5, 2024

I think the jupyter team should define some mandatory CSS variables that are to be defined in any frontend, including Jupyter Lab, VS Code, and the output of HTML conversion scripts (e.g. nbconvert, MyST-nb)

@martinRenou
Copy link

It's actually already defined. ipywidgets requires the same CSS variables as a JupyterLab theme would provide.

Note that ipywidgets provides a set of default values for when there is no JupyterLab theme available in the page: https://github.com/jupyter-widgets/ipywidgets/blob/main/packages/controls/css/labvariables.css. The VSCode jupyter extension should make a bridge between the current VSCode theme and the Lab variables.

@flying-sheep
Copy link

I see, so this is really just a missing feature in this extension.

The extension should define all these variables similar to how it’s done in this: #7161 (comment)

@alimantu
Copy link

alimantu commented Nov 6, 2024

I would love to see this one available in a newer version.

@DonJayamanne, how can I support this feature so it goes into development?

@bjornasm
Copy link

Is there any progress here?

github-merge-queue bot pushed a commit to microsoft/qsharp that referenced this issue Jan 22, 2025
…ark theme (#2120)

(See related issues
microsoft/vscode-jupyter#7161 and
microsoft/vscode-jupyter#9403 for more
background)

Our CSS override to address the widget theming issue wasn't working
somtimes, which was very frustrating, as in Dark Mode our widgets would
often appear as they should in light mode.

The reason is that the order in which the style sheets get injected is
non-deterministic, and as the 'problematic' CSS rule and the override to
fix it have the same specificity, it would be 'last one wins'. Sometimes
our style-sheet is last and it works...

<img width="955" alt="image"
src="https://github.com/user-attachments/assets/281524d8-a3d5-4d15-a649-442a21b5ddec"
/>

And sometimes the IPyWidgets 'force it to white' rule is last so the
issue persists...

<img width="960" alt="image"
src="https://github.com/user-attachments/assets/f60f762e-0312-49de-9a2d-6f3cf4833b20"
/>

The unfortunate best _hack_ I could come up with is to programmatically
ensure the override CSS rule is always last in the `style`s in the
header.

Not pretty, but it works.
idavis pushed a commit to microsoft/qsharp that referenced this issue Feb 2, 2025
…ark theme (#2120)

(See related issues
microsoft/vscode-jupyter#7161 and
microsoft/vscode-jupyter#9403 for more
background)

Our CSS override to address the widget theming issue wasn't working
somtimes, which was very frustrating, as in Dark Mode our widgets would
often appear as they should in light mode.

The reason is that the order in which the style sheets get injected is
non-deterministic, and as the 'problematic' CSS rule and the override to
fix it have the same specificity, it would be 'last one wins'. Sometimes
our style-sheet is last and it works...

<img width="955" alt="image"
src="https://github.com/user-attachments/assets/281524d8-a3d5-4d15-a649-442a21b5ddec"
/>

And sometimes the IPyWidgets 'force it to white' rule is last so the
issue persists...

<img width="960" alt="image"
src="https://github.com/user-attachments/assets/f60f762e-0312-49de-9a2d-6f3cf4833b20"
/>

The unfortunate best _hack_ I could come up with is to programmatically
ensure the override CSS rule is always last in the `style`s in the
header.

Not pretty, but it works.
@kevinjohncutler
Copy link

Would love to see this too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality ipywidgets Rendering, loading, saving, anything to do with IPyWidgets
Projects
None yet
Development

No branches or pull requests