mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-07-19 20:16:22 +02:00
refactor: remove unnecessary methods and properties
This commit is contained in:
@@ -16,7 +16,7 @@ from tagstudio.core.library.alchemy.models import Entry
|
||||
from tagstudio.core.utils.ffmpeg_status import FfmpegStatus, FfprobeStatus
|
||||
from tagstudio.core.utils.types import unwrap
|
||||
from tagstudio.qt.mixed.field_containers import FieldContainers
|
||||
from tagstudio.qt.mixed.file_attributes import FileAttributeData, FileAttributes
|
||||
from tagstudio.qt.mixed.file_attributes import FileAttributeData
|
||||
from tagstudio.qt.views.preview_panel_view import PreviewPanelView
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
@@ -191,23 +191,5 @@ class PreviewPanel(QWidget):
|
||||
self._layout.preview_thumb.media_player.stop()
|
||||
|
||||
@property
|
||||
def add_buttons_enabled(self) -> bool: # needed for the tests
|
||||
field = self._layout.add_field_button.isEnabled()
|
||||
tag = self._layout.add_tag_button.isEnabled()
|
||||
assert field == tag
|
||||
return field
|
||||
|
||||
@add_buttons_enabled.setter
|
||||
def add_buttons_enabled(self, enabled: bool) -> None:
|
||||
self._layout.add_field_button.setEnabled(enabled)
|
||||
self._layout.add_tag_button.setEnabled(enabled)
|
||||
|
||||
@property
|
||||
def file_attributes_widget(self) -> FileAttributes: # needed for the tests
|
||||
"""Getter for the file attributes widget."""
|
||||
return self._layout.file_attrs
|
||||
|
||||
@property
|
||||
def field_containers_widget(self) -> FieldContainers: # needed for the tests
|
||||
"""Getter for the field containers widget."""
|
||||
def containers(self) -> FieldContainers:
|
||||
return self._layout.containers
|
||||
|
||||
@@ -57,7 +57,7 @@ class FieldContainers(QWidget):
|
||||
self.common_fields: list = []
|
||||
self.mixed_fields: list = []
|
||||
self.cached_entries: list[Entry] = []
|
||||
self.containers: list[FieldContainer] = []
|
||||
self._containers: list[FieldContainer] = []
|
||||
|
||||
self.scroll_layout = QVBoxLayout()
|
||||
self.scroll_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
|
||||
@@ -128,8 +128,8 @@ class FieldContainers(QWidget):
|
||||
self.write_field_container(index, field, is_mixed=False)
|
||||
|
||||
# Hide leftover container(s)
|
||||
if len(self.containers) > container_len:
|
||||
for i, c in enumerate(self.containers):
|
||||
if len(self._containers) > container_len:
|
||||
for i, c in enumerate(self._containers):
|
||||
if i > (container_len - 1):
|
||||
c.setHidden(True)
|
||||
|
||||
@@ -148,7 +148,7 @@ class FieldContainers(QWidget):
|
||||
|
||||
def hide_containers(self) -> None:
|
||||
"""Hide all field and tag containers."""
|
||||
for c in self.containers:
|
||||
for c in self._containers:
|
||||
c.setHidden(True)
|
||||
|
||||
def get_tag_categories(self, tags: set[Tag]) -> dict[Tag | None, set[Tag]]:
|
||||
@@ -364,12 +364,12 @@ class FieldContainers(QWidget):
|
||||
)
|
||||
|
||||
# Create new containers if necessary
|
||||
if len(self.containers) < (index + 1):
|
||||
if len(self._containers) < (index + 1):
|
||||
container = FieldContainer()
|
||||
self.containers.append(container)
|
||||
self._containers.append(container)
|
||||
self.scroll_layout.addWidget(container)
|
||||
else:
|
||||
container = self.containers[index]
|
||||
container = self._containers[index]
|
||||
|
||||
# Set field title
|
||||
field_name_key: str = FIELD_TYPE_KEYS.get(field.class_name, "field_type.unknown")
|
||||
@@ -398,12 +398,12 @@ class FieldContainers(QWidget):
|
||||
If True, field is not present in all selected items.
|
||||
"""
|
||||
logger.info("[FieldContainers][write_tag_container]", index=index)
|
||||
if len(self.containers) < (index + 1):
|
||||
if len(self._containers) < (index + 1):
|
||||
container = FieldContainer()
|
||||
self.containers.append(container)
|
||||
self._containers.append(container)
|
||||
self.scroll_layout.addWidget(container)
|
||||
else:
|
||||
container = self.containers[index]
|
||||
container = self._containers[index]
|
||||
|
||||
container.set_title(Translations["entries.tags"] if not category_tag else category_tag.name)
|
||||
|
||||
|
||||
@@ -500,7 +500,7 @@ class ItemThumb(FlowWidget):
|
||||
):
|
||||
selected = self.driver._selected
|
||||
if len(selected) == 1 and entry_id in selected:
|
||||
self.driver.main_window.preview_panel.field_containers_widget.update_toggled_tag(
|
||||
self.driver.main_window.preview_panel.containers.update_toggled_tag(
|
||||
tag_id, toggle_value
|
||||
)
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ class TagColorManager(QWidget):
|
||||
self.setup_color_groups(),
|
||||
()
|
||||
if len(self.driver.selected) < 1
|
||||
else self.driver.main_window.preview_panel.field_containers_widget.update_from_entry( # noqa: E501
|
||||
else self.driver.main_window.preview_panel.containers.update_from_entry( # noqa: E501
|
||||
self.driver.selected[0], update_badges=False
|
||||
),
|
||||
)
|
||||
@@ -142,7 +142,7 @@ class TagColorManager(QWidget):
|
||||
self.setup_color_groups(),
|
||||
()
|
||||
if len(self.driver.selected) < 1
|
||||
else self.driver.main_window.preview_panel.field_containers_widget.update_from_entry( # noqa: E501
|
||||
else self.driver.main_window.preview_panel.containers.update_from_entry( # noqa: E501
|
||||
self.driver.selected[0], update_badges=False
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# SPDX-FileCopyrightText: (c) TagStudio Contributors
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# pyright: reportPrivateUsage=false
|
||||
|
||||
from tagstudio.core.library.alchemy.models import Entry, Tag
|
||||
from tagstudio.core.utils.types import unwrap
|
||||
@@ -17,7 +18,7 @@ def test_update_selection_empty(qt_driver: QtDriver):
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# FieldContainer should hide all containers
|
||||
for container in panel.field_containers_widget.containers:
|
||||
for container in panel.containers._containers:
|
||||
assert container.isHidden()
|
||||
|
||||
|
||||
@@ -29,7 +30,7 @@ def test_update_selection_single(qt_driver: QtDriver, entry_full: Entry):
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# FieldContainer should show all applicable tags and field containers
|
||||
for container in panel.field_containers_widget.containers:
|
||||
for container in panel.containers._containers:
|
||||
assert not container.isHidden()
|
||||
|
||||
|
||||
@@ -44,7 +45,7 @@ def test_update_selection_multiple(qt_driver: QtDriver):
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# FieldContainer should show mixed field editing
|
||||
for container in panel.field_containers_widget.containers:
|
||||
for container in panel.containers._containers:
|
||||
assert container.isHidden()
|
||||
|
||||
|
||||
@@ -58,7 +59,7 @@ def test_add_tag_to_selection_single(qt_driver: QtDriver, entry_full: Entry):
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Add new tag
|
||||
panel.field_containers_widget.add_tags_to_selected(2000)
|
||||
panel.containers.add_tags_to_selected(2000)
|
||||
|
||||
# Then reload entry
|
||||
refreshed_entry: Entry = next(qt_driver.lib.all_entries(with_joins=True))
|
||||
@@ -75,7 +76,7 @@ def test_add_same_tag_to_selection_single(qt_driver: QtDriver, entry_full: Entry
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Add an existing tag
|
||||
panel.field_containers_widget.add_tags_to_selected(1000)
|
||||
panel.containers.add_tags_to_selected(1000)
|
||||
|
||||
# Then reload entry
|
||||
refreshed_entry = next(qt_driver.lib.all_entries(with_joins=True))
|
||||
@@ -105,7 +106,7 @@ def test_add_tag_to_selection_multiple(qt_driver: QtDriver):
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Add new tag
|
||||
panel.field_containers_widget.add_tags_to_selected(1000)
|
||||
panel.containers.add_tags_to_selected(1000)
|
||||
|
||||
# Then reload all entries and recheck the presence of tag 1000
|
||||
refreshed_entries = qt_driver.lib.all_entries(with_joins=True)
|
||||
@@ -133,8 +134,8 @@ def test_meta_tag_category(qt_driver: QtDriver, entry_full: Entry):
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# FieldContainer should hide all containers
|
||||
assert len(panel.field_containers_widget.containers) == 3
|
||||
for i, container in enumerate(panel.field_containers_widget.containers):
|
||||
assert len(panel.containers._containers) == 3
|
||||
for i, container in enumerate(panel.containers._containers):
|
||||
match i:
|
||||
case 0:
|
||||
# Check if the container is the Meta Tags category
|
||||
@@ -166,8 +167,8 @@ def test_custom_tag_category(qt_driver: QtDriver, entry_full: Entry):
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# FieldContainer should hide all containers
|
||||
assert len(panel.field_containers_widget.containers) == 3
|
||||
for i, container in enumerate(panel.field_containers_widget.containers):
|
||||
assert len(panel.containers._containers) == 3
|
||||
for i, container in enumerate(panel.containers._containers):
|
||||
match i:
|
||||
case 0:
|
||||
# Check if the container is the Meta Tags category
|
||||
|
||||
@@ -74,7 +74,7 @@ def test_file_path_display(
|
||||
entry = qt_driver.lib.get_entry(2)
|
||||
assert isinstance(entry, Entry)
|
||||
filename = entry.path
|
||||
panel.file_attributes_widget.update_stats(filepath=unwrap(qt_driver.lib.library_dir) / filename)
|
||||
panel._layout.file_attrs.update_stats(filepath=unwrap(qt_driver.lib.library_dir) / filename)
|
||||
|
||||
# Generate the expected file string.
|
||||
# This is copied directly from the file_attributes.py file
|
||||
@@ -92,7 +92,7 @@ def test_file_path_display(
|
||||
file_str += f"<b>{'\u200b'.join(part_)}</b>"
|
||||
|
||||
# Assert the file path is displayed correctly
|
||||
assert panel.file_attributes_widget.file_label.text() == file_str
|
||||
assert panel._layout.file_attrs.file_label.text() == file_str
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# SPDX-FileCopyrightText: (c) TagStudio Contributors
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# pyright: reportPrivateUsage=false
|
||||
|
||||
from tagstudio.core.library.alchemy.models import Entry
|
||||
from tagstudio.qt.controllers.preview_panel import PreviewPanel
|
||||
@@ -16,7 +17,11 @@ def test_update_selection_empty(qt_driver: QtDriver):
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Panel should disable UI that allows for entry modification
|
||||
assert not panel.add_buttons_enabled
|
||||
assert panel._layout.add_tag_button.isEnabled() == panel._layout.add_field_button.isEnabled()
|
||||
assert (
|
||||
not panel._layout.add_tag_button.isEnabled()
|
||||
and not panel._layout.add_field_button.isEnabled()
|
||||
)
|
||||
|
||||
|
||||
def test_update_selection_single(qt_driver: QtDriver, entry_full: Entry):
|
||||
@@ -27,7 +32,8 @@ def test_update_selection_single(qt_driver: QtDriver, entry_full: Entry):
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Panel should enable UI that allows for entry modification
|
||||
assert panel.add_buttons_enabled
|
||||
assert panel._layout.add_tag_button.isEnabled() == panel._layout.add_field_button.isEnabled()
|
||||
assert panel._layout.add_tag_button.isEnabled() and panel._layout.add_field_button.isEnabled()
|
||||
|
||||
|
||||
def test_update_selection_multiple(qt_driver: QtDriver):
|
||||
@@ -39,4 +45,5 @@ def test_update_selection_multiple(qt_driver: QtDriver):
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Panel should enable UI that allows for entry modification
|
||||
assert panel.add_buttons_enabled
|
||||
assert panel._layout.add_tag_button.isEnabled() == panel._layout.add_field_button.isEnabled()
|
||||
assert panel._layout.add_tag_button.isEnabled() and panel._layout.add_field_button.isEnabled()
|
||||
|
||||
Reference in New Issue
Block a user