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.

popup()[source]

Show the notification from code. This will initialize and activate if needed.

Notes

This does NOT block. Callbacks should be used to handle click events or the show state should be observed to know when it is closed.

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_widget()[source]

The notification is created in init_layout

init_layout()[source]

Create the notification in the top down pass if show = True

destroy()[source]

A reimplemented destructor that cancels the notification before destroying.

create_notification()[source]

Instead of the typical create_widget we use create_notification because after it’s closed it needs created again.

get_declared_items()[source]

Get the members that were set in the enamldef block for this Declaration.

Returns

result – List of keys and values

Return type

List of (k,v) pairs that were defined for this widget in enaml

refresh()[source]

If the

No iOS implementation found.