From 09f7e7a3ae774390fc01856875908e4190a48d6f Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 7 May 2014 09:03:40 +0200 Subject: [PATCH 1/5] Don't crash when opening qute:pyeval without :pyeval. --- qutebrowser/network/qutescheme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/network/qutescheme.py b/qutebrowser/network/qutescheme.py index db94d3232..8f3be58fa 100644 --- a/qutebrowser/network/qutescheme.py +++ b/qutebrowser/network/qutescheme.py @@ -45,7 +45,7 @@ _HTML_TEMPLATE = """ """ -pyeval_output = None +pyeval_output = ":pyeval was never called" def _get_html(title, snippet): From 19af445da0de2e47f62fa3c67c4bf9afb65d5c6a Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 7 May 2014 09:06:22 +0200 Subject: [PATCH 2/5] TODO += eliding bug --- TODO | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TODO b/TODO index b1007d66b..4c58c1e1b 100644 --- a/TODO +++ b/TODO @@ -62,6 +62,9 @@ Bugs http://pydoc.net/Python/grab/0.4.5/ghost.ghost/ does webview.close(); del self.manager; del self.page; del self.mainframe +- Eliding doesn't work correctly in tabs (cuts off start) + This especially happens when there's no favicon + Style ===== From 68b134b4a91ba3991c5a5b3bd972e57644de9811 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 7 May 2014 17:20:01 +0200 Subject: [PATCH 3/5] Don't filter events if mainwindow is not focused --- TODO | 2 -- qutebrowser/app.py | 8 +------- qutebrowser/keyinput/modeman.py | 7 ++++++- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index 4c58c1e1b..5f62ec30f 100644 --- a/TODO +++ b/TODO @@ -11,8 +11,6 @@ Before 0.1 - Autosave feature (against segfaults/...) - Save tabs feature - More dwb keybindings -- Filter events in QMainWindow, not QApplication - or at least release them when opening other windows, e.g. print dialog - Use :open engine searchterm syntax for searching Crashes diff --git a/qutebrowser/app.py b/qutebrowser/app.py index be935f887..17fa736b1 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -135,6 +135,7 @@ class QuteBrowser(QApplication): self._init_cmds() self.mainwindow = MainWindow() + self.modeman.mainwindow = self.mainwindow self.installEventFilter(self.modeman) self.setQuitOnLastWindowClosed(False) @@ -399,13 +400,6 @@ class QuteBrowser(QApplication): self._quit_status['crash'] = False - # Give key input back for crash dialog - try: - self.removeEventFilter(self.modeman) - except AttributeError: - # self.modeman could be None - pass - if exctype is BdbQuit or not issubclass(exctype, Exception): # pdb exit, KeyboardInterrupt, ... try: diff --git a/qutebrowser/keyinput/modeman.py b/qutebrowser/keyinput/modeman.py index 8abce25dc..14c6eb701 100644 --- a/qutebrowser/keyinput/modeman.py +++ b/qutebrowser/keyinput/modeman.py @@ -62,6 +62,7 @@ class ModeManager(QObject): Attributes: mode: The current mode (readonly property). passthrough: A list of modes in which to pass through events. + mainwindow: The mainwindow object _handlers: A dictionary of modes and their handlers. _mode_stack: A list of the modes we're currently in, with the active one on the right. @@ -84,6 +85,7 @@ class ModeManager(QObject): def __init__(self, parent=None): super().__init__(parent) + self.mainwindow = None self._handlers = {} self.passthrough = [] self._mode_stack = [] @@ -248,7 +250,10 @@ class ModeManager(QObject): logging.debug("Ignoring event {} for {}".format( debug.EVENTS[typ], obj.__class__.__name__)) return False - + if QApplication.instance().activeWindow() is not self.mainwindow: + # Some other window (print dialog, etc.) is focused so we pass + # the event through. + return False logging.debug("Got event {} for {} in mode {}".format( debug.EVENTS[typ], obj.__class__.__name__, self.mode)) From 45621b0645ce8d1f470d08cd0e161edb73835ce3 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 7 May 2014 17:29:28 +0200 Subject: [PATCH 4/5] Do a hard exit on crash --- qutebrowser/app.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 17fa736b1..e4e58a319 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -398,8 +398,6 @@ class QuteBrowser(QApplication): exc = (exctype, excvalue, tb) sys.__excepthook__(*exc) - self._quit_status['crash'] = False - if exctype is BdbQuit or not issubclass(exctype, Exception): # pdb exit, KeyboardInterrupt, ... try: @@ -407,6 +405,9 @@ class QuteBrowser(QApplication): return except Exception: self.quit() + + self._quit_status['crash'] = False + try: pages = self._recover_pages() except Exception: @@ -441,7 +442,9 @@ class QuteBrowser(QApplication): logging.debug("Running {} with args {}".format(sys.executable, argv)) subprocess.Popen(argv) - self._maybe_quit('crash') + # We might risk a segfault here, but that's better than continuing to + # run in some undefined state. + sys.exit(1) def _maybe_quit(self, sender): """Maybe quit qutebrowser. From a76c7b56f12f216cfd84389180dc59b68447d3e0 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 7 May 2014 18:00:38 +0200 Subject: [PATCH 5/5] Fix lingering PyQt exception --- qutebrowser/keyinput/modeman.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/qutebrowser/keyinput/modeman.py b/qutebrowser/keyinput/modeman.py index 14c6eb701..75518f379 100644 --- a/qutebrowser/keyinput/modeman.py +++ b/qutebrowser/keyinput/modeman.py @@ -96,6 +96,18 @@ class ModeManager(QObject): @property def mode(self): """Read-only property for the current mode.""" + # For some reason, on Ubuntu (Python 3.3.2, PyQt 5.0.1, Qt 5.0.2) there + # is a lingering exception here sometimes. With this construct, we + # clear this exception which makes no sense at all anyways. + # Details: + # http://www.riverbankcomputing.com/pipermail/pyqt/2014-May/034196.html + # If we wouldn't clear the exception, we would actually get an + # AttributeError for the mode property in eventFilter because of + # another PyQt oddity. + try: + raise + except: # pylint: disable=bare-except + pass if not self._mode_stack: return None return self._mode_stack[-1] @@ -230,14 +242,7 @@ class ModeManager(QObject): Emit: key_pressed: When a key was actually pressed. """ - if not hasattr(self, 'mode'): - # FIXME I have no idea how this could possibly happen, but on - # Ubuntu it does on startup. - # self.mode is a simple @property and we certainly don't delete it, - # so this all makes no sense at all. - logging.warn("eventFilter called but self.mode doesn't exist!") - return False - elif self.mode is None: + if self.mode is None: # We got events before mode is set, so just pass them through. return False typ = event.type()