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)
def _load_css(self):
styleProvider = Gtk.CssProvider()
styleProvider.load_from_resource(self._get_resource_path('gtk.css'))
style_provider = Gtk.CssProvider()
style_provider.load_from_resource(self._get_resource_path('gtk.css'))
Gtk.StyleContext.add_provider_for_display(
Gdk.Display.get_default(), styleProvider,
Gdk.Display.get_default(), style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
def _setup_actions(self):

View file

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

View file

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

View file

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

View file

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

View file

@ -23,10 +23,10 @@ from .zeroconf import ZeroconfProvider
class WindowState(GObject.Object):
WIDTH = 'width'
HEIGHT = 'height'
IS_MAXIMIZED = 'is_maximized'
IS_FULLSCREENED = 'is_fullscreened'
PROP_WIDTH = 'width'
PROP_HEIGHT = 'height'
PROP_MAXIMIZED = 'is_maximized'
PROP_FULLSCREENED = 'is_fullscreened'
width = GObject.Property(type=int, default=800)
height = GObject.Property(type=int, default=600)
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.on_settings_sort_type_changed)
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,
WindowState.HEIGHT, Gio.SettingsBindFlags.DEFAULT)
WindowState.PROP_HEIGHT,
Gio.SettingsBindFlags.DEFAULT)
self._settings.bind(Window.SETTING_WINDOW_MAXIMIZED, self._state,
WindowState.IS_MAXIMIZED,
WindowState.PROP_MAXIMIZED,
Gio.SettingsBindFlags.DEFAULT)
# Actions
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.content_stack.set_visible_child(self._connection_panel)
if self._settings.get_boolean(Window.SETTING_CONNECTED):
@ -274,7 +276,7 @@ class Window(Adw.ApplicationWindow):
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):
if not self._state.get_property(WindowState.PROP_FULLSCREENED):
self.fullscreen()
else:
self.unfullscreen()
@ -290,14 +292,14 @@ class Window(Adw.ApplicationWindow):
height = self.get_size(Gtk.Orientation.VERTICAL)
if width > 0:
self._cover_panel.set_width(width)
if not self._state.get_property(WindowState.IS_MAXIMIZED):
self._state.set_property(WindowState.WIDTH, width)
self._state.set_property(WindowState.HEIGHT, height)
if not self._state.get_property(WindowState.PROP_MAXIMIZED):
self._state.set_property(WindowState.PROP_WIDTH, width)
self._state.set_property(WindowState.PROP_HEIGHT, height)
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)
self._state.set_property(WindowState.PROP_MAXIMIZED, maximized is True)
def on_fullscreened(self, widget, fullscreened):
self._fullscreen(self.is_fullscreen())
@ -371,7 +373,7 @@ class Window(Adw.ApplicationWindow):
self._mcg.enable_output_device(device, enabled)
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()
else:
self.unfullscreen()
@ -433,7 +435,10 @@ class Window(Adw.ApplicationWindow):
bitrate, error):
# 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)
# State
if state == 'play':
@ -534,10 +539,11 @@ 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,
WindowState.PROP_FULLSCREENED
):
self._state.set_property(WindowState.PROP_FULLSCREENED,
fullscreened_new)
if self._state.get_property(WindowState.IS_FULLSCREENED):
if self._state.get_property(WindowState.PROP_FULLSCREENED):
self.headerbar.hide()
self._cover_panel.set_fullscreen(True)
self.set_cursor(Gdk.Cursor.new_from_name("none", None))