Adjust line length to match Code Style Guide (see #103)
This commit is contained in:
parent
d2e1f6f5d8
commit
a1f8b73590
1 changed files with 436 additions and 258 deletions
|
|
@ -25,13 +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
|
||||
|
|
@ -85,7 +86,8 @@ 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
|
||||
|
|
@ -93,13 +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_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
|
||||
|
|
@ -113,7 +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):
|
||||
|
|
@ -131,12 +137,14 @@ 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):
|
||||
|
|
@ -163,7 +171,10 @@ 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)
|
||||
|
||||
|
|
@ -182,7 +193,8 @@ 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):
|
||||
|
|
@ -242,13 +254,19 @@ 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
|
||||
|
|
@ -267,7 +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:
|
||||
|
|
@ -284,10 +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()
|
||||
|
|
@ -296,7 +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)
|
||||
|
|
@ -318,20 +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)
|
||||
|
|
@ -339,7 +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()
|
||||
|
|
@ -353,16 +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():
|
||||
|
|
@ -394,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)
|
||||
|
|
@ -429,27 +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))
|
||||
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,
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue