Fix lint.

This commit is contained in:
Florian Bruhin 2015-05-11 20:32:27 +02:00
parent d3c6ebcf15
commit a36c0fcd4c
5 changed files with 31 additions and 20 deletions

View File

@ -42,7 +42,6 @@ from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils,
objreg, utils) objreg, utils)
from qutebrowser.utils.usertypes import KeyMode from qutebrowser.utils.usertypes import KeyMode
from qutebrowser.misc import editor from qutebrowser.misc import editor
from qutebrowser.keyinput import modeman
class CommandDispatcher: class CommandDispatcher:
@ -1267,9 +1266,11 @@ class CommandDispatcher:
"""Move the cursor or select to the start of next block.""" """Move the cursor or select to the start of next block."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = [QWebPage.MoveToEndOfBlock, QWebPage.MoveToNextLine, QWebPage.MoveToStartOfBlock] act = [QWebPage.MoveToEndOfBlock, QWebPage.MoveToNextLine,
QWebPage.MoveToStartOfBlock]
else: else:
act = [QWebPage.SelectEndOfBlock, QWebPage.SelectNextLine, QWebPage.SelectStartOfBlock] act = [QWebPage.SelectEndOfBlock, QWebPage.SelectNextLine,
QWebPage.SelectStartOfBlock]
for _ in range(count): for _ in range(count):
for a in act: for a in act:
webview.triggerPageAction(a) webview.triggerPageAction(a)
@ -1280,9 +1281,11 @@ class CommandDispatcher:
"""Move the cursor or select to the start of previous block.""" """Move the cursor or select to the start of previous block."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = [QWebPage.MoveToStartOfBlock, QWebPage.MoveToPreviousLine, QWebPage.MoveToStartOfBlock] act = [QWebPage.MoveToStartOfBlock, QWebPage.MoveToPreviousLine,
QWebPage.MoveToStartOfBlock]
else: else:
act = [QWebPage.SelectStartOfBlock, QWebPage.SelectPreviousLine, QWebPage.SelectStartOfBlock] act = [QWebPage.SelectStartOfBlock, QWebPage.SelectPreviousLine,
QWebPage.SelectStartOfBlock]
for _ in range(count): for _ in range(count):
for a in act: for a in act:
webview.triggerPageAction(a) webview.triggerPageAction(a)
@ -1293,9 +1296,11 @@ class CommandDispatcher:
"""Move the cursor or select to the end of next block.""" """Move the cursor or select to the end of next block."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = [QWebPage.MoveToEndOfBlock, QWebPage.MoveToNextLine, QWebPage.MoveToEndOfBlock] act = [QWebPage.MoveToEndOfBlock, QWebPage.MoveToNextLine,
QWebPage.MoveToEndOfBlock]
else: else:
act = [QWebPage.SelectEndOfBlock, QWebPage.SelectNextLine, QWebPage.SelectEndOfBlock] act = [QWebPage.SelectEndOfBlock, QWebPage.SelectNextLine,
QWebPage.SelectEndOfBlock]
for _ in range(count): for _ in range(count):
for a in act: for a in act:
webview.triggerPageAction(a) webview.triggerPageAction(a)
@ -1306,9 +1311,11 @@ class CommandDispatcher:
"""Move the cursor or select to the end of previous block.""" """Move the cursor or select to the end of previous block."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = [QWebPage.MoveToStartOfBlock, QWebPage.MoveToPreviousLine, QWebPage.MoveToEndOfBlock] act = [QWebPage.MoveToStartOfBlock, QWebPage.MoveToPreviousLine,
QWebPage.MoveToEndOfBlock]
else: else:
act = [QWebPage.SelectStartOfBlock, QWebPage.SelectPreviousLine, QWebPage.SelectEndOfBlock] act = [QWebPage.SelectStartOfBlock, QWebPage.SelectPreviousLine,
QWebPage.SelectEndOfBlock]
for _ in range(count): for _ in range(count):
for a in act: for a in act:
webview.triggerPageAction(a) webview.triggerPageAction(a)
@ -1364,8 +1371,10 @@ class CommandDispatcher:
modes=[KeyMode.caret], scope='window') modes=[KeyMode.caret], scope='window')
def toggle_selection(self): def toggle_selection(self):
"""Toggle caret selection mode.""" """Toggle caret selection mode."""
self._current_widget().selection_enabled = not self._current_widget().selection_enabled widget = self._current_widget()
mainwindow = objreg.get('main-window', scope='window', window=self._win_id) widget.selection_enabled = not widget.selection_enabled
mainwindow = objreg.get('main-window', scope='window',
window=self._win_id)
mainwindow.status.on_mode_entered(usertypes.KeyMode.caret) mainwindow.status.on_mode_entered(usertypes.KeyMode.caret)
@cmdutils.register(instance='command-dispatcher', hide=True, @cmdutils.register(instance='command-dispatcher', hide=True,

View File

@ -106,7 +106,7 @@ class WebView(QWebView):
self.keep_icon = False self.keep_icon = False
self.search_text = None self.search_text = None
self.search_flags = 0 self.search_flags = 0
self.selection_enabled = False; self.selection_enabled = False
self.init_neighborlist() self.init_neighborlist()
cfg = objreg.get('config') cfg = objreg.get('config')
cfg.changed.connect(self.init_neighborlist) cfg.changed.connect(self.init_neighborlist)
@ -441,13 +441,14 @@ class WebView(QWebView):
settings.setAttribute(QWebSettings.CaretBrowsingEnabled, True) settings.setAttribute(QWebSettings.CaretBrowsingEnabled, True)
self.selection_enabled = False self.selection_enabled = False
tabbed = objreg.get('tabbed-browser', scope='window', window=self.win_id) tabbed_browser = objreg.get('tabbed-browser', scope='window',
if tabbed.currentWidget().tab_id == self.tab_id: window=self.win_id)
if tabbed_browser.currentWidget().tab_id == self.tab_id:
self.clearFocus() self.clearFocus()
self.setFocus(Qt.OtherFocusReason) self.setFocus(Qt.OtherFocusReason)
self.page().currentFrame().evaluateJavaScript( self.page().currentFrame().evaluateJavaScript(
utils.read_file('javascript/position_caret.js')) utils.read_file('javascript/position_caret.js'))
@pyqtSlot(usertypes.KeyMode) @pyqtSlot(usertypes.KeyMode)
def on_mode_left(self, mode): def on_mode_left(self, mode):
@ -463,7 +464,7 @@ class WebView(QWebView):
# Remove selection if exist # Remove selection if exist
self.triggerPageAction(QWebPage.MoveToNextChar) self.triggerPageAction(QWebPage.MoveToNextChar)
settings.setAttribute(QWebSettings.CaretBrowsingEnabled, False) settings.setAttribute(QWebSettings.CaretBrowsingEnabled, False)
self.selection_enabled = False; self.selection_enabled = False
self.setFocusPolicy(Qt.WheelFocus) self.setFocusPolicy(Qt.WheelFocus)

View File

@ -822,7 +822,8 @@ def data(readonly=False):
('statusbar.bg.caret-selection', ('statusbar.bg.caret-selection',
SettingValue(typ.QssColor(), '#a12dff'), SettingValue(typ.QssColor(), '#a12dff'),
"Background color of the statusbar in caret selection enabled mode."), "Background color of the statusbar in caret mode with a "
"selection"),
('statusbar.progress.bg', ('statusbar.progress.bg',
SettingValue(typ.QssColor(), 'white'), SettingValue(typ.QssColor(), 'white'),

View File

@ -231,4 +231,3 @@ class CaretKeyParser(keyparser.CommandKeyParser):
def __repr__(self): def __repr__(self):
return utils.get_repr(self) return utils.get_repr(self)

View File

@ -270,7 +270,7 @@ class StatusBar(QWidget):
@pyqtProperty(bool) @pyqtProperty(bool)
def caret_selection_active(self): def caret_selection_active(self):
"""Getter for self.caret_selection_active, so it can be used as Qt property.""" """Getter for caret_selection_active, so it can be used as property."""
return self._caret_selection_active return self._caret_selection_active
def _set_mode_active(self, mode, val): def _set_mode_active(self, mode, val):
@ -284,7 +284,8 @@ class StatusBar(QWidget):
self._insert_active = val self._insert_active = val
elif mode == usertypes.KeyMode.caret: elif mode == usertypes.KeyMode.caret:
log.statusbar.debug("Setting caret_active to {}".format(val)) log.statusbar.debug("Setting caret_active to {}".format(val))
webview = objreg.get("tabbed-browser", scope="window", window=self._win_id).currentWidget() webview = objreg.get("tabbed-browser", scope="window",
window=self._win_id).currentWidget()
if val and webview.selection_enabled: if val and webview.selection_enabled:
self._set_mode_text("{} selection".format(mode.name)) self._set_mode_text("{} selection".format(mode.name))
self._caret_selection_active = val self._caret_selection_active = val