From d49098dbcaf15f37a89c3e8c4811af6c743381c1 Mon Sep 17 00:00:00 2001 From: Michael Stevenson Date: Sun, 27 Nov 2022 09:49:46 -0800 Subject: [PATCH 1/4] Show image index in the title --- scripts/image_caption_gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/image_caption_gui.py b/scripts/image_caption_gui.py index b664716..153a711 100644 --- a/scripts/image_caption_gui.py +++ b/scripts/image_caption_gui.py @@ -116,7 +116,7 @@ class ImageView(tk.Frame): img = self.images[self.index] # filename title = self.images[self.index].path.name if len(self.images) > 0 else '' - self.root.title(title) + self.root.title(title + f' ({self.index+1}/{len(self.images)})') # caption self.caption_field.delete(1.0, tk.END) self.caption_field.insert(tk.END, img.read_caption()) From da90d86bbd191ceae354620d89d0cd5b9b2d8570 Mon Sep 17 00:00:00 2001 From: Michael Stevenson Date: Sun, 27 Nov 2022 09:50:03 -0800 Subject: [PATCH 2/4] Case insensitive filename sorting --- scripts/image_caption_gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/image_caption_gui.py b/scripts/image_caption_gui.py index 153a711..aeacc1f 100644 --- a/scripts/image_caption_gui.py +++ b/scripts/image_caption_gui.py @@ -35,7 +35,7 @@ class CaptionedImage(): # sort def __lt__(self, other): - return self.path < other.path + return str(self.path).lower() < str(other.path).lower() class ImageView(tk.Frame): From ba7e2a5328e1e19eed3e78097bf85acd43d36094 Mon Sep 17 00:00:00 2001 From: Michael Stevenson Date: Mon, 28 Nov 2022 09:33:39 -0800 Subject: [PATCH 3/4] Handle open dialog canceled --- scripts/image_caption_gui.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/image_caption_gui.py b/scripts/image_caption_gui.py index aeacc1f..8ed7334 100644 --- a/scripts/image_caption_gui.py +++ b/scripts/image_caption_gui.py @@ -60,7 +60,10 @@ class ImageView(tk.Frame): self.caption_frame.pack(fill=tk.Y, side=tk.RIGHT) def open_folder(self): - self.base_path = Path(filedialog.askdirectory()) + dir = filedialog.askdirectory() + if not dir: + return + self.base_path = Path(dir) if self.base_path is None: return self.images.clear() From 53809e3b3ff5e5012d4797634f913d6dddc74d24 Mon Sep 17 00:00:00 2001 From: Michael Stevenson Date: Mon, 28 Nov 2022 09:37:08 -0800 Subject: [PATCH 4/4] Fix index out of range when deleting the final image --- scripts/image_caption_gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/image_caption_gui.py b/scripts/image_caption_gui.py index 8ed7334..f416610 100644 --- a/scripts/image_caption_gui.py +++ b/scripts/image_caption_gui.py @@ -106,8 +106,8 @@ class ImageView(tk.Frame): caption_path = img.caption_path() if caption_path.exists(): caption_path.rename(trash_path / caption_path.name) - del self.images[self.index] + self.set_index(self.index) self.update_ui() def update_ui(self):