Commit f10cd910 authored by Yan's avatar Yan
Browse files

Pep8 fix, more fixes after uniting of spect vars

* spectrum variables were implemented into update_spectrum
* flake8 check of the whole project
parent c960cedf
#!/usr/bin/env python3 #!/usr/bin/env python3
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt5agg import\
FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure from matplotlib.figure import Figure
from matplotlib.widgets import SpanSelector from matplotlib.widgets import SpanSelector
from matplotlib.gridspec import GridSpec
from PyQt5 import QtCore from PyQt5 import QtCore
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from PyQt5 import QtGui from PyQt5 import QtGui
...@@ -14,7 +14,7 @@ from prasopes.predictmz import predict as getmzpattern ...@@ -14,7 +14,7 @@ from prasopes.predictmz import predict as getmzpattern
try: try:
from rawautoparams import load_params from rawautoparams import load_params
autoparams = True autoparams = True
except: except ImportError:
autoparams = False autoparams = False
import numpy as np import numpy as np
import prasopes.config as cf import prasopes.config as cf
...@@ -50,7 +50,7 @@ class QStatusBarLogger(logging.Handler): ...@@ -50,7 +50,7 @@ class QStatusBarLogger(logging.Handler):
class AugFigureCanvas(FigureCanvas): class AugFigureCanvas(FigureCanvas):
#TODO: move the widget into graphtools when I'm done # TODO: move the widget into graphtools when I'm done
def __init__(self): def __init__(self):
self.figure = Figure(figsize=(5, 4), dpi=100, facecolor="None", self.figure = Figure(figsize=(5, 4), dpi=100, facecolor="None",
constrained_layout=True) constrained_layout=True)
...@@ -59,28 +59,31 @@ class AugFigureCanvas(FigureCanvas): ...@@ -59,28 +59,31 @@ class AugFigureCanvas(FigureCanvas):
self.ms = dict(annotation=[], name="Spectrum", xlabel="m/z", self.ms = dict(annotation=[], name="Spectrum", xlabel="m/z",
ylabel="ion count", xtics=20, predict=None, ylabel="ion count", xtics=20, predict=None,
params=[], headers=[], texts=[]) params=[], headers=[], texts=[])
self.chrom = dict(x=[0], y=[0], t_start=None, t_end=None, machtype=None, self.chrom = dict(
name="Chromatogram", xlabel="time(min)", x=[0], y=[0], t_start=None, t_end=None, machtype=None,
ylabel="total ion count", timesarg=[]) name="Chromatogram", xlabel="time(min)", ylabel="total ion count",
timesarg=[])
self.filename = None self.filename = None
self.drlcache = [None, None] self.drlcache = [None, None]
grid = self.figure.add_gridspec(2, 1) grid = self.figure.add_gridspec(2, 1)
self.chromplot = self.figure.add_subplot(grid[0,0], facecolor=(1, 1, 1, 0.8)) self.chromplot = self.figure.add_subplot(grid[0, 0],
self.spectplot = self.figure.add_subplot(grid[1,0], facecolor=(1, 1, 1, 0.8)) facecolor=(1, 1, 1, 0.8))
self.spectplot = self.figure.add_subplot(grid[1, 0],
facecolor=(1, 1, 1, 0.8))
self.setStyleSheet("background-color:transparent;") self.setStyleSheet("background-color:transparent;")
self.setAutoFillBackground(False) self.setAutoFillBackground(False)
self.paramstable = dt.table(["","name","value"], 100) self.paramstable = dt.table(["", "name", "value"], 100)
gt.pan_factory(self.chromplot) gt.pan_factory(self.chromplot)
gt.zoom_factory(self.chromplot, 1.15) gt.zoom_factory(self.chromplot, 1.15)
gt.pan_factory(self.spectplot, self.ms) gt.pan_factory(self.spectplot, self.ms)
gt.zoom_factory(self.spectplot, 1.15, self.ms) gt.zoom_factory(self.spectplot, 1.15, self.ms)
gt.textedit_factory(self.spectplot, self.ms) gt.textedit_factory(self.spectplot, self.ms)
self.mass_selector = gt.AugSpanSelector(self.spectplot, self.ms) self.mass_selector = gt.AugSpanSelector(self.spectplot, self.ms)
#TODO: rewrite timeSelector to better shape when I'm done # TODO: rewrite timeSelector to better shape when I'm done
self.time_selector = SpanSelector(self.chromplot, lambda x_min, x_max: self.time_selector = SpanSelector(
gt.pick_times(x_min, x_max, self), 'horizontal', self.chromplot, lambda x_min, x_max: gt.pick_times(
useblit=True, rectprops=dict(alpha=0.15, facecolor='purple'), x_min, x_max, self), 'horizontal', useblit=True,
button=3) rectprops=dict(alpha=0.15, facecolor='purple'), button=3)
def load_file(parent, augCanvas, update, settings, loadthread, filename=None): def load_file(parent, augCanvas, update, settings, loadthread, filename=None):
...@@ -89,15 +92,16 @@ def load_file(parent, augCanvas, update, settings, loadthread, filename=None): ...@@ -89,15 +92,16 @@ def load_file(parent, augCanvas, update, settings, loadthread, filename=None):
filename = filename or QtWidgets.QFileDialog.getOpenFileName( filename = filename or QtWidgets.QFileDialog.getOpenFileName(
caption="Open spectrum", directory=directory, caption="Open spectrum", directory=directory,
filter="Finnigan RAW files (*.raw, *.RAW)")[0] filter="Finnigan RAW files (*.raw, *.RAW)")[0]
if filename is not '' and os.path.isfile(filename)\ if filename != '' and os.path.isfile(filename)\
and not os.path.isdir(filename): and not os.path.isdir(filename):
error = update_signal() error = update_signal()
errormsg = [] errormsg = []
def runfnc(): def runfnc():
try: try:
[i.clear() for i in ( [i.clear() for i in (
augCanvas.ds, augCanvas.chrom['timesarg'], augCanvas.ds, augCanvas.chrom['timesarg'],
augCanvas.ms['params'],augCanvas.ms['headers'])] augCanvas.ms['params'], augCanvas.ms['headers'])]
[augCanvas.ds.append(dict( [augCanvas.ds.append(dict(
chrom_dat=i[0], masses=i[1], matrix=i[2])) chrom_dat=i[0], masses=i[1], matrix=i[2]))
for i in load_raw(filename, settings.value("tmp_location"))] for i in load_raw(filename, settings.value("tmp_location"))]
...@@ -109,10 +113,10 @@ def load_file(parent, augCanvas, update, settings, loadthread, filename=None): ...@@ -109,10 +113,10 @@ def load_file(parent, augCanvas, update, settings, loadthread, filename=None):
"Error message:\n{}".format(pex.args[0])) "Error message:\n{}".format(pex.args[0]))
error.signal.emit() error.signal.emit()
return return
if autoparams == True: if autoparams:
try: try:
(augCanvas.ms['params'], rawheaders (augCanvas.ms['params'], rawheaders,
, augCanvas.chrom['machtype']) = load_params(filename) augCanvas.chrom['machtype']) = load_params(filename)
segments = [len(subset['chrom_dat'][0]) segments = [len(subset['chrom_dat'][0])
for subset in augCanvas.ds] for subset in augCanvas.ds]
indicies = [sum(segments[:i+1]) indicies = [sum(segments[:i+1])
...@@ -131,13 +135,13 @@ def load_file(parent, augCanvas, update, settings, loadthread, filename=None): ...@@ -131,13 +135,13 @@ def load_file(parent, augCanvas, update, settings, loadthread, filename=None):
parent.setWindowTitle("Prasopes - {}".format( parent.setWindowTitle("Prasopes - {}".format(
os.path.basename(filename))) os.path.basename(filename)))
update.signal.emit() update.signal.emit()
error.signal.connect(lambda: error.signal.connect(lambda: QtWidgets.QMessageBox.critical(
QtWidgets.QMessageBox.critical(parent, errormsg[0], errormsg[1])) parent, errormsg[0], errormsg[1]))
loadthread.run = runfnc loadthread.run = runfnc
loadthread.start() loadthread.start()
def print_graph(data_set, mass_spec, chrom_spec, spect, fn, table): def print_graph(augCanvas):
def printimage(printdevice, img): def printimage(printdevice, img):
printer.setResolution(600) printer.setResolution(600)
painter = QtGui.QPainter(printdevice) painter = QtGui.QPainter(printdevice)
...@@ -145,45 +149,46 @@ def print_graph(data_set, mass_spec, chrom_spec, spect, fn, table): ...@@ -145,45 +149,46 @@ def print_graph(data_set, mass_spec, chrom_spec, spect, fn, table):
linesize = printer.resolution()/15 linesize = printer.resolution()/15
font.setPixelSize(linesize) font.setPixelSize(linesize)
painter.setFont(font) painter.setFont(font)
painter.drawImage(0,0,img) painter.drawImage(0, 0, img)
offset = img.size().height() offset = img.size().height()
line = 1 line = 1
spacing = 1.5 spacing = 1.5
for row in range(table.rowCount()): for row in range(augCanvas.paramstable.rowCount()):
if table.cellWidget(row,0).checkState() == 2: if augCanvas.paramstable.cellWidget(row, 0).checkState() == 2:
text = table.item(row,1).text() + table.item(row,2).text() text = augCanvas.paramstable.item(row, 1).text() +\
painter.drawText(300,int(offset+line*linesize*spacing), text) augCanvas.paramstable.item(row, 2).text()
painter.drawText(300, int(offset+line*linesize*spacing), text)
line += 1 line += 1
painter.end() painter.end()
#TODO: substitute the QPrintPreviewDialog with QPrintPreviewWidget # TODO: substitute the QPrintPreviewDialog with QPrintPreviewWidget
printPreview = QtPrintSupport.QPrintPreviewDialog() printPreview = QtPrintSupport.QPrintPreviewDialog()
printer = printPreview.printer() printer = printPreview.printer()
printer.setPageSize(printer.A5) printer.setPageSize(printer.A5)
printer.setDuplex(printer.DuplexNone) printer.setDuplex(printer.DuplexNone)
image = imgt.paint_image(mass_spec, spect, printer) image = imgt.paint_image(augCanvas.ms, augCanvas.spectplot,
augCanvas.filename, printer)
printPreview.paintRequested.connect(lambda: printPreview.paintRequested.connect(lambda:
printimage(printer, image)) printimage(printer, image))
printPreview.exec() printPreview.exec()
def update_spectrum(chromatogram, spect, ds, ms, fn, chrom, config): def update_spectrum(augCanvas, config):
if fn[0] is not None: if augCanvas.filename:
slims = [spect.get_xlim(), spect.get_ylim()] slims = [augCanvas.spectplot.get_xlim(),
ds.clear() augCanvas.spectplot.get_ylim()]
[ds.append(dict(chrom_dat=i[0], masses=i[1], matrix=i[2])) for i augCanvas.ds.clear()
in load_raw(fn[0], config.value("tmp_location"))] [augCanvas.ds.append(dict(chrom_dat=i[0], masses=i[1], matrix=i[2]))
gt.populate(chromatogram, spect, ds, ms, chrom) for i in load_raw(augCanvas.filename, config.value("tmp_location"))]
spect.set_xlim(slims[0]) gt.populate(augCanvas)
spect.set_ylim(slims[1]) augCanvas.spectplot.set_xlim(slims[0])
gt.ann_spec(spect, ms) augCanvas.spectplot.set_ylim(slims[1])
spect.get_figure().canvas.draw() gt.ann_spec(augCanvas.spectplot, augCanvas.ms)
augCanvas.draw()
def dropped(event, parent, chromatogram, spectrum, ds, ms, filename, def dropped(event, parent, augCanvas, update, config, loadthread):
chrom, update, config, loadthread):
dropurl = event.mimeData().urls()[0].toLocalFile() dropurl = event.mimeData().urls()[0].toLocalFile()
load_file(parent, chromatogram, spectrum, ds, ms, filename, load_file(parent, augCanvas, update, config, loadthread, filename=dropurl)
chrom, update, config, loadthread, filename=dropurl)
def drag_entered(event): def drag_entered(event):
...@@ -192,23 +197,23 @@ def drag_entered(event): ...@@ -192,23 +197,23 @@ def drag_entered(event):
event.accept() event.accept()
def predictmz(form, chromatogram, spect, ds, ms, chrom): def predictmz(form, augCanvas):
text = form.text() text = form.text()
if text == "": if text == "":
ms["predict"] = None augCanvas.ms["predict"] = None
return return
slims = [spect.get_xlim(), spect.get_ylim()] slims = [augCanvas.spectplot.get_xlim(),
ms["predict"] = getmzpattern(text) augCanvas.spectplot.get_ylim()]
gt.populate(chromatogram, spect, ds, ms, chrom) augCanvas.ms["predict"] = getmzpattern(text)
spect.set_xlim(slims[0]) gt.populate(augCanvas)
spect.set_ylim(slims[1]) augCanvas.spectplot.set_xlim(slims[0])
spect.get_figure().canvas.draw() augCanvas.spectplot.set_ylim(slims[1])
augCanvas.draw()
def oddeven_changed(chromatogram, spectrum, ds, ms, filename, chrom, config, def oddeven_changed(augCanvas, config, oddevenact):
oddevenact):
config.setValue("view/oddeven", oddevenact.isChecked()) config.setValue("view/oddeven", oddevenact.isChecked())
update_spectrum(chromatogram, spectrum, ds, ms, filename, chrom, config) update_spectrum(augCanvas, config)
def key_pressed(event, augCanvas, config): def key_pressed(event, augCanvas, config):
...@@ -221,7 +226,7 @@ def key_pressed(event, augCanvas, config): ...@@ -221,7 +226,7 @@ def key_pressed(event, augCanvas, config):
else: else:
imgt.clip_spect_img(augCanvas.ms, augCanvas.spectplot, imgt.clip_spect_img(augCanvas.ms, augCanvas.spectplot,
augCanvas.filename) augCanvas.filename)
if event.modifiers().__int__() == QtCore.Qt.ControlModifier+\ if event.modifiers().__int__() == QtCore.Qt.ControlModifier + \
QtCore.Qt.ShiftModifier: QtCore.Qt.ShiftModifier:
dt.clip_spectstr(augCanvas) dt.clip_spectstr(augCanvas)
if event.key() in (QtCore.Qt.Key_Left, QtCore.Qt.Key_Right): if event.key() in (QtCore.Qt.Key_Left, QtCore.Qt.Key_Right):
...@@ -246,22 +251,22 @@ def main(): ...@@ -246,22 +251,22 @@ def main():
config = cf.settings() config = cf.settings()
barHandler = QStatusBarLogger() barHandler = QStatusBarLogger()
barHandler.trigger.signal.connect(lambda: barHandler.trigger.signal.connect(
barHandler.statusBar.showMessage(barHandler.msg)) lambda: barHandler.statusBar.showMessage(barHandler.msg))
p_logger = logging.getLogger('parseLogger') p_logger = logging.getLogger('parseLogger')
params_logger = logging.getLogger('acqLogLogger') params_logger = logging.getLogger('acqLogLogger')
drl_logger = logging.getLogger('drlLogger') drl_logger = logging.getLogger('drlLogger')
zce_logger = logging.getLogger('zceLogger') zce_logger = logging.getLogger('zceLogger')
#mpl_logger = logging.getLogger('matplotlib') # mpl_logger = logging.getLogger('matplotlib')
#mpl_logger.setLevel("DEBUG") # mpl_logger.setLevel("DEBUG")
logging.basicConfig() logging.basicConfig()
#p_logger.setLevel("WARN") # p_logger.setLevel("WARN")
#p_logger.setLevel("DEBUG") # p_logger.setLevel("DEBUG")
#drl_logger.setLevel("INFO") # drl_logger.setLevel("INFO")
drl_logger.setLevel("DEBUG") drl_logger.setLevel("DEBUG")
zce_logger.setLevel("DEBUG") zce_logger.setLevel("DEBUG")
#params_logger.setLevel("DEBUG") # params_logger.setLevel("DEBUG")
p_logger.addHandler(barHandler) p_logger.addHandler(barHandler)
zce_logger.addHandler(barHandler) zce_logger.addHandler(barHandler)
params_logger.addHandler(barHandler) params_logger.addHandler(barHandler)
...@@ -269,14 +274,14 @@ def main(): ...@@ -269,14 +274,14 @@ def main():
main_window = QtWidgets.QMainWindow(windowTitle="Prasopes") main_window = QtWidgets.QMainWindow(windowTitle="Prasopes")
if QtGui.QIcon.themeName() is "": if QtGui.QIcon.themeName() == "":
QtGui.QIcon.setThemeName("TangoMFK") QtGui.QIcon.setThemeName("TangoMFK")
consoledock = docks.consoleDockWidget( consoledock = docks.consoleDockWidget(
locals(), "&Console", "view/consolevisible") locals(), "&Console", "view/consolevisible")
treedock = docks.treeDockWidget( treedock = docks.treeDockWidget(
"&File browser", "view/filebrowservisible", update, load_file, main_window, "&File browser", "view/filebrowservisible", update, load_file,
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))
...@@ -321,18 +326,19 @@ def main(): ...@@ -321,18 +326,19 @@ def main():
autozoomy.triggered.connect(lambda: config.setValue( autozoomy.triggered.connect(lambda: config.setValue(
"view/autozoomy", autozoomy.isChecked())) "view/autozoomy", autozoomy.isChecked()))
autozoomy.triggered.connect(lambda: gt.autozoomy(augCanvas.spectrum)) autozoomy.triggered.connect(lambda: gt.autozoomy(augCanvas.spectrum))
intensitiesact = QtWidgets.QAction("&Show intensities", None, intensitiesact = QtWidgets.QAction(
checkable=True, checked=config.value("view/intensities", "&Show intensities", None, checkable=True, checked=config.value(
type=bool)) "view/intensities", type=bool))
intensitiesact.triggered.connect(lambda: config.setValue( intensitiesact.triggered.connect(lambda: config.setValue(
"view/intensities", intensitiesact.isChecked())) "view/intensities", intensitiesact.isChecked()))
intensitiesact.triggered.connect(lambda: gt.ann_spec( intensitiesact.triggered.connect(lambda: gt.ann_spec(
augCanvas.spectplot, augCanvas.ms)) augCanvas.spectplot, augCanvas.ms))
intensitiesact.triggered.connect(lambda: augCanvas.draw()) intensitiesact.triggered.connect(lambda: augCanvas.draw())
oddevenact = QtWidgets.QAction("&Odd / even", None, checkable=True, oddevenact = QtWidgets.QAction(
checked=config.value("view/oddeven", type=bool)) "&Odd / even", None, checkable=True, checked=config.value(
oddevenact.triggered.connect(lambda: "view/oddeven", type=bool))
oddeven_changed(augCanvas, config, oddevenact)) oddevenact.triggered.connect(
lambda: oddeven_changed(augCanvas, config, oddevenact))
predictform = QtWidgets.QLineEdit(maximumWidth=150) predictform = QtWidgets.QLineEdit(maximumWidth=150)
predictform.editingFinished.connect(lambda: predictmz( predictform.editingFinished.connect(lambda: predictmz(
...@@ -354,7 +360,8 @@ def main(): ...@@ -354,7 +360,8 @@ def main():
tools_menu.addAction(drlact) tools_menu.addAction(drlact)
tools_menu.addSeparator() tools_menu.addSeparator()
view_menu = QtWidgets.QMenu('&View', main_window) view_menu = QtWidgets.QMenu('&View', main_window)
[view_menu.addAction(i.action) for i in (treedock, paramsdock, consoledock)] [view_menu.addAction(i.action) for i in
(treedock, paramsdock, consoledock)]
[view_menu.addAction(i) for i in (autozoomy, intensitiesact)] [view_menu.addAction(i) for i in (autozoomy, intensitiesact)]
view_menu.addSeparator() view_menu.addSeparator()
view_menu.addAction(oddevenact) view_menu.addAction(oddevenact)
...@@ -384,7 +391,7 @@ def main(): ...@@ -384,7 +391,7 @@ def main():
main_window.dragEnterEvent = lambda event: drag_entered(event) main_window.dragEnterEvent = lambda event: drag_entered(event)
main_window.dropEvent = lambda event: dropped( main_window.dropEvent = lambda event: dropped(
event, main_window, augCanvas, update, config) event, main_window, augCanvas, update, config, loadthread)
main_window.setAcceptDrops(True) main_window.setAcceptDrops(True)
main_window.keyPressEvent = lambda event: key_pressed( main_window.keyPressEvent = lambda event: key_pressed(
event, augCanvas, config) event, augCanvas, config)
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
from PyQt5 import QtCore from PyQt5 import QtCore
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from PyQt5 import QtGui from PyQt5 import QtGui
from PyQt5 import QtPrintSupport
def settings(): def settings():
settings = QtCore.QSettings("Yansoft","Prasopes") settings = QtCore.QSettings("Yansoft", "Prasopes")
defvals = {("view/autozoomy", True), defvals = {("view/autozoomy", True),
("view/filebrowservisible", True), ("view/filebrowservisible", True),
("view/consolevisible", True), ("view/consolevisible", True),
...@@ -21,13 +20,14 @@ def settings(): ...@@ -21,13 +20,14 @@ def settings():
("imggen/yinch", 4), ("imggen/yinch", 4),
("imggen/dpi", 300), ("imggen/dpi", 300),
("imggen/xtics", 5)} ("imggen/xtics", 5)}
[settings.setValue(i[0], i[1]) for i in defvals if settings.value(i[0]) == None] [settings.setValue(i[0], i[1])
for i in defvals if not settings.value(i[0])]
return settings return settings
def pathsearch(text, value, config): def pathsearch(text, value, config):
filename = QtWidgets.QFileDialog.getExistingDirectory() filename = QtWidgets.QFileDialog.getExistingDirectory()
if filename is not '': if filename != '':
text.setText(filename) text.setText(filename)
config.setValue(value, filename) config.setValue(value, filename)
...@@ -67,7 +67,7 @@ def dial(parent): ...@@ -67,7 +67,7 @@ def dial(parent):
"""constructs a dialog window""" """constructs a dialog window"""
dialog = QtWidgets.QDialog( dialog = QtWidgets.QDialog(
parent, windowTitle='Settings') parent, windowTitle='Settings')
dialog.resize(600,-1) dialog.resize(600, -1)
config = settings() config = settings()
......
...@@ -27,7 +27,8 @@ def specttostr(augCanvas, delim=" "): ...@@ -27,7 +27,8 @@ def specttostr(augCanvas, delim=" "):
strdata = [] strdata = []
for i in range(np.max([len(line.get_xdata()) for line in lines])): for i in range(np.max([len(line.get_xdata()) for line in lines])):
pairs = [("{}"+delim+"{}").format(line.get_xdata()[i], line.get_ydata()[i]) if\ pairs = [("{}"+delim+"{}").format(
line.get_xdata()[i], line.get_ydata()[i]) if
i < len(line.get_xdata()) else delim for line in lines] i < len(line.get_xdata()) else delim for line in lines]
strline = delim.join(pairs)+"\n" strline = delim.join(pairs)+"\n"
strdata.append(strline) strdata.append(strline)
...@@ -37,7 +38,7 @@ def specttostr(augCanvas, delim=" "): ...@@ -37,7 +38,7 @@ def specttostr(augCanvas, delim=" "):
def clip_spectstr(augCanvas): def clip_spectstr(augCanvas):
string = specttostr(augCanvas, delim="\t") string = specttostr(augCanvas, delim="\t")
QApplication.clipboard().clear() QtWidgets.QApplication.clipboard().clear()
[QtWidgets.QApplication.clipboard().setText(string, i) for i in range(2)] [QtWidgets.QApplication.clipboard().setText(string, i) for i in range(2)]
...@@ -47,7 +48,7 @@ def clip_tablestr(augCanvas): ...@@ -47,7 +48,7 @@ def clip_tablestr(augCanvas):
for row in range(augCanvas.paramstable.rowCount()) for row in range(augCanvas.paramstable.rowCount())
if augCanvas.paramstable.cellWidget(row, 0).checkState()] if augCanvas.paramstable.cellWidget(row, 0).checkState()]
text = ", ".join(pairs) text = ", ".join(pairs)
QApplication.clipboard().clear() QtWidgets.QApplication.clipboard().clear()
[QtWidgets.QApplication.clipboard().setText(text, i) for i in range(2)] [QtWidgets.QApplication.clipboard().setText(text, i) for i in range(2)]
......
...@@ -5,7 +5,6 @@ from code import InteractiveConsole ...@@ -5,7 +5,6 @@ from code import InteractiveConsole
from io import StringIO from io import StringIO
from os import path from os import path
import contextlib import contextlib
import numpy as np
import prasopes.config as cf import prasopes.config as cf
...@@ -19,11 +18,13 @@ class augDock(QtWidgets.QDockWidget): ...@@ -19,11 +18,13 @@ class augDock(QtWidgets.QDockWidget):
self.action = QtWidgets.QAction( self.action = QtWidgets.QAction(
actionname, None, checkable=True, actionname, None, checkable=True,
checked=config.value(cfval, type=bool)) checked=config.value(cfval, type=bool))
self.action.triggered.connect(lambda: self.show() if\ self.action.triggered.connect(
self.action.isChecked() == True else self.hide()) lambda: self.show() if self.action.isChecked()
else self.hide())
self.closeEvent = lambda event: self.closeOverride(event) self.closeEvent = lambda event: self.closeOverride(event)
if not config.value(cfval, type=bool): if not config.value(cfval, type=bool):
self.hide() self.hide()
def closeOverride(self, event): def closeOverride(self, event):
self.action.setChecked(False) self.action.setChecked(False)
self.hide() self.hide()
...@@ -42,8 +43,9 @@ def consoleDockWidget(localvars, actionname, cfval): ...@@ -42,8 +43,9 @@ def consoleDockWidget(localvars, actionname, cfval):
outtext = stream.getvalue() outtext = stream.getvalue()
if outtext == "": if outtext == "":
with contextlib.redirect_stderr(StringIO()): with contextlib.redirect_stderr(StringIO()):
#If anybody knows better sanitization feel free to let me know # Brief sanitization
console.runcode("""print(eval('{}'.format(str('"""+text+"""'))))""") console.runcode("""print(eval('{}'.format(str('""" +
text + """'))))""")
outtext = stream.getvalue() outtext = stream.getvalue()
if outtext != "": if outtext != "":
outp.append(outtext[:-1])