Be PEP257 compliant.

This commit is contained in:
Florian Bruhin 2014-02-07 20:21:50 +01:00
parent e8b01b2b31
commit 01633007e0
22 changed files with 229 additions and 47 deletions

View File

@ -2,7 +2,7 @@
Files: Files:
__init__.py - This file. __init__.py - This file.
__main__.py - Entry point for qutebrowser, to use\ __main__.py - Entry point for qutebrowser, to use
'python -m qutebrowser'. 'python -m qutebrowser'.
app.py - Main qutebrowser application> app.py - Main qutebrowser application>
simplebrowser.py - Simple browser for testing purposes. simplebrowser.py - Simple browser for testing purposes.
@ -11,6 +11,7 @@ Subpackages:
commands - Handling of commands and key parsing. commands - Handling of commands and key parsing.
utils - Misc utility code. utils - Misc utility code.
widgets - Qt widgets displayed on the screen. widgets - Qt widgets displayed on the screen.
""" """
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org> # Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>

View File

@ -1,4 +1,4 @@
""" Initialization of qutebrowser and application-wide things """ """Initialization of qutebrowser and application-wide things."""
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org> # Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
# #
@ -44,13 +44,16 @@ from qutebrowser.utils.appdirs import AppDirs
class QuteBrowser(QApplication): class QuteBrowser(QApplication):
"""Main object for qutebrowser. """Main object for qutebrowser.
Can be used like this: Can be used like this:
>>> app = QuteBrowser() >>> app = QuteBrowser()
>>> sys.exit(app.exec_()) >>> sys.exit(app.exec_())
""" """
dirs = None # AppDirs - config/cache directories dirs = None # AppDirs - config/cache directories
config = None # Config(Parser) object config = None # Config(Parser) object
mainwindow = None mainwindow = None
@ -112,6 +115,7 @@ class QuteBrowser(QApplication):
"""Process initial positional args. """Process initial positional args.
URLs to open have no prefix, commands to execute begin with a colon. URLs to open have no prefix, commands to execute begin with a colon.
""" """
opened_urls = False opened_urls = False
@ -135,6 +139,7 @@ class QuteBrowser(QApplication):
It'll try very hard to write all open tabs to a file, and then exit It'll try very hard to write all open tabs to a file, and then exit
gracefully. gracefully.
""" """
# pylint: disable=broad-except # pylint: disable=broad-except
@ -178,6 +183,7 @@ class QuteBrowser(QApplication):
This sets up the uncaught exception hook, quits with an appropriate This sets up the uncaught exception hook, quits with an appropriate
exit status, and handles Ctrl+C properly by passing control to the exit status, and handles Ctrl+C properly by passing control to the
Python interpreter once all 500ms. Python interpreter once all 500ms.
""" """
signal(SIGINT, lambda *args: self.exit(128 + SIGINT)) signal(SIGINT, lambda *args: self.exit(128 + SIGINT))
self.timer = QTimer() self.timer = QTimer()
@ -220,6 +226,7 @@ class QuteBrowser(QApplication):
"""Initialisation of the qutebrowser commands. """Initialisation of the qutebrowser commands.
Registers all commands, connects its signals, and sets up keyparser. Registers all commands, connects its signals, and sets up keyparser.
""" """
cmdutils.register_all() cmdutils.register_all()
for cmd in cmdutils.cmd_dict.values(): for cmd in cmdutils.cmd_dict.values():
@ -238,6 +245,7 @@ class QuteBrowser(QApplication):
tpl -- A tuple in the form (count, argv) where argv is [cmd, arg, ...] tpl -- A tuple in the form (count, argv) where argv is [cmd, arg, ...]
All handlers supporting a count should have a keyword argument count. All handlers supporting a count should have a keyword argument count.
""" """
(count, argv) = tpl (count, argv) = tpl
cmd = argv[0] cmd = argv[0]
@ -283,6 +291,7 @@ class QuteBrowser(QApplication):
s -- The string to evaluate. s -- The string to evaluate.
:pyeval command handler. :pyeval command handler.
""" """
try: try:
r = eval(s) r = eval(s)
@ -296,5 +305,6 @@ class QuteBrowser(QApplication):
"""Crash for debugging purposes. """Crash for debugging purposes.
:crash command handler. :crash command handler.
""" """
raise Exception raise Exception

View File

@ -6,15 +6,12 @@ via inspect.
A command class can set the following properties: A command class can set the following properties:
nargs -- Number of arguments. Either a number, '?' (0 or 1), '+' (1 or nargs -- Number of arguments. Either a number, '?' (0 or 1), '+' (1 or
more), or '*' (any). Default: 0 more), or '*' (any). Default: 0
name -- The name of the command, or a list of aliases. name -- The name of the command, or a list of aliases.
split_args -- If arguments should be split or not. Default: True split_args -- If arguments should be split or not. Default: True
count -- If the command supports a count. Default: False count -- If the command supports a count. Default: False
hide -- If the command should be hidden in tab completion. Default: False hide -- If the command should be hidden in tab completion. Default: False
""" """
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org> # Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
@ -38,9 +35,11 @@ from qutebrowser.commands.template import Command
class Open(Command): class Open(Command):
"""Open a page in the current or [count]th tab. """Open a page in the current or [count]th tab.
arg: The URL to open. arg: The URL to open.
""" """
nargs = 1 nargs = 1
@ -49,15 +48,19 @@ class Open(Command):
class OpenCur(Command): class OpenCur(Command):
"""Fill the statusbar with :open and the current url.""" """Fill the statusbar with :open and the current url."""
nargs = 0 nargs = 0
hide = True hide = True
class TabOpen(Command): class TabOpen(Command):
"""Open a page in a new tab. """Open a page in a new tab.
arg: The URL to open. arg: The URL to open.
""" """
nargs = 1 nargs = 1
@ -65,71 +68,93 @@ class TabOpen(Command):
class TabOpenCur(Command): class TabOpenCur(Command):
"""Fill the statusbar with :tabopen and the current url.""" """Fill the statusbar with :tabopen and the current url."""
nargs = 0 nargs = 0
hide = True hide = True
class TabClose(Command): class TabClose(Command):
"""Close the current tab, or tab [count].""" """Close the current tab, or tab [count]."""
nargs = 0 nargs = 0
count = True count = True
class TabNext(Command): class TabNext(Command):
"""Switch to the next tab, or skip [count] tabs.""" """Switch to the next tab, or skip [count] tabs."""
nargs = 0 nargs = 0
count = True count = True
class TabPrev(Command): class TabPrev(Command):
"""Switch to the previous tab, or skip [count] tabs.""" """Switch to the previous tab, or skip [count] tabs."""
nargs = 0 nargs = 0
count = True count = True
class Quit(Command): class Quit(Command):
"""Quit qutebrowser.""" """Quit qutebrowser."""
name = ['quit', 'q'] name = ['quit', 'q']
nargs = 0 nargs = 0
class Reload(Command): class Reload(Command):
"""Reload the current page, or the page in tab [count].""" """Reload the current page, or the page in tab [count]."""
nargs = 0 nargs = 0
count = True count = True
class Stop(Command): class Stop(Command):
"""Stop loading the current page, or the page in tab [count].""" """Stop loading the current page, or the page in tab [count]."""
nargs = 0 nargs = 0
count = True count = True
class Back(Command): class Back(Command):
"""Go back one/[count] page(s) in the history.""" """Go back one/[count] page(s) in the history."""
nargs = 0 nargs = 0
count = True count = True
class Forward(Command): class Forward(Command):
"""Go forward one/[count] page(s) in the history.""" """Go forward one/[count] page(s) in the history."""
nargs = 0 nargs = 0
count = True count = True
class Print(Command): class Print(Command):
"""Print the current page, or the page in tab [count].""" """Print the current page, or the page in tab [count]."""
nargs = 0 nargs = 0
count = True count = True
class Scroll(Command): class Scroll(Command):
"""Scroll in x/y direction by a number of pixels. """Scroll in x/y direction by a number of pixels.
arg 1: delta x arg 1: delta x
arg 2: delta y arg 2: delta y
count: multiplicator count: multiplicator
""" """
nargs = 2 nargs = 2
@ -138,15 +163,19 @@ class Scroll(Command):
class Undo(Command): class Undo(Command):
"""Undo closing a tab.""" """Undo closing a tab."""
nargs = 0 nargs = 0
class ScrollPercX(Command): class ScrollPercX(Command):
"""Scroll N percent horizontally. """Scroll N percent horizontally.
optional arg: How many percent to scroll. optional arg: How many percent to scroll.
count: How many percent to scroll. count: How many percent to scroll.
""" """
nargs = '?' nargs = '?'
@ -156,10 +185,12 @@ class ScrollPercX(Command):
class ScrollPercY(Command): class ScrollPercY(Command):
"""Scroll N percent vertically. """Scroll N percent vertically.
optional arg: How many percent to scroll. optional arg: How many percent to scroll.
count: How many percent to scroll. count: How many percent to scroll.
""" """
nargs = '?' nargs = '?'
@ -169,9 +200,11 @@ class ScrollPercY(Command):
class PyEval(Command): class PyEval(Command):
"""Evaluate python code. """Evaluate python code.
arg: The python code to evaluate. arg: The python code to evaluate.
""" """
nargs = 1 nargs = 1
@ -179,6 +212,7 @@ class PyEval(Command):
class NextSearch(Command): class NextSearch(Command):
"""Jump to the next or [count]th next search term.""" """Jump to the next or [count]th next search term."""
nargs = 0 nargs = 0
@ -187,42 +221,52 @@ class NextSearch(Command):
class Yank(Command): class Yank(Command):
"""Yank the URL of the current tab to the clipboard. """Yank the URL of the current tab to the clipboard.
optional arg: If 'sel', yank to the primary selection. optional arg: If 'sel', yank to the primary selection.
""" """
nargs = '?' nargs = '?'
class YankTitle(Command): class YankTitle(Command):
"""Yank the title of the current tab to the clipboard. """Yank the title of the current tab to the clipboard.
optional arg: If 'sel', yank to the primary selection. optional arg: If 'sel', yank to the primary selection.
""" """
nargs = '?' nargs = '?'
class Paste(Command): class Paste(Command):
"""Open an URL from the clipboard. """Open an URL from the clipboard.
optional arg: If 'sel', paste from the primary selection. optional arg: If 'sel', paste from the primary selection.
""" """
nargs = '?' nargs = '?'
class TabPaste(Command): class TabPaste(Command):
"""Open an URL from the clipboard in a new tab. """Open an URL from the clipboard in a new tab.
optional arg: If 'sel', paste from the primary selection. optional arg: If 'sel', paste from the primary selection.
""" """
nargs = '?' nargs = '?'
class Crash(Command): class Crash(Command):
"""Simply raise an exception for debugging.""" """Simply raise an exception for debugging."""
nargs = 0 nargs = 0
hide = True hide = True

View File

@ -1,6 +1,7 @@
"""Exception classes for commands.utils and commands.template. """Exception classes for commands.utils and commands.template.
Defined here to avoid circular dependency hell. Defined here to avoid circular dependency hell.
""" """
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org> # Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
@ -22,10 +23,14 @@ Defined here to avoid circular dependency hell.
class NoSuchCommandError(ValueError): class NoSuchCommandError(ValueError):
"""Raised when a command wasn't found.""" """Raised when a command wasn't found."""
pass pass
class ArgumentCountError(TypeError): class ArgumentCountError(TypeError):
"""Raised when a command was called with an invalid count of arguments.""" """Raised when a command was called with an invalid count of arguments."""
pass pass

View File

@ -31,7 +31,9 @@ startchars = ":/?"
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
# Signal emitted when the statusbar should set a partial command # Signal emitted when the statusbar should set a partial command
set_cmd_text = pyqtSignal(str) set_cmd_text = pyqtSignal(str)
@ -55,6 +57,7 @@ class KeyParser(QObject):
Config format: key = command, e.g.: Config format: key = command, e.g.:
gg = scrollstart gg = scrollstart
""" """
for (key, cmd) in sect.items(): for (key, cmd) in sect.items():
if key.startswith('@') and key.endswith('@'): if key.startswith('@') and key.endswith('@'):
@ -71,6 +74,7 @@ class KeyParser(QObject):
"""Handle a new keypress and call the respective handlers. """Handle a new keypress and call the respective handlers.
e -- the KeyPressEvent from Qt e -- the KeyPressEvent from Qt
""" """
handled = self._handle_modifier_key(e) handled = self._handle_modifier_key(e)
if not handled: if not handled:
@ -83,6 +87,7 @@ class KeyParser(QObject):
Returns True if the keypress has been handled, and False if not. Returns True if the keypress has been handled, and False if not.
e -- the KeyPressEvent from Qt e -- the KeyPressEvent from Qt
""" """
MODMASK2STR = { MODMASK2STR = {
Qt.ControlModifier: 'Ctrl', Qt.ControlModifier: 'Ctrl',
@ -118,6 +123,7 @@ class KeyParser(QObject):
displays an error. displays an error.
e -- the KeyPressEvent from Qt e -- the KeyPressEvent from Qt
""" """
# FIXME maybe we can do this in an easier way by using QKeySeqyence # FIXME maybe we can do this in an easier way by using QKeySeqyence
# which has a matches method. # which has a matches method.
@ -169,6 +175,7 @@ class KeyParser(QObject):
"""Try to match a given keystring with any bound keychain. """Try to match a given keystring with any bound keychain.
cmdstr_needle: The command string to find. cmdstr_needle: The command string to find.
""" """
try: try:
cmdstr_hay = self.bindings[cmdstr_needle] cmdstr_hay = self.bindings[cmdstr_needle]
@ -187,9 +194,10 @@ class KeyParser(QObject):
return (self.MATCH_NONE, None) return (self.MATCH_NONE, None)
def _normalize_keystr(self, keystr): def _normalize_keystr(self, keystr):
"""Normalizes a keystring like Ctrl-Q to a keystring like Ctrl+Q. """Normalize a keystring like Ctrl-Q to a keystring like Ctrl+Q.
keystr -- The key combination as a string. keystr -- The key combination as a string.
""" """
replacements = [ replacements = [
('Control', 'Ctrl'), ('Control', 'Ctrl'),
@ -205,11 +213,12 @@ class KeyParser(QObject):
return keystr return keystr
def _run_or_fill(self, cmdstr, count=None, ignore_exc=True): def _run_or_fill(self, cmdstr, count=None, ignore_exc=True):
"""Runs the command in cmdstr or fills the statusbar if args missing. """Run the command in cmdstr or fill the statusbar if args missing.
cmdstr -- The command string. cmdstr -- The command string.
count -- Optional command count. count -- Optional command count.
ignore_exc -- Ignore exceptions. ignore_exc -- Ignore exceptions.
""" """
try: try:
self.commandparser.run(cmdstr, count=count, ignore_exc=ignore_exc) self.commandparser.run(cmdstr, count=count, ignore_exc=ignore_exc)

View File

@ -25,9 +25,11 @@ from qutebrowser.commands.exceptions import ArgumentCountError
class Command(QObject): class Command(QObject):
"""Base skeleton for a command. """Base skeleton for a command.
See the module documentation for qutebrowser.commands.commands for details. See the module documentation for qutebrowser.commands.commands for details.
""" """
# FIXME: # FIXME:
@ -53,8 +55,10 @@ class Command(QObject):
self.mainname = self.name[0] self.mainname = self.name[0]
def check(self, args): def check(self, args):
"""Check if the argument count is valid. Raise ArgumentCountError if """Check if the argument count is valid.
not.
Raise ArgumentCountError if not.
""" """
if ((isinstance(self.nargs, int) and len(args) != self.nargs) or if ((isinstance(self.nargs, int) and len(args) != self.nargs) or
(self.nargs == '?' and len(args) > 1) or (self.nargs == '?' and len(args) > 1) or
@ -63,10 +67,11 @@ class Command(QObject):
raise ArgumentCountError raise ArgumentCountError
def run(self, args=None, count=None): def run(self, args=None, count=None):
"""Runs the command. """Run the command.
args -- Arguments to the command. args -- Arguments to the command.
count -- Command repetition count. count -- Command repetition count.
""" """
dbgout = ["command called:", self.mainname] dbgout = ["command called:", self.mainname]
if args: if args:

View File

@ -48,7 +48,9 @@ def register_all():
class SearchParser(QObject): class SearchParser(QObject):
"""Parse qutebrowser searches.""" """Parse qutebrowser searches."""
text = None text = None
flags = 0 flags = 0
do_search = pyqtSignal(str, 'QWebPage::FindFlags') do_search = pyqtSignal(str, 'QWebPage::FindFlags')
@ -57,6 +59,7 @@ class SearchParser(QObject):
"""Search for a text on a website. """Search for a text on a website.
text -- The text to search for. text -- The text to search for.
""" """
self._search(text) self._search(text)
@ -64,6 +67,7 @@ class SearchParser(QObject):
"""Search for a text on a website in reverse direction. """Search for a text on a website in reverse direction.
text -- The text to search for. text -- The text to search for.
""" """
self._search(text, rev=True) self._search(text, rev=True)
@ -72,6 +76,7 @@ class SearchParser(QObject):
text -- The text to search for. text -- The text to search for.
rev -- Search direction. rev -- Search direction.
""" """
if self.text != text: if self.text != text:
self.do_search.emit('', 0) self.do_search.emit('', 0)
@ -93,7 +98,9 @@ class SearchParser(QObject):
class CommandParser(QObject): class CommandParser(QObject):
"""Parse qutebrowser commandline commands.""" """Parse qutebrowser commandline commands."""
text = '' text = ''
cmd = '' cmd = ''
args = [] args = []
@ -103,6 +110,7 @@ class CommandParser(QObject):
"""Split the commandline text into command and arguments. """Split the commandline text into command and arguments.
Raise NoSuchCommandError if a command wasn't found. Raise NoSuchCommandError if a command wasn't found.
""" """
self.text = text self.text = text
parts = self.text.strip().split(maxsplit=1) parts = self.text.strip().split(maxsplit=1)
@ -142,6 +150,7 @@ class CommandParser(QObject):
Raise NoSuchCommandError if a command wasn't found, and Raise NoSuchCommandError if a command wasn't found, and
ArgumentCountError if a command was called with the wrong count of ArgumentCountError if a command was called with the wrong count of
arguments. arguments.
""" """
try: try:
self._parse(text) self._parse(text)

View File

@ -1,4 +1,4 @@
"""Utility functions""" """Misc utility functions."""
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org> # Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
# #
@ -62,6 +62,7 @@ def _git_str():
"""Try to find out git version and return a string if possible. """Try to find out git version and return a string if possible.
Return None if there was an error or we're not in a git repo. Return None if there was an error or we're not in a git repo.
""" """
# FIXME this runs in PWD, not the qutebrowser dir?! # FIXME this runs in PWD, not the qutebrowser dir?!
if not os.path.isdir(".git"): if not os.path.isdir(".git"):

View File

@ -42,6 +42,7 @@ def handle(url):
"""Handle about page with an url. """Handle about page with an url.
Returns HTML content. Returns HTML content.
""" """
if not is_about_url(url): if not is_about_url(url):
raise ValueError raise ValueError
@ -59,11 +60,13 @@ def _get_html(title, snippet):
title -- The title the page should have. title -- The title the page should have.
snippet -- The html snippet. snippet -- The html snippet.
""" """
return _html_template.format(title=title, body=snippet).encode('UTF-8') return _html_template.format(title=title, body=snippet).encode('UTF-8')
class AboutHandlers: class AboutHandlers:
"""Handlers for about:... pages.""" """Handlers for about:... pages."""
@classmethod @classmethod

View File

@ -4,6 +4,7 @@ Contains:
CompletionModel -- A simple tree model based on Python data. CompletionModel -- A simple tree model based on Python data.
CompletionItem -- One item in the CompletionModel. CompletionItem -- One item in the CompletionModel.
CompletionFilterModel -- A QSortFilterProxyModel subclass for completions. CompletionFilterModel -- A QSortFilterProxyModel subclass for completions.
""" """
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org> # Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
@ -34,6 +35,7 @@ class CompletionModel(QAbstractItemModel):
"""A simple tree model based on Python OrderdDict containing tuples. """A simple tree model based on Python OrderdDict containing tuples.
Used for showing completions later in the CompletionView. Used for showing completions later in the CompletionView.
""" """
def __init__(self, parent=None): def __init__(self, parent=None):
@ -48,6 +50,7 @@ class CompletionModel(QAbstractItemModel):
"""Remove rows from the model. """Remove rows from the model.
Overrides QAbstractItemModel::removeRows. Overrides QAbstractItemModel::removeRows.
""" """
node = self._node(parent) node = self._node(parent)
self.beginRemoveRows(parent, position, position + count - 1) self.beginRemoveRows(parent, position, position + count - 1)
@ -59,6 +62,7 @@ class CompletionModel(QAbstractItemModel):
Returns the CompletionItem for index, or the root CompletionItem if the Returns the CompletionItem for index, or the root CompletionItem if the
index was invalid. index was invalid.
""" """
if index.isValid(): if index.isValid():
return self.id_map[index.internalId()] return self.id_map[index.internalId()]
@ -69,6 +73,7 @@ class CompletionModel(QAbstractItemModel):
"""Return the column count in the model. """Return the column count in the model.
Overrides QAbstractItemModel::columnCount. Overrides QAbstractItemModel::columnCount.
""" """
# pylint: disable=unused-argument # pylint: disable=unused-argument
return self.root.column_count() return self.root.column_count()
@ -78,6 +83,7 @@ class CompletionModel(QAbstractItemModel):
Returns an invalid QVariant on error. Returns an invalid QVariant on error.
Overrides QAbstractItemModel::data. Overrides QAbstractItemModel::data.
""" """
if not index.isValid(): if not index.isValid():
return QVariant() return QVariant()
@ -95,6 +101,7 @@ class CompletionModel(QAbstractItemModel):
Returns Qt.NoItemFlags on error. Returns Qt.NoItemFlags on error.
Overrides QAbstractItemModel::flags. Overrides QAbstractItemModel::flags.
""" """
# FIXME categories are not selectable, but moving via arrow keys still # FIXME categories are not selectable, but moving via arrow keys still
# tries to select them # tries to select them
@ -111,6 +118,7 @@ class CompletionModel(QAbstractItemModel):
Returns an invalid QVariant on error. Returns an invalid QVariant on error.
Overrides QAbstractItemModel::headerData. Overrides QAbstractItemModel::headerData.
""" """
if orientation == Qt.Horizontal and role == Qt.DisplayRole: if orientation == Qt.Horizontal and role == Qt.DisplayRole:
return QVariant(self.root.data(section)) return QVariant(self.root.data(section))
@ -121,6 +129,7 @@ class CompletionModel(QAbstractItemModel):
Returns True on success, False on failure. Returns True on success, False on failure.
Overrides QAbstractItemModel::setData. Overrides QAbstractItemModel::setData.
""" """
if not index.isValid(): if not index.isValid():
return False return False
@ -137,6 +146,7 @@ class CompletionModel(QAbstractItemModel):
Returns an invalid QModelIndex on failure. Returns an invalid QModelIndex on failure.
Overrides QAbstractItemModel::index. Overrides QAbstractItemModel::index.
""" """
if (0 <= row < self.rowCount(parent) and if (0 <= row < self.rowCount(parent) and
0 <= column < self.columnCount(parent)): 0 <= column < self.columnCount(parent)):
@ -162,6 +172,7 @@ class CompletionModel(QAbstractItemModel):
Returns an invalid QModelIndex on failure. Returns an invalid QModelIndex on failure.
Overrides QAbstractItemModel::parent. Overrides QAbstractItemModel::parent.
""" """
if not index.isValid(): if not index.isValid():
return QModelIndex() return QModelIndex()
@ -171,10 +182,11 @@ class CompletionModel(QAbstractItemModel):
return self.createIndex(item.row(), 0, id(item)) return self.createIndex(item.row(), 0, id(item))
def rowCount(self, parent=QModelIndex()): def rowCount(self, parent=QModelIndex()):
"""Return the rowCount (children count) for a parent. """Return the children count of an item.
Uses the root frame if parent is invalid. Uses the root frame if parent is invalid.
Overrides QAbstractItemModel::data. Overrides QAbstractItemModel::data.
""" """
if parent.column() > 0: if parent.column() > 0:
return 0 return 0
@ -191,6 +203,7 @@ class CompletionModel(QAbstractItemModel):
Raises NotImplementedError, should be overwritten in a superclass. Raises NotImplementedError, should be overwritten in a superclass.
Overrides QAbstractItemModel::sort. Overrides QAbstractItemModel::sort.
""" """
raise NotImplementedError raise NotImplementedError
@ -209,6 +222,7 @@ class CompletionModel(QAbstractItemModel):
"""Mark a string in all items (children of root-children). """Mark a string in all items (children of root-children).
needle -- The string to mark. needle -- The string to mark.
""" """
for i in range(self.rowCount()): for i in range(self.rowCount()):
cat = self.index(i, 0) cat = self.index(i, 0)
@ -234,6 +248,7 @@ class CompletionModel(QAbstractItemModel):
class CompletionItem(): class CompletionItem():
"""An item (row) in a CompletionModel.""" """An item (row) in a CompletionModel."""
parent = None parent = None
@ -246,6 +261,7 @@ class CompletionItem():
data -- The data for the model, as tuple (columns). data -- The data for the model, as tuple (columns).
parent -- An optional parent item. parent -- An optional parent item.
""" """
self.parent = parent self.parent = parent
self._data = data self._data = data
@ -256,6 +272,7 @@ class CompletionItem():
"""Get the data for role/column. """Get the data for role/column.
Raise ValueError if the role is invalid. Raise ValueError if the role is invalid.
""" """
if role == Qt.DisplayRole: if role == Qt.DisplayRole:
return self._data[column] return self._data[column]
@ -268,6 +285,7 @@ class CompletionItem():
"""Set the data for column/role to value. """Set the data for column/role to value.
Raise ValueError if the role is invalid. Raise ValueError if the role is invalid.
""" """
if role == Qt.DisplayRole: if role == Qt.DisplayRole:
self._data[column] = value self._data[column] = value
@ -307,6 +325,7 @@ class CompletionFilterModel(QSortFilterProxyModel):
"""Set a new source model and clear the pattern. """Set a new source model and clear the pattern.
model -- The new source model. model -- The new source model.
""" """
self.setSourceModel(model) self.setSourceModel(model)
self.srcmodel = model self.srcmodel = model
@ -320,6 +339,7 @@ class CompletionFilterModel(QSortFilterProxyModel):
If the current completion model overrides sort(), it is used. If the current completion model overrides sort(), it is used.
If not, the default implementation in QCompletionFilterModel is called. If not, the default implementation in QCompletionFilterModel is called.
""" """
self._pattern = val self._pattern = val
self.invalidateFilter() self.invalidateFilter()
@ -342,6 +362,7 @@ class CompletionFilterModel(QSortFilterProxyModel):
Returns True if self.pattern is contained in item, or if it's a root Returns True if self.pattern is contained in item, or if it's a root
item (category). Else returns False. item (category). Else returns False.
""" """
if parent == QModelIndex(): if parent == QModelIndex():
return True return True
@ -360,6 +381,7 @@ class CompletionFilterModel(QSortFilterProxyModel):
Prefers all items which start with self.pattern. Other than that, uses Prefers all items which start with self.pattern. Other than that, uses
normal Python string sorting. normal Python string sorting.
""" """
left = self.srcmodel.data(lindex).value() left = self.srcmodel.data(lindex).value()
right = self.srcmodel.data(rindex).value() right = self.srcmodel.data(rindex).value()
@ -377,11 +399,11 @@ class CompletionFilterModel(QSortFilterProxyModel):
return left < right return left < right
def first_item(self): def first_item(self):
"""Returns the first item in the model.""" """Return the first item in the model."""
cat = self.index(0, 0) cat = self.index(0, 0)
return self.index(0, 0, cat) return self.index(0, 0, cat)
def last_item(self): def last_item(self):
"""Returns the last item in the model.""" """Return the last item in the model."""
cat = self.index(self.rowCount() - 1, 0) cat = self.index(self.rowCount() - 1, 0)
return self.index(self.rowCount(cat) - 1, 0, cat) return self.index(self.rowCount(cat) - 1, 0, cat)

View File

@ -4,6 +4,7 @@ config -- The main Config object.
colordict -- All configured colors. colordict -- All configured colors.
default_config -- The default config as dict. default_config -- The default config as dict.
MONOSPACE -- A list of suitable monospace fonts. MONOSPACE -- A list of suitable monospace fonts.
""" """
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org> # Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
@ -128,10 +129,10 @@ def get_stylesheet(template):
class ColorDict(dict): class ColorDict(dict):
"""A dict aimed at Qt stylesheet colors.""" """A dict aimed at Qt stylesheet colors."""
def __getitem__(self, key): def __getitem__(self, key):
"""Override dict __getitem__. """Override dict __getitem__.
If a value wasn't found, return an empty string. If a value wasn't found, return an empty string.
@ -141,8 +142,8 @@ class ColorDict(dict):
If the key has a .bg. element in it, return background-color: X;. If the key has a .bg. element in it, return background-color: X;.
In all other cases, return the plain value. In all other cases, return the plain value.
"""
"""
try: try:
val = super().__getitem__(key) val = super().__getitem__(key)
except KeyError: except KeyError:
@ -158,6 +159,7 @@ class ColorDict(dict):
"""Get a value without the transformations done in __getitem__. """Get a value without the transformations done in __getitem__.
Returns a value, or None if the value wasn't found. Returns a value, or None if the value wasn't found.
""" """
try: try:
return super().__getitem__(key) return super().__getitem__(key)
@ -166,6 +168,7 @@ class ColorDict(dict):
class Config(ConfigParser): class Config(ConfigParser):
"""Our own ConfigParser subclass.""" """Our own ConfigParser subclass."""
configdir = None configdir = None
@ -177,6 +180,7 @@ class Config(ConfigParser):
"""Config constructor. """Config constructor.
configdir -- directory to store the config in. configdir -- directory to store the config in.
""" """
super().__init__(interpolation=ExtendedInterpolation()) super().__init__(interpolation=ExtendedInterpolation())
self.default_cp = ConfigParser(interpolation=ExtendedInterpolation()) self.default_cp = ConfigParser(interpolation=ExtendedInterpolation())
@ -197,6 +201,7 @@ class Config(ConfigParser):
"""Get an item from the configparser or default dict. """Get an item from the configparser or default dict.
Extends ConfigParser's __getitem__. Extends ConfigParser's __getitem__.
""" """
try: try:
return super().__getitem__(key) return super().__getitem__(key)
@ -207,6 +212,7 @@ class Config(ConfigParser):
"""Get an item from the configparser or default dict. """Get an item from the configparser or default dict.
Extends ConfigParser's get(). Extends ConfigParser's get().
""" """
if 'fallback' in kwargs: if 'fallback' in kwargs:
del kwargs['fallback'] del kwargs['fallback']
@ -226,9 +232,7 @@ class Config(ConfigParser):
os.fsync(f.fileno()) os.fsync(f.fileno())
def dump_userconfig(self): def dump_userconfig(self):
"""Returns the part of the config which was changed by the user as a """Return the part of the config which was changed by the user."""
string.
"""
with io.StringIO() as f: with io.StringIO() as f:
self.write(f) self.write(f)
return f.getvalue() return f.getvalue()

View File

@ -2,6 +2,7 @@
In its own file so it doesn't include any Qt stuff, because if it did, it In its own file so it doesn't include any Qt stuff, because if it did, it
wouldn't work. wouldn't work.
""" """
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org> # Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
@ -33,6 +34,7 @@ def fix():
This fixes crashes on various sites. This fixes crashes on various sites.
See https://bugreports.qt-project.org/browse/QTBUG-36099 See https://bugreports.qt-project.org/browse/QTBUG-36099
""" """
if sys.platform.startswith('linux'): if sys.platform.startswith('linux'):
# Switch to old but stable font rendering engine # Switch to old but stable font rendering engine

View File

@ -19,6 +19,7 @@ def urlstring(url):
"""Return an QUrl as string. """Return an QUrl as string.
qurl -- URL as string or QUrl. qurl -- URL as string or QUrl.
""" """
return url.url() if isinstance(url, QUrl) else url return url.url() if isinstance(url, QUrl) else url
@ -27,6 +28,7 @@ def fuzzy_url(url):
"""Return a QUrl based on an user input which is URL or search term. """Return a QUrl based on an user input which is URL or search term.
url -- URL to load as QUrl or string. url -- URL to load as QUrl or string.
""" """
u = qurl(url) u = qurl(url)
urlstr = urlstring(url) urlstr = urlstring(url)

View File

@ -27,6 +27,7 @@ import qutebrowser.utils as utils
class CrashDialog(QDialog): class CrashDialog(QDialog):
"""Dialog which gets shown after there was a crash.""" """Dialog which gets shown after there was a crash."""
def __init__(self, pages, cmdhist, exc): def __init__(self, pages, cmdhist, exc):

View File

@ -2,6 +2,7 @@
Defines BrowserTab (our own QWebView subclass) and TabbedBrowser (a TabWidget Defines BrowserTab (our own QWebView subclass) and TabbedBrowser (a TabWidget
containing BrowserTabs). containing BrowserTabs).
""" """
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org> # Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
@ -38,6 +39,7 @@ from qutebrowser.widgets.tabbar import TabWidget
class TabbedBrowser(TabWidget): class TabbedBrowser(TabWidget):
"""A TabWidget with QWebViews inside. """A TabWidget with QWebViews inside.
Provides methods to manage tabs, convenience methods to interact with the Provides methods to manage tabs, convenience methods to interact with the
@ -49,6 +51,7 @@ class TabbedBrowser(TabWidget):
emitted again if the current tab changes. emitted again if the current tab changes.
- the signal gets filtered with _filter_signals and self.cur_* gets - the signal gets filtered with _filter_signals and self.cur_* gets
emitted if the signal occured in the current tab. emitted if the signal occured in the current tab.
""" """
cur_progress = pyqtSignal(int) # Progress of the current tab changed cur_progress = pyqtSignal(int) # Progress of the current tab changed
@ -74,6 +77,7 @@ class TabbedBrowser(TabWidget):
"""Open a new tab with a given url. """Open a new tab with a given url.
Also connect all the signals we need to _filter_signals. Also connect all the signals we need to _filter_signals.
""" """
logging.debug("Opening {}".format(url)) logging.debug("Opening {}".format(url))
url = urlutils.qurl(url) url = urlutils.qurl(url)
@ -104,6 +108,7 @@ class TabbedBrowser(TabWidget):
Command handler for :open. Command handler for :open.
url -- The URL to open. url -- The URL to open.
""" """
tab = self._widget(count) tab = self._widget(count)
if tab is not None: if tab is not None:
@ -118,6 +123,7 @@ class TabbedBrowser(TabWidget):
"""Undo closing a tab. """Undo closing a tab.
Command handler for :undo. Command handler for :undo.
""" """
if self._url_stack: if self._url_stack:
self.tabopen(self._url_stack.pop()) self.tabopen(self._url_stack.pop())
@ -126,6 +132,7 @@ class TabbedBrowser(TabWidget):
"""Close the current/[count]th tab. """Close the current/[count]th tab.
Command handler for :close. Command handler for :close.
""" """
if self.count() > 1: if self.count() > 1:
idx = self.currentIndex() if count is None else count - 1 idx = self.currentIndex() if count is None else count - 1
@ -142,6 +149,7 @@ class TabbedBrowser(TabWidget):
"""Reload the current/[count]th tab. """Reload the current/[count]th tab.
Command handler for :reload. Command handler for :reload.
""" """
tab = self._widget(count) tab = self._widget(count)
if tab is not None: if tab is not None:
@ -151,6 +159,7 @@ class TabbedBrowser(TabWidget):
"""Stop loading in the current/[count]th tab. """Stop loading in the current/[count]th tab.
Command handler for :stop. Command handler for :stop.
""" """
tab = self._widget(count) tab = self._widget(count)
if tab is not None: if tab is not None:
@ -160,6 +169,7 @@ class TabbedBrowser(TabWidget):
"""Print the current/[count]th tab. """Print the current/[count]th tab.
Command handler for :print. Command handler for :print.
""" """
# FIXME that does not what I expect # FIXME that does not what I expect
tab = self._widget(count) tab = self._widget(count)
@ -173,6 +183,7 @@ class TabbedBrowser(TabWidget):
Go back for 1 page if count is unset, else go back [count] pages. Go back for 1 page if count is unset, else go back [count] pages.
Command handler for :back. Command handler for :back.
""" """
# FIXME display warning if beginning of history # FIXME display warning if beginning of history
for i in range(count): # pylint: disable=unused-variable for i in range(count): # pylint: disable=unused-variable
@ -183,6 +194,7 @@ class TabbedBrowser(TabWidget):
Go forward for 1 page if count is unset, else go forward [count] pages. Go forward for 1 page if count is unset, else go forward [count] pages.
Command handler for :forward. Command handler for :forward.
""" """
# FIXME display warning if end of history # FIXME display warning if end of history
for i in range(count): # pylint: disable=unused-variable for i in range(count): # pylint: disable=unused-variable
@ -193,13 +205,15 @@ class TabbedBrowser(TabWidget):
text -- The text to search for. text -- The text to search for.
flags -- The QWebPage::FindFlags. flags -- The QWebPage::FindFlags.
""" """
self.currentWidget().findText(text, flags) self.currentWidget().findText(text, flags)
def cur_scroll(self, dx, dy, count=1): def cur_scroll(self, dx, dy, count=1):
"""Scroll the current tab by count * dx/dy """Scroll the current tab by count * dx/dy.
Command handler for :scroll. Command handler for :scroll.
""" """
dx = int(count) * int(dx) dx = int(count) * int(dx)
dy = int(count) * int(dy) dy = int(count) * int(dy)
@ -207,17 +221,21 @@ class TabbedBrowser(TabWidget):
def cur_scroll_percent_x(self, perc=None, count=None): def cur_scroll_percent_x(self, perc=None, count=None):
"""Scroll the current tab to a specific percent of the page. """Scroll the current tab to a specific percent of the page.
Accepts percentage either as argument, or as count. Accepts percentage either as argument, or as count.
Command handler for :scroll_perc_x. Command handler for :scroll_perc_x.
""" """
self._cur_scroll_percent(perc, count, Qt.Horizontal) self._cur_scroll_percent(perc, count, Qt.Horizontal)
def cur_scroll_percent_y(self, perc=None, count=None): def cur_scroll_percent_y(self, perc=None, count=None):
"""Scroll the current tab to a specific percent of the page """Scroll the current tab to a specific percent of the page.
Accepts percentage either as argument, or as count. Accepts percentage either as argument, or as count.
Command handler for :scroll_perc_y Command handler for :scroll_perc_y
""" """
self._cur_scroll_percent(perc, count, Qt.Vertical) self._cur_scroll_percent(perc, count, Qt.Vertical)
@ -239,6 +257,7 @@ class TabbedBrowser(TabWidget):
"""Switch to the ([count]th) previous tab. """Switch to the ([count]th) previous tab.
Command handler for :tabprev. Command handler for :tabprev.
""" """
idx = self.currentIndex() idx = self.currentIndex()
if idx - count >= 0: if idx - count >= 0:
@ -251,6 +270,7 @@ class TabbedBrowser(TabWidget):
"""Switch to the ([count]th) next tab. """Switch to the ([count]th) next tab.
Command handler for :tabnext. Command handler for :tabnext.
""" """
idx = self.currentIndex() idx = self.currentIndex()
if idx + count < self.count(): if idx + count < self.count():
@ -263,6 +283,7 @@ class TabbedBrowser(TabWidget):
"""Scroll when space is pressed. """Scroll when space is pressed.
This gets called from the space QShortcut in __init__. This gets called from the space QShortcut in __init__.
""" """
try: try:
amount = config.config['general']['space_scroll'] amount = config.config['general']['space_scroll']
@ -274,6 +295,7 @@ class TabbedBrowser(TabWidget):
"""Yank the current url to the clipboard or primary selection. """Yank the current url to the clipboard or primary selection.
Command handler for :yank. Command handler for :yank.
""" """
clip = QApplication.clipboard() clip = QApplication.clipboard()
url = self.currentWidget().url().toString() url = self.currentWidget().url().toString()
@ -285,6 +307,7 @@ class TabbedBrowser(TabWidget):
"""Yank the current title to the clipboard or primary selection. """Yank the current title to the clipboard or primary selection.
Command handler for :yanktitle. Command handler for :yanktitle.
""" """
clip = QApplication.clipboard() clip = QApplication.clipboard()
title = self.tabText(self.currentIndex()) title = self.tabText(self.currentIndex())
@ -296,6 +319,7 @@ class TabbedBrowser(TabWidget):
"""Open a page from the clipboard. """Open a page from the clipboard.
Command handler for :paste. Command handler for :paste.
""" """
# FIXME what happens for invalid URLs? # FIXME what happens for invalid URLs?
clip = QApplication.clipboard() clip = QApplication.clipboard()
@ -308,6 +332,7 @@ class TabbedBrowser(TabWidget):
"""Open a page from the clipboard in a new tab. """Open a page from the clipboard in a new tab.
Command handler for :paste. Command handler for :paste.
""" """
# FIXME what happens for invalid URLs? # FIXME what happens for invalid URLs?
clip = QApplication.clipboard() clip = QApplication.clipboard()
@ -325,6 +350,7 @@ class TabbedBrowser(TabWidget):
"""Return a widget based on a count/idx. """Return a widget based on a count/idx.
If count is None, return the current widget. If count is None, return the current widget.
""" """
if count is None: if count is None:
return self.currentWidget() return self.currentWidget()
@ -337,6 +363,7 @@ class TabbedBrowser(TabWidget):
"""Set the title of a tab. """Set the title of a tab.
Slot for the titleChanged signal of any tab. Slot for the titleChanged signal of any tab.
""" """
logging.debug('title changed to "{}"'.format(text)) logging.debug('title changed to "{}"'.format(text))
if text: if text:
@ -345,12 +372,14 @@ class TabbedBrowser(TabWidget):
logging.debug('ignoring title change') logging.debug('ignoring title change')
def _filter_factory(self, signal): def _filter_factory(self, signal):
"""Returns a partial functon calling _filter_signals with a signal.""" """Return a partial functon calling _filter_signals with a signal."""
return functools.partial(self._filter_signals, signal) return functools.partial(self._filter_signals, signal)
def _filter_signals(self, signal, *args): def _filter_signals(self, signal, *args):
"""Filter signals and trigger TabbedBrowser signals if the signal """Filter signals and trigger TabbedBrowser signals if needed.
was sent from the _current_ tab and not from any other one.
Triggers signal if the original signal was sent from the _current_ tab
and not from any other one.
The original signal does not matter, since we get the new signal and The original signal does not matter, since we get the new signal and
all args. all args.
@ -360,6 +389,7 @@ class TabbedBrowser(TabWidget):
signal -- The signal to emit if the sender was the current widget. signal -- The signal to emit if the sender was the current widget.
*args -- The args to pass to the signal. *args -- The args to pass to the signal.
""" """
# FIXME BUG the signal cache ordering seems to be weird sometimes. # FIXME BUG the signal cache ordering seems to be weird sometimes.
# How to reproduce: # How to reproduce:
@ -394,6 +424,7 @@ class TabbedBrowser(TabWidget):
Populates all signals from the signal cache. Populates all signals from the signal cache.
Slot for the currentChanged signal. Slot for the currentChanged signal.
""" """
for (sigstr, (signal, args)) in self.widget(idx).signal_cache.items(): for (sigstr, (signal, args)) in self.widget(idx).signal_cache.items():
dbgstr = "{} ({})".format(sigstr, ','.join([str(e) for e in args])) dbgstr = "{} ({})".format(sigstr, ','.join([str(e) for e in args]))
@ -402,10 +433,13 @@ class TabbedBrowser(TabWidget):
class BrowserTab(QWebView): class BrowserTab(QWebView):
"""One browser tab in TabbedBrowser. """One browser tab in TabbedBrowser.
Our own subclass of a QWebView with some added bells and whistles. Our own subclass of a QWebView with some added bells and whistles.
""" """
progress = 0 progress = 0
scroll_pos_changed = pyqtSignal(int, int) scroll_pos_changed = pyqtSignal(int, int)
open_tab = pyqtSignal('QUrl') open_tab = pyqtSignal('QUrl')
@ -427,6 +461,7 @@ class BrowserTab(QWebView):
"""Open an URL in the browser. """Open an URL in the browser.
url -- The URL to load, as string or QUrl. url -- The URL to load, as string or QUrl.
""" """
u = urlutils.fuzzy_url(url) u = urlutils.fuzzy_url(url)
logging.debug('New title: {}'.format(u.url())) logging.debug('New title: {}'.format(u.url()))
@ -449,6 +484,7 @@ class BrowserTab(QWebView):
tab (middle-click or control) or not, and does so. tab (middle-click or control) or not, and does so.
url -- The url to handle, as string or QUrl. url -- The url to handle, as string or QUrl.
""" """
if self._open_new_tab: if self._open_new_tab:
self.open_tab.emit(url) self.open_tab.emit(url)
@ -461,6 +497,7 @@ class BrowserTab(QWebView):
Slot for the loadProgress signal. Slot for the loadProgress signal.
prog -- New progress. prog -- New progress.
""" """
self.progress = prog self.progress = prog
@ -473,6 +510,7 @@ class BrowserTab(QWebView):
watched -- The watched Qt object. watched -- The watched Qt object.
e -- The new event. e -- The new event.
""" """
if watched == self and e.type() == QEvent.Paint: if watched == self and e.type() == QEvent.Paint:
frame = self.page().mainFrame() frame = self.page().mainFrame()
@ -499,7 +537,8 @@ class BrowserTab(QWebView):
This also is a bit of a hack, but it seems it's the only possible way. This also is a bit of a hack, but it seems it's the only possible way.
Set the _open_new_tab attribute accordingly. Set the _open_new_tab attribute accordingly.
e -- The arrived event e -- The arrived event.
""" """
if e.type() in [QEvent.MouseButtonPress, QEvent.MouseButtonDblClick]: if e.type() in [QEvent.MouseButtonPress, QEvent.MouseButtonDblClick]:
self._open_new_tab = (e.button() == Qt.MidButton or self._open_new_tab = (e.button() == Qt.MidButton or

View File

@ -1,8 +1,8 @@
"""Completion view which appears when something is typed in the statusbar """Completion view for statusbar command section.
command section.
Defines a CompletionView which uses CompletionFiterModel and CompletionModel Defines a CompletionView which uses CompletionFiterModel and CompletionModel
subclasses to provide completions. subclasses to provide completions.
""" """
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org> # Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
@ -37,12 +37,14 @@ from qutebrowser.commands.utils import CommandCompletionModel
class CompletionView(QTreeView): class CompletionView(QTreeView):
"""The view showing available completions. """The view showing available completions.
Based on QTreeView but heavily customized so root elements show as category Based on QTreeView but heavily customized so root elements show as category
headers, and children show as flat list. headers, and children show as flat list.
Highlights completions based on marks in the UserRole. Highlights completions based on marks in the UserRole.
""" """
_stylesheet = """ _stylesheet = """
@ -111,6 +113,7 @@ class CompletionView(QTreeView):
Called from cmd_text_changed(). Called from cmd_text_changed().
model -- A QAbstractItemModel with available completions. model -- A QAbstractItemModel with available completions.
""" """
self.model.setsrc(self.completion_models[model]) self.model.setsrc(self.completion_models[model])
self.expandAll() self.expandAll()
@ -121,6 +124,7 @@ class CompletionView(QTreeView):
Slot for the resized signal of the statusbar. Slot for the resized signal of the statusbar.
geom -- A QRect containing the statusbar geometry. geom -- A QRect containing the statusbar geometry.
""" """
bottomleft = geom.topLeft() bottomleft = geom.topLeft()
bottomright = geom.topRight() bottomright = geom.topRight()
@ -135,6 +139,7 @@ class CompletionView(QTreeView):
Slot for the textChanged signal of the statusbar command widget. Slot for the textChanged signal of the statusbar command widget.
text -- The new text text -- The new text
""" """
if self.ignore_next: if self.ignore_next:
# Text changed by a completion, so we don't have to complete again. # Text changed by a completion, so we don't have to complete again.
@ -161,6 +166,7 @@ class CompletionView(QTreeView):
statusbar. Called by key_(s)tab_handler in statusbar.command. statusbar. Called by key_(s)tab_handler in statusbar.command.
shift -- Whether shift is pressed or not. shift -- Whether shift is pressed or not.
""" """
if not self.completing: if not self.completing:
# No completion running at the moment, ignore keypress # No completion running at the moment, ignore keypress
@ -179,6 +185,7 @@ class CompletionView(QTreeView):
Used by tab_handler. Used by tab_handler.
upwards -- Get previous item, not next. upwards -- Get previous item, not next.
""" """
idx = self.selectionModel().currentIndex() idx = self.selectionModel().currentIndex()
if not idx.isValid(): if not idx.isValid():
@ -197,6 +204,7 @@ class CompletionView(QTreeView):
class CompletionItemDelegate(QStyledItemDelegate): class CompletionItemDelegate(QStyledItemDelegate):
"""Delegate used by CompletionView to draw individual items. """Delegate used by CompletionView to draw individual items.
Mainly a cleaned up port of Qt's way to draw a TreeView item, except it Mainly a cleaned up port of Qt's way to draw a TreeView item, except it
@ -204,6 +212,7 @@ class CompletionItemDelegate(QStyledItemDelegate):
Original implementation: Original implementation:
qt/src/gui/styles/qcommonstyle.cpp:drawControl:2153 qt/src/gui/styles/qcommonstyle.cpp:drawControl:2153
""" """
opt = None opt = None
@ -211,10 +220,11 @@ class CompletionItemDelegate(QStyledItemDelegate):
painter = None painter = None
def sizeHint(self, option, index): def sizeHint(self, option, index):
"""Overrides sizeHint of QStyledItemDelegate. """Override sizeHint of QStyledItemDelegate.
Returns the cell size based on the QTextDocument size, but might not Returns the cell size based on the QTextDocument size, but might not
work correctly yet. work correctly yet.
""" """
value = index.data(Qt.SizeHintRole) value = index.data(Qt.SizeHintRole)
if value is not None: if value is not None:
@ -228,7 +238,7 @@ class CompletionItemDelegate(QStyledItemDelegate):
docsize, self.opt.widget) + QSize(10, 0) docsize, self.opt.widget) + QSize(10, 0)
def paint(self, painter, option, index): def paint(self, painter, option, index):
"""Overrides the QStyledItemDelegate paint function.""" """Override the QStyledItemDelegate paint function."""
painter.save() painter.save()
self.painter = painter self.painter = painter
@ -244,12 +254,12 @@ class CompletionItemDelegate(QStyledItemDelegate):
painter.restore() painter.restore()
def _draw_background(self): def _draw_background(self):
"""Draw the background of an ItemViewItem""" """Draw the background of an ItemViewItem."""
self.style.drawPrimitive(self.style.PE_PanelItemViewItem, self.opt, self.style.drawPrimitive(self.style.PE_PanelItemViewItem, self.opt,
self.painter, self.opt.widget) self.painter, self.opt.widget)
def _draw_icon(self): def _draw_icon(self):
"""Draw the icon of an ItemViewItem""" """Draw the icon of an ItemViewItem."""
icon_rect = self.style.subElementRect( icon_rect = self.style.subElementRect(
self.style.SE_ItemViewItemDecoration, self.opt, self.opt.widget) self.style.SE_ItemViewItemDecoration, self.opt, self.opt.widget)
@ -269,6 +279,7 @@ class CompletionItemDelegate(QStyledItemDelegate):
in Qt: We use a QTextDocument to draw text. in Qt: We use a QTextDocument to draw text.
index of the item of the item -- The QModelIndex of the item to draw. index of the item of the item -- The QModelIndex of the item to draw.
""" """
if not self.opt.text: if not self.opt.text:
return return
@ -311,6 +322,7 @@ class CompletionItemDelegate(QStyledItemDelegate):
doc -- The QTextDocument to draw. doc -- The QTextDocument to draw.
text_rect -- The QRect to clip the drawing to. text_rect -- The QRect to clip the drawing to.
""" """
clip = QRectF(0, 0, text_rect.width(), text_rect.height()) clip = QRectF(0, 0, text_rect.width(), text_rect.height())
doc.drawContents(self.painter, clip) doc.drawContents(self.painter, clip)
@ -319,6 +331,7 @@ class CompletionItemDelegate(QStyledItemDelegate):
"""Return the QTextDocument of an item. """Return the QTextDocument of an item.
index -- The QModelIndex of the item to draw. index -- The QModelIndex of the item to draw.
""" """
# FIXME we probably should do eliding here. See # FIXME we probably should do eliding here. See
# qcommonstyle.cpp:viewItemDrawText # qcommonstyle.cpp:viewItemDrawText
@ -358,7 +371,7 @@ class CompletionItemDelegate(QStyledItemDelegate):
return doc return doc
def _draw_focus_rect(self): def _draw_focus_rect(self):
"""Draws the focus rectangle of an ItemViewItem""" """Draw the focus rectangle of an ItemViewItem."""
state = self.opt.state state = self.opt.state
if not state & QStyle.State_HasFocus: if not state & QStyle.State_HasFocus:
return return

View File

@ -25,11 +25,14 @@ from qutebrowser.widgets.completion import CompletionView
class MainWindow(QMainWindow): class MainWindow(QMainWindow):
"""The main window of QuteBrowser. """The main window of QuteBrowser.
Adds all needed components to a vbox, initializes subwidgets and connects Adds all needed components to a vbox, initializes subwidgets and connects
signals. signals.
""" """
cwidget = None cwidget = None
vbox = None vbox = None
tabs = None tabs = None

View File

@ -27,7 +27,9 @@ 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
cmd = None cmd = None
txt = None txt = None
@ -46,7 +48,7 @@ class StatusBar(QWidget):
""" """
def __setattr__(self, name, value): def __setattr__(self, name, value):
"""Update the stylesheet if relevant attributes have been changed""" """Update the stylesheet if relevant attributes have been changed."""
super().__setattr__(name, value) super().__setattr__(name, value)
if name == 'fgcolor' and value is not None: if name == 'fgcolor' and value is not None:
config.colordict['statusbar.fg.__cur__'] = value config.colordict['statusbar.fg.__cur__'] = value
@ -78,13 +80,13 @@ class StatusBar(QWidget):
self.hbox.addWidget(self.prog) self.hbox.addWidget(self.prog)
def disp_error(self, text): def disp_error(self, text):
"""Displays an error in the statusbar""" """Displaysan error in the statusbar."""
self.bgcolor = config.colordict.getraw('statusbar.bg.error') self.bgcolor = config.colordict.getraw('statusbar.bg.error')
self.fgcolor = config.colordict.getraw('statusbar.fg.error') self.fgcolor = config.colordict.getraw('statusbar.fg.error')
self.txt.error = text self.txt.error = text
def clear_error(self): def clear_error(self):
"""Clears a displayed error from the status bar""" """Clear a displayed error from the status bar."""
self.bgcolor = config.colordict.getraw('statusbar.bg') self.bgcolor = config.colordict.getraw('statusbar.bg')
self.fgcolor = config.colordict.getraw('statusbar.fg') self.fgcolor = config.colordict.getraw('statusbar.fg')
self.txt.error = '' self.txt.error = ''
@ -93,6 +95,7 @@ class StatusBar(QWidget):
"""Extend resizeEvent of QWidget to emit a resized signal afterwards. """Extend resizeEvent of QWidget to emit a resized signal afterwards.
e -- The QResizeEvent. e -- The QResizeEvent.
""" """
super().resizeEvent(e) super().resizeEvent(e)
self.resized.emit(self.geometry()) self.resized.emit(self.geometry())

View File

@ -27,7 +27,9 @@ import qutebrowser.commands.keys as keys
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 # Emitted when a command is triggered by the user
got_cmd = pyqtSignal(str) got_cmd = pyqtSignal(str)
# Emitted for searches triggered by the user # Emitted for searches triggered by the user
@ -108,13 +110,12 @@ class Command(QLineEdit):
super().focusInEvent(e) super().focusInEvent(e)
def _histbrowse_start(self): def _histbrowse_start(self):
"""Start browsing to the history. """Start browsing to the history.
Called when the user presses the up/down key and wasn't browsing the Called when the user presses the up/down key and wasn't browsing the
history already. history already.
"""
"""
pre = self.text().strip() pre = self.text().strip()
logging.debug('Preset text: "{}"'.format(pre)) logging.debug('Preset text: "{}"'.format(pre))
if pre: if pre:
@ -157,16 +158,17 @@ class Command(QLineEdit):
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):
"""Override QValidator::validate.
"""Overrides QValidator::validate.
string -- The string to validate. string -- The string to validate.
pos -- The current curser position. pos -- The current curser position.
Returns a tuple (status, string, pos) as a QValidator should.\ Returns a tuple (status, string, pos) as a QValidator should.
""" """
if any(string.startswith(c) for c in keys.startchars): if any(string.startswith(c) for c in keys.startchars):
return (QValidator.Acceptable, string, pos) return (QValidator.Acceptable, string, pos)

View File

@ -23,7 +23,9 @@ from PyQt5.QtWidgets import QProgressBar, QSizePolicy
class Progress(QProgressBar): class Progress(QProgressBar):
"""The progress bar part of the status bar.""" """The progress bar part of the status bar."""
statusbar = None statusbar = None
color = None color = None
_stylesheet = """ _stylesheet = """
@ -67,12 +69,11 @@ class Progress(QProgressBar):
self.show() self.show()
def load_finished(self, ok): def load_finished(self, ok):
"""Hide the progress bar or color it red, depending on ok. """Hide the progress bar or color it red, depending on ok.
Slot for the loadFinished signal of a QWebView. Slot for the loadFinished signal of a QWebView.
"""
"""
if ok: if ok:
self.color = config.colordict.getraw('status.progress.bg') self.color = config.colordict.getraw('status.progress.bg')
self.hide() self.hide()

View File

@ -26,7 +26,9 @@ class Text(QLabel):
"""The text part of the status bar. """The text part of the status bar.
Contains several parts (keystring, error, text, scrollperc) which are later Contains several parts (keystring, error, text, scrollperc) which are later
joined and displayed.""" joined and displayed.
"""
keystring = '' keystring = ''
error = '' error = ''

View File

@ -24,6 +24,7 @@ import qutebrowser.utils.config as config
class TabWidget(QTabWidget): class TabWidget(QTabWidget):
"""The tabwidget used for TabbedBrowser.""" """The tabwidget used for TabbedBrowser."""
# FIXME there is still some ugly 1px white stripe from somewhere if we do # FIXME there is still some ugly 1px white stripe from somewhere if we do