From 846e7cd4aa7a5ee8aec54a6e087dc53681ae77ab Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 18 Mar 2021 10:54:02 +1000 Subject: [PATCH] tweak hook names --- qt/aqt/browser.py | 12 ++++++------ qt/aqt/main.py | 4 ++-- qt/tools/genhooks_gui.py | 34 +++++++++++++++++----------------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 437a83377..0770cd1a4 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -514,12 +514,12 @@ class Browser(QMainWindow): gui_hooks.browser_will_show(self) self.show() - def on_operations_will_execute(self) -> None: + def on_backend_will_block(self) -> None: # make sure the card list doesn't try to refresh itself during the operation, # as that will block the UI self.model.block_updates = True - def on_operations_did_execute(self) -> None: + def on_backend_did_block(self) -> None: self.model.block_updates = False def on_operation_did_execute(self, changes: OpChanges) -> None: @@ -1424,8 +1424,8 @@ where id in %s""" # fixme: remove these once all items are using `operation_did_execute` gui_hooks.sidebar_should_refresh_decks.append(self.on_item_added) gui_hooks.sidebar_should_refresh_notetypes.append(self.on_item_added) - gui_hooks.operations_will_execute.append(self.on_operations_will_execute) - gui_hooks.operations_did_execute.append(self.on_operations_did_execute) + gui_hooks.backend_will_block.append(self.on_backend_will_block) + gui_hooks.backend_did_block.append(self.on_backend_did_block) gui_hooks.operation_did_execute.append(self.on_operation_did_execute) gui_hooks.focus_did_change.append(self.on_focus_change) @@ -1433,8 +1433,8 @@ where id in %s""" gui_hooks.undo_state_did_change.remove(self.onUndoState) gui_hooks.sidebar_should_refresh_decks.remove(self.on_item_added) gui_hooks.sidebar_should_refresh_notetypes.remove(self.on_item_added) - gui_hooks.operations_will_execute.remove(self.on_operations_will_execute) - gui_hooks.operations_did_execute.remove(self.on_operations_will_execute) + gui_hooks.backend_will_block.remove(self.on_backend_will_block) + gui_hooks.backend_did_block.remove(self.on_backend_will_block) gui_hooks.operation_did_execute.remove(self.on_operation_did_execute) gui_hooks.focus_did_change.remove(self.on_focus_change) diff --git a/qt/aqt/main.py b/qt/aqt/main.py index 6667e6048..79eb3041d 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -823,13 +823,13 @@ class AnkiQt(QMainWindow): def _increase_background_ops(self) -> None: if not self._background_op_count: - gui_hooks.operations_will_execute() + gui_hooks.backend_will_block() self._background_op_count += 1 def _decrease_background_ops(self) -> None: self._background_op_count -= 1 if not self._background_op_count: - gui_hooks.operations_did_execute() + gui_hooks.backend_did_block() assert self._background_op_count >= 0 def _fire_change_hooks_after_op_performed( diff --git a/qt/tools/genhooks_gui.py b/qt/tools/genhooks_gui.py index 692caa9ec..5e950eb93 100644 --- a/qt/tools/genhooks_gui.py +++ b/qt/tools/genhooks_gui.py @@ -399,21 +399,6 @@ hooks = [ New code should use `operation_did_execute` instead. """, ), - Hook( - name="operations_will_execute", - doc="""Called before one or more operations are executed with mw.perform_op(). - - Subscribers can use this to set a flag to avoid DB updates until the operation - completes, as doing so will freeze the UI. - """, - ), - Hook( - name="operations_did_execute", - doc="""Called after one or more operations are executed with mw.perform_op(). - Called regardless of the success of individual operations, and only called when - there are no outstanding ops. - """, - ), Hook( name="operation_did_execute", args=[ @@ -422,8 +407,7 @@ hooks = [ doc="""Called after an operation completes. Changes can be inspected to determine whether the UI needs updating. - This will also be called when the legacy mw.reset() is used. When called via - mw.reset(), `operation_will_execute` will not be called. + This will also be called when the legacy mw.reset() is used. """, ), Hook( @@ -435,6 +419,22 @@ hooks = [ doc="""Called each time the focus changes. Can be used to defer updates from `operation_did_execute` until a window is brought to the front.""", ), + Hook( + name="backend_will_block", + doc="""Called before one or more operations are executed with mw.perform_op(). + + Subscribers can use this to set a flag to avoid DB queries until the operation + completes, as doing so will freeze the UI until the long-running operation + completes. + """, + ), + Hook( + name="backend_did_block", + doc="""Called after one or more operations are executed with mw.perform_op(). + Called regardless of the success of individual operations, and only called when + there are no outstanding ops. + """, + ), # Webview ################### Hook(