more typing work

This commit is contained in:
Kovid Goyal
2020-03-13 16:13:26 +05:30
parent 9f2fb76309
commit 917559f883
14 changed files with 693 additions and 488 deletions

View File

@@ -2,7 +2,7 @@
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
from typing import Dict
from typing import Dict, Optional
from .constants import is_macos, logo_png_file
@@ -10,16 +10,14 @@ if is_macos:
from .fast_data_types import cocoa_send_notification
def notify(
title,
body,
timeout=5000,
application='kitty',
icon=True,
identifier=None
):
if icon is True:
icon = None
cocoa_send_notification(identifier, title, body, icon)
title: str,
body: str,
timeout: int = 5000,
application: str = 'kitty',
icon: bool = True,
identifier: Optional[str] = None
) -> None:
cocoa_send_notification(identifier, title, body, None)
else:
@@ -28,12 +26,12 @@ else:
alloc_map: Dict[int, str] = {}
identifier_map: Dict[str, int] = {}
def dbus_notification_created(alloc_id, notification_id):
def dbus_notification_created(alloc_id: int, notification_id: int) -> None:
identifier = alloc_map.pop(alloc_id, None)
if identifier is not None:
identifier_map[identifier] = notification_id
def dbus_notification_activated(notification_id, action):
def dbus_notification_activated(notification_id: int, action: str) -> None:
rmap = {v: k for k, v in identifier_map.items()}
identifier = rmap.get(notification_id)
if identifier is not None:
@@ -41,15 +39,16 @@ else:
notification_activated(identifier)
def notify(
title,
body,
timeout=-1,
application='kitty',
icon=True,
identifier=None
):
title: str,
body: str,
timeout: int = -1,
application: str = 'kitty',
icon: bool = True,
identifier: Optional[str] = None
) -> None:
icf = ''
if icon is True:
icon = logo_png_file
alloc_id = dbus_send_notification(application, icon, title, body, 'Click to see changes', timeout)
icf = logo_png_file
alloc_id = dbus_send_notification(application, icf, title, body, 'Click to see changes', timeout)
if alloc_id and identifier is not None:
alloc_map[alloc_id] = identifier