Display error on unknown command
This commit is contained in:
parent
837f53edea
commit
cb0c2604f3
@ -13,6 +13,7 @@ def main():
|
||||
kp.set_cmd_text.connect(mw.status.cmd.set_cmd)
|
||||
mw.status.cmd.got_cmd.connect(cp.parse)
|
||||
mw.status.cmd.got_cmd.connect(mw.setFocus)
|
||||
cp.error.connect(mw.status.disp_error)
|
||||
cmds.cmd_dict['open'].signal.connect(mw.tabs.openurl)
|
||||
cmds.cmd_dict['tabopen'].signal.connect(mw.tabs.tabopen)
|
||||
cmds.cmd_dict['quit'].signal.connect(QApplication.closeAllWindows) # FIXME
|
||||
|
@ -12,11 +12,17 @@ def register_all():
|
||||
cls.bind()
|
||||
|
||||
class CommandParser(QObject):
|
||||
error = pyqtSignal(str)
|
||||
|
||||
def parse(self, text):
|
||||
parts = text.strip().split()
|
||||
cmd = parts[0]
|
||||
argv = parts[1:]
|
||||
obj = cmd_dict[cmd]
|
||||
try:
|
||||
obj = cmd_dict[cmd]
|
||||
except KeyError:
|
||||
self.error.emit("{}: no such command".format(cmd))
|
||||
return
|
||||
try:
|
||||
obj.check(argv)
|
||||
except TypeError:
|
||||
|
@ -6,7 +6,7 @@ class StatusBar(QWidget):
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
self.setObjectName(self.__class__.__name__)
|
||||
self.bg_color("black")
|
||||
self.bg_color("white", "black")
|
||||
self.hbox = QHBoxLayout(self)
|
||||
self.hbox.setObjectName("status_hbox")
|
||||
self.hbox.setContentsMargins(0, 0, 0, 0)
|
||||
@ -18,14 +18,18 @@ class StatusBar(QWidget):
|
||||
self.lbl = StatusText(self)
|
||||
self.hbox.addWidget(self.lbl)
|
||||
|
||||
def bg_color(self, color):
|
||||
def bg_color(self, fg, bg):
|
||||
self.setStyleSheet("""
|
||||
* {
|
||||
background: """ + color + """;
|
||||
color: white;
|
||||
background: """ + bg + """;
|
||||
color: """ + fg + """;
|
||||
font-family: Monospace;
|
||||
}""")
|
||||
|
||||
def disp_error(self, text):
|
||||
self.bg_color('white', 'red')
|
||||
self.lbl.setText('Error: {}'.format(text))
|
||||
|
||||
class StatusText(QLabel):
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
Loading…
Reference in New Issue
Block a user