Toggle watch status with [W]

This commit is contained in:
Jan Hamal Dvořák 2025-03-09 10:08:26 +01:00
parent a511dae284
commit 7355fc6a19
2 changed files with 24 additions and 6 deletions

View file

@ -304,7 +304,7 @@ class MainWindow(Gtk.ApplicationWindow):
success, duration = self.pipeline.query_duration(Gst.Format.TIME)
if success:
self.pipeline.seek_simple(
Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, duration - 1
Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, duration
)
return True
@ -314,6 +314,22 @@ class MainWindow(Gtk.ApplicationWindow):
return False
def _toggle_watched_status(self) -> None:
"""Toggle watched status for the selected file"""
file_item = self.selection
if file_item.file_type == FileType.DIRECTORY:
return
position = file_item.load_attribute("position", 0)
duration = file_item.load_attribute("duration", 1)
# If position exists and is >= 90% through, clear it
if position > 0 and (position / duration) >= 0.9:
file_item.save_attribute("position", None)
else:
# Otherwise mark as complete
file_item.save_attribute("position", duration)
def _on_menu_key_pressed(
self,
keyval: int,
@ -324,6 +340,10 @@ class MainWindow(Gtk.ApplicationWindow):
self.close()
return True
elif keyval == Gdk.keyval_from_name("w"):
self._toggle_watched_status()
return True
return False
def _on_key_pressed(

View file

@ -1,7 +1,6 @@
from __future__ import annotations
import os
import sys
from enum import Enum, auto
from typing import overload
@ -52,8 +51,7 @@ class FileItem(GObject.Object):
try:
strval = os.getxattr(self.full_path, f"user.lazy_player.{name}")
return type(dfl)(strval)
except OSError as err:
print(err, file=sys.stderr)
except OSError:
return dfl
def save_attribute(self, name: str, value: str | float | int | None) -> None:
@ -62,5 +60,5 @@ class FileItem(GObject.Object):
os.removexattr(self.full_path, f"user.lazy_player.{name}")
else:
os.setxattr(self.full_path, f"user.lazy_player.{name}", str(value).encode("utf8"))
except OSError as err:
print(err, file=sys.stderr)
except OSError:
pass