Commit 89180a1e authored by Yan's avatar Yan
Browse files

Console history, fixed config

* removed bug induced by commit 9720776c
* rewrote console dock - console has history now
parent 60009e5a
...@@ -282,7 +282,7 @@ def main(): ...@@ -282,7 +282,7 @@ def main():
treedock = docks.treeDockWidget( treedock = docks.treeDockWidget(
"&File browser", "view/filebrowservisible", update, load_file, "&File browser", "view/filebrowservisible", update, load_file,
main_window, augCanvas, config, loadthread) main_window, augCanvas, config, loadthread)
paramsdock = docks.augDock("Acquisition parameters", "&Acq parameters", paramsdock = docks.AugDock("Acquisition parameters", "&Acq parameters",
"view/acqparvisible") "view/acqparvisible")
update.signal.connect(lambda: gt.update_paramstable(augCanvas)) update.signal.connect(lambda: gt.update_paramstable(augCanvas))
paramsdock.setWidget(augCanvas.paramstable) paramsdock.setWidget(augCanvas.paramstable)
......
...@@ -20,7 +20,7 @@ def settings(): ...@@ -20,7 +20,7 @@ def settings():
("imggen/yinch", 4), ("imggen/yinch", 4),
("imggen/dpi", 300), ("imggen/dpi", 300),
("imggen/xtics", 5)} ("imggen/xtics", 5)}
[print("will set value", i[0]) [settings.setValue(*i)
for i in defvals if not settings.contains(i[0])] for i in defvals if not settings.contains(i[0])]
return settings return settings
......
#!/usr/bin/env python3 #!/usr/bin/env python3
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from PyQt5 import QtCore
from code import InteractiveConsole from code import InteractiveConsole
from io import StringIO from io import StringIO
from os import path from os import path
...@@ -8,11 +9,11 @@ import contextlib ...@@ -8,11 +9,11 @@ import contextlib
import prasopes.config as cf import prasopes.config as cf
class augDock(QtWidgets.QDockWidget): class AugDock(QtWidgets.QDockWidget):
"""construct dock with vboxlayout and action to show/hide""" """construct dock with vboxlayout and action to show/hide"""
def __init__(self, name, actionname, cfval): def __init__(self, name, actionname, cfval):
config = cf.settings() config = cf.settings()
QtWidgets.QDockWidget.__init__(self, name) super().__init__(name)
self.setWidget(QtWidgets.QWidget()) self.setWidget(QtWidgets.QWidget())
self.layout = QtWidgets.QVBoxLayout(self.widget()) self.layout = QtWidgets.QVBoxLayout(self.widget())
self.action = QtWidgets.QAction( self.action = QtWidgets.QAction(
...@@ -31,6 +32,27 @@ class augDock(QtWidgets.QDockWidget): ...@@ -31,6 +32,27 @@ class augDock(QtWidgets.QDockWidget):
event.ignore() event.ignore()
class AugLineEdit(QtWidgets.QLineEdit):
"""QLineEdit with history"""
def __init__(self):
super().__init__()
self.history = []
self.historypos = 0
self.returnPressed.connect(lambda: self.history.append(self.text())
if self.text() != "" else None)
def keyPressEvent(self, event):
"""super().keyPressEvent override"""
if event.key() in (QtCore.Qt.Key_Up, QtCore.Qt.Key_Down):
self.historypos = min(len(self.history), self.historypos+1) if\
event.key() == QtCore.Qt.Key_Up else max(0, self.historypos-1)
self.setText(self.history[-self.historypos])\
if self.historypos > 0 else self.setText("")
else:
self.historypos = 0
super().keyPressEvent(event)
def consoleDockWidget(localvars, actionname, cfval): def consoleDockWidget(localvars, actionname, cfval):
def consoleExecfunc(inp, outp, loc): def consoleExecfunc(inp, outp, loc):
stream = StringIO() stream = StringIO()
...@@ -49,10 +71,10 @@ def consoleDockWidget(localvars, actionname, cfval): ...@@ -49,10 +71,10 @@ def consoleDockWidget(localvars, actionname, cfval):
outtext = stream.getvalue() outtext = stream.getvalue()
if outtext != "": if outtext != "":
outp.append(outtext[:-1]) outp.append(outtext[:-1])
dock = augDock("console", actionname, cfval) dock = AugDock("console", actionname, cfval)
coutput = QtWidgets.QTextEdit() coutput = QtWidgets.QTextEdit()
coutput.setReadOnly(True) coutput.setReadOnly(True)
cinput = QtWidgets.QLineEdit() cinput = AugLineEdit()
cinput.returnPressed.connect(lambda: consoleExecfunc( cinput.returnPressed.connect(lambda: consoleExecfunc(
cinput, coutput, localvars)) cinput, coutput, localvars))
[dock.layout.addWidget(i) for i in (coutput, cinput)] [dock.layout.addWidget(i) for i in (coutput, cinput)]
...@@ -71,7 +93,7 @@ def treeDockWidget(actionname, cfval, update, loadfnc, parent, ...@@ -71,7 +93,7 @@ def treeDockWidget(actionname, cfval, update, loadfnc, parent,
treeview.expand(activeDir) treeview.expand(activeDir)
dirview = QtWidgets.QListView() dirview = QtWidgets.QListView()
dirview.setModel(fileModel) dirview.setModel(fileModel)
dock = augDock("Folder View", actionname, cfval) dock = AugDock("Folder View", actionname, cfval)
[dock.layout.addWidget(i) for i in (treeview, dirview)] [dock.layout.addWidget(i) for i in (treeview, dirview)]
def scrolltoonce(): def scrolltoonce():
......
Supports Markdown
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