|
|
|
|
@ -80,10 +80,7 @@ class Console(QtWidgets.QPlainTextEdit):
|
|
|
|
|
with open(filename) as f: |
|
|
|
|
script = f.read() |
|
|
|
|
|
|
|
|
|
# eval is generally considered bad practice. use it wisely! |
|
|
|
|
result = eval(script, self.namespace, self.namespace) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.exec_command(script) |
|
|
|
|
|
|
|
|
|
def updateNamespace(self, namespace): |
|
|
|
|
self.namespace.update(namespace) |
|
|
|
|
@ -205,13 +202,18 @@ class Console(QtWidgets.QPlainTextEdit):
|
|
|
|
|
for i in range(len(self.prompt) + position): |
|
|
|
|
self.moveCursor(QtGui.QTextCursor.Right) |
|
|
|
|
|
|
|
|
|
def runCommand(self): |
|
|
|
|
def run_command(self): |
|
|
|
|
command = self.getCommand() |
|
|
|
|
self.addToHistory(command) |
|
|
|
|
|
|
|
|
|
command = self.getConstruct(command) |
|
|
|
|
|
|
|
|
|
if command: |
|
|
|
|
self.exec_command(command) |
|
|
|
|
self.newPrompt('') |
|
|
|
|
self.set_json(False) |
|
|
|
|
|
|
|
|
|
def exec_command(self, command): |
|
|
|
|
tmp_stdout = sys.stdout |
|
|
|
|
|
|
|
|
|
class stdoutProxy(): |
|
|
|
|
@ -232,7 +234,6 @@ class Console(QtWidgets.QPlainTextEdit):
|
|
|
|
|
if type(self.namespace.get(command)) == type(lambda:None): |
|
|
|
|
self.appendPlainText("'{}' is a function. Type '{}()' to use it in the Python console." |
|
|
|
|
.format(command, command)) |
|
|
|
|
self.newPrompt('') |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
sys.stdout = stdoutProxy(self.appendPlainText) |
|
|
|
|
@ -257,9 +258,6 @@ class Console(QtWidgets.QPlainTextEdit):
|
|
|
|
|
traceback_lines.pop(i) |
|
|
|
|
self.appendPlainText('\n'.join(traceback_lines)) |
|
|
|
|
sys.stdout = tmp_stdout |
|
|
|
|
self.newPrompt('') |
|
|
|
|
self.set_json(False) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def keyPressEvent(self, event): |
|
|
|
|
if event.key() == QtCore.Qt.Key_Tab: |
|
|
|
|
@ -269,7 +267,7 @@ class Console(QtWidgets.QPlainTextEdit):
|
|
|
|
|
self.hide_completions() |
|
|
|
|
|
|
|
|
|
if event.key() in (QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return): |
|
|
|
|
self.runCommand() |
|
|
|
|
self.run_command() |
|
|
|
|
return |
|
|
|
|
if event.key() == QtCore.Qt.Key_Home: |
|
|
|
|
self.setCursorPosition(0) |
|
|
|
|
|