solaar: Add type hints
This commit is contained in:
parent
0481950324
commit
128ec43d70
|
@ -14,9 +14,12 @@
|
|||
## You should have received a copy of the GNU General Public License along
|
||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from typing import Callable
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
|
@ -49,14 +52,22 @@ _LOGIND_PATH = "/org/freedesktop/login1"
|
|||
_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
|
||||
_suspend_callback = on_suspend_callback
|
||||
_resume_callback = on_resume_callback
|
||||
if bus is not None and on_resume_callback is not None or on_suspend_callback is not None:
|
||||
bus.add_signal_receiver(_suspend_or_resume, "PrepareForSleep", dbus_interface=_LOGIND_INTERFACE, path=_LOGIND_PATH)
|
||||
bus.add_signal_receiver(
|
||||
_suspend_or_resume,
|
||||
"PrepareForSleep",
|
||||
dbus_interface=_LOGIND_INTERFACE,
|
||||
path=_LOGIND_PATH,
|
||||
)
|
||||
if logger.isEnabledFor(logging.INFO):
|
||||
logger.info("connected to system dbus, watching for suspend/resume events")
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
import logging
|
||||
|
||||
from typing import Callable
|
||||
|
||||
import gi
|
||||
import yaml
|
||||
|
||||
|
@ -43,6 +45,9 @@ logger = logging.getLogger(__name__)
|
|||
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())
|
||||
|
@ -88,12 +93,21 @@ def _shutdown(app, shutdown_hook):
|
|||
desktop_notifications.uninit()
|
||||
|
||||
|
||||
def run_loop(startup_hook, shutdown_hook, use_tray, show_window):
|
||||
def run_loop(
|
||||
startup_hook: Callable[[], None],
|
||||
shutdown_hook: Callable[[], 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)
|
||||
|
|
Loading…
Reference in New Issue