Commit b24052b8 authored by Yan's avatar Yan
Browse files

Rewritten docks, console dock widget pt2

* all docks are described in docks.py file and they use common class
* actions linked to dock visibility is inherited in the class
parent 67ec9b57
......@@ -24,7 +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.docks as docks
import prasopes.tangoicons
import sys
import matplotlib
......@@ -261,6 +261,15 @@ def main():
if QtGui.QIcon.themeName() is "":
QtGui.QIcon.setThemeName("TangoMFK")
consoledock = docks.consoleDockWidget(
locals(), "&Console", "view/consolevisible")
treedock = docks.treeDockWidget(
load_file, update, "&File browser", "view/filebrowservisible")
paramsdock = docks.augDock("Acquisition parameters", "&Acq parameters",
"view/acqparvisible")
update.signal.connect(lambda: gt.update_paramstable(paramstable, ms, chrom))
paramsdock.setWidget(paramstable)
openact = QtWidgets.QAction(QtGui.QIcon.fromTheme(
"document-open"), "&Open...", None)
openact.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_O)
......@@ -314,14 +323,6 @@ def main():
oddevenact.triggered.connect(lambda:
oddeven_changed(chromatogram, spectrum, ds, ms, filename, chrom,
config, oddevenact))
filebrowseract = QtWidgets.QAction(
"&File browser", None, checkable=True,
checked=config.value("view/filebrowservisible", type=bool))
filebrowseract.triggered.connect(lambda: config.setValue(
"view/filebrowservisible", filebrowseract.isChecked()))
filebrowseract.triggered.connect(
lambda: treedock.show() if filebrowseract.isChecked() == True
else treedock.hide())
predictform = QtWidgets.QLineEdit(maximumWidth=150)
predictform.editingFinished.connect(lambda: predictmz(
......@@ -343,9 +344,8 @@ def main():
tools_menu.addAction(drlact)
tools_menu.addSeparator()
view_menu = QtWidgets.QMenu('&View', main_window)
view_menu.addAction(filebrowseract)
view_menu.addAction(autozoomy)
view_menu.addAction(intensitiesact)
[view_menu.addAction(i.action) for i in (treedock, paramsdock, consoledock)]
[view_menu.addAction(i) for i in (autozoomy, intensitiesact)]
view_menu.addSeparator()
view_menu.addAction(oddevenact)
main_window.menuBar().addMenu(view_menu)
......@@ -372,50 +372,6 @@ def main():
toolBar.addSeparator()
toolBar.addAction(autozoomy)
paramsdock = QtWidgets.QDockWidget()
update.signal.connect(lambda: gt.update_paramstable(paramstable, ms, chrom))
paramsdock.setWidget(paramstable)
fileModel = QtWidgets.QFileSystemModel()
fileModel.setRootPath('')
activeDir = fileModel.index(config.value("open_folder"))
treeview = QtWidgets.QTreeView()
treeview.setModel(fileModel)
treeview.setCurrentIndex(activeDir)
treeview.expand(activeDir)
dirview = QtWidgets.QListView()
dirview.setModel(fileModel)
treedock = QtWidgets.QDockWidget()
def scrolltoonce():
fileModel.directoryLoaded.disconnect(scrolltoonce)
treeview.scrollTo(fileModel.index(config.value("open_folder")), 1)
fileModel.directoryLoaded.connect(scrolltoonce)
fileModel.directoryLoaded.connect(
lambda: treeview.resizeColumnToContents(0))
if not config.value("view/filebrowservisible",type=bool):
treedock.hide()
treedock.setWidget(QtWidgets.QWidget())
treedock_layout = QtWidgets.QVBoxLayout(treedock.widget())
treedock_layout.addWidget(treeview)
treedock_layout.addWidget(dirview)
update.signal.connect(lambda: treeview.setCurrentIndex(fileModel.index(
filename[0])))
update.signal.connect(lambda: dirview.setRootIndex(fileModel.index(
os.path.dirname(os.path.realpath(filename[0])))))
clickload = lambda index: load_file(
main_window, chromatogram, spectrum, ds, ms, filename, chrom,
update, config, loadthread, filename=fileModel.filePath(index))
for i in [treeview.doubleClicked, dirview.doubleClicked, dirview.clicked]:
i.connect(clickload)
def closeOverride(event, dock, action):
action.setChecked(False)
dock.hide()
event.ignore()
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,
......
......@@ -9,6 +9,8 @@ def settings():
settings = QtCore.QSettings("Yansoft","Prasopes")
defvals = {("view/autozoomy", True),
("view/filebrowservisible", True),
("view/consolevisible", True),
("view/acqparvisible", True),
("view/intensities", False),
("view/oddeven", False),
("print/xinch", 10),
......
#!/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
#!/usr/bin/env python3
from PyQt5 import QtWidgets
from code import InteractiveConsole
from io import StringIO
import contextlib
import numpy as np
import prasopes.config as cf
class augDock(QtWidgets.QDockWidget):
"""construct dock with vboxlayout and action to show/hide"""
def __init__(self, name, actionname, cfval):
config = cf.settings()
QtWidgets.QDockWidget.__init__(self, name)
self.setWidget(QtWidgets.QWidget())
self.layout = QtWidgets.QVBoxLayout(self.widget())
self.action = QtWidgets.QAction(
actionname, None, checkable=True,
checked=config.value(cfval, type=bool))
self.action.triggered.connect(lambda: self.show() if\
self.action.isChecked() == True else self.hide())
self.closeEvent = lambda event: self.closeOverride(event)
if not config.value(cfval, type=bool):
self.hide()
def closeOverride(self, event):
self.action.setChecked(False)
self.hide()
event.ignore()
def consoleDockWidget(localvars, actionname, cfval):
def consoleExecfunc(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()):
#If anybody knows better sanitization feel free to let me know
console.runcode("""print(eval('{}'.format(str('"""+text+"""'))))""")
outtext = stream.getvalue()
if outtext != "":
outp.append(outtext[:-1])
dock = augDock("console", actionname, cfval)
coutput = QtWidgets.QTextEdit()
coutput.setReadOnly(True)
cinput = QtWidgets.QLineEdit()
cinput.returnPressed.connect(lambda: consoleExecfunc(
cinput, coutput, localvars))
[dock.layout.addWidget(i) for i in (coutput, cinput)]
return dock
def treeDockWidget(load_file, update, actionname, cfval):
def scrolltoonce():
fileModel.directoryLoaded.disconnect(scrolltoonce)
treeview.scrollTo(fileModel.index(config.value("open_folder")), 1)
config = cf.settings()
fileModel = QtWidgets.QFileSystemModel()
fileModel.setRootPath('')
activeDir = fileModel.index(config.value("open_folder"))
treeview = QtWidgets.QTreeView()
treeview.setModel(fileModel)
treeview.setCurrentIndex(activeDir)
treeview.expand(activeDir)
dirview = QtWidgets.QListView()
dirview.setModel(fileModel)
dock = augDock("Folder View", actionname, cfval)
[dock.layout.addWidget(i) for i in (treeview, dirview)]
fileModel.directoryLoaded.connect(scrolltoonce)
fileModel.directoryLoaded.connect(
lambda: treeview.resizeColumnToContents(0))
update.signal.connect(lambda: treeview.setCurrentIndex(fileModel.index(
filename[0])))
update.signal.connect(lambda: dirview.setRootIndex(fileModel.index(
os.path.dirname(os.path.realpath(filename[0])))))
clickload = lambda index: load_file(
main_window, chromatogram, spectrum, ds, ms, filename, chrom,
update, config, loadthread, filename=fileModel.filePath(index))
for i in [treeview.doubleClicked, dirview.doubleClicked, dirview.clicked]:
i.connect(clickload)
return 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