Skip to content

Commit

Permalink
solaar: Add type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
MattHag committed Sep 15, 2024
1 parent ef71a2c commit 341b4b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/solaar/dbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import logging

from collections.abc import Callable

logger = logging.getLogger(__name__)

try:
Expand Down Expand Up @@ -49,7 +51,7 @@ def _suspend_or_resume(suspend):
_LOGIND_INTERFACE = "org.freedesktop.login1.Manager"


def watch_suspend_resume(on_resume_callback=None, on_suspend_callback=None):
def watch_suspend_resume(on_resume_callback: Callable[None, None] = None, on_suspend_callback: Callable[None, None] = None):
"""Register callback for suspend/resume events.
They are called only if the system DBus is running, and the Login daemon is available."""
global _resume_callback, _suspend_callback
Expand Down
20 changes: 17 additions & 3 deletions lib/solaar/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import logging

from collections.abc import Callable

import gi
import yaml

Expand All @@ -43,6 +45,9 @@
assert Gtk.get_major_version() > 2, "Solaar requires Gtk 3 python bindings"


APP_ID = "io.github.pwr_solaar.solaar"


def _startup(app, startup_hook, use_tray, show_window):
if logger.isEnabledFor(logging.DEBUG):
logger.debug("startup registered=%s, remote=%s", app.get_is_registered(), app.get_is_remote())
Expand Down Expand Up @@ -88,12 +93,21 @@ def _shutdown(app, shutdown_hook):
notify.uninit()


def run_loop(startup_hook, shutdown_hook, use_tray, show_window):
def run_loop(
startup_hook: Callable[None, None],
shutdown_hook: Callable[None, None],
use_tray: bool,
show_window: bool,
):
assert use_tray or show_window, "need either tray or visible window"
APP_ID = "io.github.pwr_solaar.solaar"

application = Gtk.Application.new(APP_ID, Gio.ApplicationFlags.HANDLES_COMMAND_LINE)

application.connect("startup", lambda app, startup_hook: _startup(app, startup_hook, use_tray, show_window), startup_hook)
application.connect(
"startup",
lambda app, startup_hook: _startup(app, startup_hook, use_tray, show_window),
startup_hook,
)
application.connect("command-line", _command_line)
application.connect("activate", _activate)
application.connect("shutdown", _shutdown, shutdown_hook)
Expand Down

0 comments on commit 341b4b5

Please sign in to comment.