From f87e9c3546cc493c701ed0b319cbbb6741d2ddd5 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 21 Jan 2014 17:44:50 +0100 Subject: [PATCH] Move CmdValidator out of StatusCommand, add CmdCompleter example --- qutebrowser/widgets/statusbar.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/qutebrowser/widgets/statusbar.py b/qutebrowser/widgets/statusbar.py index e34d07fa2..d99cd5b04 100644 --- a/qutebrowser/widgets/statusbar.py +++ b/qutebrowser/widgets/statusbar.py @@ -1,7 +1,7 @@ import logging from PyQt5.QtWidgets import (QLineEdit, QHBoxLayout, QLabel, QWidget, - QShortcut, QProgressBar, QSizePolicy) + QShortcut, QProgressBar, QSizePolicy, QCompleter) from PyQt5.QtCore import pyqtSignal, Qt, QSize from PyQt5.QtGui import QValidator, QKeySequence @@ -135,13 +135,6 @@ class StatusText(QLabel): class StatusCommand(QLineEdit): """The commandline part of the statusbar""" - class CmdValidator(QValidator): - """Validator to prevent the : from getting deleted""" - def validate(self, string, pos): - if string.startswith(':'): - return (QValidator.Acceptable, string, pos) - else: - return (QValidator.Invalid, string, pos) got_cmd = pyqtSignal(str) # Emitted when a command is triggered by the user bar = None # The status bar object @@ -154,7 +147,8 @@ class StatusCommand(QLineEdit): super().__init__(bar) self.bar = bar self.setStyleSheet("border: 0px; padding-left: 1px") - self.setValidator(self.CmdValidator()) + self.setValidator(CmdValidator()) + self.setCompleter(CmdCompleter()) self.returnPressed.connect(self.process_cmd) self.textEdited.connect(self._histbrowse_stop) @@ -235,3 +229,15 @@ class StatusCommand(QLineEdit): def key_tab_handler(self): # TODO implement tab completion logging.debug('tab pressed') + +class CmdValidator(QValidator): + """Validator to prevent the : from getting deleted""" + def validate(self, string, pos): + if string.startswith(':'): + return (QValidator.Acceptable, string, pos) + else: + return (QValidator.Invalid, string, pos) + +class CmdCompleter(QCompleter): + def __init__(self): + super().__init__([':foo', ':bar', 'baz'])