Notification¶
Example¶
""" Example demonstrates how to create and use Notifications
with the NotificationManager.show_notification or the Notification widget.
"""
from enamlnative.widgets.api import *
from enamlnative.android.api import NotificationManager
CHANNEL_ID = "John Doe"
enamldef ContentView(Flexbox): view:
flex_direction = "column"
async func create_channel():
channel = await NotificationManager.create_channel(CHANNEL_ID, "Messages")
print(f"Created {channel}")
activated:: app.deferred_call(create_channel)
async func show_notification():
result = await NotificationManager.show_notification(CHANNEL_ID,
title="John Doe", text="Hello world!", color="#F00")
print(f'Show notification: {result}')
Button:
text = "Show basic notification"
clicked :: app.deferred_call(show_notification)
Button:
text = "Show progress notification"
clicked ::
pn.show = True
# Simulate progress
for i in range(10):
app.timed_call(i*1000, lambda v=pn, i=i:setattr(v, 'progress', i*10))
app.timed_call(11000, lambda v=pn: setattr(v, 'show', False))
Notification: pn:
channel_id = CHANNEL_ID
title = "Picture download"
text << f"Download in progress {self.progress}%"
color = "#bac"
show_progress = True
progress = 0 # Initial progress must be zero then incremented
settings = {"ongoing": True}
async func show_action_notification():
# Must save a ref when using it this way or the buttons won't work
btn.ref = await NotificationManager.show_notification(
CHANNEL_ID,
title="Good morning!",
text="Hope you have a great day!",
actions=[
("@drawable/ic_snooze", "SNOOZE", btn.on_snooze),
]
)
Button: btn:
text = "Show notification with actions"
attr ref
func on_snooze(intent):
app.show_toast("Snooze clicked!")
clicked :: app.deferred_call(show_action_notification)
Declaration¶
- class enamlnative.widgets.notification.Notification(parent=None, **kwargs)[source]¶
Bases:
enaml.widgets.toolkit_object.ToolkitObject
A notification that may contain a view.
- channel_id¶
Set the channel ID
- title¶
Set the title (first row) of the notification, in a standard notification.
- text¶
Set the text (second row) of the notification, in a standard notification.
- info¶
Set the large text at the right-hand side of the notification.
- icon¶
Set the small icon to use in the notification layouts.
- color¶
Sets color.
- show¶
Start the dialog and display it on screen (or hide if False)
- priority¶
Set the priority or importance
- progress¶
Progress
- progress_indeterminate¶
Show an indeterminate progress bar
- show_progress¶
Show a progress bar
- show_when¶
Show a timestamp
- style¶
Notification style using the @style format (ex. @style/Theme_Light_NoTitleBar_Fullscreen
- settings¶
Extra notification settings
- clicked¶
Clicked event
- proxy¶
A reference to the proxy object.
Android Implementation¶
- class enamlnative.android.android_notification.AndroidNotification[source]¶
Bases:
enamlnative.android.android_toolkit_object.AndroidToolkitObject
,enamlnative.widgets.notification.ProxyNotification
An Android implementation of an Enaml ProxyNotification.
- builder¶
A reference to the widget created by the proxy.
- shown¶
Keep track of
- create_notification()[source]¶
Instead of the typical create_widget we use create_notification because after it’s closed it needs created again.
No iOS implementation found.