diff --git a/data/ui/library-panel.ui b/data/ui/library-panel.ui index 1985edb..c459cd0 100644 --- a/data/ui/library-panel.ui +++ b/data/ui/library-panel.ui @@ -150,10 +150,6 @@ - search library diff --git a/src/librarypanel.py b/src/librarypanel.py index 4f9ebc8..70efc8c 100644 --- a/src/librarypanel.py +++ b/src/librarypanel.py @@ -85,13 +85,13 @@ class LibraryPanel(Adw.Bin): 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_for_display(Gdk.Display.get_default()) self._standalone_pixbuf = None self._selected_albums = [] - self._grid_width = 0 self._is_selected = False # Widgets @@ -190,28 +190,8 @@ class LibraryPanel(Adw.Bin): def set_size(self, width, height): - 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 on_toolbar_update(self, widget): - self.emit('update') + self._set_marks() + self._resize_standalone_image() @Gtk.Template.Callback() @@ -341,7 +321,7 @@ class LibraryPanel(Adw.Bin): def _sort_grid_model(self): - 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): @@ -403,7 +383,7 @@ class LibraryPanel(Adw.Bin): GObject.idle_add(self.progress_bar.set_text, locale.gettext("Loading images")) 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() @@ -454,6 +434,27 @@ class LibraryPanel(Adw.Bin): 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.library_stack.set_visible_child(self.panel_standalone) self.emit('open-standalone') @@ -468,15 +469,19 @@ class LibraryPanel(Adw.Bin): """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) diff --git a/src/playlistpanel.py b/src/playlistpanel.py index 569fde0..f9f77ce 100644 --- a/src/playlistpanel.py +++ b/src/playlistpanel.py @@ -159,6 +159,10 @@ class PlaylistPanel(Adw.Bin): self._close_standalone() + def set_size(self, width, height): + self._resize_standalone_image() + + def set_item_size(self, item_size): if self._item_size != item_size: self._item_size = item_size @@ -268,15 +272,19 @@ class PlaylistPanel(Adw.Bin): """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) diff --git a/src/window.py b/src/window.py index 4d83b39..430bcb7 100644 --- a/src/window.py +++ b/src/window.py @@ -254,6 +254,7 @@ class Window(Adw.ApplicationWindow): if not self._state.get_property(WindowState.IS_MAXIMIZED): self._state.set_property(WindowState.WIDTH, width) self._state.set_property(WindowState.HEIGHT, height) + GObject.idle_add(self._playlist_panel.set_size, width, height) GObject.idle_add(self._library_panel.set_size, width, height)