Skip to content

Commit

Permalink
stricter types
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Oct 4, 2023
1 parent 73b72de commit 7368b21
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 20 deletions.
5 changes: 3 additions & 2 deletions xpra/client/gtk3/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
gi.require_version('Notify', '0.7') # @UndefinedVariable
from gi.repository import Notify #@UnresolvedImport

from xpra.common import NotificationID
from xpra.notifications.notifier_base import NotifierBase


class GINotifier(NotifierBase):

def show_notify(self, dbus_id, tray, nid:int,
app_name:str, replaces_nid:int, app_icon,
def show_notify(self, dbus_id, tray, nid:int|NotificationID,
app_name:str, replaces_nid:int|NotificationID, app_icon,
summary:str, body:str, actions, hints, timeout:int, icon):
if not self.dbus_check(dbus_id):
return
Expand Down
7 changes: 4 additions & 3 deletions xpra/gtk/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from gi.repository import GLib, Gtk, Gdk, GdkPixbuf # @UnresolvedImport

from xpra.os_util import OSX
from xpra.common import NotificationID
from xpra.gtk.gtk_util import add_close_accel, color_parse
from xpra.gtk.widget import label
from xpra.gtk.pixbuf import get_icon_pixbuf
Expand Down Expand Up @@ -109,9 +110,9 @@ def close_notify(self, nid):
if x.nid==nid:
x.hide_notification()

def show_notify(self, dbus_id, tray, nid,
app_name, replaces_nid, app_icon,
summary, body, actions, hints, timeout, icon):
def show_notify(self, dbus_id, tray, nid:int|NotificationID,
app_name:str, replaces_nid:int|NotificationID, app_icon,
summary:str, body:str, actions, hints, timeout, icon):
GLib.idle_add(self.new_popup, nid, summary, body, actions, icon, timeout, 0<timeout<=600)

def new_popup(self, nid:int, summary:str, body:str, actions:tuple, icon, timeout=10*1000, show_timeout=False):
Expand Down
5 changes: 3 additions & 2 deletions xpra/notifications/dbus_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from xpra.util.str_fn import csv, ellipsizer
from xpra.os_util import bytestostr
from xpra.dbus.helper import native_to_dbus
from xpra.common import NotificationID
from xpra.notifications.notifier_base import NotifierBase, log
try:
#new recommended way of using the glib main loop:
Expand Down Expand Up @@ -69,8 +70,8 @@ def cleanup(self) -> None:
super().cleanup()


def show_notify(self, dbus_id, tray, nid:int,
app_name:str, replaces_nid:int, app_icon,
def show_notify(self, dbus_id, tray, nid:int|NotificationID,
app_name:str, replaces_nid:int|NotificationID, app_icon,
summary:str, body:str, actions, hints, timeout:int, icon) -> None:
if not self.dbus_check(dbus_id):
return
Expand Down
13 changes: 7 additions & 6 deletions xpra/notifications/notifier_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from xpra.os_util import osexpand
from xpra.log import Logger
from xpra.common import NotificationID

log = Logger("notify")

Expand All @@ -29,12 +30,12 @@ def cleanup(self) -> None:
for nid in self.temp_files:
self.clean_notification(nid)

def show_notify(self, dbus_id, tray, nid:int,
app_name:str, replaces_nid:int, app_icon,
def show_notify(self, dbus_id, tray, nid:int|NotificationID,
app_name:str, replaces_nid:int|NotificationID, app_icon,
summary:str, body:str, actions, hints, timeout:int, icon) -> None:
raise NotImplementedError()

def get_icon_string(self, nid : int, app_icon, icon) -> str:
def get_icon_string(self, nid : int|NotificationID, app_icon, icon) -> str:
if app_icon and not os.path.isabs(app_icon):
#safe to use
return app_icon
Expand All @@ -56,12 +57,12 @@ def get_icon_string(self, nid : int, app_icon, icon) -> str:
prefix='xpra-notification-icon-', dir=tmp, delete=False)
temp.write(icon_data)
temp.close()
self.temp_files[nid] = temp.name
self.temp_files[int(nid)] = temp.name
return temp.name
return ""

def clean_notification(self, nid : int) -> None:
temp_file = self.temp_files.pop(nid, None)
def clean_notification(self, nid:int|NotificationID) -> None:
temp_file = self.temp_files.pop(int(nid), None)
log("clean_notification(%s) temp_file=%s", nid, temp_file)
if temp_file:
try:
Expand Down
5 changes: 3 additions & 2 deletions xpra/notifications/pynotify_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import notify2 #@UnresolvedImport

from xpra.notifications.notifier_base import NotifierBase
from xpra.common import NotificationID


class PyNotify_Notifier(NotifierBase):

CACHE : dict[int,Any] = {}

def show_notify(self, dbus_id, tray, nid:int,
app_name:str, replaces_nid:int, app_icon,
def show_notify(self, dbus_id, tray, nid:int|NotificationID,
app_name:str, replaces_nid:int|NotificationID, app_icon,
summary:str, body:str, actions, hints, timeout:int, icon) -> None:
if not self.dbus_check(dbus_id):
return
Expand Down
9 changes: 5 additions & 4 deletions xpra/platform/darwin/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
NSUserNotificationDefaultSoundName, #@UnresolvedImport
)

from xpra.common import roundup
from xpra.common import roundup, NotificationID
from xpra.util.env import envint, envbool
from xpra.notifications.notifier_base import NotifierBase
from xpra.platform.darwin import get_OSXApplication
Expand Down Expand Up @@ -116,8 +116,9 @@ def __init__(self, closed_cb=None, action_cb=None):
self.notification_center = NSUserNotificationCenter.defaultUserNotificationCenter()
assert self.notification_center

def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon,
summary, body, actions, hints, expire_timeout, icon):
def show_notify(self, dbus_id, tray, nid:int|NotificationID,
app_name:str, replaces_nid:int|NotificationID, app_icon,
summary:str, body:str, actions, hints, expire_timeout:int, icon):
GTK_NOTIFIER = envbool("XPRA_OSX_GTK_NOTIFIER", True)
if actions and GTK_NOTIFIER:
#try to use GTK notifier if we have actions buttons to handle:
Expand All @@ -133,7 +134,7 @@ def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon,
return
GLib.idle_add(self.do_show_notify, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon)

def do_show_notify(self, dbus_id, tray, nid:int, app_name, replaces_nid:int, app_icon,
def do_show_notify(self, dbus_id, tray, nid:int|NotificationID, app_name:str, replaces_nid:int|NotificationID, app_icon,
summary:str, body:str, actions, hints, expire_timeout:int, icon):
notification = NSUserNotification.alloc()
notification.init()
Expand Down
5 changes: 4 additions & 1 deletion xpra/platform/win32/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys

from xpra.util.env import envbool
from xpra.common import NotificationID
from xpra.notifications.notifier_base import NotifierBase, log
from xpra.platform.win32.balloon import notify

Expand Down Expand Up @@ -43,7 +44,9 @@ def get_gtk_notifier(self):
log("failed to load GTK Notifier fallback", exc_info=True)
return self.gtk_notifier

def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon):
def show_notify(self, dbus_id, tray, nid:int|NotificationID,
app_name:str, replaces_nid:int|NotificationID,
app_icon, summary:str, body:str, actions, hints, expire_timeout:int, icon):
getHWND = getattr(tray, "getHWND", None)
if GTK_NOTIFIER and (actions or not getHWND):
log("show_notify(..) using gtk fallback, GTK_NOTIFIER=%s, tray=%s, getHWND=%s, actions=%s",
Expand Down

0 comments on commit 7368b21

Please sign in to comment.