Run black on entire project
This commit is contained in:
@@ -2,39 +2,32 @@ from datetime import datetime
|
||||
from typing import Any, Callable, Set
|
||||
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gdk, Gio, GLib, GObject, Gtk, Pango
|
||||
|
||||
from sublime.cache_manager import CacheManager, SearchResult
|
||||
from sublime.config import AppConfiguration
|
||||
from sublime.ui import (
|
||||
albums, artists, browse, player_controls, playlists, util)
|
||||
from sublime.ui import albums, artists, browse, player_controls, playlists, util
|
||||
from sublime.ui.common import SpinnerImage
|
||||
|
||||
|
||||
class MainWindow(Gtk.ApplicationWindow):
|
||||
"""Defines the main window for Sublime Music."""
|
||||
|
||||
__gsignals__ = {
|
||||
'song-clicked': (
|
||||
"song-clicked": (
|
||||
GObject.SignalFlags.RUN_FIRST,
|
||||
GObject.TYPE_NONE,
|
||||
(int, object, object),
|
||||
),
|
||||
'songs-removed': (
|
||||
GObject.SignalFlags.RUN_FIRST,
|
||||
GObject.TYPE_NONE,
|
||||
(object, ),
|
||||
),
|
||||
'refresh-window': (
|
||||
"songs-removed": (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE, (object,),),
|
||||
"refresh-window": (
|
||||
GObject.SignalFlags.RUN_FIRST,
|
||||
GObject.TYPE_NONE,
|
||||
(object, bool),
|
||||
),
|
||||
'go-to': (
|
||||
GObject.SignalFlags.RUN_FIRST,
|
||||
GObject.TYPE_NONE,
|
||||
(str, str),
|
||||
),
|
||||
"go-to": (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE, (str, str),),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -48,20 +41,20 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
Browse=browse.BrowsePanel(),
|
||||
Playlists=playlists.PlaylistsPanel(),
|
||||
)
|
||||
self.stack.set_transition_type(
|
||||
Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
|
||||
self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
|
||||
|
||||
self.titlebar = self._create_headerbar(self.stack)
|
||||
self.set_titlebar(self.titlebar)
|
||||
|
||||
self.player_controls = player_controls.PlayerControls()
|
||||
self.player_controls.connect(
|
||||
'song-clicked', lambda _, *a: self.emit('song-clicked', *a))
|
||||
"song-clicked", lambda _, *a: self.emit("song-clicked", *a)
|
||||
)
|
||||
self.player_controls.connect(
|
||||
'songs-removed', lambda _, *a: self.emit('songs-removed', *a))
|
||||
"songs-removed", lambda _, *a: self.emit("songs-removed", *a)
|
||||
)
|
||||
self.player_controls.connect(
|
||||
'refresh-window',
|
||||
lambda _, *args: self.emit('refresh-window', *args),
|
||||
"refresh-window", lambda _, *args: self.emit("refresh-window", *args),
|
||||
)
|
||||
|
||||
flowbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
@@ -69,21 +62,23 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
flowbox.pack_start(self.player_controls, False, True, 0)
|
||||
self.add(flowbox)
|
||||
|
||||
self.connect('button-release-event', self._on_button_release)
|
||||
self.connect("button-release-event", self._on_button_release)
|
||||
|
||||
def update(self, app_config: AppConfiguration, force: bool = False):
|
||||
# Update the Connected to label on the popup menu.
|
||||
if app_config.server:
|
||||
self.connected_to_label.set_markup(
|
||||
f'<b>Connected to {app_config.server.name}</b>')
|
||||
f"<b>Connected to {app_config.server.name}</b>"
|
||||
)
|
||||
else:
|
||||
self.connected_to_label.set_markup(
|
||||
f'<span style="italic">Not Connected to a Server</span>')
|
||||
'<span style="italic">Not Connected to a Server</span>'
|
||||
)
|
||||
|
||||
self.stack.set_visible_child_name(app_config.state.current_tab)
|
||||
|
||||
active_panel = self.stack.get_visible_child()
|
||||
if hasattr(active_panel, 'update'):
|
||||
if hasattr(active_panel, "update"):
|
||||
active_panel.update(app_config, force=force)
|
||||
|
||||
self.player_controls.update(app_config)
|
||||
@@ -92,12 +87,10 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
stack = Gtk.Stack()
|
||||
for name, child in kwargs.items():
|
||||
child.connect(
|
||||
'song-clicked',
|
||||
lambda _, *args: self.emit('song-clicked', *args),
|
||||
"song-clicked", lambda _, *args: self.emit("song-clicked", *args),
|
||||
)
|
||||
child.connect(
|
||||
'refresh-window',
|
||||
lambda _, *args: self.emit('refresh-window', *args),
|
||||
"refresh-window", lambda _, *args: self.emit("refresh-window", *args),
|
||||
)
|
||||
stack.add_titled(child, name.lower(), name)
|
||||
return stack
|
||||
@@ -108,20 +101,17 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
"""
|
||||
header = Gtk.HeaderBar()
|
||||
header.set_show_close_button(True)
|
||||
header.props.title = 'Sublime Music'
|
||||
header.props.title = "Sublime Music"
|
||||
|
||||
# Search
|
||||
self.search_entry = Gtk.SearchEntry(
|
||||
placeholder_text='Search everything...')
|
||||
self.search_entry = Gtk.SearchEntry(placeholder_text="Search everything...")
|
||||
self.search_entry.connect("focus-in-event", self._on_search_entry_focus)
|
||||
self.search_entry.connect(
|
||||
'focus-in-event', self._on_search_entry_focus)
|
||||
self.search_entry.connect(
|
||||
'button-press-event', self._on_search_entry_button_press)
|
||||
self.search_entry.connect(
|
||||
'focus-out-event', self._on_search_entry_loose_focus)
|
||||
self.search_entry.connect('changed', self._on_search_entry_changed)
|
||||
self.search_entry.connect(
|
||||
'stop-search', self._on_search_entry_stop_search)
|
||||
"button-press-event", self._on_search_entry_button_press
|
||||
)
|
||||
self.search_entry.connect("focus-out-event", self._on_search_entry_loose_focus)
|
||||
self.search_entry.connect("changed", self._on_search_entry_changed)
|
||||
self.search_entry.connect("stop-search", self._on_search_entry_stop_search)
|
||||
header.pack_start(self.search_entry)
|
||||
|
||||
# Search popup
|
||||
@@ -133,13 +123,13 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
|
||||
# Menu button
|
||||
menu_button = Gtk.MenuButton()
|
||||
menu_button.set_tooltip_text('Open application menu')
|
||||
menu_button.set_tooltip_text("Open application menu")
|
||||
menu_button.set_use_popover(True)
|
||||
menu_button.set_popover(self._create_menu())
|
||||
menu_button.connect('clicked', self._on_menu_clicked)
|
||||
menu_button.connect("clicked", self._on_menu_clicked)
|
||||
self.menu.set_relative_to(menu_button)
|
||||
|
||||
icon = Gio.ThemedIcon(name='open-menu-symbolic')
|
||||
icon = Gio.ThemedIcon(name="open-menu-symbolic")
|
||||
image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
|
||||
menu_button.add(image)
|
||||
|
||||
@@ -156,31 +146,28 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
**kwargs,
|
||||
)
|
||||
label.set_markup(text)
|
||||
label.get_style_context().add_class('search-result-row')
|
||||
label.get_style_context().add_class("search-result-row")
|
||||
return label
|
||||
|
||||
def _create_menu(self) -> Gtk.PopoverMenu:
|
||||
self.menu = Gtk.PopoverMenu()
|
||||
|
||||
self.connected_to_label = self._create_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>')
|
||||
'<span style="italic">Not Connected to a Server</span>'
|
||||
)
|
||||
|
||||
menu_items = [
|
||||
(None, self.connected_to_label),
|
||||
(
|
||||
'app.configure-servers',
|
||||
Gtk.ModelButton(text='Configure Servers'),
|
||||
),
|
||||
('app.settings', Gtk.ModelButton(text='Settings')),
|
||||
("app.configure-servers", Gtk.ModelButton(text="Configure Servers"),),
|
||||
("app.settings", Gtk.ModelButton(text="Settings")),
|
||||
]
|
||||
|
||||
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
for name, item in menu_items:
|
||||
if name:
|
||||
item.set_action_name(name)
|
||||
item.get_style_context().add_class('menu-button')
|
||||
item.get_style_context().add_class("menu-button")
|
||||
vbox.pack_start(item, False, True, 0)
|
||||
self.menu.add(vbox)
|
||||
|
||||
@@ -190,36 +177,33 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
self.search_popup = Gtk.PopoverMenu(modal=False)
|
||||
|
||||
results_scrollbox = Gtk.ScrolledWindow(
|
||||
min_content_width=500,
|
||||
min_content_height=750,
|
||||
min_content_width=500, min_content_height=750,
|
||||
)
|
||||
|
||||
def make_search_result_header(text: str) -> Gtk.Label:
|
||||
label = self._create_label(text)
|
||||
label.get_style_context().add_class('search-result-header')
|
||||
label.get_style_context().add_class("search-result-header")
|
||||
return label
|
||||
|
||||
search_results_box = Gtk.Box(
|
||||
orientation=Gtk.Orientation.VERTICAL,
|
||||
name='search-results',
|
||||
orientation=Gtk.Orientation.VERTICAL, name="search-results",
|
||||
)
|
||||
self.search_results_loading = Gtk.Spinner(
|
||||
active=False, name='search-spinner')
|
||||
self.search_results_loading = Gtk.Spinner(active=False, name="search-spinner")
|
||||
search_results_box.add(self.search_results_loading)
|
||||
|
||||
search_results_box.add(make_search_result_header('Songs'))
|
||||
search_results_box.add(make_search_result_header("Songs"))
|
||||
self.song_results = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
search_results_box.add(self.song_results)
|
||||
|
||||
search_results_box.add(make_search_result_header('Albums'))
|
||||
search_results_box.add(make_search_result_header("Albums"))
|
||||
self.album_results = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
search_results_box.add(self.album_results)
|
||||
|
||||
search_results_box.add(make_search_result_header('Artists'))
|
||||
search_results_box.add(make_search_result_header("Artists"))
|
||||
self.artist_results = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
search_results_box.add(self.artist_results)
|
||||
|
||||
search_results_box.add(make_search_result_header('Playlists'))
|
||||
search_results_box.add(make_search_result_header("Playlists"))
|
||||
self.playlist_results = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
search_results_box.add(self.playlist_results)
|
||||
|
||||
@@ -238,24 +222,20 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
# Event Listeners
|
||||
# =========================================================================
|
||||
def _on_button_release(self, win: Any, event: Gdk.EventButton) -> bool:
|
||||
if not self._event_in_widgets(
|
||||
event,
|
||||
self.search_entry,
|
||||
self.search_popup,
|
||||
):
|
||||
if not self._event_in_widgets(event, self.search_entry, self.search_popup,):
|
||||
self._hide_search()
|
||||
|
||||
if not self._event_in_widgets(
|
||||
event,
|
||||
self.player_controls.device_button,
|
||||
self.player_controls.device_popover,
|
||||
event,
|
||||
self.player_controls.device_button,
|
||||
self.player_controls.device_popover,
|
||||
):
|
||||
self.player_controls.device_popover.popdown()
|
||||
|
||||
if not self._event_in_widgets(
|
||||
event,
|
||||
self.player_controls.play_queue_button,
|
||||
self.player_controls.play_queue_popover,
|
||||
event,
|
||||
self.player_controls.play_queue_button,
|
||||
self.player_controls.play_queue_popover,
|
||||
):
|
||||
self.player_controls.play_queue_popover.popdown()
|
||||
|
||||
@@ -294,8 +274,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
|
||||
def create_search_callback(idx: int) -> Callable[..., Any]:
|
||||
def search_result_calback(
|
||||
result: SearchResult,
|
||||
is_last_in_batch: bool,
|
||||
result: SearchResult, is_last_in_batch: bool,
|
||||
):
|
||||
# Ignore slow returned searches.
|
||||
if idx < self.latest_returned_search_idx:
|
||||
@@ -316,7 +295,8 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
entry.get_text(),
|
||||
search_callback=create_search_callback(self.search_idx),
|
||||
before_download=lambda: self._set_search_loading(True),
|
||||
))
|
||||
)
|
||||
)
|
||||
|
||||
self.search_idx += 1
|
||||
|
||||
@@ -348,25 +328,25 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
widget.remove(c)
|
||||
|
||||
def _create_search_result_row(
|
||||
self,
|
||||
text: str,
|
||||
action_name: str,
|
||||
value: Any,
|
||||
artwork_future: CacheManager.Result,
|
||||
self,
|
||||
text: str,
|
||||
action_name: str,
|
||||
value: Any,
|
||||
artwork_future: CacheManager.Result,
|
||||
) -> Gtk.Button:
|
||||
def on_search_row_button_press(*args):
|
||||
if action_name == 'song':
|
||||
goto_action_name, goto_id = 'album', value.albumId
|
||||
if action_name == "song":
|
||||
goto_action_name, goto_id = "album", value.albumId
|
||||
else:
|
||||
goto_action_name, goto_id = action_name, value.id
|
||||
self.emit('go-to', goto_action_name, goto_id)
|
||||
self.emit("go-to", goto_action_name, goto_id)
|
||||
self._hide_search()
|
||||
|
||||
row = Gtk.Button(relief=Gtk.ReliefStyle.NONE)
|
||||
row.connect('button-press-event', on_search_row_button_press)
|
||||
row.connect("button-press-event", on_search_row_button_press)
|
||||
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
image = SpinnerImage(image_name='search-artwork', image_size=30)
|
||||
image = SpinnerImage(image_name="search-artwork", image_size=30)
|
||||
box.add(image)
|
||||
box.add(self._create_label(text))
|
||||
row.add(box)
|
||||
@@ -375,8 +355,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
image.set_loading(False)
|
||||
image.set_from_file(f.result())
|
||||
|
||||
artwork_future.add_done_callback(
|
||||
lambda f: GLib.idle_add(image_callback, f))
|
||||
artwork_future.add_done_callback(lambda f: GLib.idle_add(image_callback, f))
|
||||
|
||||
return row
|
||||
|
||||
@@ -386,14 +365,14 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
self._remove_all_from_widget(self.song_results)
|
||||
for song in search_results.song or []:
|
||||
label_text = util.dot_join(
|
||||
f'<b>{util.esc(song.title)}</b>',
|
||||
util.esc(song.artist),
|
||||
f"<b>{util.esc(song.title)}</b>", util.esc(song.artist),
|
||||
)
|
||||
cover_art_future = CacheManager.get_cover_art_filename(
|
||||
song.coverArt)
|
||||
cover_art_future = CacheManager.get_cover_art_filename(song.coverArt)
|
||||
self.song_results.add(
|
||||
self._create_search_result_row(
|
||||
label_text, 'song', song, cover_art_future))
|
||||
label_text, "song", song, cover_art_future
|
||||
)
|
||||
)
|
||||
|
||||
self.song_results.show_all()
|
||||
|
||||
@@ -402,14 +381,14 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
self._remove_all_from_widget(self.album_results)
|
||||
for album in search_results.album or []:
|
||||
label_text = util.dot_join(
|
||||
f'<b>{util.esc(album.name)}</b>',
|
||||
util.esc(album.artist),
|
||||
f"<b>{util.esc(album.name)}</b>", util.esc(album.artist),
|
||||
)
|
||||
cover_art_future = CacheManager.get_cover_art_filename(
|
||||
album.coverArt)
|
||||
cover_art_future = CacheManager.get_cover_art_filename(album.coverArt)
|
||||
self.album_results.add(
|
||||
self._create_search_result_row(
|
||||
label_text, 'album', album, cover_art_future))
|
||||
label_text, "album", album, cover_art_future
|
||||
)
|
||||
)
|
||||
|
||||
self.album_results.show_all()
|
||||
|
||||
@@ -421,7 +400,9 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
cover_art_future = CacheManager.get_artist_artwork(artist)
|
||||
self.artist_results.add(
|
||||
self._create_search_result_row(
|
||||
label_text, 'artist', artist, cover_art_future))
|
||||
label_text, "artist", artist, cover_art_future
|
||||
)
|
||||
)
|
||||
|
||||
self.artist_results.show_all()
|
||||
|
||||
@@ -431,10 +412,13 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
for playlist in search_results.playlist or []:
|
||||
label_text = util.esc(playlist.name)
|
||||
cover_art_future = CacheManager.get_cover_art_filename(
|
||||
playlist.coverArt)
|
||||
playlist.coverArt
|
||||
)
|
||||
self.playlist_results.add(
|
||||
self._create_search_result_row(
|
||||
label_text, 'playlist', playlist, cover_art_future))
|
||||
label_text, "playlist", playlist, cover_art_future
|
||||
)
|
||||
)
|
||||
|
||||
self.playlist_results.show_all()
|
||||
|
||||
@@ -451,8 +435,9 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
bound_y = (win_y + widget_y, win_y + widget_y + allocation.height)
|
||||
|
||||
# If the event is in this widget, return True immediately.
|
||||
if ((bound_x[0] <= event.x_root <= bound_x[1])
|
||||
and (bound_y[0] <= event.y_root <= bound_y[1])):
|
||||
if (bound_x[0] <= event.x_root <= bound_x[1]) and (
|
||||
bound_y[0] <= event.y_root <= bound_y[1]
|
||||
):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
Reference in New Issue
Block a user