Commit 4d36df96 authored by Yan's avatar Yan
Browse files

Merge branch 'master' of gitlab.science.ru.nl:jzelenka/prasopes

parents bf7df136 863d9e29
...@@ -215,7 +215,7 @@ def key_pressed(event, augCanvas, config): ...@@ -215,7 +215,7 @@ def key_pressed(event, augCanvas, config):
update_spectrum(augCanvas, config) update_spectrum(augCanvas, config)
if event.key() == QtCore.Qt.Key_C: if event.key() == QtCore.Qt.Key_C:
if event.modifiers().__int__() == QtCore.Qt.ControlModifier: if event.modifiers().__int__() == QtCore.Qt.ControlModifier:
imgt.clip_spect_img(augCanvas) imgt.clip_spect_img(augCanvas.ms, augCanvas.spectplot, fn)
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)
......
...@@ -47,12 +47,13 @@ def pathlineconf(label, value, config): ...@@ -47,12 +47,13 @@ def pathlineconf(label, value, config):
return layout return layout
def posintvarconf(label, value, config): def posvarconf(label, value, config, num="int"):
"""adds generic positive integer config line""" """adds generic positive integer config line"""
textfield = QtWidgets.QLineEdit(str(config.value(value))) textfield = QtWidgets.QLineEdit(str(config.value(value)))
textfield.editingFinished.connect(lambda: config.setValue( textfield.editingFinished.connect(lambda: config.setValue(
value, textfield.text())) value, textfield.text()))
validator = QtGui.QIntValidator() validator = QtGui.QIntValidator() if num == "int"\
else QtGui.QDoubleValidator()
validator.setBottom(0) validator.setBottom(0)
textfield.setValidator(validator) textfield.setValidator(validator)
layout = QtWidgets.QHBoxLayout() layout = QtWidgets.QHBoxLayout()
...@@ -82,25 +83,25 @@ def dial(parent): ...@@ -82,25 +83,25 @@ def dial(parent):
printtab = QtWidgets.QWidget() printtab = QtWidgets.QWidget()
printlayout = QtWidgets.QVBoxLayout(printtab) printlayout = QtWidgets.QVBoxLayout(printtab)
printlayout.addLayout(posintvarconf( printlayout.addLayout(posvarconf(
"Figure width (inch)", "print/xinch", config)) "Figure width (inch)", "print/xinch", config, "nonint"))
printlayout.addLayout(posintvarconf( printlayout.addLayout(posvarconf(
"Figure height (inch)", "print/yinch", config)) "Figure height (inch)", "print/yinch", config, "nonint"))
printlayout.addLayout(posintvarconf( printlayout.addLayout(posvarconf(
"Figure dpi", "print/dpi", config)) "Figure dpi", "print/dpi", config))
printlayout.addLayout(posintvarconf( printlayout.addLayout(posvarconf(
"Figure x axis major ticks count", "print/xtics", config)) "Figure x axis major ticks count", "print/xtics", config))
tabs.addTab(printtab, "Printing") tabs.addTab(printtab, "Printing")
imggentab = QtWidgets.QWidget() imggentab = QtWidgets.QWidget()
imggenlayout = QtWidgets.QVBoxLayout(imggentab) imggenlayout = QtWidgets.QVBoxLayout(imggentab)
imggenlayout.addLayout(posintvarconf( imggenlayout.addLayout(posvarconf(
"Figure width (inch)", "imggen/xinch", config)) "Figure width (inch)", "imggen/xinch", config, "nonint"))
imggenlayout.addLayout(posintvarconf( imggenlayout.addLayout(posvarconf(
"Figure height (inch)", "imggen/yinch", config)) "Figure height (inch)", "imggen/yinch", config, "nonint"))
imggenlayout.addLayout(posintvarconf( imggenlayout.addLayout(posvarconf(
"Figure dpi", "imggen/dpi", config)) "Figure dpi", "imggen/dpi", config))
imggenlayout.addLayout(posintvarconf( imggenlayout.addLayout(posvarconf(
"Figure x axis major ticks count", "imggen/xtics", config)) "Figure x axis major ticks count", "imggen/xtics", config))
tabs.addTab(imggentab, "Image clip/export") tabs.addTab(imggentab, "Image clip/export")
......
...@@ -6,33 +6,39 @@ from PyQt5 import QtCore ...@@ -6,33 +6,39 @@ from PyQt5 import QtCore
from PyQt5 import QtGui from PyQt5 import QtGui
from PyQt5 import QtPrintSupport from PyQt5 import QtPrintSupport
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from pathlib import Path
import copy
import prasopes.graphtools as gt import prasopes.graphtools as gt
import prasopes.config as cf import prasopes.config as cf
def paint_image(mass_spec, spect, painttarget=None): def paint_image(mass_spec, spect, fn=None, painttarget=None):
"""generates QImage from mass spectrum""" """generates QImage from mass spectrum"""
if isinstance(painttarget, type(QtPrintSupport.QPrinter())): configtype = "print/{}" if isinstance(
xinch, yinch, dpi, xtics = [cf.settings().value("print/{}".format(i), painttarget, type(QtPrintSupport.QPrinter())) else "imggen/{}"
type=int) for i in ("xinch", "yinch", "dpi", "xtics")] xinch, yinch = [float(cf.settings().value(configtype.format(i)).replace(",",".")) for i
else: in ("xinch", "yinch")]
xinch, yinch, dpi, xtics = [cf.settings().value("imggen/{}".format(i), dpi, xtics = [int(cf.settings().value(configtype.format(i))) for i
type=int) for i in ("xinch", "yinch", "dpi", "xtics")] in ("dpi", "xtics")]
paintfig = Figure(figsize=(xinch, yinch), dpi=dpi, constrained_layout=True) paintfig = Figure(figsize=(xinch, yinch), dpi=dpi, constrained_layout=True)
canvas = FigureCanvas(paintfig) canvas = FigureCanvas(paintfig)
printplot = paintfig.add_subplot(111) printplot = paintfig.add_subplot(111)
printplot.set_xlim(spect.get_xlim()) printplot.set_xlim(spect.get_xlim())
printplot.set_ylim(spect.get_ylim()) printplot.set_ylim(spect.get_ylim())
data = [line.get_data() for line in spect.lines] data = [line.get_data() for line in spect.lines]
texts = copy.copy(mass_spec)
if len(mass_spec['headers']) != 0: if len(mass_spec['headers']) != 0:
legend = spect.get_legend().get_texts() legend = spect.get_legend().get_texts()
[gt.pop_plot(*line, printplot, mass_spec, i, legend[i].get_text()) [gt.pop_plot(*line, printplot, texts, i, legend[i].get_text())
for i,line in enumerate(data)] for i,line in enumerate(data)]
printplot.legend(loc=2) printplot.legend(loc=2)
else: else:
[gt.pop_plot(*line, printplot, mass_spec, i) [gt.pop_plot(*line, printplot, texts, i)
for i,line in enumerate(data)] for i,line in enumerate(data)]
printplot.locator_params(nbins=xtics, axis='x') printplot.locator_params(nbins=xtics, axis='x')
if fn not in (None, [None]):
printplot.set_title(Path(*Path(fn[0]).resolve().parts[-2:]),
loc="right")
cache_file = BytesIO() cache_file = BytesIO()
paintfig.savefig(cache_file) paintfig.savefig(cache_file)
cache_file.seek(0) cache_file.seek(0)
...@@ -40,7 +46,7 @@ def paint_image(mass_spec, spect, painttarget=None): ...@@ -40,7 +46,7 @@ def paint_image(mass_spec, spect, painttarget=None):
return image return image
def clip_spect_img(mass_spec, spect): def clip_spect_img(mass_spec, spect, fn):
image = paint_image(mass_spec, spect) image = paint_image(mass_spec, spect, fn=fn)
[QtWidgets.QApplication.clipboard().setImage(image, i) for i in range(2)] [QtWidgets.QApplication.clipboard().setImage(image, i) for i in range(2)]
#QtWidgets.QApplication.clipboard().setPixmap(QtGui.QPixmap.fromImage(image)) #QtWidgets.QApplication.clipboard().setPixmap(QtGui.QPixmap.fromImage(image))
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 PyQt5 import QtCore from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from PyQt5 import QtPrintSupport from PyQt5 import QtPrintSupport
from prasopes.zcetools_help import helpstr from prasopes.zcetools_help import helpstr
from io import BytesIO
import numpy as np import numpy as np
import prasopes.graphtools as gt import prasopes.graphtools as gt
import prasopes.filetools as ft import prasopes.filetools as ft
...@@ -98,23 +100,49 @@ def help_msg(pw): ...@@ -98,23 +100,49 @@ def help_msg(pw):
pw, "TSQ zce tool help", "{}".format(helpstr)) pw, "TSQ zce tool help", "{}".format(helpstr))
def print_graph(ds, coff, coffgrad, filename): def paint_zcegraph(ds, coff, coffgrad, filename):
printfig = Figure(figsize=(5, 2), dpi=100) paintfig = Figure(figsize=(5, 2), dpi=300, constrained_layout=True)
printplot = printfig.add_subplot(111) printplot = paintfig.add_subplot(111)
printplot_overlay = printplot.twinx() printplot_overlay = printplot.twinx()
printcanvas = FigureCanvas(printfig) canvas = FigureCanvas(paintfig)
textfield = QtWidgets.QLabel() textfield = QtWidgets.QLabel()
pop_dial(printplot, printplot_overlay, ds, coff, coffgrad, pop_dial(printplot, printplot_overlay, ds, coff, coffgrad,
textfield, filename, None) textfield, filename, None)
widget = QtWidgets.QDialog(None, windowTitle='Print preview') cache_file = BytesIO()
layout = QtWidgets.QVBoxLayout(widget) paintfig.savefig(cache_file)
layout.addWidget(printcanvas) cache_file.seek(0)
widget.resize(600, 400) image = QtGui.QImage.fromData(cache_file.read())
widget.show() return image
dialog = QtPrintSupport.QPrintDialog()
if dialog.exec_() == QtWidgets.QDialog.Accepted:
printcanvas.render(dialog.printer()) def clip_spect_img(ds, coff, coffgrad, filename):
widget.close() image = paint_zcegraph(ds, coff, coffgrad, filename)
QtWidgets.QApplication.clipboard().setImage(image)
QtWidgets.QApplication.clipboard().setPixmap(QtGui.QPixmap.fromImage(image))
def print_graph(ds, coff, coffgrad, filename):
def printimage(printdevice, img):
printer.setResolution(600)
painter = QtGui.QPainter(printdevice)
painter.drawImage(0,0,img)
painter.end()
#TODO: substitute the QPrintPreviewDialog with QPrintPreviewWidget
printPreview = QtPrintSupport.QPrintPreviewDialog()
printer = printPreview.printer()
printer.setPageSize(printer.A5)
printer.setDuplex(printer.DuplexNone)
image = paint_zcegraph(ds, coff, coffgrad, filename)
printPreview.paintRequested.connect(lambda:
printimage(printer, image))
printPreview.exec()
def key_pressed(event, ds, coff, coffgrad, filename):
print("trigged")
if event.key() == QtCore.Qt.Key_C:
if event.modifiers().__int__() == QtCore.Qt.ControlModifier:
clip_spect_img(ds, coff, coffgrad, filename)
def dialog(parent, augCanvas, update_signal): def dialog(parent, augCanvas, update_signal):
...@@ -144,7 +172,6 @@ def dialog(parent, augCanvas, update_signal): ...@@ -144,7 +172,6 @@ def dialog(parent, augCanvas, update_signal):
graph_canvas = FigureCanvas(dial_graph) graph_canvas = FigureCanvas(dial_graph)
graph_canvas.setStyleSheet("background-color:transparent;") graph_canvas.setStyleSheet("background-color:transparent;")
graph_canvas.setAutoFillBackground(False) graph_canvas.setAutoFillBackground(False)
graph_canvas.setFocusPolicy(QtCore.Qt.ClickFocus)
gt.zoom_factory(coffspect_grad, 1.15, coffgrad) gt.zoom_factory(coffspect_grad, 1.15, coffgrad)
gt.pan_factory(coffspect_grad, coffgrad) gt.pan_factory(coffspect_grad, coffgrad)
...@@ -160,6 +187,9 @@ def dialog(parent, augCanvas, update_signal): ...@@ -160,6 +187,9 @@ def dialog(parent, augCanvas, update_signal):
close_button = QtWidgets.QPushButton("Close") close_button = QtWidgets.QPushButton("Close")
close_button.clicked.connect(dial_widget.close) close_button.clicked.connect(dial_widget.close)
dial_widget.keyPressEvent = lambda event: key_pressed(
event, ds, coff, coffgrad, filename)
butt_layout = QtWidgets.QHBoxLayout() butt_layout = QtWidgets.QHBoxLayout()
butt_layout.addWidget(zce_help) butt_layout.addWidget(zce_help)
butt_layout.addStretch(1) butt_layout.addStretch(1)
...@@ -173,6 +203,7 @@ def dialog(parent, augCanvas, update_signal): ...@@ -173,6 +203,7 @@ def dialog(parent, augCanvas, update_signal):
dial_layout = QtWidgets.QVBoxLayout(dial_widget) dial_layout = QtWidgets.QVBoxLayout(dial_widget)
dial_layout.addWidget(graph_canvas) dial_layout.addWidget(graph_canvas)
dial_layout.addLayout(butt_layout) dial_layout.addLayout(butt_layout)
dial_widget.setFocus()
dial_widget.show() dial_widget.show()
pop_dial(coffspect, coffspect_grad, augCanvas.ds, coff, coffgrad, pop_dial(coffspect, coffspect_grad, augCanvas.ds, coff, coffgrad,
textfield, augCanvas.filename, parent) textfield, augCanvas.filename, parent)
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