Open
Conversation
Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
asymingt
reviewed
Mar 4, 2026
| def on_key_press(self, event): | ||
| key = event.key() | ||
| if key == Qt.Key_Space: | ||
| if key == Qt.Key.Key_Space: |
There was a problem hiding this comment.
I realize you didn't write this code originally.
However, in the worst case you're going to evaluate N conditionals to get the desired action. Consider doing this in O(1) with a dictionary of function pointers declared on init, which IMO is more readable:
def __init__(self, context, publish_clock):
...
self.KEY_TO_ACTION = {
Qt.Key.Key_Space: self._timeline.toggle_play,
Qt.Key.Key_Home: self._timeline.navigate_start,
Qt.Key.Key_End: self._handle_end_clicked,
Qt.Key.Key_Plus self._handle_faster_clicked,
Qt.Key.Key_Equal: self._handle_faster_clicked,
Qt.Key.Key_Minus: self._handle_slower_clicked,
Qt.Key.Key_Left: self._timeline.translate_timeline_left,
Qt.Key.Key_Right: self._timeline.translate_timeline_right,
Qt.Key.Key_Up self._handle_zoom_in_clicked,
Qt.Key.Key_PageUp: self._handle_zoom_in_clicked,
Qt.Key.Key_Down: self._handle_zoom_out_clicked,
Qt.Key.Key_PageDown: self._handle_zoom_out_clicked
}
Then you just call this here:
self.KEY_TO_ACTION.get(event.key(), lambda: None)()
| from python_qt_binding import QT_BINDING_VERSION | ||
| from python_qt_binding.QtGui import QIcon | ||
| from python_qt_binding.QtWidgets import QAction, QToolBar | ||
| if Version(QT_BINDING_VERSION) > Version('6.0.0'): |
There was a problem hiding this comment.
Consider try - catch with ImportErrror
asymingt
approved these changes
Mar 26, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.