-
-
Notifications
You must be signed in to change notification settings - Fork 465
Fix/reload smartbutton #3476
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
ChrisCrosley
wants to merge
2
commits into
pyrevitlabs:develop
Choose a base branch
from
ChrisCrosley:fix/reload-smartbutton
base: develop
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
Fix/reload smartbutton #3476
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
11 changes: 11 additions & 0 deletions
11
...Dev.tab/Debug.panel/Bundle Tests.pulldown/Test Reload Icon Toggle.smartbutton/bundle.yaml
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,11 @@ | ||
| title: >- | ||
| Test Reload | ||
|
|
||
| Icon Toggle | ||
| tooltip: >- | ||
| SmartButton that mirrors Update.smartbutton: click to toggle a state | ||
| stored in the user config ini; __selfinit__ applies the orange dot icon | ||
| when the state is on and leaves the default bundle icon when off. After a | ||
| reload the icon must match the stored state - default shown while on | ||
| means __selfinit__ was not re-run in this pulldown, orange shown while | ||
| off means the loader failed to restore the bundle icon. |
Binary file added
BIN
+1.15 KB
...g.panel/Bundle Tests.pulldown/Test Reload Icon Toggle.smartbutton/icon.dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.78 KB
.../Debug.panel/Bundle Tests.pulldown/Test Reload Icon Toggle.smartbutton/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.15 KB
...ug.panel/Bundle Tests.pulldown/Test Reload Icon Toggle.smartbutton/off.dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.78 KB
...b/Debug.panel/Bundle Tests.pulldown/Test Reload Icon Toggle.smartbutton/off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.66 KB
...ab/Debug.panel/Bundle Tests.pulldown/Test Reload Icon Toggle.smartbutton/on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions
45
...itDev.tab/Debug.panel/Bundle Tests.pulldown/Test Reload Icon Toggle.smartbutton/script.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,45 @@ | ||
| """Test SmartButton icon persistence across reloads inside pulldowns. | ||
|
|
||
| Mirrors the Update.smartbutton pattern: __selfinit__ applies the orange dot | ||
| icon only when the stored state is on, and leaves the loader-applied default | ||
| icon otherwise. Click the button to toggle the state; it is stored in the | ||
| user config ini so it can be inspected while troubleshooting. | ||
|
|
||
| After a reload the icon must match the stored state: orange when on, the | ||
| default bundle icon when off. A mismatch means __selfinit__ was not re-run | ||
| (default shown while state is on) or the loader failed to restore the bundle | ||
| icon (orange shown while state is off). | ||
| """ | ||
| #pylint: disable=C0103,E0401 | ||
| from pyrevit import script | ||
| from pyrevit.coreutils.ribbon import ICON_MEDIUM | ||
|
|
||
| CONFIG_SECTION = 'devtools_reload_tests' | ||
| STATE_OPTION = 'pulldown_state' | ||
|
|
||
|
|
||
| def __selfinit__(script_cmp, ui_button_cmp, __rvt__): | ||
| # apply the stored state; the loader is responsible for restoring the | ||
| # default bundle icon when the state is off | ||
| config = script.get_config(CONFIG_SECTION) | ||
| if config.get_option(STATE_OPTION, default_value=False): | ||
| icon = script_cmp.get_bundle_file('on.png') | ||
| ui_button_cmp.set_icon(icon, icon_size=ICON_MEDIUM) | ||
| return True | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| from pyrevit.userconfig import user_config | ||
|
|
||
| config = script.get_config(CONFIG_SECTION) | ||
| state = not config.get_option(STATE_OPTION, default_value=False) | ||
| config.set_option(STATE_OPTION, state) | ||
| script.save_config() | ||
| # the default bundle icon stands in for the off state so the click | ||
| # result matches what a reload would show | ||
| script.toggle_icon(state, off_icon_path=script.get_bundle_file('icon.png')) | ||
|
|
||
| print('Config file: {}'.format(user_config.config_file)) | ||
| print('[{}] {} = {}'.format(CONFIG_SECTION, STATE_OPTION, state)) | ||
| print('Icon should now be {} and must stay that way after a reload.' | ||
| .format('the orange dot' if state else 'the default bundle icon')) |
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
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.
This "run
ExecuteSelfInit, disable onfalse, log" block is now duplicated almost verbatim in 6 places:PushButtonBuilder.BuildandUpdateExistingButton,PulldownButtonBuilder.AddSingleChildToPulldown(existing) and here, andSplitButtonBuilder.AddSingleChildToSplitButton(existing) and itsUpdateExistingChildrencounterpart. SinceButtonBuilderBasealready centralizes similar cross-cutting helpers (UpdatePushButtonCommandBinding,DeactivateRibbonItem), consider factoring this into a shared helper there, e.g.:This would prevent the two behaviors (create-path vs. update-path re-init) from drifting apart again in the future, which is effectively what caused the bug this PR fixes.
actions
Feedback: Rate this comment to help me improve future code reviews: