From abfb4684f4bd72781fef81f69e9f9e5f00f59ef4 Mon Sep 17 00:00:00 2001 From: totaam Date: Tue, 7 Nov 2023 22:07:25 +0700 Subject: [PATCH] silence more gi import warnings --- xpra/client/gtk3/notifier.py | 19 +++++------- xpra/platform/posix/appindicator_tray.py | 39 +++++++++++------------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/xpra/client/gtk3/notifier.py b/xpra/client/gtk3/notifier.py index e2813a6d36..93b08ebba9 100644 --- a/xpra/client/gtk3/notifier.py +++ b/xpra/client/gtk3/notifier.py @@ -3,33 +3,30 @@ # Xpra is released under the terms of the GNU GPL v2, or, at your option, any # later version. See the file COPYING for details. -#pylint: disable=wrong-import-position - -import gi -gi.require_version('Notify', '0.7') # @UndefinedVariable -from gi.repository import Notify #@UnresolvedImport - +from xpra.os_util import gi_import from xpra.common import NotificationID from xpra.notifications.notifier_base import NotifierBase +Notify = gi_import("Notify", "0.7") + class GINotifier(NotifierBase): - 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): + 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 icon_string = self.get_icon_string(nid, app_icon, icon) Notify.init(app_name or "Xpra") n = Notify.Notification.new(summary=summary, body=body, icon=icon_string) + def closed(*_args): self.clean_notification(nid) n.connect("closed", closed) n.show() - - def close_notify(self, nid:int) -> None: + def close_notify(self, nid: int) -> None: self.clean_notification(nid) def cleanup(self) -> None: diff --git a/xpra/platform/posix/appindicator_tray.py b/xpra/platform/posix/appindicator_tray.py index 1a5942db1b..3f0448f073 100644 --- a/xpra/platform/posix/appindicator_tray.py +++ b/xpra/platform/posix/appindicator_tray.py @@ -11,14 +11,13 @@ # - that menu looks bloody awful # etc -import gi import os import sys import tempfile from time import monotonic from xpra.util.env import envbool -from xpra.os_util import osexpand +from xpra.os_util import osexpand, gi_import from xpra.client.gui.tray_base import TrayBase from xpra.platform.paths import get_icon_dir, get_icon_filename, get_xpra_tmp_dir from xpra.log import Logger @@ -26,14 +25,12 @@ log = Logger("tray", "posix") try: - gi.require_version("AyatanaAppIndicator3", "0.1") # @UndefinedVariable - from gi.repository import AyatanaAppIndicator3 as AppIndicator3 #pylint: disable=wrong-import-order, wrong-import-position, ungrouped-imports + AppIndicator3 = gi_import("AyatanaAppIndicator3", "0.1") log("loaded `AyatanaAppIndicator3`") except (ImportError, ValueError): log("failed to load `AyatanaAppIndicator3`", exc_info=True) try: - gi.require_version("AppIndicator3", "0.1") # @UndefinedVariable - from gi.repository import AppIndicator3 #pylint: disable=wrong-import-order, wrong-import-position, ungrouped-imports + AppIndicator3 = gi_import("AppIndicator3", "0.1") # @UndefinedVariable log("loaded `AppIndicator3`") except ValueError as ve: log("failed to load `AppIndicator3`", exc_info=True) @@ -44,7 +41,9 @@ PASSIVE = AppIndicator3.IndicatorStatus.PASSIVE ACTIVE = AppIndicator3.IndicatorStatus.ACTIVE APPLICATION_STATUS = AppIndicator3.IndicatorCategory.APPLICATION_STATUS -def Indicator(tooltip:str, filename:str, status:AppIndicator3.IndicatorStatus): + + +def Indicator(tooltip: str, filename: str, status: AppIndicator3.IndicatorStatus): return AppIndicator3.Indicator.new(id=tooltip, icon_name=filename, category=status) @@ -70,7 +69,7 @@ def __init__(self, *args, **kwargs): self.tray_widget.set_menu(self.menu) def get_geometry(self): - #no way to tell :( + # no way to tell :( return None def hide(self) -> None: @@ -79,19 +78,19 @@ def hide(self) -> None: def show(self) -> None: self.tray_widget.set_status(ACTIVE) - def set_blinking(self, on:bool) -> None: - #"I'm Afraid I Can't Do That" + def set_blinking(self, on: bool) -> None: + # "I'm Afraid I Can't Do That" pass def set_tooltip(self, tooltip="") -> None: - #we only use this if we haven't got an icon - #as with appindicator this creates a large text label - #next to where the icon is/should be + # we only use this if we haven't got an icon + # as with appindicator this creates a large text label + # next to where the icon is/should be if not self._has_icon: self.tray_widget.set_label(tooltip or "Xpra") - def set_icon_from_data(self, pixels, has_alpha:bool, w:int, h:int, rowstride:int, _options=None) -> None: - #use a temporary file (yuk) + def set_icon_from_data(self, pixels, has_alpha: bool, w: int, h: int, rowstride: int, _options=None) -> None: + # use a temporary file (yuk) self.clean_last_tmp_icon() # pylint: disable=import-outside-toplevel from xpra.gtk.pixbuf import pixbuf_save_to_memory @@ -118,7 +117,7 @@ def set_icon_from_data(self, pixels, has_alpha:bool, w:int, h:int, rowstride:int os.close(fd) self.do_set_icon_from_file(self.tmp_filename) - def do_set_icon_from_file(self, filename:str) -> None: + def do_set_icon_from_file(self, filename: str) -> None: if not hasattr(self.tray_widget, "set_icon_theme_path"): self.tray_widget.set_icon(filename) self._has_icon = True @@ -127,7 +126,7 @@ def do_set_icon_from_file(self, filename:str) -> None: if head: log(f"do_set_icon_from_file({filename!r}) setting icon theme path={head!r}") self.tray_widget.set_icon_theme_path(head) - #remove extension (wtf?) + # remove extension (wtf?) noext = os.path.splitext(icon_name)[0] log(f"do_set_icon_from_file({filename!r}) setting icon={noext}") try: @@ -150,7 +149,7 @@ def cleanup(self) -> None: super().cleanup() -def main(): # pragma: no cover +def main(): # pragma: no cover # pylint: disable=import-outside-toplevel from xpra.platform import program_context with program_context("AppIndicator-Test", "AppIndicator Test"): @@ -159,9 +158,7 @@ def main(): # pragma: no cover enable_debug_for("tray") from xpra.gtk.signals import register_os_signals - - gi.require_version('Gtk', '3.0') # @UndefinedVariable - from gi.repository import Gtk # @UnresolvedImport + Gtk = gi_import("Gtk", "3.0") menu = Gtk.Menu() item = Gtk.MenuItem(label="Top Menu Item 1") submenu = Gtk.Menu()