Enhance: Add shield, information, and error icons to forms.alert() - #3552
Enhance: Add shield, information, and error icons to forms.alert()#3552smit-8462 wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
PR Summary:
- Adds an
iconparameter toforms.alert()supporting"shield","information","error", and"warning"icons mapped to Revit API'sTaskDialogIconenum. - Preserves full backward compatibility: the legacy
warn_iconboolean path is used wheniconis not provided;icontakes precedence when both are passed. - Also includes unrelated black formatting touch-ups (blank lines after imports, quote normalization,
FamilyParamOptionreformatting).
Review Summary:
The core feature is well-designed and backward-compatible — the legacy warn_icon path is correctly preserved and the new icon parameter cleanly extends the API. One high-severity issue was found in the icon-mapping block: the PR's own test table contradicts the actual code behavior for the two "icon conflict" cases (the "Expected Result" column text is wrong; the code correctly makes icon take precedence), and the docstring should state the precedence rule explicitly. Additionally, invalid icon values (e.g. typos like "erorr") silently fall back to no icon with zero feedback — per the repo guideline that configuration errors should never fail silently, this should log a warning via mlogger.warning(...). The redundant if icon else "" guard inside the .get() call is dead code given the outer if icon: check. IronPython compatibility, black formatting, and PEP 8 naming are all respected.
Suggestions
…of failing silently
There was a problem hiding this comment.
Pull request overview
This PR extends the widely-used forms.alert() helper in pyRevit's IronPython forms backend (pyrevitlib/pyrevit/forms/_ipy.py) so callers can select a TaskDialog icon beyond the existing warning/none options. It resolves issue #3551 by exposing the Revit API TaskDialogIcon values for "shield", "information", and "error" (plus explicit "warning") through a new icon string parameter, while preserving the legacy warn_icon boolean behavior for full backward compatibility.
Changes:
- Added an
iconkeyword parameter toalert()with an icon-mapping dictionary; a non-emptyicontakes precedence overwarn_icon, and unknown values log a warning and fall back to no icon. - Preserved the original
warn_iconlogic path wheniconis empty, so existing callers are unaffected. - Applied incidental Black-style formatting (blank lines after imports, single→double quotes, wrapped
FamilyParamOption.__init__signature) and updated the docstring.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Minor grammar fix. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
smit-8462
left a comment
There was a problem hiding this comment.
Grammar fixed (as per bot).
Add shield, information, and error icons to forms.alert()
Description
The
iconparameter is introduced informs.alert()for specifying the TaskDialog icons to be used foralertform.Following changes are implemented in this PR -
"shield","information", and"error"icons derived from Revit API'sTaskDialogIconenum TaskDialog class, in addition to existing"warning"icon."shield","information", and"error"by usingiconparameter.warn_iconparameter for"warn"icon is preserved for full backwardcompatibility.
warn_iconparameter is used, original icon-mapping logic will be used.iconparameter is used, new icon-mapping logic will be used.warn_iconandiconparameters are passed, theniconparameter will take precedence overwarn_iconparameter, and new icon-mapping logic will be used.No breaking changes, existing calls to
forms.alert(), with or withoutwarn_iconwill behave exactly as before.Checklist
Before submitting your pull request, ensure the following requirements are met:
pipenv run black {source_file_or_directory}Related Issues
Additional Notes
Tested manually in Revit 2025.4 via pyRevit reload:
forms.alert("Default (Warning) icon")forms.alert("No icon shown", warn_icon=False)forms.alert("Shield icon", icon="shield")forms.alert("Information icon", icon="information")forms.alert("Error icon", icon="error")forms.alert("Warning icon", icon="warning")forms.alert("No icon (incorrect input)", icon="bogus")iconkey)forms.alert("Warning icon (empty input)", icon="")iconfalls back towarn_icondefault)forms.alert("Icon conflict", warn_icon=True, icon="shield")icontakes precedence)forms.alert("Icon conflict", warn_icon=False, icon="warning")icontakes precedence)Reference: TaskDialogIcon Enumeration – Revit API Docs
Thank you for contributing to pyRevit! 🎉