Skip to content
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

PR: Restore widget shortcuts to Preferences and allow to change them on the fly (Shortcuts) #23024

Merged
merged 19 commits into from
Dec 2, 2024

Conversation

ccordoba12
Copy link
Member

@ccordoba12 ccordoba12 commented Nov 19, 2024

Description of Changes

  • Those shortcuts were not shown in Spyder 6, as reported by several users.
  • That was a regression introduced by PR: Fix shortcuts for several Run and Debugger actions #22230, which unfortunately we overlooked.
  • This also fixes an important usability issue: changing those shortcuts didn't have an immediate effect (like all other shortcuts), but required an app restart. That issue was also present in Spyder 5 and it was very counterintuitive. Now those shortcuts will be updated on the fly.
  • Introduce a new ShortcutData dataclass to represent shortcut data internally and work more easily with it.
  • Change context of Switcher plugin shortcuts to be _, i.e. global (before their context was switcher but that made little sense).

Issue(s) Resolved

Fixes #23072
Fixes #22741
Fixes #22516

Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

I certify the above statement is true and correct: @ccordoba12

@ccordoba12 ccordoba12 added this to the v6.0.3 milestone Nov 19, 2024
@ccordoba12 ccordoba12 self-assigned this Nov 19, 2024
@ccordoba12 ccordoba12 marked this pull request as draft November 19, 2024 03:17
@ccordoba12 ccordoba12 force-pushed the issue-22516 branch 7 times, most recently from 251ca02 to 8b3fe55 Compare November 21, 2024 17:15
@ccordoba12 ccordoba12 closed this Nov 21, 2024
@ccordoba12 ccordoba12 reopened this Nov 21, 2024
@ccordoba12 ccordoba12 marked this pull request as ready for review November 21, 2024 23:42
@ccordoba12 ccordoba12 requested a review from dalthviz November 21, 2024 23:42
@ccordoba12
Copy link
Member Author

@dalthviz, this is ready for review. Please check that:

  • Shortcuts registered with register_shortcut_for_widget are shown in Preferences.
  • Changing those shortcuts works immediately (i.e. without a restart) in their respective widgets.

@dalthviz
Copy link
Member

Gave this an initial check and seems like manually changing shortcuts is working and also shortcuts like duplicate line down are being displayed over the shortcuts preferences page 👍 However, when you modify a shortcut and then trigger a reset from the preferences page, the reset changes are not being honored inmediatly:

widget_shortcuts

The current docstrings were not easy to understand.
- The previous solution, which used tuples to collect those data, was
easy to break, because it required to put data in the right order; and
undocumented, because it was unclear what kind of data had to be added
in the tuple elements.
- Those limitations made difficult to reason about shortcuts-related
code.
- Before we only allowed class methods decorated with on_conf_change to
do that.
- But that's too limited if we need to use regular functions to observe
an option. And that's precisely what this new method allows us to do.
This is necessary to add observers for specific shortcuts.
- That allows those shortcuts to be updated on the fly when they are
changed in Preferences or directly with set_conf.
- Also, fix inheritance of classes that inherit from
SpyderShortcutsMixin to accomodate this change.
That was introducing an error in test_shortcut_for_widget_is_updated
when run on CI due to the incorrectly named section.
This is to have feature parity of kwargs with the other methods of
SpyderShortcutsMixin.
Also, add inline typing for several attributes of ConfigurationManager
and remove associated comments.
@ccordoba12
Copy link
Member Author

ccordoba12 commented Nov 25, 2024

However, when you modify a shortcut and then trigger a reset from the preferences page, the reset changes are not being honored inmediatly

Thanks for checking that @dalthviz! It should be fixed now.

I also took the opportunity to change the context of the Switcher shortcut actions to be _ because they are actually global shortcuts (the context was switcher).

Copy link
Member

@dalthviz dalthviz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ccordoba12 ! Gave another local check to the reset shortcuts to default values and seems like things are working as expected now. Left a couple of questions and couple of suggestions like using an f-string at somepoint and an idea to extend a test but other than that this LGTM 👍

spyder/config/manager.py Outdated Show resolved Hide resolved
spyder/config/manager.py Show resolved Hide resolved
- That prevents third-party plugin developers to set shortcuts that
can't be processed by Spyder.
- Print errors when instantiating CONF to allow third-party developers
understand what's wrong with it.
- Use an f-string when setting shortcuts for clarity.
@pep8speaks
Copy link

pep8speaks commented Nov 30, 2024

Hello @ccordoba12! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-11-30 16:21:36 UTC

@ccordoba12
Copy link
Member Author

ccordoba12 commented Nov 30, 2024

@dalthviz, this is ready for another review. Besides addressing your comments, I also took the opportunity to fix other problems with shortcuts I found while doing that in my last four commits.

Specifically, I:

  • Fixed getting, saving and setting shortcut options with capitalized names (third-party developers could set them like that, so we need to be able to process them).
  • Add a test for registering widget shortcuts for external plugins (so that that doesn't break with future changes).
  • Validate that shortcut options have the right format (i.e. context/name) when setting defaults. This will ensure that third-party plugins use shortcuts in the way expected by Spyder.

Copy link
Member

@dalthviz dalthviz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ccordoba12 ! Left a question regarding the usage of print instead of the login module in some error handling but other than that this seems like ready to be merged 👍

Will leave this approved so feel free to merge this is you think is ready.


try:
CONF = ConfigurationManager()
except Exception:
from qtpy.QtWidgets import QApplication, QMessageBox

# Print traceback to show error in the terminal in case it's needed
print(traceback.format_exc()) # spyder: test-skip
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use the logging module for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so because this will help third-party developers to see, even without logging enabled, that their plugin config is incorrect, like this:

imagen

@ccordoba12 ccordoba12 merged commit c34f19c into spyder-ide:master Dec 2, 2024
17 checks passed
@ccordoba12 ccordoba12 deleted the issue-22516 branch December 2, 2024 03:47
@ccordoba12
Copy link
Member Author

@meeseeksdev please backport to 6.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants