Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preview panel + main window fixes and optimizations #700

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tagstudio/src/qt/modals/folders_to_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def __init__(self, library: "Library", driver: "QtDriver"):
def on_apply(self, event):
folders_to_tags(self.library)
self.close()
self.driver.preview_panel.update_widgets()
self.driver.preview_panel.update_widgets(update_preview=False)

def on_open(self, event):
for i in reversed(range(self.scroll_layout.count())):
Expand Down
17 changes: 13 additions & 4 deletions tagstudio/src/qt/ts_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def create_dupe_files_modal():
self.autofill_action.triggered.connect(
lambda: (
self.run_macros(MacroID.AUTOFILL, self.selected),
self.preview_panel.update_widgets(),
self.preview_panel.update_widgets(update_preview=False),
)
)
macros_menu.addAction(self.autofill_action)
Expand Down Expand Up @@ -626,7 +626,6 @@ def init_library_window(self):
self.main_window.pagination.index.connect(lambda i: self.page_move(page_id=i))

self.splash.finish(self.main_window)
self.preview_panel.update_widgets()

def show_grid_filenames(self, value: bool):
for thumb in self.item_thumbs:
Expand Down Expand Up @@ -666,6 +665,13 @@ def close_library(self, is_shutdown: bool = False):
self.settings.setValue(SettingItems.LAST_LIBRARY, str(self.lib.library_dir))
self.settings.sync()

# Reset library state
self.preview_panel.update_widgets()
self.main_window.searchField.setText("")
scrollbar: QScrollArea = self.main_window.scrollArea
scrollbar.verticalScrollBar().setValue(0)
self.filter = FilterState.show_all()

self.lib.close()

self.thumb_job_queue.queue.clear()
Expand Down Expand Up @@ -736,7 +742,7 @@ def select_all_action_callback(self):
item.thumb_button.set_selected(True)

self.set_macro_menu_viability()
self.preview_panel.update_widgets()
self.preview_panel.update_widgets(update_preview=False)

def clear_select_action_callback(self):
self.selected.clear()
Expand All @@ -749,7 +755,7 @@ def clear_select_action_callback(self):
def show_tag_database(self):
self.modal = PanelModal(
widget=TagDatabasePanel(self.lib),
done_callback=self.preview_panel.update_widgets,
done_callback=lambda: self.preview_panel.update_widgets(update_preview=False),
has_save=False,
)
Translations.translate_with_setter(self.modal.setTitle, "tag_manager.title")
Expand Down Expand Up @@ -1409,6 +1415,9 @@ def open_library(self, path: Path) -> None:
)
self.main_window.repaint()

if self.lib.library_dir:
self.close_library()

open_status: LibraryStatus = None
try:
open_status = self.lib.open_library(path)
Expand Down
2 changes: 1 addition & 1 deletion tagstudio/src/qt/widgets/item_thumb.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def toggle_item_tag(
self.lib.remove_tags_from_entry(entry_id, tag_id)

if self.driver.preview_panel.is_open:
self.driver.preview_panel.update_widgets()
self.driver.preview_panel.update_widgets(update_preview=False)

def mouseMoveEvent(self, event): # noqa: N802
if event.buttons() is not Qt.MouseButton.LeftButton:
Expand Down
14 changes: 10 additions & 4 deletions tagstudio/src/qt/widgets/preview_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,13 @@ def __init__(self, library: Library, driver: "QtDriver"):
root_layout.addWidget(splitter)
root_layout.addWidget(add_buttons_container)

def update_widgets(self) -> bool:
"""Render the panel widgets with the newest data from the Library."""
def update_widgets(self, update_preview: bool = True) -> bool:
"""Render the panel widgets with the newest data from the Library.

Args:
update_preview(bool): Should the file preview be updated?
(Only works with one or more items selected)
"""
# No Items Selected
try:
if len(self.driver.selected) == 0:
Expand All @@ -151,8 +156,9 @@ def update_widgets(self) -> bool:
filepath: Path = self.lib.library_dir / entry.path
ext: str = filepath.suffix.lower()

stats: dict = self.thumb.update_preview(filepath, ext)
self.file_attrs.update_stats(filepath, ext, stats)
if update_preview:
stats: dict = self.thumb.update_preview(filepath, ext)
self.file_attrs.update_stats(filepath, ext, stats)
self.file_attrs.update_date_label(filepath)
self.fields.update_from_entry(entry_id)
self.update_add_tag_button(entry_id)
Expand Down
4 changes: 2 additions & 2 deletions tagstudio/src/qt/widgets/tag_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def set_tags(self, tags: typing.Iterable[Tag]):
tag_widget.on_remove.connect(
lambda tag_id=tag.id: (
self.remove_tag(tag_id),
self.driver.preview_panel.update_widgets(),
self.driver.preview_panel.update_widgets(update_preview=False),
)
)
tag_widget.on_edit.connect(lambda t=tag: self.edit_tag(t))
Expand All @@ -77,7 +77,7 @@ def edit_tag(self, tag: Tag):
build_tag_panel,
tag.name, # TODO - display name including parent tags
"Edit Tag",
done_callback=self.driver.preview_panel.update_widgets,
done_callback=lambda: self.driver.preview_panel.update_widgets(update_preview=False),
has_save=True,
)
# TODO - this was update_tag()
Expand Down
Loading