Add black overlay
This commit is contained in:
parent
9f929fd04e
commit
981beffcce
2 changed files with 48 additions and 7 deletions
lazy_player
|
@ -14,6 +14,8 @@ from gi.repository import Gdk, Gst, Gtk # NOQA: E402
|
|||
|
||||
class MainWindow(Gtk.ApplicationWindow):
|
||||
file_info_label: Gtk.Label
|
||||
stack: Gtk.Stack
|
||||
list_view: Gtk.ListView
|
||||
|
||||
def __init__(self, *args: Any, **kwargs: Any):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
@ -22,9 +24,28 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||
self.set_decorated(False)
|
||||
self.fullscreen()
|
||||
|
||||
# Setup key event controller
|
||||
key_controller = Gtk.EventControllerKey()
|
||||
key_controller.connect("key-pressed", self._on_key_pressed)
|
||||
self.add_controller(key_controller)
|
||||
|
||||
# Main horizontal box to split the screen
|
||||
main_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
|
||||
# Create stack to hold our widgets
|
||||
self.stack = Gtk.Stack()
|
||||
|
||||
# Create black overlay
|
||||
overlay_box = Gtk.Box()
|
||||
overlay_box.set_name("black-overlay")
|
||||
overlay_box.set_vexpand(True)
|
||||
overlay_box.set_hexpand(True)
|
||||
|
||||
# Add both main menu and overlay to stack
|
||||
self.stack.add_named(main_box, "menu")
|
||||
self.stack.add_named(overlay_box, "overlay")
|
||||
self.stack.set_visible_child_name("menu")
|
||||
|
||||
# Create a grid to handle the 1:2 ratio
|
||||
grid = Gtk.Grid()
|
||||
grid.set_column_homogeneous(True)
|
||||
|
@ -49,11 +70,11 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||
|
||||
# Create list store and view
|
||||
list_store = Gtk.StringList()
|
||||
list_view = Gtk.ListView()
|
||||
self.list_view = Gtk.ListView()
|
||||
selection_model = Gtk.SingleSelection.new(list_store)
|
||||
selection_model.connect("selection-changed", self._on_selection_changed)
|
||||
list_view.set_model(selection_model)
|
||||
list_view.set_vexpand(True)
|
||||
self.list_view.set_model(selection_model)
|
||||
self.list_view.set_vexpand(True)
|
||||
|
||||
def on_activate(widget: Gtk.ListView, index: int):
|
||||
selected_item = selection_model.get_item(index)
|
||||
|
@ -62,23 +83,25 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||
string = string_obj.get_string()
|
||||
print("activated", string)
|
||||
|
||||
list_view.connect("activate", on_activate)
|
||||
self.stack.set_visible_child_name("overlay")
|
||||
|
||||
self.list_view.connect("activate", on_activate)
|
||||
|
||||
# Factory for list items
|
||||
factory = Gtk.SignalListItemFactory()
|
||||
factory.connect("setup", self._setup_list_item)
|
||||
factory.connect("bind", self._bind_list_item)
|
||||
list_view.set_factory(factory)
|
||||
self.list_view.set_factory(factory)
|
||||
|
||||
# Populate the list store
|
||||
self._populate_file_list(list_store)
|
||||
|
||||
# Add list view to a scrolled window
|
||||
scrolled = Gtk.ScrolledWindow()
|
||||
scrolled.set_child(list_view)
|
||||
scrolled.set_child(self.list_view)
|
||||
right_box.append(scrolled)
|
||||
|
||||
self.set_child(main_box)
|
||||
self.set_child(self.stack)
|
||||
|
||||
def _setup_list_item(self, factory: Gtk.SignalListItemFactory, list_item: Gtk.ListItem):
|
||||
label = Gtk.Label()
|
||||
|
@ -104,6 +127,20 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||
string_obj = cast(Gtk.StringObject, selected_item)
|
||||
self.file_info_label.set_text(string_obj.get_string())
|
||||
|
||||
def _on_key_pressed(
|
||||
self,
|
||||
controller: Gtk.EventControllerKey,
|
||||
keyval: int,
|
||||
keycode: int,
|
||||
state: Gdk.ModifierType,
|
||||
) -> bool:
|
||||
if keyval == Gdk.keyval_from_name("Escape"):
|
||||
self.stack.set_visible_child_name("menu")
|
||||
self.list_view.grab_focus()
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def _populate_file_list(self, list_store: Gtk.StringList) -> None:
|
||||
# TODO: Implement proper version sort (strverscmp equivalent)
|
||||
|
||||
|
|
|
@ -3,3 +3,7 @@ listview > row {
|
|||
font-size: 48px;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
#black-overlay {
|
||||
background-color: black;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue