Refactor commandline parsing

This commit is contained in:
Florian Bruhin 2014-01-16 17:49:57 +01:00
parent 7c866f5014
commit 857228e4f2
3 changed files with 10 additions and 2 deletions

View File

@ -8,7 +8,7 @@ def main():
mw = MainWindow()
cp = cmds.CommandParser()
mw.status.cmd.returnPressed.connect(lambda: cp.parse(mw.status.cmd.text()))
mw.status.cmd.got_cmd.connect(cp.parse)
cmds.cmd_dict['openurl'].connect(mw.tabs.openurl)
cmds.cmd_dict['tabopen'].connect(mw.tabs.tabopen)
cmds.cmd_dict['quit'].connect(QApplication.closeAllWindows) # FIXME

View File

@ -13,7 +13,7 @@ def register_all():
class CommandParser(QObject):
def parse(self, test):
parts = text.lstrip(':').strip().split()
parts = text.strip().split()
cmd = parts[0]
args = parts[1:]
obj = cmd_dict[cmd]()

View File

@ -31,7 +31,15 @@ class StatusText(QLabel):
self.setStyleSheet("padding-right: 1px")
class StatusCommand(QLineEdit):
got_cmd = pyqtSignal(str)
def __init__(self, parent):
super().__init__(parent)
self.setObjectName(self.__class__.__name__)
self.setStyleSheet("border: 0px; padding-left: 1px")
self.returnPressed.connect(self.process_cmd)
def process_cmd(self):
text = self.text().lstrip(':')
self.setText('')
self.got_cmd.emit(text)