Use EventLoop which raises an Exception on double exec_()

This commit is contained in:
Florian Bruhin 2014-06-14 21:00:08 +02:00
parent e453d9c8ca
commit 392784213b
2 changed files with 23 additions and 4 deletions

View File

@ -32,7 +32,7 @@ from urllib.parse import urljoin, urlencode
from functools import reduce from functools import reduce
from distutils.version import StrictVersion as Version from distutils.version import StrictVersion as Version
from PyQt5.QtCore import QCoreApplication, QStandardPaths, qVersion from PyQt5.QtCore import QCoreApplication, QStandardPaths, QEventLoop, qVersion
from PyQt5.QtGui import QColor from PyQt5.QtGui import QColor
from pkg_resources import resource_string from pkg_resources import resource_string
@ -384,3 +384,21 @@ def format_size(size, base=1024, suffix=''):
return '{:.02f}{}{}'.format(size, p, suffix) return '{:.02f}{}{}'.format(size, p, suffix)
size /= base size /= base
return '{:.02f}{}{}'.format(size, prefixes[-1], suffix) return '{:.02f}{}{}'.format(size, prefixes[-1], suffix)
class EventLoop(QEventLoop):
"""A thin wrapper around QEventLoop which raises an exception when doing
exec_() multiple times.
"""
def __init__(self, parent=None):
super().__init__(parent)
self._executing = False
def exec_(self, flags=QEventLoop.AllEvents):
if self._executing:
raise AssertionError("Eventloop is already running!")
self._executing = True
super().exec_(flags)
self._executing = False

View File

@ -17,7 +17,7 @@
"""Prompt shown in the statusbar.""" """Prompt shown in the statusbar."""
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QEventLoop from PyQt5.QtCore import pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import QHBoxLayout, QWidget, QLineEdit from PyQt5.QtWidgets import QHBoxLayout, QWidget, QLineEdit
import qutebrowser.keyinput.modeman as modeman import qutebrowser.keyinput.modeman as modeman
@ -25,6 +25,7 @@ import qutebrowser.commands.utils as cmdutils
from qutebrowser.widgets.statusbar.textbase import TextBase from qutebrowser.widgets.statusbar.textbase import TextBase
from qutebrowser.widgets.misc import MinimalLineEdit from qutebrowser.widgets.misc import MinimalLineEdit
from qutebrowser.utils.usertypes import PromptMode, Question from qutebrowser.utils.usertypes import PromptMode, Question
from qutebrowser.utils.misc import EventLoop
class Prompt(QWidget): class Prompt(QWidget):
@ -33,7 +34,7 @@ class Prompt(QWidget):
Attributes: Attributes:
question: A Question object with the question to be asked to the user. question: A Question object with the question to be asked to the user.
loop: A local QEventLoop to spin in exec_. loop: A local EventLoop to spin in exec_.
_hbox: The QHBoxLayout used to display the text and prompt. _hbox: The QHBoxLayout used to display the text and prompt.
_txt: The TextBase instance (QLabel) used to display the prompt text. _txt: The TextBase instance (QLabel) used to display the prompt text.
_input: The MinimalLineEdit instance (QLineEdit) used for the input. _input: The MinimalLineEdit instance (QLineEdit) used for the input.
@ -50,7 +51,7 @@ class Prompt(QWidget):
super().__init__(parent) super().__init__(parent)
self.question = None self.question = None
self.loop = QEventLoop() self.loop = EventLoop()
self._hbox = QHBoxLayout(self) self._hbox = QHBoxLayout(self)
self._hbox.setContentsMargins(0, 0, 0, 0) self._hbox.setContentsMargins(0, 0, 0, 0)