From 32a2647942409aba027ccdaf5e6ca0f87fd66c1a Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Fri, 5 Apr 2019 17:23:59 -0700 Subject: Move _on_aborted to slot --- qutebrowser/mainwindow/prompt.py | 22 +++++++++++++--------- tests/end2end/features/downloads.feature | 9 +++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index 166e3f283..d7d34a0cf 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -22,6 +22,7 @@ import os.path import html import collections +import functools import attr from PyQt5.QtCore import (pyqtSlot, pyqtSignal, Qt, QTimer, QDir, QModelIndex, @@ -329,16 +330,10 @@ class PromptContainer(QWidget): log.prompt.debug("Displaying prompt {}".format(prompt)) self._prompt = prompt + # If this question was interrupted, we already connected the signal if not question.interrupted: - # If this question was interrupted, we already connected the signal - def on_aborted(): - try: - modeman.leave(self._win_id, prompt.KEY_MODE, - 'aborted', maybe=True) - except objreg.RegistryUnavailableError: - # window was deleted: ignore - pass - question.aborted.connect(on_aborted) + question.aborted.connect( + functools.partial(self._on_aborted, prompt.KEY_MODE)) modeman.enter(self._win_id, prompt.KEY_MODE, 'question asked') self.setSizePolicy(prompt.sizePolicy()) @@ -348,6 +343,15 @@ class PromptContainer(QWidget): prompt.setFocus() self.update_geometry.emit() + @pyqtSlot() + def _on_aborted(self, key_mode): + """Leave KEY_MODE whenever a prompt is aborted.""" + try: + modeman.leave(self._win_id, key_mode, 'aborted', maybe=True) + except objreg.RegistryUnavailableError: + # window was deleted: ignore + pass + @pyqtSlot(usertypes.KeyMode) def _on_prompt_done(self, key_mode): """Leave the prompt mode in this window if a question was answered.""" diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature index b1d92145d..1ead5a839 100644 --- a/tests/end2end/features/downloads.feature +++ b/tests/end2end/features/downloads.feature @@ -92,6 +92,15 @@ Feature: Downloading things from a website. And I run :leave-mode Then no crash should happen + Scenario: Aborting a download in a different window (issue 3378) + When I set downloads.location.suggestion to filename + And I set downloads.location.prompt to true + And I open data/downloads/download.bin in a new window without waiting + And I wait for "Asking question *" in the log + And I run :window-only + And I run :leave-mode + Then no crash should happen + # https://github.com/qutebrowser/qutebrowser/issues/4240 @qt<5.11.2 Scenario: Downloading with SSL errors (issue 1413) -- cgit v1.2.3-54-g00ecf