-
-
Notifications
You must be signed in to change notification settings - Fork 462
feat: field template manager #1374
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
Open
TrigamDev
wants to merge
12
commits into
TagStudioDev:main
Choose a base branch
from
TrigamDev:feat/field_manager
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
055c3bf
refactor: merge tag_database.py into tag_search.py
TrigamDev a6708c9
refactor: mvc split of tag_search.py
TrigamDev b878423
refactor: tweaks
TrigamDev 8583f9d
doc: REUSE license information
TrigamDev d86662a
doc: add REUSE license information
TrigamDev 76318e5
refactor: split generic functionality into "search panel"
TrigamDev 54ee0cf
feat: field template search panel
TrigamDev ea0aa80
feat: field template manager
TrigamDev 9e7159f
fix: rename `tag.view_limit` key for other languages
TrigamDev 40a2be5
tweak: remove exclusion from field template search panel
TrigamDev f80234e
tweak: rename `is_field_chooser` to `is_field_template_chooser`
TrigamDev c267268
feat: switch from multiple inheritance to composition
TrigamDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/tagstudio/qt/controllers/field_template_search_panel_controller.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| # SPDX-FileCopyrightText: (c) TagStudio Contributors | ||
| # SPDX-License-Identifier: GPL-3.0-only | ||
|
|
||
|
|
||
| from warnings import catch_warnings | ||
|
|
||
| import structlog | ||
| from PySide6.QtCore import Signal | ||
|
|
||
| from tagstudio.core.library.alchemy.fields import BaseFieldTemplate | ||
| from tagstudio.core.library.alchemy.library import Library | ||
| from tagstudio.qt.controllers.field_template_widget_controller import FieldTemplateWidget | ||
| from tagstudio.qt.controllers.search_panel_controller import SearchPanel | ||
| from tagstudio.qt.translations import Translations | ||
| from tagstudio.qt.views.field_template_search_panel_view import FieldTemplateSearchPanelView | ||
| from tagstudio.qt.views.panel_modal import PanelModal, PanelWidget | ||
|
|
||
| logger = structlog.get_logger(__name__) | ||
|
|
||
|
|
||
| class FieldTemplateSearchModal(PanelModal): | ||
| def __init__( | ||
| self, | ||
| library: Library, | ||
| is_field_template_chooser: bool = True, | ||
| done_callback=None, | ||
| save_callback=None, | ||
| has_save=False, | ||
| ) -> None: | ||
| self.search_panel: FieldTemplateSearchPanel = FieldTemplateSearchPanel( | ||
| library, | ||
| is_field_template_chooser, | ||
| view=FieldTemplateSearchPanelView(is_field_template_chooser), | ||
| ) | ||
| super().__init__( | ||
| self.search_panel, | ||
| Translations["field.add.plural"], | ||
| done_callback=done_callback, | ||
| save_callback=save_callback, | ||
| has_save=has_save, | ||
| ) | ||
|
|
||
|
|
||
| class FieldTemplateSearchPanel(SearchPanel[BaseFieldTemplate]): | ||
| field_template_chosen = Signal(object) | ||
|
|
||
| def __init__( | ||
| self, | ||
| library: Library, | ||
| is_field_template_chooser: bool = True, | ||
| view: FieldTemplateSearchPanelView | None = None, | ||
| ) -> None: | ||
| super().__init__( | ||
| view=view or FieldTemplateSearchPanelView(is_field_template_chooser), | ||
| exclude=[], | ||
| is_chooser=is_field_template_chooser, | ||
| ) | ||
| self.__lib = library | ||
|
|
||
| self._unlimited_limit_item_label = Translations["field_template.all_field_templates"] | ||
| self._create_and_add_button_label_key = "field_template.create_add" | ||
|
|
||
| def _get_max_limit(self) -> int: | ||
| return len(self.__lib.field_templates) | ||
|
|
||
| def on_item_create(self) -> None: | ||
| # TODO: Allow creation of field templates | ||
| pass | ||
|
|
||
| def on_item_edit(self, item: BaseFieldTemplate) -> None: | ||
| # TODO: Allow creation of field templates | ||
| pass | ||
|
|
||
| def _on_item_remove(self, item: BaseFieldTemplate) -> None: | ||
| if self.is_chooser: | ||
| return | ||
|
|
||
| # TODO: Allow creation of field templates | ||
| pass | ||
|
|
||
| def on_item_create_and_add(self) -> None: | ||
| # TODO: Allow creation of field templates | ||
| pass | ||
|
|
||
| def _on_item_chosen(self, item: BaseFieldTemplate) -> None: | ||
| self.field_template_chosen.emit(item) | ||
|
|
||
| def search_items(self, query: str) -> tuple[list[BaseFieldTemplate], list[BaseFieldTemplate]]: | ||
| return self.__lib.search_field_templates(name=query, limit=self._get_limit()[1]), [] | ||
|
|
||
| def set_item_widget(self, item: BaseFieldTemplate | None, index: int) -> None: | ||
| """Set the field template of a field template widget at a specific index.""" | ||
| field_template_widget: FieldTemplateWidget = self.get_item_widget(index, self.__lib) | ||
| field_template_widget.set_field_template(item) | ||
| field_template_widget.setHidden(item is None) | ||
|
|
||
| if item is None: | ||
| return | ||
|
|
||
| # field_template_widget.has_remove = not self.is_chooser | ||
|
|
||
| # Disconnect previous callbacks | ||
| with catch_warnings(record=True): | ||
| # tag_widget.on_edit.disconnect() | ||
| # tag_widget.on_remove.disconnect() | ||
| field_template_widget.on_click.disconnect() | ||
|
|
||
| # Connect callbacks | ||
| # tag_widget.on_edit.connect(lambda edit_tag=item: self.on_item_edit(edit_tag)) | ||
| # tag_widget.on_remove.connect(lambda remove_tag=item: self._on_item_remove(remove_tag)) | ||
| field_template_widget.on_click.connect( | ||
| lambda checked=False, tag=item: self._on_item_chosen(tag) | ||
| ) | ||
|
|
||
| def create_item(self, build_item_modal: PanelModal, choose_item: bool = False) -> None: | ||
| # TODO: Allow creation of field templates | ||
| pass | ||
|
|
||
| def edit_item(self, edit_item_panel: PanelWidget) -> None: | ||
| # TODO: Allow creation of field templates | ||
| pass |
22 changes: 22 additions & 0 deletions
22
src/tagstudio/qt/controllers/field_template_widget_controller.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # SPDX-FileCopyrightText: (c) TagStudio Contributors | ||
| # SPDX-License-Identifier: GPL-3.0-only | ||
|
|
||
| from tagstudio.core.library.alchemy.fields import BaseFieldTemplate | ||
| from tagstudio.qt.translations import FIELD_TYPE_KEYS, Translations | ||
| from tagstudio.qt.views.field_template_widget_view import FieldTemplateWidgetView | ||
|
|
||
|
|
||
| class FieldTemplateWidget(FieldTemplateWidgetView): | ||
| def __init__(self) -> None: | ||
| super().__init__() | ||
|
|
||
| self.__field_template: BaseFieldTemplate | None = None | ||
|
|
||
| def set_field_template(self, field_template: BaseFieldTemplate | None) -> None: | ||
| self.__field_template = field_template | ||
|
|
||
| if field_template is None: | ||
| return | ||
|
|
||
| field_name_key: str = FIELD_TYPE_KEYS.get(field_template.class_name, "field_type.unknown") | ||
| self._bg_button.setText(f"{field_template.name} ({Translations[field_name_key]})") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was having some issues with pytest not recognizing new files, and adding this line fixed it.