-
-
Notifications
You must be signed in to change notification settings - Fork 163
PR: Add missing kwargs to add_action wrapper #531
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -112,13 +112,53 @@ def test_QMenu_functions(qtbot): | |||
| # A window is required for static calls | ||||
| window = QtWidgets.QMainWindow() | ||||
| menu = QtWidgets.QMenu(window) | ||||
| menu.addAction("QtPy") | ||||
| menu.addAction("QtPy with a Qt.Key shortcut", QtCore.Qt.Key_F1) | ||||
| menu.addAction( | ||||
| QtGui.QIcon(), | ||||
| "QtPy with an icon and a QKeySequence shortcut", | ||||
| QtGui.QKeySequence.UnknownKey, | ||||
|
|
||||
| # Actions | ||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests have only been added to QMenu, in theory qtpy supports these for QToolBar as well.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a little bit of context the original PR from where this patch approach comes is #437 The idea shown there only takes care of the more simple cases of compatibility for QMenu and QToolbar so I will say we currently only support backwards compatibility for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added tests for QToolbar. |
||||
|
|
||||
| class Receiver(QtCore.QObject): | ||||
| triggered = QtCore.Signal | ||||
|
|
||||
| func = lambda: print('Action') | ||||
| icon = QtGui.QIcon() | ||||
| text = "QtPy" | ||||
| shortcuts = ( | ||||
| QtGui.QKeySequence.StandardKey.HelpContents, | ||||
| QtCore.Qt.Key_F1, | ||||
| 'F1', | ||||
| 1, | ||||
| ) | ||||
| receiver = Receiver(parent=window) | ||||
| member = 'triggered' | ||||
| connection_type = QtCore.Qt.ConnectionType.DirectConnection | ||||
| action = QtWidgets.QAction() | ||||
|
|
||||
| menu.addAction(text) | ||||
| menu.addAction(text, func) | ||||
| menu.addAction(icon, text) | ||||
| menu.addAction(icon, text, func) | ||||
|
|
||||
| menu.addAction(action) | ||||
|
|
||||
| for shortcut in shortcuts: | ||||
| menu.addAction(text, func, shortcut) | ||||
| menu.addAction(text, func, shortcut=shortcut) | ||||
| menu.addAction(text, receiver, member, shortcut) | ||||
| menu.addAction(icon, text, func, shortcut) | ||||
| menu.addAction(icon, text, func, shortcut=shortcut) | ||||
| menu.addAction(icon, text, receiver, member, shortcut) | ||||
|
|
||||
| # Qt 5 | ||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These signatures are valid in Qt5 but not Qt6, do we still need to support them?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think they should still be available to ensure things with Qt5 bindings work. If no Qt6 bindings signature is usable with the passed arguments we should detect that case and probably at the very least show a warning explaining the situation (something like no Qt6 compatible signature is available please use one of the following to keep compatibility between Qt versions...).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, we'd have to also change this section here: Line 225 in cc853c3
I feel like the error is pretty clear already: This way we're also ensuring that we're not adding unnecessary code for when the user uses a modern Qt6 binding. Are you okay, if we just leave it as is? |
||||
| menu.addAction(text, receiver, member, shortcut=shortcut) | ||||
| menu.addAction(icon, text, receiver, member, shortcut=shortcut) | ||||
|
|
||||
| # Qt>=6.3 signature | ||||
| menu.addAction(text, shortcut) | ||||
| menu.addAction(text, shortcut, receiver, member, type=connection_type) | ||||
| menu.addAction(icon, text, shortcut) | ||||
| menu.addAction( | ||||
| icon, text, shortcut, receiver, member, type=connection_type | ||||
| ) | ||||
|
|
||||
| window.show() | ||||
|
|
||||
| with qtbot.waitExposed(window): | ||||
|
|
||||
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.
These signatures got added in 6.3 and won't error in Qt5 but type is not supported. How should this be handled?
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.
Showing a warning if someone uses the argument with a binding that doesn't support it makes sense to me
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.
If we leave the AttributeError, should we then also change this warning to an exception?