diff options
Diffstat (limited to 'modui/mpvwidget.py')
| -rw-r--r-- | modui/mpvwidget.py | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/modui/mpvwidget.py b/modui/mpvwidget.py index 50e5859..80c162f 100644 --- a/modui/mpvwidget.py +++ b/modui/mpvwidget.py @@ -1,5 +1,9 @@ import time -import fcntl, struct, termios + +import fcntl +import struct +import termios + from sys import stdout from textual import events, log @@ -7,6 +11,7 @@ from textual.widgets import Static from fhost import app as fhost_app + class MpvWidget(Static): def __init__(self, **kwargs): super().__init__(**kwargs) @@ -14,8 +19,10 @@ class MpvWidget(Static): self.mpv = None self.vo = fhost_app.config.get("MOD_PREVIEW_PROTO") - if not self.vo in ["sixel", "kitty"]: - self.update("⚠ Previews not enabled. \n\nSet MOD_PREVIEW_PROTO to 'sixel' or 'kitty' in config.py,\nwhichever is supported by your terminal.") + if self.vo not in ["sixel", "kitty"]: + self.update("⚠ Previews not enabled. \n\nSet MOD_PREVIEW_PROTO " + "to 'sixel' or 'kitty' in config.py,\nwhichever is " + "supported by your terminal.") else: try: import mpv @@ -27,28 +34,35 @@ class MpvWidget(Static): self.mpv[f"vo-sixel-buffered"] = True self.mpv["audio"] = False self.mpv["loop-file"] = "inf" - self.mpv["image-display-duration"] = 0.5 if self.vo == "sixel" else "inf" + self.mpv["image-display-duration"] = 0.5 \ + if self.vo == "sixel" else "inf" except Exception as e: self.mpv = None - self.update(f"⚠ Previews require python-mpv with libmpv 0.36.0 or later \n\nError was:\n{type(e).__name__}: {e}") + self.update("⚠ Previews require python-mpv with libmpv " + "0.36.0 or later \n\nError was:\n" + f"{type(e).__name__}: {e}") - def start_mpv(self, f: str|None = None, pos: float|str|None = None) -> None: + def start_mpv(self, f: str | None = None, + pos: float | str | None = None) -> None: self.display = True self.screen._refresh_layout() if self.mpv: if self.content_region.x: - r, c, w, h = struct.unpack('hhhh', fcntl.ioctl(0, termios.TIOCGWINSZ, '12345678')) + winsz = fcntl.ioctl(0, termios.TIOCGWINSZ, '12345678') + r, c, w, h = struct.unpack('hhhh', winsz) width = int((w / c) * self.content_region.width) - height = int((h / r) * (self.content_region.height + (1 if self.vo == "sixel" else 0))) + height = int((h / r) * (self.content_region.height + + (1 if self.vo == "sixel" else 0))) self.mpv[f"vo-{self.vo}-left"] = self.content_region.x + 1 self.mpv[f"vo-{self.vo}-top"] = self.content_region.y + 1 - self.mpv[f"vo-{self.vo}-rows"] = self.content_region.height + (1 if self.vo == "sixel" else 0) + self.mpv[f"vo-{self.vo}-rows"] = self.content_region.height + \ + (1 if self.vo == "sixel" else 0) self.mpv[f"vo-{self.vo}-cols"] = self.content_region.width self.mpv[f"vo-{self.vo}-width"] = width self.mpv[f"vo-{self.vo}-height"] = height - if pos != None: + if pos is not None: self.mpv["start"] = pos if f: |
