Skip to content

Commit

Permalink
Merge pull request #3 from zauberzeug/feature/notifications
Browse files Browse the repository at this point in the history
addingFeature/notifications
  • Loading branch information
rodja authored Aug 21, 2021
2 parents b87c8cc + f84db4f commit 7ebe20a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ __pycache__/
*.egg-info/
.*.swp
dist
/test.py
6 changes: 5 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def button_increment():
ui.button('Close', on_click=dialog.close)

ui.button('Open dialog', on_click=dialog.open)

with example(ui.menu):

with ui.menu() as menu:
Expand All @@ -298,6 +298,10 @@ def button_increment():

ui.button('Basic menu', on_click=menu.open).props('color=secondary')

with example(ui.notify):

ui.button('show notification', on_click=lambda: ui.notify(message='Some message', close_button='OK'))

lifecycle = '''### Lifecycle
You can run a function or coroutine on startup as a parallel task by passing it to `ui.on_startup`.
Expand Down
33 changes: 33 additions & 0 deletions nicegui/elements/notify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import justpy as jp
from .element import Element
import asyncio


class Notify(Element):

def __init__(self,
message: str = '',
position: str = 'bottom',
close_button: str = ''
):
"""Notification Element
Displays a notification on the screen.
:param message: the content of the notification
:param position: possible position: 'top-left', 'top-right', 'bottom-left','bottom-right, 'top', 'bottom', 'left', 'right', 'center'
:param close_button: label of the button to dismiss the notification
"""

view = jp.QNotify(message=message, position=position)

if close_button:
view.closeBtn = close_button

super().__init__(view)
asyncio.get_event_loop().create_task(self.notify_async())

async def notify_async(self):
self.view.notify = True
await self.parent_view.update()
self.view.notify = False
1 change: 1 addition & 0 deletions nicegui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Ui:
from .elements.log import Log as log
from .elements.markdown import Markdown as markdown
from .elements.menu import Menu as menu
from .elements.notify import Notify as notify
from .elements.number import Number as number
from .elements.radio import Radio as radio
from .elements.select import Select as select
Expand Down

0 comments on commit 7ebe20a

Please sign in to comment.