Compare commits

..

No commits in common. "6d09b7d1e7c57b596ad3d927adbc885848b860f7" and "f89623a201f8277aaf722691e75e8b7456054f6b" have entirely different histories.

3 changed files with 17 additions and 77 deletions

View file

@ -217,8 +217,8 @@ class MainWindow(Gtk.ApplicationWindow):
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
box.set_spacing(8) box.set_spacing(8)
# Create icon image # Create icon placeholder
icon = Gtk.Image() icon = Gtk.Box()
icon.set_css_classes(["file-icon"]) icon.set_css_classes(["file-icon"])
box.append(icon) box.append(icon)
@ -231,29 +231,12 @@ class MainWindow(Gtk.ApplicationWindow):
def _bind_list_item(self, factory: Gtk.SignalListItemFactory, list_item: Gtk.ListItem): def _bind_list_item(self, factory: Gtk.SignalListItemFactory, list_item: Gtk.ListItem):
box = cast(Gtk.Box, list_item.get_child()) box = cast(Gtk.Box, list_item.get_child())
icon = cast(Gtk.Image, box.get_first_child()) icon = cast(Gtk.Box, box.get_first_child())
label = cast(Gtk.Label, box.get_last_child()) label = cast(Gtk.Label, box.get_last_child())
item = cast(FileItem, list_item.get_item()) item = cast(FileItem, list_item.get_item())
# Set appropriate icon # Make icon transparent for directories
icon.set_opacity(1.0) icon.set_opacity(0.0 if item.file_type == FileType.DIRECTORY else 1.0)
if item.file_type == FileType.DIRECTORY:
icon.set_from_icon_name("folder-symbolic")
icon.set_css_classes(["file-icon"])
else:
position = item.load_attribute("position", 0)
duration = item.load_attribute("duration", 1) or 1
if position == 0:
icon.set_from_icon_name("checkbox-symbolic")
icon.set_css_classes(["file-icon", "unwatched"])
elif (position / duration) >= 0.9:
icon.set_from_icon_name("object-select-symbolic")
icon.set_css_classes(["file-icon", "completed"])
else:
icon.set_from_icon_name("media-playback-pause-symbolic")
icon.set_css_classes(["file-icon", "in-progress"])
label.set_text(item.name) label.set_text(item.name)
def _on_selection_changed( def _on_selection_changed(
@ -321,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 Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, duration - 1
) )
return True return True
@ -331,41 +314,6 @@ 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) or 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)
# Force the list to update the changed item
self.list_store.items_changed(self.selection_model.get_selected(), 1, 1)
def _on_menu_key_pressed(
self,
keyval: int,
keycode: int,
state: Gdk.ModifierType,
) -> bool:
if keyval == Gdk.keyval_from_name("q"):
self.close()
return True
elif keyval == Gdk.keyval_from_name("w"):
self._toggle_watched_status()
return True
return False
def _on_key_pressed( def _on_key_pressed(
self, self,
controller: Gtk.EventControllerKey, controller: Gtk.EventControllerKey,
@ -373,11 +321,10 @@ class MainWindow(Gtk.ApplicationWindow):
keycode: int, keycode: int,
state: Gdk.ModifierType, state: Gdk.ModifierType,
) -> bool: ) -> bool:
# Handle keys differently based on which view is active # If we're showing video, handle keys differently
if self.stack.get_visible_child_name() == "overlay": if self.stack.get_visible_child_name() == "overlay":
return self._on_video_key_pressed(keyval, keycode, state) return self._on_video_key_pressed(keyval, keycode, state)
else: return False
return self._on_menu_key_pressed(keyval, keycode, state)
def _seek_relative(self, offset: int) -> None: def _seek_relative(self, offset: int) -> None:
"""Seek relative to current position by offset seconds""" """Seek relative to current position by offset seconds"""

View file

@ -1,6 +1,7 @@
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
@ -51,7 +52,8 @@ 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: except OSError as err:
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:
@ -60,5 +62,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: except OSError as err:
pass print(err, file=sys.stderr)

View file

@ -5,19 +5,10 @@ listview > row {
} }
.file-icon { .file-icon {
-gtk-icon-size: 24px; min-width: 32px;
} min-height: 32px;
margin-right: 8px;
.unwatched { border: 1px solid #666;
color: #666;
}
.in-progress {
color: #ff0;
}
.completed {
color: #0f0;
} }
#black-overlay { #black-overlay {