WIP
This commit is contained in:
@@ -14,8 +14,9 @@ from ..adapters import (
|
||||
Result,
|
||||
)
|
||||
from ..config import AppConfiguration
|
||||
from ..ui import util
|
||||
from ..ui.common import AlbumWithSongs, IconButton, LoadError, SpinnerImage, Sizer
|
||||
from . import util
|
||||
from .common import AlbumWithSongs, IconButton, LoadError, SpinnerImage, Sizer
|
||||
from .actions import run_action
|
||||
|
||||
|
||||
COVER_ART_WIDTH = 150
|
||||
@@ -50,28 +51,12 @@ def _from_str(type_str: str) -> AlbumSearchQuery.Type:
|
||||
|
||||
|
||||
class AlbumsPanel(Handy.Leaflet):
|
||||
__gsignals__ = {
|
||||
"song-clicked": (
|
||||
GObject.SignalFlags.RUN_FIRST,
|
||||
GObject.TYPE_NONE,
|
||||
(int, object, object),
|
||||
),
|
||||
"refresh-window": (
|
||||
GObject.SignalFlags.RUN_FIRST,
|
||||
GObject.TYPE_NONE,
|
||||
(object, bool),
|
||||
),
|
||||
}
|
||||
|
||||
current_query: AlbumSearchQuery = AlbumSearchQuery(AlbumSearchQuery.Type.RANDOM)
|
||||
offline_mode = False
|
||||
provider_id: Optional[str] = None
|
||||
|
||||
populating_genre_combo = False
|
||||
album_sort_direction: str = "ascending"
|
||||
# album_page_size: int = 30
|
||||
album_page: int = 0
|
||||
grid_pages_count: int = 0
|
||||
|
||||
current_albums_result: Result = None
|
||||
|
||||
@@ -146,14 +131,6 @@ class AlbumsPanel(Handy.Leaflet):
|
||||
self.refresh_button.connect("clicked", self.on_refresh_clicked)
|
||||
actionbar.pack_end(self.refresh_button)
|
||||
|
||||
# actionbar.pack_end(Gtk.Label(label="albums per page"))
|
||||
# self.show_count_dropdown, _ = self.make_combobox(
|
||||
# ((x, x, True) for x in ("20", "30", "40", "50")),
|
||||
# self.on_show_count_dropdown_change,
|
||||
# )
|
||||
# actionbar.pack_end(self.show_count_dropdown)
|
||||
# actionbar.pack_end(Gtk.Label(label="Show"))
|
||||
|
||||
self.grid_box.pack_start(actionbar, False, False, 0)
|
||||
|
||||
# 700 shows ~3 albums
|
||||
@@ -176,47 +153,8 @@ class AlbumsPanel(Handy.Leaflet):
|
||||
selection_mode=Gtk.SelectionMode.SINGLE)
|
||||
self.grid.connect("child-activated", self.on_album_clicked)
|
||||
|
||||
# self.grid.connect(
|
||||
# "song-clicked",
|
||||
# lambda _, *args: self.emit("song-clicked", *args),
|
||||
# )
|
||||
# self.grid.connect(
|
||||
# "refresh-window",
|
||||
# lambda _, *args: self.emit("refresh-window", *args),
|
||||
# )
|
||||
# self.grid.connect("cover-clicked", self.on_album_clicked)
|
||||
# self.grid.connect("num-pages-changed", self.on_grid_num_pages_changed)
|
||||
|
||||
box.add(self.grid)
|
||||
|
||||
bottom_actionbar = Gtk.ActionBar()
|
||||
|
||||
# Add the page widget.
|
||||
page_widget = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
|
||||
self.prev_page = IconButton(
|
||||
"go-previous-symbolic", "Go to the previous page", sensitive=False
|
||||
)
|
||||
self.prev_page.connect("clicked", self.on_prev_page_clicked)
|
||||
page_widget.add(self.prev_page)
|
||||
page_widget.add(Gtk.Label(label="Page"))
|
||||
self.page_entry = Gtk.Entry()
|
||||
self.page_entry.set_width_chars(1)
|
||||
self.page_entry.set_max_width_chars(1)
|
||||
self.page_entry.connect("changed", self.on_page_entry_changed)
|
||||
self.page_entry.connect("insert-text", self.on_page_entry_insert_text)
|
||||
page_widget.add(self.page_entry)
|
||||
page_widget.add(Gtk.Label(label="of"))
|
||||
self.page_count_label = Gtk.Label(label="-")
|
||||
page_widget.add(self.page_count_label)
|
||||
self.next_page = IconButton(
|
||||
"go-next-symbolic", "Go to the next page", sensitive=False
|
||||
)
|
||||
self.next_page.connect("clicked", self.on_next_page_clicked)
|
||||
page_widget.add(self.next_page)
|
||||
bottom_actionbar.set_center_widget(page_widget)
|
||||
|
||||
box.add(bottom_actionbar)
|
||||
|
||||
scrolled_window.add(box)
|
||||
grid_sizer.add(scrolled_window)
|
||||
self.grid_box.pack_start(grid_sizer, True, True, 0)
|
||||
@@ -228,8 +166,6 @@ class AlbumsPanel(Handy.Leaflet):
|
||||
self.album_with_songs = AlbumWithSongs(scroll_contents=True)
|
||||
self.album_with_songs.get_style_context().add_class("details-panel")
|
||||
|
||||
self.album_with_songs.connect("song-clicked", lambda _, *args: self.emit("song-clicked", *args))
|
||||
|
||||
def back_clicked(_):
|
||||
self.set_visible_child(self.grid_box)
|
||||
self.album_with_songs.connect("back-clicked", back_clicked)
|
||||
@@ -336,11 +272,8 @@ class AlbumsPanel(Handy.Leaflet):
|
||||
lambda f: GLib.idle_add(self._albums_loaded, f)
|
||||
)
|
||||
|
||||
if (self.album_sort_direction != app_config.state.album_sort_direction
|
||||
or self.album_page != app_config.state.album_page):
|
||||
|
||||
if self.album_sort_direction != app_config.state.album_sort_direction:
|
||||
self.album_sort_direction = app_config.state.album_sort_direction
|
||||
self.album_page = app_config.state.album_page
|
||||
|
||||
self._update_albums()
|
||||
# self.current_query = app_config.state.current_album_search_query
|
||||
@@ -361,12 +294,8 @@ class AlbumsPanel(Handy.Leaflet):
|
||||
|
||||
# Update the page display
|
||||
if app_config:
|
||||
self.album_page = app_config.state.album_page
|
||||
self.refresh_button.set_sensitive(not app_config.offline_mode)
|
||||
|
||||
self.prev_page.set_sensitive(self.album_page > 0)
|
||||
self.page_entry.set_text(str(self.album_page + 1))
|
||||
|
||||
# Show/hide the combo boxes.
|
||||
def show_if(sort_type: Iterable[AlbumSearchQuery.Type], *elements):
|
||||
for element in elements:
|
||||
@@ -508,85 +437,50 @@ class AlbumsPanel(Handy.Leaflet):
|
||||
return None
|
||||
|
||||
def on_sort_toggle_clicked(self, _):
|
||||
self.emit(
|
||||
"refresh-window",
|
||||
{
|
||||
"album_sort_direction": self._get_opposite_sort_dir(
|
||||
self.album_sort_direction
|
||||
),
|
||||
"album_page": 0,
|
||||
"selected_album_id": None,
|
||||
},
|
||||
False,
|
||||
)
|
||||
run_action(self, 'albums.set-search-query', self.current_query, self._get_opposite_sort_dir(self.album_sort_direction))
|
||||
|
||||
def on_refresh_clicked(self, _):
|
||||
self.emit("refresh-window", {}, True)
|
||||
|
||||
class _Genre(API.Genre):
|
||||
def __init__(self, name: str):
|
||||
self.name = name
|
||||
|
||||
def on_grid_num_pages_changed(self, grid: Any, pages: int):
|
||||
self.grid_pages_count = pages
|
||||
pages_str = str(self.grid_pages_count)
|
||||
self.page_count_label.set_text(pages_str)
|
||||
self.next_page.set_sensitive(self.album_page < self.grid_pages_count - 1)
|
||||
num_digits = len(pages_str)
|
||||
self.page_entry.set_width_chars(num_digits)
|
||||
self.page_entry.set_max_width_chars(num_digits)
|
||||
run_action(self, "app.force-refresh")
|
||||
|
||||
def on_type_combo_changed(self, combo: Gtk.ComboBox):
|
||||
id = self.get_id(combo)
|
||||
assert id
|
||||
if id == "alphabetical":
|
||||
id += "_" + cast(str, self.get_id(self.alphabetical_type_combo))
|
||||
self.emit_if_not_updating(
|
||||
"refresh-window",
|
||||
{
|
||||
"current_album_search_query": AlbumSearchQuery(
|
||||
_from_str(id),
|
||||
self.current_query.year_range,
|
||||
self.current_query.genre,
|
||||
),
|
||||
"album_page": 0,
|
||||
"selected_album_id": None,
|
||||
},
|
||||
False,
|
||||
)
|
||||
run_action(
|
||||
self,
|
||||
'albums.set-search-query',
|
||||
AlbumSearchQuery(
|
||||
_from_str(id),
|
||||
self.current_query.year_range,
|
||||
self.current_query.genre,
|
||||
),
|
||||
self.album_sort_direction)
|
||||
|
||||
def on_alphabetical_type_change(self, combo: Gtk.ComboBox):
|
||||
id = "alphabetical_" + cast(str, self.get_id(combo))
|
||||
self.emit_if_not_updating(
|
||||
"refresh-window",
|
||||
{
|
||||
"current_album_search_query": AlbumSearchQuery(
|
||||
_from_str(id),
|
||||
self.current_query.year_range,
|
||||
self.current_query.genre,
|
||||
),
|
||||
"album_page": 0,
|
||||
"selected_album_id": None,
|
||||
},
|
||||
False,
|
||||
)
|
||||
run_action(
|
||||
self,
|
||||
'albums.set-search-query',
|
||||
AlbumSearchQuery(
|
||||
_from_str(id),
|
||||
self.current_query.year_range,
|
||||
self.current_query.genre,
|
||||
),
|
||||
self.album_sort_direction)
|
||||
|
||||
def on_genre_change(self, combo: Gtk.ComboBox):
|
||||
genre = self.get_id(combo)
|
||||
assert genre
|
||||
self.emit_if_not_updating(
|
||||
"refresh-window",
|
||||
{
|
||||
"current_album_search_query": AlbumSearchQuery(
|
||||
self.current_query.type,
|
||||
self.current_query.year_range,
|
||||
AlbumsPanel._Genre(genre),
|
||||
),
|
||||
"album_page": 0,
|
||||
"selected_album_id": None,
|
||||
},
|
||||
False,
|
||||
)
|
||||
run_action(
|
||||
self,
|
||||
'albums.set-search-query',
|
||||
AlbumSearchQuery(
|
||||
self.current_query.type,
|
||||
self.current_query.year_range,
|
||||
AlbumSearchQuery.Genre(genre),
|
||||
),
|
||||
self.album_sort_direction)
|
||||
|
||||
def on_year_changed(self, entry: Gtk.SpinButton) -> bool:
|
||||
year = int(entry.get_value())
|
||||
@@ -596,27 +490,19 @@ class AlbumsPanel(Handy.Leaflet):
|
||||
else:
|
||||
new_year_tuple = (year, self.current_query.year_range[1])
|
||||
|
||||
self.emit_if_not_updating(
|
||||
"refresh-window",
|
||||
{
|
||||
"current_album_search_query": AlbumSearchQuery(
|
||||
self.current_query.type, new_year_tuple, self.current_query.genre
|
||||
),
|
||||
"album_page": 0,
|
||||
"selected_album_id": None,
|
||||
},
|
||||
False,
|
||||
)
|
||||
run_action(
|
||||
self,
|
||||
'albums.set-search-query',
|
||||
AlbumSearchQuery(
|
||||
self.current_query.type, new_year_tuple, self.current_query.genre
|
||||
),
|
||||
self.album_sort_direction)
|
||||
|
||||
return False
|
||||
|
||||
def on_page_entry_changed(self, entry: Gtk.Entry) -> bool:
|
||||
if len(text := entry.get_text()) > 0:
|
||||
self.emit_if_not_updating(
|
||||
"refresh-window",
|
||||
{"album_page": int(text) - 1, "selected_album_id": None},
|
||||
False,
|
||||
)
|
||||
run_action(self, 'albums.set-page', int(text) - 1)
|
||||
return False
|
||||
|
||||
def on_page_entry_insert_text(
|
||||
@@ -633,50 +519,18 @@ class AlbumsPanel(Handy.Leaflet):
|
||||
return True
|
||||
return False
|
||||
|
||||
def on_prev_page_clicked(self, _):
|
||||
self.emit_if_not_updating(
|
||||
"refresh-window",
|
||||
{"album_page": self.album_page - 1, "selected_album_id": None},
|
||||
False,
|
||||
)
|
||||
|
||||
def on_next_page_clicked(self, _):
|
||||
self.emit_if_not_updating(
|
||||
"refresh-window",
|
||||
{"album_page": self.album_page + 1, "selected_album_id": None},
|
||||
False,
|
||||
)
|
||||
|
||||
def on_album_clicked(self, _:Any, child: Gtk.FlowBoxChild):
|
||||
album = self.albums[child.get_index()]
|
||||
|
||||
if self.get_folded() and self.get_visible_child() == self.grid_box:
|
||||
self.set_visible_child(self.album_container)
|
||||
|
||||
self.emit(
|
||||
"refresh-window",
|
||||
{"selected_album_id": album.id},
|
||||
False,
|
||||
)
|
||||
|
||||
def on_show_count_dropdown_change(self, combo: Gtk.ComboBox):
|
||||
show_count = int(self.get_id(combo) or 30)
|
||||
self.emit(
|
||||
"refresh-window",
|
||||
{"album_page_size": show_count, "album_page": 0},
|
||||
False,
|
||||
)
|
||||
|
||||
def emit_if_not_updating(self, *args):
|
||||
if self.updating_query:
|
||||
return
|
||||
self.emit(*args)
|
||||
|
||||
run_action(self, 'albums.select-album', album.id)
|
||||
|
||||
"""
|
||||
|
||||
# TODO: REMOVE
|
||||
class AlbumsGrid(Gtk.Overlay):
|
||||
"""Defines the albums panel."""
|
||||
|
||||
__gsignals__ = {
|
||||
"cover-clicked": (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE, (object,)),
|
||||
@@ -1155,3 +1009,4 @@ class AlbumsGrid(Gtk.Overlay):
|
||||
self.grid_bottom.unselect_all()
|
||||
|
||||
self.currently_selected_index = selected_index
|
||||
"""
|
||||
|
Reference in New Issue
Block a user