small cleanups

This commit is contained in:
Martin Wagner 2021-03-27 12:50:45 +01:00
parent b84deacf18
commit 8831a75f11

View File

@ -132,7 +132,6 @@ class MPRISInterface: # TODO emit Seeked if needed
"""
def __init__(self, window, client, settings):
# adding vars
self._window=window
self._client=client
self._settings=settings
@ -522,15 +521,12 @@ class EventEmitter(GObject.Object):
"add_to_playlist": (GObject.SignalFlags.RUN_FIRST, None, (str,)),
"show_info": (GObject.SignalFlags.RUN_FIRST, None, ())
}
def __init__(self):
super().__init__()
class Client(MPDClient):
def __init__(self, settings):
super().__init__()
# adding vars
self._settings=settings
self.emitter=EventEmitter()
self._last_status={}
@ -738,7 +734,7 @@ class Client(MPDClient):
self.emitter.emit("bitrate", float(val))
elif key == "songid":
self.emitter.emit("current_song_changed")
elif key in ["state", "single"]:
elif key in ("state", "single"):
self.emitter.emit(key, val)
elif key == "audio":
# see: https://www.musicpd.org/doc/html/user.html#audio-output-format
@ -750,7 +746,7 @@ class Client(MPDClient):
self.emitter.emit("volume_changed", float(val))
elif key == "playlist":
self.emitter.emit("playlist_changed", int(val))
elif key in ["repeat", "random", "consume"]:
elif key in ("repeat", "random", "consume"):
if val == "1":
self.emitter.emit(key, True)
else:
@ -850,8 +846,6 @@ class Settings(Gio.Settings):
class GeneralSettings(Gtk.Box):
def __init__(self, settings):
super().__init__(orientation=Gtk.Orientation.VERTICAL, spacing=6, border_width=18)
# adding vars
self._settings=settings
self._settings_handlers=[]
@ -950,8 +944,6 @@ class GeneralSettings(Gtk.Box):
class ProfileSettings(Gtk.Grid):
def __init__(self, parent, client, settings):
super().__init__(row_spacing=6, column_spacing=12, border_width=18)
# adding vars
self._client=client
self._settings=settings
self._gui_modification=False # indicates whether the settings were changed from the settings dialog
@ -1152,8 +1144,6 @@ class ProfileSettings(Gtk.Grid):
class PlaylistSettings(Gtk.Box):
def __init__(self, settings):
super().__init__(orientation=Gtk.Orientation.VERTICAL, spacing=6, border_width=18)
# adding vars
self._settings=settings
# label
@ -1389,8 +1379,6 @@ class AutoSizedIcon(Gtk.Image):
pixel_size=settings.get_int(settings_key)
if pixel_size > 0:
self.set_pixel_size(pixel_size)
# adding vars
self._settings=settings
self._settings_key=settings_key
@ -1446,8 +1434,6 @@ class FocusFrame(Gtk.Overlay):
class SongPopover(Gtk.Popover):
def __init__(self, client):
super().__init__()
# adding vars
self._client=client
self._rect=Gdk.Rectangle()
@ -1544,9 +1530,6 @@ class SongPopover(Gtk.Popover):
class SongsView(Gtk.TreeView):
def __init__(self, client, store, file_column_id):
super().__init__(model=store, search_column=-1, activate_on_single_click=True)
self.columns_autosize()
# adding vars
self._client=client
self._store=store
self._file_column_id=file_column_id
@ -1606,11 +1589,8 @@ class SongsView(Gtk.TreeView):
class SongsWindow(Gtk.Box):
__gsignals__={"button-clicked": (GObject.SignalFlags.RUN_FIRST, None, ())}
def __init__(self, client, store, file_column_id, focus_indicator=True):
super().__init__(orientation=Gtk.Orientation.VERTICAL)
# adding vars
self._client=client
# treeview
@ -1673,8 +1653,6 @@ class SongsWindow(Gtk.Box):
class AlbumPopover(Gtk.Popover):
def __init__(self, client, settings):
super().__init__()
# adding vars
self._client=client
self._settings=settings
self._rect=Gdk.Rectangle()
@ -1749,8 +1727,6 @@ class AlbumPopover(Gtk.Popover):
class ArtistPopover(Gtk.Popover):
def __init__(self, client):
super().__init__()
# adding vars
self._client=client
self._rect=Gdk.Rectangle()
self._artist=None
@ -1842,8 +1818,6 @@ class Cover(object):
class SearchWindow(Gtk.Box):
def __init__(self, client):
super().__init__(orientation=Gtk.Orientation.VERTICAL)
# adding vars
self._client=client
self._stop_flag=False
self._done=True
@ -2014,11 +1988,8 @@ class SearchWindow(Gtk.Box):
class GenreSelect(Gtk.ComboBoxText):
__gsignals__={"genre_changed": (GObject.SignalFlags.RUN_FIRST, None, ())}
def __init__(self, client):
super().__init__(wrap_width=3)
# adding vars
self._client=client
# connect
@ -2063,11 +2034,8 @@ class GenreSelect(Gtk.ComboBoxText):
class ArtistWindow(FocusFrame):
__gsignals__={"artists_changed": (GObject.SignalFlags.RUN_FIRST, None, ()), "clear": (GObject.SignalFlags.RUN_FIRST, None, ())}
def __init__(self, client, settings, genre_select):
super().__init__()
# adding vars
self._client=client
self._settings=settings
self._genre_select=genre_select
@ -2216,8 +2184,6 @@ class ArtistWindow(FocusFrame):
class AlbumWindow(FocusFrame):
def __init__(self, client, settings, artist_window):
super().__init__()
# adding vars
self._settings=settings
self._client=client
self._artist_window=artist_window
@ -2474,12 +2440,9 @@ class AlbumWindow(FocusFrame):
GLib.idle_add(callback)
class Browser(Gtk.Paned):
__gsignals__={"search_focus_changed": (GObject.SignalFlags.RUN_FIRST, None, (bool,))}
__gsignals__={"search-focus-changed": (GObject.SignalFlags.RUN_FIRST, None, (bool,))}
def __init__(self, client, settings):
super().__init__(orientation=Gtk.Orientation.HORIZONTAL)
# adding vars
self._client=client
self._settings=settings
self._use_csd=self._settings.get_boolean("use-csd")
@ -2506,8 +2469,8 @@ class Browser(Gtk.Paned):
# connect
self.back_to_current_album_button.connect("clicked", self._back_to_current_album)
self.search_button.connect("toggled", self._on_search_toggled)
self._search_window.search_entry.connect("focus_in_event", lambda *args: self.emit("search_focus_changed", True))
self._search_window.search_entry.connect("focus_out_event", lambda *args: self.emit("search_focus_changed", False))
self._search_window.search_entry.connect("focus_in_event", lambda *args: self.emit("search-focus-changed", True))
self._search_window.search_entry.connect("focus_out_event", lambda *args: self.emit("search-focus-changed", False))
self._artist_window.connect("artists_changed", self._on_artists_changed)
self._settings.connect("notify::mini-player", self._on_mini_player)
self._client.emitter.connect("disconnected", self._on_disconnected)
@ -2599,8 +2562,6 @@ class Browser(Gtk.Paned):
class LyricsWindow(FocusFrame):
def __init__(self, client, settings):
super().__init__()
# adding vars
self._settings=settings
self._client=client
self._displayed_song_file=None
@ -2703,8 +2664,6 @@ class LyricsWindow(FocusFrame):
class AudioType(Gtk.Label):
def __init__(self, client):
super().__init__()
# adding vars
self._client=client
self.freq, self.res, self.chan, self.brate, self.file_type=(0, 0, 0, 0, "")
@ -2755,8 +2714,6 @@ class AudioType(Gtk.Label):
class CoverEventBox(Gtk.EventBox):
def __init__(self, client, settings):
super().__init__()
# adding vars
self._client=client
self._settings=settings
@ -2795,6 +2752,8 @@ class CoverEventBox(Gtk.EventBox):
class MainCover(Gtk.Frame):
def __init__(self, client, settings):
super().__init__()
self._client=client
self._settings=settings
# css
style_context=self.get_style_context()
@ -2803,10 +2762,6 @@ class MainCover(Gtk.Frame):
provider.load_from_data(css)
style_context.add_provider(provider, 600)
# adding vars
self._client=client
self._settings=settings
# cover
self._cover=Gtk.Image.new()
size=self._settings.get_int("track-cover")
@ -2842,8 +2797,6 @@ class MainCover(Gtk.Frame):
class PlaylistWindow(Gtk.Box):
def __init__(self, client, settings):
super().__init__(orientation=Gtk.Orientation.VERTICAL)
# adding vars
self._client=client
self._settings=settings
self._playlist_version=None
@ -3140,8 +3093,6 @@ class PlaylistWindow(Gtk.Box):
class CoverPlaylistWindow(Gtk.Paned):
def __init__(self, client, settings):
super().__init__()
# adding vars
self._client=client
self._settings=settings
@ -3221,8 +3172,6 @@ class CoverPlaylistWindow(Gtk.Paned):
class PlaybackControl(Gtk.ButtonBox):
def __init__(self, client, settings):
super().__init__(layout_style=Gtk.ButtonBoxStyle.EXPAND)
# adding vars
self._client=client
self._settings=settings
@ -3317,8 +3266,6 @@ class PlaybackControl(Gtk.ButtonBox):
class SeekBar(Gtk.Box):
def __init__(self, client):
super().__init__(hexpand=True)
# adding vars
self._client=client
self._update=True
self._jumped=False
@ -3435,8 +3382,6 @@ class OutputPopover(Gtk.Popover):
def __init__(self, client, relative):
super().__init__()
self.set_relative_to(relative)
# adding vars
self._client=client
# widgets
@ -3461,8 +3406,6 @@ class OutputPopover(Gtk.Popover):
class PlaybackOptions(Gtk.Box):
def __init__(self, client, settings):
super().__init__(spacing=6)
# adding vars
self._client=client
self._settings=settings
self._popover=None
@ -3614,8 +3557,6 @@ class PlaybackOptions(Gtk.Box):
class MPDActionGroup(Gio.SimpleActionGroup):
def __init__(self, client):
super().__init__()
# adding vars
self._client=client
# actions
@ -3688,7 +3629,6 @@ class MPDActionGroup(Gio.SimpleActionGroup):
class ShortcutsWindow(Gtk.ShortcutsWindow):
def __init__(self):
super().__init__()
general_group=Gtk.ShortcutsGroup(title=_("General"), visible=True)
window_group=Gtk.ShortcutsGroup(title=_("Window"), visible=True)
playback_group=Gtk.ShortcutsGroup(title=_("Playback"), visible=True)
@ -3744,8 +3684,6 @@ class ShortcutsWindow(Gtk.ShortcutsWindow):
class ConnectionNotify(Gtk.Revealer):
def __init__(self, client, settings):
super().__init__(valign=Gtk.Align.START, halign=Gtk.Align.CENTER)
# adding vars
self._client=client
self._settings=settings
@ -3792,15 +3730,10 @@ class MainWindow(Gtk.ApplicationWindow):
def __init__(self, app, client, settings):
super().__init__(title=("mpdevil"), icon_name="org.mpdevil.mpdevil", application=app)
self.set_default_icon_name("org.mpdevil.mpdevil")
Notify.init("mpdevil")
self.set_default_size(settings.get_int("width"), settings.get_int("height"))
if settings.get_boolean("maximize"):
self.maximize() # request maximize
shortcuts_window=ShortcutsWindow()
self.set_help_overlay(shortcuts_window)
shortcuts_window.set_modal(False)
# adding vars
Notify.init("mpdevil")
self._client=client
self._settings=settings
self._use_csd=self._settings.get_boolean("use-csd")
@ -3827,6 +3760,11 @@ class MainWindow(Gtk.ApplicationWindow):
self._mpd_action_group=MPDActionGroup(self._client)
self.insert_action_group("mpd", self._mpd_action_group)
# shortcuts
shortcuts_window=ShortcutsWindow()
self.set_help_overlay(shortcuts_window)
shortcuts_window.set_modal(False)
# widgets
if self._use_csd:
icons={"open-menu-symbolic": Gtk.Image.new_from_icon_name("open-menu-symbolic", Gtk.IconSize.BUTTON)}
@ -3880,7 +3818,7 @@ class MainWindow(Gtk.ApplicationWindow):
self._client.emitter.connect("current_song_changed", self._on_song_changed)
self._client.emitter.connect("disconnected", self._on_disconnected)
self._client.emitter.connect("reconnected", self._on_reconnected)
self._browser.connect("search_focus_changed", self._on_search_focus_changed)
self._browser.connect("search-focus-changed", self._on_search_focus_changed)
# auto save window state and size
self.connect("size-allocate", self._on_size_allocate)
self._settings.bind("maximize", self, "is-maximized", Gio.SettingsBindFlags.SET)