Commit 863d9e29 authored by 3Yan's avatar 3Yan
Browse files

ZCE can be now copied to clipboard

parent 53960fe8
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, ds, filename, update_signal):
......@@ -144,7 +172,6 @@ def dialog(parent, ds, filename, 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, ds, filename, 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, ds, filename, 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, ds, coff, coffgrad,
textfield, 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