fxutils
¶
Utility functions for the fxgui package.
Qt helpers every widget and application shares: UI loading, actions, shadows, menus, trees, window corners and wrapper lifetimes.
Examples:
Classes:
| Name | Description |
|---|---|
TreeState |
What is open, selected and current in a tree, named by row text. |
Functions:
| Name | Description |
|---|---|
add_shadow |
Cast the theme's drop shadow under |
add_submenu |
Add and return a submenu titled |
children_of |
Yield every child row of |
create_action |
Create a QAction owned by |
filter_tree |
Tell |
fit_columns |
Widen each column to its widest row, collapsed rows too; never narrow. |
focus_step |
Return the widget after |
later |
Run |
load_ui |
Load a Qt Designer UI file as a new widget parented to |
markdown_to_plain_text |
Return |
popup_menu |
Show |
rehome |
Give |
repolish |
Force re-evaluation of the stylesheet rules for a widget. |
round_window_corners |
Give |
set_app_user_model_id |
Tell Windows this process is its own application, |
Classes¶
TreeState
dataclass
¶
TreeState(
expanded: Tuple[_RowPath, ...] = (),
selected: Tuple[_RowPath, ...] = (),
current: Optional[_RowPath] = None,
scroll: int = 0,
)
What is open, selected and current in a tree, named by row text.
Text survives a tree that is cleared and refilled; items do not.
Examples:
Methods:
| Name | Description |
|---|---|
of |
Return what is open, selected and current in |
restore |
Put this state back on |
Functions:¶
add_shadow
¶
add_submenu
¶
children_of
¶
children_of(item: QTreeWidgetItem) -> Iterator[QTreeWidgetItem]
Yield every child row of item.
create_action
¶
create_action(
parent: QWidget,
name: str,
trigger: Optional[Callable] = None,
enable: bool = True,
shortcut: Optional[str] = None,
checkable: bool = False,
icon_name: Optional[str] = None,
) -> QAction
Create a QAction owned by parent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
QWidget
|
Parent widget for the action. |
required |
|
str
|
Display name for the action. |
required |
|
Optional[Callable]
|
Called when the action is triggered. |
None
|
|
bool
|
Whether the action is enabled. |
True
|
|
Optional[str]
|
Keyboard shortcut (e.g., "Ctrl+S"). |
None
|
|
bool
|
Whether the action is checkable. |
False
|
|
Optional[str]
|
An fxicons name, drawn in the theme's colours. |
None
|
Examples:
filter_tree
¶
filter_tree(
tree: QTreeWidget,
text: str,
mark: Callable[[QTreeWidgetItem, bool], None] = _hide_unless,
) -> None
Tell mark for every row of tree whether text keeps it.
A row matches when any column holds text, ignoring case; empty text
matches every row. A match keeps its whole subtree and its ancestors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
QTreeWidget
|
The tree to walk, top level down. |
required |
|
str
|
The text to find. |
required |
|
Callable[[QTreeWidgetItem, bool], None]
|
Called with each row and its verdict; the default hides the rows the text drops. |
_hide_unless
|
fit_columns
¶
Widen each column to its widest row, collapsed rows too; never narrow.
resizeColumnToContents measures only the rows that are expanded.
focus_step
¶
focus_step(widget, forward: bool = True)
Return the widget after widget in the focus chain, or before it.
later
¶
later(ms: int, owner, call) -> None
Run call once after ms milliseconds, unless owner died first.
Stands in for QTimer.singleShot(ms, owner, call), which Houdini 21's
PySide6 6.5 lacks. Call it on owner's thread: the timer is its child.
load_ui
¶
load_ui(parent: QWidget, ui_file: str) -> QWidget
Load a Qt Designer UI file as a new widget parented to parent.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specified UI file doesn't exist. |
Examples:
markdown_to_plain_text
cached
¶
Return text with its Markdown formatting removed.
Without the optional markdown package the text is returned as is.
popup_menu
¶
Show menu at global position at, freeing it once it closes.
popup rather than exec, whose own event loop no key-driven test can
step through; a parented menu is never freed, so aboutToHide frees it.
rehome
¶
Give widget's Python wrapper back to its own parent's; return it.
PySide files a widget a getter returns under the widget asked, and
kills that one's wrapped children when it dies. Qt skips a setParent
to the same parent; the binding files the wrapper back. A parent only
C++ made is filed first, up to one Python made.
repolish
¶
repolish(widget: QWidget) -> None
Force re-evaluation of the stylesheet rules for a widget.
Call after changing a Qt dynamic property that a stylesheet
attribute selector depends on, e.g.
MyBanner[level="error"] { ... }.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
QWidget
|
The widget to unpolish/polish and repaint. |
required |
Examples:
round_window_corners
¶
Give widget's own window the corners and shadow of a flyout.
One DwmSetWindowAttribute call on Windows 11: the compositor clips and
shades the window, and its geometry does not change. Nothing raises.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
QWidget
|
A window; asking a child for its handle would make it native. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Whether the compositor took the request; False off Windows 11. |
Examples:
set_app_user_model_id
¶
Tell Windows this process is its own application, app_id.
Windows groups taskbar buttons and picks their icon by this id, so a Python-run application otherwise wears the Python icon. Call before the first window exists: Windows reads the id when a window is made. A pinned shortcut must carry the same id. Nothing here raises.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
A machine-wide id, such as |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Whether Windows took it; always False off Windows. |
Examples: