pep8 fixes
This commit is contained in:
parent
9caebdda3b
commit
6f3a2448ba
@ -1 +1 @@
|
|||||||
|
"""A vim like browser based on Qt"""
|
||||||
|
@ -13,6 +13,7 @@ from qutebrowser.widgets.mainwindow import MainWindow
|
|||||||
from qutebrowser.commands.keys import KeyParser
|
from qutebrowser.commands.keys import KeyParser
|
||||||
from qutebrowser.utils.appdirs import AppDirs
|
from qutebrowser.utils.appdirs import AppDirs
|
||||||
|
|
||||||
|
|
||||||
class QuteBrowser(QApplication):
|
class QuteBrowser(QApplication):
|
||||||
"""Main object for QuteBrowser"""
|
"""Main object for QuteBrowser"""
|
||||||
dirs = None # AppDirs - config/cache directories
|
dirs = None # AppDirs - config/cache directories
|
||||||
|
@ -19,79 +19,95 @@ A command class can set the following properties:
|
|||||||
|
|
||||||
from qutebrowser.commands.utils import Command
|
from qutebrowser.commands.utils import Command
|
||||||
|
|
||||||
|
|
||||||
class Open(Command):
|
class Open(Command):
|
||||||
nargs = 1
|
nargs = 1
|
||||||
split_args = False
|
split_args = False
|
||||||
desc = 'Open a page'
|
desc = 'Open a page'
|
||||||
|
|
||||||
|
|
||||||
class TabOpen(Command):
|
class TabOpen(Command):
|
||||||
nargs = 1
|
nargs = 1
|
||||||
split_args = False
|
split_args = False
|
||||||
desc = 'Open a page in a new tab'
|
desc = 'Open a page in a new tab'
|
||||||
|
|
||||||
|
|
||||||
class TabClose(Command):
|
class TabClose(Command):
|
||||||
nargs = 0
|
nargs = 0
|
||||||
desc = 'Close the current tab'
|
desc = 'Close the current tab'
|
||||||
# FIXME also close [count]th tab
|
# FIXME also close [count]th tab
|
||||||
|
|
||||||
|
|
||||||
class TabNext(Command):
|
class TabNext(Command):
|
||||||
nargs = 0
|
nargs = 0
|
||||||
desc = 'Switch to the next tab'
|
desc = 'Switch to the next tab'
|
||||||
# FIXME also support [count]
|
# FIXME also support [count]
|
||||||
|
|
||||||
|
|
||||||
class TabPrev(Command):
|
class TabPrev(Command):
|
||||||
nargs = 0
|
nargs = 0
|
||||||
desc = 'Switch to the previous tab'
|
desc = 'Switch to the previous tab'
|
||||||
# FIXME also support [count]
|
# FIXME also support [count]
|
||||||
|
|
||||||
|
|
||||||
class Quit(Command):
|
class Quit(Command):
|
||||||
name = ['quit', 'q']
|
name = ['quit', 'q']
|
||||||
nargs = 0
|
nargs = 0
|
||||||
desc = 'Quit qutebrowser'
|
desc = 'Quit qutebrowser'
|
||||||
|
|
||||||
|
|
||||||
class Reload(Command):
|
class Reload(Command):
|
||||||
nargs = 0
|
nargs = 0
|
||||||
desc = 'Reload the current page'
|
desc = 'Reload the current page'
|
||||||
|
|
||||||
|
|
||||||
class Stop(Command):
|
class Stop(Command):
|
||||||
nargs = 0
|
nargs = 0
|
||||||
desc = 'Stop loading the current page'
|
desc = 'Stop loading the current page'
|
||||||
|
|
||||||
|
|
||||||
class Back(Command):
|
class Back(Command):
|
||||||
nargs = 0
|
nargs = 0
|
||||||
desc = 'Go back one page in the history'
|
desc = 'Go back one page in the history'
|
||||||
# FIXME also support [count]
|
# FIXME also support [count]
|
||||||
|
|
||||||
|
|
||||||
class Forward(Command):
|
class Forward(Command):
|
||||||
nargs = 0
|
nargs = 0
|
||||||
desc = 'Go forward one page in the history'
|
desc = 'Go forward one page in the history'
|
||||||
# FIXME also support [count]
|
# FIXME also support [count]
|
||||||
|
|
||||||
|
|
||||||
class Print(Command):
|
class Print(Command):
|
||||||
nargs = 0
|
nargs = 0
|
||||||
desc = 'Print the current page'
|
desc = 'Print the current page'
|
||||||
|
|
||||||
|
|
||||||
class Scroll(Command):
|
class Scroll(Command):
|
||||||
nargs = 2
|
nargs = 2
|
||||||
count = True
|
count = True
|
||||||
hide = True
|
hide = True
|
||||||
|
|
||||||
|
|
||||||
class Undo(Command):
|
class Undo(Command):
|
||||||
nargs = 0
|
nargs = 0
|
||||||
desc = 'Undo closing a tab'
|
desc = 'Undo closing a tab'
|
||||||
|
|
||||||
|
|
||||||
class ScrollPercX(Command):
|
class ScrollPercX(Command):
|
||||||
nargs = '?'
|
nargs = '?'
|
||||||
count = True
|
count = True
|
||||||
hide = True
|
hide = True
|
||||||
name = 'scroll_perc_x'
|
name = 'scroll_perc_x'
|
||||||
|
|
||||||
|
|
||||||
class ScrollPercY(Command):
|
class ScrollPercY(Command):
|
||||||
nargs = '?'
|
nargs = '?'
|
||||||
count = True
|
count = True
|
||||||
hide = True
|
hide = True
|
||||||
name = 'scroll_perc_y'
|
name = 'scroll_perc_y'
|
||||||
|
|
||||||
|
|
||||||
class PyEval(Command):
|
class PyEval(Command):
|
||||||
nargs = 1
|
nargs = 1
|
||||||
split_args = False
|
split_args = False
|
||||||
|
@ -6,6 +6,7 @@ from PyQt5.QtCore import QObject, pyqtSignal
|
|||||||
from qutebrowser.commands.utils import (CommandParser, ArgumentCountError,
|
from qutebrowser.commands.utils import (CommandParser, ArgumentCountError,
|
||||||
NoSuchCommandError)
|
NoSuchCommandError)
|
||||||
|
|
||||||
|
|
||||||
class KeyParser(QObject):
|
class KeyParser(QObject):
|
||||||
"""Parser for vim-like key sequences"""
|
"""Parser for vim-like key sequences"""
|
||||||
keystring = '' # The currently entered key sequence
|
keystring = '' # The currently entered key sequence
|
||||||
|
@ -10,12 +10,15 @@ from qutebrowser.utils.completion import CompletionModel
|
|||||||
|
|
||||||
cmd_dict = {}
|
cmd_dict = {}
|
||||||
|
|
||||||
|
|
||||||
class ArgumentCountError(TypeError):
|
class ArgumentCountError(TypeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NoSuchCommandError(ValueError):
|
class NoSuchCommandError(ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def register_all():
|
def register_all():
|
||||||
"""Register and initialize all commands."""
|
"""Register and initialize all commands."""
|
||||||
# We do this here to avoid a circular import, since commands.commands
|
# We do this here to avoid a circular import, since commands.commands
|
||||||
@ -32,6 +35,7 @@ def register_all():
|
|||||||
for n in names:
|
for n in names:
|
||||||
cmd_dict[n] = obj
|
cmd_dict[n] = obj
|
||||||
|
|
||||||
|
|
||||||
class CommandParser(QObject):
|
class CommandParser(QObject):
|
||||||
"""Parser for qutebrowser commandline commands"""
|
"""Parser for qutebrowser commandline commands"""
|
||||||
text = ''
|
text = ''
|
||||||
@ -84,6 +88,7 @@ class CommandParser(QObject):
|
|||||||
raise
|
raise
|
||||||
self._run(count=count)
|
self._run(count=count)
|
||||||
|
|
||||||
|
|
||||||
class CommandCompletionModel(CompletionModel):
|
class CommandCompletionModel(CompletionModel):
|
||||||
# pylint: disable=abstract-method
|
# pylint: disable=abstract-method
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
@ -96,6 +101,7 @@ class CommandCompletionModel(CompletionModel):
|
|||||||
self._data['Commands'] = sorted(cmdlist)
|
self._data['Commands'] = sorted(cmdlist)
|
||||||
self.init_data()
|
self.init_data()
|
||||||
|
|
||||||
|
|
||||||
class Command(QObject):
|
class Command(QObject):
|
||||||
"""Base skeleton for a command. See the module help for
|
"""Base skeleton for a command. See the module help for
|
||||||
qutebrowser.commands.commands for details.
|
qutebrowser.commands.commands for details.
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from PyQt5.QtCore import QUrl
|
from PyQt5.QtCore import QUrl
|
||||||
|
|
||||||
|
|
||||||
def qurl(url):
|
def qurl(url):
|
||||||
if isinstance(url, QUrl):
|
if isinstance(url, QUrl):
|
||||||
return url
|
return url
|
||||||
|
@ -3,6 +3,7 @@ from collections import OrderedDict
|
|||||||
from PyQt5.QtCore import (QAbstractItemModel, Qt, QModelIndex, QVariant,
|
from PyQt5.QtCore import (QAbstractItemModel, Qt, QModelIndex, QVariant,
|
||||||
QSortFilterProxyModel, pyqtSignal)
|
QSortFilterProxyModel, pyqtSignal)
|
||||||
|
|
||||||
|
|
||||||
class CompletionModel(QAbstractItemModel):
|
class CompletionModel(QAbstractItemModel):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
@ -110,6 +111,7 @@ class CompletionModel(QAbstractItemModel):
|
|||||||
newitem = CompletionItem(item, newcat)
|
newitem = CompletionItem(item, newcat)
|
||||||
newcat.children.append(newitem)
|
newcat.children.append(newitem)
|
||||||
|
|
||||||
|
|
||||||
class CompletionItem():
|
class CompletionItem():
|
||||||
parent = None
|
parent = None
|
||||||
_data = None
|
_data = None
|
||||||
@ -146,6 +148,7 @@ class CompletionItem():
|
|||||||
return self.parent.children.index(self)
|
return self.parent.children.index(self)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
class CompletionFilterModel(QSortFilterProxyModel):
|
class CompletionFilterModel(QSortFilterProxyModel):
|
||||||
_pattern = None
|
_pattern = None
|
||||||
pattern_changed = pyqtSignal(str)
|
pattern_changed = pyqtSignal(str)
|
||||||
|
@ -60,6 +60,7 @@ _MONOSPACE = ['Monospace', 'DejaVu Sans Mono', 'Consolas', 'Monaco',
|
|||||||
|
|
||||||
MONOSPACE = ', '.join(_MONOSPACE)
|
MONOSPACE = ', '.join(_MONOSPACE)
|
||||||
|
|
||||||
|
|
||||||
def init(confdir):
|
def init(confdir):
|
||||||
global config, colordict
|
global config, colordict
|
||||||
config = Config(confdir)
|
config = Config(confdir)
|
||||||
@ -68,9 +69,11 @@ def init(confdir):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
colordict = ColorDict()
|
colordict = ColorDict()
|
||||||
|
|
||||||
|
|
||||||
def get_stylesheet(template):
|
def get_stylesheet(template):
|
||||||
return template.strip().format(color=colordict, monospace=MONOSPACE)
|
return template.strip().format(color=colordict, monospace=MONOSPACE)
|
||||||
|
|
||||||
|
|
||||||
class ColorDict(dict):
|
class ColorDict(dict):
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
try:
|
try:
|
||||||
@ -90,6 +93,7 @@ class ColorDict(dict):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class Config(ConfigParser):
|
class Config(ConfigParser):
|
||||||
"""Our own ConfigParser"""
|
"""Our own ConfigParser"""
|
||||||
configdir = None
|
configdir = None
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from PyQt5.QtWidgets import QShortcut
|
from PyQt5.QtWidgets import QShortcut
|
||||||
from PyQt5.QtCore import QUrl, pyqtSignal, Qt, QPoint, QEvent
|
from PyQt5.QtCore import QUrl, pyqtSignal, Qt, QEvent
|
||||||
from PyQt5.QtPrintSupport import QPrintPreviewDialog
|
from PyQt5.QtPrintSupport import QPrintPreviewDialog
|
||||||
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
|
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
|
||||||
|
|
||||||
@ -9,6 +9,7 @@ import qutebrowser.utils as utils
|
|||||||
import qutebrowser.utils.config as config
|
import qutebrowser.utils.config as config
|
||||||
from qutebrowser.widgets.tabbar import TabWidget
|
from qutebrowser.widgets.tabbar import TabWidget
|
||||||
|
|
||||||
|
|
||||||
class TabbedBrowser(TabWidget):
|
class TabbedBrowser(TabWidget):
|
||||||
"""A TabWidget with QWebViews inside"""
|
"""A TabWidget with QWebViews inside"""
|
||||||
|
|
||||||
@ -204,6 +205,7 @@ class TabbedBrowser(TabWidget):
|
|||||||
round(100 * y / m[1]) if m[1] != 0 else 0)
|
round(100 * y / m[1]) if m[1] != 0 else 0)
|
||||||
self.cur_scroll_perc_changed.emit(*perc)
|
self.cur_scroll_perc_changed.emit(*perc)
|
||||||
|
|
||||||
|
|
||||||
class BrowserTab(QWebView):
|
class BrowserTab(QWebView):
|
||||||
"""One browser tab in TabbedBrowser"""
|
"""One browser tab in TabbedBrowser"""
|
||||||
progress = 0
|
progress = 0
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import logging
|
|
||||||
import html
|
import html
|
||||||
|
|
||||||
from PyQt5.QtWidgets import (QTreeView, QStyledItemDelegate, QStyle,
|
from PyQt5.QtWidgets import (QTreeView, QStyledItemDelegate, QStyle,
|
||||||
@ -12,6 +11,7 @@ import qutebrowser.utils.config as config
|
|||||||
from qutebrowser.utils.completion import CompletionFilterModel
|
from qutebrowser.utils.completion import CompletionFilterModel
|
||||||
from qutebrowser.commands.utils import CommandCompletionModel
|
from qutebrowser.commands.utils import CommandCompletionModel
|
||||||
|
|
||||||
|
|
||||||
class CompletionView(QTreeView):
|
class CompletionView(QTreeView):
|
||||||
_stylesheet = """
|
_stylesheet = """
|
||||||
QTreeView {{
|
QTreeView {{
|
||||||
@ -72,7 +72,7 @@ class CompletionView(QTreeView):
|
|||||||
def resizeEvent(self, e):
|
def resizeEvent(self, e):
|
||||||
width = e.size().width()
|
width = e.size().width()
|
||||||
for i in range(self.model.columnCount()):
|
for i in range(self.model.columnCount()):
|
||||||
self.setColumnWidth(i, width/2)
|
self.setColumnWidth(i, width / 2)
|
||||||
super().resizeEvent(e)
|
super().resizeEvent(e)
|
||||||
|
|
||||||
def setmodel(self, model):
|
def setmodel(self, model):
|
||||||
@ -166,6 +166,7 @@ class CompletionView(QTreeView):
|
|||||||
# Item is a real item, not a category header -> success
|
# Item is a real item, not a category header -> success
|
||||||
return idx
|
return idx
|
||||||
|
|
||||||
|
|
||||||
class CompletionItemDelegate(QStyledItemDelegate):
|
class CompletionItemDelegate(QStyledItemDelegate):
|
||||||
opt = None
|
opt = None
|
||||||
style = None
|
style = None
|
||||||
@ -203,7 +204,6 @@ class CompletionItemDelegate(QStyledItemDelegate):
|
|||||||
self.opt.icon.paint(self.painter, icon_rect,
|
self.opt.icon.paint(self.painter, icon_rect,
|
||||||
self.opt.decorationAlignment, mode, state)
|
self.opt.decorationAlignment, mode, state)
|
||||||
|
|
||||||
|
|
||||||
def _draw_text(self, index):
|
def _draw_text(self, index):
|
||||||
if not self.opt.text:
|
if not self.opt.text:
|
||||||
return
|
return
|
||||||
|
@ -4,6 +4,7 @@ from qutebrowser.widgets.statusbar import StatusBar
|
|||||||
from qutebrowser.widgets.browser import TabbedBrowser
|
from qutebrowser.widgets.browser import TabbedBrowser
|
||||||
from qutebrowser.widgets.completion import CompletionView
|
from qutebrowser.widgets.completion import CompletionView
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
"""The main window of QuteBrowser"""
|
"""The main window of QuteBrowser"""
|
||||||
cwidget = None
|
cwidget = None
|
||||||
@ -47,4 +48,3 @@ class MainWindow(QMainWindow):
|
|||||||
#self.retranslateUi(MainWindow)
|
#self.retranslateUi(MainWindow)
|
||||||
#self.tabWidget.setCurrentIndex(0)
|
#self.tabWidget.setCurrentIndex(0)
|
||||||
#QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
#QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import logging
|
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal
|
from PyQt5.QtCore import pyqtSignal
|
||||||
from PyQt5.QtWidgets import QHBoxLayout, QWidget
|
from PyQt5.QtWidgets import QHBoxLayout, QWidget
|
||||||
|
|
||||||
@ -8,6 +6,7 @@ from qutebrowser.widgets.statusbar.command import Command
|
|||||||
from qutebrowser.widgets.statusbar.text import Text
|
from qutebrowser.widgets.statusbar.text import Text
|
||||||
from qutebrowser.widgets.statusbar.progress import Progress
|
from qutebrowser.widgets.statusbar.progress import Progress
|
||||||
|
|
||||||
|
|
||||||
class StatusBar(QWidget):
|
class StatusBar(QWidget):
|
||||||
"""The statusbar at the bottom of the mainwindow"""
|
"""The statusbar at the bottom of the mainwindow"""
|
||||||
hbox = None
|
hbox = None
|
||||||
|
@ -4,12 +4,11 @@ from PyQt5.QtWidgets import QLineEdit, QShortcut
|
|||||||
from PyQt5.QtCore import pyqtSignal, Qt
|
from PyQt5.QtCore import pyqtSignal, Qt
|
||||||
from PyQt5.QtGui import QValidator, QKeySequence
|
from PyQt5.QtGui import QValidator, QKeySequence
|
||||||
|
|
||||||
from qutebrowser.commands.utils import CommandCompletionModel
|
|
||||||
|
|
||||||
class Command(QLineEdit):
|
class Command(QLineEdit):
|
||||||
"""The commandline part of the statusbar"""
|
"""The commandline part of the statusbar"""
|
||||||
|
# Emitted when a command is triggered by the user
|
||||||
got_cmd = pyqtSignal(str) # Emitted when a command is triggered by the user
|
got_cmd = pyqtSignal(str)
|
||||||
bar = None # The status bar object
|
bar = None # The status bar object
|
||||||
esc_pressed = pyqtSignal() # Emitted when escape is pressed
|
esc_pressed = pyqtSignal() # Emitted when escape is pressed
|
||||||
tab_pressed = pyqtSignal(bool) # Emitted when tab is pressed (arg: shift)
|
tab_pressed = pyqtSignal(bool) # Emitted when tab is pressed (arg: shift)
|
||||||
@ -19,7 +18,8 @@ class Command(QLineEdit):
|
|||||||
_histpos = None
|
_histpos = None
|
||||||
|
|
||||||
# FIXME won't the tab key switch to the next widget?
|
# FIXME won't the tab key switch to the next widget?
|
||||||
# See http://www.saltycrane.com/blog/2008/01/how-to-capture-tab-key-press-event-with/
|
# See
|
||||||
|
# noqa http://www.saltycrane.com/blog/2008/01/how-to-capture-tab-key-press-event-with/
|
||||||
# for a possible fix.
|
# for a possible fix.
|
||||||
|
|
||||||
def __init__(self, bar):
|
def __init__(self, bar):
|
||||||
@ -119,6 +119,7 @@ class Command(QLineEdit):
|
|||||||
def key_stab_handler(self):
|
def key_stab_handler(self):
|
||||||
self.tab_pressed.emit(True)
|
self.tab_pressed.emit(True)
|
||||||
|
|
||||||
|
|
||||||
class Validator(QValidator):
|
class Validator(QValidator):
|
||||||
"""Validator to prevent the : from getting deleted"""
|
"""Validator to prevent the : from getting deleted"""
|
||||||
def validate(self, string, pos):
|
def validate(self, string, pos):
|
||||||
@ -126,4 +127,3 @@ class Validator(QValidator):
|
|||||||
return (QValidator.Acceptable, string, pos)
|
return (QValidator.Acceptable, string, pos)
|
||||||
else:
|
else:
|
||||||
return (QValidator.Invalid, string, pos)
|
return (QValidator.Invalid, string, pos)
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import qutebrowser.utils.config as config
|
|||||||
from PyQt5.QtWidgets import QProgressBar, QSizePolicy
|
from PyQt5.QtWidgets import QProgressBar, QSizePolicy
|
||||||
from PyQt5.QtCore import QSize
|
from PyQt5.QtCore import QSize
|
||||||
|
|
||||||
|
|
||||||
class Progress(QProgressBar):
|
class Progress(QProgressBar):
|
||||||
""" The progress bar part of the status bar"""
|
""" The progress bar part of the status bar"""
|
||||||
bar = None
|
bar = None
|
||||||
@ -59,4 +60,3 @@ class Progress(QProgressBar):
|
|||||||
self.hide()
|
self.hide()
|
||||||
else:
|
else:
|
||||||
self.color = config.colordict.getraw('statusbar.progress.bg.error')
|
self.color = config.colordict.getraw('statusbar.progress.bg.error')
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from PyQt5.QtWidgets import QLabel
|
from PyQt5.QtWidgets import QLabel
|
||||||
|
|
||||||
|
|
||||||
class Text(QLabel):
|
class Text(QLabel):
|
||||||
"""The text part of the status bar, composed of several 'widgets'"""
|
"""The text part of the status bar, composed of several 'widgets'"""
|
||||||
keystring = ''
|
keystring = ''
|
||||||
@ -37,4 +38,3 @@ class Text(QLabel):
|
|||||||
"""Update the text displayed"""
|
"""Update the text displayed"""
|
||||||
self.setText(' '.join([self.keystring, self.error, self.text,
|
self.setText(' '.join([self.keystring, self.error, self.text,
|
||||||
self.scrollperc]))
|
self.scrollperc]))
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ from PyQt5.QtCore import Qt
|
|||||||
|
|
||||||
import qutebrowser.utils.config as config
|
import qutebrowser.utils.config as config
|
||||||
|
|
||||||
|
|
||||||
class TabWidget(QTabWidget):
|
class TabWidget(QTabWidget):
|
||||||
"""The tabwidget used for TabbedBrowser"""
|
"""The tabwidget used for TabbedBrowser"""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user