Commit f58e84a4 authored by 3Yan's avatar 3Yan

Exception handling improved, reactivity tools copying

* ctrl+c copies the reactivity Figure
* minor reactivitytools improvement
* exception handling ignores figure collapse
parent 8fa44a8b
......@@ -13,7 +13,7 @@ from . import zcetools_help
from . import reactivitytools
__version__ = "0.0.22"
__version__ = "0.0.23"
__all__ = ['config', 'datatools', 'docks', 'drltools', 'drltoos_gui', 'filetools',
......
......@@ -45,6 +45,8 @@ class QStatusBarLogger(logging.Handler):
def show_exception_and_exit(exc_type, exc_value, tb):
if "figure size must be positive finite not" in str(exc_value):
return
import traceback
traceback.print_exception(exc_type, exc_value, tb)
errmsg = "\n".join(traceback.format_exception(exc_type, exc_value, tb))
......
......@@ -6,6 +6,7 @@ from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtPrintSupport
from io import BytesIO
import matplotlib
import numpy as np
import prasopes.datatools as dt
......@@ -20,6 +21,13 @@ matplotlib.use("Qt5Agg")
logger = logging.getLogger('reactivityLogger')
def key_pressed(event, augCanvas, drls, grph, labels, parselect, coef1, coef2):
print("trigged")
if event.key() == QtCore.Qt.Key_C:
if event.modifiers().__int__() == QtCore.Qt.ControlModifier:
clip_spect_img(augCanvas, drls, grph, labels, parselect, coef1, coef2)
def update_parselect(augCanvas, parselect):
index = parselect.currentIndex()
if index == -1:
......@@ -31,6 +39,29 @@ def update_parselect(augCanvas, parselect):
if index <= len(parlist):
parselect.setCurrentIndex(index)
def paint_image(augCanvas, drls, grph, labels, parselect, coef1, coef2):
paintfig = Figure(figsize=(3.5,2), dpi=300, constrained_layout=True)
FigureCanvas(paintfig)
printplot = paintfig.add_subplot(111)
pop_dial(augCanvas, drls, printplot, labels, parselect, coef1, coef2)
printplot.set_xlim(grph.get_xlim())
printplot.set_ylim(grph.get_ylim())
paintfig.canvas.draw()
cache_file = BytesIO()
paintfig.savefig(cache_file)
cache_file.seek(0)
image = QtGui.QImage.fromData(cache_file.read())
return image
def clip_spect_img(augCanvas, drls, grph, labels, parselect, coef1, coef2):
image=paint_image(augCanvas, drls, grph, labels, parselect, coef1, coef2)
QtWidgets.QApplication.clipboard().clear()
[QtWidgets.QApplication.clipboard().setImage(image, i) for i in range(2)]
def pop_dial(augCanvas, drls, graph, labels, parselect, coef1, coef2):
logger.debug("populating reactivity dialog")
# Do not do anything when data set is not populated
......@@ -76,7 +107,7 @@ def pop_dial(augCanvas, drls, graph, labels, parselect, coef1, coef2):
graph.plot(np.asarray(pressures).T[1], relint[goodtimes],
label=names[i], color=(gt.colors[
colorargs[i] % len(gt.colors)] / 255), marker=".",
markersize=2, linestyle="None")
markersize=1, linestyle="None")
graph.autoscale(True)
graph.figure.canvas.draw()
......@@ -98,7 +129,8 @@ def main_window(parent, augCanvas, update_signal, drls):
dial_widget.closeEvent = lambda event: onclose(
dial_widget, event, update_fnc)
update_signal.signal.connect(update_fnc)
dial_graph = Figure(figsize=(5, 2), dpi=100, facecolor="None")
dial_graph = Figure(figsize=(5, 2), dpi=100, facecolor="None",
constrained_layout=True)
dialspect = dial_graph.add_subplot(111, facecolor=(1, 1, 1, 0.8))
graph_canvas = FigureCanvas(dial_graph)
graph_canvas.setStyleSheet("background-color:transparent;")
......@@ -113,6 +145,16 @@ def main_window(parent, augCanvas, update_signal, drls):
cf.settings().setValue("reactivity/index", x))
formula = QtWidgets.QLabel(
"Formula for the x-axis: (Parameter - a) * b")
xlabelabel = QtWidgets.QLabel("x axis label:")
xlabeldial = QtWidgets.QLineEdit("pressure (mT)")
def changevalue(x):
reactlabels['xlabel'] = x
dialspect.set_xlabel(x)
graph_canvas.draw()
xlabeldial.textChanged.connect(changevalue)
xannlayout = QtWidgets.QHBoxLayout()
[xannlayout.addWidget(i) for i in [xlabelabel, xlabeldial]]
xannlayout.addStretch()
label1 = QtWidgets.QLabel("a: ", alignment=130)
coef1 = QtWidgets.QDoubleSpinBox(
decimals=4, minimum=float("-inf"), maximum=float("inf"))
......@@ -137,8 +179,13 @@ def main_window(parent, augCanvas, update_signal, drls):
for i in [label1, coef1, label2, coef2]:
coef_layout.addWidget(i)
dial_widget.keyPressEvent = lambda event: key_pressed(
event, augCanvas, drls, dialspect, reactlabels, parselect, coef1, coef2)
dial_layout = QtWidgets.QVBoxLayout(dial_widget)
dial_layout.addWidget(graph_canvas)
dial_layout.addWidget(graph_canvas, stretch=1)
dial_layout.addLayout(xannlayout)
dial_layout.addLayout(param_layout)
dial_layout.addWidget(formula)
dial_layout.addLayout(coef_layout)
......
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