Move CmdValidator out of StatusCommand, add CmdCompleter example
This commit is contained in:
parent
d18162d902
commit
f87e9c3546
@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from PyQt5.QtWidgets import (QLineEdit, QHBoxLayout, QLabel, QWidget,
|
from PyQt5.QtWidgets import (QLineEdit, QHBoxLayout, QLabel, QWidget,
|
||||||
QShortcut, QProgressBar, QSizePolicy)
|
QShortcut, QProgressBar, QSizePolicy, QCompleter)
|
||||||
from PyQt5.QtCore import pyqtSignal, Qt, QSize
|
from PyQt5.QtCore import pyqtSignal, Qt, QSize
|
||||||
from PyQt5.QtGui import QValidator, QKeySequence
|
from PyQt5.QtGui import QValidator, QKeySequence
|
||||||
|
|
||||||
@ -135,13 +135,6 @@ class StatusText(QLabel):
|
|||||||
|
|
||||||
class StatusCommand(QLineEdit):
|
class StatusCommand(QLineEdit):
|
||||||
"""The commandline part of the statusbar"""
|
"""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
|
got_cmd = pyqtSignal(str) # Emitted when a command is triggered by the user
|
||||||
bar = None # The status bar object
|
bar = None # The status bar object
|
||||||
@ -154,7 +147,8 @@ class StatusCommand(QLineEdit):
|
|||||||
super().__init__(bar)
|
super().__init__(bar)
|
||||||
self.bar = bar
|
self.bar = bar
|
||||||
self.setStyleSheet("border: 0px; padding-left: 1px")
|
self.setStyleSheet("border: 0px; padding-left: 1px")
|
||||||
self.setValidator(self.CmdValidator())
|
self.setValidator(CmdValidator())
|
||||||
|
self.setCompleter(CmdCompleter())
|
||||||
self.returnPressed.connect(self.process_cmd)
|
self.returnPressed.connect(self.process_cmd)
|
||||||
self.textEdited.connect(self._histbrowse_stop)
|
self.textEdited.connect(self._histbrowse_stop)
|
||||||
|
|
||||||
@ -235,3 +229,15 @@ class StatusCommand(QLineEdit):
|
|||||||
def key_tab_handler(self):
|
def key_tab_handler(self):
|
||||||
# TODO implement tab completion
|
# TODO implement tab completion
|
||||||
logging.debug('tab pressed')
|
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'])
|
||||||
|
Loading…
Reference in New Issue
Block a user