diff options
Diffstat (limited to 'modui')
| -rw-r--r-- | modui/filetable.py | 13 | ||||
| -rw-r--r-- | modui/mime.py | 94 | ||||
| -rw-r--r-- | modui/mpvwidget.py | 34 | ||||
| -rw-r--r-- | modui/notification.py | 1 |
4 files changed, 82 insertions, 60 deletions
diff --git a/modui/filetable.py b/modui/filetable.py index 879eed0..4345227 100644 --- a/modui/filetable.py +++ b/modui/filetable.py @@ -7,12 +7,14 @@ from jinja2.filters import do_filesizeformat from fhost import File from modui import mime + class FileTable(DataTable): query = Reactive(None) order_col = Reactive(0) order_desc = Reactive(True) limit = 10000 - colmap = [File.id, File.removed, File.nsfw_score, None, File.ext, File.size, File.mime] + colmap = [File.id, File.removed, File.nsfw_score, None, File.ext, + File.size, File.mime] def __init__(self, **kwargs): super().__init__(**kwargs) @@ -33,6 +35,8 @@ class FileTable(DataTable): def watch_query(self, old, value) -> None: def fmt_file(f: File) -> tuple: + mimemoji = mime.mimemoji.get(f.mime.split('/')[0], + mime.mimemoji.get(f.mime)) or ' ' return ( str(f.id), "🔴" if f.removed else " ", @@ -40,14 +44,15 @@ class FileTable(DataTable): "👻" if not f.getpath().is_file() else " ", f.getname(), do_filesizeformat(f.size, True), - f"{mime.mimemoji.get(f.mime.split('/')[0], mime.mimemoji.get(f.mime)) or ' '} " + f.mime, + f"{mimemoji} {f.mime}", ) if (self.query): - order = FileTable.colmap[self.order_col] q = self.query - if order: q = q.order_by(order.desc() if self.order_desc else order, File.id) + if order: + q = q.order_by(order.desc() if self.order_desc + else order, File.id) qres = list(map(fmt_file, q.limit(self.limit))) ri = 0 diff --git a/modui/mime.py b/modui/mime.py index fae51af..e693ebe 100644 --- a/modui/mime.py +++ b/modui/mime.py @@ -2,46 +2,46 @@ from enum import Enum from textual import log mimemoji = { - "audio" : "🔈", - "video" : "🎞", - "text" : "📄", - "image" : "🖼", - "application/zip" : "🗜️", - "application/x-zip-compressed" : "🗜️", - "application/x-tar" : "🗄", - "application/x-cpio" : "🗄", - "application/x-xz" : "🗜️", - "application/x-7z-compressed" : "🗜️", - "application/gzip" : "🗜️", - "application/zstd" : "🗜️", - "application/x-rar" : "🗜️", - "application/x-rar-compressed" : "🗜️", - "application/vnd.ms-cab-compressed" : "🗜️", - "application/x-bzip2" : "🗜️", - "application/x-lzip" : "🗜️", - "application/x-iso9660-image" : "💿", - "application/pdf" : "📕", - "application/epub+zip" : "📕", - "application/mxf" : "🎞", - "application/vnd.android.package-archive" : "📦", - "application/vnd.debian.binary-package" : "📦", - "application/x-rpm" : "📦", - "application/x-dosexec" : "⚙", - "application/x-execuftable" : "⚙", - "application/x-sharedlib" : "⚙", - "application/java-archive" : "☕", - "application/x-qemu-disk" : "🖴", - "application/pgp-encrypted" : "🔏", + "audio": "🔈", + "video": "🎞", + "text": "📄", + "image": "🖼", + "application/zip": "🗜️", + "application/x-zip-compressed": "🗜️", + "application/x-tar": "🗄", + "application/x-cpio": "🗄", + "application/x-xz": "🗜️", + "application/x-7z-compressed": "🗜️", + "application/gzip": "🗜️", + "application/zstd": "🗜️", + "application/x-rar": "🗜️", + "application/x-rar-compressed": "🗜️", + "application/vnd.ms-cab-compressed": "🗜️", + "application/x-bzip2": "🗜️", + "application/x-lzip": "🗜️", + "application/x-iso9660-image": "💿", + "application/pdf": "📕", + "application/epub+zip": "📕", + "application/mxf": "🎞", + "application/vnd.android.package-archive": "📦", + "application/vnd.debian.binary-package": "📦", + "application/x-rpm": "📦", + "application/x-dosexec": "⚙", + "application/x-execuftable": "⚙", + "application/x-sharedlib": "⚙", + "application/java-archive": "☕", + "application/x-qemu-disk": "🖴", + "application/pgp-encrypted": "🔏", } -MIMECategory = Enum("MIMECategory", - ["Archive", "Text", "AV", "Document", "Fallback"] -) +MIMECategory = Enum("MIMECategory", ["Archive", "Text", "AV", "Document", + "Fallback"]) + class MIMEHandler: def __init__(self): self.handlers = { - MIMECategory.Archive : [[ + MIMECategory.Archive: [[ "application/zip", "application/x-zip-compressed", "application/x-tar", @@ -62,31 +62,31 @@ class MIMEHandler: "application/java-archive", "application/vnd.openxmlformats" ], []], - MIMECategory.Text : [[ + MIMECategory.Text: [[ "text", "application/json", "application/xml", ], []], - MIMECategory.AV : [[ + MIMECategory.AV: [[ "audio", "video", "image", "application/mxf" ], []], - MIMECategory.Document : [[ + MIMECategory.Document: [[ "application/pdf", "application/epub", "application/x-mobipocket-ebook", ], []], - MIMECategory.Fallback : [[], []] + MIMECategory.Fallback: [[], []] } self.exceptions = { - MIMECategory.Archive : { - ".cbz" : MIMECategory.Document, - ".xps" : MIMECategory.Document, - ".epub" : MIMECategory.Document, + MIMECategory.Archive: { + ".cbz": MIMECategory.Document, + ".xps": MIMECategory.Document, + ".epub": MIMECategory.Document, }, - MIMECategory.Text : { - ".fb2" : MIMECategory.Document, + MIMECategory.Text: { + ".fb2": MIMECategory.Document, } } @@ -115,12 +115,14 @@ class MIMEHandler: cat = getcat(mime) for handler in self.handlers[cat][1]: try: - if handler(cat): return + if handler(cat): + return except: pass for handler in self.handlers[MIMECategory.Fallback][1]: try: - if handler(None): return + if handler(None): + return except: pass raise RuntimeError(f"Unhandled MIME type category: {cat}") 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: diff --git a/modui/notification.py b/modui/notification.py index ecae6e4..4866130 100644 --- a/modui/notification.py +++ b/modui/notification.py @@ -1,5 +1,6 @@ from textual.widgets import Static + class Notification(Static): def on_mount(self) -> None: self.set_timer(3, self.remove) |
