33# Created for TagStudio: https://github.com/CyanVoxel/TagStudio
44
55
6+ import typing
7+
68import src .qt .modals .build_tag as build_tag
79import structlog
810from PySide6 .QtCore import QSize , Qt , Signal
3234
3335logger = structlog .get_logger (__name__ )
3436
37+ # Only import for type checking/autocompletion, will not be imported at runtime.
38+ if typing .TYPE_CHECKING :
39+ from src .qt .modals .build_tag import BuildTagPanel
40+
3541
3642class TagSearchPanel (PanelWidget ):
3743 tag_chosen = Signal (int )
@@ -41,7 +47,12 @@ class TagSearchPanel(PanelWidget):
4147 is_tag_chooser : bool
4248 exclude : list [int ]
4349
44- def __init__ (self , library : Library , exclude : list [int ] = None , is_tag_chooser : bool = True ):
50+ def __init__ (
51+ self ,
52+ library : Library ,
53+ exclude : list [int ] = None ,
54+ is_tag_chooser : bool = True ,
55+ ):
4556 super ().__init__ ()
4657 self .lib = library
4758 self .exclude = exclude or []
@@ -93,6 +104,17 @@ def __build_row_item_widget(self, tag: Tag):
93104
94105 tag_widget .on_edit .connect (lambda t = tag : self .edit_tag (t ))
95106 tag_widget .on_remove .connect (lambda t = tag : self .remove_tag (t ))
107+
108+ # NOTE: A solution to this would be to pass the driver to TagSearchPanel, however that
109+ # creates an exponential amount of work trying to fix the preexisting tests.
110+
111+ # tag_widget.search_for_tag_action.triggered.connect(
112+ # lambda checked=False, tag_id=tag.id: (
113+ # self.driver.main_window.searchField.setText(f"tag_id:{tag_id}"),
114+ # self.driver.filter_items(FilterState.from_tag_id(tag_id)),
115+ # )
116+ # )
117+
96118 row .addWidget (tag_widget )
97119
98120 primary_color = get_primary_color (tag )
@@ -196,7 +218,7 @@ def on_tag_modal_saved():
196218 self .search_field .setText ("" )
197219 self .update_tags ()
198220
199- self .build_tag_modal : build_tag . BuildTagPanel = build_tag .BuildTagPanel (self .lib )
221+ self .build_tag_modal : BuildTagPanel = build_tag .BuildTagPanel (self .lib )
200222 self .add_tag_modal : PanelModal = PanelModal (self .build_tag_modal , has_save = True )
201223 Translations .translate_with_setter (self .add_tag_modal .setTitle , "tag.new" )
202224 Translations .translate_with_setter (self .add_tag_modal .setWindowTitle , "tag.add" )
0 commit comments