A simple overlay / splash page #2994
BlankAdventure
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
This is really cool! If we tweak it then additonal settings can be customized and you can then use it more like the other Nice GUI elements where you can nest from nicegui import ui, app
from typing import Optional
from nicegui.elements.timer import Timer
from nicegui.element import Element
class Overlay(Element):
def __init__(self,
time_out: Optional[float] = None,
click_close: bool = True,
color: Optional[str] = 'black',
) -> None:
self.time_out = time_out
super().__init__(tag='div')
self.classes(f'fixed block w-full h-full z-10 inset-0 cursor-pointer bg-{color} opacity-60')
self.hide()
if click_close:
self.on('click', handler=lambda: self.hide())
def show(self):
print('showing')
self.set_visibility(True)
if self.time_out is not None:
Timer(self.time_out, callback=lambda: self.hide(), once=True)
def hide(self):
self.set_visibility(False)
@ui.page('/')
async def index():
async def show():
overlay.show()
ui.label('something obscured in the background')
overlay = Overlay(time_out=4)
with overlay:
with ui.column().classes("h-screen items-center justify-center"):
ui.label('Please be Patient!').classes('text-white text-xl')
ui.spinner(size='lg')
app.on_connect(show)
ui.run() |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Mentioned this in another thread but thought some others might find it useful. I've used this a few times when I want to toss up a blocking overlay during a long operation. Could also be used as a splash screen during start up, etc.
Could easily be extended to show an image, a progress widget, etc.
Beta Was this translation helpful? Give feedback.
All reactions