From 6706695d611aa6f42d23461a57d6641fc1cee5b7 Mon Sep 17 00:00:00 2001 From: coderkun Date: Sun, 26 May 2024 18:29:10 +0200 Subject: [PATCH 1/6] Adjust blank lines to match Code Style Guide (see #103) --- src/__init__.py | 7 -- src/albumheaderbar.py | 5 -- src/application.py | 14 ---- src/client.py | 154 ----------------------------------------- src/connectionpanel.py | 14 ---- src/coverpanel.py | 19 ----- src/librarypanel.py | 45 ------------ src/main.py | 1 - src/playlistpanel.py | 29 -------- src/serverpanel.py | 9 --- src/shortcutsdialog.py | 3 - src/utils.py | 19 ----- src/window.py | 67 ------------------ src/zeroconf.py | 7 -- 14 files changed, 393 deletions(-) diff --git a/src/__init__.py b/src/__init__.py index cb91a42..87f16c5 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -5,8 +5,6 @@ import os - - # Set environment srcdir = os.path.abspath(os.path.dirname(__file__)) datadir = os.path.join(srcdir, 'data') @@ -23,19 +21,14 @@ if not os.environ.get('GSETTINGS_SCHEMA_DIR'): os.environ['GSETTINGS_SCHEMA_DIR'] = datadirdev - - class Environment: """Wrapper class to access environment settings.""" - def get_srcdir(): return srcdir - def get_data(subdir): return os.path.join(datadir, subdir) - def get_locale(): return localedir diff --git a/src/albumheaderbar.py b/src/albumheaderbar.py index ab6607a..00397db 100644 --- a/src/albumheaderbar.py +++ b/src/albumheaderbar.py @@ -8,8 +8,6 @@ gi.require_version('Adw', '1') from gi.repository import Gtk, GObject, Adw - - @Gtk.Template(resource_path='/xyz/suruatoel/mcg/ui/album-headerbar.ui') class AlbumHeaderbar(Adw.Bin): __gtype_name__ = 'McgAlbumHeaderbar' @@ -21,16 +19,13 @@ class AlbumHeaderbar(Adw.Bin): standalone_title = Gtk.Template.Child() standalone_artist = Gtk.Template.Child() - def __init__(self): super().__init__() - @Gtk.Template.Callback() def on_close_clicked(self, widget): self.emit('close') - def set_album(self, album): self.standalone_title.set_text(album.get_title()) self.standalone_artist.set_text(", ".join(album.get_albumartists())) diff --git a/src/application.py b/src/application.py index 7bbde2b..f7b9eda 100644 --- a/src/application.py +++ b/src/application.py @@ -12,14 +12,11 @@ from gi.repository import Gio, Gtk, Gdk, GLib, Adw from .window import Window - - class Application(Gtk.Application): TITLE = "CoverGrid" ID = 'xyz.suruatoel.mcg' DOMAIN = 'mcg' - def __init__(self): super().__init__(application_id=Application.ID, flags=Gio.ApplicationFlags.FLAGS_NONE) self._window = None @@ -38,7 +35,6 @@ class Application(Gtk.Application): self.set_accels_for_action('win.panel("2")', ['KP_3']) self.set_accels_for_action('win.panel("3")', ['KP_4']) - def do_startup(self): Gtk.Application.do_startup(self) self._setup_logging() @@ -48,14 +44,12 @@ class Application(Gtk.Application): self._setup_actions() self._setup_adw() - def do_activate(self): Gtk.Application.do_activate(self) if not self._window: self._window = Window(self, Application.TITLE, self._settings) self._window.present() - def on_menu_info(self, action, value): self._info_dialog = Adw.AboutDialog() self._info_dialog.set_application_icon("xyz.suruatoel.mcg") @@ -67,27 +61,22 @@ class Application(Gtk.Application): self._info_dialog.set_issue_url("https://git.suruatoel.xyz/coderkun/mcg") self._info_dialog.present() - def on_menu_quit(self, action, value): self.quit() - def _setup_logging(self): logging.basicConfig( level=self._verbosity, format="%(asctime)s %(levelname)s: %(message)s" ) - def _load_settings(self): self._settings = Gio.Settings.new(Application.ID) - def _set_default_settings(self): style_manager = Adw.StyleManager.get_default() style_manager.set_color_scheme(Adw.ColorScheme.PREFER_DARK) - def _load_css(self): styleProvider = Gtk.CssProvider() styleProvider.load_from_resource(self._get_resource_path('gtk.css')) @@ -97,7 +86,6 @@ class Application(Gtk.Application): Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION ) - def _setup_actions(self): action = Gio.SimpleAction.new("info", None) action.connect('activate', self.on_menu_info) @@ -106,11 +94,9 @@ class Application(Gtk.Application): action.connect('activate', self.on_menu_quit) self.add_action(action) - def _get_resource_path(self, path): return "/{}/{}".format(Application.ID.replace('.', '/'), path) - def _setup_adw(self): Adw.HeaderBar() Adw.ToolbarView() diff --git a/src/client.py b/src/client.py index 551f524..7d5ab8b 100644 --- a/src/client.py +++ b/src/client.py @@ -15,14 +15,11 @@ from mcg.utils import SortOrder from mcg.utils import Utils - - class MPDException(Exception): def __init__(self, error): super(MPDException, self).__init__(self._parse_error(error)) self._error = error - def _parse_error(self, error): if error: parts = re.match("\[(\d+)@(\d+)\]\s\{(\w+)\}\s(.*)", error) @@ -33,19 +30,15 @@ class MPDException(Exception): return parts.group(4) return error - def get_error(self): return self._error - def get_error_number(self): return self._error_number - def get_command_number(self): return self._command_number - def get_command_name(self): return self._command_name @@ -62,53 +55,41 @@ class CommandException(MPDException): pass - - class Future(concurrent.futures.Future): def __init__(self, signal): concurrent.futures.Future.__init__(self) self._signal = signal - def get_signal(self): return self._signal - - class Base(): def __init__(self): self._callbacks = {} - def connect_signal(self, signal, callback): """Connect a callback function to a signal (event).""" self._callbacks[signal] = callback - def disconnect_signal(self, signal): """Disconnect a callback function from a signal (event).""" if self._has_callback(signal): del self._callbacks[signal] - def _has_callback(self, signal): """Check if there is a registered callback function for a signal.""" return signal in self._callbacks - def _callback(self, signal, *data): if signal in self._callbacks: callback = self._callbacks[signal] callback(*data) - def _callback_future(self, future): self._callback(future.get_signal(), *future.result()) - - class Client(Base): """Client library for handling the connection to the Music Player Daemon. @@ -148,8 +129,6 @@ class Client(Base): # Buffer size for reading from socket SOCKET_BUFSIZE = 4096 - - def __init__(self): """Set class variables and instantiates the Client.""" Base.__init__(self) @@ -166,11 +145,9 @@ class Client(Base): self._playlist = [] self._state = None - def get_logger(self): return self._logger - # Client commands def connect(self, host, port, password=None): @@ -183,132 +160,108 @@ class Client(Base): self._stop.clear() self._start_worker() - def is_connected(self): """Return the connection status.""" return self._worker is not None and self._worker.is_alive() - def disconnect(self): """Disconnect from the connected MPD.""" self._logger.info("disconnect") self._stop.set() self._add_action(self._disconnect) - def join(self): self._actions.join() - def get_status(self): """Determine the current status.""" self._logger.info("get status") self._add_action_signal(Client.SIGNAL_STATUS, self._get_status) - def get_stats(self): """Load statistics.""" self._logger.info("get stats") self._add_action_signal(Client.SIGNAL_STATS, self._get_stats) - def get_output_devices(self): """Determine the list of audio output devices.""" self._logger.info("get output devices") self._add_action_signal(Client.SIGNAL_LOAD_OUTPUT_DEVICES, self._get_output_devices) - def enable_output_device(self, device, enabled): """Enable/disable an audio output device.""" self._logger.info("enable output device") self._add_action(self._enable_output_device, device, enabled) - - def load_albums(self): self._logger.info("load albums") self._add_action_signal(Client.SIGNAL_LOAD_ALBUMS, self._load_albums) - def update(self): self._logger.info("update") self._add_action(self._update) - def load_playlist(self): self._logger.info("load playlist") self._add_action_signal(Client.SIGNAL_LOAD_PLAYLIST, self._load_playlist) - def clear_playlist(self): """Clear the current playlist""" self._logger.info("clear playlist") self._add_action(self._clear_playlist) - def remove_album_from_playlist(self, album): """Remove the given album from the playlist.""" self._logger.info("remove album from playlist") self._add_action(self._remove_album_from_playlist, album) - def remove_albums_from_playlist(self, albums): """Remove multiple albums from the playlist in one step.""" self._logger.info("remove multiple albums from playlist") self._add_action(self._remove_albums_from_playlist, albums) - def play_album_from_playlist(self, album): """Play the given album from the playlist.""" self._logger.info("play album from playlist") self._add_action(self._play_album_from_playlist, album) - def playpause(self): """Play or pauses the current state.""" self._logger.info("playpause") self._add_action(self._playpause) - def play_album(self, album): """Add the given album to the queue and play it immediately.""" self._logger.info("play album") self._add_action(self._play_album, album) - def queue_album(self, album): """Add the given album to the queue.""" self._logger.info("play album") self._add_action(self._queue_album, album) - def queue_albums(self, albums): """Add the given albums to the queue.""" self._logger.info("play albums") self._add_action(self._queue_albums, albums) - def seek(self, pos, time): """Seeks to a song at a position""" self._logger.info("seek") self._add_action(self._seek, pos, time) - def stop(self): self._logger.info("stop") self._add_action(self._stop) - def set_volume(self, volume): self._logger.info("set volume") self._add_action(self._set_volume, volume) - def get_albumart(self, album): self._logger.info("get albumart") self._add_action_signal(Client.SIGNAL_LOAD_ALBUMART, self._get_albumart, album) - def get_albumart_now(self, album): self._logger.info("get albumart now") future = concurrent.futures.Future() @@ -316,7 +269,6 @@ class Client(Base): (_, albumart) = future.result() return albumart - # Private methods def _connect(self, host, port, password): @@ -335,7 +287,6 @@ class Client(Base): except OSError as e: raise ConnectionException("connection failed: {}".format(e)) - def _connect_socket(self, host, port): sock = None error = None @@ -356,7 +307,6 @@ class Client(Base): else: raise ConnectionException("no suitable socket") - def _greet(self): greeting = self._read_line() self._logger.debug("greeting: %s", greeting.strip()) @@ -366,12 +316,10 @@ class Client(Base): self._protocol_version = greeting[len(Client.PROTOCOL_GREETING):].strip() self._logger.debug("protocol version: %s", self._protocol_version) - def _disconnect(self): self._logger.info("disconnecting") self._disconnect_socket() - def _disconnect_socket(self): if self._sock_write is not None: self._sock_write.close() @@ -382,7 +330,6 @@ class Client(Base): self._logger.info("disconnected") self._set_connection_status(False) - def _idle(self): """React to idle events from MPD.""" self._logger.info("idle") @@ -410,13 +357,11 @@ class Client(Base): self.get_output_devices() self.get_status() - def _noidle(self): if self._idling: self._logger.debug("noidle") self._write("noidle") - def _get_status(self): """Action: Perform the real status determination.""" self._logger.info("getting status") @@ -471,7 +416,6 @@ class Client(Base): bitrate = status['bitrate'] return (state, album, pos, time, volume, file, audio, bitrate, error) - def _get_stats(self): """Action: Perform the real statistics gathering.""" self._logger.info("getting statistics") @@ -504,7 +448,6 @@ class Client(Base): uptime = stats['uptime'] return (artists, albums, songs, dbplaytime, playtime, uptime) - def _get_output_devices(self): """Action: Perform the real loading of output devices.""" devices = [] @@ -514,7 +457,6 @@ class Client(Base): devices.append(device) return (devices, ) - def _enable_output_device(self, device, enabled): """Action: Perform the real enabling/disabling of an output device.""" if enabled: @@ -522,7 +464,6 @@ class Client(Base): else: self._call('disableoutput ', device.get_id()) - def _load_albums(self): """Action: Perform the real update.""" self._callback(Client.SIGNAL_INIT_ALBUMS) @@ -542,11 +483,9 @@ class Client(Base): album.add_track(track) return (self._albums, ) - def _update(self): self._call('update') - def _load_playlist(self): self._playlist = [] for song in self._parse_list(self._call('playlistinfo'), ['file', 'playlist']): @@ -565,19 +504,16 @@ class Client(Base): album.add_track(track) return (self._playlist, ) - def _clear_playlist(self): """Action: Perform the real clearing of the current playlist.""" self._call('clear') - def _remove_album_from_playlist(self, album): self._call_list('command_list_begin') for track in album.get_tracks(): self._call_list('deleteid', track.get_id()) self._call('command_list_end') - def _remove_albums_from_playlist(self, albums): self._call_list('command_list_begin') for album in albums: @@ -585,12 +521,10 @@ class Client(Base): self._call_list('deleteid', track.get_id()) self._call('command_list_end') - def _play_album_from_playlist(self, album): if album.get_tracks(): self._call('playid', album.get_tracks()[0].get_id()) - def _playpause(self): """Action: Perform the real play/pause command.""" #status = self._parse_dict(self._call('status')) @@ -600,14 +534,12 @@ class Client(Base): else: self._call('play') - def _play_album(self, album): track_ids = self._queue_album(album) if track_ids: self._logger.info("play track %d", track_ids[0]) self._call('playid', track_ids[0]) - def _queue_album(self, album): track_ids = [] if album in self._albums: @@ -623,25 +555,20 @@ class Client(Base): track_ids.append(track_id) return track_ids - def _queue_albums(self, albums): track_ids = [] for album in albums: track_ids.extend(self._queue_album(album)) - def _seek(self, pos, time): self._call('seek', pos, time) - def _stop(self): self._call('stop') - def _set_volume(self, volume): self._call('setvol', volume) - def _get_albumart(self, album): if album in self._albums: album = self._albums[album] @@ -663,7 +590,6 @@ class Client(Base): return (album, None) - def _start_worker(self): """Start the worker thread which waits for action to be performed.""" self._logger.debug("start worker") @@ -672,7 +598,6 @@ class Client(Base): self._worker.start() self._logger.debug("worker started") - def _run(self): while not self._stop.is_set() or not self._actions.empty(): if self._sock is not None and self._actions.empty(): @@ -684,7 +609,6 @@ class Client(Base): self._logger.debug("action done") self._logger.debug("worker finished") - def _add_action(self, method, *args): """Add an action to the action list.""" self._logger.debug("add action %r (%r)", method.__name__, args) @@ -695,7 +619,6 @@ class Client(Base): return future - def _add_action_signal(self, signal, method, *args): """Add an action to the action list that triggers a callback.""" self._logger.debug("add action signal %r: %r (%r)", signal, method.__name__, args) @@ -705,7 +628,6 @@ class Client(Base): return future - def _add_action_future(self, future, method, *args): """Add an action to the action list based on a futre.""" self._logger.debug("add action future %r (%r)", method.__name__, args) @@ -713,7 +635,6 @@ class Client(Base): self._actions.put(action) self._noidle() - def _work(self, action): (future, method, args) = action self._logger.debug("work: %r", method.__name__) @@ -730,7 +651,6 @@ class Client(Base): future.set_exception(e) self._callback(Client.SIGNAL_ERROR, e) - def _call(self, command, *args): try: self._write(command, args) @@ -740,7 +660,6 @@ class Client(Base): self.disconnect() self._callback(Client.SIGNAL_ERROR, e) - def _call_list(self, command, *args): try: self._write(command, args) @@ -749,7 +668,6 @@ class Client(Base): self.disconnect() self._callback(Client.SIGNAL_ERROR, e) - def _write(self, command, args=None): if args is not None and len(args) > 0: line = '{} "{}"\n'.format(command, '" "'.join(str(x).replace('"', '\\\"') for x in args)) @@ -759,7 +677,6 @@ class Client(Base): self._sock_write.write(line) self._sock_write.flush() - def _read(self): self._logger.debug("reading response") response = [] @@ -776,7 +693,6 @@ class Client(Base): self._logger.debug("response: %r", response) return response - def _read_line(self): self._logger.debug("reading line") @@ -800,7 +716,6 @@ class Client(Base): return data.decode('utf-8') return None - def _read_binary(self, command, filename, has_mimetype): data = None size = 1 @@ -849,7 +764,6 @@ class Client(Base): break return data - def _read_bytes(self, buf, nbytes): self._logger.debug("reading bytes") # Use already buffered data @@ -863,7 +777,6 @@ class Client(Base): nbytes_read += self._sock.recv_into(buf_view, nbytes) return nbytes_read - def _buffer_get_char(self, char): pos = self._buffer.find(char) if pos < 0: @@ -872,7 +785,6 @@ class Client(Base): self._buffer = self._buffer[pos+1:] return buf - def _buffer_get_size(self, size): buf = self._buffer[0:size] self._logger.debug("get %d bytes from buffer", len(buf)) @@ -880,12 +792,10 @@ class Client(Base): self._logger.debug("leaving %d in the buffer", len(self._buffer)) return buf - def _buffer_set(self, buf): self._logger.debug("set %d %s as buffer", len(buf), type(buf)) self._buffer = buf - def _parse_dict(self, response): dict = {} if response: @@ -894,7 +804,6 @@ class Client(Base): dict[key] = value return dict - def _parse_list(self, response, delimiters): entry = {} if response: @@ -912,12 +821,10 @@ class Client(Base): if entry: yield entry - def _split_line(self, line): parts = line.split(':') return parts[0].lower(), ':'.join(parts[1:]).lstrip() - def _extract_album(self, song, lookup=True): album = None if 'album' not in song: @@ -931,7 +838,6 @@ class Client(Base): self._albums[id] = album return album - def _extract_track(self, song): track = None if 'artist' in song and 'title' in song and 'file' in song: @@ -948,54 +854,42 @@ class Client(Base): track.set_last_modified(song['last-modified']) return track - def _extract_playlist_track(self, song): track = self._extract_track(song) if track and 'id' in song and 'pos' in song: track = MCGPlaylistTrack(track, song['id'], song['pos']) return track - def _set_connection_status(self, status): self._callback(Client.SIGNAL_CONNECTION, status) - - class OutputDevice: - def __init__(self, id, name): self._id = id self._name = name self._enabled = None - def get_id(self): return self._id - def get_name(self): return self._name - def set_enabled(self, enabled): self._enabled = enabled - def is_enabled(self): return self._enabled - - class MCGAlbum: DEFAULT_ALBUM = 'Various' _FILE_NAMES = ['cover', 'folder'] _FILE_EXTS = ['jpg', 'png', 'jpeg'] _FILTER_DELIMITER = ' ' - def __init__(self, title, host): self._artists = [] self._albumartists = [] @@ -1010,49 +904,39 @@ class MCGAlbum: self._last_modified = None self._id = Utils.generate_id(title) - def __eq__(self, other): return (other and self.get_id() == other.get_id()) - def __hash__(self): return hash(self._title) - def get_id(self): return self._id - def get_artists(self): if self._albumartists: return [artist for artist in self._artists if artist not in self._albumartists] return self._artists - def get_albumartists(self): if self._albumartists: return self._albumartists return self._artists - def get_title(self): return self._title - def get_dates(self): return self._dates - def get_date(self): if len(self._dates) == 0: return None return self._dates[0] - def get_path(self): return self._path - def add_track(self, track): self._tracks.append(track) self._length = self._length + track.get_length() @@ -1071,19 +955,15 @@ class MCGAlbum: if not self._last_modified or track.get_last_modified() > self._last_modified: self._last_modified = track.get_last_modified() - def get_tracks(self): return self._tracks - def get_length(self): return self._length - def get_last_modified(self): return self._last_modified - def filter(self, filter_string): if len(filter_string) == 0: return True @@ -1109,7 +989,6 @@ class MCGAlbum: return False return True - def compare(album1, album2, criterion=None, reverse=False): if criterion == None: criterion = SortOrder.TITLE @@ -1140,8 +1019,6 @@ class MCGAlbum: return 1 * reverseMultiplier - - class MCGTrack: def __init__(self, artists, title, file): if type(artists) is not list: @@ -1160,41 +1037,33 @@ class MCGTrack: self._date = None self._last_modified = None - def __eq__(self, other): return self._file == other.get_file() - def __hash__(self): return hash(self._file) - def get_artists(self): if self._albumartists: return [artist for artist in self._artists if artist not in self._albumartists] return self._artists - def set_albumartists(self, artists): if type(artists) is not list: artists = [artists] self._albumartists = artists - def get_albumartists(self): if self._albumartists: return self._albumartists return self._artists - def get_title(self): return self._title - def get_track(self): return self._track - def set_track(self, track): if type(track) is list: track = track[0] @@ -1207,29 +1076,23 @@ class MCGTrack: track = 0 self._track = track - def get_length(self): return self._length - def set_length(self, length): self._length = int(length) - def get_date(self): return self._date - def set_date(self, date): if type(date) is list: date = date[0] self._date = date - def get_file(self): return self._file - def set_last_modified(self, date_string): if date_string: try: @@ -1237,13 +1100,10 @@ class MCGTrack: except ValueError as e: self._logger.debug("Invalid date format: %s", date_string) - def get_last_modified(self): return self._last_modified - - class MCGPlaylistTrack(MCGTrack): def __init__(self, track, id, pos): MCGTrack.__init__( @@ -1259,51 +1119,40 @@ class MCGPlaylistTrack(MCGTrack): self._id = int(id) self._pos = int(pos) - def get_id(self): return self._id - def get_pos(self): return self._pos - - class MCGConfig(configparser.ConfigParser): CONFIG_DIR = '~/.config/mcg/' - def __init__(self, filename): configparser.ConfigParser.__init__(self) self._filename = os.path.expanduser(os.path.join(MCGConfig.CONFIG_DIR, filename)) self._create_dir() - def load(self): if os.path.isfile(self._filename): self.read(self._filename) - def save(self): with open(self._filename, 'w') as configfile: self.write(configfile) - def _create_dir(self): dirname = os.path.dirname(self._filename) if not os.path.exists(dirname): os.makedirs(dirname) - - class MCGCache(): DIRNAME = '~/.cache/mcg/' SIZE_FILENAME = 'size' _lock = threading.Lock() - def __init__(self, host, size): self._logger = logging.getLogger(__name__) self._host = host @@ -1313,11 +1162,9 @@ class MCGCache(): os.makedirs(self._dirname) self._read_size() - def create_filename(self, album): return os.path.join(self._dirname, '-'.join([album.get_id()])) - def _read_size(self): size = 100 MCGCache._lock.acquire() @@ -1338,7 +1185,6 @@ class MCGCache(): f.write(str(self._size)) MCGCache._lock.release() - def _clear(self): for filename in os.listdir(self._dirname): path = os.path.join(self._dirname, filename) diff --git a/src/connectionpanel.py b/src/connectionpanel.py index 5cfd4ad..8cf7a08 100644 --- a/src/connectionpanel.py +++ b/src/connectionpanel.py @@ -11,8 +11,6 @@ from gi.repository import Gtk, Gio, GObject, Adw from mcg.zeroconf import ZeroconfProvider - - @Gtk.Template(resource_path='/xyz/suruatoel/mcg/ui/connection-panel.ui') class ConnectionPanel(Adw.Bin): __gtype_name__ = 'McgConnectionPanel' @@ -27,7 +25,6 @@ class ConnectionPanel(Adw.Bin): port_spinner = Gtk.Template.Child() password_row = Gtk.Template.Child() - def __init__(self, **kwargs): super().__init__(**kwargs) @@ -35,7 +32,6 @@ class ConnectionPanel(Adw.Bin): self._zeroconf_provider = ZeroconfProvider() self._zeroconf_provider.connect_signal(ZeroconfProvider.SIGNAL_SERVICE_NEW, self.on_new_service) - def on_new_service(self, service): name, host, port = service @@ -50,50 +46,40 @@ class ConnectionPanel(Adw.Bin): self.zeroconf_list.insert(row, -1) - def on_service_selected(self, widget, host, port): self.set_host(host) self.set_port(port) - @Gtk.Template.Callback() def on_host_entry_apply(self, widget): self._call_back() - @Gtk.Template.Callback() def on_port_spinner_value_changed(self, widget): self._call_back() - def set_host(self, host): self.host_row.set_text(host) - def get_host(self): return self.host_row.get_text() - def set_port(self, port): self.port_spinner.set_value(port) - def get_port(self): return self.port_spinner.get_value_as_int() - def set_password(self, password): if password is None: password = "" self.password_row.set_text(password) - def get_password(self): if self.password_row.get_text() == "": return None else: return self.password_entry.get_text() - def _call_back(self): self.emit('connection-changed', self.get_host(), self.get_port(), self.get_password(),) diff --git a/src/coverpanel.py b/src/coverpanel.py index 59c75a3..645149c 100644 --- a/src/coverpanel.py +++ b/src/coverpanel.py @@ -11,8 +11,6 @@ from gi.repository import Gtk, Gdk, GObject, GdkPixbuf from mcg.utils import Utils - - @Gtk.Template(resource_path='/xyz/suruatoel/mcg/ui/cover-panel.ui') class CoverPanel(Gtk.Overlay): __gtype_name__ = 'McgCoverPanel' @@ -42,8 +40,6 @@ class CoverPanel(Gtk.Overlay): # Songs songs_scale = Gtk.Template.Child() - - def __init__(self, **kwargs): super().__init__(**kwargs) @@ -70,25 +66,20 @@ class CoverPanel(Gtk.Overlay): buttonController.connect('unpaired-release', self.on_songs_scale_released) self.songs_scale.add_controller(buttonController) - def get_toolbar(self): return self.toolbar - def set_selected(self, selected): pass - def on_cover_box_pressed(self, widget, npress, x, y): if self._current_album and npress == 2: self.emit('toggle-fullscreen') - def set_width(self, width): GObject.idle_add(self._resize_image) self.cover_info_scroll.set_max_content_width(width // 2) - def on_songs_scale_pressed(self, widget, npress, x, y): if self._timer: GObject.source_remove(self._timer) @@ -107,7 +98,6 @@ class CoverPanel(Gtk.Overlay): time = max(value - time - 1, 0) self.emit('set-song', pos, time) - def set_album(self, album): if album: # Set labels @@ -129,7 +119,6 @@ class CoverPanel(Gtk.Overlay): self._enable_tracklist() self.fullscreen_button.set_sensitive(self._current_album is not None) - def set_play(self, pos, time): if self._timer is not None: GObject.source_remove(self._timer) @@ -141,13 +130,11 @@ class CoverPanel(Gtk.Overlay): self.songs_scale.set_value(time+1) self._timer = GObject.timeout_add(1000, self._playing) - def set_pause(self): if self._timer is not None: GObject.source_remove(self._timer) self._timer = None - def set_fullscreen(self, active): if active: self.info_revealer.set_reveal_child(False) @@ -159,7 +146,6 @@ class CoverPanel(Gtk.Overlay): self.info_revealer.set_reveal_child(True) GObject.idle_add(self._resize_image) - def set_albumart(self, album, data): if album == self._current_album: if data: @@ -177,7 +163,6 @@ class CoverPanel(Gtk.Overlay): # Show image GObject.idle_add(self._show_image) - def _set_tracks(self, album): self.songs_scale.clear_marks() self.songs_scale.set_range(0, album.get_length()) @@ -200,7 +185,6 @@ class CoverPanel(Gtk.Overlay): "{0[0]:02d}:{0[1]:02d} minutes".format(divmod(length, 60)) ) - def _enable_tracklist(self): if self._current_album: # enable @@ -210,14 +194,12 @@ class CoverPanel(Gtk.Overlay): # disable self.info_revealer.set_reveal_child(False) - def _playing(self): value = self.songs_scale.get_value() + 1 self.songs_scale.set_value(value) return True - def _show_image(self): if self._cover_pixbuf: self._resize_image() @@ -226,7 +208,6 @@ class CoverPanel(Gtk.Overlay): self.cover_stack.set_visible_child(self.cover_default) self.cover_spinner.stop() - def _resize_image(self): """Diese Methode skaliert das geladene Bild aus dem Pixelpuffer auf die Größe des Fensters unter Beibehalt der Seitenverhältnisse diff --git a/src/librarypanel.py b/src/librarypanel.py index aee5fcc..6de3611 100644 --- a/src/librarypanel.py +++ b/src/librarypanel.py @@ -19,8 +19,6 @@ from mcg.utils import GridItem from mcg.utils import SearchFilter - - @Gtk.Template(resource_path='/xyz/suruatoel/mcg/ui/library-panel.ui') class LibraryPanel(Adw.Bin): __gtype_name__ = 'McgLibraryPanel' @@ -37,7 +35,6 @@ class LibraryPanel(Adw.Bin): 'albumart': (GObject.SIGNAL_RUN_FIRST, None, (str,)), } - # Widgets library_stack = Gtk.Template.Child() panel_normal = Gtk.Template.Child() @@ -74,7 +71,6 @@ class LibraryPanel(Adw.Bin): standalone_scroll = Gtk.Template.Child() standalone_image = Gtk.Template.Child() - def __init__(self, client, **kwargs): super().__init__(**kwargs) self._logger = logging.getLogger(__name__) @@ -121,19 +117,15 @@ class LibraryPanel(Adw.Bin): buttonController.connect('unpaired-release', self.on_grid_scale_released) self.grid_scale.add_controller(buttonController) - def get_headerbar_standalone(self): return self._headerbar_standalone - def get_toolbar(self): return self.toolbar - def set_selected(self, selected): self._is_selected = selected - @Gtk.Template.Callback() def on_select_toggled(self, widget): if self.select_button.get_active(): @@ -147,12 +139,10 @@ class LibraryPanel(Adw.Bin): self.library_grid.set_single_click_activate(True) self.library_grid.get_style_context().remove_class(Utils.CSS_SELECTION) - @Gtk.Template.Callback() def on_update_clicked(self, widget): self.emit('update') - def on_grid_scale_released(self, widget, x, y, npress, sequence): size = math.floor(self.grid_scale.get_value()) range = self.grid_scale.get_adjustment() @@ -163,7 +153,6 @@ class LibraryPanel(Adw.Bin): self._redraw() GObject.idle_add(self.toolbar_popover.popdown) - @Gtk.Template.Callback() def on_grid_scale_changed(self, widget): size = math.floor(self.grid_scale.get_value()) @@ -172,7 +161,6 @@ class LibraryPanel(Adw.Bin): return self._set_widget_grid_size(self.library_grid, size, True) - @Gtk.Template.Callback() def on_sort_toggled(self, widget): if widget.get_active(): @@ -180,7 +168,6 @@ class LibraryPanel(Adw.Bin): self._sort_grid_model() self.emit('sort-order-changed', self._sort_order) - @Gtk.Template.Callback() def on_sort_order_toggled(self, button): if button.get_active(): @@ -190,17 +177,14 @@ class LibraryPanel(Adw.Bin): self._sort_grid_model() self.emit('sort-type-changed', button.get_active()) - def set_size(self, width, height): self._set_marks() self._resize_standalone_image() - @Gtk.Template.Callback() def on_filter_entry_changed(self, widget): self._library_grid_filter.set_filter(SearchFilter(self.filter_entry.get_text())) - @Gtk.Template.Callback() def on_library_grid_clicked(self, widget, position): # Get selected album @@ -222,49 +206,40 @@ class LibraryPanel(Adw.Bin): self.standalone_stack.set_visible_child(self.standalone_spinner) self.standalone_spinner.start() - @Gtk.Template.Callback() def on_selection_cancel_clicked(self, widget): self.select_button.set_active(False) - @Gtk.Template.Callback() def on_selection_add_clicked(self, widget): self.emit('queue-multiple', self._get_selected_albums()) self.select_button.set_active(False) - @Gtk.Template.Callback() def on_standalone_play_clicked(self, widget): self.emit('play', self._selected_albums[0].get_id()) self._close_standalone() - @Gtk.Template.Callback() def on_standalone_queue_clicked(self, widget): self.emit('queue', self._selected_albums[0].get_id()) self._close_standalone() - def on_standalone_close_clicked(self, widget): self._close_standalone() - def show_search(self): self.filter_bar.set_search_mode(True) - def set_item_size(self, item_size): if self._item_size != item_size: self._item_size = item_size self.grid_scale.set_value(item_size) self._redraw() - def get_item_size(self): return self._item_size - def set_sort_order(self, sort): button = self._toolbar_sort_buttons[sort] if button: @@ -273,7 +248,6 @@ class LibraryPanel(Adw.Bin): button.set_active(True) self._sort_grid_model() - def set_sort_type(self, sort_type): sort_type_gtk = Gtk.SortType.DESCENDING if sort_type else Gtk.SortType.ASCENDING @@ -282,25 +256,20 @@ class LibraryPanel(Adw.Bin): self.toolbar_sort_order_button.set_active(sort_type) self._sort_grid_model() - def get_sort_type(self): return (self._sort_type != Gtk.SortType.ASCENDING) - def init_albums(self): self.progress_bar.set_text(locale.gettext("Loading albums")) - def load_albums(self): self.progress_bar.pulse() - def set_albums(self, host, albums): self._host = host self._library_stop.set() threading.Thread(target=self._set_albums, args=(host, albums, self._item_size,)).start() - def set_albumart(self, album, data): if album in self._selected_albums: if data: @@ -315,19 +284,15 @@ class LibraryPanel(Adw.Bin): # Show image GObject.idle_add(self._show_image) - def _sort_grid_model(self): GObject.idle_add(self._library_grid_model.sort, self._grid_model_compare_func, self._sort_order, self._sort_type) - def _grid_model_compare_func(self, item1, item2, criterion, order): return client.MCGAlbum.compare(item1.get_album(), item2.get_album(), criterion, (order == Gtk.SortType.DESCENDING)) - def stop_threads(self): self._library_stop.set() - def _set_albums(self, host, albums, size): self._library_lock.acquire() self._albums = albums @@ -373,12 +338,10 @@ class LibraryPanel(Adw.Bin): GObject.idle_add(self.stack.set_visible_child, self.scroll) self._sort_grid_model() - def _set_widget_grid_size(self, grid_widget, size, vertical): self._library_stop.set() threading.Thread(target=self._set_widget_grid_size_thread, args=(grid_widget, size, vertical,)).start() - def _set_widget_grid_size_thread(self, grid_widget, size, vertical): self._library_lock.acquire() self._library_stop.clear() @@ -409,18 +372,15 @@ class LibraryPanel(Adw.Bin): self._library_lock.release() - def _show_image(self): self._resize_standalone_image() self.standalone_stack.set_visible_child(self.standalone_scroll) self.standalone_spinner.stop() - def _redraw(self): if self._albums is not None: self.set_albums(self._host, self._albums) - def _set_marks(self): width = self.scroll.get_width() if width == self._grid_width: @@ -441,17 +401,14 @@ class LibraryPanel(Adw.Bin): None ) - def _open_standalone(self): self.library_stack.set_visible_child(self.panel_standalone) self.emit('open-standalone') - def _close_standalone(self): self.library_stack.set_visible_child(self.panel_normal) self.emit('close-standalone') - def _resize_standalone_image(self): """Diese Methode skaliert das geladene Bild aus dem Pixelpuffer auf die Größe des Fensters unter Beibehalt der Seitenverhältnisse @@ -481,7 +438,6 @@ class LibraryPanel(Adw.Bin): self.standalone_image.set_from_pixbuf(pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.HYPER)) self.standalone_image.show() - def _get_default_image(self): return self._icon_theme.lookup_icon( Utils.STOCK_ICON_DEFAULT, @@ -492,7 +448,6 @@ class LibraryPanel(Adw.Bin): Gtk.IconLookupFlags.FORCE_SYMBOLIC ) - def _get_selected_albums(self): albums = [] for i in range(self.library_grid.get_model().get_n_items()): diff --git a/src/main.py b/src/main.py index 39e5be5..bc1476c 100644 --- a/src/main.py +++ b/src/main.py @@ -3,7 +3,6 @@ import sys from .application import Application - def main(version): app = Application() return app.run(sys.argv) diff --git a/src/playlistpanel.py b/src/playlistpanel.py index c705f1d..f22fc10 100644 --- a/src/playlistpanel.py +++ b/src/playlistpanel.py @@ -16,8 +16,6 @@ from mcg.utils import Utils from mcg.utils import GridItem - - @Gtk.Template(resource_path='/xyz/suruatoel/mcg/ui/playlist-panel.ui') class PlaylistPanel(Adw.Bin): __gtype_name__ = 'McgPlaylistPanel' @@ -31,7 +29,6 @@ class PlaylistPanel(Adw.Bin): 'albumart': (GObject.SIGNAL_RUN_FIRST, None, (str,)), } - # Widgets playlist_stack = Gtk.Template.Child() panel_normal = Gtk.Template.Child() @@ -52,7 +49,6 @@ class PlaylistPanel(Adw.Bin): standalone_scroll = Gtk.Template.Child() standalone_image = Gtk.Template.Child() - def __init__(self, client, **kwargs): super().__init__(**kwargs) self._client = client @@ -78,19 +74,15 @@ class PlaylistPanel(Adw.Bin): # Playlist Grid self.playlist_grid.set_model(self._playlist_grid_selection_single) - def get_headerbar_standalone(self): return self._headerbar_standalone - def get_toolbar(self): return self.toolbar - def set_selected(self, selected): self._is_selected = selected - @Gtk.Template.Callback() def on_select_toggled(self, widget): if self.select_button.get_active(): @@ -104,12 +96,10 @@ class PlaylistPanel(Adw.Bin): self.playlist_grid.set_single_click_activate(True) self.playlist_grid.get_style_context().remove_class(Utils.CSS_SELECTION) - @Gtk.Template.Callback() def on_clear_clicked(self, widget): self.emit('clear-playlist') - @Gtk.Template.Callback() def on_playlist_grid_clicked(self, widget, position): # Get selected album @@ -131,54 +121,44 @@ class PlaylistPanel(Adw.Bin): self.standalone_stack.set_visible_child(self.standalone_spinner) self.standalone_spinner.start() - @Gtk.Template.Callback() def on_selection_cancel_clicked(self, widget): self.select_button.set_active(False) - @Gtk.Template.Callback() def on_selection_remove_clicked(self, widget): self.emit('remove-multiple-albums', self._get_selected_albums()) self.select_button.set_active(False) - def on_headerbar_close_clicked(self, widget): self._close_standalone() - @Gtk.Template.Callback() def on_standalone_remove_clicked(self, widget): self.emit('remove-album', self._get_selected_albums()[0]) self._close_standalone() - @Gtk.Template.Callback() def on_standalone_play_clicked(self, widget): self.emit('play', self._get_selected_albums()[0]) self._close_standalone() - def set_size(self, width, height): self._resize_standalone_image() - def set_item_size(self, item_size): if self._item_size != item_size: self._item_size = item_size self._redraw() - def get_item_size(self): return self._item_size - def set_playlist(self, host, playlist): self._host = host self._playlist_stop.set() threading.Thread(target=self._set_playlist, args=(host, playlist, self._item_size,)).start() - def set_albumart(self, album, data): if album in self._selected_albums: if data: @@ -193,11 +173,9 @@ class PlaylistPanel(Adw.Bin): # Show image GObject.idle_add(self._show_image) - def stop_threads(self): self._playlist_stop.set() - def _set_playlist(self, host, playlist, size): self._playlist_lock.acquire() self._playlist_stop.clear() @@ -237,28 +215,23 @@ class PlaylistPanel(Adw.Bin): self.playlist_grid.set_model(self._playlist_grid_selection_single) self._playlist_lock.release() - def _show_image(self): self._resize_standalone_image() self.standalone_stack.set_visible_child(self.standalone_scroll) self.standalone_spinner.stop() - def _redraw(self): if self._playlist is not None: self.set_playlist(self._host, self._playlist) - def _open_standalone(self): self.playlist_stack.set_visible_child(self.panel_standalone) self.emit('open-standalone') - def _close_standalone(self): self.playlist_stack.set_visible_child(self.panel_normal) self.emit('close-standalone') - def _resize_standalone_image(self): """Diese Methode skaliert das geladene Bild aus dem Pixelpuffer auf die Größe des Fensters unter Beibehalt der Seitenverhältnisse @@ -288,7 +261,6 @@ class PlaylistPanel(Adw.Bin): self.standalone_image.set_from_pixbuf(pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.HYPER)) self.standalone_image.show() - def _get_default_image(self): return self._icon_theme.lookup_icon( Utils.STOCK_ICON_DEFAULT, @@ -299,7 +271,6 @@ class PlaylistPanel(Adw.Bin): Gtk.IconLookupFlags.FORCE_SYMBOLIC ) - def _get_selected_albums(self): albums = [] for i in range(self.playlist_grid.get_model().get_n_items()): diff --git a/src/serverpanel.py b/src/serverpanel.py index 75c3628..1e85b3c 100644 --- a/src/serverpanel.py +++ b/src/serverpanel.py @@ -8,8 +8,6 @@ gi.require_version('Adw', '1') from gi.repository import Gtk, Adw, GObject - - @Gtk.Template(resource_path='/xyz/suruatoel/mcg/ui/server-panel.ui') class ServerPanel(Adw.Bin): __gtype_name__ = 'McgServerPanel' @@ -34,7 +32,6 @@ class ServerPanel(Adw.Bin): # Audio ouptut devices widgets output_devices = Gtk.Template.Child() - def __init__(self, **kwargs): super().__init__(**kwargs) self._none_label = "" @@ -44,19 +41,15 @@ class ServerPanel(Adw.Bin): # Widgets self._none_label = self.status_file.get_label() - def set_selected(self, selected): self._is_selected = selected - def get_toolbar(self): return self.toolbar - def on_output_device_toggled(self, widget, device): self.emit('change-output-device', device, widget.get_active()) - def set_status(self, file, audio, bitrate, error): if file: file = GObject.markup_escape_text(file) @@ -84,7 +77,6 @@ class ServerPanel(Adw.Bin): error = self._none_label self.status_error.set_markup(error) - def set_stats(self, artists, albums, songs, dbplaytime, playtime, uptime): self.stats_artists.set_text(str(artists)) self.stats_albums.set_text(str(albums)) @@ -93,7 +85,6 @@ class ServerPanel(Adw.Bin): self.stats_playtime.set_text(str(playtime)) self.stats_uptime.set_text(str(uptime)) - def set_output_devices(self, devices): device_ids = [] diff --git a/src/shortcutsdialog.py b/src/shortcutsdialog.py index 6bf16e5..6b1d210 100644 --- a/src/shortcutsdialog.py +++ b/src/shortcutsdialog.py @@ -7,12 +7,9 @@ gi.require_version('Adw', '1') from gi.repository import Gtk - - @Gtk.Template(resource_path='/xyz/suruatoel/mcg/ui/shortcuts-dialog.ui') class ShortcutsDialog(Gtk.ShortcutsWindow): __gtype_name__ = 'McgShortcutsDialog' - def __init__(self): super().__init__() diff --git a/src/utils.py b/src/utils.py index 3f2ef3a..f1918a8 100644 --- a/src/utils.py +++ b/src/utils.py @@ -11,13 +11,10 @@ import urllib from gi.repository import Gdk, GdkPixbuf, GObject, Gtk - - class Utils: CSS_SELECTION = 'selection' STOCK_ICON_DEFAULT = 'image-x-generic-symbolic' - def load_pixbuf(data): loader = GdkPixbuf.PixbufLoader() try: @@ -26,7 +23,6 @@ class Utils: loader.close() return loader.get_pixbuf() - def load_thumbnail(cache, client, album, size): cache_url = cache.create_filename(album) pixbuf = None @@ -43,7 +39,6 @@ class Utils: pixbuf.savev(cache_url, 'jpeg', [], []) return pixbuf - def create_artists_label(album): label = ', '.join(album.get_albumartists()) if album.get_artists(): @@ -53,14 +48,12 @@ class Utils: ) return label - def create_length_label(album): minutes = album.get_length() // 60 seconds = album.get_length() - minutes * 60 return locale.gettext("{}:{} minutes").format(minutes, seconds) - def create_track_title(track): title = track.get_title() if track.get_artists(): @@ -70,7 +63,6 @@ class Utils: ) return title - def generate_id(values): if type(values) is not list: values = [values] @@ -80,8 +72,6 @@ class Utils: return m.hexdigest() - - class SortOrder: ARTIST = 0 TITLE = 1 @@ -89,15 +79,12 @@ class SortOrder: MODIFIED = 3 - - class GridItem(GObject.GObject): __gtype_name__ = "GridItem" tooltip = GObject.Property(type=str, default=None) cover = GObject.Property(type=Gdk.Paintable, default=None) - def __init__(self, album, cover): super().__init__() self._album = album @@ -110,24 +97,18 @@ class GridItem(GObject.GObject): Utils.create_length_label(album) ])) - def get_album(self): return self._album - def set_cover(self, cover): self.cover = Gdk.Texture.new_for_pixbuf(cover) - - class SearchFilter(Gtk.Filter): - def __init__(self, search_string): super().__init__() self._search_string = search_string - def do_match(self, grid_item): return grid_item.get_album().filter(self._search_string) diff --git a/src/window.py b/src/window.py index 26eed81..579950a 100644 --- a/src/window.py +++ b/src/window.py @@ -25,8 +25,6 @@ from .librarypanel import LibraryPanel from .zeroconf import ZeroconfProvider - - class WindowState(GObject.Object): WIDTH = 'width' HEIGHT = 'height' @@ -37,13 +35,10 @@ class WindowState(GObject.Object): is_maximized = GObject.Property(type=bool, default=False) is_fullscreened = GObject.Property(type=bool, default=False) - def __init__(self): super().__init__() - - @Gtk.Template(resource_path='/xyz/suruatoel/mcg/ui/window.ui') class Window(Adw.ApplicationWindow): __gtype_name__ = 'McgAppWindow' @@ -72,7 +67,6 @@ class Window(Adw.ApplicationWindow): # Infobar info_toast = Gtk.Template.Child() - def __init__(self, app, title, settings, **kwargs): super().__init__(**kwargs) self.set_application(app) @@ -205,26 +199,21 @@ class Window(Adw.ApplicationWindow): self._search_library_action.connect('activate', self.on_menu_search_library) self.add_action(self._search_library_action) - # Menu callbacks def on_menu_connect(self, action, value): self._connect() - def on_menu_play(self, action, value): self._mcg.playpause() - def on_menu_clear_playlist(self, action, value): self._mcg.clear_playlist() - def on_menu_panel(self, action, value): action.set_state(value) self.panel_stack.set_visible_child(self._panels[int(value.get_string())]) - def on_menu_toggle_fullscreen(self, action, value): self.panel_stack.set_visible_child(self._cover_panel) if not self._state.get_property(WindowState.IS_FULLSCREENED): @@ -232,12 +221,10 @@ class Window(Adw.ApplicationWindow): else: self.unfullscreen() - def on_menu_search_library(self, action, value): self.panel_stack.set_visible_child(self.library_panel_page) self._library_panel.show_search() - # Window callbacks def on_resize(self, widget, event): @@ -251,15 +238,12 @@ class Window(Adw.ApplicationWindow): GObject.idle_add(self._playlist_panel.set_size, width, height) GObject.idle_add(self._library_panel.set_size, width, height) - def on_maximized(self, widget, maximized): self._state.set_property(WindowState.IS_MAXIMIZED, maximized is True) - def on_fullscreened(self, widget, fullscreened): self._fullscreen(self.is_fullscreen()) - # HeaderBar callbacks @Gtk.Template.Callback() @@ -267,20 +251,17 @@ class Window(Adw.ApplicationWindow): if self._headerbar_connection_button_active: self._connect() - @Gtk.Template.Callback() def on_headerbar_volume_changed(self, widget, value): if not self._setting_volume: self._mcg.set_volume(int(value*100)) - @Gtk.Template.Callback() def on_headerbar_playpause_toggled(self, widget): if self._headerbar_playpause_button_active: self._mcg.playpause() self._mcg.get_status() - # Panel callbacks def on_stack_switched(self, widget, prop): @@ -290,17 +271,14 @@ class Window(Adw.ApplicationWindow): for panel in self._panels: panel.set_selected(panel == self.panel_stack.get_visible_child()) - def on_panel_open_standalone(self, panel): self.toolbar_view.add_top_bar(panel.get_headerbar_standalone()) self.toolbar_view.remove(self.headerbar) - def on_panel_close_standalone(self, panel): self.toolbar_view.add_top_bar(self.headerbar) self.toolbar_view.remove(panel.get_headerbar_standalone()) - def on_connection_panel_connection_changed(self, widget, host, port, password): self._settings.set_string(Window.SETTING_HOST, host) self._settings.set_int(Window.SETTING_PORT, port) @@ -311,79 +289,61 @@ class Window(Adw.ApplicationWindow): if keyring.get_password(ZeroconfProvider.KEYRING_SYSTEM, ZeroconfProvider.KEYRING_USERNAME): keyring.delete_password(ZeroconfProvider.KEYRING_SYSTEM, ZeroconfProvider.KEYRING_USERNAME) - def on_playlist_panel_clear_playlist(self, widget): self._mcg.clear_playlist() - def on_playlist_panel_remove(self, widget, album): self._mcg.remove_album_from_playlist(album) - def on_playlist_panel_remove_multiple(self, widget, albums): self._mcg.remove_albums_from_playlist(albums) - def on_playlist_panel_play(self, widget, album): self._mcg.play_album_from_playlist(album) - def on_playlist_panel_albumart(self, widget, album): self._mcg.get_albumart(album) - def on_server_panel_output_device_changed(self, widget, device, enabled): self._mcg.enable_output_device(device, enabled) - def on_cover_panel_toggle_fullscreen(self, widget): if not self._state.get_property(WindowState.IS_FULLSCREENED): self.fullscreen() else: self.unfullscreen() - def on_cover_panel_set_song(self, widget, pos, time): self._mcg.seek(pos, time) - def on_cover_panel_albumart(self, widget, album): self._mcg.get_albumart(album) - def on_library_panel_update(self, widget): self._mcg.update() - def on_library_panel_play(self, widget, album): self._mcg.play_album(album) - def on_library_panel_queue(self, widget, album): self._mcg.queue_album(album) - def on_library_panel_queue_multiple(self, widget, albums): self._mcg.queue_albums(albums) - def on_library_panel_item_size_changed(self, widget, size): self._playlist_panel.set_item_size(size) self._settings.set_int(Window.SETTING_ITEM_SIZE, self._library_panel.get_item_size()) - def on_library_panel_sort_order_changed(self, widget, sort_order): self._settings.set_enum(Window.SETTING_SORT_ORDER, sort_order) - def on_library_panel_sort_type_changed(self, widget, sort_type): self._settings.set_boolean(Window.SETTING_SORT_TYPE, sort_type) - def on_library_panel_albumart(self, widget, album): self._mcg.get_albumart(album) - # MCG callbacks def on_mcg_connect(self, connected): @@ -405,7 +365,6 @@ class Window(Adw.ApplicationWindow): self._clear_playlist_action.set_enabled(False) self._panel_action.set_enabled(False) - def on_mcg_status(self, state, album, pos, time, volume, file, audio, bitrate, error): # Album GObject.idle_add(self._cover_panel.set_album, album) @@ -428,64 +387,51 @@ class Window(Adw.ApplicationWindow): if error: self._show_error(error) - def on_mcg_stats(self, artists, albums, songs, dbplaytime, playtime, uptime): self._server_panel.set_stats(artists, albums, songs, dbplaytime, playtime, uptime) - def on_mcg_load_output_devices(self, devices): self._server_panel.set_output_devices(devices) - def on_mcg_load_playlist(self, playlist): self._playlist_panel.set_playlist(self._connection_panel.get_host(), playlist) - def on_mcg_init_albums(self): GObject.idle_add(self._library_panel.init_albums) - def on_mcg_pulse_albums(self): GObject.idle_add(self._library_panel.load_albums) - def on_mcg_load_albums(self, albums): self._library_panel.set_albums(self._connection_panel.get_host(), albums) - def on_mcg_load_albumart(self, album, data): self._cover_panel.set_albumart(album, data) self._playlist_panel.set_albumart(album, data) self._library_panel.set_albumart(album, data) - def on_mcg_error(self, error): GObject.idle_add(self._show_error, str(error)) - # Settings callbacks def on_settings_panel_changed(self, settings, key): panel_index = settings.get_int(key) self.panel_stack.set_visible_child(self._panels[panel_index]) - def on_settings_item_size_changed(self, settings, key): size = settings.get_int(key) self._playlist_panel.set_item_size(size) self._library_panel.set_item_size(size) - def on_settings_sort_order_changed(self, settings, key): sort_order = settings.get_enum(key) self._library_panel.set_sort_order(sort_order) - def on_settings_sort_type_changed(self, settings, key): sort_type = settings.get_boolean(key) self._library_panel.set_sort_type(sort_type) - # Private methods def _connect(self): @@ -501,14 +447,12 @@ class Window(Adw.ApplicationWindow): self._mcg.connect(host, port, password) self._settings.set_boolean(Window.SETTING_CONNECTED, True) - def _connect_connected(self): self._headerbar_connected() self._set_headerbar_sensitive(True, False) self.content_stack.set_visible_child(self.panel_stack) self.panel_stack.set_visible_child(self._panels[self._settings.get_int(Window.SETTING_PANEL)]) - def _connect_disconnected(self): self._playlist_panel.stop_threads(); self._library_panel.stop_threads(); @@ -518,7 +462,6 @@ class Window(Adw.ApplicationWindow): self.content_stack.set_visible_child(self._connection_panel) self._connection_panel.set_sensitive(True) - def _fullscreen(self, fullscreened_new): if fullscreened_new != self._state.get_property(WindowState.IS_FULLSCREENED): self._state.set_property(WindowState.IS_FULLSCREENED, fullscreened_new) @@ -531,35 +474,29 @@ class Window(Adw.ApplicationWindow): self._cover_panel.set_fullscreen(False) self.set_cursor(Gdk.Cursor.new_from_name("default", None)) - def _save_visible_panel(self): panel_index_selected = self._panels.index(self.panel_stack.get_visible_child()) self._settings.set_int(Window.SETTING_PANEL, panel_index_selected) - def _set_menu_visible_panel(self): panel_index_selected = self._panels.index(self.panel_stack.get_visible_child()) self._panel_action.set_state(GLib.Variant.new_string(str(panel_index_selected))) - def _set_visible_toolbar(self): panel_index_selected = self._panels.index(self.panel_stack.get_visible_child()) toolbar = self._panels[panel_index_selected].get_toolbar() self.toolbar_stack.set_visible_child(toolbar) - def _set_play(self): self._headerbar_playpause_button_active = False self.headerbar_button_playpause.set_active(True) self._headerbar_playpause_button_active = True - def _set_pause(self): self._headerbar_playpause_button_active = False self.headerbar_button_playpause.set_active(False) self._headerbar_playpause_button_active = True - def _set_volume(self, volume): if volume >= 0: self.headerbar_button_volume.set_visible(True) @@ -569,27 +506,23 @@ class Window(Adw.ApplicationWindow): else: self.headerbar_button_volume.set_visible(False) - def _headerbar_connected(self): self._headerbar_connection_button_active = False self.headerbar_button_connect.set_active(True) self.headerbar_button_connect.set_state(True) self._headerbar_connection_button_active = True - def _headerbar_disconnected(self): self._headerbar_connection_button_active = False self.headerbar_button_connect.set_active(False) self.headerbar_button_connect.set_state(False) self._headerbar_connection_button_active = True - def _set_headerbar_sensitive(self, sensitive, connecting): self.headerbar_button_playpause.set_sensitive(sensitive) self.headerbar_button_volume.set_sensitive(sensitive) self.headerbar_panel_switcher.set_sensitive(sensitive) self.headerbar_button_connect.set_sensitive(not connecting) - def _show_error(self, message): self.info_toast.add_toast(Adw.Toast.new(message)) diff --git a/src/zeroconf.py b/src/zeroconf.py index eaa1faa..93a92f9 100644 --- a/src/zeroconf.py +++ b/src/zeroconf.py @@ -13,15 +13,12 @@ import logging from mcg import client - - class ZeroconfProvider(client.Base): KEYRING_SYSTEM = 'mcg' KEYRING_USERNAME = 'mpd' SIGNAL_SERVICE_NEW = 'service-new' TYPE = '_mpd._tcp' - def __init__(self): client.Base.__init__(self) self._service_resolvers = [] @@ -31,7 +28,6 @@ class ZeroconfProvider(client.Base): if use_avahi: self._start_client() - def on_new_service(self, browser, interface, protocol, name, type, domain, flags): #if not (flags & Avahi.LookupResultFlags.GA_LOOKUP_RESULT_LOCAL): service_resolver = Avahi.ServiceResolver(interface=interface, protocol=protocol, name=name, type=type, domain=domain, aprotocol=Avahi.Protocol.GA_PROTOCOL_UNSPEC, flags=0,) @@ -40,19 +36,16 @@ class ZeroconfProvider(client.Base): service_resolver.attach(self._client) self._service_resolvers.append(service_resolver) - def on_found(self, resolver, interface, protocol, name, type, domain, host, date, port, *args): if (host, port) not in self._services.keys(): service = (name,host,port) self._services[(host,port)] = service self._callback(ZeroconfProvider.SIGNAL_SERVICE_NEW, service) - def on_failure(self, resolver, date): if resolver in self._service_resolvers: self._service_resolvers.remove(resolver) - def _start_client(self): self._logger.info("Starting Avahi client") self._client = Avahi.Client(flags=0,) From befd2e06e7dbdea44262351fae6068178f9e8f12 Mon Sep 17 00:00:00 2001 From: coderkun Date: Mon, 27 May 2024 12:46:46 +0200 Subject: [PATCH 2/6] Adjust line length to match Code Style Guide (see #103) --- src/application.py | 15 +- src/client.py | 159 ++++++++++++++--- src/connectionpanel.py | 12 +- src/coverpanel.py | 23 ++- src/librarypanel.py | 117 ++++++++++--- src/playlistpanel.py | 54 ++++-- src/serverpanel.py | 26 ++- src/utils.py | 6 +- src/window.py | 377 +++++++++++++++++++++++++++++++++-------- src/zeroconf.py | 42 ++++- 10 files changed, 683 insertions(+), 148 deletions(-) diff --git a/src/application.py b/src/application.py index f7b9eda..97ea726 100644 --- a/src/application.py +++ b/src/application.py @@ -18,7 +18,10 @@ class Application(Gtk.Application): DOMAIN = 'mcg' def __init__(self): - super().__init__(application_id=Application.ID, flags=Gio.ApplicationFlags.FLAGS_NONE) + super().__init__( + application_id=Application.ID, + flags=Gio.ApplicationFlags.FLAGS_NONE + ) self._window = None self._info_dialog = None self._verbosity = logging.WARNING @@ -55,10 +58,16 @@ class Application(Gtk.Application): self._info_dialog.set_application_icon("xyz.suruatoel.mcg") self._info_dialog.set_application_name("CoverGrid") self._info_dialog.set_version("3.2.1") - self._info_dialog.set_comments("CoverGrid is a client for the Music Player Daemon, focusing on albums instead of single tracks.") + self._info_dialog.set_comments( + """CoverGrid is a client for the Music Player Daemon, focusing on + albums instead of single tracks. + """ + ) self._info_dialog.set_website("https://www.suruatoel.xyz/codes/mcg") self._info_dialog.set_license_type(Gtk.License.GPL_3_0) - self._info_dialog.set_issue_url("https://git.suruatoel.xyz/coderkun/mcg") + self._info_dialog.set_issue_url( + "https://git.suruatoel.xyz/coderkun/mcg" + ) self._info_dialog.present() def on_menu_quit(self, action, value): diff --git a/src/client.py b/src/client.py index 7d5ab8b..3514aa7 100644 --- a/src/client.py +++ b/src/client.py @@ -186,7 +186,10 @@ class Client(Base): def get_output_devices(self): """Determine the list of audio output devices.""" self._logger.info("get output devices") - self._add_action_signal(Client.SIGNAL_LOAD_OUTPUT_DEVICES, self._get_output_devices) + self._add_action_signal( + Client.SIGNAL_LOAD_OUTPUT_DEVICES, + self._get_output_devices + ) def enable_output_device(self, device, enabled): """Enable/disable an audio output device.""" @@ -203,7 +206,10 @@ class Client(Base): def load_playlist(self): self._logger.info("load playlist") - self._add_action_signal(Client.SIGNAL_LOAD_PLAYLIST, self._load_playlist) + self._add_action_signal( + Client.SIGNAL_LOAD_PLAYLIST, + self._load_playlist + ) def clear_playlist(self): """Clear the current playlist""" @@ -260,7 +266,10 @@ class Client(Base): def get_albumart(self, album): self._logger.info("get albumart") - self._add_action_signal(Client.SIGNAL_LOAD_ALBUMART, self._get_albumart, album) + self._add_action_signal( + Client.SIGNAL_LOAD_ALBUMART, + self._get_albumart, album + ) def get_albumart_now(self, album): self._logger.info("get albumart now") @@ -290,7 +299,14 @@ class Client(Base): def _connect_socket(self, host, port): sock = None error = None - for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP): + resources = socket.getaddrinfo( + host, + port, + socket.AF_UNSPEC, + socket.SOCK_STREAM, + socket.IPPROTO_TCP + ) + for res in resources: af, socktype, proto, canonname, sa = res try: sock = socket.socket(af, socktype, proto) @@ -313,7 +329,9 @@ class Client(Base): if not greeting.startswith(Client.PROTOCOL_GREETING): self._disconnect_socket() raise ProtocolException("invalid greeting: {}".format(greeting)) - self._protocol_version = greeting[len(Client.PROTOCOL_GREETING):].strip() + self._protocol_version = greeting[ + len(Client.PROTOCOL_GREETING): + ].strip() self._logger.debug("protocol version: %s", self._protocol_version) def _disconnect(self): @@ -476,7 +494,14 @@ class Client(Base): album = self._extract_album(album) self._logger.debug("album: %r", album) # Tracks - for song in self._parse_list(self._call('find album ', album.get_title()), ['file']): + songs = self._parse_list( + self._call( + 'find album ', + album.get_title() + ), + ['file'] + ) + for song in songs: track = self._extract_track(song) if track: self._logger.debug("track: %r", track) @@ -488,14 +513,23 @@ class Client(Base): def _load_playlist(self): self._playlist = [] - for song in self._parse_list(self._call('playlistinfo'), ['file', 'playlist']): + songs = self._parse_list( + self._call( + 'playlistinfo' + ), + ['file', 'playlist'] + ) + for song in songs: self._logger.debug("song: %r", song) # Track track = self._extract_playlist_track(song) self._logger.debug("track: %r", track) # Album album = self._extract_album(song, lookup=False) - if len(self._playlist) == 0 or self._playlist[len(self._playlist)-1] != album: + if ( + len(self._playlist) == 0 + or self._playlist[len(self._playlist)-1] != album + ): self._playlist.append(album) else: album = self._playlist[len(self._playlist)-1] @@ -547,7 +581,12 @@ class Client(Base): for track in self._albums[album].get_tracks(): self._logger.info("addid: %r", track.get_file()) track_id = None - track_id_response = self._parse_dict(self._call('addid', track.get_file())) + track_id_response = self._parse_dict( + self._call( + 'addid', + track.get_file() + ) + ) if 'id' in track_id_response: track_id = track_id_response['id'] self._logger.debug("track id: %r", track_id) @@ -572,19 +611,33 @@ class Client(Base): def _get_albumart(self, album): if album in self._albums: album = self._albums[album] - self._logger.debug("get albumart for album \"%s\"", album.get_title()) + self._logger.debug( + "get albumart for album \"%s\"", + album.get_title() + ) # Use "albumart" command if album.get_tracks(): try: - return (album, self._read_binary('albumart', album.get_tracks()[0].get_file(), False)) + return ( + album, + self._read_binary( + 'albumart', + album.get_tracks()[0].get_file(), + False + ) + ) except CommandException as e: # The "albumart" command throws an exception if not found if e.get_error_number() != Client.PROTOCOL_ERROR_NOEXISTS: raise e # If no albumart can be found, use "readpicture" command for track in album.get_tracks(): - data = self._read_binary('readpicture', track.get_file(), True) + data = self._read_binary( + 'readpicture', + track.get_file(), + True + ) if data: return (album, data) @@ -593,7 +646,11 @@ class Client(Base): def _start_worker(self): """Start the worker thread which waits for action to be performed.""" self._logger.debug("start worker") - self._worker = threading.Thread(target=self._run, name='mcg-worker', args=()) + self._worker = threading.Thread( + target=self._run, + name='mcg-worker', + args=() + ) self._worker.setDaemon(True) self._worker.start() self._logger.debug("worker started") @@ -621,7 +678,12 @@ class Client(Base): def _add_action_signal(self, signal, method, *args): """Add an action to the action list that triggers a callback.""" - self._logger.debug("add action signal %r: %r (%r)", signal, method.__name__, args) + self._logger.debug( + "add action signal %r: %r (%r)", + signal, + method.__name__, + args + ) future = Future(signal) future.add_done_callback(self._callback_future) self._add_action_future(future, method, *args) @@ -656,7 +718,10 @@ class Client(Base): self._write(command, args) return self._read() except MPDException as e: - if command == 'idle' and e.get_error_number() == Client.PROTOCOL_ERROR_PERMISSION: + if ( + command == 'idle' + and e.get_error_number() == Client.PROTOCOL_ERROR_PERMISSION + ): self.disconnect() self._callback(Client.SIGNAL_ERROR, e) @@ -664,13 +729,21 @@ class Client(Base): try: self._write(command, args) except MPDException as e: - if command == 'idle' and e.get_error_number() == Client.PROTOCOL_ERROR_PERMISSION: + if ( + command == 'idle' + and e.get_error_number() == Client.PROTOCOL_ERROR_PERMISSION + ): self.disconnect() self._callback(Client.SIGNAL_ERROR, e) def _write(self, command, args=None): if args is not None and len(args) > 0: - line = '{} "{}"\n'.format(command, '" "'.join(str(x).replace('"', '\\\"') for x in args)) + line = '{} "{}"\n'.format( + command, + '" "'.join( + str(x).replace('"', '\\\"') for x in args + ) + ) else: line = '{}\n'.format(command) self._logger.debug("write: %r", line) @@ -681,7 +754,10 @@ class Client(Base): self._logger.debug("reading response") response = [] line = self._read_line() - while not line.startswith(Client.PROTOCOL_COMPLETION) and not line.startswith(Client.PROTOCOL_ERROR): + while ( + not line.startswith(Client.PROTOCOL_COMPLETION) + and not line.startswith(Client.PROTOCOL_ERROR) + ): response.append(line.strip()) line = self._read_line() if line.startswith(Client.PROTOCOL_COMPLETION): @@ -915,7 +991,11 @@ class MCGAlbum: def get_artists(self): if self._albumartists: - return [artist for artist in self._artists if artist not in self._albumartists] + return [ + artist + for artist in self._artists + if artist not in self._albumartists + ] return self._artists def get_albumartists(self): @@ -946,13 +1026,19 @@ class MCGAlbum: for artist in track.get_albumartists(): if artist not in self._albumartists: self._albumartists.append(artist) - if track.get_date() is not None and track.get_date() not in self._dates: + if ( + track.get_date() is not None + and track.get_date() not in self._dates + ): self._dates.append(track.get_date()) path = os.path.dirname(track.get_file()) if path not in self._pathes: self._pathes.append(path) if track.get_last_modified(): - if not self._last_modified or track.get_last_modified() > self._last_modified: + if ( + not self._last_modified + or track.get_last_modified() > self._last_modified + ): self._last_modified = track.get_last_modified() def get_tracks(self): @@ -982,7 +1068,10 @@ class MCGAlbum: continue # Search in track data for track in self._tracks: - if keyword in track.get_title().lower() or keyword in track.get_file().lower(): + if ( + keyword in track.get_title().lower() + or keyword in track.get_file().lower() + ): result = True break if not result: @@ -1045,7 +1134,11 @@ class MCGTrack: def get_artists(self): if self._albumartists: - return [artist for artist in self._artists if artist not in self._albumartists] + return [ + artist + for artist in self._artists + if artist not in self._albumartists + ] return self._artists def set_albumartists(self, artists): @@ -1131,7 +1224,12 @@ class MCGConfig(configparser.ConfigParser): def __init__(self, filename): configparser.ConfigParser.__init__(self) - self._filename = os.path.expanduser(os.path.join(MCGConfig.CONFIG_DIR, filename)) + self._filename = os.path.expanduser( + os.path.join( + MCGConfig.CONFIG_DIR, + filename + ) + ) self._create_dir() def load(self): @@ -1157,7 +1255,12 @@ class MCGCache(): self._logger = logging.getLogger(__name__) self._host = host self._size = size - self._dirname = os.path.expanduser(os.path.join(MCGCache.DIRNAME, host)) + self._dirname = os.path.expanduser( + os.path.join( + MCGCache.DIRNAME, + host + ) + ) if not os.path.exists(self._dirname): os.makedirs(self._dirname) self._read_size() @@ -1175,7 +1278,11 @@ class MCGCache(): try: size = int(f.readline()) except: - self._logger.warning("invalid cache file: %s, deleting file", filename, exc_info=True) + self._logger.warning( + "invalid cache file: %s, deleting file", + filename, + exc_info=True + ) size = None # Clear cache if size has changed if size != self._size: diff --git a/src/connectionpanel.py b/src/connectionpanel.py index 8cf7a08..c89f431 100644 --- a/src/connectionpanel.py +++ b/src/connectionpanel.py @@ -30,7 +30,10 @@ class ConnectionPanel(Adw.Bin): # Zeroconf provider self._zeroconf_provider = ZeroconfProvider() - self._zeroconf_provider.connect_signal(ZeroconfProvider.SIGNAL_SERVICE_NEW, self.on_new_service) + self._zeroconf_provider.connect_signal( + ZeroconfProvider.SIGNAL_SERVICE_NEW, + self.on_new_service + ) def on_new_service(self, service): name, host, port = service @@ -82,4 +85,9 @@ class ConnectionPanel(Adw.Bin): return self.password_entry.get_text() def _call_back(self): - self.emit('connection-changed', self.get_host(), self.get_port(), self.get_password(),) + self.emit( + 'connection-changed', + self.get_host(), + self.get_port(), + self.get_password(), + ) diff --git a/src/coverpanel.py b/src/coverpanel.py index 645149c..b71aaa3 100644 --- a/src/coverpanel.py +++ b/src/coverpanel.py @@ -48,7 +48,9 @@ class CoverPanel(Gtk.Overlay): self._cover_pixbuf = None self._timer = None self._properties = {} - self._icon_theme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default()) + self._icon_theme = Gtk.IconTheme.get_for_display( + Gdk.Display.get_default() + ) self._fullscreened = False self._current_size = None @@ -63,7 +65,10 @@ class CoverPanel(Gtk.Overlay): # Button controller for songs scale buttonController = Gtk.GestureClick() buttonController.connect('pressed', self.on_songs_scale_pressed) - buttonController.connect('unpaired-release', self.on_songs_scale_released) + buttonController.connect( + 'unpaired-release', + self.on_songs_scale_released + ) self.songs_scale.add_controller(buttonController) def get_toolbar(self): @@ -103,7 +108,11 @@ class CoverPanel(Gtk.Overlay): # Set labels self.album_title_label.set_label(album.get_title()) self.album_date_label.set_label(', '.join(album.get_dates())) - self.album_artist_label.set_label(', '.join(album.get_albumartists())) + self.album_artist_label.set_label( + ', '.join( + album.get_albumartists() + ) + ) # Set tracks self._set_tracks(album) @@ -239,5 +248,11 @@ class CoverPanel(Gtk.Overlay): height = int(math.floor(pixbuf.get_height()*ratio)) if width <= 0 or height <= 0: return - self.cover_image.set_from_pixbuf(pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.HYPER)) + self.cover_image.set_from_pixbuf( + pixbuf.scale_simple( + width, + height, + GdkPixbuf.InterpType.HYPER + ) + ) self.cover_image.show() diff --git a/src/librarypanel.py b/src/librarypanel.py index 6de3611..e20552e 100644 --- a/src/librarypanel.py +++ b/src/librarypanel.py @@ -28,7 +28,9 @@ class LibraryPanel(Adw.Bin): 'update': (GObject.SIGNAL_RUN_FIRST, None, ()), 'play': (GObject.SIGNAL_RUN_FIRST, None, (str,)), 'queue': (GObject.SIGNAL_RUN_FIRST, None, (str,)), - 'queue-multiple': (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)), + 'queue-multiple': ( + GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT,) + ), 'item-size-changed': (GObject.SIGNAL_RUN_FIRST, None, (int,)), 'sort-order-changed': (GObject.SIGNAL_RUN_FIRST, None, (int,)), 'sort-type-changed': (GObject.SIGNAL_RUN_FIRST, None, (bool,)), @@ -86,7 +88,9 @@ class LibraryPanel(Adw.Bin): self._old_ranges = {} self._library_lock = threading.Lock() self._library_stop = threading.Event() - self._icon_theme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default()) + self._icon_theme = Gtk.IconTheme.get_for_display( + Gdk.Display.get_default() + ) self._standalone_pixbuf = None self._selected_albums = [] self._is_selected = False @@ -94,13 +98,20 @@ class LibraryPanel(Adw.Bin): # Widgets # Header bar self._headerbar_standalone = AlbumHeaderbar() - self._headerbar_standalone.connect('close', self.on_standalone_close_clicked) + self._headerbar_standalone.connect( + 'close', + self.on_standalone_close_clicked + ) # Library Grid: Model self._library_grid_model = Gio.ListStore() self._library_grid_filter = Gtk.FilterListModel() self._library_grid_filter.set_model(self._library_grid_model) - self._library_grid_selection_multi = Gtk.MultiSelection.new(self._library_grid_filter) - self._library_grid_selection_single = Gtk.SingleSelection.new(self._library_grid_filter) + self._library_grid_selection_multi = Gtk.MultiSelection.new( + self._library_grid_filter + ) + self._library_grid_selection_single = Gtk.SingleSelection.new( + self._library_grid_filter + ) # Library Grid self.library_grid.set_model(self._library_grid_selection_single) # Toolbar menu @@ -114,7 +125,10 @@ class LibraryPanel(Adw.Bin): # Button controller for grid scale buttonController = Gtk.GestureClick() - buttonController.connect('unpaired-release', self.on_grid_scale_released) + buttonController.connect( + 'unpaired-release', + self.on_grid_scale_released + ) self.grid_scale.add_controller(buttonController) def get_headerbar_standalone(self): @@ -132,12 +146,16 @@ class LibraryPanel(Adw.Bin): self.actionbar_revealer.set_reveal_child(True) self.library_grid.set_model(self._library_grid_selection_multi) self.library_grid.set_single_click_activate(False) - self.library_grid.get_style_context().add_class(Utils.CSS_SELECTION) + self.library_grid.get_style_context().add_class( + Utils.CSS_SELECTION + ) else: self.actionbar_revealer.set_reveal_child(False) self.library_grid.set_model(self._library_grid_selection_single) self.library_grid.set_single_click_activate(True) - self.library_grid.get_style_context().remove_class(Utils.CSS_SELECTION) + self.library_grid.get_style_context().remove_class( + Utils.CSS_SELECTION + ) @Gtk.Template.Callback() def on_update_clicked(self, widget): @@ -164,7 +182,11 @@ class LibraryPanel(Adw.Bin): @Gtk.Template.Callback() def on_sort_toggled(self, widget): if widget.get_active(): - self._sort_order = [key for key, value in self._toolbar_sort_buttons.items() if value is widget][0] + self._sort_order = [ + key + for key, value in self._toolbar_sort_buttons.items() + if value is widget + ][0] self._sort_grid_model() self.emit('sort-order-changed', self._sort_order) @@ -183,7 +205,11 @@ class LibraryPanel(Adw.Bin): @Gtk.Template.Callback() def on_filter_entry_changed(self, widget): - self._library_grid_filter.set_filter(SearchFilter(self.filter_entry.get_text())) + self._library_grid_filter.set_filter( + SearchFilter( + self.filter_entry.get_text() + ) + ) @Gtk.Template.Callback() def on_library_grid_clicked(self, widget, position): @@ -243,13 +269,20 @@ class LibraryPanel(Adw.Bin): def set_sort_order(self, sort): button = self._toolbar_sort_buttons[sort] if button: - self._sort_order = [key for key, value in self._toolbar_sort_buttons.items() if value is button][0] + self._sort_order = [ + key + for key, value in self._toolbar_sort_buttons.items() + if value is button + ][0] if not button.get_active(): button.set_active(True) self._sort_grid_model() def set_sort_type(self, sort_type): - sort_type_gtk = Gtk.SortType.DESCENDING if sort_type else Gtk.SortType.ASCENDING + if sort_type: + sort_type_gtk = Gtk.SortType.DESCENDING + else: + sort_type_gtk = Gtk.SortType.ASCENDING if sort_type_gtk != self._sort_type: self._sort_type = sort_type_gtk @@ -268,7 +301,10 @@ class LibraryPanel(Adw.Bin): def set_albums(self, host, albums): self._host = host self._library_stop.set() - threading.Thread(target=self._set_albums, args=(host, albums, self._item_size,)).start() + threading.Thread( + target=self._set_albums, + args=(host, albums, self._item_size,) + ).start() def set_albumart(self, album, data): if album in self._selected_albums: @@ -285,10 +321,20 @@ class LibraryPanel(Adw.Bin): GObject.idle_add(self._show_image) def _sort_grid_model(self): - GObject.idle_add(self._library_grid_model.sort, self._grid_model_compare_func, self._sort_order, self._sort_type) + GObject.idle_add( + self._library_grid_model.sort, + self._grid_model_compare_func, + self._sort_order, + self._sort_type + ) def _grid_model_compare_func(self, item1, item2, criterion, order): - return client.MCGAlbum.compare(item1.get_album(), item2.get_album(), criterion, (order == Gtk.SortType.DESCENDING)) + return client.MCGAlbum.compare( + item1.get_album(), + item2.get_album(), + criterion, + (order == Gtk.SortType.DESCENDING) + ) def stop_threads(self): self._library_stop.set() @@ -297,7 +343,10 @@ class LibraryPanel(Adw.Bin): self._library_lock.acquire() self._albums = albums stack_transition_type = self.stack.get_transition_type() - GObject.idle_add(self.stack.set_transition_type, Gtk.StackTransitionType.NONE) + GObject.idle_add( + self.stack.set_transition_type, + Gtk.StackTransitionType.NONE + ) GObject.idle_add(self.stack.set_visible_child, self.progress_box) GObject.idle_add(self.progress_bar.set_fraction, 0.0) GObject.idle_add(self.stack.set_transition_type, stack_transition_type) @@ -328,11 +377,17 @@ class LibraryPanel(Adw.Bin): ) if pixbuf is not None: self._grid_pixbufs[album.get_id()] = pixbuf - GObject.idle_add(self._library_grid_model.append, GridItem(album, pixbuf)) + GObject.idle_add( + self._library_grid_model.append, + GridItem(album, pixbuf) + ) i += 1 GObject.idle_add(self.progress_bar.set_fraction, i/n) - GObject.idle_add(self.progress_bar.set_text, locale.gettext("Loading images")) + GObject.idle_add( + self.progress_bar.set_text, + locale.gettext("Loading images") + ) self._library_lock.release() GObject.idle_add(self.stack.set_visible_child, self.scroll) @@ -340,7 +395,10 @@ class LibraryPanel(Adw.Bin): def _set_widget_grid_size(self, grid_widget, size, vertical): self._library_stop.set() - threading.Thread(target=self._set_widget_grid_size_thread, args=(grid_widget, size, vertical,)).start() + threading.Thread( + target=self._set_widget_grid_size_thread, + args=(grid_widget, size, vertical,) + ).start() def _set_widget_grid_size_thread(self, grid_widget, size, vertical): self._library_lock.acquire() @@ -354,7 +412,11 @@ class LibraryPanel(Adw.Bin): pixbuf = self._grid_pixbufs[album_id] if pixbuf is not None: - pixbuf = pixbuf.scale_simple(size, size, GdkPixbuf.InterpType.NEAREST) + pixbuf = pixbuf.scale_simple( + size, + size, + GdkPixbuf.InterpType.NEAREST + ) else: pixbuf = self._icon_theme.lookup_icon( Utils.STOCK_ICON_DEFAULT, @@ -435,7 +497,13 @@ class LibraryPanel(Adw.Bin): if width <= 0 or height <= 0: return # Pixelpuffer auf Oberfläche zeichnen - self.standalone_image.set_from_pixbuf(pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.HYPER)) + self.standalone_image.set_from_pixbuf( + pixbuf.scale_simple( + width, + height, + GdkPixbuf.InterpType.HYPER + ) + ) self.standalone_image.show() def _get_default_image(self): @@ -452,5 +520,10 @@ class LibraryPanel(Adw.Bin): albums = [] for i in range(self.library_grid.get_model().get_n_items()): if self.library_grid.get_model().is_selected(i): - albums.append(self.library_grid.get_model().get_item(i).get_album().get_id()) + albums.append( + self.library_grid.get_model() + .get_item(i) + .get_album() + .get_id() + ) return albums diff --git a/src/playlistpanel.py b/src/playlistpanel.py index f22fc10..5dd252c 100644 --- a/src/playlistpanel.py +++ b/src/playlistpanel.py @@ -23,8 +23,16 @@ class PlaylistPanel(Adw.Bin): 'open-standalone': (GObject.SIGNAL_RUN_FIRST, None, ()), 'close-standalone': (GObject.SIGNAL_RUN_FIRST, None, ()), 'clear-playlist': (GObject.SIGNAL_RUN_FIRST, None, ()), - 'remove-album': (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)), - 'remove-multiple-albums': (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)), + 'remove-album': ( + GObject.SIGNAL_RUN_FIRST, + None, + (GObject.TYPE_PYOBJECT,) + ), + 'remove-multiple-albums': ( + GObject.SIGNAL_RUN_FIRST, + None, + (GObject.TYPE_PYOBJECT,) + ), 'play': (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)), 'albumart': (GObject.SIGNAL_RUN_FIRST, None, (str,)), } @@ -58,7 +66,9 @@ class PlaylistPanel(Adw.Bin): self._playlist_albums = None self._playlist_lock = threading.Lock() self._playlist_stop = threading.Event() - self._icon_theme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default()) + self._icon_theme = Gtk.IconTheme.get_for_display( + Gdk.Display.get_default() + ) self._standalone_pixbuf = None self._selected_albums = [] self._is_selected = False @@ -66,11 +76,18 @@ class PlaylistPanel(Adw.Bin): # Widgets # Header bar self._headerbar_standalone = AlbumHeaderbar() - self._headerbar_standalone.connect('close', self.on_headerbar_close_clicked) + self._headerbar_standalone.connect( + 'close', + self.on_headerbar_close_clicked + ) # Playlist Grid: Model self._playlist_grid_model = Gio.ListStore() - self._playlist_grid_selection_multi = Gtk.MultiSelection.new(self._playlist_grid_model) - self._playlist_grid_selection_single = Gtk.SingleSelection.new(self._playlist_grid_model) + self._playlist_grid_selection_multi = Gtk.MultiSelection.new( + self._playlist_grid_model + ) + self._playlist_grid_selection_single = Gtk.SingleSelection.new( + self._playlist_grid_model + ) # Playlist Grid self.playlist_grid.set_model(self._playlist_grid_selection_single) @@ -89,12 +106,16 @@ class PlaylistPanel(Adw.Bin): self.actionbar_revealer.set_reveal_child(True) self.playlist_grid.set_model(self._playlist_grid_selection_multi) self.playlist_grid.set_single_click_activate(False) - self.playlist_grid.get_style_context().add_class(Utils.CSS_SELECTION) + self.playlist_grid.get_style_context().add_class( + Utils.CSS_SELECTION + ) else: self.actionbar_revealer.set_reveal_child(False) self.playlist_grid.set_model(self._playlist_grid_selection_single) self.playlist_grid.set_single_click_activate(True) - self.playlist_grid.get_style_context().remove_class(Utils.CSS_SELECTION) + self.playlist_grid.get_style_context().remove_class( + Utils.CSS_SELECTION + ) @Gtk.Template.Callback() def on_clear_clicked(self, widget): @@ -157,7 +178,10 @@ class PlaylistPanel(Adw.Bin): def set_playlist(self, host, playlist): self._host = host self._playlist_stop.set() - threading.Thread(target=self._set_playlist, args=(host, playlist, self._item_size,)).start() + threading.Thread( + target=self._set_playlist, + args=(host, playlist, self._item_size,) + ).start() def set_albumart(self, album, data): if album in self._selected_albums: @@ -258,7 +282,13 @@ class PlaylistPanel(Adw.Bin): if width <= 0 or height <= 0: return # Pixelpuffer auf Oberfläche zeichnen - self.standalone_image.set_from_pixbuf(pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.HYPER)) + self.standalone_image.set_from_pixbuf( + pixbuf.scale_simple( + width, + height, + GdkPixbuf.InterpType.HYPER + ) + ) self.standalone_image.show() def _get_default_image(self): @@ -275,5 +305,7 @@ class PlaylistPanel(Adw.Bin): albums = [] for i in range(self.playlist_grid.get_model().get_n_items()): if self.playlist_grid.get_model().is_selected(i): - albums.append(self.playlist_grid.get_model().get_item(i).get_album()) + albums.append( + self.playlist_grid.get_model().get_item(i).get_album() + ) return albums diff --git a/src/serverpanel.py b/src/serverpanel.py index 1e85b3c..c4ab7a6 100644 --- a/src/serverpanel.py +++ b/src/serverpanel.py @@ -12,7 +12,11 @@ from gi.repository import Gtk, Adw, GObject class ServerPanel(Adw.Bin): __gtype_name__ = 'McgServerPanel' __gsignals__ = { - 'change-output-device': (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT,bool,)), + 'change-output-device': ( + GObject.SIGNAL_RUN_FIRST, + None, + (GObject.TYPE_PYOBJECT,bool,) + ), } # Widgets @@ -60,7 +64,11 @@ class ServerPanel(Adw.Bin): if audio: parts = audio.split(":") if len(parts) == 3: - audio = "{} Hz, {} bit, {} channels".format(parts[0], parts[1], parts[2]) + audio = "{} Hz, {} bit, {} channels".format( + parts[0], + parts[1], + parts[2] + ) else: audio = self._none_label self.status_audio.set_markup(audio) @@ -93,17 +101,25 @@ class ServerPanel(Adw.Bin): device_ids.append(device.get_id()) if device.get_id() in self._output_buttons.keys(): self._output_buttons[device.get_id()].freeze_notify() - self._output_buttons[device.get_id()].set_active(device.is_enabled()) + self._output_buttons[device.get_id()].set_active( + device.is_enabled() + ) self._output_buttons[device.get_id()].thaw_notify() else: button = Gtk.CheckButton.new_with_label(device.get_name()) if device.is_enabled(): button.set_active(True) - handler = button.connect('toggled', self.on_output_device_toggled, device) + handler = button.connect( + 'toggled', + self.on_output_device_toggled, + device + ) self.output_devices.insert(button, -1) self._output_buttons[device.get_id()] = button # Remove devices for id in self._output_buttons.keys(): if id not in device_ids: - self.output_devices.remove(self._output_buttons[id].get_parent()) + self.output_devices.remove( + self._output_buttons[id].get_parent() + ) diff --git a/src/utils.py b/src/utils.py index f1918a8..6819ad0 100644 --- a/src/utils.py +++ b/src/utils.py @@ -35,7 +35,11 @@ class Utils: if albumart: pixbuf = Utils.load_pixbuf(albumart) if pixbuf is not None: - pixbuf = pixbuf.scale_simple(size, size, GdkPixbuf.InterpType.HYPER) + pixbuf = pixbuf.scale_simple( + size, + size, + GdkPixbuf.InterpType.HYPER + ) pixbuf.savev(cache_url, 'jpeg', [], []) return pixbuf diff --git a/src/window.py b/src/window.py index 579950a..df752de 100644 --- a/src/window.py +++ b/src/window.py @@ -92,20 +92,52 @@ class Window(Adw.ApplicationWindow): self._panels.append(self._cover_panel) # Playlist panel self._playlist_panel = PlaylistPanel(self._mcg) - self._playlist_panel.connect('open-standalone', self.on_panel_open_standalone) - self._playlist_panel.connect('close-standalone', self.on_panel_close_standalone) + self._playlist_panel.connect( + 'open-standalone', + self.on_panel_open_standalone + ) + self._playlist_panel.connect( + 'close-standalone', + self.on_panel_close_standalone + ) self._panels.append(self._playlist_panel) # Library panel self._library_panel = LibraryPanel(self._mcg) - self._library_panel.connect('open-standalone', self.on_panel_open_standalone) - self._library_panel.connect('close-standalone', self.on_panel_close_standalone) + self._library_panel.connect( + 'open-standalone', + self.on_panel_open_standalone + ) + self._library_panel.connect( + 'close-standalone', + self.on_panel_close_standalone + ) self._panels.append(self._library_panel) # Stack self.content_stack.add_child(self._connection_panel) - self.panel_stack.add_titled_with_icon(self._server_panel, 'server-panel', locale.gettext("Server"), "network-wired-symbolic") - self.panel_stack.add_titled_with_icon(self._cover_panel, 'cover-panel', locale.gettext("Cover"), "image-x-generic-symbolic") - self.panel_stack.add_titled_with_icon(self._playlist_panel, 'playlist-panel', locale.gettext("Playlist"), "view-list-symbolic") - self.panel_stack.add_titled_with_icon(self._library_panel, 'library-panel', locale.gettext("Library"), "emblem-music-symbolic") + self.panel_stack.add_titled_with_icon( + self._server_panel, + 'server-panel', + locale.gettext("Server"), + "network-wired-symbolic" + ) + self.panel_stack.add_titled_with_icon( + self._cover_panel, + 'cover-panel', + locale.gettext("Cover"), + "image-x-generic-symbolic" + ) + self.panel_stack.add_titled_with_icon( + self._playlist_panel, + 'playlist-panel', + locale.gettext("Playlist"), + "view-list-symbolic" + ) + self.panel_stack.add_titled_with_icon( + self._library_panel, + 'library-panel', + locale.gettext("Library"), + "emblem-music-symbolic" + ) # Toolbar stack self.toolbar_stack.add_child(self._server_panel.get_toolbar()) self.toolbar_stack.add_child(self._cover_panel.get_toolbar()) @@ -114,56 +146,163 @@ class Window(Adw.ApplicationWindow): # Properties self._set_headerbar_sensitive(False, False) - self._connection_panel.set_host(self._settings.get_string(Window.SETTING_HOST)) - self._connection_panel.set_port(self._settings.get_int(Window.SETTING_PORT)) + self._connection_panel.set_host( + self._settings.get_string(Window.SETTING_HOST) + ) + self._connection_panel.set_port( + self._settings.get_int(Window.SETTING_PORT) + ) if use_keyring: - self._connection_panel.set_password(keyring.get_password(ZeroconfProvider.KEYRING_SYSTEM, ZeroconfProvider.KEYRING_USERNAME)) - self._playlist_panel.set_item_size(self._settings.get_int(Window.SETTING_ITEM_SIZE)) - self._library_panel.set_item_size(self._settings.get_int(Window.SETTING_ITEM_SIZE)) - self._library_panel.set_sort_order(self._settings.get_enum(Window.SETTING_SORT_ORDER)) - self._library_panel.set_sort_type(self._settings.get_boolean(Window.SETTING_SORT_TYPE)) + self._connection_panel.set_password( + keyring.get_password( + ZeroconfProvider.KEYRING_SYSTEM, + ZeroconfProvider.KEYRING_USERNAME + ) + ) + self._playlist_panel.set_item_size( + self._settings.get_int(Window.SETTING_ITEM_SIZE) + ) + self._library_panel.set_item_size( + self._settings.get_int(Window.SETTING_ITEM_SIZE) + ) + self._library_panel.set_sort_order( + self._settings.get_enum(Window.SETTING_SORT_ORDER) + ) + self._library_panel.set_sort_type( + self._settings.get_boolean(Window.SETTING_SORT_TYPE) + ) # Signals self.connect("notify::default-width", self.on_resize) self.connect("notify::default-height", self.on_resize) self.connect("notify::maximized", self.on_maximized) self.connect("notify::fullscreened", self.on_fullscreened) - self._connection_panel.connect('connection-changed', self.on_connection_panel_connection_changed) - self.panel_stack.connect('notify::visible-child', self.on_stack_switched) - self._server_panel.connect('change-output-device', self.on_server_panel_output_device_changed) - self._cover_panel.connect('toggle-fullscreen', self.on_cover_panel_toggle_fullscreen) + self._connection_panel.connect( + 'connection-changed', + self.on_connection_panel_connection_changed + ) + self.panel_stack.connect( + 'notify::visible-child', + self.on_stack_switched + ) + self._server_panel.connect( + 'change-output-device', + self.on_server_panel_output_device_changed + ) + self._cover_panel.connect( + 'toggle-fullscreen', + self.on_cover_panel_toggle_fullscreen + ) self._cover_panel.connect('set-song', self.on_cover_panel_set_song) self._cover_panel.connect('albumart', self.on_cover_panel_albumart) - self._playlist_panel.connect('clear-playlist', self.on_playlist_panel_clear_playlist) - self._playlist_panel.connect('remove-album', self.on_playlist_panel_remove) - self._playlist_panel.connect('remove-multiple-albums', self.on_playlist_panel_remove_multiple) + self._playlist_panel.connect( + 'clear-playlist', + self.on_playlist_panel_clear_playlist + ) + self._playlist_panel.connect( + 'remove-album', + self.on_playlist_panel_remove + ) + self._playlist_panel.connect( + 'remove-multiple-albums', + self.on_playlist_panel_remove_multiple + ) self._playlist_panel.connect('play', self.on_playlist_panel_play) - self._playlist_panel.connect('albumart', self.on_playlist_panel_albumart) + self._playlist_panel.connect( + 'albumart', + self.on_playlist_panel_albumart + ) self._library_panel.connect('update', self.on_library_panel_update) self._library_panel.connect('play', self.on_library_panel_play) self._library_panel.connect('queue', self.on_library_panel_queue) - self._library_panel.connect('queue-multiple', self.on_library_panel_queue_multiple) - self._library_panel.connect('item-size-changed', self.on_library_panel_item_size_changed) - self._library_panel.connect('sort-order-changed', self.on_library_panel_sort_order_changed) - self._library_panel.connect('sort-type-changed', self.on_library_panel_sort_type_changed) + self._library_panel.connect( + 'queue-multiple', + self.on_library_panel_queue_multiple + ) + self._library_panel.connect( + 'item-size-changed', + self.on_library_panel_item_size_changed + ) + self._library_panel.connect( + 'sort-order-changed', + self.on_library_panel_sort_order_changed + ) + self._library_panel.connect( + 'sort-type-changed', + self.on_library_panel_sort_type_changed + ) self._library_panel.connect('albumart', self.on_library_panel_albumart) - self._mcg.connect_signal(client.Client.SIGNAL_CONNECTION, self.on_mcg_connect) - self._mcg.connect_signal(client.Client.SIGNAL_STATUS, self.on_mcg_status) + self._mcg.connect_signal( + client.Client.SIGNAL_CONNECTION, + self.on_mcg_connect + ) + self._mcg.connect_signal( + client.Client.SIGNAL_STATUS, + self.on_mcg_status + ) self._mcg.connect_signal(client.Client.SIGNAL_STATS, self.on_mcg_stats) - self._mcg.connect_signal(client.Client.SIGNAL_LOAD_OUTPUT_DEVICES, self.on_mcg_load_output_devices) - self._mcg.connect_signal(client.Client.SIGNAL_LOAD_PLAYLIST, self.on_mcg_load_playlist) - self._mcg.connect_signal(client.Client.SIGNAL_PULSE_ALBUMS, self.on_mcg_pulse_albums) - self._mcg.connect_signal(client.Client.SIGNAL_INIT_ALBUMS, self.on_mcg_init_albums) - self._mcg.connect_signal(client.Client.SIGNAL_LOAD_ALBUMS, self.on_mcg_load_albums) - self._mcg.connect_signal(client.Client.SIGNAL_LOAD_ALBUMART, self.on_mcg_load_albumart) - self._mcg.connect_signal(client.Client.SIGNAL_ERROR, self.on_mcg_error) - self._settings.connect('changed::'+Window.SETTING_PANEL, self.on_settings_panel_changed) - self._settings.connect('changed::'+Window.SETTING_ITEM_SIZE, self.on_settings_item_size_changed) - self._settings.connect('changed::'+Window.SETTING_SORT_ORDER, self.on_settings_sort_order_changed) - self._settings.connect('changed::'+Window.SETTING_SORT_TYPE, self.on_settings_sort_type_changed) - self._settings.bind(Window.SETTING_WINDOW_WIDTH, self._state, WindowState.WIDTH, Gio.SettingsBindFlags.DEFAULT) - self._settings.bind(Window.SETTING_WINDOW_HEIGHT, self._state, WindowState.HEIGHT, Gio.SettingsBindFlags.DEFAULT) - self._settings.bind(Window.SETTING_WINDOW_MAXIMIZED, self._state, WindowState.IS_MAXIMIZED, Gio.SettingsBindFlags.DEFAULT) + self._mcg.connect_signal( + client.Client.SIGNAL_LOAD_OUTPUT_DEVICES, + self.on_mcg_load_output_devices + ) + self._mcg.connect_signal( + client.Client.SIGNAL_LOAD_PLAYLIST, + self.on_mcg_load_playlist + ) + self._mcg.connect_signal( + client.Client.SIGNAL_PULSE_ALBUMS, + self.on_mcg_pulse_albums + ) + self._mcg.connect_signal( + client.Client.SIGNAL_INIT_ALBUMS, + self.on_mcg_init_albums + ) + self._mcg.connect_signal( + client.Client.SIGNAL_LOAD_ALBUMS, + self.on_mcg_load_albums + ) + self._mcg.connect_signal( + client.Client.SIGNAL_LOAD_ALBUMART, + self.on_mcg_load_albumart + ) + self._mcg.connect_signal( + client.Client.SIGNAL_ERROR, + self.on_mcg_error + ) + self._settings.connect( + 'changed::'+Window.SETTING_PANEL, + self.on_settings_panel_changed + ) + self._settings.connect( + 'changed::'+Window.SETTING_ITEM_SIZE, + self.on_settings_item_size_changed + ) + self._settings.connect( + 'changed::'+Window.SETTING_SORT_ORDER, + self.on_settings_sort_order_changed + ) + self._settings.connect( + 'changed::'+Window.SETTING_SORT_TYPE, + self.on_settings_sort_type_changed + ) + self._settings.bind( + Window.SETTING_WINDOW_WIDTH, + self._state, + WindowState.WIDTH, + Gio.SettingsBindFlags.DEFAULT + ) + self._settings.bind( + Window.SETTING_WINDOW_HEIGHT, + self._state, + WindowState.HEIGHT, + Gio.SettingsBindFlags.DEFAULT + ) + self._settings.bind( + Window.SETTING_WINDOW_MAXIMIZED, + self._state, + WindowState.IS_MAXIMIZED, + Gio.SettingsBindFlags.DEFAULT + ) # Actions self.set_default_size(self._state.width, self._state.height) @@ -174,29 +313,59 @@ class Window(Adw.ApplicationWindow): self._connect() # Menu actions - self._connect_action = Gio.SimpleAction.new_stateful("connect", None, GLib.Variant.new_boolean(False)) + self._connect_action = Gio.SimpleAction.new_stateful( + "connect", + None, + GLib.Variant.new_boolean(False) + ) self._connect_action.connect('change-state', self.on_menu_connect) self.add_action(self._connect_action) - self._play_action = Gio.SimpleAction.new_stateful("play", None, GLib.Variant.new_boolean(False)) + self._play_action = Gio.SimpleAction.new_stateful( + "play", + None, + GLib.Variant.new_boolean(False) + ) self._play_action.set_enabled(False) self._play_action.connect('change-state', self.on_menu_play) self.add_action(self._play_action) - self._clear_playlist_action = Gio.SimpleAction.new("clear-playlist", None) + self._clear_playlist_action = Gio.SimpleAction.new( + "clear-playlist", + None + ) self._clear_playlist_action.set_enabled(False) - self._clear_playlist_action.connect('activate', self.on_menu_clear_playlist) + self._clear_playlist_action.connect( + 'activate', + self.on_menu_clear_playlist + ) self.add_action(self._clear_playlist_action) panel_variant = GLib.Variant.new_string("0") - self._panel_action = Gio.SimpleAction.new_stateful("panel", panel_variant.get_type(), panel_variant) + self._panel_action = Gio.SimpleAction.new_stateful( + "panel", + panel_variant.get_type(), + panel_variant + ) self._panel_action.set_enabled(False) self._panel_action.connect('change-state', self.on_menu_panel) self.add_action(self._panel_action) - self._toggle_fullscreen_action = Gio.SimpleAction.new("toggle-fullscreen", None) + self._toggle_fullscreen_action = Gio.SimpleAction.new( + "toggle-fullscreen", + None + ) self._toggle_fullscreen_action.set_enabled(True) - self._toggle_fullscreen_action.connect('activate', self.on_menu_toggle_fullscreen) + self._toggle_fullscreen_action.connect( + 'activate', + self.on_menu_toggle_fullscreen + ) self.add_action(self._toggle_fullscreen_action) - self._search_library_action = Gio.SimpleAction.new("search-library", None) + self._search_library_action = Gio.SimpleAction.new( + "search-library", + None + ) self._search_library_action.set_enabled(True) - self._search_library_action.connect('activate', self.on_menu_search_library) + self._search_library_action.connect( + 'activate', + self.on_menu_search_library + ) self.add_action(self._search_library_action) # Menu callbacks @@ -212,7 +381,9 @@ class Window(Adw.ApplicationWindow): def on_menu_panel(self, action, value): action.set_state(value) - self.panel_stack.set_visible_child(self._panels[int(value.get_string())]) + self.panel_stack.set_visible_child( + self._panels[int(value.get_string())] + ) def on_menu_toggle_fullscreen(self, action, value): self.panel_stack.set_visible_child(self._cover_panel) @@ -279,15 +450,31 @@ class Window(Adw.ApplicationWindow): self.toolbar_view.add_top_bar(self.headerbar) self.toolbar_view.remove(panel.get_headerbar_standalone()) - def on_connection_panel_connection_changed(self, widget, host, port, password): + def on_connection_panel_connection_changed( + self, + widget, + host, + port, + password + ): self._settings.set_string(Window.SETTING_HOST, host) self._settings.set_int(Window.SETTING_PORT, port) if use_keyring: if password: - keyring.set_password(ZeroconfProvider.KEYRING_SYSTEM, ZeroconfProvider.KEYRING_USERNAME, password) + keyring.set_password( + ZeroconfProvider.KEYRING_SYSTEM, + ZeroconfProvider.KEYRING_USERNAME, + password + ) else: - if keyring.get_password(ZeroconfProvider.KEYRING_SYSTEM, ZeroconfProvider.KEYRING_USERNAME): - keyring.delete_password(ZeroconfProvider.KEYRING_SYSTEM, ZeroconfProvider.KEYRING_USERNAME) + if keyring.get_password( + ZeroconfProvider.KEYRING_SYSTEM, + ZeroconfProvider.KEYRING_USERNAME + ): + keyring.delete_password( + ZeroconfProvider.KEYRING_SYSTEM, + ZeroconfProvider.KEYRING_USERNAME + ) def on_playlist_panel_clear_playlist(self, widget): self._mcg.clear_playlist() @@ -333,7 +520,10 @@ class Window(Adw.ApplicationWindow): def on_library_panel_item_size_changed(self, widget, size): self._playlist_panel.set_item_size(size) - self._settings.set_int(Window.SETTING_ITEM_SIZE, self._library_panel.get_item_size()) + self._settings.set_int( + Window.SETTING_ITEM_SIZE, + self._library_panel.get_item_size() + ) def on_library_panel_sort_order_changed(self, widget, sort_order): self._settings.set_enum(Window.SETTING_SORT_ORDER, sort_order) @@ -365,7 +555,18 @@ class Window(Adw.ApplicationWindow): self._clear_playlist_action.set_enabled(False) self._panel_action.set_enabled(False) - def on_mcg_status(self, state, album, pos, time, volume, file, audio, bitrate, error): + def on_mcg_status( + self, + state, + album, + pos, + time, + volume, + file, + audio, + bitrate, + error + ): # Album GObject.idle_add(self._cover_panel.set_album, album) if not album and self._state.get_property(WindowState.IS_FULLSCREENED): @@ -387,14 +588,32 @@ class Window(Adw.ApplicationWindow): if error: self._show_error(error) - def on_mcg_stats(self, artists, albums, songs, dbplaytime, playtime, uptime): - self._server_panel.set_stats(artists, albums, songs, dbplaytime, playtime, uptime) + def on_mcg_stats( + self, + artists, + albums, + songs, + dbplaytime, + playtime, + uptime + ): + self._server_panel.set_stats( + artists, + albums, + songs, + dbplaytime, + playtime, + uptime + ) def on_mcg_load_output_devices(self, devices): self._server_panel.set_output_devices(devices) def on_mcg_load_playlist(self, playlist): - self._playlist_panel.set_playlist(self._connection_panel.get_host(), playlist) + self._playlist_panel.set_playlist( + self._connection_panel.get_host(), + playlist + ) def on_mcg_init_albums(self): GObject.idle_add(self._library_panel.init_albums) @@ -403,7 +622,10 @@ class Window(Adw.ApplicationWindow): GObject.idle_add(self._library_panel.load_albums) def on_mcg_load_albums(self, albums): - self._library_panel.set_albums(self._connection_panel.get_host(), albums) + self._library_panel.set_albums( + self._connection_panel.get_host(), + albums + ) def on_mcg_load_albumart(self, album, data): self._cover_panel.set_albumart(album, data) @@ -451,7 +673,9 @@ class Window(Adw.ApplicationWindow): self._headerbar_connected() self._set_headerbar_sensitive(True, False) self.content_stack.set_visible_child(self.panel_stack) - self.panel_stack.set_visible_child(self._panels[self._settings.get_int(Window.SETTING_PANEL)]) + self.panel_stack.set_visible_child( + self._panels[self._settings.get_int(Window.SETTING_PANEL)] + ) def _connect_disconnected(self): self._playlist_panel.stop_threads(); @@ -463,8 +687,13 @@ class Window(Adw.ApplicationWindow): self._connection_panel.set_sensitive(True) def _fullscreen(self, fullscreened_new): - if fullscreened_new != self._state.get_property(WindowState.IS_FULLSCREENED): - self._state.set_property(WindowState.IS_FULLSCREENED, fullscreened_new) + if fullscreened_new != self._state.get_property( + WindowState.IS_FULLSCREENED + ): + self._state.set_property( + WindowState.IS_FULLSCREENED, + fullscreened_new + ) if self._state.get_property(WindowState.IS_FULLSCREENED): self.headerbar.hide() self._cover_panel.set_fullscreen(True) @@ -475,15 +704,23 @@ class Window(Adw.ApplicationWindow): self.set_cursor(Gdk.Cursor.new_from_name("default", None)) def _save_visible_panel(self): - panel_index_selected = self._panels.index(self.panel_stack.get_visible_child()) + panel_index_selected = self._panels.index( + self.panel_stack.get_visible_child() + ) self._settings.set_int(Window.SETTING_PANEL, panel_index_selected) def _set_menu_visible_panel(self): - panel_index_selected = self._panels.index(self.panel_stack.get_visible_child()) - self._panel_action.set_state(GLib.Variant.new_string(str(panel_index_selected))) + panel_index_selected = self._panels.index( + self.panel_stack.get_visible_child() + ) + self._panel_action.set_state( + GLib.Variant.new_string(str(panel_index_selected)) + ) def _set_visible_toolbar(self): - panel_index_selected = self._panels.index(self.panel_stack.get_visible_child()) + panel_index_selected = self._panels.index( + self.panel_stack.get_visible_child() + ) toolbar = self._panels[panel_index_selected].get_toolbar() self.toolbar_stack.set_visible_child(toolbar) diff --git a/src/zeroconf.py b/src/zeroconf.py index 93a92f9..939e54b 100644 --- a/src/zeroconf.py +++ b/src/zeroconf.py @@ -28,15 +28,44 @@ class ZeroconfProvider(client.Base): if use_avahi: self._start_client() - def on_new_service(self, browser, interface, protocol, name, type, domain, flags): + def on_new_service( + self, + browser, + interface, + protocol, + name, + type, + domain, + flags + ): #if not (flags & Avahi.LookupResultFlags.GA_LOOKUP_RESULT_LOCAL): - service_resolver = Avahi.ServiceResolver(interface=interface, protocol=protocol, name=name, type=type, domain=domain, aprotocol=Avahi.Protocol.GA_PROTOCOL_UNSPEC, flags=0,) + service_resolver = Avahi.ServiceResolver( + interface=interface, + protocol=protocol, + name=name, + type=type, + domain=domain, + aprotocol=Avahi.Protocol.GA_PROTOCOL_UNSPEC, + flags=0, + ) service_resolver.connect('found', self.on_found) service_resolver.connect('failure', self.on_failure) service_resolver.attach(self._client) self._service_resolvers.append(service_resolver) - def on_found(self, resolver, interface, protocol, name, type, domain, host, date, port, *args): + def on_found( + self, + resolver, + interface, + protocol, + name, + type, + domain, + host, + date, + port, + *args + ): if (host, port) not in self._services.keys(): service = (name,host,port) self._services[(host,port)] = service @@ -52,7 +81,12 @@ class ZeroconfProvider(client.Base): try: self._client.start() # Browser - self._service_browser = Avahi.ServiceBrowser(domain='local', flags=0, interface=-1, protocol=Avahi.Protocol.GA_PROTOCOL_UNSPEC, type=ZeroconfProvider.TYPE) + self._service_browser = Avahi.ServiceBrowser( + domain='local', + flags=0, interface=-1, + protocol=Avahi.Protocol.GA_PROTOCOL_UNSPEC, + type=ZeroconfProvider.TYPE + ) self._service_browser.connect('new_service', self.on_new_service) self._service_browser.attach(self._client) except Exception as e: From c04216e634c51bd98737b1b5c837ae423fe3a792 Mon Sep 17 00:00:00 2001 From: coderkun Date: Mon, 27 May 2024 18:08:58 +0200 Subject: [PATCH 3/6] fixup! Adjust blank lines to match Code Style Guide (see #103) --- src/__init__.py | 2 -- src/albumheaderbar.py | 2 +- src/application.py | 5 +---- src/client.py | 5 ++++- src/connectionpanel.py | 2 +- src/coverpanel.py | 3 +-- src/librarypanel.py | 3 +-- src/playlistpanel.py | 3 +-- src/serverpanel.py | 2 +- src/shortcutsdialog.py | 2 +- src/utils.py | 2 +- src/window.py | 2 +- src/zeroconf.py | 1 - 13 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/__init__.py b/src/__init__.py index 87f16c5..aae3b90 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1,10 +1,8 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- - import os - # Set environment srcdir = os.path.abspath(os.path.dirname(__file__)) datadir = os.path.join(srcdir, 'data') diff --git a/src/albumheaderbar.py b/src/albumheaderbar.py index 00397db..801e884 100644 --- a/src/albumheaderbar.py +++ b/src/albumheaderbar.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 - import gi + gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') diff --git a/src/application.py b/src/application.py index 97ea726..82f7bd9 100644 --- a/src/application.py +++ b/src/application.py @@ -1,14 +1,11 @@ #!/usr/bin/env python3 - import logging -import urllib - import gi + gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') from gi.repository import Gio, Gtk, Gdk, GLib, Adw - from .window import Window diff --git a/src/client.py b/src/client.py index 3514aa7..d8fe179 100644 --- a/src/client.py +++ b/src/client.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 - import concurrent.futures import configparser import dateutil.parser @@ -16,6 +15,7 @@ from mcg.utils import Utils class MPDException(Exception): + def __init__(self, error): super(MPDException, self).__init__(self._parse_error(error)) self._error = error @@ -56,6 +56,7 @@ class CommandException(MPDException): class Future(concurrent.futures.Future): + def __init__(self, signal): concurrent.futures.Future.__init__(self) self._signal = signal @@ -65,6 +66,7 @@ class Future(concurrent.futures.Future): class Base(): + def __init__(self): self._callbacks = {} @@ -1109,6 +1111,7 @@ class MCGAlbum: class MCGTrack: + def __init__(self, artists, title, file): if type(artists) is not list: artists = [artists] diff --git a/src/connectionpanel.py b/src/connectionpanel.py index c89f431..51e2b8b 100644 --- a/src/connectionpanel.py +++ b/src/connectionpanel.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 - import gi + gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') import locale diff --git a/src/coverpanel.py b/src/coverpanel.py index b71aaa3..164ac65 100644 --- a/src/coverpanel.py +++ b/src/coverpanel.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 - import gi + gi.require_version('Gtk', '4.0') import logging import math from gi.repository import Gtk, Gdk, GObject, GdkPixbuf - from mcg.utils import Utils diff --git a/src/librarypanel.py b/src/librarypanel.py index e20552e..f58ebd2 100644 --- a/src/librarypanel.py +++ b/src/librarypanel.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 - import gi + gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') import locale @@ -10,7 +10,6 @@ import math import threading from gi.repository import Gtk, Gdk, GObject, GdkPixbuf, Gio, Adw - from mcg import client from mcg.albumheaderbar import AlbumHeaderbar from mcg.utils import SortOrder diff --git a/src/playlistpanel.py b/src/playlistpanel.py index 5dd252c..341f9c8 100644 --- a/src/playlistpanel.py +++ b/src/playlistpanel.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 - import gi + gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') import logging @@ -9,7 +9,6 @@ import math import threading from gi.repository import Gtk, Gdk, Gio, GObject, GdkPixbuf, Adw - from mcg import client from mcg.albumheaderbar import AlbumHeaderbar from mcg.utils import Utils diff --git a/src/serverpanel.py b/src/serverpanel.py index c4ab7a6..0f39e86 100644 --- a/src/serverpanel.py +++ b/src/serverpanel.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 - import gi + gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') diff --git a/src/shortcutsdialog.py b/src/shortcutsdialog.py index 6b1d210..2db83e3 100644 --- a/src/shortcutsdialog.py +++ b/src/shortcutsdialog.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 - import gi + gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') from gi.repository import Gtk diff --git a/src/utils.py b/src/utils.py index 6819ad0..4146ef2 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 - import gi + gi.require_version('Gtk', '4.0') import hashlib import locale diff --git a/src/window.py b/src/window.py index df752de..120aa1d 100644 --- a/src/window.py +++ b/src/window.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 - import gi + gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') try: diff --git a/src/zeroconf.py b/src/zeroconf.py index 939e54b..82fb438 100644 --- a/src/zeroconf.py +++ b/src/zeroconf.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 - import gi try: gi.require_version('Avahi', '0.6') From ded9cf026b6031b68884576538efec8550b55a49 Mon Sep 17 00:00:00 2001 From: coderkun Date: Mon, 27 May 2024 18:29:01 +0200 Subject: [PATCH 4/6] fixup! Adjust line length to match Code Style Guide (see #103) --- src/albumheaderbar.py | 4 +- src/application.py | 27 +-- src/client.py | 152 +++++---------- src/connectionpanel.py | 4 +- src/coverpanel.py | 54 ++---- src/librarypanel.py | 175 ++++++----------- src/playlistpanel.py | 84 +++----- src/serverpanel.py | 30 ++- src/utils.py | 18 +- src/window.py | 424 +++++++++++++---------------------------- src/zeroconf.py | 39 +--- 11 files changed, 326 insertions(+), 685 deletions(-) diff --git a/src/albumheaderbar.py b/src/albumheaderbar.py index 801e884..2a8a7e1 100644 --- a/src/albumheaderbar.py +++ b/src/albumheaderbar.py @@ -11,9 +11,7 @@ from gi.repository import Gtk, GObject, Adw @Gtk.Template(resource_path='/xyz/suruatoel/mcg/ui/album-headerbar.ui') class AlbumHeaderbar(Adw.Bin): __gtype_name__ = 'McgAlbumHeaderbar' - __gsignals__ = { - 'close': (GObject.SIGNAL_RUN_FIRST, None, ()) - } + __gsignals__ = {'close': (GObject.SIGNAL_RUN_FIRST, None, ())} # Widgets standalone_title = Gtk.Template.Child() diff --git a/src/application.py b/src/application.py index 82f7bd9..187793e 100644 --- a/src/application.py +++ b/src/application.py @@ -15,10 +15,8 @@ class Application(Gtk.Application): DOMAIN = 'mcg' def __init__(self): - super().__init__( - application_id=Application.ID, - flags=Gio.ApplicationFlags.FLAGS_NONE - ) + super().__init__(application_id=Application.ID, + flags=Gio.ApplicationFlags.FLAGS_NONE) self._window = None self._info_dialog = None self._verbosity = logging.WARNING @@ -56,25 +54,20 @@ class Application(Gtk.Application): self._info_dialog.set_application_name("CoverGrid") self._info_dialog.set_version("3.2.1") self._info_dialog.set_comments( - """CoverGrid is a client for the Music Player Daemon, focusing on - albums instead of single tracks. - """ - ) + """CoverGrid is a client for the Music Player Daemon, focusing on \ +albums instead of single tracks.""") self._info_dialog.set_website("https://www.suruatoel.xyz/codes/mcg") self._info_dialog.set_license_type(Gtk.License.GPL_3_0) self._info_dialog.set_issue_url( - "https://git.suruatoel.xyz/coderkun/mcg" - ) + "https://git.suruatoel.xyz/coderkun/mcg") self._info_dialog.present() def on_menu_quit(self, action, value): self.quit() def _setup_logging(self): - logging.basicConfig( - level=self._verbosity, - format="%(asctime)s %(levelname)s: %(message)s" - ) + logging.basicConfig(level=self._verbosity, + format="%(asctime)s %(levelname)s: %(message)s") def _load_settings(self): self._settings = Gio.Settings.new(Application.ID) @@ -87,10 +80,8 @@ class Application(Gtk.Application): styleProvider = Gtk.CssProvider() styleProvider.load_from_resource(self._get_resource_path('gtk.css')) Gtk.StyleContext.add_provider_for_display( - Gdk.Display.get_default(), - styleProvider, - Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION - ) + Gdk.Display.get_default(), styleProvider, + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) def _setup_actions(self): action = Gio.SimpleAction.new("info", None) diff --git a/src/client.py b/src/client.py index d8fe179..a18846f 100644 --- a/src/client.py +++ b/src/client.py @@ -188,10 +188,8 @@ class Client(Base): def get_output_devices(self): """Determine the list of audio output devices.""" self._logger.info("get output devices") - self._add_action_signal( - Client.SIGNAL_LOAD_OUTPUT_DEVICES, - self._get_output_devices - ) + self._add_action_signal(Client.SIGNAL_LOAD_OUTPUT_DEVICES, + self._get_output_devices) def enable_output_device(self, device, enabled): """Enable/disable an audio output device.""" @@ -208,10 +206,8 @@ class Client(Base): def load_playlist(self): self._logger.info("load playlist") - self._add_action_signal( - Client.SIGNAL_LOAD_PLAYLIST, - self._load_playlist - ) + self._add_action_signal(Client.SIGNAL_LOAD_PLAYLIST, + self._load_playlist) def clear_playlist(self): """Clear the current playlist""" @@ -268,10 +264,8 @@ class Client(Base): def get_albumart(self, album): self._logger.info("get albumart") - self._add_action_signal( - Client.SIGNAL_LOAD_ALBUMART, - self._get_albumart, album - ) + self._add_action_signal(Client.SIGNAL_LOAD_ALBUMART, + self._get_albumart, album) def get_albumart_now(self, album): self._logger.info("get albumart now") @@ -301,13 +295,8 @@ class Client(Base): def _connect_socket(self, host, port): sock = None error = None - resources = socket.getaddrinfo( - host, - port, - socket.AF_UNSPEC, - socket.SOCK_STREAM, - socket.IPPROTO_TCP - ) + resources = socket.getaddrinfo(host, port, socket.AF_UNSPEC, + socket.SOCK_STREAM, socket.IPPROTO_TCP) for res in resources: af, socktype, proto, canonname, sa = res try: @@ -331,9 +320,8 @@ class Client(Base): if not greeting.startswith(Client.PROTOCOL_GREETING): self._disconnect_socket() raise ProtocolException("invalid greeting: {}".format(greeting)) - self._protocol_version = greeting[ - len(Client.PROTOCOL_GREETING): - ].strip() + self._protocol_version = greeting[len(Client.PROTOCOL_GREETING + ):].strip() self._logger.debug("protocol version: %s", self._protocol_version) def _disconnect(self): @@ -446,7 +434,7 @@ class Client(Base): artists = 0 if 'artists' in stats: artists = int(stats['artists']) - # Albums + # Albums albums = 0 if 'albums' in stats: albums = int(stats['albums']) @@ -497,12 +485,7 @@ class Client(Base): self._logger.debug("album: %r", album) # Tracks songs = self._parse_list( - self._call( - 'find album ', - album.get_title() - ), - ['file'] - ) + self._call('find album ', album.get_title()), ['file']) for song in songs: track = self._extract_track(song) if track: @@ -515,12 +498,8 @@ class Client(Base): def _load_playlist(self): self._playlist = [] - songs = self._parse_list( - self._call( - 'playlistinfo' - ), - ['file', 'playlist'] - ) + songs = self._parse_list(self._call('playlistinfo'), + ['file', 'playlist']) for song in songs: self._logger.debug("song: %r", song) # Track @@ -528,13 +507,11 @@ class Client(Base): self._logger.debug("track: %r", track) # Album album = self._extract_album(song, lookup=False) - if ( - len(self._playlist) == 0 - or self._playlist[len(self._playlist)-1] != album - ): + if (len(self._playlist) == 0 + or self._playlist[len(self._playlist) - 1] != album): self._playlist.append(album) else: - album = self._playlist[len(self._playlist)-1] + album = self._playlist[len(self._playlist) - 1] self._logger.debug("album: %r", album) if track: album.add_track(track) @@ -584,11 +561,7 @@ class Client(Base): self._logger.info("addid: %r", track.get_file()) track_id = None track_id_response = self._parse_dict( - self._call( - 'addid', - track.get_file() - ) - ) + self._call('addid', track.get_file())) if 'id' in track_id_response: track_id = track_id_response['id'] self._logger.debug("track id: %r", track_id) @@ -613,33 +586,24 @@ class Client(Base): def _get_albumart(self, album): if album in self._albums: album = self._albums[album] - self._logger.debug( - "get albumart for album \"%s\"", - album.get_title() - ) + self._logger.debug("get albumart for album \"%s\"", + album.get_title()) # Use "albumart" command if album.get_tracks(): try: - return ( - album, - self._read_binary( - 'albumart', - album.get_tracks()[0].get_file(), - False - ) - ) + return (album, + self._read_binary('albumart', + album.get_tracks()[0].get_file(), + False)) except CommandException as e: # The "albumart" command throws an exception if not found if e.get_error_number() != Client.PROTOCOL_ERROR_NOEXISTS: raise e # If no albumart can be found, use "readpicture" command for track in album.get_tracks(): - data = self._read_binary( - 'readpicture', - track.get_file(), - True - ) + data = self._read_binary('readpicture', + track.get_file(), True) if data: return (album, data) @@ -648,11 +612,9 @@ class Client(Base): def _start_worker(self): """Start the worker thread which waits for action to be performed.""" self._logger.debug("start worker") - self._worker = threading.Thread( - target=self._run, - name='mcg-worker', - args=() - ) + self._worker = threading.Thread(target=self._run, + name='mcg-worker', + args=()) self._worker.setDaemon(True) self._worker.start() self._logger.debug("worker started") @@ -680,12 +642,8 @@ class Client(Base): def _add_action_signal(self, signal, method, *args): """Add an action to the action list that triggers a callback.""" - self._logger.debug( - "add action signal %r: %r (%r)", - signal, - method.__name__, - args - ) + self._logger.debug("add action signal %r: %r (%r)", signal, + method.__name__, args) future = Future(signal) future.add_done_callback(self._callback_future) self._add_action_future(future, method, *args) @@ -741,11 +699,7 @@ class Client(Base): def _write(self, command, args=None): if args is not None and len(args) > 0: line = '{} "{}"\n'.format( - command, - '" "'.join( - str(x).replace('"', '\\\"') for x in args - ) - ) + command, '" "'.join(str(x).replace('"', '\\\"') for x in args)) else: line = '{}\n'.format(command) self._logger.debug("write: %r", line) @@ -828,7 +782,7 @@ class Client(Base): if not data: data = bytearray(size) # Create a view for the current chunk of data - data_view = memoryview(data)[offset:offset+binary] + data_view = memoryview(data)[offset:offset + binary] # Read actual bytes self._read_bytes(data_view, binary) offset += binary @@ -858,9 +812,9 @@ class Client(Base): def _buffer_get_char(self, char): pos = self._buffer.find(char) if pos < 0: - pos = len(self._buffer)-1 - buf = self._buffer[0:pos+1] - self._buffer = self._buffer[pos+1:] + pos = len(self._buffer) - 1 + buf = self._buffer[0:pos + 1] + self._buffer = self._buffer[pos + 1:] return buf def _buffer_get_size(self, size): @@ -994,8 +948,7 @@ class MCGAlbum: def get_artists(self): if self._albumartists: return [ - artist - for artist in self._artists + artist for artist in self._artists if artist not in self._albumartists ] return self._artists @@ -1138,8 +1091,7 @@ class MCGTrack: def get_artists(self): if self._albumartists: return [ - artist - for artist in self._artists + artist for artist in self._artists if artist not in self._albumartists ] return self._artists @@ -1164,7 +1116,7 @@ class MCGTrack: if type(track) is list: track = track[0] if type(track) is str and '/' in track: - track = track[0: track.index('/')] + track = track[0:track.index('/')] if track is not None: try: track = int(track) @@ -1201,13 +1153,10 @@ class MCGTrack: class MCGPlaylistTrack(MCGTrack): + def __init__(self, track, id, pos): - MCGTrack.__init__( - self, - track.get_artists(), - track.get_title(), - track.get_file() - ) + MCGTrack.__init__(self, track.get_artists(), track.get_title(), + track.get_file()) self.set_albumartists(track.get_albumartists()) self.set_track(track.get_track()) self.set_length(track.get_length()) @@ -1228,11 +1177,7 @@ class MCGConfig(configparser.ConfigParser): def __init__(self, filename): configparser.ConfigParser.__init__(self) self._filename = os.path.expanduser( - os.path.join( - MCGConfig.CONFIG_DIR, - filename - ) - ) + os.path.join(MCGConfig.CONFIG_DIR, filename)) self._create_dir() def load(self): @@ -1258,12 +1203,8 @@ class MCGCache(): self._logger = logging.getLogger(__name__) self._host = host self._size = size - self._dirname = os.path.expanduser( - os.path.join( - MCGCache.DIRNAME, - host - ) - ) + self._dirname = os.path.expanduser(os.path.join( + MCGCache.DIRNAME, host)) if not os.path.exists(self._dirname): os.makedirs(self._dirname) self._read_size() @@ -1284,8 +1225,7 @@ class MCGCache(): self._logger.warning( "invalid cache file: %s, deleting file", filename, - exc_info=True - ) + exc_info=True) size = None # Clear cache if size has changed if size != self._size: diff --git a/src/connectionpanel.py b/src/connectionpanel.py index 51e2b8b..4286e6a 100644 --- a/src/connectionpanel.py +++ b/src/connectionpanel.py @@ -31,9 +31,7 @@ class ConnectionPanel(Adw.Bin): # Zeroconf provider self._zeroconf_provider = ZeroconfProvider() self._zeroconf_provider.connect_signal( - ZeroconfProvider.SIGNAL_SERVICE_NEW, - self.on_new_service - ) + ZeroconfProvider.SIGNAL_SERVICE_NEW, self.on_new_service) def on_new_service(self, service): name, host, port = service diff --git a/src/coverpanel.py b/src/coverpanel.py index 164ac65..9ac970b 100644 --- a/src/coverpanel.py +++ b/src/coverpanel.py @@ -15,8 +15,8 @@ class CoverPanel(Gtk.Overlay): __gtype_name__ = 'McgCoverPanel' __gsignals__ = { 'toggle-fullscreen': (GObject.SIGNAL_RUN_FIRST, None, ()), - 'set-song': (GObject.SIGNAL_RUN_FIRST, None, (int, int,)), - 'albumart': (GObject.SIGNAL_RUN_FIRST, None, (str,)) + 'set-song': (GObject.SIGNAL_RUN_FIRST, None, (int, int, )), + 'albumart': (GObject.SIGNAL_RUN_FIRST, None, (str, )) } # Widgets @@ -48,8 +48,7 @@ class CoverPanel(Gtk.Overlay): self._timer = None self._properties = {} self._icon_theme = Gtk.IconTheme.get_for_display( - Gdk.Display.get_default() - ) + Gdk.Display.get_default()) self._fullscreened = False self._current_size = None @@ -64,10 +63,8 @@ class CoverPanel(Gtk.Overlay): # Button controller for songs scale buttonController = Gtk.GestureClick() buttonController.connect('pressed', self.on_songs_scale_pressed) - buttonController.connect( - 'unpaired-release', - self.on_songs_scale_released - ) + buttonController.connect('unpaired-release', + self.on_songs_scale_released) self.songs_scale.add_controller(buttonController) def get_toolbar(self): @@ -94,7 +91,7 @@ class CoverPanel(Gtk.Overlay): time = self._current_album.get_length() tracks = self._current_album.get_tracks() pos = 0 - for index in range(len(tracks)-1, -1, -1): + for index in range(len(tracks) - 1, -1, -1): time = time - tracks[index].get_length() pos = tracks[index].get_pos() if time < value: @@ -107,11 +104,8 @@ class CoverPanel(Gtk.Overlay): # Set labels self.album_title_label.set_label(album.get_title()) self.album_date_label.set_label(', '.join(album.get_dates())) - self.album_artist_label.set_label( - ', '.join( - album.get_albumartists() - ) - ) + self.album_artist_label.set_label(', '.join( + album.get_albumartists())) # Set tracks self._set_tracks(album) @@ -135,7 +129,7 @@ class CoverPanel(Gtk.Overlay): for index in range(0, pos): time = time + tracks[index].get_length() - self.songs_scale.set_value(time+1) + self.songs_scale.set_value(time + 1) self._timer = GObject.timeout_add(1000, self._playing) def set_pause(self): @@ -180,18 +174,12 @@ class CoverPanel(Gtk.Overlay): if length > 0 and length < album.get_length(): cur_length = cur_length + 1 self.songs_scale.add_mark( - cur_length, - Gtk.PositionType.RIGHT, - GObject.markup_escape_text( - Utils.create_track_title(track) - ) - ) + cur_length, Gtk.PositionType.RIGHT, + GObject.markup_escape_text(Utils.create_track_title(track))) length = length + track.get_length() self.songs_scale.add_mark( - length, - Gtk.PositionType.RIGHT, - "{0[0]:02d}:{0[1]:02d} minutes".format(divmod(length, 60)) - ) + length, Gtk.PositionType.RIGHT, + "{0[0]:02d}:{0[1]:02d} minutes".format(divmod(length, 60))) def _enable_tracklist(self): if self._current_album: @@ -228,7 +216,10 @@ class CoverPanel(Gtk.Overlay): current_width, current_height = self._current_size if size_width == current_width and size_height == current_height: return - self._current_size = (size_width, size_height,) + self._current_size = ( + size_width, + size_height, + ) # Get pixelbuffer pixbuf = self._cover_pixbuf @@ -243,15 +234,10 @@ class CoverPanel(Gtk.Overlay): ratio = min(ratioW, ratioH) ratio = min(ratio, 1) # Neue Breite und Höhe berechnen - width = int(math.floor(pixbuf.get_width()*ratio)) - height = int(math.floor(pixbuf.get_height()*ratio)) + width = int(math.floor(pixbuf.get_width() * ratio)) + height = int(math.floor(pixbuf.get_height() * ratio)) if width <= 0 or height <= 0: return self.cover_image.set_from_pixbuf( - pixbuf.scale_simple( - width, - height, - GdkPixbuf.InterpType.HYPER - ) - ) + pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.HYPER)) self.cover_image.show() diff --git a/src/librarypanel.py b/src/librarypanel.py index f58ebd2..27f8e60 100644 --- a/src/librarypanel.py +++ b/src/librarypanel.py @@ -25,15 +25,14 @@ class LibraryPanel(Adw.Bin): 'open-standalone': (GObject.SIGNAL_RUN_FIRST, None, ()), 'close-standalone': (GObject.SIGNAL_RUN_FIRST, None, ()), 'update': (GObject.SIGNAL_RUN_FIRST, None, ()), - 'play': (GObject.SIGNAL_RUN_FIRST, None, (str,)), - 'queue': (GObject.SIGNAL_RUN_FIRST, None, (str,)), - 'queue-multiple': ( - GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT,) - ), - 'item-size-changed': (GObject.SIGNAL_RUN_FIRST, None, (int,)), - 'sort-order-changed': (GObject.SIGNAL_RUN_FIRST, None, (int,)), - 'sort-type-changed': (GObject.SIGNAL_RUN_FIRST, None, (bool,)), - 'albumart': (GObject.SIGNAL_RUN_FIRST, None, (str,)), + 'play': (GObject.SIGNAL_RUN_FIRST, None, (str, )), + 'queue': (GObject.SIGNAL_RUN_FIRST, None, (str, )), + 'queue-multiple': + (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT, )), + 'item-size-changed': (GObject.SIGNAL_RUN_FIRST, None, (int, )), + 'sort-order-changed': (GObject.SIGNAL_RUN_FIRST, None, (int, )), + 'sort-type-changed': (GObject.SIGNAL_RUN_FIRST, None, (bool, )), + 'albumart': (GObject.SIGNAL_RUN_FIRST, None, (str, )), } # Widgets @@ -88,8 +87,7 @@ class LibraryPanel(Adw.Bin): self._library_lock = threading.Lock() self._library_stop = threading.Event() self._icon_theme = Gtk.IconTheme.get_for_display( - Gdk.Display.get_default() - ) + Gdk.Display.get_default()) self._standalone_pixbuf = None self._selected_albums = [] self._is_selected = False @@ -97,20 +95,16 @@ class LibraryPanel(Adw.Bin): # Widgets # Header bar self._headerbar_standalone = AlbumHeaderbar() - self._headerbar_standalone.connect( - 'close', - self.on_standalone_close_clicked - ) + self._headerbar_standalone.connect('close', + self.on_standalone_close_clicked) # Library Grid: Model self._library_grid_model = Gio.ListStore() self._library_grid_filter = Gtk.FilterListModel() self._library_grid_filter.set_model(self._library_grid_model) self._library_grid_selection_multi = Gtk.MultiSelection.new( - self._library_grid_filter - ) + self._library_grid_filter) self._library_grid_selection_single = Gtk.SingleSelection.new( - self._library_grid_filter - ) + self._library_grid_filter) # Library Grid self.library_grid.set_model(self._library_grid_selection_single) # Toolbar menu @@ -124,10 +118,8 @@ class LibraryPanel(Adw.Bin): # Button controller for grid scale buttonController = Gtk.GestureClick() - buttonController.connect( - 'unpaired-release', - self.on_grid_scale_released - ) + buttonController.connect('unpaired-release', + self.on_grid_scale_released) self.grid_scale.add_controller(buttonController) def get_headerbar_standalone(self): @@ -146,15 +138,13 @@ class LibraryPanel(Adw.Bin): self.library_grid.set_model(self._library_grid_selection_multi) self.library_grid.set_single_click_activate(False) self.library_grid.get_style_context().add_class( - Utils.CSS_SELECTION - ) + Utils.CSS_SELECTION) else: self.actionbar_revealer.set_reveal_child(False) self.library_grid.set_model(self._library_grid_selection_single) self.library_grid.set_single_click_activate(True) self.library_grid.get_style_context().remove_class( - Utils.CSS_SELECTION - ) + Utils.CSS_SELECTION) @Gtk.Template.Callback() def on_update_clicked(self, widget): @@ -182,8 +172,7 @@ class LibraryPanel(Adw.Bin): def on_sort_toggled(self, widget): if widget.get_active(): self._sort_order = [ - key - for key, value in self._toolbar_sort_buttons.items() + key for key, value in self._toolbar_sort_buttons.items() if value is widget ][0] self._sort_grid_model() @@ -205,10 +194,7 @@ class LibraryPanel(Adw.Bin): @Gtk.Template.Callback() def on_filter_entry_changed(self, widget): self._library_grid_filter.set_filter( - SearchFilter( - self.filter_entry.get_text() - ) - ) + SearchFilter(self.filter_entry.get_text())) @Gtk.Template.Callback() def on_library_grid_clicked(self, widget, position): @@ -269,8 +255,7 @@ class LibraryPanel(Adw.Bin): button = self._toolbar_sort_buttons[sort] if button: self._sort_order = [ - key - for key, value in self._toolbar_sort_buttons.items() + key for key, value in self._toolbar_sort_buttons.items() if value is button ][0] if not button.get_active(): @@ -300,10 +285,12 @@ class LibraryPanel(Adw.Bin): def set_albums(self, host, albums): self._host = host self._library_stop.set() - threading.Thread( - target=self._set_albums, - args=(host, albums, self._item_size,) - ).start() + threading.Thread(target=self._set_albums, + args=( + host, + albums, + self._item_size, + )).start() def set_albumart(self, album, data): if album in self._selected_albums: @@ -320,20 +307,14 @@ class LibraryPanel(Adw.Bin): GObject.idle_add(self._show_image) def _sort_grid_model(self): - GObject.idle_add( - self._library_grid_model.sort, - self._grid_model_compare_func, - self._sort_order, - self._sort_type - ) + GObject.idle_add(self._library_grid_model.sort, + self._grid_model_compare_func, self._sort_order, + self._sort_type) def _grid_model_compare_func(self, item1, item2, criterion, order): - return client.MCGAlbum.compare( - item1.get_album(), - item2.get_album(), - criterion, - (order == Gtk.SortType.DESCENDING) - ) + return client.MCGAlbum.compare(item1.get_album(), item2.get_album(), + criterion, + (order == Gtk.SortType.DESCENDING)) def stop_threads(self): self._library_stop.set() @@ -342,10 +323,8 @@ class LibraryPanel(Adw.Bin): self._library_lock.acquire() self._albums = albums stack_transition_type = self.stack.get_transition_type() - GObject.idle_add( - self.stack.set_transition_type, - Gtk.StackTransitionType.NONE - ) + GObject.idle_add(self.stack.set_transition_type, + Gtk.StackTransitionType.NONE) GObject.idle_add(self.stack.set_visible_child, self.progress_box) GObject.idle_add(self.progress_bar.set_fraction, 0.0) GObject.idle_add(self.stack.set_transition_type, stack_transition_type) @@ -367,26 +346,18 @@ class LibraryPanel(Adw.Bin): self._logger.exception("Failed to load albumart", e) if pixbuf is None: pixbuf = self._icon_theme.lookup_icon( - Utils.STOCK_ICON_DEFAULT, - None, - self._item_size, - self._item_size, - Gtk.TextDirection.LTR, - Gtk.IconLookupFlags.FORCE_SYMBOLIC - ) + Utils.STOCK_ICON_DEFAULT, None, self._item_size, + self._item_size, Gtk.TextDirection.LTR, + Gtk.IconLookupFlags.FORCE_SYMBOLIC) if pixbuf is not None: self._grid_pixbufs[album.get_id()] = pixbuf - GObject.idle_add( - self._library_grid_model.append, - GridItem(album, pixbuf) - ) + GObject.idle_add(self._library_grid_model.append, + GridItem(album, pixbuf)) i += 1 - GObject.idle_add(self.progress_bar.set_fraction, i/n) - GObject.idle_add( - self.progress_bar.set_text, - locale.gettext("Loading images") - ) + GObject.idle_add(self.progress_bar.set_fraction, i / n) + GObject.idle_add(self.progress_bar.set_text, + locale.gettext("Loading images")) self._library_lock.release() GObject.idle_add(self.stack.set_visible_child, self.scroll) @@ -394,10 +365,12 @@ class LibraryPanel(Adw.Bin): def _set_widget_grid_size(self, grid_widget, size, vertical): self._library_stop.set() - threading.Thread( - target=self._set_widget_grid_size_thread, - args=(grid_widget, size, vertical,) - ).start() + threading.Thread(target=self._set_widget_grid_size_thread, + args=( + grid_widget, + size, + vertical, + )).start() def _set_widget_grid_size_thread(self, grid_widget, size, vertical): self._library_lock.acquire() @@ -411,20 +384,12 @@ class LibraryPanel(Adw.Bin): pixbuf = self._grid_pixbufs[album_id] if pixbuf is not None: - pixbuf = pixbuf.scale_simple( - size, - size, - GdkPixbuf.InterpType.NEAREST - ) + pixbuf = pixbuf.scale_simple(size, size, + GdkPixbuf.InterpType.NEAREST) else: pixbuf = self._icon_theme.lookup_icon( - Utils.STOCK_ICON_DEFAULT, - None, - size, - size, - Gtk.TextDirection.LTR, - Gtk.IconLookupFlags.FORCE_SYMBOLIC - ) + Utils.STOCK_ICON_DEFAULT, None, size, size, + Gtk.TextDirection.LTR, Gtk.IconLookupFlags.FORCE_SYMBOLIC) GObject.idle_add(grid_item.set_cover, pixbuf) if self._library_stop.is_set(): @@ -456,11 +421,7 @@ class LibraryPanel(Adw.Bin): for index in range(countMin, countMax): pixel = int(width / index) pixel = pixel - (2 * int(pixel / 100)) - self.grid_scale.add_mark( - pixel, - Gtk.PositionType.BOTTOM, - None - ) + self.grid_scale.add_mark(pixel, Gtk.PositionType.BOTTOM, None) def _open_standalone(self): self.library_stack.set_visible_child(self.panel_standalone) @@ -491,38 +452,24 @@ class LibraryPanel(Adw.Bin): ratio = min(ratioW, ratioH) ratio = min(ratio, 1) # Neue Breite und Höhe berechnen - width = int(math.floor(pixbuf.get_width()*ratio)) - height = int(math.floor(pixbuf.get_height()*ratio)) + width = int(math.floor(pixbuf.get_width() * ratio)) + height = int(math.floor(pixbuf.get_height() * ratio)) if width <= 0 or height <= 0: return # Pixelpuffer auf Oberfläche zeichnen self.standalone_image.set_from_pixbuf( - pixbuf.scale_simple( - width, - height, - GdkPixbuf.InterpType.HYPER - ) - ) + pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.HYPER)) self.standalone_image.show() def _get_default_image(self): - return self._icon_theme.lookup_icon( - Utils.STOCK_ICON_DEFAULT, - None, - 512, - 512, - Gtk.TextDirection.LTR, - Gtk.IconLookupFlags.FORCE_SYMBOLIC - ) + return self._icon_theme.lookup_icon(Utils.STOCK_ICON_DEFAULT, None, + 512, 512, Gtk.TextDirection.LTR, + Gtk.IconLookupFlags.FORCE_SYMBOLIC) def _get_selected_albums(self): albums = [] for i in range(self.library_grid.get_model().get_n_items()): if self.library_grid.get_model().is_selected(i): - albums.append( - self.library_grid.get_model() - .get_item(i) - .get_album() - .get_id() - ) + albums.append(self.library_grid.get_model().get_item( + i).get_album().get_id()) return albums diff --git a/src/playlistpanel.py b/src/playlistpanel.py index 341f9c8..dc5e3e5 100644 --- a/src/playlistpanel.py +++ b/src/playlistpanel.py @@ -22,18 +22,12 @@ class PlaylistPanel(Adw.Bin): 'open-standalone': (GObject.SIGNAL_RUN_FIRST, None, ()), 'close-standalone': (GObject.SIGNAL_RUN_FIRST, None, ()), 'clear-playlist': (GObject.SIGNAL_RUN_FIRST, None, ()), - 'remove-album': ( - GObject.SIGNAL_RUN_FIRST, - None, - (GObject.TYPE_PYOBJECT,) - ), - 'remove-multiple-albums': ( - GObject.SIGNAL_RUN_FIRST, - None, - (GObject.TYPE_PYOBJECT,) - ), - 'play': (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)), - 'albumart': (GObject.SIGNAL_RUN_FIRST, None, (str,)), + 'remove-album': + (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT, )), + 'remove-multiple-albums': + (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT, )), + 'play': (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT, )), + 'albumart': (GObject.SIGNAL_RUN_FIRST, None, (str, )), } # Widgets @@ -66,8 +60,7 @@ class PlaylistPanel(Adw.Bin): self._playlist_lock = threading.Lock() self._playlist_stop = threading.Event() self._icon_theme = Gtk.IconTheme.get_for_display( - Gdk.Display.get_default() - ) + Gdk.Display.get_default()) self._standalone_pixbuf = None self._selected_albums = [] self._is_selected = False @@ -75,18 +68,14 @@ class PlaylistPanel(Adw.Bin): # Widgets # Header bar self._headerbar_standalone = AlbumHeaderbar() - self._headerbar_standalone.connect( - 'close', - self.on_headerbar_close_clicked - ) + self._headerbar_standalone.connect('close', + self.on_headerbar_close_clicked) # Playlist Grid: Model self._playlist_grid_model = Gio.ListStore() self._playlist_grid_selection_multi = Gtk.MultiSelection.new( - self._playlist_grid_model - ) + self._playlist_grid_model) self._playlist_grid_selection_single = Gtk.SingleSelection.new( - self._playlist_grid_model - ) + self._playlist_grid_model) # Playlist Grid self.playlist_grid.set_model(self._playlist_grid_selection_single) @@ -106,15 +95,13 @@ class PlaylistPanel(Adw.Bin): self.playlist_grid.set_model(self._playlist_grid_selection_multi) self.playlist_grid.set_single_click_activate(False) self.playlist_grid.get_style_context().add_class( - Utils.CSS_SELECTION - ) + Utils.CSS_SELECTION) else: self.actionbar_revealer.set_reveal_child(False) self.playlist_grid.set_model(self._playlist_grid_selection_single) self.playlist_grid.set_single_click_activate(True) self.playlist_grid.get_style_context().remove_class( - Utils.CSS_SELECTION - ) + Utils.CSS_SELECTION) @Gtk.Template.Callback() def on_clear_clicked(self, widget): @@ -177,10 +164,12 @@ class PlaylistPanel(Adw.Bin): def set_playlist(self, host, playlist): self._host = host self._playlist_stop.set() - threading.Thread( - target=self._set_playlist, - args=(host, playlist, self._item_size,) - ).start() + threading.Thread(target=self._set_playlist, + args=( + host, + playlist, + self._item_size, + )).start() def set_albumart(self, album, data): if album in self._selected_albums: @@ -221,13 +210,9 @@ class PlaylistPanel(Adw.Bin): self._logger.exception("Failed to load albumart") if pixbuf is None: pixbuf = self._icon_theme.lookup_icon( - Utils.STOCK_ICON_DEFAULT, - None, - self._item_size, - self._item_size, - Gtk.TextDirection.LTR, - Gtk.IconLookupFlags.FORCE_SYMBOLIC - ) + Utils.STOCK_ICON_DEFAULT, None, self._item_size, + self._item_size, Gtk.TextDirection.LTR, + Gtk.IconLookupFlags.FORCE_SYMBOLIC) if pixbuf is not None: self._playlist_grid_model.append(GridItem(album, pixbuf)) @@ -276,35 +261,24 @@ class PlaylistPanel(Adw.Bin): ratio = min(ratioW, ratioH) ratio = min(ratio, 1) # Neue Breite und Höhe berechnen - width = int(math.floor(pixbuf.get_width()*ratio)) - height = int(math.floor(pixbuf.get_height()*ratio)) + width = int(math.floor(pixbuf.get_width() * ratio)) + height = int(math.floor(pixbuf.get_height() * ratio)) if width <= 0 or height <= 0: return # Pixelpuffer auf Oberfläche zeichnen self.standalone_image.set_from_pixbuf( - pixbuf.scale_simple( - width, - height, - GdkPixbuf.InterpType.HYPER - ) - ) + pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.HYPER)) self.standalone_image.show() def _get_default_image(self): - return self._icon_theme.lookup_icon( - Utils.STOCK_ICON_DEFAULT, - None, - 512, - 512, - Gtk.TextDirection.LTR, - Gtk.IconLookupFlags.FORCE_SYMBOLIC - ) + return self._icon_theme.lookup_icon(Utils.STOCK_ICON_DEFAULT, None, + 512, 512, Gtk.TextDirection.LTR, + Gtk.IconLookupFlags.FORCE_SYMBOLIC) def _get_selected_albums(self): albums = [] for i in range(self.playlist_grid.get_model().get_n_items()): if self.playlist_grid.get_model().is_selected(i): albums.append( - self.playlist_grid.get_model().get_item(i).get_album() - ) + self.playlist_grid.get_model().get_item(i).get_album()) return albums diff --git a/src/serverpanel.py b/src/serverpanel.py index 0f39e86..e52e45d 100644 --- a/src/serverpanel.py +++ b/src/serverpanel.py @@ -12,11 +12,10 @@ from gi.repository import Gtk, Adw, GObject class ServerPanel(Adw.Bin): __gtype_name__ = 'McgServerPanel' __gsignals__ = { - 'change-output-device': ( - GObject.SIGNAL_RUN_FIRST, - None, - (GObject.TYPE_PYOBJECT,bool,) - ), + 'change-output-device': (GObject.SIGNAL_RUN_FIRST, None, ( + GObject.TYPE_PYOBJECT, + bool, + )), } # Widgets @@ -61,14 +60,11 @@ class ServerPanel(Adw.Bin): file = self._none_label self.status_file.set_markup(file) # Audio information - if audio: + if audio: parts = audio.split(":") if len(parts) == 3: audio = "{} Hz, {} bit, {} channels".format( - parts[0], - parts[1], - parts[2] - ) + parts[0], parts[1], parts[2]) else: audio = self._none_label self.status_audio.set_markup(audio) @@ -102,18 +98,14 @@ class ServerPanel(Adw.Bin): if device.get_id() in self._output_buttons.keys(): self._output_buttons[device.get_id()].freeze_notify() self._output_buttons[device.get_id()].set_active( - device.is_enabled() - ) + device.is_enabled()) self._output_buttons[device.get_id()].thaw_notify() else: button = Gtk.CheckButton.new_with_label(device.get_name()) if device.is_enabled(): button.set_active(True) - handler = button.connect( - 'toggled', - self.on_output_device_toggled, - device - ) + handler = button.connect('toggled', + self.on_output_device_toggled, device) self.output_devices.insert(button, -1) self._output_buttons[device.get_id()] = button @@ -121,5 +113,5 @@ class ServerPanel(Adw.Bin): for id in self._output_buttons.keys(): if id not in device_ids: self.output_devices.remove( - self._output_buttons[id].get_parent() - ) + self._output_buttons[id].get_parent()) + diff --git a/src/utils.py b/src/utils.py index 4146ef2..1b16308 100644 --- a/src/utils.py +++ b/src/utils.py @@ -35,11 +35,8 @@ class Utils: if albumart: pixbuf = Utils.load_pixbuf(albumart) if pixbuf is not None: - pixbuf = pixbuf.scale_simple( - size, - size, - GdkPixbuf.InterpType.HYPER - ) + pixbuf = pixbuf.scale_simple(size, size, + GdkPixbuf.InterpType.HYPER) pixbuf.savev(cache_url, 'jpeg', [], []) return pixbuf @@ -47,9 +44,7 @@ class Utils: label = ', '.join(album.get_albumartists()) if album.get_artists(): label = locale.gettext("{} feat. {}").format( - label, - ", ".join(album.get_artists()) - ) + label, ", ".join(album.get_artists())) return label def create_length_label(album): @@ -62,9 +57,7 @@ class Utils: title = track.get_title() if track.get_artists(): title = locale.gettext("{} feat. {}").format( - title, - ", ".join(track.get_artists()) - ) + title, ", ".join(track.get_artists())) return title def generate_id(values): @@ -95,8 +88,7 @@ class GridItem(GObject.GObject): if cover: self.cover = Gdk.Texture.new_for_pixbuf(cover) self.tooltip = GObject.markup_escape_text("\n".join([ - album.get_title(), - ', '.join(album.get_dates()), + album.get_title(), ', '.join(album.get_dates()), Utils.create_artists_label(album), Utils.create_length_label(album) ])) diff --git a/src/window.py b/src/window.py index 120aa1d..2024894 100644 --- a/src/window.py +++ b/src/window.py @@ -92,52 +92,35 @@ class Window(Adw.ApplicationWindow): self._panels.append(self._cover_panel) # Playlist panel self._playlist_panel = PlaylistPanel(self._mcg) - self._playlist_panel.connect( - 'open-standalone', - self.on_panel_open_standalone - ) - self._playlist_panel.connect( - 'close-standalone', - self.on_panel_close_standalone - ) + self._playlist_panel.connect('open-standalone', + self.on_panel_open_standalone) + self._playlist_panel.connect('close-standalone', + self.on_panel_close_standalone) self._panels.append(self._playlist_panel) # Library panel self._library_panel = LibraryPanel(self._mcg) - self._library_panel.connect( - 'open-standalone', - self.on_panel_open_standalone - ) - self._library_panel.connect( - 'close-standalone', - self.on_panel_close_standalone - ) + self._library_panel.connect('open-standalone', + self.on_panel_open_standalone) + self._library_panel.connect('close-standalone', + self.on_panel_close_standalone) self._panels.append(self._library_panel) # Stack self.content_stack.add_child(self._connection_panel) - self.panel_stack.add_titled_with_icon( - self._server_panel, - 'server-panel', - locale.gettext("Server"), - "network-wired-symbolic" - ) - self.panel_stack.add_titled_with_icon( - self._cover_panel, - 'cover-panel', - locale.gettext("Cover"), - "image-x-generic-symbolic" - ) - self.panel_stack.add_titled_with_icon( - self._playlist_panel, - 'playlist-panel', - locale.gettext("Playlist"), - "view-list-symbolic" - ) - self.panel_stack.add_titled_with_icon( - self._library_panel, - 'library-panel', - locale.gettext("Library"), - "emblem-music-symbolic" - ) + self.panel_stack.add_titled_with_icon(self._server_panel, + 'server-panel', + locale.gettext("Server"), + "network-wired-symbolic") + self.panel_stack.add_titled_with_icon(self._cover_panel, 'cover-panel', + locale.gettext("Cover"), + "image-x-generic-symbolic") + self.panel_stack.add_titled_with_icon(self._playlist_panel, + 'playlist-panel', + locale.gettext("Playlist"), + "view-list-symbolic") + self.panel_stack.add_titled_with_icon(self._library_panel, + 'library-panel', + locale.gettext("Library"), + "emblem-music-symbolic") # Toolbar stack self.toolbar_stack.add_child(self._server_panel.get_toolbar()) self.toolbar_stack.add_child(self._cover_panel.get_toolbar()) @@ -147,30 +130,21 @@ class Window(Adw.ApplicationWindow): # Properties self._set_headerbar_sensitive(False, False) self._connection_panel.set_host( - self._settings.get_string(Window.SETTING_HOST) - ) + self._settings.get_string(Window.SETTING_HOST)) self._connection_panel.set_port( - self._settings.get_int(Window.SETTING_PORT) - ) + self._settings.get_int(Window.SETTING_PORT)) if use_keyring: self._connection_panel.set_password( - keyring.get_password( - ZeroconfProvider.KEYRING_SYSTEM, - ZeroconfProvider.KEYRING_USERNAME - ) - ) + keyring.get_password(ZeroconfProvider.KEYRING_SYSTEM, + ZeroconfProvider.KEYRING_USERNAME)) self._playlist_panel.set_item_size( - self._settings.get_int(Window.SETTING_ITEM_SIZE) - ) + self._settings.get_int(Window.SETTING_ITEM_SIZE)) self._library_panel.set_item_size( - self._settings.get_int(Window.SETTING_ITEM_SIZE) - ) + self._settings.get_int(Window.SETTING_ITEM_SIZE)) self._library_panel.set_sort_order( - self._settings.get_enum(Window.SETTING_SORT_ORDER) - ) + self._settings.get_enum(Window.SETTING_SORT_ORDER)) self._library_panel.set_sort_type( - self._settings.get_boolean(Window.SETTING_SORT_TYPE) - ) + self._settings.get_boolean(Window.SETTING_SORT_TYPE)) # Signals self.connect("notify::default-width", self.on_resize) @@ -178,131 +152,69 @@ class Window(Adw.ApplicationWindow): self.connect("notify::maximized", self.on_maximized) self.connect("notify::fullscreened", self.on_fullscreened) self._connection_panel.connect( - 'connection-changed', - self.on_connection_panel_connection_changed - ) - self.panel_stack.connect( - 'notify::visible-child', - self.on_stack_switched - ) - self._server_panel.connect( - 'change-output-device', - self.on_server_panel_output_device_changed - ) - self._cover_panel.connect( - 'toggle-fullscreen', - self.on_cover_panel_toggle_fullscreen - ) + 'connection-changed', self.on_connection_panel_connection_changed) + self.panel_stack.connect('notify::visible-child', + self.on_stack_switched) + self._server_panel.connect('change-output-device', + self.on_server_panel_output_device_changed) + self._cover_panel.connect('toggle-fullscreen', + self.on_cover_panel_toggle_fullscreen) self._cover_panel.connect('set-song', self.on_cover_panel_set_song) self._cover_panel.connect('albumart', self.on_cover_panel_albumart) - self._playlist_panel.connect( - 'clear-playlist', - self.on_playlist_panel_clear_playlist - ) - self._playlist_panel.connect( - 'remove-album', - self.on_playlist_panel_remove - ) - self._playlist_panel.connect( - 'remove-multiple-albums', - self.on_playlist_panel_remove_multiple - ) + self._playlist_panel.connect('clear-playlist', + self.on_playlist_panel_clear_playlist) + self._playlist_panel.connect('remove-album', + self.on_playlist_panel_remove) + self._playlist_panel.connect('remove-multiple-albums', + self.on_playlist_panel_remove_multiple) self._playlist_panel.connect('play', self.on_playlist_panel_play) - self._playlist_panel.connect( - 'albumart', - self.on_playlist_panel_albumart - ) + self._playlist_panel.connect('albumart', + self.on_playlist_panel_albumart) self._library_panel.connect('update', self.on_library_panel_update) self._library_panel.connect('play', self.on_library_panel_play) self._library_panel.connect('queue', self.on_library_panel_queue) - self._library_panel.connect( - 'queue-multiple', - self.on_library_panel_queue_multiple - ) - self._library_panel.connect( - 'item-size-changed', - self.on_library_panel_item_size_changed - ) - self._library_panel.connect( - 'sort-order-changed', - self.on_library_panel_sort_order_changed - ) - self._library_panel.connect( - 'sort-type-changed', - self.on_library_panel_sort_type_changed - ) + self._library_panel.connect('queue-multiple', + self.on_library_panel_queue_multiple) + self._library_panel.connect('item-size-changed', + self.on_library_panel_item_size_changed) + self._library_panel.connect('sort-order-changed', + self.on_library_panel_sort_order_changed) + self._library_panel.connect('sort-type-changed', + self.on_library_panel_sort_type_changed) self._library_panel.connect('albumart', self.on_library_panel_albumart) - self._mcg.connect_signal( - client.Client.SIGNAL_CONNECTION, - self.on_mcg_connect - ) - self._mcg.connect_signal( - client.Client.SIGNAL_STATUS, - self.on_mcg_status - ) + self._mcg.connect_signal(client.Client.SIGNAL_CONNECTION, + self.on_mcg_connect) + self._mcg.connect_signal(client.Client.SIGNAL_STATUS, + self.on_mcg_status) self._mcg.connect_signal(client.Client.SIGNAL_STATS, self.on_mcg_stats) - self._mcg.connect_signal( - client.Client.SIGNAL_LOAD_OUTPUT_DEVICES, - self.on_mcg_load_output_devices - ) - self._mcg.connect_signal( - client.Client.SIGNAL_LOAD_PLAYLIST, - self.on_mcg_load_playlist - ) - self._mcg.connect_signal( - client.Client.SIGNAL_PULSE_ALBUMS, - self.on_mcg_pulse_albums - ) - self._mcg.connect_signal( - client.Client.SIGNAL_INIT_ALBUMS, - self.on_mcg_init_albums - ) - self._mcg.connect_signal( - client.Client.SIGNAL_LOAD_ALBUMS, - self.on_mcg_load_albums - ) - self._mcg.connect_signal( - client.Client.SIGNAL_LOAD_ALBUMART, - self.on_mcg_load_albumart - ) - self._mcg.connect_signal( - client.Client.SIGNAL_ERROR, - self.on_mcg_error - ) - self._settings.connect( - 'changed::'+Window.SETTING_PANEL, - self.on_settings_panel_changed - ) - self._settings.connect( - 'changed::'+Window.SETTING_ITEM_SIZE, - self.on_settings_item_size_changed - ) - self._settings.connect( - 'changed::'+Window.SETTING_SORT_ORDER, - self.on_settings_sort_order_changed - ) - self._settings.connect( - 'changed::'+Window.SETTING_SORT_TYPE, - self.on_settings_sort_type_changed - ) - self._settings.bind( - Window.SETTING_WINDOW_WIDTH, - self._state, - WindowState.WIDTH, - Gio.SettingsBindFlags.DEFAULT - ) - self._settings.bind( - Window.SETTING_WINDOW_HEIGHT, - self._state, - WindowState.HEIGHT, - Gio.SettingsBindFlags.DEFAULT - ) - self._settings.bind( - Window.SETTING_WINDOW_MAXIMIZED, - self._state, - WindowState.IS_MAXIMIZED, - Gio.SettingsBindFlags.DEFAULT - ) + self._mcg.connect_signal(client.Client.SIGNAL_LOAD_OUTPUT_DEVICES, + self.on_mcg_load_output_devices) + self._mcg.connect_signal(client.Client.SIGNAL_LOAD_PLAYLIST, + self.on_mcg_load_playlist) + self._mcg.connect_signal(client.Client.SIGNAL_PULSE_ALBUMS, + self.on_mcg_pulse_albums) + self._mcg.connect_signal(client.Client.SIGNAL_INIT_ALBUMS, + self.on_mcg_init_albums) + self._mcg.connect_signal(client.Client.SIGNAL_LOAD_ALBUMS, + self.on_mcg_load_albums) + self._mcg.connect_signal(client.Client.SIGNAL_LOAD_ALBUMART, + self.on_mcg_load_albumart) + self._mcg.connect_signal(client.Client.SIGNAL_ERROR, self.on_mcg_error) + self._settings.connect('changed::' + Window.SETTING_PANEL, + self.on_settings_panel_changed) + self._settings.connect('changed::' + Window.SETTING_ITEM_SIZE, + self.on_settings_item_size_changed) + self._settings.connect('changed::' + Window.SETTING_SORT_ORDER, + self.on_settings_sort_order_changed) + self._settings.connect('changed::' + Window.SETTING_SORT_TYPE, + self.on_settings_sort_type_changed) + self._settings.bind(Window.SETTING_WINDOW_WIDTH, self._state, + WindowState.WIDTH, Gio.SettingsBindFlags.DEFAULT) + self._settings.bind(Window.SETTING_WINDOW_HEIGHT, self._state, + WindowState.HEIGHT, Gio.SettingsBindFlags.DEFAULT) + self._settings.bind(Window.SETTING_WINDOW_MAXIMIZED, self._state, + WindowState.IS_MAXIMIZED, + Gio.SettingsBindFlags.DEFAULT) # Actions self.set_default_size(self._state.width, self._state.height) @@ -314,58 +226,37 @@ class Window(Adw.ApplicationWindow): # Menu actions self._connect_action = Gio.SimpleAction.new_stateful( - "connect", - None, - GLib.Variant.new_boolean(False) - ) + "connect", None, GLib.Variant.new_boolean(False)) self._connect_action.connect('change-state', self.on_menu_connect) self.add_action(self._connect_action) self._play_action = Gio.SimpleAction.new_stateful( - "play", - None, - GLib.Variant.new_boolean(False) - ) + "play", None, GLib.Variant.new_boolean(False)) self._play_action.set_enabled(False) self._play_action.connect('change-state', self.on_menu_play) self.add_action(self._play_action) self._clear_playlist_action = Gio.SimpleAction.new( - "clear-playlist", - None - ) + "clear-playlist", None) self._clear_playlist_action.set_enabled(False) - self._clear_playlist_action.connect( - 'activate', - self.on_menu_clear_playlist - ) + self._clear_playlist_action.connect('activate', + self.on_menu_clear_playlist) self.add_action(self._clear_playlist_action) panel_variant = GLib.Variant.new_string("0") self._panel_action = Gio.SimpleAction.new_stateful( - "panel", - panel_variant.get_type(), - panel_variant - ) + "panel", panel_variant.get_type(), panel_variant) self._panel_action.set_enabled(False) self._panel_action.connect('change-state', self.on_menu_panel) self.add_action(self._panel_action) self._toggle_fullscreen_action = Gio.SimpleAction.new( - "toggle-fullscreen", - None - ) + "toggle-fullscreen", None) self._toggle_fullscreen_action.set_enabled(True) - self._toggle_fullscreen_action.connect( - 'activate', - self.on_menu_toggle_fullscreen - ) + self._toggle_fullscreen_action.connect('activate', + self.on_menu_toggle_fullscreen) self.add_action(self._toggle_fullscreen_action) self._search_library_action = Gio.SimpleAction.new( - "search-library", - None - ) + "search-library", None) self._search_library_action.set_enabled(True) - self._search_library_action.connect( - 'activate', - self.on_menu_search_library - ) + self._search_library_action.connect('activate', + self.on_menu_search_library) self.add_action(self._search_library_action) # Menu callbacks @@ -381,9 +272,8 @@ class Window(Adw.ApplicationWindow): def on_menu_panel(self, action, value): action.set_state(value) - self.panel_stack.set_visible_child( - self._panels[int(value.get_string())] - ) + self.panel_stack.set_visible_child(self._panels[int( + value.get_string())]) def on_menu_toggle_fullscreen(self, action, value): self.panel_stack.set_visible_child(self._cover_panel) @@ -425,7 +315,7 @@ class Window(Adw.ApplicationWindow): @Gtk.Template.Callback() def on_headerbar_volume_changed(self, widget, value): if not self._setting_volume: - self._mcg.set_volume(int(value*100)) + self._mcg.set_volume(int(value * 100)) @Gtk.Template.Callback() def on_headerbar_playpause_toggled(self, widget): @@ -450,31 +340,20 @@ class Window(Adw.ApplicationWindow): self.toolbar_view.add_top_bar(self.headerbar) self.toolbar_view.remove(panel.get_headerbar_standalone()) - def on_connection_panel_connection_changed( - self, - widget, - host, - port, - password - ): + def on_connection_panel_connection_changed(self, widget, host, port, + password): self._settings.set_string(Window.SETTING_HOST, host) self._settings.set_int(Window.SETTING_PORT, port) if use_keyring: if password: - keyring.set_password( - ZeroconfProvider.KEYRING_SYSTEM, - ZeroconfProvider.KEYRING_USERNAME, - password - ) + keyring.set_password(ZeroconfProvider.KEYRING_SYSTEM, + ZeroconfProvider.KEYRING_USERNAME, + password) else: - if keyring.get_password( - ZeroconfProvider.KEYRING_SYSTEM, - ZeroconfProvider.KEYRING_USERNAME - ): - keyring.delete_password( - ZeroconfProvider.KEYRING_SYSTEM, - ZeroconfProvider.KEYRING_USERNAME - ) + if keyring.get_password(ZeroconfProvider.KEYRING_SYSTEM, + ZeroconfProvider.KEYRING_USERNAME): + keyring.delete_password(ZeroconfProvider.KEYRING_SYSTEM, + ZeroconfProvider.KEYRING_USERNAME) def on_playlist_panel_clear_playlist(self, widget): self._mcg.clear_playlist() @@ -520,10 +399,8 @@ class Window(Adw.ApplicationWindow): def on_library_panel_item_size_changed(self, widget, size): self._playlist_panel.set_item_size(size) - self._settings.set_int( - Window.SETTING_ITEM_SIZE, - self._library_panel.get_item_size() - ) + self._settings.set_int(Window.SETTING_ITEM_SIZE, + self._library_panel.get_item_size()) def on_library_panel_sort_order_changed(self, widget, sort_order): self._settings.set_enum(Window.SETTING_SORT_ORDER, sort_order) @@ -555,18 +432,8 @@ class Window(Adw.ApplicationWindow): self._clear_playlist_action.set_enabled(False) self._panel_action.set_enabled(False) - def on_mcg_status( - self, - state, - album, - pos, - time, - volume, - file, - audio, - bitrate, - error - ): + def on_mcg_status(self, state, album, pos, time, volume, file, audio, + bitrate, error): # Album GObject.idle_add(self._cover_panel.set_album, album) if not album and self._state.get_property(WindowState.IS_FULLSCREENED): @@ -588,32 +455,17 @@ class Window(Adw.ApplicationWindow): if error: self._show_error(error) - def on_mcg_stats( - self, - artists, - albums, - songs, - dbplaytime, - playtime, - uptime - ): - self._server_panel.set_stats( - artists, - albums, - songs, - dbplaytime, - playtime, - uptime - ) + def on_mcg_stats(self, artists, albums, songs, dbplaytime, playtime, + uptime): + self._server_panel.set_stats(artists, albums, songs, dbplaytime, + playtime, uptime) def on_mcg_load_output_devices(self, devices): self._server_panel.set_output_devices(devices) def on_mcg_load_playlist(self, playlist): - self._playlist_panel.set_playlist( - self._connection_panel.get_host(), - playlist - ) + self._playlist_panel.set_playlist(self._connection_panel.get_host(), + playlist) def on_mcg_init_albums(self): GObject.idle_add(self._library_panel.init_albums) @@ -622,10 +474,8 @@ class Window(Adw.ApplicationWindow): GObject.idle_add(self._library_panel.load_albums) def on_mcg_load_albums(self, albums): - self._library_panel.set_albums( - self._connection_panel.get_host(), - albums - ) + self._library_panel.set_albums(self._connection_panel.get_host(), + albums) def on_mcg_load_albumart(self, album, data): self._cover_panel.set_albumart(album, data) @@ -673,13 +523,12 @@ class Window(Adw.ApplicationWindow): self._headerbar_connected() self._set_headerbar_sensitive(True, False) self.content_stack.set_visible_child(self.panel_stack) - self.panel_stack.set_visible_child( - self._panels[self._settings.get_int(Window.SETTING_PANEL)] - ) + self.panel_stack.set_visible_child(self._panels[self._settings.get_int( + Window.SETTING_PANEL)]) def _connect_disconnected(self): - self._playlist_panel.stop_threads(); - self._library_panel.stop_threads(); + self._playlist_panel.stop_threads() + self._library_panel.stop_threads() self._headerbar_disconnected() self._set_headerbar_sensitive(False, False) self._save_visible_panel() @@ -688,12 +537,9 @@ class Window(Adw.ApplicationWindow): def _fullscreen(self, fullscreened_new): if fullscreened_new != self._state.get_property( - WindowState.IS_FULLSCREENED - ): - self._state.set_property( - WindowState.IS_FULLSCREENED, - fullscreened_new - ) + WindowState.IS_FULLSCREENED): + self._state.set_property(WindowState.IS_FULLSCREENED, + fullscreened_new) if self._state.get_property(WindowState.IS_FULLSCREENED): self.headerbar.hide() self._cover_panel.set_fullscreen(True) @@ -705,22 +551,18 @@ class Window(Adw.ApplicationWindow): def _save_visible_panel(self): panel_index_selected = self._panels.index( - self.panel_stack.get_visible_child() - ) + self.panel_stack.get_visible_child()) self._settings.set_int(Window.SETTING_PANEL, panel_index_selected) def _set_menu_visible_panel(self): panel_index_selected = self._panels.index( - self.panel_stack.get_visible_child() - ) + self.panel_stack.get_visible_child()) self._panel_action.set_state( - GLib.Variant.new_string(str(panel_index_selected)) - ) + GLib.Variant.new_string(str(panel_index_selected))) def _set_visible_toolbar(self): panel_index_selected = self._panels.index( - self.panel_stack.get_visible_child() - ) + self.panel_stack.get_visible_child()) toolbar = self._panels[panel_index_selected].get_toolbar() self.toolbar_stack.set_visible_child(toolbar) diff --git a/src/zeroconf.py b/src/zeroconf.py index 82fb438..cdb0bd2 100644 --- a/src/zeroconf.py +++ b/src/zeroconf.py @@ -27,16 +27,8 @@ class ZeroconfProvider(client.Base): if use_avahi: self._start_client() - def on_new_service( - self, - browser, - interface, - protocol, - name, - type, - domain, - flags - ): + def on_new_service(self, browser, interface, protocol, name, type, domain, + flags): #if not (flags & Avahi.LookupResultFlags.GA_LOOKUP_RESULT_LOCAL): service_resolver = Avahi.ServiceResolver( interface=interface, @@ -52,22 +44,11 @@ class ZeroconfProvider(client.Base): service_resolver.attach(self._client) self._service_resolvers.append(service_resolver) - def on_found( - self, - resolver, - interface, - protocol, - name, - type, - domain, - host, - date, - port, - *args - ): + def on_found(self, resolver, interface, protocol, name, type, domain, host, + date, port, *args): if (host, port) not in self._services.keys(): - service = (name,host,port) - self._services[(host,port)] = service + service = (name, host, port) + self._services[(host, port)] = service self._callback(ZeroconfProvider.SIGNAL_SERVICE_NEW, service) def on_failure(self, resolver, date): @@ -76,16 +57,16 @@ class ZeroconfProvider(client.Base): def _start_client(self): self._logger.info("Starting Avahi client") - self._client = Avahi.Client(flags=0,) + self._client = Avahi.Client(flags=0, ) try: self._client.start() # Browser self._service_browser = Avahi.ServiceBrowser( domain='local', - flags=0, interface=-1, + flags=0, + interface=-1, protocol=Avahi.Protocol.GA_PROTOCOL_UNSPEC, - type=ZeroconfProvider.TYPE - ) + type=ZeroconfProvider.TYPE) self._service_browser.connect('new_service', self.on_new_service) self._service_browser.attach(self._client) except Exception as e: From ce46f87cc2b52bf96e35517ca1806c3e91298af5 Mon Sep 17 00:00:00 2001 From: coderkun Date: Mon, 27 May 2024 18:33:59 +0200 Subject: [PATCH 5/6] Fix import statements and order (see #103) --- src/albumheaderbar.py | 1 - src/application.py | 2 +- src/connectionpanel.py | 6 ++---- src/coverpanel.py | 4 +--- src/librarypanel.py | 5 ++--- src/playlistpanel.py | 6 ++---- src/serverpanel.py | 1 - src/utils.py | 4 +--- src/window.py | 9 +++------ src/zeroconf.py | 2 +- 10 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/albumheaderbar.py b/src/albumheaderbar.py index 2a8a7e1..2f0b40b 100644 --- a/src/albumheaderbar.py +++ b/src/albumheaderbar.py @@ -4,7 +4,6 @@ import gi gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') - from gi.repository import Gtk, GObject, Adw diff --git a/src/application.py b/src/application.py index 187793e..23f482e 100644 --- a/src/application.py +++ b/src/application.py @@ -5,7 +5,7 @@ import gi gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') -from gi.repository import Gio, Gtk, Gdk, GLib, Adw +from gi.repository import Gio, Gtk, Gdk, Adw from .window import Window diff --git a/src/connectionpanel.py b/src/connectionpanel.py index 4286e6a..a4060ed 100644 --- a/src/connectionpanel.py +++ b/src/connectionpanel.py @@ -1,13 +1,11 @@ #!/usr/bin/env python3 import gi +import locale gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') -import locale - -from gi.repository import Gtk, Gio, GObject, Adw - +from gi.repository import Gtk, GObject, Adw from mcg.zeroconf import ZeroconfProvider diff --git a/src/coverpanel.py b/src/coverpanel.py index 9ac970b..88988b5 100644 --- a/src/coverpanel.py +++ b/src/coverpanel.py @@ -1,11 +1,9 @@ #!/usr/bin/env python3 import gi - -gi.require_version('Gtk', '4.0') -import logging import math +gi.require_version('Gtk', '4.0') from gi.repository import Gtk, Gdk, GObject, GdkPixbuf from mcg.utils import Utils diff --git a/src/librarypanel.py b/src/librarypanel.py index 27f8e60..8027620 100644 --- a/src/librarypanel.py +++ b/src/librarypanel.py @@ -1,14 +1,13 @@ #!/usr/bin/env python3 import gi - -gi.require_version('Gtk', '4.0') -gi.require_version('Adw', '1') import locale import logging import math import threading +gi.require_version('Gtk', '4.0') +gi.require_version('Adw', '1') from gi.repository import Gtk, Gdk, GObject, GdkPixbuf, Gio, Adw from mcg import client from mcg.albumheaderbar import AlbumHeaderbar diff --git a/src/playlistpanel.py b/src/playlistpanel.py index dc5e3e5..02526e0 100644 --- a/src/playlistpanel.py +++ b/src/playlistpanel.py @@ -1,13 +1,11 @@ #!/usr/bin/env python3 import gi - -gi.require_version('Gtk', '4.0') -gi.require_version('Adw', '1') -import logging import math import threading +gi.require_version('Gtk', '4.0') +gi.require_version('Adw', '1') from gi.repository import Gtk, Gdk, Gio, GObject, GdkPixbuf, Adw from mcg import client from mcg.albumheaderbar import AlbumHeaderbar diff --git a/src/serverpanel.py b/src/serverpanel.py index e52e45d..be7bd97 100644 --- a/src/serverpanel.py +++ b/src/serverpanel.py @@ -4,7 +4,6 @@ import gi gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') - from gi.repository import Gtk, Adw, GObject diff --git a/src/utils.py b/src/utils.py index 1b16308..1a9e6e7 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,13 +1,11 @@ #!/usr/bin/env python3 import gi - -gi.require_version('Gtk', '4.0') import hashlib import locale import os -import urllib +gi.require_version('Gtk', '4.0') from gi.repository import Gdk, GdkPixbuf, GObject, Gtk diff --git a/src/window.py b/src/window.py index 2024894..1c6d25c 100644 --- a/src/window.py +++ b/src/window.py @@ -1,20 +1,17 @@ #!/usr/bin/env python3 import gi - -gi.require_version('Gtk', '4.0') -gi.require_version('Adw', '1') try: import keyring use_keyring = True -except: +except ImportError: use_keyring = False use_keyring = False import locale -import logging +gi.require_version('Gtk', '4.0') +gi.require_version('Adw', '1') from gi.repository import Gtk, Adw, Gdk, GObject, GLib, Gio - from . import client from .shortcutsdialog import ShortcutsDialog from .connectionpanel import ConnectionPanel diff --git a/src/zeroconf.py b/src/zeroconf.py index cdb0bd2..5fa3363 100644 --- a/src/zeroconf.py +++ b/src/zeroconf.py @@ -5,7 +5,7 @@ try: gi.require_version('Avahi', '0.6') from gi.repository import Avahi use_avahi = True -except: +except ValueError | ImportError: use_avahi = False import logging From c4d421793b8d5d31a1ca87b8ca9afed7ac6daf71 Mon Sep 17 00:00:00 2001 From: coderkun Date: Mon, 27 May 2024 18:35:42 +0200 Subject: [PATCH 6/6] fixup! fixup! Adjust line length to match Code Style Guide (see #103) --- src/client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/client.py b/src/client.py index a18846f..ac7235b 100644 --- a/src/client.py +++ b/src/client.py @@ -507,8 +507,10 @@ class Client(Base): self._logger.debug("track: %r", track) # Album album = self._extract_album(song, lookup=False) - if (len(self._playlist) == 0 - or self._playlist[len(self._playlist) - 1] != album): + if ( + len(self._playlist) == 0 + or self._playlist[len(self._playlist) - 1] != album + ): self._playlist.append(album) else: album = self._playlist[len(self._playlist) - 1]