Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from typing import TYPE_CHECKING

import structlog
from PySide6.QtCore import Signal
from PySide6.QtWidgets import QMessageBox

from tagstudio.core.library.alchemy.models import TagColorGroup
from tagstudio.qt.mixed.build_color import BuildColorPanel
from tagstudio.qt.translations import Translations
from tagstudio.qt.views.panel_modal import PanelModal
from tagstudio.qt.views.preview_panel.fields.color_box_widget_view import ColorBoxWidgetView

if TYPE_CHECKING:
from tagstudio.core.library.alchemy.library import Library

logger = structlog.get_logger(__name__)


class ColorBoxWidget(ColorBoxWidgetView):
"""A widget holding a list of tag colors."""

on_update = Signal()

def __init__(self, group: str, colors: list[TagColorGroup], library: "Library") -> None:
super().__init__(group, colors, library)
self.__lib: Library = library

def _on_edit_color(self, color_group: TagColorGroup) -> None:
build_color_panel = BuildColorPanel(self.__lib, color_group)

edit_color_modal = PanelModal(
build_color_panel,
"Edit Color",
has_save=True,
)

edit_color_modal.saved.connect(
lambda: (
self.__lib.update_color(*build_color_panel.build_color()),
self.on_update.emit(),
)
)

edit_color_modal.show()

def _on_delete_color(self, color_group: TagColorGroup) -> None:
# Dialogue box
message_box = QMessageBox(
QMessageBox.Icon.Warning,
Translations["color.delete"],
Translations.format("color.confirm_delete", color_name=color_group.name),
)

# Buttons
cancel_button = message_box.addButton(
Translations["generic.cancel_alt"], QMessageBox.ButtonRole.RejectRole
)
message_box.addButton(
Translations["generic.delete_alt"], QMessageBox.ButtonRole.DestructiveRole
)
message_box.setEscapeButton(cancel_button)

# Dialogue box result
result = message_box.exec_()
logger.info(QMessageBox.ButtonRole.DestructiveRole.value)

if result != QMessageBox.ButtonRole.ActionRole.value:
return

logger.info("[ColorBoxWidget] Removing color", color=color_group)
self.__lib.delete_color(color_group)
self.on_update.emit()
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from tagstudio.core.utils.types import unwrap
from tagstudio.qt.mixed.build_tag import BuildTagPanel
from tagstudio.qt.views.panel_modal import PanelModal
from tagstudio.qt.views.tag_box_view import TagBoxWidgetView
from tagstudio.qt.views.preview_panel.fields.tag_box_widget_view import TagBoxWidgetView

if TYPE_CHECKING:
from tagstudio.qt.ts_qt import QtDriver
Expand All @@ -22,11 +22,13 @@


class TagBoxWidget(TagBoxWidgetView):
"""A widget that holds a list of tags."""

on_update = Signal()

__entries: list[int] = []

def __init__(self, title: str, driver: "QtDriver"):
def __init__(self, title: str, driver: "QtDriver") -> None:
super().__init__(title, driver)
self.__driver = driver

Expand Down
166 changes: 0 additions & 166 deletions src/tagstudio/qt/mixed/color_box.py

This file was deleted.

46 changes: 23 additions & 23 deletions src/tagstudio/qt/mixed/field_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
from tagstudio.core.library.alchemy.library import Library
from tagstudio.core.library.alchemy.models import Entry, Tag
from tagstudio.core.utils.types import unwrap
from tagstudio.qt.controllers.tag_box_controller import TagBoxWidget
from tagstudio.qt.controllers.preview_panel.fields.tag_box_widget_controller import TagBoxWidget
from tagstudio.qt.mixed.datetime_picker import DatetimePicker
from tagstudio.qt.mixed.field_widget import FieldContainer
from tagstudio.qt.mixed.text_field import TextWidget
from tagstudio.qt.translations import Translations
from tagstudio.qt.views.edit_text_box_modal import EditTextBox
from tagstudio.qt.views.edit_text_line_modal import EditTextLine
from tagstudio.qt.views.panel_modal import PanelModal
from tagstudio.qt.views.preview_panel.fields.field_container import FieldContainer
from tagstudio.qt.views.preview_panel.fields.text_field_widget import TextFieldWidget

if typing.TYPE_CHECKING:
from tagstudio.qt.ts_qt import QtDriver
Expand Down Expand Up @@ -270,8 +270,8 @@ def write_container(self, index: int, field: BaseField, is_mixed: bool = False):
text = "<i>Mixed Data</i>"

title = f"{field.type.name} ({field.type.type.value})"
inner_widget = TextWidget(title, text)
container.set_inner_widget(inner_widget)
inner_widget = TextFieldWidget(title, text)
container.set_field_widget(inner_widget)
if not is_mixed:
modal = PanelModal(
EditTextLine(field.value),
Expand Down Expand Up @@ -309,8 +309,8 @@ def write_container(self, index: int, field: BaseField, is_mixed: bool = False):
else:
text = "<i>Mixed Data</i>"
title = f"{field.type.name} (Text Box)"
inner_widget = TextWidget(title, text)
container.set_inner_widget(inner_widget)
inner_widget = TextFieldWidget(title, text)
container.set_field_widget(inner_widget)
if not is_mixed:
modal = PanelModal(
EditTextBox(field.value),
Expand Down Expand Up @@ -350,8 +350,8 @@ def write_container(self, index: int, field: BaseField, is_mixed: bool = False):
title += " (Unknown Format)"
text = str(field.value)

inner_widget = TextWidget(title, text)
container.set_inner_widget(inner_widget)
inner_widget = TextFieldWidget(title, text)
container.set_field_widget(inner_widget)

modal = PanelModal(
DatetimePicker(self.driver, field.value or dt.now()),
Expand All @@ -377,15 +377,15 @@ def write_container(self, index: int, field: BaseField, is_mixed: bool = False):
else:
text = "<i>Mixed Data</i>"
title = f"{field.type.name} (Wacky Date)"
inner_widget = TextWidget(title, text)
container.set_inner_widget(inner_widget)
inner_widget = TextFieldWidget(title, text)
container.set_field_widget(inner_widget)
else:
logger.warning("[FieldContainers][write_container] Unknown Field", field=field)
container.set_title(field.type.name)
container.set_inline(False)
title = f"{field.type.name} (Unknown Field Type)"
inner_widget = TextWidget(title, field.type.name)
container.set_inner_widget(inner_widget)
inner_widget = TextFieldWidget(title, field.type.name)
container.set_field_widget(inner_widget)
container.set_remove_callback(
lambda: self.remove_message_box(
prompt=self.remove_field_prompt(field.type.name),
Expand Down Expand Up @@ -423,28 +423,28 @@ def write_tag_container(
container.set_inline(False)

if not is_mixed:
inner_widget = container.get_inner_widget()
field_widget = container.get_field_widget()

if isinstance(inner_widget, TagBoxWidget):
if isinstance(field_widget, TagBoxWidget):
with catch_warnings(record=True):
inner_widget.on_update.disconnect()
field_widget.on_update.disconnect()

else:
inner_widget = TagBoxWidget(
field_widget = TagBoxWidget(
"Tags",
self.driver,
)
container.set_inner_widget(inner_widget)
inner_widget.set_entries([e.id for e in self.cached_entries])
inner_widget.set_tags(tags)
container.set_field_widget(field_widget)
field_widget.set_entries([e.id for e in self.cached_entries])
field_widget.set_tags(tags)

inner_widget.on_update.connect(
field_widget.on_update.connect(
lambda: (self.update_from_entry(self.cached_entries[0].id, update_badges=True))
)
else:
text = "<i>Mixed Data</i>"
inner_widget = TextWidget("Mixed Tags", text)
container.set_inner_widget(inner_widget)
field_widget = TextFieldWidget("Mixed Tags", text)
container.set_field_widget(field_widget)

container.set_edit_callback()
container.set_remove_callback()
Expand Down
Loading