Align log formatting
This commit is contained in:
parent
ebba452268
commit
2ec14f35f2
4 changed files with 47 additions and 8 deletions
|
|
@ -11,6 +11,8 @@
|
||||||
- Install deps: `uv sync`.
|
- Install deps: `uv sync`.
|
||||||
- Run daemon: `uv run python3 src/leld.py --config ~/.config/lel/config.json`.
|
- Run daemon: `uv run python3 src/leld.py --config ~/.config/lel/config.json`.
|
||||||
|
|
||||||
|
System packages (example names): `portaudio`/`libportaudio2`, `libayatana-appindicator3`.
|
||||||
|
|
||||||
## Coding Style & Naming Conventions
|
## Coding Style & Naming Conventions
|
||||||
|
|
||||||
- Shell scripts use Bash with `set -euo pipefail`.
|
- Shell scripts use Bash with `set -euo pipefail`.
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ Python X11 STT daemon that records audio, runs Whisper, logs the transcript, and
|
||||||
- X11 (not Wayland)
|
- X11 (not Wayland)
|
||||||
- `sounddevice` (PortAudio)
|
- `sounddevice` (PortAudio)
|
||||||
- `faster-whisper`
|
- `faster-whisper`
|
||||||
- Tray icon deps: `gtk3`
|
- Tray icon deps: `gtk3`, `libayatana-appindicator3`
|
||||||
- Python deps: `pillow`, `python-xlib`, `faster-whisper`, `PyGObject`, `sounddevice`
|
- Python deps: `pillow`, `python-xlib`, `faster-whisper`, `PyGObject`, `sounddevice`
|
||||||
|
|
||||||
System packages (example names): `portaudio`/`libportaudio2`.
|
System packages (example names): `portaudio`/`libportaudio2`.
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,11 @@ def main() -> int:
|
||||||
parser.add_argument("text", nargs="?", default="", help="text to process (or stdin)")
|
parser.add_argument("text", nargs="?", default="", help="text to process (or stdin)")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
logging.basicConfig(stream=sys.stderr, level=logging.INFO, format="ai: %(asctime)s %(message)s")
|
logging.basicConfig(
|
||||||
|
stream=sys.stderr,
|
||||||
|
level=logging.INFO,
|
||||||
|
format="lel: %(asctime)s %(levelname)s %(message)s",
|
||||||
|
)
|
||||||
cfg = load(args.config)
|
cfg = load(args.config)
|
||||||
|
|
||||||
logging.info(
|
logging.info(
|
||||||
|
|
|
||||||
45
src/leld.py
45
src/leld.py
|
|
@ -7,6 +7,7 @@ import signal
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
import warnings
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
|
|
@ -19,6 +20,11 @@ from inject import inject
|
||||||
from x11_hotkey import listen
|
from x11_hotkey import listen
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
|
try:
|
||||||
|
gi.require_version("AppIndicator3", "0.1")
|
||||||
|
from gi.repository import AppIndicator3 # type: ignore[import-not-found]
|
||||||
|
except ValueError:
|
||||||
|
AppIndicator3 = None
|
||||||
|
|
||||||
from gi.repository import GLib, Gtk # type: ignore[import-not-found]
|
from gi.repository import GLib, Gtk # type: ignore[import-not-found]
|
||||||
|
|
||||||
|
|
@ -57,14 +63,32 @@ class Daemon:
|
||||||
device=cfg.stt.get("device", "cpu"),
|
device=cfg.stt.get("device", "cpu"),
|
||||||
compute_type=_compute_type(cfg.stt.get("device", "cpu")),
|
compute_type=_compute_type(cfg.stt.get("device", "cpu")),
|
||||||
)
|
)
|
||||||
self.icon = Gtk.StatusIcon()
|
self.indicator = None
|
||||||
self.icon.set_visible(True)
|
self.status_icon = None
|
||||||
self.icon.connect("popup-menu", self._on_tray_menu)
|
if AppIndicator3 is not None:
|
||||||
|
self.indicator = AppIndicator3.Indicator.new(
|
||||||
|
"lel",
|
||||||
|
self._icon_path(State.IDLE),
|
||||||
|
AppIndicator3.IndicatorCategory.APPLICATION_STATUS,
|
||||||
|
)
|
||||||
|
self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
|
||||||
|
else:
|
||||||
|
logging.warning("AppIndicator3 unavailable; falling back to deprecated Gtk.StatusIcon")
|
||||||
|
warnings.filterwarnings(
|
||||||
|
"ignore",
|
||||||
|
message=".*Gtk.StatusIcon.*",
|
||||||
|
category=DeprecationWarning,
|
||||||
|
)
|
||||||
|
self.status_icon = Gtk.StatusIcon()
|
||||||
|
self.status_icon.set_visible(True)
|
||||||
|
self.status_icon.connect("popup-menu", self._on_tray_menu)
|
||||||
self.menu = Gtk.Menu()
|
self.menu = Gtk.Menu()
|
||||||
quit_item = Gtk.MenuItem(label="Quit")
|
quit_item = Gtk.MenuItem(label="Quit")
|
||||||
quit_item.connect("activate", lambda *_: self._quit())
|
quit_item.connect("activate", lambda *_: self._quit())
|
||||||
self.menu.append(quit_item)
|
self.menu.append(quit_item)
|
||||||
self.menu.show_all()
|
self.menu.show_all()
|
||||||
|
if self.indicator is not None:
|
||||||
|
self.indicator.set_menu(self.menu)
|
||||||
|
|
||||||
def set_state(self, state: str):
|
def set_state(self, state: str):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
|
|
@ -228,8 +252,13 @@ class Daemon:
|
||||||
|
|
||||||
def _update_tray(self):
|
def _update_tray(self):
|
||||||
state = self.get_state()
|
state = self.get_state()
|
||||||
self.icon.set_from_file(self._icon_path(state))
|
icon_path = self._icon_path(state)
|
||||||
self.icon.set_tooltip_text(self._title(state))
|
if self.indicator is not None:
|
||||||
|
self.indicator.set_icon_full(icon_path, self._title(state))
|
||||||
|
self.indicator.set_label(self._title(state), "")
|
||||||
|
elif self.status_icon is not None:
|
||||||
|
self.status_icon.set_from_file(icon_path)
|
||||||
|
self.status_icon.set_tooltip_text(self._title(state))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def run_tray(self):
|
def run_tray(self):
|
||||||
|
|
@ -259,7 +288,11 @@ def main():
|
||||||
parser.add_argument("--dry-run", action="store_true", help="log hotkey only")
|
parser.add_argument("--dry-run", action="store_true", help="log hotkey only")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
logging.basicConfig(stream=sys.stderr, level=logging.INFO, format="leld: %(asctime)s %(message)s")
|
logging.basicConfig(
|
||||||
|
stream=sys.stderr,
|
||||||
|
level=logging.INFO,
|
||||||
|
format="lel: %(asctime)s %(levelname)s %(message)s",
|
||||||
|
)
|
||||||
cfg = load(args.config)
|
cfg = load(args.config)
|
||||||
_lock_single_instance()
|
_lock_single_instance()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue