class Notifier: """ Notifier class is responsible for creating and managing the notification Args: summary: title of the notification message: message to be displayed icon: icon of notification bar """ def __init__(self, app_name: str, summary: str, message: str = "", icon: str = "") -> None: self._app_name = app_name self._summary = summary self._message = message self._icon = icon notify2.init(self._app_name) self._notification = Notification(self._summary, self._message, self._icon) def show(self, urgency_level: int = notify2.URGENCY_NORMAL) -> None: """ Show notification bar Args: urgency_level: level of urgency (NORMAL, LOW, CRITICAL) """ self._notification.set_urgency(urgency_level) self._notification.show() def close(self) -> None: """ Remove notification bar from tray """ self._notification.close()
import power import time import notify2 from notify2 import Notification notify2.init("Charger Warning") n = Notification("WARNING", "Laptop running on battery. Plug in charger!") n.set_urgency(notify2.URGENCY_CRITICAL) while (True): source = power.PowerManagement().get_providing_power_source_type() if source == power.POWER_TYPE_BATTERY: n.show() print('NOT CHARGING!') else: print('CHARGING') time.sleep(300)