From 3d63c2226a35fda28f807d646752979e81478cc6 Mon Sep 17 00:00:00 2001 From: RozeFound Date: Fri, 24 Mar 2023 06:02:38 +0700 Subject: [PATCH 01/16] Fix label_no_cover not being used --- bottles/frontend/ui/library-entry.blp | 1 - 1 file changed, 1 deletion(-) diff --git a/bottles/frontend/ui/library-entry.blp b/bottles/frontend/ui/library-entry.blp index f0e210728d..c7fee76fdf 100644 --- a/bottles/frontend/ui/library-entry.blp +++ b/bottles/frontend/ui/library-entry.blp @@ -28,7 +28,6 @@ template LibraryEntry : Box { } Label label_no_cover { - visible: false; halign: center; valign: center; hexpand: true; From cfaf09a3cfb31ffa77d3cf92b0382554c98a010b Mon Sep 17 00:00:00 2001 From: RozeFound Date: Fri, 24 Mar 2023 06:02:58 +0700 Subject: [PATCH 02/16] Center grid items in library --- bottles/frontend/ui/library.blp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bottles/frontend/ui/library.blp b/bottles/frontend/ui/library.blp index f1ceac6f3c..9d7081db19 100644 --- a/bottles/frontend/ui/library.blp +++ b/bottles/frontend/ui/library.blp @@ -19,8 +19,8 @@ template LibraryView : .AdwBin { FlowBox main_flow { row-spacing: 5; column-spacing: 5; - halign: start; - valign: start; + halign: center; + valign: center; margin-top: 5; margin-start: 5; margin-bottom: 5; From f90e0d95bfbc975ba69e51576433c382a90dbf03 Mon Sep 17 00:00:00 2001 From: RozeFound Date: Sat, 25 Mar 2023 03:37:24 +0700 Subject: [PATCH 03/16] Properly center view --- bottles/frontend/ui/library-entry.blp | 2 -- bottles/frontend/ui/library.blp | 3 ++- bottles/frontend/views/library.py | 5 ++++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bottles/frontend/ui/library-entry.blp b/bottles/frontend/ui/library-entry.blp index c7fee76fdf..5d3e5df521 100644 --- a/bottles/frontend/ui/library-entry.blp +++ b/bottles/frontend/ui/library-entry.blp @@ -2,8 +2,6 @@ using Gtk 4.0; template LibraryEntry : Box { orientation: vertical; - halign: start; - valign: start; width-request: 128; height-request: 348; overflow: hidden; diff --git a/bottles/frontend/ui/library.blp b/bottles/frontend/ui/library.blp index 9d7081db19..c444e0cd6a 100644 --- a/bottles/frontend/ui/library.blp +++ b/bottles/frontend/ui/library.blp @@ -17,10 +17,11 @@ template LibraryView : .AdwBin { vexpand: true; FlowBox main_flow { + max-children-per-line: bind LibraryView.items_per_line; row-spacing: 5; column-spacing: 5; halign: center; - valign: center; + valign: start; margin-top: 5; margin-start: 5; margin-bottom: 5; diff --git a/bottles/frontend/views/library.py b/bottles/frontend/views/library.py index a94d5eff3b..eb66893706 100644 --- a/bottles/frontend/views/library.py +++ b/bottles/frontend/views/library.py @@ -19,7 +19,7 @@ import re from gettext import gettext as _ -from gi.repository import Gtk, Adw +from gi.repository import Gtk, Adw, GObject from bottles.backend.managers.library import LibraryManager from bottles.frontend.utils.gtk import GtkUtils @@ -36,6 +36,8 @@ class LibraryView(Adw.Bin): status_page = Gtk.Template.Child() style_provider = Gtk.CssProvider() + items_per_line = GObject.property(type=int, default=0) + # endregion def __init__(self, window, **kwargs): @@ -59,6 +61,7 @@ def update(self): with contextlib.suppress(Exception): entry = LibraryEntry(self, u, e) self.main_flow.append(entry) + self.items_per_line += 1 def remove_entry(self, entry): @GtkUtils.run_in_main_loop From b1bc424e0ebb15c3b350c82c9a2a941d1ee49e6a Mon Sep 17 00:00:00 2001 From: RozeFound Date: Sat, 25 Mar 2023 03:39:45 +0700 Subject: [PATCH 04/16] move comment --- bottles/frontend/views/library.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bottles/frontend/views/library.py b/bottles/frontend/views/library.py index eb66893706..30e7be541e 100644 --- a/bottles/frontend/views/library.py +++ b/bottles/frontend/views/library.py @@ -35,11 +35,10 @@ class LibraryView(Adw.Bin): main_flow = Gtk.Template.Child() status_page = Gtk.Template.Child() style_provider = Gtk.CssProvider() + # endregion items_per_line = GObject.property(type=int, default=0) - # endregion - def __init__(self, window, **kwargs): super().__init__(**kwargs) self.window = window From d834280a918c207d46c49065ec51e0078698efe4 Mon Sep 17 00:00:00 2001 From: RozeFound Date: Sat, 25 Mar 2023 04:58:38 +0700 Subject: [PATCH 05/16] Fix items_per_line not updating --- bottles/frontend/views/library.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bottles/frontend/views/library.py b/bottles/frontend/views/library.py index 30e7be541e..dab07fb558 100644 --- a/bottles/frontend/views/library.py +++ b/bottles/frontend/views/library.py @@ -55,12 +55,13 @@ def update(self): self.status_page.set_visible(len(entries) == 0) self.scroll_window.set_visible(not len(entries) == 0) + self.items_per_line = len(entries) + for u, e in entries.items(): # We suppress exceptions so that it doesn't continue if the init fails with contextlib.suppress(Exception): entry = LibraryEntry(self, u, e) self.main_flow.append(entry) - self.items_per_line += 1 def remove_entry(self, entry): @GtkUtils.run_in_main_loop From f4875c31c7014dd50aad9253c8506adee7aa32d8 Mon Sep 17 00:00:00 2001 From: RozeFound Date: Sat, 25 Mar 2023 09:13:13 +0700 Subject: [PATCH 06/16] Adapt view on entry removal --- bottles/frontend/views/library.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bottles/frontend/views/library.py b/bottles/frontend/views/library.py index dab07fb558..5f05f49552 100644 --- a/bottles/frontend/views/library.py +++ b/bottles/frontend/views/library.py @@ -55,7 +55,7 @@ def update(self): self.status_page.set_visible(len(entries) == 0) self.scroll_window.set_visible(not len(entries) == 0) - self.items_per_line = len(entries) + self.items_per_line = len(entries) for u, e in entries.items(): # We suppress exceptions so that it doesn't continue if the init fails @@ -66,6 +66,7 @@ def update(self): def remove_entry(self, entry): @GtkUtils.run_in_main_loop def undo_callback(*args): + self.items_per_line += 1 entry.show() @GtkUtils.run_in_main_loop @@ -73,6 +74,7 @@ def dismissed_callback(*args): self.__delete_entry(entry) entry.hide() + self.items_per_line -= 1 self.window.show_toast( message=_("\"{0}\" removed from the library.").format(entry.name), timeout=5, From 88d4742b0dd37fad2b1c964638a60ecd73e4ef76 Mon Sep 17 00:00:00 2001 From: RozeFound Date: Fri, 26 May 2023 08:26:54 +0700 Subject: [PATCH 07/16] Fix window not remembering size on Ctrl+Q --- bottles/frontend/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bottles/frontend/main.py b/bottles/frontend/main.py index 9478e4b7f3..4b6618aaee 100644 --- a/bottles/frontend/main.py +++ b/bottles/frontend/main.py @@ -242,6 +242,7 @@ def __quit(action=None, param=None): It is used by the [Ctrl+Q] shortcut. """ logging.info(_("[Quit] request received."), ) + MainWindow.on_close_request() quit() @staticmethod From 7f80a1871fe4b2bb9cae2bd55f272cf96757bebf Mon Sep 17 00:00:00 2001 From: RozeFound Date: Fri, 26 May 2023 08:30:03 +0700 Subject: [PATCH 08/16] Gtk.Picture.set_pixbuf deprecation --- bottles/frontend/widgets/library.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bottles/frontend/widgets/library.py b/bottles/frontend/widgets/library.py index 8963088629..637084be1e 100644 --- a/bottles/frontend/widgets/library.py +++ b/bottles/frontend/widgets/library.py @@ -17,7 +17,7 @@ from gettext import gettext as _ -from gi.repository import Gtk, GdkPixbuf +from gi.repository import Gtk from bottles.backend.logger import Logger from bottles.backend.managers.library import LibraryManager @@ -89,8 +89,8 @@ def __init__(self, library, uuid, entry, *args, **kwargs): path = ThumbnailManager.get_path(self.config, entry['thumbnail']) if path is not None: - pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(path, 240, 360) - self.img_cover.set_pixbuf(pixbuf) + # Gtk.Picture.set_pixbuf deprecated in GTK 4.12 + self.img_cover.set_filename(path) self.img_cover.set_visible(True) self.label_no_cover.set_visible(False) From 2007a090ff271b7b8666c89f6d36d84d1db98123 Mon Sep 17 00:00:00 2001 From: RozeFound Date: Fri, 26 May 2023 08:30:38 +0700 Subject: [PATCH 09/16] Remove unused import --- bottles/frontend/views/library.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bottles/frontend/views/library.py b/bottles/frontend/views/library.py index 5f05f49552..9f96eadc48 100644 --- a/bottles/frontend/views/library.py +++ b/bottles/frontend/views/library.py @@ -16,7 +16,6 @@ # import contextlib -import re from gettext import gettext as _ from gi.repository import Gtk, Adw, GObject From 50bc2a67b459a3c948a40fc0824104c0b4199277 Mon Sep 17 00:00:00 2001 From: RozeFound Date: Fri, 26 May 2023 08:34:12 +0700 Subject: [PATCH 10/16] Set full application name for "No cover" placeholder --- bottles/frontend/widgets/library.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bottles/frontend/widgets/library.py b/bottles/frontend/widgets/library.py index 637084be1e..56372b3877 100644 --- a/bottles/frontend/widgets/library.py +++ b/bottles/frontend/widgets/library.py @@ -75,6 +75,7 @@ def __init__(self, library, uuid, entry, *args, **kwargs): self.label_name.set_text(name) self.label_bottle.set_text(entry['bottle']['name']) + self.label_no_cover.set_label(self.name) if entry.get('thumbnail'): path = ThumbnailManager.get_path(self.config, entry['thumbnail']) From 84e56d44956f23aab1453513be984ffde471916c Mon Sep 17 00:00:00 2001 From: RozeFound Date: Fri, 26 May 2023 09:51:50 +0700 Subject: [PATCH 11/16] Wrap full name in "no cover" --- bottles/frontend/ui/library-entry.blp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bottles/frontend/ui/library-entry.blp b/bottles/frontend/ui/library-entry.blp index 5d3e5df521..47fa971bc7 100644 --- a/bottles/frontend/ui/library-entry.blp +++ b/bottles/frontend/ui/library-entry.blp @@ -32,6 +32,9 @@ template LibraryEntry : Box { vexpand: true; label: _("No Thumbnail"); + wrap: true; + wrap-mode: word_char; + styles [ "dim-label", ] From 15d7a26c4bb8fe196ceb413940e9734317f0e8f4 Mon Sep 17 00:00:00 2001 From: RozeFound Date: Sat, 27 May 2023 14:22:09 +0700 Subject: [PATCH 12/16] Load cover asynchronimously --- bottles/frontend/widgets/library.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/bottles/frontend/widgets/library.py b/bottles/frontend/widgets/library.py index 56372b3877..84ab0a1a21 100644 --- a/bottles/frontend/widgets/library.py +++ b/bottles/frontend/widgets/library.py @@ -89,12 +89,8 @@ def __init__(self, library, uuid, entry, *args, **kwargs): entry = library_manager.get_library().get(uuid) path = ThumbnailManager.get_path(self.config, entry['thumbnail']) - if path is not None: - # Gtk.Picture.set_pixbuf deprecated in GTK 4.12 - self.img_cover.set_filename(path) - self.img_cover.set_visible(True) - self.label_no_cover.set_visible(False) - + if path is not None: self.load_cover(path) + motion_ctrl = Gtk.EventControllerMotion.new() motion_ctrl.connect("enter", self.__on_motion_enter) motion_ctrl.connect("leave", self.__on_motion_leave) @@ -104,6 +100,13 @@ def __init__(self, library, uuid, entry, *args, **kwargs): self.btn_stop.connect("clicked", self.stop_process) self.btn_remove.connect("clicked", self.__remove_entry) + @RunAsync.run_async + def load_cover(self, path): + # Gtk.Picture.set_pixbuf deprecated in GTK 4.12 + self.img_cover.set_filename(path) + self.img_cover.set_visible(True) + self.label_no_cover.set_visible(False) + def __get_config(self): bottles = self.manager.local_bottles if self.entry['bottle']['name'] in bottles: From 9306528059dd6c112171dcb7733bd3041cfda0f5 Mon Sep 17 00:00:00 2001 From: RozeFound Date: Thu, 1 Jun 2023 00:13:56 +0700 Subject: [PATCH 13/16] Use Gdk.Texture --- bottles/frontend/widgets/library.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bottles/frontend/widgets/library.py b/bottles/frontend/widgets/library.py index 84ab0a1a21..c0474fceb3 100644 --- a/bottles/frontend/widgets/library.py +++ b/bottles/frontend/widgets/library.py @@ -17,7 +17,7 @@ from gettext import gettext as _ -from gi.repository import Gtk +from gi.repository import Gtk, Gdk from bottles.backend.logger import Logger from bottles.backend.managers.library import LibraryManager @@ -103,7 +103,8 @@ def __init__(self, library, uuid, entry, *args, **kwargs): @RunAsync.run_async def load_cover(self, path): # Gtk.Picture.set_pixbuf deprecated in GTK 4.12 - self.img_cover.set_filename(path) + texture = Gdk.Texture.new_from_filename(path) + self.img_cover.set_paintable(texture) self.img_cover.set_visible(True) self.label_no_cover.set_visible(False) From 389bfdaf64951ae69f91f9235c5f47ccacb90be2 Mon Sep 17 00:00:00 2001 From: RozeFound Date: Wed, 7 Jun 2023 20:31:49 +0700 Subject: [PATCH 14/16] GTK is not thread-safe --- bottles/frontend/widgets/library.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/bottles/frontend/widgets/library.py b/bottles/frontend/widgets/library.py index c0474fceb3..71239af7ea 100644 --- a/bottles/frontend/widgets/library.py +++ b/bottles/frontend/widgets/library.py @@ -89,7 +89,12 @@ def __init__(self, library, uuid, entry, *args, **kwargs): entry = library_manager.get_library().get(uuid) path = ThumbnailManager.get_path(self.config, entry['thumbnail']) - if path is not None: self.load_cover(path) + if path is not None: + # Gtk.Picture.set_pixbuf deprecated in GTK 4.12 + texture = Gdk.Texture.new_from_filename(path) + self.img_cover.set_paintable(texture) + self.img_cover.set_visible(True) + self.label_no_cover.set_visible(False) motion_ctrl = Gtk.EventControllerMotion.new() motion_ctrl.connect("enter", self.__on_motion_enter) @@ -100,14 +105,6 @@ def __init__(self, library, uuid, entry, *args, **kwargs): self.btn_stop.connect("clicked", self.stop_process) self.btn_remove.connect("clicked", self.__remove_entry) - @RunAsync.run_async - def load_cover(self, path): - # Gtk.Picture.set_pixbuf deprecated in GTK 4.12 - texture = Gdk.Texture.new_from_filename(path) - self.img_cover.set_paintable(texture) - self.img_cover.set_visible(True) - self.label_no_cover.set_visible(False) - def __get_config(self): bottles = self.manager.local_bottles if self.entry['bottle']['name'] in bottles: From 24efddf14a91cd18587f11fc4065f5ba02e109e6 Mon Sep 17 00:00:00 2001 From: RozeFound Date: Wed, 7 Jun 2023 20:45:39 +0700 Subject: [PATCH 15/16] __quit is no longer staticmethod --- bottles/frontend/main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bottles/frontend/main.py b/bottles/frontend/main.py index 4b6618aaee..2b653a2f0d 100644 --- a/bottles/frontend/main.py +++ b/bottles/frontend/main.py @@ -235,14 +235,13 @@ def do_activate(self): self.win = win win.present() - @staticmethod - def __quit(action=None, param=None): + def __quit(self, *args): """ This function close the application. It is used by the [Ctrl+Q] shortcut. """ logging.info(_("[Quit] request received."), ) - MainWindow.on_close_request() + self.win.on_close_request() quit() @staticmethod From 21e9889524710dd5707fc848c8144dc3d9a8f19e Mon Sep 17 00:00:00 2001 From: RozeFound Date: Wed, 7 Jun 2023 20:46:58 +0700 Subject: [PATCH 16/16] Remove whitespace --- bottles/frontend/widgets/library.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bottles/frontend/widgets/library.py b/bottles/frontend/widgets/library.py index 71239af7ea..0ddbe01ffa 100644 --- a/bottles/frontend/widgets/library.py +++ b/bottles/frontend/widgets/library.py @@ -95,7 +95,7 @@ def __init__(self, library, uuid, entry, *args, **kwargs): self.img_cover.set_paintable(texture) self.img_cover.set_visible(True) self.label_no_cover.set_visible(False) - + motion_ctrl = Gtk.EventControllerMotion.new() motion_ctrl.connect("enter", self.__on_motion_enter) motion_ctrl.connect("leave", self.__on_motion_leave)