Fix skip_if_selection_is_empty() for triggers

It seems to be enough if one decorator calls pyqtSlot(), but to avoid
problems in the future, let's have all decorators do that.
This commit is contained in:
RumovZ 2021-04-25 19:50:56 +02:00
parent 09629e4e4a
commit 9900f73cee
2 changed files with 18 additions and 11 deletions

View file

@ -72,6 +72,7 @@ from aqt.utils import (
showInfo,
showWarning,
skip_if_selection_is_empty,
skip_if_selection_is_empty_on_trigger,
tooltip,
tr,
)
@ -574,7 +575,7 @@ where id in %s"""
# Misc menu options
######################################################################
@skip_if_selection_is_empty
@skip_if_selection_is_empty_on_trigger
@ensure_editor_saved_on_trigger
def onChangeModel(self) -> None:
ChangeModel(self, self.oneModelNotes())
@ -619,7 +620,7 @@ where id in %s"""
# Card deletion
######################################################################
@skip_if_selection_is_empty
@skip_if_selection_is_empty_on_trigger
def delete_selected_notes(self) -> None:
# ensure deletion is not accidentally triggered when the user is focused
# in the editing screen or search bar
@ -641,7 +642,7 @@ where id in %s"""
# Deck change
######################################################################
@skip_if_selection_is_empty
@skip_if_selection_is_empty_on_trigger
@ensure_editor_saved_on_trigger
def set_deck_of_selected_cards(self) -> None:
from aqt.studydeck import StudyDeck
@ -670,7 +671,7 @@ where id in %s"""
# Tags
######################################################################
@skip_if_selection_is_empty
@skip_if_selection_is_empty_on_trigger
@ensure_editor_saved_on_trigger
def add_tags_to_selected_notes(
self,
@ -683,7 +684,7 @@ where id in %s"""
parent=self, note_ids=self.selected_notes(), space_separated_tags=tags
).run_in_background(initiator=self)
@skip_if_selection_is_empty
@skip_if_selection_is_empty_on_trigger
@ensure_editor_saved_on_trigger
def remove_tags_from_selected_notes(self, tags: Optional[str] = None) -> None:
"Shows prompt if tags not provided."
@ -730,7 +731,7 @@ where id in %s"""
# Exporting
######################################################################
@skip_if_selection_is_empty
@skip_if_selection_is_empty_on_trigger
def _on_export_notes(self) -> None:
cids = self.selectedNotesAsCards()
ExportDialog(self.mw, cids=list(cids))
@ -781,7 +782,7 @@ where id in %s"""
# Scheduling
######################################################################
@skip_if_selection_is_empty
@skip_if_selection_is_empty_on_trigger
@ensure_editor_saved_on_trigger
def reposition(self) -> None:
if self.card and self.card.queue != QUEUE_TYPE_NEW:
@ -793,7 +794,7 @@ where id in %s"""
):
op.run_in_background()
@skip_if_selection_is_empty
@skip_if_selection_is_empty_on_trigger
@ensure_editor_saved_on_trigger
def set_due_date(self) -> None:
if op := set_due_date_dialog(
@ -803,7 +804,7 @@ where id in %s"""
):
op.run_in_background()
@skip_if_selection_is_empty
@skip_if_selection_is_empty_on_trigger
@ensure_editor_saved_on_trigger
def forget_cards(self) -> None:
forget_cards(
@ -814,7 +815,7 @@ where id in %s"""
# Edit: selection
######################################################################
@skip_if_selection_is_empty
@skip_if_selection_is_empty_on_trigger
@ensure_editor_saved_on_trigger
def selectNotes(self) -> None:
nids = self.selected_notes()
@ -863,7 +864,7 @@ where id in %s"""
# Edit: replacing
######################################################################
@skip_if_selection_is_empty
@skip_if_selection_is_empty_on_trigger
@ensure_editor_saved_on_trigger
def onFindReplace(self) -> None:
FindAndReplaceDialog(self, mw=self.mw, note_ids=self.selected_notes())

View file

@ -1022,6 +1022,12 @@ def skip_if_selection_is_empty(func: Callable) -> Callable:
return decorated
def skip_if_selection_is_empty_on_trigger(func: Callable) -> Callable:
"""Like skip_if_selection_is_empty(), but tells Qt this function takes no args."""
return pyqtSlot()(skip_if_selection_is_empty(func)) # type: ignore
class KeyboardModifiersPressed:
"Util for type-safe checks of currently-pressed modifier keys."