diff --git a/dist/renamer-0.4.4-py3-none-any.whl b/dist/renamer-0.4.4-py3-none-any.whl new file mode 100644 index 0000000..f53d627 Binary files /dev/null and b/dist/renamer-0.4.4-py3-none-any.whl differ diff --git a/pyproject.toml b/pyproject.toml index 550ae2b..313b4e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "renamer" -version = "0.4.3" +version = "0.4.4" description = "Terminal-based media file renamer and metadata viewer" readme = "README.md" requires-python = ">=3.11" diff --git a/renamer/app.py b/renamer/app.py index 85601eb..7793119 100644 --- a/renamer/app.py +++ b/renamer/app.py @@ -71,6 +71,7 @@ class RenamerApp(App): self.scan_files() def scan_files(self): + logging.info("scan_files called") if not self.scan_dir or not self.scan_dir.exists() or not self.scan_dir.is_dir(): details = self.query_one("#details", Static) details.update("Error: Directory does not exist or is not a directory") @@ -213,8 +214,12 @@ class RenamerApp(App): def update_renamed_file(self, old_path: Path, new_path: Path): """Update the tree node for a renamed file.""" - tree = self.query_one("#file_tree", Tree) + logging.info(f"update_renamed_file called with old_path={old_path}, new_path={new_path}") + tree = self.query_one("#file_tree", Tree) + logging.info(f"Before update: cursor_node.data = {tree.cursor_node.data if tree.cursor_node else None}") + + # Update only the specific node def find_node(node): if node.data == old_path: return node @@ -226,14 +231,27 @@ class RenamerApp(App): node = find_node(tree.root) if node: + logging.info(f"Found node for {old_path}, updating to {new_path.name}") node.label = escape(new_path.name) node.data = new_path - # If this node is currently selected, refresh the details - if tree.cursor_node == node: - self._start_loading_animation() - threading.Thread( - target=self._extract_and_show_details, args=(new_path,) - ).start() + logging.info(f"After update: node.data = {node.data}, node.label = {node.label}") + # Ensure cursor stays on the renamed file + tree.select_node(node) + logging.info(f"Selected node: {tree.cursor_node.data if tree.cursor_node else None}") + else: + logging.info(f"No node found for {old_path}") + + logging.info(f"After update: cursor_node.data = {tree.cursor_node.data if tree.cursor_node else None}") + + # Refresh the details if the node is currently selected + if tree.cursor_node and tree.cursor_node.data == new_path: + logging.info("Refreshing details for renamed file") + self._start_loading_animation() + threading.Thread( + target=self._extract_and_show_details, args=(new_path,) + ).start() + else: + logging.info("Not refreshing details, cursor not on renamed file") def on_key(self, event): if event.key == "right": diff --git a/renamer/screens.py b/renamer/screens.py index 277d536..2819fec 100644 --- a/renamer/screens.py +++ b/renamer/screens.py @@ -3,6 +3,7 @@ from textual.widgets import Input, Button, Static from textual.containers import Vertical, Horizontal, Center, Container from textual.markup import escape from pathlib import Path +import logging class OpenScreen(Screen): @@ -128,6 +129,7 @@ class RenameConfirmScreen(Screen): self.old_path = old_path self.new_name = new_name self.new_path = old_path.parent / new_name + self.was_edited = False def compose(self): from .formatters.text_formatter import TextFormatter @@ -165,6 +167,7 @@ Do you want to proceed with renaming? if event.input.id == "new_name_input": self.new_name = event.input.value self.new_path = self.old_path.parent / self.new_name + self.was_edited = True # Update the display from .formatters.text_formatter import TextFormatter display = self.query_one("#new_name_display", Static) @@ -173,6 +176,7 @@ Do you want to proceed with renaming? def on_button_pressed(self, event): if event.button.id == "rename": try: + logging.info(f"Renaming {self.old_path} to {self.new_path}") self.old_path.rename(self.new_path) # Update the tree node self.app.update_renamed_file(self.old_path, self.new_path) # type: ignore @@ -222,6 +226,7 @@ Do you want to proceed with renaming? if event.key == "y": # Trigger rename try: + logging.info(f"Hotkey renaming {self.old_path} to {self.new_path}") self.old_path.rename(self.new_path) # Update the tree node self.app.update_renamed_file(self.old_path, self.new_path) # type: ignore diff --git a/renamer/test/filenames/[02] Balto Wolf Quest (2002) [1080i,ukr,eng].mkv b/renamer/test/filenames/The Adventures of Jimmy Neutron. Boy Genius (2002) [480p,ukr,eng].mkv similarity index 100% rename from renamer/test/filenames/[02] Balto Wolf Quest (2002) [1080i,ukr,eng].mkv rename to renamer/test/filenames/The Adventures of Jimmy Neutron. Boy Genius (2002) [480p,ukr,eng].mkv diff --git a/renamer/test/filenames/The Adventures of Jimmy Neutron: Boy Genius (2002).[480p,ukr,eng].mkv b/renamer/test/filenames/The Adventures of Jimmy Neutron: Boy Genius (2002).[480p,ukr,eng].mkv new file mode 100644 index 0000000..e69de29 diff --git a/renamer/test/filenames/[02] Balto: Wolf Quest (2002) [1080i,ukr,eng] [tmdbid-25913].mkv b/renamer/test/filenames/[02] Balto: Wolf Quest (2002) [1080i,ukr,eng] [tmdbid-25913].mkv new file mode 100644 index 0000000..e69de29 diff --git a/renamer/test/filenames/wJimmy Neutron: Boy Genius (2001) [480p,ukr,eng] [tmdbid-12589].mkv b/renamer/test/filenames/wJimmy Neutron: Boy Genius (2001) [480p,ukr,eng] [tmdbid-12589].mkv new file mode 100644 index 0000000..e69de29 diff --git a/uv.lock b/uv.lock index 38b49ec..7c0a68e 100644 --- a/uv.lock +++ b/uv.lock @@ -255,7 +255,7 @@ wheels = [ [[package]] name = "renamer" -version = "0.4.3" +version = "0.4.4" source = { editable = "." } dependencies = [ { name = "langcodes" },