-
Notifications
You must be signed in to change notification settings - Fork 110
/
toggle_debug.py
47 lines (33 loc) · 1.04 KB
/
toggle_debug.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
A function, designed for keybinding, that toggles debug logging. By default, a
desktop notification is sent to report the new logging mode, but this can be disabled by
passing ``notify=False``.
Example usage:
from toggle_debug import toggle_debug
keys.extend([
Key([mod, "control"], "d", lazy.function(toggle_debug, timeout=1000)),
])
Qtile versions known to work: 0.21
"""
from __future__ import annotations
from logging import DEBUG
from typing import TYPE_CHECKING
from libqtile.utils import send_notification
if TYPE_CHECKING:
from libqtile.core.manager import Qtile
_notif_id = None
def toggle_debug(qtile: Qtile, notify: bool = True, timeout: int = 2500) -> None:
if qtile.cmd_loglevel() == DEBUG:
qtile.cmd_warning()
state = "disabled"
else:
qtile.cmd_debug()
state = "enabled"
if notify:
global _notif_id
_notif_id = send_notification(
"Logging",
f"Debugging {state}",
timeout=timeout,
id_=_notif_id,
)