fuzzy_search_tree
_fuzzy_search_tree
¶
Fuzzy search tree widget with relevance-based filtering and sorting.
Classes:
| Name | Description |
|---|---|
FXFuzzySearchTree |
A searchable tree widget with fuzzy matching capabilities. |
Functions:
| Name | Description |
|---|---|
example |
Run an example demonstrating the FXFuzzySearchTree widget. |
Classes¶
FXFuzzySearchTree
¶
FXFuzzySearchTree(
parent: Optional[QWidget] = None,
placeholder: str = "Search...",
ratio: float = 0.5,
show_ratio_slider: bool = False,
color_match: bool = True,
)
Bases: FXThemeAware, QWidget
flowchart TD
fxgui.fxwidgets._fuzzy_search_tree.FXFuzzySearchTree[FXFuzzySearchTree]
fxgui.fxstyle.FXThemeAware[FXThemeAware]
fxgui.fxstyle.FXThemeAware --> fxgui.fxwidgets._fuzzy_search_tree.FXFuzzySearchTree
click fxgui.fxwidgets._fuzzy_search_tree.FXFuzzySearchTree href "" "fxgui.fxwidgets._fuzzy_search_tree.FXFuzzySearchTree"
click fxgui.fxstyle.FXThemeAware href "" "fxgui.fxstyle.FXThemeAware"
A searchable tree widget with fuzzy matching capabilities.
This widget combines a search bar with a tree view that uses fuzzy matching to filter and sort items by relevance. Items are colored based on their match quality (green for good matches, red for poor matches).
The tree supports hierarchical data with parent-child relationships. When filtering, parent items remain visible if any of their children match.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Optional[QWidget]
|
Parent widget. |
None
|
|
str
|
Placeholder text for the search input. |
'Search...'
|
|
float
|
Initial similarity ratio threshold (0.0 to 1.0). |
0.5
|
|
bool
|
Whether to show the ratio adjustment slider. |
False
|
|
bool
|
Whether to color items based on match quality. |
True
|
Signals
item_selected: Emitted when an item is clicked. Passes the item text. item_double_clicked: Emitted when an item is double-clicked. Passes the item text. item_activated: Emitted when Enter is pressed on an item. Passes the item text. selection_changed: Emitted when the selection changes. Passes a list of selected item texts. item_expanded: Emitted when an item is expanded. Passes the item text. item_collapsed: Emitted when an item is collapsed. Passes the item text.
Examples:
Basic usage with hierarchical data:
>>> fuzzy_tree = FXFuzzySearchTree(placeholder="Search assets...")
>>> fuzzy_tree.add_item("Characters")
>>> fuzzy_tree.add_item("Hero", parent="Characters")
>>> fuzzy_tree.add_item("Villain", parent="Characters")
>>> fuzzy_tree.item_selected.connect(lambda text: print(f"Selected: {text}"))
With ratio slider for user adjustment:
>>> fuzzy_tree = FXFuzzySearchTree(show_ratio_slider=True, ratio=0.6)
>>> fuzzy_tree.set_items({
... "Props": ["sword", "shield", "chair"],
... "Vehicles": ["car", "truck", "motorcycle"],
... })
Methods:
| Name | Description |
|---|---|
add_item |
Add a single item to the tree. |
clear |
Clear all items from the tree. |
clear_search |
Clear the search input. |
collapse_all |
Collapse all items in the tree. |
collapse_item |
Collapse an item by its text. |
expand_all |
Expand all items in the tree. |
expand_item |
Expand an item by its text. |
get_item |
Get an item by its text. |
remove_item |
Remove an item from the tree by its text. |
select_item |
Select an item by its text. |
setFocus |
Set focus to the search input. |
set_color_match |
Enable or disable color-coded match quality. |
set_items |
Set the tree items from a list or dictionary. |
set_placeholder |
Set the search bar placeholder text. |
set_selection_mode |
Set the tree view selection mode. |
show_ratio_slider |
Show or hide the ratio adjustment slider. |
Attributes:
| Name | Type | Description |
|---|---|---|
current_item |
Optional[str]
|
Return the current item text. |
items |
List[str]
|
Return all item texts in the source model. |
proxy_model |
FXSortFilterProxyModel
|
Return the proxy model for advanced customization. |
ratio |
float
|
Return the current similarity ratio threshold. |
search_text |
str
|
Return the current search text. |
selected_items |
List[str]
|
Return currently selected items. |
source_model |
QStandardItemModel
|
Return the source model for advanced customization. |
top_level_items |
List[str]
|
Return top-level item texts. |
tree_view |
QTreeView
|
Return the tree view for advanced customization. |
Attributes¶
current_item
property
¶
items
property
¶
proxy_model
property
¶
proxy_model: FXSortFilterProxyModel
Return the proxy model for advanced customization.
Returns:
| Type | Description |
|---|---|
FXSortFilterProxyModel
|
The underlying proxy model. |
ratio
property
writable
¶
ratio: float
Return the current similarity ratio threshold.
Returns:
| Type | Description |
|---|---|
float
|
The ratio threshold (0.0 to 1.0). |
selected_items
property
¶
source_model
property
¶
Return the source model for advanced customization.
Returns:
| Type | Description |
|---|---|
QStandardItemModel
|
The underlying QStandardItemModel. |
top_level_items
property
¶
tree_view
property
¶
Return the tree view for advanced customization.
Returns:
| Type | Description |
|---|---|
QTreeView
|
The underlying QTreeView. |
Functions¶
add_item
¶
Add a single item to the tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
¶ |
str
|
The item text to add. |
required |
parent
¶ |
Optional[str]
|
The parent item text. If None, adds as top-level item. |
None
|
data
¶ |
Optional[dict]
|
Optional dictionary of user data to store on the item. |
None
|
Returns:
| Type | Description |
|---|---|
QStandardItem
|
The created QStandardItem. |