Clicking on the results goes to them
This commit is contained in:
@@ -2,6 +2,7 @@ import os
|
||||
import math
|
||||
import random
|
||||
|
||||
from collections import namedtuple
|
||||
from os import environ
|
||||
|
||||
import gi
|
||||
@@ -132,6 +133,7 @@ class SublimeMusicApp(Gtk.Application):
|
||||
self.window.connect('song-clicked', self.on_song_clicked)
|
||||
self.window.connect('songs-removed', self.on_songs_removed)
|
||||
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(
|
||||
'device-update', self.on_device_update)
|
||||
@@ -447,6 +449,13 @@ class SublimeMusicApp(Gtk.Application):
|
||||
self.reset_state()
|
||||
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()
|
||||
def on_play_pause(self, *args):
|
||||
if self.state.current_song_index < 0:
|
||||
@@ -541,10 +550,11 @@ class SublimeMusicApp(Gtk.Application):
|
||||
self.update_window()
|
||||
|
||||
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()
|
||||
self.state.current_album_sort = 'byGenre'
|
||||
self.state.current_album_genre = album.genre
|
||||
self.state.current_album_sort = 'byYear'
|
||||
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.current_tab = 'albums'
|
||||
self.update_window(force=True)
|
||||
|
@@ -26,8 +26,15 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
GObject.TYPE_NONE,
|
||||
(object, bool),
|
||||
),
|
||||
'go-to': (
|
||||
GObject.SignalFlags.RUN_FIRST,
|
||||
GObject.TYPE_NONE,
|
||||
(str, str),
|
||||
),
|
||||
}
|
||||
|
||||
browse_by_tags: bool = False
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.set_default_size(1150, 768)
|
||||
@@ -62,6 +69,8 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
self.connect('button-release-event', self.on_button_release)
|
||||
|
||||
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.
|
||||
if state.config.current_server >= 0:
|
||||
server_name = state.config.servers[
|
||||
@@ -135,10 +144,12 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
|
||||
return header
|
||||
|
||||
def create_label(self, text):
|
||||
def create_label(self, text, *args, **kwargs):
|
||||
label = Gtk.Label(
|
||||
label=text,
|
||||
halign=Gtk.Align.START,
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
label.get_style_context().add_class('search-result-row')
|
||||
return label
|
||||
@@ -146,7 +157,8 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
def create_menu(self):
|
||||
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(
|
||||
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()
|
||||
|
||||
return False
|
||||
|
||||
def on_menu_clicked(self, button):
|
||||
self.menu.popup()
|
||||
self.menu.show_all()
|
||||
@@ -263,7 +277,10 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
|
||||
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(
|
||||
create_search_callback(self.search_idx))
|
||||
|
||||
@@ -278,22 +295,36 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
for c in widget.get_children():
|
||||
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):
|
||||
# Albums
|
||||
self.remove_all_from_widget(self.album_results)
|
||||
for album in search_results.album or []:
|
||||
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
|
||||
self.remove_all_from_widget(self.artist_results)
|
||||
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
|
||||
self.remove_all_from_widget(self.song_results)
|
||||
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()
|
||||
|
||||
|
Reference in New Issue
Block a user