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