From 26604a683b661b61c6110a92e746b10b8a0ac271 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 29 Sep 2014 07:47:32 +0200 Subject: [PATCH] Fix lint --- qutebrowser/utils/objreg.py | 62 ++++++++++++++++++------------- qutebrowser/widgets/completion.py | 6 +-- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/qutebrowser/utils/objreg.py b/qutebrowser/utils/objreg.py index 57aefb135..1aceaedef 100644 --- a/qutebrowser/utils/objreg.py +++ b/qutebrowser/utils/objreg.py @@ -91,6 +91,40 @@ meta_registry['global'] = global_registry window_registry = ObjectRegistry() +def _get_tab_registry(): + """Get the registry of a tab.""" + app = get('app') + win = app.activeWindow() + tabbed_browser = get('tabbed-browser', scope='window', window=win) + widget = tabbed_browser.currentWidget() + if widget is None: + raise RegistryUnavailableError('tab') + try: + return widget.registry + except AttributeError: + raise RegistryUnavailableError('tab') + + +def _get_window_registry(window): + """Get the registry of a window.""" + if window is None: + raise TypeError("window is None with scope window!") + if window is 'current': + app = get('app') + win = app.activeWindow() + if win is None: + raise RegistryUnavailableError('window') + else: + try: + win = window_registry[window] + except KeyError: + raise RegistryUnavailableError('window') + try: + return win.registry + except AttributeError: + raise RegistryUnavailableError('window') + + def _get_registry(scope, window): """Get the correct registry for a given scope.""" if window is not None and scope is not 'window': @@ -98,33 +132,9 @@ def _get_registry(scope, window): if scope == 'global': return global_registry elif scope == 'tab': - app = get('app') - win = app.activeWindow() - tabbed_browser = get('tabbed-browser', scope='window', window=win) - widget = tabbed_browser.currentWidget() - if widget is None: - raise RegistryUnavailableError(scope) - try: - return widget.registry - except AttributeError: - raise RegistryUnavailableError(scope) + return _get_tab_registry() elif scope == 'window': - if window is None: - raise TypeError("window is None with scope window!") - if window is 'current': - app = get('app') - win = app.activeWindow() - if win is None: - raise RegistryUnavailableError(scope) - else: - try: - win = window_registry[window] - except KeyError: - raise RegistryUnavailableError(scope) - try: - return win.registry - except AttributeError: - raise RegistryUnavailableError(scope) + return _get_window_registry(window) elif scope == 'meta': return meta_registry else: diff --git a/qutebrowser/widgets/completion.py b/qutebrowser/widgets/completion.py index f8379147d..815e04992 100644 --- a/qutebrowser/widgets/completion.py +++ b/qutebrowser/widgets/completion.py @@ -228,9 +228,9 @@ class CompletionView(QTreeView): def selectionChanged(self, selected, deselected): """Extend selectionChanged to call completers selection_changed.""" super().selectionChanged(selected, deselected) - completer = objreg.get('completer', scope='window', - window=self._win_id) - completer.selection_changed(selected, deselected) + completer_obj = objreg.get('completer', scope='window', + window=self._win_id) + completer_obj.selection_changed(selected, deselected) def resizeEvent(self, e): """Extend resizeEvent to adjust column size."""