Toggle watch status with [W]
This commit is contained in:
parent
a511dae284
commit
7355fc6a19
2 changed files with 24 additions and 6 deletions
lazy_player
|
@ -304,7 +304,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
success, duration = self.pipeline.query_duration(Gst.Format.TIME)
|
success, duration = self.pipeline.query_duration(Gst.Format.TIME)
|
||||||
if success:
|
if success:
|
||||||
self.pipeline.seek_simple(
|
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
|
return True
|
||||||
|
|
||||||
|
@ -314,6 +314,22 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
|
|
||||||
return False
|
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(
|
def _on_menu_key_pressed(
|
||||||
self,
|
self,
|
||||||
keyval: int,
|
keyval: int,
|
||||||
|
@ -324,6 +340,10 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
self.close()
|
self.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
elif keyval == Gdk.keyval_from_name("w"):
|
||||||
|
self._toggle_watched_status()
|
||||||
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _on_key_pressed(
|
def _on_key_pressed(
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
from typing import overload
|
from typing import overload
|
||||||
|
|
||||||
|
@ -52,8 +51,7 @@ class FileItem(GObject.Object):
|
||||||
try:
|
try:
|
||||||
strval = os.getxattr(self.full_path, f"user.lazy_player.{name}")
|
strval = os.getxattr(self.full_path, f"user.lazy_player.{name}")
|
||||||
return type(dfl)(strval)
|
return type(dfl)(strval)
|
||||||
except OSError as err:
|
except OSError:
|
||||||
print(err, file=sys.stderr)
|
|
||||||
return dfl
|
return dfl
|
||||||
|
|
||||||
def save_attribute(self, name: str, value: str | float | int | None) -> None:
|
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}")
|
os.removexattr(self.full_path, f"user.lazy_player.{name}")
|
||||||
else:
|
else:
|
||||||
os.setxattr(self.full_path, f"user.lazy_player.{name}", str(value).encode("utf8"))
|
os.setxattr(self.full_path, f"user.lazy_player.{name}", str(value).encode("utf8"))
|
||||||
except OSError as err:
|
except OSError:
|
||||||
print(err, file=sys.stderr)
|
pass
|
||||||
|
|
Loading…
Reference in a new issue