Skip to content
Merged
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
23 changes: 3 additions & 20 deletions src/tagstudio/qt/mixed/field_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from warnings import catch_warnings

import structlog
from PySide6.QtCore import Qt, Signal
from PySide6.QtCore import Qt
from PySide6.QtGui import QGuiApplication
from PySide6.QtWidgets import (
QFrame,
Expand All @@ -22,7 +22,6 @@
QWidget,
)

from tagstudio.core.constants import TAG_ARCHIVED, TAG_FAVORITE
from tagstudio.core.enums import Theme
from tagstudio.core.library.alchemy.enums import FieldTypeEnum
from tagstudio.core.library.alchemy.fields import (
Expand Down Expand Up @@ -51,9 +50,6 @@
class FieldContainers(QWidget):
"""The Preview Panel Widget."""

favorite_updated = Signal(bool)
archived_updated = Signal(bool)

def __init__(self, library: Library, driver: "QtDriver"):
super().__init__()

Expand Down Expand Up @@ -131,7 +127,7 @@ def update_granular(
container_index += 1
container_len += 1
if update_badges:
self.emit_badge_signals({t.id for t in entry_tags})
self.driver.emit_badge_signals({t.id for t in entry_tags})

# Write field container(s)
for index, field in enumerate(entry_fields, start=container_index):
Expand Down Expand Up @@ -242,7 +238,7 @@ def add_tags_to_selected(self, tags: int | list[int]):
self.driver.selected,
tag_ids=tags,
)
self.emit_badge_signals(tags, emit_on_absent=False)
self.driver.emit_badge_signals(tags, emit_on_absent=False)

def write_container(self, index: int, field: BaseField, is_mixed: bool = False):
"""Update/Create data for a FieldContainer.
Expand Down Expand Up @@ -493,16 +489,3 @@ def remove_message_box(self, prompt: str, callback: Callable) -> None:
result = remove_mb.exec_()
if result == QMessageBox.ButtonRole.ActionRole.value:
callback()

def emit_badge_signals(self, tag_ids: list[int] | set[int], emit_on_absent: bool = True):
"""Emit any connected signals for updating badge icons."""
logger.info("[emit_badge_signals] Emitting", tag_ids=tag_ids, emit_on_absent=emit_on_absent)
if TAG_ARCHIVED in tag_ids:
self.archived_updated.emit(True) # noqa: FBT003
elif emit_on_absent:
self.archived_updated.emit(False) # noqa: FBT003

if TAG_FAVORITE in tag_ids:
self.favorite_updated.emit(True) # noqa: FBT003
elif emit_on_absent:
self.favorite_updated.emit(False) # noqa: FBT003
34 changes: 26 additions & 8 deletions src/tagstudio/qt/ts_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ class QtDriver(DriverMixin, QObject):

SIGTERM = Signal()

favorite_updated = Signal(bool)
archived_updated = Signal(bool)

tag_manager_panel: PanelModal | None = None
color_manager_panel: TagColorManager | None = None
ignore_modal: PanelModal | None = None
Expand Down Expand Up @@ -357,8 +360,9 @@ def start(self) -> None:
self.tag_manager_panel = PanelModal(
widget=TagDatabasePanel(self, self.lib),
title=Translations["tag_manager.title"],
done_callback=lambda checked=False,
s=self.selected: self.main_window.preview_panel.set_selection(s, update_preview=False),
done_callback=lambda checked=False: (
self.main_window.preview_panel.set_selection(self.selected, update_preview=False)
),
has_save=False,
)

Expand All @@ -369,9 +373,9 @@ def start(self) -> None:
self.add_tag_modal = TagSearchModal(self.lib, is_tag_chooser=True)
self.add_tag_modal.tsp.set_driver(self)
self.add_tag_modal.tsp.tag_chosen.connect(
lambda t, s=self.selected: (
self.add_tags_to_selected_callback(t),
self.main_window.preview_panel.set_selection(s),
lambda chosen_tag: (
self.add_tags_to_selected_callback([chosen_tag]),
self.main_window.preview_panel.set_selection(self.selected),
)
)

Expand Down Expand Up @@ -559,12 +563,12 @@ def create_about_modal():

self.main_window.search_field.textChanged.connect(self.update_completions_list)

self.main_window.preview_panel.field_containers_widget.archived_updated.connect(
self.archived_updated.connect(
lambda hidden: self.update_badges(
{BadgeType.ARCHIVED: hidden}, origin_id=0, add_tags=False
)
)
self.main_window.preview_panel.field_containers_widget.favorite_updated.connect(
self.favorite_updated.connect(
lambda hidden: self.update_badges(
{BadgeType.FAVORITE: hidden}, origin_id=0, add_tags=False
)
Expand Down Expand Up @@ -800,6 +804,19 @@ def backup_library(self):
)
)

def emit_badge_signals(self, tag_ids: list[int] | set[int], emit_on_absent: bool = True):
"""Emit any connected signals for updating badge icons."""
logger.info("[emit_badge_signals] Emitting", tag_ids=tag_ids, emit_on_absent=emit_on_absent)
if TAG_ARCHIVED in tag_ids:
self.archived_updated.emit(True) # noqa: FBT003
elif emit_on_absent:
self.archived_updated.emit(False) # noqa: FBT003

if TAG_FAVORITE in tag_ids:
self.favorite_updated.emit(True) # noqa: FBT003
elif emit_on_absent:
self.favorite_updated.emit(False) # noqa: FBT003

def add_tag_action_callback(self):
panel = BuildTagPanel(self.lib)
self.modal = PanelModal(
Expand Down Expand Up @@ -848,9 +865,10 @@ def clear_select_action_callback(self):
self.main_window.preview_panel.set_selection(self.selected)

def add_tags_to_selected_callback(self, tag_ids: list[int]):
selected = self.selected
selected: list[int] = self.selected
self.main_window.thumb_layout.add_tags(selected, tag_ids)
self.lib.add_tags_to_entries(selected, tag_ids)
self.emit_badge_signals(tag_ids)

def delete_files_callback(self, origin_path: str | Path, origin_id: int | None = None):
"""Callback to send on or more files to the system trash.
Expand Down