Clicking on the results goes to them

This commit is contained in:
Sumner Evans
2019-12-28 21:46:40 -07:00
parent 7744356a47
commit 026b147f7f
2 changed files with 50 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ import os
import math import math
import random import random
from collections import namedtuple
from os import environ from os import environ
import gi import gi
@@ -132,6 +133,7 @@ class SublimeMusicApp(Gtk.Application):
self.window.connect('song-clicked', self.on_song_clicked) self.window.connect('song-clicked', self.on_song_clicked)
self.window.connect('songs-removed', self.on_songs_removed) self.window.connect('songs-removed', self.on_songs_removed)
self.window.connect('refresh-window', self.on_refresh_window) self.window.connect('refresh-window', self.on_refresh_window)
self.window.connect('go-to', self.on_window_go_to)
self.window.player_controls.connect('song-scrub', self.on_song_scrub) self.window.player_controls.connect('song-scrub', self.on_song_scrub)
self.window.player_controls.connect( self.window.player_controls.connect(
'device-update', self.on_device_update) 'device-update', self.on_device_update)
@@ -447,6 +449,13 @@ class SublimeMusicApp(Gtk.Application):
self.reset_state() self.reset_state()
dialog.destroy() dialog.destroy()
def on_window_go_to(self, win, action, value):
{
'album': self.on_go_to_album,
'artist': self.on_go_to_artist,
'playlist': self.on_go_to_playlist,
}[action](None, GLib.Variant('s', value))
@dbus_propagate() @dbus_propagate()
def on_play_pause(self, *args): def on_play_pause(self, *args):
if self.state.current_song_index < 0: if self.state.current_song_index < 0:
@@ -541,10 +550,11 @@ class SublimeMusicApp(Gtk.Application):
self.update_window() self.update_window()
def on_go_to_album(self, action, album_id): def on_go_to_album(self, action, album_id):
# Switch to the By Genre view to guarantee that the album is there. # Switch to the By Year view to guarantee that the album is there.
album = CacheManager.get_album(album_id.get_string()).result() album = CacheManager.get_album(album_id.get_string()).result()
self.state.current_album_sort = 'byGenre' self.state.current_album_sort = 'byYear'
self.state.current_album_genre = album.genre self.state.current_album_from_year = album.year
self.state.current_album_to_year = album.year
self.state.selected_album_id = album_id.get_string() self.state.selected_album_id = album_id.get_string()
self.state.current_tab = 'albums' self.state.current_tab = 'albums'
self.update_window(force=True) self.update_window(force=True)

View File

@@ -26,8 +26,15 @@ class MainWindow(Gtk.ApplicationWindow):
GObject.TYPE_NONE, GObject.TYPE_NONE,
(object, bool), (object, bool),
), ),
'go-to': (
GObject.SignalFlags.RUN_FIRST,
GObject.TYPE_NONE,
(str, str),
),
} }
browse_by_tags: bool = False
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.set_default_size(1150, 768) self.set_default_size(1150, 768)
@@ -62,6 +69,8 @@ class MainWindow(Gtk.ApplicationWindow):
self.connect('button-release-event', self.on_button_release) self.connect('button-release-event', self.on_button_release)
def update(self, state: ApplicationState, force=False): def update(self, state: ApplicationState, force=False):
self.browse_by_tags = state.config.server.browse_by_tags
# Update the Connected to label on the popup menu. # Update the Connected to label on the popup menu.
if state.config.current_server >= 0: if state.config.current_server >= 0:
server_name = state.config.servers[ server_name = state.config.servers[
@@ -135,10 +144,12 @@ class MainWindow(Gtk.ApplicationWindow):
return header return header
def create_label(self, text): def create_label(self, text, *args, **kwargs):
label = Gtk.Label( label = Gtk.Label(
label=text, label=text,
halign=Gtk.Align.START, halign=Gtk.Align.START,
*args,
**kwargs,
) )
label.get_style_context().add_class('search-result-row') label.get_style_context().add_class('search-result-row')
return label return label
@@ -146,7 +157,8 @@ class MainWindow(Gtk.ApplicationWindow):
def create_menu(self): def create_menu(self):
self.menu = Gtk.PopoverMenu() self.menu = Gtk.PopoverMenu()
self.connected_to_label = Gtk.Label(name='connected-to-label') self.connected_to_label = self.create_label(
'', name='connected-to-label')
self.connected_to_label.set_markup( self.connected_to_label.set_markup(
f'<span style="italic">Not Connected to a Server</span>') f'<span style="italic">Not Connected to a Server</span>')
@@ -233,6 +245,8 @@ class MainWindow(Gtk.ApplicationWindow):
): ):
self.player_controls.play_queue_popover.popdown() self.player_controls.play_queue_popover.popdown()
return False
def on_menu_clicked(self, button): def on_menu_clicked(self, button):
self.menu.popup() self.menu.popup()
self.menu.show_all() self.menu.show_all()
@@ -263,7 +277,10 @@ class MainWindow(Gtk.ApplicationWindow):
return lambda f: GLib.idle_add(search_done, f) return lambda f: GLib.idle_add(search_done, f)
search_future = CacheManager.search2(entry.get_text()) search_fn = (
CacheManager.search3
if self.browse_by_tags else CacheManager.search2)
search_future = search_fn(entry.get_text())
search_future.add_done_callback( search_future.add_done_callback(
create_search_callback(self.search_idx)) create_search_callback(self.search_idx))
@@ -278,22 +295,36 @@ class MainWindow(Gtk.ApplicationWindow):
for c in widget.get_children(): for c in widget.get_children():
widget.remove(c) widget.remove(c)
def create_search_result_row(self, text, action_name, value):
row = Gtk.Button(relief=Gtk.ReliefStyle.NONE)
row.add(self.create_label(text))
row.connect(
'button-press-event',
lambda *a: self.emit('go-to', action_name, value),
)
return row
def update_search_results(self, search_results): def update_search_results(self, search_results):
# Albums # Albums
self.remove_all_from_widget(self.album_results) self.remove_all_from_widget(self.album_results)
for album in search_results.album or []: for album in search_results.album or []:
name = album.title if type(album) == Child else album.name name = album.title if type(album) == Child else album.name
self.album_results.add(self.create_label(name)) self.album_results.add(
self.create_search_result_row(name, 'album', album.id))
# Artists # Artists
self.remove_all_from_widget(self.artist_results) self.remove_all_from_widget(self.artist_results)
for artist in search_results.artist or []: for artist in search_results.artist or []:
self.artist_results.add(self.create_label(artist.name)) self.artist_results.add(
self.create_search_result_row(
artist.name, 'artist', artist.id))
# Songs # Songs
self.remove_all_from_widget(self.song_results) self.remove_all_from_widget(self.song_results)
for song in search_results.song or []: for song in search_results.song or []:
self.song_results.add(self.create_label(song.title)) self.song_results.add(
self.create_search_result_row(
song.title, 'album', song.albumId))
self.search_popup.show_all() self.search_popup.show_all()