Fix lint.

This commit is contained in:
Florian Bruhin 2015-04-28 16:50:42 +02:00
parent 9e8c781871
commit 32562c6878
7 changed files with 83 additions and 95 deletions

View File

@ -40,6 +40,7 @@ from qutebrowser.config import config, configexc
from qutebrowser.browser import webelem, inspector
from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils,
objreg, utils)
from qutebrowser.utils.usertypes import KeyMode
from qutebrowser.misc import editor
from qutebrowser.keyinput import modeman
@ -1031,8 +1032,7 @@ class CommandDispatcher:
self._open(url, tab, bg, window)
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.insert],
hide=True, scope='window')
modes=[KeyMode.insert], hide=True, scope='window')
def open_editor(self):
"""Open an external editor with the currently selected form field.
@ -1152,166 +1152,153 @@ class CommandDispatcher:
for _ in range(count):
view.search(view.search_text, flags)
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.caret, usertypes.KeyMode.visual],
hide=True, scope='window')
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret, KeyMode.visual], scope='window')
def move_to_next_line(self):
"""Move the cursor or select to the next line."""
modemanager = modeman._get_modeman(self._win_id)
if modemanager.mode == usertypes.KeyMode.caret:
modemanager = modeman.get_modeman(self._win_id)
if modemanager.mode == KeyMode.caret:
act = QWebPage.MoveToNextLine
else:
act = QWebPage.SelectNextLine
self._current_widget().triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.caret, usertypes.KeyMode.visual],
hide=True, scope='window')
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret, KeyMode.visual], scope='window')
def move_to_prev_line(self):
"""Move the cursor or select to the prev line."""
modemanager = modeman._get_modeman(self._win_id)
if modemanager.mode == usertypes.KeyMode.caret:
modemanager = modeman.get_modeman(self._win_id)
if modemanager.mode == KeyMode.caret:
act = QWebPage.MoveToPreviousLine
else:
act = QWebPage.SelectPreviousLine
self._current_widget().triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.caret, usertypes.KeyMode.visual],
hide=True, scope='window')
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret, KeyMode.visual], scope='window')
def move_to_next_char(self):
"""Move the cursor or select to the next char."""
modemanager = modeman._get_modeman(self._win_id)
if modemanager.mode == usertypes.KeyMode.caret:
modemanager = modeman.get_modeman(self._win_id)
if modemanager.mode == KeyMode.caret:
act = QWebPage.MoveToNextChar
else:
act = QWebPage.SelectNextChar
self._current_widget().triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.caret, usertypes.KeyMode.visual],
hide=True, scope='window')
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret, KeyMode.visual], scope='window')
def move_to_prev_char(self):
"""Move the cursor or select to the prev char."""
modemanager = modeman._get_modeman(self._win_id)
if modemanager.mode == usertypes.KeyMode.caret:
modemanager = modeman.get_modeman(self._win_id)
if modemanager.mode == KeyMode.caret:
act = QWebPage.MoveToPreviousChar
else:
act = QWebPage.SelectPreviousChar
self._current_widget().triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.caret, usertypes.KeyMode.visual],
hide=True, scope='window')
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret, KeyMode.visual], scope='window')
def move_to_end_of_word(self):
"""Move the cursor or select to the next word."""
modemanager = modeman._get_modeman(self._win_id)
if modemanager.mode == usertypes.KeyMode.caret:
modemanager = modeman.get_modeman(self._win_id)
if modemanager.mode == KeyMode.caret:
act = QWebPage.MoveToNextWord
else:
act = QWebPage.SelectNextWord
self._current_widget().triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.caret, usertypes.KeyMode.visual],
hide=True, scope='window')
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret, KeyMode.visual],
scope='window')
def move_to_next_word(self):
"""Move the cursor or select to the next word."""
modemanager = modeman._get_modeman(self._win_id)
if modemanager.mode == usertypes.KeyMode.caret:
modemanager = modeman.get_modeman(self._win_id)
if modemanager.mode == KeyMode.caret:
act = [QWebPage.MoveToNextWord, QWebPage.MoveToNextChar]
else:
act = [QWebPage.SelectNextWord, QWebPage.SelectNextChar]
for a in act:
self._current_widget().triggerPageAction(a)
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.caret, usertypes.KeyMode.visual],
hide=True, scope='window')
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret, KeyMode.visual], scope='window')
def move_to_prev_word(self):
"""Move the cursor or select to the prev word."""
modemanager = modeman._get_modeman(self._win_id)
if modemanager.mode == usertypes.KeyMode.caret:
modemanager = modeman.get_modeman(self._win_id)
if modemanager.mode == KeyMode.caret:
act = QWebPage.MoveToPreviousWord
else:
act = QWebPage.SelectPreviousWord
self._current_widget().triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.caret, usertypes.KeyMode.visual],
hide=True, scope='window')
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret, KeyMode.visual], scope='window')
def move_to_start_of_line(self):
"""Move the cursor or select to the start of line."""
modemanager = modeman._get_modeman(self._win_id)
if modemanager.mode == usertypes.KeyMode.caret:
modemanager = modeman.get_modeman(self._win_id)
if modemanager.mode == KeyMode.caret:
act = QWebPage.MoveToStartOfLine
else:
act = QWebPage.SelectStartOfLine
self._current_widget().triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.caret, usertypes.KeyMode.visual],
hide=True, scope='window')
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret, KeyMode.visual], scope='window')
def move_to_end_of_line(self):
"""Move the cursor or select to the end of line."""
modemanager = modeman._get_modeman(self._win_id)
if modemanager.mode == usertypes.KeyMode.caret:
modemanager = modeman.get_modeman(self._win_id)
if modemanager.mode == KeyMode.caret:
act = QWebPage.MoveToEndOfLine
else:
act = QWebPage.SelectEndOfLine
self._current_widget().triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.caret, usertypes.KeyMode.visual],
hide=True, scope='window')
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret, KeyMode.visual], scope='window')
def move_to_start_of_block(self):
"""Move the cursor or select to the start of block."""
modemanager = modeman._get_modeman(self._win_id)
if modemanager.mode == usertypes.KeyMode.caret:
modemanager = modeman.get_modeman(self._win_id)
if modemanager.mode == KeyMode.caret:
act = QWebPage.MoveToStartOfBlock
else:
act = QWebPage.SelectStartOfBlock
self._current_widget().triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.caret, usertypes.KeyMode.visual],
hide=True, scope='window')
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret, KeyMode.visual], scope='window')
def move_to_end_of_block(self):
"""Move the cursor or select to the end of block."""
modemanager = modeman._get_modeman(self._win_id)
if modemanager.mode == usertypes.KeyMode.caret:
modemanager = modeman.get_modeman(self._win_id)
if modemanager.mode == KeyMode.caret:
act = QWebPage.MoveToEndOfBlock
else:
act = QWebPage.SelectEndOfBlock
self._current_widget().triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.caret, usertypes.KeyMode.visual],
hide=True, scope='window')
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret, KeyMode.visual], scope='window')
def move_to_start_of_document(self):
"""Move the cursor or select to the start of document."""
modemanager = modeman._get_modeman(self._win_id)
if modemanager.mode == usertypes.KeyMode.caret:
modemanager = modeman.get_modeman(self._win_id)
if modemanager.mode == KeyMode.caret:
act = QWebPage.MoveToStartOfDocument
else:
act = QWebPage.SelectStartOfDocument
self._current_widget().triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.caret, usertypes.KeyMode.visual],
hide=True, scope='window')
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret, KeyMode.visual], scope='window')
def move_to_end_of_document(self):
"""Move the cursor or select to the end of document."""
modemanager = modeman._get_modeman(self._win_id)
if modemanager.mode == usertypes.KeyMode.caret:
modemanager = modeman.get_modeman(self._win_id)
if modemanager.mode == KeyMode.caret:
act = QWebPage.MoveToEndOfDocument
else:
act = QWebPage.SelectEndOfDocument
self._current_widget().triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.visual],
hide=True, scope='window')
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.visual], scope='window')
def yank_selected(self, sel=False):
"""Yank selected text to the clipboard or primary selection.
@ -1332,12 +1319,11 @@ class CommandDispatcher:
target = "clipboard"
log.misc.debug("Yanking to {}: '{}'".format(target, s))
clipboard.setText(s, mode)
message.info(self._win_id, "{} {} yanked to {}"
.format(len(s), "char" if len(s) == 1 else "chars", target))
message.info(self._win_id, "{} {} yanked to {}".format(
len(s), "char" if len(s) == 1 else "chars", target))
@cmdutils.register(instance='command-dispatcher',
modes=[usertypes.KeyMode.visual],
hide=True, scope='window')
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.visual], scope='window')
def drop_selection(self):
"""Drop selection and stay in visual mode."""
self._current_widget().triggerPageAction(QWebPage.MoveToNextChar)

View File

@ -23,11 +23,10 @@ import sys
import itertools
import functools
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QTimer, QUrl, QPoint
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QTimer, QUrl
from PyQt5.QtWidgets import QApplication, QStyleFactory
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
from PyQt5.QtGui import QMouseEvent
from qutebrowser.config import config
from qutebrowser.keyinput import modeman
@ -437,7 +436,8 @@ class WebView(QWebView):
"entered.".format(mode))
self.setFocusPolicy(Qt.NoFocus)
elif mode in (usertypes.KeyMode.caret, usertypes.KeyMode.visual):
self.settings().setAttribute(QWebSettings.CaretBrowsingEnabled, True)
settings = self.settings()
settings.setAttribute(QWebSettings.CaretBrowsingEnabled, True)
self.clearFocus()
self.setFocus(Qt.OtherFocusReason)
@ -449,11 +449,12 @@ class WebView(QWebView):
log.webview.debug("Restoring focus policy because mode {} was "
"left.".format(mode))
elif mode in (usertypes.KeyMode.caret, usertypes.KeyMode.visual):
if self.settings().testAttribute(QWebSettings.CaretBrowsingEnabled):
settings = self.settings()
if settings.testAttribute(QWebSettings.CaretBrowsingEnabled):
if mode == usertypes.KeyMode.visual and self.hasSelection():
# Remove selection if exist
self.triggerPageAction(QWebPage.MoveToNextChar)
self.settings().setAttribute(QWebSettings.CaretBrowsingEnabled, False)
settings.setAttribute(QWebSettings.CaretBrowsingEnabled, False)
self.setFocusPolicy(Qt.WheelFocus)

View File

@ -817,12 +817,12 @@ def data(readonly=False):
"Background color of the statusbar in insert mode."),
('statusbar.bg.caret',
SettingValue(typ.QssColor(), 'purple'),
"Background color of the statusbar in caret mode."),
SettingValue(typ.QssColor(), 'purple'),
"Background color of the statusbar in caret mode."),
('statusbar.bg.visual',
SettingValue(typ.QssColor(), '#a12dff'),
"Background color of the statusbar in visual mode."),
SettingValue(typ.QssColor(), '#a12dff'),
"Background color of the statusbar in visual mode."),
('statusbar.progress.bg',
SettingValue(typ.QssColor(), 'white'),

View File

@ -24,7 +24,6 @@ import functools
from PyQt5.QtCore import pyqtSignal, Qt, QObject, QEvent
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebKitWidgets import QWebView
from PyQt5.QtWebKit import QWebSettings
from qutebrowser.keyinput import modeparsers, keyparser
from qutebrowser.config import config
@ -100,25 +99,25 @@ def init(win_id, parent):
return modeman
def _get_modeman(win_id):
def get_modeman(win_id):
"""Get a modemanager object."""
return objreg.get('mode-manager', scope='window', window=win_id)
def enter(win_id, mode, reason=None, only_if_normal=False):
"""Enter the mode 'mode'."""
_get_modeman(win_id).enter(mode, reason, only_if_normal)
get_modeman(win_id).enter(mode, reason, only_if_normal)
def leave(win_id, mode, reason=None):
"""Leave the mode 'mode'."""
_get_modeman(win_id).leave(mode, reason)
get_modeman(win_id).leave(mode, reason)
def maybe_leave(win_id, mode, reason=None):
"""Convenience method to leave 'mode' without exceptions."""
try:
_get_modeman(win_id).leave(mode, reason)
get_modeman(win_id).leave(mode, reason)
except NotInModeError as e:
# This is rather likely to happen, so we only log to debug log.
log.modes.debug("{} (leave reason: {})".format(e, reason))

View File

@ -219,6 +219,7 @@ class HintKeyParser(keyparser.CommandKeyParser):
window=self._win_id, tab='current')
hintmanager.handle_partial_key(keystr)
class CaretKeyParser(keyparser.CommandKeyParser):
"""KeyParser for Caret mode."""
@ -231,6 +232,7 @@ class CaretKeyParser(keyparser.CommandKeyParser):
def __repr__(self):
return utils.get_repr(self)
class VisualKeyParser(keyparser.CommandKeyParser):
"""KeyParser for Visual mode."""

View File

@ -274,7 +274,7 @@ class StatusBar(QWidget):
return self._visual_active
def _set_mode_active(self, mode, val):
"""Setter for self.insert_active, self.caret_active or self.visual_active.
"""Setter for self.{insert,caret,visual}_active.
Re-set the stylesheet after setting the value, so everything gets
updated by Qt properly.
@ -465,8 +465,8 @@ class StatusBar(QWidget):
window=self._win_id)
if mode in mode_manager.passthrough:
self._set_mode_text(mode.name)
if mode in (usertypes.KeyMode.insert, usertypes.KeyMode.caret,
usertypes.KeyMode.visual):
if mode in (usertypes.KeyMode.insert, usertypes.KeyMode.caret,
usertypes.KeyMode.visual):
self._set_mode_active(mode, True)
@pyqtSlot(usertypes.KeyMode, usertypes.KeyMode)
@ -479,8 +479,8 @@ class StatusBar(QWidget):
self._set_mode_text(new_mode.name)
else:
self.txt.set_text(self.txt.Text.normal, '')
if old_mode in (usertypes.KeyMode.insert, usertypes.KeyMode.caret,
usertypes.KeyMode.visual):
if old_mode in (usertypes.KeyMode.insert, usertypes.KeyMode.caret,
usertypes.KeyMode.visual):
self._set_mode_active(old_mode, False)
@config.change_filter('ui', 'message-timeout')

View File

@ -519,7 +519,7 @@ class TabbedBrowser(tabwidget.TabWidget):
log.modes.debug("Current tab changed, focusing {!r}".format(tab))
tab.setFocus()
for mode in (usertypes.KeyMode.hint, usertypes.KeyMode.insert,
usertypes.KeyMode.caret, usertypes.KeyMode.visual):
usertypes.KeyMode.caret, usertypes.KeyMode.visual):
modeman.maybe_leave(self._win_id, mode, 'tab changed')
if self._now_focused is not None:
objreg.register('last-focused-tab', self._now_focused, update=True,