Port UI to GTK 4 (close #85)
This commit is contained in:
parent
6ba8bc550f
commit
75b99e5820
1 changed files with 1730 additions and 3285 deletions
|
|
@ -2,135 +2,27 @@
|
|||
|
||||
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gtk', '4.0')
|
||||
gi.require_version('Adw', '1')
|
||||
import locale
|
||||
import logging
|
||||
import math
|
||||
import threading
|
||||
|
||||
from gi.repository import Gtk, GObject, GdkPixbuf
|
||||
from gi.repository import Gtk, Gdk, GObject, GdkPixbuf, Gio, Adw
|
||||
|
||||
from mcg import client
|
||||
from mcg.albumheaderbar import AlbumHeaderbar
|
||||
from mcg.utils import SortOrder
|
||||
from mcg.utils import Utils
|
||||
|
||||
|
||||
|
||||
|
||||
@Gtk.Template(resource_path='/xyz/suruatoel/mcg/ui/library-toolbar.ui')
|
||||
class LibraryToolbar(Gtk.ButtonBox):
|
||||
__gtype_name__ = 'McgLibraryToolbar'
|
||||
__gsignals__ = {
|
||||
'select': (GObject.SIGNAL_RUN_FIRST, None, (bool,)),
|
||||
'toggle-search': (GObject.SIGNAL_RUN_FIRST, None, (bool,)),
|
||||
'update': (GObject.SIGNAL_RUN_FIRST, None, ()),
|
||||
'start-scale': (GObject.SIGNAL_RUN_FIRST, None, (int,)),
|
||||
'end-scale': (GObject.SIGNAL_RUN_FIRST, None, (int,)),
|
||||
'sort': (GObject.SIGNAL_RUN_FIRST, None, (int,)),
|
||||
'sort-type': (GObject.SIGNAL_RUN_FIRST, None, (Gtk.SortType,))
|
||||
}
|
||||
|
||||
# Widgets
|
||||
select_button = Gtk.Template.Child()
|
||||
toolbar_search_bar = Gtk.Template.Child()
|
||||
toolbar_popover = Gtk.Template.Child()
|
||||
toolbar_sort_order_button = Gtk.Template.Child()
|
||||
sort_artist = Gtk.Template.Child()
|
||||
sort_title = Gtk.Template.Child()
|
||||
sort_year = Gtk.Template.Child()
|
||||
sort_modified = Gtk.Template.Child()
|
||||
grid_scale = Gtk.Template.Child()
|
||||
|
||||
|
||||
def __init__(self, item_size):
|
||||
super().__init__()
|
||||
|
||||
# Toolbar menu
|
||||
self.grid_scale.set_value(item_size)
|
||||
self._toolbar_sort_buttons = {
|
||||
SortOrder.ARTIST: self.sort_artist,
|
||||
SortOrder.TITLE: self.sort_title,
|
||||
SortOrder.YEAR: self.sort_year,
|
||||
SortOrder.MODIFIED: self.sort_modified
|
||||
}
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_select_toggled(self, widget):
|
||||
self.emit('select', widget.get_active())
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_search_toggled(self, widget):
|
||||
self.emit('toggle-search', widget.get_active())
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_update_clicked(self, widget):
|
||||
self.emit('update')
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_grid_scale_change(self, widget, scroll, value):
|
||||
self.emit('start-scale', value)
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_grid_scale_changed(self, widget, event):
|
||||
self.emit('end-scale', self.grid_scale.get_value())
|
||||
self.toolbar_popover.popdown()
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_sort_toggled(self, widget):
|
||||
if widget.get_active():
|
||||
sort = [key for key, value in self._toolbar_sort_buttons.items() if value is widget][0]
|
||||
self.emit('sort', sort)
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_sort_order_toggled(self, button):
|
||||
if button.get_active():
|
||||
sort_type = Gtk.SortType.DESCENDING
|
||||
else:
|
||||
sort_type = Gtk.SortType.ASCENDING
|
||||
self.emit('sort-type', sort_type)
|
||||
|
||||
|
||||
def get_grid_scale(self):
|
||||
return self.grid_scale
|
||||
|
||||
|
||||
def is_search_active(self):
|
||||
return self.toolbar_search_bar.get_active()
|
||||
|
||||
|
||||
def set_search_active(self, active):
|
||||
self.toolbar_search_bar.set_active(active)
|
||||
|
||||
|
||||
def exit_selection(self):
|
||||
self.select_button.set_active(False)
|
||||
|
||||
|
||||
def set_sort_order(self, sort):
|
||||
button = self._toolbar_sort_buttons[sort]
|
||||
if button and not button.get_active():
|
||||
button.set_active(True)
|
||||
|
||||
|
||||
def set_sort_type(self, sort_type):
|
||||
if sort_type:
|
||||
self.toolbar_sort_order_button.set_active(True)
|
||||
else:
|
||||
self.toolbar_sort_order_button.set_active(False)
|
||||
from mcg.utils import GridItem
|
||||
from mcg.utils import SearchFilter
|
||||
|
||||
|
||||
|
||||
|
||||
@Gtk.Template(resource_path='/xyz/suruatoel/mcg/ui/library-panel.ui')
|
||||
class LibraryPanel(Gtk.Stack):
|
||||
class LibraryPanel(Adw.Bin):
|
||||
__gtype_name__ = 'McgLibraryPanel'
|
||||
__gsignals__ = {
|
||||
'open-standalone': (GObject.SIGNAL_RUN_FIRST, None, ()),
|
||||
|
|
@ -141,14 +33,27 @@ class LibraryPanel(Gtk.Stack):
|
|||
'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, (Gtk.SortType,)),
|
||||
'albumart': (GObject.SIGNAL_RUN_FIRST, None, (str,))
|
||||
'sort-type-changed': (GObject.SIGNAL_RUN_FIRST, None, (bool,)),
|
||||
'albumart': (GObject.SIGNAL_RUN_FIRST, None, (str,)),
|
||||
}
|
||||
|
||||
|
||||
# Widgets
|
||||
library_stack = Gtk.Template.Child()
|
||||
panel_normal = Gtk.Template.Child()
|
||||
panel_standalone = Gtk.Template.Child()
|
||||
actionbar_revealer = Gtk.Template.Child()
|
||||
# Toolbar
|
||||
toolbar = Gtk.Template.Child()
|
||||
select_button = Gtk.Template.Child()
|
||||
toolbar_search_bar = Gtk.Template.Child()
|
||||
toolbar_popover = Gtk.Template.Child()
|
||||
toolbar_sort_order_button = Gtk.Template.Child()
|
||||
sort_artist = Gtk.Template.Child()
|
||||
sort_title = Gtk.Template.Child()
|
||||
sort_year = Gtk.Template.Child()
|
||||
sort_modified = Gtk.Template.Child()
|
||||
grid_scale = Gtk.Template.Child()
|
||||
# Filter/search bar
|
||||
filter_bar = Gtk.Template.Child()
|
||||
filter_entry = Gtk.Template.Child()
|
||||
|
|
@ -160,6 +65,9 @@ class LibraryPanel(Gtk.Stack):
|
|||
scroll = Gtk.Template.Child()
|
||||
# Library Grid
|
||||
library_grid = Gtk.Template.Child()
|
||||
# Action bar (normal)
|
||||
actionbar = Gtk.Template.Child()
|
||||
actionbar_standalone = Gtk.Template.Child()
|
||||
# Standalone Image
|
||||
standalone_stack = Gtk.Template.Child()
|
||||
standalone_spinner = Gtk.Template.Child()
|
||||
|
|
@ -167,52 +75,51 @@ class LibraryPanel(Gtk.Stack):
|
|||
standalone_image = Gtk.Template.Child()
|
||||
|
||||
|
||||
def __init__(self, client):
|
||||
super().__init__()
|
||||
def __init__(self, client, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self._logger = logging.getLogger(__name__)
|
||||
self._client = client
|
||||
self._buttons = {}
|
||||
self._albums = None
|
||||
self._host = "localhost"
|
||||
self._filter_string = ""
|
||||
self._item_size = 150
|
||||
self._sort_order = SortOrder.YEAR
|
||||
self._sort_type = Gtk.SortType.DESCENDING
|
||||
self._grid_pixbufs = {}
|
||||
self._grid_width = 0
|
||||
self._old_ranges = {}
|
||||
self._library_lock = threading.Lock()
|
||||
self._library_stop = threading.Event()
|
||||
self._icon_theme = Gtk.IconTheme.get_default()
|
||||
self._icon_theme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default())
|
||||
self._standalone_pixbuf = None
|
||||
self._selected_albums = []
|
||||
self._allocation = (0, 0)
|
||||
self._is_selected = False
|
||||
|
||||
# Widgets
|
||||
self._toolbar = LibraryToolbar(self._item_size)
|
||||
self._toolbar.connect('select', self.on_toolbar_select)
|
||||
self._toolbar.connect('toggle-search', self.on_toolbar_toggle_search)
|
||||
self._toolbar.connect('update', self.on_toolbar_update)
|
||||
self._toolbar.connect('start-scale', self.on_toolbar_scale)
|
||||
self._toolbar.connect('end-scale', self.on_toolbar_scaled)
|
||||
self._toolbar.connect('sort', self.on_toolbar_sort)
|
||||
self._toolbar.connect('sort-type', self.on_toolbar_sort_type)
|
||||
# Header bar
|
||||
self._headerbar_standalone = AlbumHeaderbar()
|
||||
self._headerbar_standalone.connect('close', self.on_standalone_close_clicked)
|
||||
# Progress Bar
|
||||
self.progress_image.set_from_pixbuf(self._get_default_image())
|
||||
# Library Grid: Model
|
||||
self._library_grid_model = Gtk.ListStore(GdkPixbuf.Pixbuf, str, str)
|
||||
self._library_grid_model.set_sort_func(2, self.compare_albums, self._sort_order)
|
||||
self._library_grid_model.set_sort_column_id(2, self._sort_type)
|
||||
self._library_grid_filter = self._library_grid_model.filter_new()
|
||||
self._library_grid_filter.set_visible_func(self.on_filter_visible)
|
||||
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)
|
||||
# Library Grid
|
||||
self.library_grid.set_model(self._library_grid_filter)
|
||||
self.library_grid.set_pixbuf_column(0)
|
||||
self.library_grid.set_text_column(-1)
|
||||
self.library_grid.set_tooltip_column(1)
|
||||
self.library_grid.set_model(self._library_grid_selection_single)
|
||||
# Toolbar menu
|
||||
self.grid_scale.set_value(self._item_size)
|
||||
self._toolbar_sort_buttons = {
|
||||
SortOrder.ARTIST: self.sort_artist,
|
||||
SortOrder.TITLE: self.sort_title,
|
||||
SortOrder.YEAR: self.sort_year,
|
||||
SortOrder.MODIFIED: self.sort_modified
|
||||
}
|
||||
|
||||
# Button controller for grid scale
|
||||
buttonController = Gtk.GestureClick()
|
||||
buttonController.connect('unpaired-release', self.on_grid_scale_released)
|
||||
self.grid_scale.add_controller(buttonController)
|
||||
|
||||
|
||||
def get_headerbar_standalone(self):
|
||||
|
|
@ -220,7 +127,7 @@ class LibraryPanel(Gtk.Stack):
|
|||
|
||||
|
||||
def get_toolbar(self):
|
||||
return self._toolbar
|
||||
return self.toolbar
|
||||
|
||||
|
||||
def set_selected(self, selected):
|
||||
|
|
@ -228,101 +135,83 @@ class LibraryPanel(Gtk.Stack):
|
|||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_resize(self, widget, event):
|
||||
new_allocation = (widget.get_allocation().width, widget.get_allocation().height)
|
||||
if new_allocation == self._allocation:
|
||||
return
|
||||
self._allocation = new_allocation
|
||||
self._toolbar.get_grid_scale().clear_marks()
|
||||
width = widget.get_allocation().width
|
||||
|
||||
lower = int(self._toolbar.get_grid_scale().get_adjustment().get_lower())
|
||||
upper = int(self._toolbar.get_grid_scale().get_adjustment().get_upper())
|
||||
countMin = max(int(width / upper), 1)
|
||||
countMax = max(int(width / lower), 1)
|
||||
for index in range(countMin, countMax):
|
||||
pixel = int(width / index)
|
||||
pixel = pixel - (2 * int(pixel / 100))
|
||||
self._toolbar.get_grid_scale().add_mark(
|
||||
pixel,
|
||||
Gtk.PositionType.BOTTOM,
|
||||
None
|
||||
)
|
||||
|
||||
|
||||
def on_toolbar_toggle_search(self, widget, active):
|
||||
self.filter_bar.set_search_mode(active)
|
||||
|
||||
|
||||
def on_toolbar_select(self, widget, active):
|
||||
if active:
|
||||
def on_select_toggled(self, widget):
|
||||
if self.select_button.get_active():
|
||||
self.actionbar_revealer.set_reveal_child(True)
|
||||
self.library_grid.set_selection_mode(Gtk.SelectionMode.MULTIPLE)
|
||||
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)
|
||||
else:
|
||||
self.actionbar_revealer.set_reveal_child(False)
|
||||
self.library_grid.set_selection_mode(Gtk.SelectionMode.SINGLE)
|
||||
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)
|
||||
|
||||
|
||||
def on_toolbar_update(self, widget):
|
||||
@Gtk.Template.Callback()
|
||||
def on_update_clicked(self, widget):
|
||||
self.emit('update')
|
||||
|
||||
|
||||
def on_toolbar_scale(self, widget, value):
|
||||
size = math.floor(value)
|
||||
range = self._toolbar.get_grid_scale().get_adjustment()
|
||||
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():
|
||||
return
|
||||
self._item_size = size
|
||||
GObject.idle_add(self.library_grid.set_item_padding, size / 100)
|
||||
GObject.idle_add(self._set_widget_grid_size, self.library_grid, size, True)
|
||||
|
||||
|
||||
def on_toolbar_scaled(self, widget, value):
|
||||
size = round(value)
|
||||
range = self._toolbar.get_grid_scale().get_adjustment()
|
||||
if size < range.get_lower() or size > range.get_upper():
|
||||
return False
|
||||
self.emit('item-size-changed', size)
|
||||
self._redraw()
|
||||
return False
|
||||
|
||||
|
||||
def on_toolbar_sort(self, widget, sort):
|
||||
self._change_sort(sort)
|
||||
|
||||
|
||||
def on_toolbar_sort_type(self, widget, sort_type):
|
||||
self._sort_type = sort_type
|
||||
self._library_grid_model.set_sort_column_id(2, sort_type)
|
||||
self.emit('sort-type-changed', sort_type)
|
||||
GObject.idle_add(self.toolbar_popover.popdown)
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_filter_bar_notify(self, widget, value):
|
||||
if self._toolbar.is_search_active() is not self.filter_bar.get_search_mode():
|
||||
self._toolbar.set_search_active(self.filter_bar.get_search_mode())
|
||||
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():
|
||||
return
|
||||
self._set_widget_grid_size(self.library_grid, size, True)
|
||||
|
||||
|
||||
@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_grid_model()
|
||||
self.emit('sort-order-changed', self._sort_order)
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_sort_order_toggled(self, button):
|
||||
if button.get_active():
|
||||
self._sort_type = Gtk.SortType.DESCENDING
|
||||
else:
|
||||
self._sort_type = Gtk.SortType.ASCENDING
|
||||
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._filter_string = self.filter_entry.get_text()
|
||||
GObject.idle_add(self._library_grid_filter.refilter)
|
||||
self._library_grid_filter.set_filter(SearchFilter(self.filter_entry.get_text()))
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_library_grid_clicked(self, widget, path):
|
||||
def on_library_grid_clicked(self, widget, position):
|
||||
# Get selected album
|
||||
path = self._library_grid_filter.convert_path_to_child_path(path)
|
||||
iter = self._library_grid_model.get_iter(path)
|
||||
id = self._library_grid_model.get_value(iter, 2)
|
||||
album = self._albums[id]
|
||||
item = self._library_grid_filter.get_item(position)
|
||||
album = item.get_album()
|
||||
id = album.get_id()
|
||||
self._selected_albums = [album]
|
||||
self.emit('albumart', id)
|
||||
|
||||
# Show standalone album
|
||||
if widget.get_selection_mode() == Gtk.SelectionMode.SINGLE:
|
||||
if widget.get_model() == self._library_grid_selection_single:
|
||||
# Set labels
|
||||
self._headerbar_standalone.set_album(album)
|
||||
|
||||
|
|
@ -334,39 +223,15 @@ class LibraryPanel(Gtk.Stack):
|
|||
self.standalone_spinner.start()
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_library_grid_selection_changed(self, widget):
|
||||
self._selected_albums = []
|
||||
for path in widget.get_selected_items():
|
||||
path = self._library_grid_filter.convert_path_to_child_path(path)
|
||||
iter = self._library_grid_model.get_iter(path)
|
||||
id = self._library_grid_model.get_value(iter, 2)
|
||||
self._selected_albums.insert(0, self._albums[id])
|
||||
|
||||
|
||||
def on_filter_visible(self, model, iter, data):
|
||||
id = model.get_value(iter, 2)
|
||||
if not id in self._albums.keys():
|
||||
return
|
||||
album = self._albums[id]
|
||||
return album.filter(self._filter_string)
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_selection_cancel_clicked(self, widget):
|
||||
self._toolbar.exit_selection()
|
||||
self.select_button.set_active(False)
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_selection_add_clicked(self, widget):
|
||||
ids = [album.get_id() for album in self._selected_albums]
|
||||
self.emit('queue-multiple', ids)
|
||||
self._toolbar.exit_selection()
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_standalone_scroll_size_allocate(self, widget, allocation):
|
||||
self._resize_standalone_image()
|
||||
self.emit('queue-multiple', self._get_selected_albums())
|
||||
self.select_button.set_active(False)
|
||||
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
|
|
@ -392,7 +257,7 @@ class LibraryPanel(Gtk.Stack):
|
|||
def set_item_size(self, item_size):
|
||||
if self._item_size != item_size:
|
||||
self._item_size = item_size
|
||||
self._toolbar.get_grid_scale().set_value(item_size)
|
||||
self.grid_scale.set_value(item_size)
|
||||
self._redraw()
|
||||
|
||||
|
||||
|
|
@ -401,26 +266,21 @@ class LibraryPanel(Gtk.Stack):
|
|||
|
||||
|
||||
def set_sort_order(self, sort):
|
||||
if self._sort_order != sort:
|
||||
self._toolbar.set_sort_order(sort)
|
||||
self._sort_order = sort
|
||||
self._library_grid_model.set_sort_func(2, self.compare_albums, self._sort_order)
|
||||
|
||||
|
||||
def get_sort_order(self):
|
||||
return self._sort_order
|
||||
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]
|
||||
if not button.get_active():
|
||||
button.set_active(True)
|
||||
self._sort_grid_model()
|
||||
|
||||
|
||||
def set_sort_type(self, sort_type):
|
||||
if self._sort_type != sort_type:
|
||||
self._toolbar.set_sort_type(sort_type)
|
||||
if sort_type:
|
||||
sort_type_gtk = Gtk.SortType.DESCENDING
|
||||
else:
|
||||
sort_type_gtk = Gtk.SortType.ASCENDING
|
||||
if self._sort_type != sort_type_gtk:
|
||||
self._sort_type = sort_type_gtk
|
||||
self._library_grid_model.set_sort_column_id(2, sort_type)
|
||||
sort_type_gtk = Gtk.SortType.DESCENDING if sort_type else Gtk.SortType.ASCENDING
|
||||
|
||||
if sort_type_gtk != self._sort_type:
|
||||
self._sort_type = sort_type_gtk
|
||||
self.toolbar_sort_order_button.set_active(sort_type)
|
||||
self._sort_grid_model()
|
||||
|
||||
|
||||
def get_sort_type(self):
|
||||
|
|
@ -456,42 +316,27 @@ class LibraryPanel(Gtk.Stack):
|
|||
GObject.idle_add(self._show_image)
|
||||
|
||||
|
||||
def compare_albums(self, model, row1, row2, criterion):
|
||||
id1 = model.get_value(row1, 2)
|
||||
id2 = model.get_value(row2, 2)
|
||||
def _sort_grid_model(self):
|
||||
GObject.idle_add(self._library_grid_model.sort, self._grid_model_compare_func, self._sort_order, self._sort_type)
|
||||
|
||||
if not id1 or not id2:
|
||||
return
|
||||
return client.MCGAlbum.compare(self._albums[id1], self._albums[id2], criterion)
|
||||
|
||||
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 _change_sort(self, sort):
|
||||
self._sort_order = sort
|
||||
self._library_grid_model.set_sort_func(2, self.compare_albums, sort)
|
||||
self.emit('sort-order-changed', sort)
|
||||
|
||||
|
||||
def _set_albums(self, host, albums, size):
|
||||
if not self._is_selected and albums != self._albums:
|
||||
GObject.idle_add(
|
||||
self.get_parent().child_set_property,
|
||||
self,
|
||||
'needs-attention',
|
||||
True
|
||||
)
|
||||
self._library_lock.acquire()
|
||||
self._library_stop.clear()
|
||||
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_visible_child, self.progress_box)
|
||||
GObject.idle_add(self.progress_bar.set_fraction, 0.0)
|
||||
GObject.idle_add(self.library_grid.set_item_padding, size / 100)
|
||||
self.library_grid.set_model(None)
|
||||
self.library_grid.freeze_child_notify()
|
||||
self._library_grid_model.clear()
|
||||
GObject.idle_add(self.stack.set_transition_type, stack_transition_type)
|
||||
GObject.idle_add(self._library_grid_model.remove_all)
|
||||
|
||||
i = 0
|
||||
n = len(albums)
|
||||
|
|
@ -506,38 +351,27 @@ class LibraryPanel(Gtk.Stack):
|
|||
# Exception is handled by client
|
||||
pass
|
||||
except Exception as e:
|
||||
self._logger.exception("Failed to load albumart")
|
||||
self._logger.exception("Failed to load albumart", e)
|
||||
if pixbuf is None:
|
||||
pixbuf = self._icon_theme.load_icon(
|
||||
pixbuf = self._icon_theme.lookup_icon(
|
||||
Utils.STOCK_ICON_DEFAULT,
|
||||
None,
|
||||
self._item_size,
|
||||
Gtk.IconLookupFlags.FORCE_SVG & Gtk.IconLookupFlags.FORCE_SIZE
|
||||
self._item_size,
|
||||
Gtk.TextDirection.LTR,
|
||||
Gtk.IconLookupFlags.FORCE_SYMBOLIC
|
||||
)
|
||||
if pixbuf is not None:
|
||||
self._grid_pixbufs[album.get_id()] = pixbuf
|
||||
self._library_grid_model.append([
|
||||
pixbuf,
|
||||
GObject.markup_escape_text("\n".join([
|
||||
album.get_title(),
|
||||
', '.join(album.get_dates()),
|
||||
Utils.create_artists_label(album),
|
||||
Utils.create_length_label(album)
|
||||
])),
|
||||
album_id
|
||||
])
|
||||
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"))
|
||||
if self._library_stop.is_set():
|
||||
self._library_lock.release()
|
||||
return
|
||||
|
||||
self.library_grid.set_model(self._library_grid_filter)
|
||||
self.library_grid.thaw_child_notify()
|
||||
self.library_grid.set_item_width(-1)
|
||||
self._library_lock.release()
|
||||
self.stack.set_visible_child(self.scroll)
|
||||
GObject.idle_add(self.stack.set_visible_child, self.scroll)
|
||||
self._sort_grid_model()
|
||||
|
||||
|
||||
def _set_widget_grid_size(self, grid_widget, size, vertical):
|
||||
|
|
@ -548,50 +382,31 @@ class LibraryPanel(Gtk.Stack):
|
|||
def _set_widget_grid_size_thread(self, grid_widget, size, vertical):
|
||||
self._library_lock.acquire()
|
||||
self._library_stop.clear()
|
||||
grid_filter = grid_widget.get_model()
|
||||
grid_model = grid_filter.get_model()
|
||||
|
||||
# get old_range
|
||||
grid_widget_id = id(grid_widget)
|
||||
if grid_widget_id not in self._old_ranges or self._old_ranges[grid_widget_id] is None:
|
||||
self._old_ranges[grid_widget_id] = range(0, len(grid_filter))
|
||||
old_range = self._old_ranges[grid_widget_id]
|
||||
old_start = len(old_range) > 0 and old_range[0] or 0
|
||||
old_end = len(old_range) > 0 and old_range[len(old_range)-1] + 1 or 0
|
||||
|
||||
# calculate visible range
|
||||
w = (grid_widget.get_allocation().width // size) + (vertical and 0 or 1)
|
||||
h = (grid_widget.get_allocation().height // size) + (vertical and 1 or 0)
|
||||
c = w * h
|
||||
vis_range = grid_widget.get_visible_range()
|
||||
if vis_range is None:
|
||||
if size == self._item_size:
|
||||
self._library_lock.release()
|
||||
return
|
||||
(vis_start,), (vis_end,) = vis_range
|
||||
vis_end = min(vis_start + c, len(grid_filter))
|
||||
vis_range = range(vis_start, vis_end)
|
||||
|
||||
# set pixbuf
|
||||
cur_start = min(old_start, vis_start)
|
||||
cur_end = max(old_end, vis_end)
|
||||
cur_range = range(cur_start, cur_end)
|
||||
for index in cur_range:
|
||||
iter = grid_filter.convert_iter_to_child_iter(grid_filter[index].iter)
|
||||
if index in vis_range:
|
||||
album_id = grid_model.get_value(iter, 2)
|
||||
pixbuf = self._grid_pixbufs[album_id]
|
||||
for i in range(self._library_grid_model.get_n_items()):
|
||||
grid_item = self._library_grid_model.get_item(i)
|
||||
album_id = grid_item.get_album().get_id()
|
||||
|
||||
pixbuf = self._grid_pixbufs[album_id]
|
||||
if pixbuf is not None:
|
||||
pixbuf = pixbuf.scale_simple(size, size, GdkPixbuf.InterpType.NEAREST)
|
||||
else:
|
||||
pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, False, 8, 1, 1)
|
||||
grid_model.set_value(iter, 0, pixbuf)
|
||||
pixbuf = self._icon_theme.lookup_icon(
|
||||
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():
|
||||
self._library_lock.release()
|
||||
return
|
||||
|
||||
self._old_ranges[grid_widget_id] = vis_range
|
||||
grid_widget.set_item_width(size)
|
||||
|
||||
self._library_lock.release()
|
||||
|
||||
|
||||
|
|
@ -606,13 +421,34 @@ class LibraryPanel(Gtk.Stack):
|
|||
self.set_albums(self._host, self._albums)
|
||||
|
||||
|
||||
def _set_marks(self):
|
||||
width = self.scroll.get_width()
|
||||
if width == self._grid_width:
|
||||
return
|
||||
self._grid_width = width
|
||||
self.grid_scale.clear_marks()
|
||||
|
||||
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):
|
||||
pixel = int(width / index)
|
||||
pixel = pixel - (2 * int(pixel / 100))
|
||||
self.grid_scale.add_mark(
|
||||
pixel,
|
||||
Gtk.PositionType.BOTTOM,
|
||||
None
|
||||
)
|
||||
|
||||
|
||||
def _open_standalone(self):
|
||||
self.set_visible_child(self.panel_standalone)
|
||||
self.library_stack.set_visible_child(self.panel_standalone)
|
||||
self.emit('open-standalone')
|
||||
|
||||
|
||||
def _close_standalone(self):
|
||||
self.set_visible_child(self.get_children()[0])
|
||||
self.library_stack.set_visible_child(self.panel_normal)
|
||||
self.emit('close-standalone')
|
||||
|
||||
|
||||
|
|
@ -620,15 +456,19 @@ class LibraryPanel(Gtk.Stack):
|
|||
"""Diese Methode skaliert das geladene Bild aus dem Pixelpuffer
|
||||
auf die Größe des Fensters unter Beibehalt der Seitenverhältnisse
|
||||
"""
|
||||
# Get size
|
||||
size_width = self.standalone_stack.get_width()
|
||||
size_height = self.standalone_stack.get_height()
|
||||
|
||||
# Get pixelbuffer
|
||||
pixbuf = self._standalone_pixbuf
|
||||
size = self.standalone_scroll.get_allocation()
|
||||
# Check pixelbuffer
|
||||
if pixbuf is None:
|
||||
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())
|
||||
ratioW = float(size_width) / float(pixbuf.get_width())
|
||||
ratioH = float(size_height) / float(pixbuf.get_height())
|
||||
# Kleineren beider Skalierungswerte nehmen, nicht Hochskalieren
|
||||
ratio = min(ratioW, ratioH)
|
||||
ratio = min(ratio, 1)
|
||||
|
|
@ -638,18 +478,24 @@ class LibraryPanel(Gtk.Stack):
|
|||
if width <= 0 or height <= 0:
|
||||
return
|
||||
# Pixelpuffer auf Oberfläche zeichnen
|
||||
self.standalone_image.set_allocation(self.standalone_scroll.get_allocation())
|
||||
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.load_icon(
|
||||
return self._icon_theme.lookup_icon(
|
||||
Utils.STOCK_ICON_DEFAULT,
|
||||
None,
|
||||
512,
|
||||
Gtk.IconLookupFlags.FORCE_SVG & Gtk.IconLookupFlags.FORCE_SIZE
|
||||
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())
|
||||
return albums
|
||||
|
|
|
|||
Loading…
Reference in a new issue