Display error on unknown command

This commit is contained in:
Florian Bruhin 2014-01-17 07:04:24 +01:00
parent 837f53edea
commit cb0c2604f3
3 changed files with 16 additions and 5 deletions

View File

@ -13,6 +13,7 @@ def main():
kp.set_cmd_text.connect(mw.status.cmd.set_cmd) kp.set_cmd_text.connect(mw.status.cmd.set_cmd)
mw.status.cmd.got_cmd.connect(cp.parse) mw.status.cmd.got_cmd.connect(cp.parse)
mw.status.cmd.got_cmd.connect(mw.setFocus) 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['open'].signal.connect(mw.tabs.openurl)
cmds.cmd_dict['tabopen'].signal.connect(mw.tabs.tabopen) cmds.cmd_dict['tabopen'].signal.connect(mw.tabs.tabopen)
cmds.cmd_dict['quit'].signal.connect(QApplication.closeAllWindows) # FIXME cmds.cmd_dict['quit'].signal.connect(QApplication.closeAllWindows) # FIXME

View File

@ -12,11 +12,17 @@ def register_all():
cls.bind() cls.bind()
class CommandParser(QObject): class CommandParser(QObject):
error = pyqtSignal(str)
def parse(self, text): def parse(self, text):
parts = text.strip().split() parts = text.strip().split()
cmd = parts[0] cmd = parts[0]
argv = parts[1:] argv = parts[1:]
obj = cmd_dict[cmd] try:
obj = cmd_dict[cmd]
except KeyError:
self.error.emit("{}: no such command".format(cmd))
return
try: try:
obj.check(argv) obj.check(argv)
except TypeError: except TypeError:

View File

@ -6,7 +6,7 @@ class StatusBar(QWidget):
def __init__(self, parent): def __init__(self, parent):
super().__init__(parent) super().__init__(parent)
self.setObjectName(self.__class__.__name__) self.setObjectName(self.__class__.__name__)
self.bg_color("black") self.bg_color("white", "black")
self.hbox = QHBoxLayout(self) self.hbox = QHBoxLayout(self)
self.hbox.setObjectName("status_hbox") self.hbox.setObjectName("status_hbox")
self.hbox.setContentsMargins(0, 0, 0, 0) self.hbox.setContentsMargins(0, 0, 0, 0)
@ -18,14 +18,18 @@ class StatusBar(QWidget):
self.lbl = StatusText(self) self.lbl = StatusText(self)
self.hbox.addWidget(self.lbl) self.hbox.addWidget(self.lbl)
def bg_color(self, color): def bg_color(self, fg, bg):
self.setStyleSheet(""" self.setStyleSheet("""
* { * {
background: """ + color + """; background: """ + bg + """;
color: white; color: """ + fg + """;
font-family: Monospace; font-family: Monospace;
}""") }""")
def disp_error(self, text):
self.bg_color('white', 'red')
self.lbl.setText('Error: {}'.format(text))
class StatusText(QLabel): class StatusText(QLabel):
def __init__(self, parent): def __init__(self, parent):
super().__init__(parent) super().__init__(parent)