Commit 044f9608 authored by Yan's avatar Yan
Browse files

Added console dock widget pt1

* initial console committed
parent 6e88d312
......@@ -24,6 +24,7 @@ import prasopes.filetools as ft
import prasopes.graphtools as gt
import prasopes.imagetools as imgt
import prasopes.zcetools as zce
import prasopes.console as console
import prasopes.tangoicons
import sys
import matplotlib
......@@ -413,6 +414,8 @@ def main():
treedock.closeEvent = lambda event: closeOverride(
event, treedock, filebrowseract)
consoledock = console.consoleDockWidget(locals())
main_window.dragEnterEvent = lambda event: drag_entered(event)
main_window.dropEvent = lambda event: dropped(
event, main_window, chromatogram, spectrum, ds, ms, filename,
......@@ -424,6 +427,7 @@ def main():
main_window.addToolBar(QtCore.Qt.TopToolBarArea, toolBar)
main_window.addDockWidget(QtCore.Qt.LeftDockWidgetArea, treedock)
main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, paramsdock)
main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, consoledock)
main_window.setStatusBar(barHandler.statusBar)
main_window.setFocus()
......
#!/usr/bin/env python3
from PyQt5 import QtWidgets
from code import InteractiveConsole
from io import StringIO
import contextlib
import numpy as np
def execfunc(inp, outp, loc):
stream = StringIO()
console = InteractiveConsole(locals=loc)
text = inp.text()
inp.setText("")
with contextlib.redirect_stdout(stream):
outp.append(">>>"+text)
console.runcode(text)
outtext = stream.getvalue()
if outtext == "":
with contextlib.redirect_stderr(StringIO()):
console.runcode("""print(eval('{}'.format(str('"""+text+"""'))))""")
outtext = stream.getvalue()
if outtext != "":
outp.append(outtext[:-1])
def consoleDockWidget(localvars):
console_output = QtWidgets.QTextEdit()
console_output.setReadOnly(True)
console_input = QtWidgets.QLineEdit()
console_widget = QtWidgets.QWidget()
console_dock = QtWidgets.QDockWidget()
console_dock.setWidget(console_widget)
main_layout = QtWidgets.QVBoxLayout(console_widget)
main_layout.addWidget(console_output)
main_layout.addWidget(console_input)
console_input.returnPressed.connect(lambda: execfunc(
console_input, console_output, localvars))
return console_dock
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment