Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search UI overhaul #807

Merged
merged 23 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ef311e5
Move search to main view instead of the popover
rdbende Dec 2, 2023
ad6c5c6
Simplify `split_strings_to_set` function
rdbende Dec 2, 2023
79427eb
Forgot to add these files
rdbende Dec 2, 2023
33944e4
Merge branch 'master' into search-page
rdbende Dec 3, 2023
3e70c78
Display result box only after it's been populated
rdbende Dec 3, 2023
4e9e56d
Remove row_type parameter from _populate_listbox method
rdbende Dec 4, 2023
1bc1027
Remove old code
rdbende Dec 9, 2023
969515a
invert ifs
rdbende Dec 9, 2023
eed3e55
Annotations
rdbende Dec 9, 2023
22852e7
Format files
rdbende Dec 9, 2023
86d27e8
Disable play pause action while searching
rdbende Dec 10, 2023
657e159
Add Ctrl+f as search action accelerator
rdbende Dec 10, 2023
0aec725
Use <primary> instead of <Control>
rdbende Dec 10, 2023
1c390be
nice try, but I obviously messed up everything I could
rdbende Dec 10, 2023
7f17801
Merge remote-tracking branch 'geigi/master' into search-page
rdbende Jan 4, 2024
f2062a2
Accindental empty newline whoopsie
rdbende Jan 4, 2024
f4bf991
Update cozy/ui/widgets/search_results.py
rdbende Jan 5, 2024
664b1ce
Update to new symbolic icon
rdbende Jan 6, 2024
93d695a
Refactor query of online books
rdbende Jan 6, 2024
fb1c7a2
Search thread doesn't need to be named
rdbende Jan 6, 2024
016bfea
Merge branch 'master' of github.com:geigi/cozy into search-page
rdbende Jan 6, 2024
5cd1ccf
We don't even need an event anymore
rdbende Jan 6, 2024
8b4c597
Don't return a new set when we're showing every books anyway
rdbende Jan 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

11 changes: 9 additions & 2 deletions cozy/ui/headerbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@
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 gi.repository import Adw, Gtk, GObject

log = logging.getLogger("Headerbar")

COVER_SIZE = 45


@Gtk.Template.from_resource('/com/github/geigi/cozy/headerbar.ui')
class Headerbar(Adw.Bin):
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 @@ -44,6 +47,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 +70,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
Loading