Skip to content

Commit

Permalink
Merge pull request #807 from rdbende/search-page
Browse files Browse the repository at this point in the history
Search UI overhaul
  • Loading branch information
geigi authored Jan 19, 2024
2 parents 7a7577b + 8b4c597 commit 4d5df20
Show file tree
Hide file tree
Showing 17 changed files with 507 additions and 753 deletions.
15 changes: 9 additions & 6 deletions cozy/app_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ def __init__(self, gtk_app, main_window_builder, main_window):

self.whats_new_window: WhatsNewWindow = WhatsNewWindow()

self.library_view: LibraryView = LibraryView(main_window_builder)
self.app_view: AppView = AppView(main_window_builder)
self.search_view: SearchView = SearchView()
self.book_detail_view: BookDetailView = BookDetailView(main_window_builder)
self.headerbar: Headerbar = Headerbar(main_window_builder)
self.library_view: LibraryView = LibraryView(main_window_builder)
self.book_detail_view: BookDetailView = BookDetailView(main_window_builder)
self.media_controller: MediaController = MediaController(main_window_builder)
self.search_view: SearchView = SearchView(main_window_builder, self.headerbar)

self.library_view_model = inject.instance(LibraryViewModel)
self.app_view_model = inject.instance(AppViewModel)
Expand All @@ -68,7 +68,7 @@ def __init__(self, gtk_app, main_window_builder, main_window):
self.settings_view_model = inject.instance(SettingsViewModel)
self.player = inject.instance(Player)

self._connect_popovers()
self._connect_search_button()

self.search_view_model.add_listener(self._on_open_view)
self.book_detail_view_model.add_listener(self._on_open_view)
Expand Down Expand Up @@ -125,8 +125,11 @@ def open_library(self):
self.library_view_model.open_library()
self.app_view_model.view = View.LIBRARY_FILTER

def _connect_popovers(self):
self.headerbar.search_button.set_popover(self.search_view.popover)
def _connect_search_button(self):
self.headerbar.search_button.connect(
"notify::active",
self.search_view.on_state_changed
)

def _on_open_view(self, event, data):
if event == OpenView.AUTHOR:
Expand Down
15 changes: 2 additions & 13 deletions cozy/extensions/set.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import re
from typing import Set


def split_strings_to_set(set_to_split: Set[str]):
finished = set()
for entry in set_to_split:
results = re.split(",|;|/|&", entry)
results = {
entry.strip()
for entry in results
}

finished.update(results)

return finished
def split_strings_to_set(set_to_split: set[str]) -> set[str]:
return {entry.strip() for item in set_to_split for entry in re.split(",|;|/|&", item)}
22 changes: 4 additions & 18 deletions cozy/ui/delete_book_view.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from gi.repository import Adw, Gtk

from cozy.ext import inject
from cozy.control.artwork_cache import ArtworkCache
from cozy.model.book import Book
from cozy.ui.widgets.book_row import BookRow


class DeleteBookView(Adw.MessageDialog):
main_window = inject.attr("MainWindow")
artwork_cache: ArtworkCache = inject.attr(ArtworkCache)

def __init__(self, callback, book):
def __init__(self, callback, book: Book):
super().__init__(
heading=_("Delete Audiobook?"),
body=_("The audiobook will be removed from your disk and from Cozy's library."),
Expand All @@ -22,22 +22,8 @@ def __init__(self, callback, book):
self.add_response("delete", _("Remove Audiobook"))
self.set_response_appearance("delete", Adw.ResponseAppearance.DESTRUCTIVE)

book_row = Adw.ActionRow(
title=book.name,
subtitle=book.author,
selectable=False,
use_markup=False,
)
album_art = Gtk.Picture(margin_top=6, margin_bottom=6)

paintable = self.artwork_cache.get_cover_paintable(book, 1, 48)
if paintable:
album_art.set_paintable(paintable)
book_row.add_prefix(album_art)

list_box = Gtk.ListBox(margin_top=12, css_classes=["boxed-list"])
list_box.append(book_row)
list_box.append(BookRow(book))
self.set_extra_child(list_box)

self.connect("response", callback, book)

23 changes: 14 additions & 9 deletions cozy/ui/headerbar.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import logging

import gi
from gi.repository import Adw, Gtk

from cozy.ext import inject
from cozy.ui.widgets.progress_popover import ProgressPopover
from cozy.view_model.headerbar_view_model import HeaderbarViewModel, HeaderBarState

from gi.repository import Adw, Gtk
from cozy.view_model.headerbar_view_model import HeaderBarState, HeaderbarViewModel

log = logging.getLogger("Headerbar")

COVER_SIZE = 45


@Gtk.Template.from_resource('/com/github/geigi/cozy/headerbar.ui')
class Headerbar(Adw.Bin):
@Gtk.Template.from_resource("/com/github/geigi/cozy/headerbar.ui")
class Headerbar(Gtk.Box):
__gtype_name__ = "Headerbar"

headerbar: Adw.HeaderBar = Gtk.Template.Child()

search_bar: Gtk.SearchBar = Gtk.Template.Child()
search_entry: Gtk.SearchEntry = Gtk.Template.Child()

show_sidebar_button: Gtk.ToggleButton = Gtk.Template.Child()
search_button: Gtk.MenuButton = Gtk.Template.Child()
menu_button: Gtk.MenuButton = Gtk.Template.Child()
Expand All @@ -34,7 +33,9 @@ def __init__(self, main_window_builder: Gtk.Builder):
self.header_container: Adw.ToolbarView = main_window_builder.get_object("header_container")
self.header_container.add_top_bar(self)

self.mobile_view_switcher: Adw.ViewSwitcherBar = main_window_builder.get_object("mobile_view_switcher")
self.mobile_view_switcher: Adw.ViewSwitcherBar = main_window_builder.get_object(
"mobile_view_switcher"
)
self.split_view: Adw.OverlaySplitView = main_window_builder.get_object("split_view")

self.sort_stack: Adw.ViewStack = main_window_builder.get_object("sort_stack")
Expand All @@ -44,6 +45,9 @@ def __init__(self, main_window_builder: Gtk.Builder):
self.progress_popover = ProgressPopover()
self.progress_menu_button.set_popover(self.progress_popover)

self.search_bar.connect_entry(self.search_entry)
self.search_bar.set_key_capture_widget(self.header_container)

self._headerbar_view_model: HeaderbarViewModel = inject.instance(HeaderbarViewModel)
self._connect_view_model()
self._connect_widgets()
Expand All @@ -64,6 +68,7 @@ def _on_sort_stack_changed(self, widget, _):
page = widget.props.visible_child_name

self.show_sidebar_button.set_visible(page != "recent")
self.search_button.set_active(False)

def _on_mobile_view(self, widget, _):
if widget.props.reveal:
Expand Down
64 changes: 28 additions & 36 deletions cozy/ui/main_view.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging
import os
import webbrowser
from threading import Thread
from collections import defaultdict
from threading import Thread
from typing import Callable

from gi.repository import Adw, Gtk, Gio, Gdk, GLib, GObject
from gi.repository import Adw, Gdk, Gio, GLib, Gtk

import cozy.control.filesystem_monitor as fs_monitor
import cozy.ext.inject as inject
Expand All @@ -13,15 +13,13 @@
from cozy.architecture.event_sender import EventSender
from cozy.architecture.singleton import Singleton
from cozy.control.db import books, close_db
from cozy.db.storage import Storage
from cozy.media.files import Files
from cozy.media.importer import Importer, ScanStatus
from cozy.media.player import Player
from cozy.model.settings import Settings as SettingsModel
from cozy.view_model.settings_view_model import SettingsViewModel
from cozy.open_view import OpenView
from cozy.ui.library_view import LibraryView
from cozy.ui.preferences_view import PreferencesView
from cozy.view_model.settings_view_model import SettingsViewModel

log = logging.getLogger("ui")

Expand Down Expand Up @@ -126,39 +124,33 @@ def __init_actions(self):
self.app.add_action(about_action)
self.app.set_accels_for_action("app.about", ["F1"])

quit_action = Gio.SimpleAction.new("quit", None)
quit_action.connect("activate", self.quit)
self.app.add_action(quit_action)
self.app.set_accels_for_action(
"app.quit", ["<Control>q", "<Control>w"])

pref_action = Gio.SimpleAction.new("prefs", None)
pref_action.connect("activate", self.show_prefs)
self.app.add_action(pref_action)
self.app.set_accels_for_action("app.prefs", ["<Control>comma"])

self.scan_action = Gio.SimpleAction.new("scan", None)
self.scan_action.connect("activate", self.scan)
self.app.add_action(self.scan_action)

self.play_pause_action = Gio.SimpleAction.new("play_pause", None)
self.play_pause_action.connect("activate", self.play_pause)
self.app.add_action(self.play_pause_action)
self.app.set_accels_for_action("app.play_pause", ["space"])

# NavigationView.pop-on-escape doesn't work in some cases, so this is a hack
back_action = Gio.SimpleAction.new("back", None)
back_action.connect("activate", lambda *_: self.navigation_view.pop())
self.app.add_action(back_action)
self.app.set_accels_for_action("app.back", ["Escape"])

self.hide_offline_action = Gio.SimpleAction.new_stateful("hide_offline",
None,
GLib.Variant.new_boolean(
self.application_settings.hide_offline))
self.create_action("about", self.about)
self.create_action("quit", self.quit, ["<primary>q", "<primary>w"])
self.create_action("prefs", self.show_prefs, ["<primary>comma"])
self.create_action("scan", self.scan)
self.play_pause_action = self.create_action("play_pause", self.play_pause, ["space"])

self.hide_offline_action = Gio.SimpleAction.new_stateful(
"hide_offline", None, GLib.Variant.new_boolean(self.application_settings.hide_offline)
)
self.hide_offline_action.connect("change-state", self.__on_hide_offline)
self.app.add_action(self.hide_offline_action)

def create_action(
self,
name: str,
callback: Callable[[Gio.SimpleAction, None], None],
shortcuts: list[str] | None = None,
) -> Gio.SimpleAction:
action = Gio.SimpleAction.new(name, None)
action.connect("activate", callback)
self.app.add_action(action)

if shortcuts:
self.app.set_accels_for_action(f"app.{name}", shortcuts)

return action

def __init_components(self):
if not self._player.loaded_book:
self.block_ui_buttons(True)
Expand Down
Loading

0 comments on commit 4d5df20

Please sign in to comment.