Enforce : in status bar command

This commit is contained in:
Florian Bruhin 2014-01-16 21:42:46 +01:00
parent 1736eb20c8
commit a691cc10af

View File

@ -1,5 +1,6 @@
from PyQt5.QtWidgets import QLineEdit, QHBoxLayout, QLabel, QWidget from PyQt5.QtWidgets import QLineEdit, QHBoxLayout, QLabel, QWidget
from PyQt5.QtCore import pyqtSignal from PyQt5.QtCore import pyqtSignal
from PyQt5.QtGui import QValidator
class StatusBar(QWidget): class StatusBar(QWidget):
def __init__(self, parent): def __init__(self, parent):
@ -38,9 +39,17 @@ class StatusCommand(QLineEdit):
super().__init__(parent) super().__init__(parent)
self.setObjectName(self.__class__.__name__) self.setObjectName(self.__class__.__name__)
self.setStyleSheet("border: 0px; padding-left: 1px") self.setStyleSheet("border: 0px; padding-left: 1px")
self.setValidator(CmdValidator())
self.returnPressed.connect(self.process_cmd) self.returnPressed.connect(self.process_cmd)
def process_cmd(self): def process_cmd(self):
text = self.text().lstrip(':') text = self.text().lstrip(':')
self.setText('') self.setText('')
self.got_cmd.emit(text) self.got_cmd.emit(text)
class CmdValidator(QValidator):
def validate(self, string, pos):
if string.startswith(':'):
return (QValidator.Acceptable, string, pos)
else:
return (QValidator.Invalid, string, pos)