Refactor commandline parsing
This commit is contained in:
parent
7c866f5014
commit
857228e4f2
@ -8,7 +8,7 @@ def main():
|
|||||||
|
|
||||||
mw = MainWindow()
|
mw = MainWindow()
|
||||||
cp = cmds.CommandParser()
|
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['openurl'].connect(mw.tabs.openurl)
|
||||||
cmds.cmd_dict['tabopen'].connect(mw.tabs.tabopen)
|
cmds.cmd_dict['tabopen'].connect(mw.tabs.tabopen)
|
||||||
cmds.cmd_dict['quit'].connect(QApplication.closeAllWindows) # FIXME
|
cmds.cmd_dict['quit'].connect(QApplication.closeAllWindows) # FIXME
|
||||||
|
@ -13,7 +13,7 @@ def register_all():
|
|||||||
|
|
||||||
class CommandParser(QObject):
|
class CommandParser(QObject):
|
||||||
def parse(self, test):
|
def parse(self, test):
|
||||||
parts = text.lstrip(':').strip().split()
|
parts = text.strip().split()
|
||||||
cmd = parts[0]
|
cmd = parts[0]
|
||||||
args = parts[1:]
|
args = parts[1:]
|
||||||
obj = cmd_dict[cmd]()
|
obj = cmd_dict[cmd]()
|
||||||
|
@ -31,7 +31,15 @@ class StatusText(QLabel):
|
|||||||
self.setStyleSheet("padding-right: 1px")
|
self.setStyleSheet("padding-right: 1px")
|
||||||
|
|
||||||
class StatusCommand(QLineEdit):
|
class StatusCommand(QLineEdit):
|
||||||
|
got_cmd = pyqtSignal(str)
|
||||||
|
|
||||||
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.setStyleSheet("border: 0px; padding-left: 1px")
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user