Improve variable names to match Code Style Guide (see #103)

This commit is contained in:
coderkun 2024-05-28 12:02:43 +02:00
parent 4ebfc12f0e
commit 54fe825acf
6 changed files with 71 additions and 65 deletions

View file

@ -77,10 +77,10 @@ albums instead of single tracks.""")
style_manager.set_color_scheme(Adw.ColorScheme.PREFER_DARK) style_manager.set_color_scheme(Adw.ColorScheme.PREFER_DARK)
def _load_css(self): def _load_css(self):
styleProvider = Gtk.CssProvider() style_provider = Gtk.CssProvider()
styleProvider.load_from_resource(self._get_resource_path('gtk.css')) style_provider.load_from_resource(self._get_resource_path('gtk.css'))
Gtk.StyleContext.add_provider_for_display( Gtk.StyleContext.add_provider_for_display(
Gdk.Display.get_default(), styleProvider, Gdk.Display.get_default(), style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
def _setup_actions(self): def _setup_actions(self):

View file

@ -831,12 +831,12 @@ class Client(Base):
self._buffer = buf self._buffer = buf
def _parse_dict(self, response): def _parse_dict(self, response):
dict = {} dictionary = {}
if response: if response:
for line in response: for line in response:
key, value = self._split_line(line) key, value = self._split_line(line)
dict[key] = value dictionary[key] = value
return dict return dictionary
def _parse_list(self, response, delimiters): def _parse_list(self, response, delimiters):
entry = {} entry = {}
@ -863,13 +863,13 @@ class Client(Base):
album = None album = None
if 'album' not in song: if 'album' not in song:
song['album'] = MCGAlbum.DEFAULT_ALBUM song['album'] = MCGAlbum.DEFAULT_ALBUM
id = Utils.generate_id(song['album']) album_id = Utils.generate_id(song['album'])
if lookup and id in self._albums.keys(): if lookup and album_id in self._albums.keys():
album = self._albums[id] album = self._albums[album_id]
else: else:
album = MCGAlbum(song['album'], self._host) album = MCGAlbum(song['album'], self._host)
if lookup: if lookup:
self._albums[id] = album self._albums[album_id] = album
return album return album
def _extract_track(self, song): def _extract_track(self, song):
@ -1047,22 +1047,22 @@ class MCGAlbum:
elif criterion == SortOrder.MODIFIED: elif criterion == SortOrder.MODIFIED:
value_function = "get_last_modified" value_function = "get_last_modified"
reverseMultiplier = -1 if reverse else 1 reverse_multiplier = -1 if reverse else 1
value1 = getattr(album1, value_function)() value1 = getattr(album1, value_function)()
value2 = getattr(album2, value_function)() value2 = getattr(album2, value_function)()
if value1 is None and value2 is None: if value1 is None and value2 is None:
return 0 return 0
elif value1 is None: elif value1 is None:
return -1 * reverseMultiplier return -1 * reverse_multiplier
elif value2 is None: elif value2 is None:
return 1 * reverseMultiplier return 1 * reverse_multiplier
if value1 < value2: if value1 < value2:
return -1 * reverseMultiplier return -1 * reverse_multiplier
elif value1 == value2: elif value1 == value2:
return 0 return 0
else: else:
return 1 * reverseMultiplier return 1 * reverse_multiplier
class MCGTrack: class MCGTrack:

View file

@ -54,16 +54,16 @@ class CoverPanel(Gtk.Overlay):
GObject.idle_add(self._enable_tracklist) GObject.idle_add(self._enable_tracklist)
# Click handler for image # Click handler for image
clickController = Gtk.GestureClick() click_controller = Gtk.GestureClick()
clickController.connect('pressed', self.on_cover_box_pressed) click_controller.connect('pressed', self.on_cover_box_pressed)
self.cover_box.add_controller(clickController) self.cover_box.add_controller(click_controller)
# Button controller for songs scale # Button controller for songs scale
buttonController = Gtk.GestureClick() button_controller = Gtk.GestureClick()
buttonController.connect('pressed', self.on_songs_scale_pressed) button_controller.connect('pressed', self.on_songs_scale_pressed)
buttonController.connect('unpaired-release', button_controller.connect('unpaired-release',
self.on_songs_scale_released) self.on_songs_scale_released)
self.songs_scale.add_controller(buttonController) self.songs_scale.add_controller(button_controller)
def get_toolbar(self): def get_toolbar(self):
return self.toolbar return self.toolbar
@ -226,10 +226,10 @@ class CoverPanel(Gtk.Overlay):
return return
# Skalierungswert für Breite und Höhe ermitteln # Skalierungswert für Breite und Höhe ermitteln
ratioW = float(size_width) / float(pixbuf.get_width()) ratio_w = float(size_width) / float(pixbuf.get_width())
ratioH = float(size_height) / float(pixbuf.get_height()) ratio_h = float(size_height) / float(pixbuf.get_height())
# Kleineren beider Skalierungswerte nehmen, nicht Hochskalieren # Kleineren beider Skalierungswerte nehmen, nicht Hochskalieren
ratio = min(ratioW, ratioH) ratio = min(ratio_w, ratio_h)
ratio = min(ratio, 1) ratio = min(ratio, 1)
# Neue Breite und Höhe berechnen # Neue Breite und Höhe berechnen
width = int(math.floor(pixbuf.get_width() * ratio)) width = int(math.floor(pixbuf.get_width() * ratio))

View file

@ -116,10 +116,10 @@ class LibraryPanel(Adw.Bin):
} }
# Button controller for grid scale # Button controller for grid scale
buttonController = Gtk.GestureClick() button_controller = Gtk.GestureClick()
buttonController.connect('unpaired-release', button_controller.connect('unpaired-release',
self.on_grid_scale_released) self.on_grid_scale_released)
self.grid_scale.add_controller(buttonController) self.grid_scale.add_controller(button_controller)
def get_headerbar_standalone(self): def get_headerbar_standalone(self):
return self._headerbar_standalone return self._headerbar_standalone
@ -151,8 +151,8 @@ class LibraryPanel(Adw.Bin):
def on_grid_scale_released(self, widget, x, y, npress, sequence): def on_grid_scale_released(self, widget, x, y, npress, sequence):
size = math.floor(self.grid_scale.get_value()) size = math.floor(self.grid_scale.get_value())
range = self.grid_scale.get_adjustment() grid_range = self.grid_scale.get_adjustment()
if size < range.get_lower() or size > range.get_upper(): if size < grid_range.get_lower() or size > grid_range.get_upper():
return return
self._item_size = size self._item_size = size
self.emit('item-size-changed', size) self.emit('item-size-changed', size)
@ -162,8 +162,8 @@ class LibraryPanel(Adw.Bin):
@Gtk.Template.Callback() @Gtk.Template.Callback()
def on_grid_scale_changed(self, widget): def on_grid_scale_changed(self, widget):
size = math.floor(self.grid_scale.get_value()) size = math.floor(self.grid_scale.get_value())
range = widget.get_adjustment() grid_range = widget.get_adjustment()
if size < range.get_lower() or size > range.get_upper(): if size < grid_range.get_lower() or size > grid_range.get_upper():
return return
self._set_widget_grid_size(self.library_grid, size, True) self._set_widget_grid_size(self.library_grid, size, True)
@ -200,9 +200,9 @@ class LibraryPanel(Adw.Bin):
# Get selected album # Get selected album
item = self._library_grid_filter.get_item(position) item = self._library_grid_filter.get_item(position)
album = item.get_album() album = item.get_album()
id = album.get_id() album_id = album.get_id()
self._selected_albums = [album] self._selected_albums = [album]
self.emit('albumart', id) self.emit('albumart', album_id)
# Show standalone album # Show standalone album
if widget.get_model() == self._library_grid_selection_single: if widget.get_model() == self._library_grid_selection_single:
@ -415,9 +415,9 @@ class LibraryPanel(Adw.Bin):
lower = int(self.grid_scale.get_adjustment().get_lower()) lower = int(self.grid_scale.get_adjustment().get_lower())
upper = int(self.grid_scale.get_adjustment().get_upper()) upper = int(self.grid_scale.get_adjustment().get_upper())
countMin = max(int(width / upper), 1) count_min = max(int(width / upper), 1)
countMax = max(int(width / lower), 1) count_max = max(int(width / lower), 1)
for index in range(countMin, countMax): for index in range(count_min, count_max):
pixel = int(width / index) pixel = int(width / index)
pixel = pixel - (2 * int(pixel / 100)) 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)
@ -445,10 +445,10 @@ class LibraryPanel(Adw.Bin):
return return
# Skalierungswert für Breite und Höhe ermitteln # Skalierungswert für Breite und Höhe ermitteln
ratioW = float(size_width) / float(pixbuf.get_width()) ratio_w = float(size_width) / float(pixbuf.get_width())
ratioH = float(size_height) / float(pixbuf.get_height()) ratio_h = float(size_height) / float(pixbuf.get_height())
# Kleineren beider Skalierungswerte nehmen, nicht Hochskalieren # Kleineren beider Skalierungswerte nehmen, nicht Hochskalieren
ratio = min(ratioW, ratioH) ratio = min(ratio_w, ratio_h)
ratio = min(ratio, 1) ratio = min(ratio, 1)
# Neue Breite und Höhe berechnen # Neue Breite und Höhe berechnen
width = int(math.floor(pixbuf.get_width() * ratio)) width = int(math.floor(pixbuf.get_width() * ratio))

View file

@ -110,9 +110,9 @@ class PlaylistPanel(Adw.Bin):
# Get selected album # Get selected album
item = self._playlist_grid_model.get_item(position) item = self._playlist_grid_model.get_item(position)
album = item.get_album() album = item.get_album()
id = album.get_id() album_id = album.get_id()
self._selected_albums = [album] self._selected_albums = [album]
self.emit('albumart', id) self.emit('albumart', album_id)
# Show standalone album # Show standalone album
if widget.get_model() == self._playlist_grid_selection_single: if widget.get_model() == self._playlist_grid_selection_single:
@ -253,10 +253,10 @@ class PlaylistPanel(Adw.Bin):
return return
# Skalierungswert für Breite und Höhe ermitteln # Skalierungswert für Breite und Höhe ermitteln
ratioW = float(size_width) / float(pixbuf.get_width()) ratio_w = float(size_width) / float(pixbuf.get_width())
ratioH = float(size_height) / float(pixbuf.get_height()) ratio_h = float(size_height) / float(pixbuf.get_height())
# Kleineren beider Skalierungswerte nehmen, nicht Hochskalieren # Kleineren beider Skalierungswerte nehmen, nicht Hochskalieren
ratio = min(ratioW, ratioH) ratio = min(ratio_w, ratio_h)
ratio = min(ratio, 1) ratio = min(ratio, 1)
# Neue Breite und Höhe berechnen # Neue Breite und Höhe berechnen
width = int(math.floor(pixbuf.get_width() * ratio)) width = int(math.floor(pixbuf.get_width() * ratio))

View file

@ -23,10 +23,10 @@ from .zeroconf import ZeroconfProvider
class WindowState(GObject.Object): class WindowState(GObject.Object):
WIDTH = 'width' PROP_WIDTH = 'width'
HEIGHT = 'height' PROP_HEIGHT = 'height'
IS_MAXIMIZED = 'is_maximized' PROP_MAXIMIZED = 'is_maximized'
IS_FULLSCREENED = 'is_fullscreened' PROP_FULLSCREENED = 'is_fullscreened'
width = GObject.Property(type=int, default=800) width = GObject.Property(type=int, default=800)
height = GObject.Property(type=int, default=600) height = GObject.Property(type=int, default=600)
is_maximized = GObject.Property(type=bool, default=False) is_maximized = GObject.Property(type=bool, default=False)
@ -206,16 +206,18 @@ class Window(Adw.ApplicationWindow):
self._settings.connect('changed::' + Window.SETTING_SORT_TYPE, self._settings.connect('changed::' + Window.SETTING_SORT_TYPE,
self.on_settings_sort_type_changed) self.on_settings_sort_type_changed)
self._settings.bind(Window.SETTING_WINDOW_WIDTH, self._state, self._settings.bind(Window.SETTING_WINDOW_WIDTH, self._state,
WindowState.WIDTH, Gio.SettingsBindFlags.DEFAULT) WindowState.PROP_WIDTH,
Gio.SettingsBindFlags.DEFAULT)
self._settings.bind(Window.SETTING_WINDOW_HEIGHT, self._state, self._settings.bind(Window.SETTING_WINDOW_HEIGHT, self._state,
WindowState.HEIGHT, Gio.SettingsBindFlags.DEFAULT) WindowState.PROP_HEIGHT,
Gio.SettingsBindFlags.DEFAULT)
self._settings.bind(Window.SETTING_WINDOW_MAXIMIZED, self._state, self._settings.bind(Window.SETTING_WINDOW_MAXIMIZED, self._state,
WindowState.IS_MAXIMIZED, WindowState.PROP_MAXIMIZED,
Gio.SettingsBindFlags.DEFAULT) Gio.SettingsBindFlags.DEFAULT)
# Actions # Actions
self.set_default_size(self._state.width, self._state.height) self.set_default_size(self._state.width, self._state.height)
if self._state.get_property(WindowState.IS_MAXIMIZED): if self._state.get_property(WindowState.PROP_MAXIMIZED):
self.maximize() self.maximize()
self.content_stack.set_visible_child(self._connection_panel) self.content_stack.set_visible_child(self._connection_panel)
if self._settings.get_boolean(Window.SETTING_CONNECTED): if self._settings.get_boolean(Window.SETTING_CONNECTED):
@ -274,7 +276,7 @@ class Window(Adw.ApplicationWindow):
def on_menu_toggle_fullscreen(self, action, value): def on_menu_toggle_fullscreen(self, action, value):
self.panel_stack.set_visible_child(self._cover_panel) self.panel_stack.set_visible_child(self._cover_panel)
if not self._state.get_property(WindowState.IS_FULLSCREENED): if not self._state.get_property(WindowState.PROP_FULLSCREENED):
self.fullscreen() self.fullscreen()
else: else:
self.unfullscreen() self.unfullscreen()
@ -290,14 +292,14 @@ class Window(Adw.ApplicationWindow):
height = self.get_size(Gtk.Orientation.VERTICAL) height = self.get_size(Gtk.Orientation.VERTICAL)
if width > 0: if width > 0:
self._cover_panel.set_width(width) self._cover_panel.set_width(width)
if not self._state.get_property(WindowState.IS_MAXIMIZED): if not self._state.get_property(WindowState.PROP_MAXIMIZED):
self._state.set_property(WindowState.WIDTH, width) self._state.set_property(WindowState.PROP_WIDTH, width)
self._state.set_property(WindowState.HEIGHT, height) self._state.set_property(WindowState.PROP_HEIGHT, height)
GObject.idle_add(self._playlist_panel.set_size, width, height) GObject.idle_add(self._playlist_panel.set_size, width, height)
GObject.idle_add(self._library_panel.set_size, width, height) GObject.idle_add(self._library_panel.set_size, width, height)
def on_maximized(self, widget, maximized): def on_maximized(self, widget, maximized):
self._state.set_property(WindowState.IS_MAXIMIZED, maximized is True) self._state.set_property(WindowState.PROP_MAXIMIZED, maximized is True)
def on_fullscreened(self, widget, fullscreened): def on_fullscreened(self, widget, fullscreened):
self._fullscreen(self.is_fullscreen()) self._fullscreen(self.is_fullscreen())
@ -371,7 +373,7 @@ class Window(Adw.ApplicationWindow):
self._mcg.enable_output_device(device, enabled) self._mcg.enable_output_device(device, enabled)
def on_cover_panel_toggle_fullscreen(self, widget): def on_cover_panel_toggle_fullscreen(self, widget):
if not self._state.get_property(WindowState.IS_FULLSCREENED): if not self._state.get_property(WindowState.PROP_FULLSCREENED):
self.fullscreen() self.fullscreen()
else: else:
self.unfullscreen() self.unfullscreen()
@ -433,7 +435,10 @@ class Window(Adw.ApplicationWindow):
bitrate, error): bitrate, error):
# Album # Album
GObject.idle_add(self._cover_panel.set_album, album) GObject.idle_add(self._cover_panel.set_album, album)
if not album and self._state.get_property(WindowState.IS_FULLSCREENED): if (
not album
and self._state.get_property(WindowState.PROP_FULLSCREENED)
):
self._fullscreen(False) self._fullscreen(False)
# State # State
if state == 'play': if state == 'play':
@ -534,10 +539,11 @@ class Window(Adw.ApplicationWindow):
def _fullscreen(self, fullscreened_new): def _fullscreen(self, fullscreened_new):
if fullscreened_new != self._state.get_property( if fullscreened_new != self._state.get_property(
WindowState.IS_FULLSCREENED): WindowState.PROP_FULLSCREENED
self._state.set_property(WindowState.IS_FULLSCREENED, ):
self._state.set_property(WindowState.PROP_FULLSCREENED,
fullscreened_new) fullscreened_new)
if self._state.get_property(WindowState.IS_FULLSCREENED): if self._state.get_property(WindowState.PROP_FULLSCREENED):
self.headerbar.hide() self.headerbar.hide()
self._cover_panel.set_fullscreen(True) self._cover_panel.set_fullscreen(True)
self.set_cursor(Gdk.Cursor.new_from_name("none", None)) self.set_cursor(Gdk.Cursor.new_from_name("none", None))