S
Solara•2y ago
Tao

Thanks how could I programatically set

Thanks ! how could I programatically set theme from Python side ?
1 Reply
MaartenBreddels
MaartenBreddels•2y ago
ok, this is going to be messy 🙂 I suggest you open an issue or discussions so we can iron some of this.. i'm gonna give you the code, since i just arrived at a new location, and don't have much time if you have questions, i can take another look tomorrow or the day after, or @mariobuikhuizen can fill in
import ipyvuetify.Themes as themes

import solara
from solara.components.non_visual import NonVisual

dark = solara.reactive(False)

try:
# the default ctor gets in the way, we should fix
# this in ipyvuetify
del themes.Theme.__init__
except AttributeError:
pass


@solara.component
def Page():

with solara.AppBar():
solara.Button(icon_name="mdi-palette", icon=True, dark=True)
solara.Checkbox(label="Dark", value=dark)
# solara.ColorPicker()
with solara.Column():
solara.Info("This in information")
solara.Warning("This is a warning")
solara.Button("This is a button", color="primary")
with NonVisual():
# inside NonVisual we can create non-dom widget elements
themes.Theme.element(dark=dark.value)
themes.ThemeColors.element(
_theme_name="light",
primary="#f00",
secondary="#424242",
accent="#82B1FF",
error="#FF5252",
info="#2196F3",
success="#4CAF50",
warning="#FB8C00",
)
import ipyvuetify.Themes as themes

import solara
from solara.components.non_visual import NonVisual

dark = solara.reactive(False)

try:
# the default ctor gets in the way, we should fix
# this in ipyvuetify
del themes.Theme.__init__
except AttributeError:
pass


@solara.component
def Page():

with solara.AppBar():
solara.Button(icon_name="mdi-palette", icon=True, dark=True)
solara.Checkbox(label="Dark", value=dark)
# solara.ColorPicker()
with solara.Column():
solara.Info("This in information")
solara.Warning("This is a warning")
solara.Button("This is a button", color="primary")
with NonVisual():
# inside NonVisual we can create non-dom widget elements
themes.Theme.element(dark=dark.value)
themes.ThemeColors.element(
_theme_name="light",
primary="#f00",
secondary="#424242",
accent="#82B1FF",
error="#FF5252",
info="#2196F3",
success="#4CAF50",
warning="#FB8C00",
)
this needs NonVisual.. which is
from typing import Callable, Dict, Optional, Tuple, cast

import ipyvuetify as vy
import ipywidgets as widgets
import reacton.core
import traitlets

import solara
import solara.lab


class NonVisualWidget(vy.VuetifyTemplate):
template_file = (__file__, "non_visual.vue")
children = traitlets.List().tag(sync=True, **widgets.widget_serialization)


@solara.component
def NonVisual(children: reacton.core.Element = []):
return NonVisualWidget.element(children=children)
from typing import Callable, Dict, Optional, Tuple, cast

import ipyvuetify as vy
import ipywidgets as widgets
import reacton.core
import traitlets

import solara
import solara.lab


class NonVisualWidget(vy.VuetifyTemplate):
template_file = (__file__, "non_visual.vue")
children = traitlets.List().tag(sync=True, **widgets.widget_serialization)


@solara.component
def NonVisual(children: reacton.core.Element = []):
return NonVisualWidget.element(children=children)
<template>
<span style="display: none"></span>
</template>
<template>
<span style="display: none"></span>
</template>
(last file is non_visual.vue) quick and dirty, but it works
Want results from more Discord servers?
Add your server