예제 #1
0
    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)
예제 #2
0
 def notify(self, title, message, timeout=10):
     n = Notification(
         "{app} - {title}".format(app=self._app_name, title=title), message,
         pyinstaller_resource_path("icon.png"))
     n.timeout = timeout * 1000
     n.add_action("open", "Open App", self.open)
     n.show()
     self._notifications.append(n)
예제 #3
0
def notify():
	init('Notify')

	n = Notification("Drink Water", "Hey asshole, drink some water FFS")

	n.show()
	sleep(10)
	n.close()
	return True
예제 #4
0
def timer(time_string, name):
    """Send notification after time is complete.

    Time should be formatted with hms e.g 1h30m or 3h20m30s.
    """
    notify2.init("timer")
    print("Starting timer!")
    sleep(to_seconds(time_string))
    print("Done!")
    n = Notification("Timer finished!", name)
    n.show()
예제 #5
0
def send(process=None, subject_format='{executable} process {pid} ended',
         timeout=notify2.EXPIRES_NEVER):
    """Display a Desktop Notification via DBUS (notify2)

    :param process: information about process. (.info() inserted into body)
    :param subject_format: subject format string. (uses process.__dict__)
    :param timeout: how long to display notification (milliseconds) default 0 (never expires)
    """
    notif = Notification(subject_format.format(**process.__dict__),
                         process.info())
    notif.timeout = timeout
    notif.show()
    def __init__ ( self ):

        # Parse config.ini
        self.CONFIG_PATH = "./config.ini"

        self.config = ConfigParser()
        self.config.read(self.CONFIG_PATH)

        self.configuration = self.config.sections()[0]

        self.platform = self.config.get(self.configuration, 'platform').lower()
        self.router_user = self.config.get(self.configuration, 'router_user')
        self.router_pass = self.config.get(self.configuration, 'router_pass')

        # Reference Map : ( status , color style - console output , router string* )
        self.connection_status = (
            ( "Online" , "\033[32m" , "Up" ) ,
            ( "Offline" , "\033[31m" , "Down" ) ,
            ( "Disconnected" , "\033[33m" )
            )
        
        self.color_reset = "\033[m" # Reset console color
        self.ignore = 404 # Report this code in case of error - notifier will ignore this

        # Buffer last reported code to this container
        self.buffer = self.ignore # Initialize container to ignore default code

        self.duration = 3 # Notification and timeloop

        self.ICON_PATH = "./wlan.ico"

        # Platform-specific notifier:

        if self.platform == "windows":

            # Import 'Windows 10' Toast module:
            from win10toast import ToastNotifier

            # Instantiate
            self.notifier_windows = ToastNotifier()

        elif self.platform == "linux":

            # Import 'Linux Desktop Notification' module (Tested on Debian 10 Buster):
            from notify2 import init, Notification

            # Instantiate
            self.notifier_linux = init( "DLink-2730U Router Connection Status Notifier" )
            self.n = Notification( "Connection Status" , message = "Daemon Running" , icon = self.ICON_PATH )
예제 #7
0
 def on_start(self):
     if self._should_run():
         self._run_command()
         self.finish_async()
     else:
         n = Notification(
             summary=str(self.command),
             message="Run now?",  # TODO include command name
             icon='dialog-question',
         )
         n.set_timeout(EXPIRES_NEVER)
         n.add_action("error", "<b>Run</b>",
                      lambda n, action: self._run_command(n))
         n.add_action("close", "Close", lambda n, action: n.close())
         n.connect('closed', lambda n: self.finish_async())
         n.show()
예제 #8
0
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)
예제 #9
0
from psutil import sensors_battery
from notify2 import init, Notification
from time import sleep

if __name__ == '__main__':
    init('battery notification')
    notification = Notification('Battery low', "Your battery is almost empty. Plug in your computer now or save your work.")
    shown = False
    while True:
        battery = sensors_battery()
        if battery.percent < 80 and not battery.power_plugged and not shown:
            notification.update('Battery low', f'Your battery is almost empty. Plug in your computer now or save your work\n'
                                               f'You have {battery.secsleft // 60} minutes left.')
            notification.show()
            shown = True
            sleep(300)
        sleep(10)
예제 #10
0
def notify(meeting):
    """ generates meeting notification """
    init('Meetings Assistant')
    Notification(summary='Meeting Reminder', message=meeting['name']).show()
# names and make sure they aren't a multiplexer
for parent in p.parents():
    if parent.name() in multiplexers:
        exit()

# get terminal pid
terminal_pid = p.parents()[-2].pid

# get Sway's information on terminal
container = i3.get_tree().find_by_pid(terminal_pid)[0]

if not container.focused:
    # the application name is handled differently for wayland and xwayland
    # wayland
    if container.app_id:
        termial = container.app_id
    # xwayland
    elif container.window_instance:
        termial = container.window_instance
    # pretty sure this fallback is unneeded but leaving this for now
    else:
        termial = "terminal"

    init("sway-terminal-notify")
    n = Notification(
        "{} finished".format(termial),
        "on workspace {}".format(container.workspace().name),
        "/usr/share/icons/breeze/apps/48/utilities-terminal.svg",
    )
    n.show()
예제 #12
0
def notify(message):
    print message
    if CanNotify:
        Notification('Auto Backup', message).show()