From 6f3a2448baaadabcacef64b46a4031894168e6d2 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 28 Jan 2014 23:04:02 +0100 Subject: [PATCH] pep8 fixes --- qutebrowser/__init__.py | 2 +- qutebrowser/app.py | 11 ++++++----- qutebrowser/commands/__init__.py | 16 ++++++++++++++++ qutebrowser/commands/keys.py | 3 ++- qutebrowser/commands/utils.py | 18 ++++++++++++------ qutebrowser/utils/__init__.py | 1 + qutebrowser/utils/completion.py | 3 +++ qutebrowser/utils/config.py | 8 ++++++-- qutebrowser/widgets/browser.py | 16 +++++++++------- qutebrowser/widgets/completion.py | 6 +++--- qutebrowser/widgets/mainwindow.py | 4 ++-- qutebrowser/widgets/statusbar/__init__.py | 3 +-- qutebrowser/widgets/statusbar/command.py | 22 +++++++++++----------- qutebrowser/widgets/statusbar/progress.py | 2 +- qutebrowser/widgets/statusbar/text.py | 2 +- qutebrowser/widgets/tabbar.py | 1 + 16 files changed, 76 insertions(+), 42 deletions(-) diff --git a/qutebrowser/__init__.py b/qutebrowser/__init__.py index 8b1378917..1a0ae0377 100644 --- a/qutebrowser/__init__.py +++ b/qutebrowser/__init__.py @@ -1 +1 @@ - +"""A vim like browser based on Qt""" diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 08e24364c..e8c90069d 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -13,15 +13,16 @@ from qutebrowser.widgets.mainwindow import MainWindow from qutebrowser.commands.keys import KeyParser from qutebrowser.utils.appdirs import AppDirs + class QuteBrowser(QApplication): """Main object for QuteBrowser""" - dirs = None # AppDirs - config/cache directories - config = None # Config(Parser) object + dirs = None # AppDirs - config/cache directories + config = None # Config(Parser) object mainwindow = None commandparser = None keyparser = None - args = None # ArgumentParser - timer = None # QTimer for python hacks + args = None # ArgumentParser + timer = None # QTimer for python hacks def __init__(self): super().__init__(sys.argv) @@ -171,7 +172,7 @@ class QuteBrowser(QApplication): try: r = eval(s) out = repr(r) - except Exception as e: # pylint: disable=broad-except + except Exception as e: # pylint: disable=broad-except out = ': '.join([e.__class__.__name__, str(e)]) # FIXME we probably want some nicer interface to display these about: diff --git a/qutebrowser/commands/__init__.py b/qutebrowser/commands/__init__.py index 4aee96ed3..da2c96aaf 100644 --- a/qutebrowser/commands/__init__.py +++ b/qutebrowser/commands/__init__.py @@ -19,79 +19,95 @@ A command class can set the following properties: from qutebrowser.commands.utils import Command + class Open(Command): nargs = 1 split_args = False desc = 'Open a page' + class TabOpen(Command): nargs = 1 split_args = False desc = 'Open a page in a new tab' + class TabClose(Command): nargs = 0 desc = 'Close the current tab' # FIXME also close [count]th tab + class TabNext(Command): nargs = 0 desc = 'Switch to the next tab' # FIXME also support [count] + class TabPrev(Command): nargs = 0 desc = 'Switch to the previous tab' # FIXME also support [count] + class Quit(Command): name = ['quit', 'q'] nargs = 0 desc = 'Quit qutebrowser' + class Reload(Command): nargs = 0 desc = 'Reload the current page' + class Stop(Command): nargs = 0 desc = 'Stop loading the current page' + class Back(Command): nargs = 0 desc = 'Go back one page in the history' # FIXME also support [count] + class Forward(Command): nargs = 0 desc = 'Go forward one page in the history' # FIXME also support [count] + class Print(Command): nargs = 0 desc = 'Print the current page' + class Scroll(Command): nargs = 2 count = True hide = True + class Undo(Command): nargs = 0 desc = 'Undo closing a tab' + class ScrollPercX(Command): nargs = '?' count = True hide = True name = 'scroll_perc_x' + class ScrollPercY(Command): nargs = '?' count = True hide = True name = 'scroll_perc_y' + class PyEval(Command): nargs = 1 split_args = False diff --git a/qutebrowser/commands/keys.py b/qutebrowser/commands/keys.py index 553c2ba79..0f617d299 100644 --- a/qutebrowser/commands/keys.py +++ b/qutebrowser/commands/keys.py @@ -6,9 +6,10 @@ from PyQt5.QtCore import QObject, pyqtSignal from qutebrowser.commands.utils import (CommandParser, ArgumentCountError, NoSuchCommandError) + class KeyParser(QObject): """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 set_cmd_text = pyqtSignal(str) # Signal emitted when the keystring is updated diff --git a/qutebrowser/commands/utils.py b/qutebrowser/commands/utils.py index 4428f5937..e6c73eae2 100644 --- a/qutebrowser/commands/utils.py +++ b/qutebrowser/commands/utils.py @@ -10,20 +10,23 @@ from qutebrowser.utils.completion import CompletionModel cmd_dict = {} + class ArgumentCountError(TypeError): pass + class NoSuchCommandError(ValueError): pass + def register_all(): """Register and initialize all commands.""" # We do this here to avoid a circular import, since commands.commands # imports Command from this module. import qutebrowser.commands - for (name, cls) in inspect.getmembers( # pylint: disable=unused-variable + for (name, cls) in inspect.getmembers( # pylint: disable=unused-variable qutebrowser.commands, (lambda o: inspect.isclass(o) and - o.__module__ == 'qutebrowser.commands')): + o.__module__ == 'qutebrowser.commands')): obj = cls() if isinstance(obj.name, str): names = [obj.name] @@ -32,12 +35,13 @@ def register_all(): for n in names: cmd_dict[n] = obj + class CommandParser(QObject): """Parser for qutebrowser commandline commands""" text = '' cmd = '' args = [] - error = pyqtSignal(str) # Emitted if there's an error + error = pyqtSignal(str) # Emitted if there's an error def _parse(self, text): """Parses a command""" @@ -84,6 +88,7 @@ class CommandParser(QObject): raise self._run(count=count) + class CommandCompletionModel(CompletionModel): # pylint: disable=abstract-method def __init__(self, parent=None): @@ -96,6 +101,7 @@ class CommandCompletionModel(CompletionModel): self._data['Commands'] = sorted(cmdlist) self.init_data() + class Command(QObject): """Base skeleton for a command. See the module help for qutebrowser.commands.commands for details. @@ -113,7 +119,7 @@ class Command(QObject): split_args = True signal = pyqtSignal(tuple) hide = False - desc = "" # FIXME add descriptions everywhere + desc = "" # FIXME add descriptions everywhere def __init__(self): super().__init__() @@ -129,8 +135,8 @@ class Command(QObject): not. """ if ((isinstance(self.nargs, int) and len(args) != self.nargs) or - (self.nargs == '?' and len(args) > 1) or - (self.nargs == '+' and len(args) < 1)): + (self.nargs == '?' and len(args) > 1) or + (self.nargs == '+' and len(args) < 1)): # for nargs == '*', anything is okay raise ArgumentCountError diff --git a/qutebrowser/utils/__init__.py b/qutebrowser/utils/__init__.py index 1adb8dbe5..bf9b36a13 100644 --- a/qutebrowser/utils/__init__.py +++ b/qutebrowser/utils/__init__.py @@ -1,5 +1,6 @@ from PyQt5.QtCore import QUrl + def qurl(url): if isinstance(url, QUrl): return url diff --git a/qutebrowser/utils/completion.py b/qutebrowser/utils/completion.py index 223d4cb0c..624516e0e 100644 --- a/qutebrowser/utils/completion.py +++ b/qutebrowser/utils/completion.py @@ -3,6 +3,7 @@ from collections import OrderedDict from PyQt5.QtCore import (QAbstractItemModel, Qt, QModelIndex, QVariant, QSortFilterProxyModel, pyqtSignal) + class CompletionModel(QAbstractItemModel): def __init__(self, parent=None): super().__init__(parent) @@ -110,6 +111,7 @@ class CompletionModel(QAbstractItemModel): newitem = CompletionItem(item, newcat) newcat.children.append(newitem) + class CompletionItem(): parent = None _data = None @@ -146,6 +148,7 @@ class CompletionItem(): return self.parent.children.index(self) return 0 + class CompletionFilterModel(QSortFilterProxyModel): _pattern = None pattern_changed = pyqtSignal(str) diff --git a/qutebrowser/utils/config.py b/qutebrowser/utils/config.py index 12f9e59d7..9c0ee7b06 100644 --- a/qutebrowser/utils/config.py +++ b/qutebrowser/utils/config.py @@ -60,6 +60,7 @@ _MONOSPACE = ['Monospace', 'DejaVu Sans Mono', 'Consolas', 'Monaco', MONOSPACE = ', '.join(_MONOSPACE) + def init(confdir): global config, colordict config = Config(confdir) @@ -68,9 +69,11 @@ def init(confdir): except KeyError: colordict = ColorDict() + def get_stylesheet(template): return template.strip().format(color=colordict, monospace=MONOSPACE) + class ColorDict(dict): def __getitem__(self, key): try: @@ -90,6 +93,7 @@ class ColorDict(dict): except KeyError: return None + class Config(ConfigParser): """Our own ConfigParser""" configdir = None @@ -98,7 +102,7 @@ class Config(ConfigParser): def __init__(self, configdir): """configdir: directory to store the config in""" super().__init__() - self.optionxform = lambda opt: opt # be case-insensitive + self.optionxform = lambda opt: opt # be case-insensitive self.configdir = configdir if self.configdir is None: self.init_config() @@ -115,7 +119,7 @@ class Config(ConfigParser): self.read_dict(default_config) return cp = ConfigParser() - cp.optionxform = lambda opt: opt # be case-insensitive + cp.optionxform = lambda opt: opt # be case-insensitive cp.read_dict(default_config) if not os.path.exists(self.configdir): os.makedirs(self.configdir, 0o755) diff --git a/qutebrowser/widgets/browser.py b/qutebrowser/widgets/browser.py index c72b0aba3..03c8b6cf8 100644 --- a/qutebrowser/widgets/browser.py +++ b/qutebrowser/widgets/browser.py @@ -1,7 +1,7 @@ import logging 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.QtWebKitWidgets import QWebView, QWebPage @@ -9,18 +9,19 @@ import qutebrowser.utils as utils import qutebrowser.utils.config as config from qutebrowser.widgets.tabbar import TabWidget + class TabbedBrowser(TabWidget): """A TabWidget with QWebViews inside""" - cur_progress = pyqtSignal(int) # Progress of the current tab changed - cur_load_started = pyqtSignal() # Current tab started loading - cur_load_finished = pyqtSignal(bool) # Current tab finished loading - cur_statusbar_message = pyqtSignal(str) # Status bar message + cur_progress = pyqtSignal(int) # Progress of the current tab changed + cur_load_started = pyqtSignal() # Current tab started loading + cur_load_finished = pyqtSignal(bool) # Current tab finished loading + cur_statusbar_message = pyqtSignal(str) # Status bar message # FIXME we need to store this in our browser object # Current tab changed scroll position cur_scroll_perc_changed = pyqtSignal(int, int) keypress = pyqtSignal('QKeyEvent') - _url_stack = [] # Stack of URLs of closed tabs + _url_stack = [] # Stack of URLs of closed tabs def __init__(self, parent): super().__init__(parent) @@ -204,12 +205,13 @@ class TabbedBrowser(TabWidget): round(100 * y / m[1]) if m[1] != 0 else 0) self.cur_scroll_perc_changed.emit(*perc) + class BrowserTab(QWebView): """One browser tab in TabbedBrowser""" progress = 0 scroll_pos_changed = pyqtSignal(int, int) _scroll_pos = (-1, -1) - open_new_tab = False # open new tab for the next action + open_new_tab = False # open new tab for the next action open_tab = pyqtSignal('QUrl') def __init__(self, parent): diff --git a/qutebrowser/widgets/completion.py b/qutebrowser/widgets/completion.py index eeb7da2a8..45b710af4 100644 --- a/qutebrowser/widgets/completion.py +++ b/qutebrowser/widgets/completion.py @@ -1,4 +1,3 @@ -import logging import html 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.commands.utils import CommandCompletionModel + class CompletionView(QTreeView): _stylesheet = """ QTreeView {{ @@ -72,7 +72,7 @@ class CompletionView(QTreeView): def resizeEvent(self, e): width = e.size().width() for i in range(self.model.columnCount()): - self.setColumnWidth(i, width/2) + self.setColumnWidth(i, width / 2) super().resizeEvent(e) def setmodel(self, model): @@ -166,6 +166,7 @@ class CompletionView(QTreeView): # Item is a real item, not a category header -> success return idx + class CompletionItemDelegate(QStyledItemDelegate): opt = None style = None @@ -203,7 +204,6 @@ class CompletionItemDelegate(QStyledItemDelegate): self.opt.icon.paint(self.painter, icon_rect, self.opt.decorationAlignment, mode, state) - def _draw_text(self, index): if not self.opt.text: return diff --git a/qutebrowser/widgets/mainwindow.py b/qutebrowser/widgets/mainwindow.py index aaaf41ca5..3f495d94c 100644 --- a/qutebrowser/widgets/mainwindow.py +++ b/qutebrowser/widgets/mainwindow.py @@ -4,6 +4,7 @@ from qutebrowser.widgets.statusbar import StatusBar from qutebrowser.widgets.browser import TabbedBrowser from qutebrowser.widgets.completion import CompletionView + class MainWindow(QMainWindow): """The main window of QuteBrowser""" cwidget = None @@ -35,7 +36,7 @@ class MainWindow(QMainWindow): self.tabs.cur_progress.connect(self.status.prog.set_progress) self.tabs.cur_load_finished.connect(self.status.prog.load_finished) self.tabs.cur_load_started.connect(lambda: - self.status.prog.set_progress(0)) + self.status.prog.set_progress(0)) self.tabs.cur_scroll_perc_changed.connect(self.status.txt.set_perc) self.tabs.cur_statusbar_message.connect(self.status.txt.set_text) self.status.cmd.esc_pressed.connect(self.tabs.setFocus) @@ -47,4 +48,3 @@ class MainWindow(QMainWindow): #self.retranslateUi(MainWindow) #self.tabWidget.setCurrentIndex(0) #QtCore.QMetaObject.connectSlotsByName(MainWindow) - diff --git a/qutebrowser/widgets/statusbar/__init__.py b/qutebrowser/widgets/statusbar/__init__.py index 307e56eeb..8ecaf7ef2 100644 --- a/qutebrowser/widgets/statusbar/__init__.py +++ b/qutebrowser/widgets/statusbar/__init__.py @@ -1,5 +1,3 @@ -import logging - from PyQt5.QtCore import pyqtSignal 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.progress import Progress + class StatusBar(QWidget): """The statusbar at the bottom of the mainwindow""" hbox = None diff --git a/qutebrowser/widgets/statusbar/command.py b/qutebrowser/widgets/statusbar/command.py index b5f984336..f3e6992cf 100644 --- a/qutebrowser/widgets/statusbar/command.py +++ b/qutebrowser/widgets/statusbar/command.py @@ -4,22 +4,22 @@ from PyQt5.QtWidgets import QLineEdit, QShortcut from PyQt5.QtCore import pyqtSignal, Qt from PyQt5.QtGui import QValidator, QKeySequence -from qutebrowser.commands.utils import CommandCompletionModel class Command(QLineEdit): """The commandline part of the statusbar""" - - got_cmd = pyqtSignal(str) # Emitted when a command is triggered by the user - bar = None # The status bar object - esc_pressed = pyqtSignal() # Emitted when escape is pressed - tab_pressed = pyqtSignal(bool) # Emitted when tab is pressed (arg: shift) - hide_completion = pyqtSignal() # Hide completion window - history = [] # The command history, with newer commands at the bottom + # Emitted when a command is triggered by the user + got_cmd = pyqtSignal(str) + bar = None # The status bar object + esc_pressed = pyqtSignal() # Emitted when escape is pressed + tab_pressed = pyqtSignal(bool) # Emitted when tab is pressed (arg: shift) + hide_completion = pyqtSignal() # Hide completion window + history = [] # The command history, with newer commands at the bottom _tmphist = [] _histpos = None # 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. def __init__(self, bar): @@ -103,7 +103,7 @@ class Command(QLineEdit): def key_down_handler(self): logging.debug("history up [pre]: pos {}".format(self._histpos, - self._tmphist, len(self._tmphist), self._histpos)) + self._tmphist, len(self._tmphist), self._histpos)) if (self._histpos is None or self._histpos >= len(self._tmphist) - 1 or not self._tmphist): @@ -119,6 +119,7 @@ class Command(QLineEdit): def key_stab_handler(self): self.tab_pressed.emit(True) + class Validator(QValidator): """Validator to prevent the : from getting deleted""" def validate(self, string, pos): @@ -126,4 +127,3 @@ class Validator(QValidator): return (QValidator.Acceptable, string, pos) else: return (QValidator.Invalid, string, pos) - diff --git a/qutebrowser/widgets/statusbar/progress.py b/qutebrowser/widgets/statusbar/progress.py index 77db7b89f..473f55a14 100644 --- a/qutebrowser/widgets/statusbar/progress.py +++ b/qutebrowser/widgets/statusbar/progress.py @@ -3,6 +3,7 @@ import qutebrowser.utils.config as config from PyQt5.QtWidgets import QProgressBar, QSizePolicy from PyQt5.QtCore import QSize + class Progress(QProgressBar): """ The progress bar part of the status bar""" bar = None @@ -59,4 +60,3 @@ class Progress(QProgressBar): self.hide() else: self.color = config.colordict.getraw('statusbar.progress.bg.error') - diff --git a/qutebrowser/widgets/statusbar/text.py b/qutebrowser/widgets/statusbar/text.py index 6073680b1..083c9bce4 100644 --- a/qutebrowser/widgets/statusbar/text.py +++ b/qutebrowser/widgets/statusbar/text.py @@ -1,6 +1,7 @@ import logging from PyQt5.QtWidgets import QLabel + class Text(QLabel): """The text part of the status bar, composed of several 'widgets'""" keystring = '' @@ -37,4 +38,3 @@ class Text(QLabel): """Update the text displayed""" self.setText(' '.join([self.keystring, self.error, self.text, self.scrollperc])) - diff --git a/qutebrowser/widgets/tabbar.py b/qutebrowser/widgets/tabbar.py index 35c7f87f4..c05071b59 100644 --- a/qutebrowser/widgets/tabbar.py +++ b/qutebrowser/widgets/tabbar.py @@ -3,6 +3,7 @@ from PyQt5.QtCore import Qt import qutebrowser.utils.config as config + class TabWidget(QTabWidget): """The tabwidget used for TabbedBrowser"""