-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If you have two shortcuts that point to the same key combo, you'll get "QAction::event: Ambiguous shortcut overload: <sequence>" in the logs and neither action will be taken. Centralize them in one place so it's easy for humans to spot duplicates. A test verifies uniqueness as well. A semgrep rule enforces that people use the new Shortcuts enum instead of just writing the sequence in the function call directly.
- Loading branch information
Showing
6 changed files
with
38 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 @@ | ||
from enum import Enum | ||
|
||
from PyQt5.QtCore import Qt | ||
|
||
|
||
class Shortcuts(Enum): | ||
"""Central listing of all keyboard shortcuts""" | ||
|
||
DOWNLOAD_CONVERSATION = Qt.CTRL + Qt.Key_D | ||
QUIT = Qt.CTRL + Qt.Key_Q # Same as QKeySequence.Quit | ||
SEND = Qt.CTRL + Qt.Key_Return |
This file contains 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 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 @@ | ||
from securedrop_client.gui.shortcuts import Shortcuts | ||
|
||
|
||
def test_all_values_are_unique(): | ||
# Get all the values in the enum | ||
enum_values = [] | ||
for value in Shortcuts.__members__.values(): | ||
enum_values.append(value.value) | ||
|
||
# Check that all values are unique | ||
assert len(enum_values) == len(set(enum_values)), "Enum values are not unique" |