Commit 924443d3 authored by 3Yan's avatar 3Yan

Reactivitytools remembers settings, legend fixed

* settings saved by the parameter index
* Fixed legend markers transparency
parent 1e5c45bf
......@@ -13,7 +13,7 @@ from . import zcetools_help
from . import reactivitytools
__version__ = "0.0.27"
__version__ = "0.0.28"
__all__ = ['config', 'datatools', 'docks', 'drltools', 'drltoos_gui', 'filetools',
......
......@@ -22,11 +22,6 @@ def settings():
("imggen/xtics", 5),
("imggen/onlymanann", False),
("reactivity/index", 0),
("reactivity/coef1", 0),
("reactivity/coef2", 0),
("reactivity/transparency", 200),
("reactivity/markersize", 10),
("reactivity/labelloc", 2),
("recents", "")}
[settings.setValue(*i)
for i in defvals if not settings.contains(i[0])]
......
......@@ -21,6 +21,46 @@ matplotlib.use("Qt5Agg")
logger = logging.getLogger('reactivityLogger')
class reactivityParam(QtWidgets.QHBoxLayout):
def __init__(self, parselect, type, valname, vallabel, min=None, max=None, decimals=4):
super().__init__()
self.valname = valname
self.addWidget(QtWidgets.QLabel(vallabel, alignment=130))
if type in (int, float):
if type == float:
self.dial = QtWidgets.QDoubleSpinBox(
decimals=decimals, minimum=float(min or "-inf"),
maximum=float(max or "inf"))
elif type == int:
self.dial = QtWidgets.QSpinBox(
minimum=(min or 0), maximum=(max or 255))
self.dial.setValue(cf.settings().value(
"reactivity/{}_par{}".format(
self.valname, parselect.currentIndex()), type=type))
self.dial.valueChanged.connect(lambda x, y=parselect:
cf.settings().setValue("reactivity/{}_par{}".format(
self.valname, y.currentIndex()), x))
parselect.currentIndexChanged.connect(lambda x:
self.dial.setValue(cf.settings().value(
"reactivity/{}_par{}".format(
self.valname, x), type=type)))
elif type == str:
self.dial = QtWidgets.QLineEdit()
self.dial.setText(cf.settings().value(
"reactivity/{}_par{}".format(
self.valname, parselect.currentIndex()), type=type))
self.dial.textChanged.connect(lambda x, y=parselect:
cf.settings().setValue("reactivity/{}_par{}".format(
self.valname, y.currentIndex()), x))
parselect.currentIndexChanged.connect(lambda x:
self.dial.setText(cf.settings().value(
"reactivity/{}_par{}".format(self.valname, x), type=type)))
else:
raise ValueError("excepted 'float', 'str', 'int' as type")
self.addWidget(self.dial, stretch=1)
def key_pressed(event, augCanvas, drls, grph, labels, parselect):
if event.key() == QtCore.Qt.Key_C:
if event.modifiers().__int__() == QtCore.Qt.ControlModifier:
......@@ -83,10 +123,10 @@ def pop_dial(augCanvas, drls, graph, labels, parselect):
# Do not do anything when data set is not populated
if len(augCanvas.ds) == 0:
return
coef1 = cf.settings().value("reactivity/coef1", type=float)
coef2 = cf.settings().value("reactivity/coef2", type=float)
parint = parselect.currentIndex()
coef1 = cf.settings().value("reactivity/coef1_par{}".format(parint), type=float)
coef2 = cf.settings().value("reactivity/coef2_par{}".format(parint), type=float)
markersize = cf.settings().value("reactivity/markersize", type=float)
update_parselect(augCanvas, parselect)
graph.clear()
gt.pop_plot([0], [0], graph, labels)
names, times, intensities = drl.get_daughterset(augCanvas.ds, drls)
......@@ -119,7 +159,7 @@ def pop_dial(augCanvas, drls, graph, labels, parselect):
return
nptpressures = np.asarray(pressures).T[0]
goodtimes = np.where([t in nptpressures for t in times])
alpha = cf.settings().value("reactivity/transparency", type=int)
alpha = cf.settings().value("reactivity/transparency_par{}".format(parint), type=int)
transcolors = [np.append(i, alpha) for i in gt.colors]
for i in range(1,len(intensities)):
label = drls['pt'].item(colorargs[i], 0).text()
......@@ -130,7 +170,9 @@ def pop_dial(augCanvas, drls, graph, labels, parselect):
label=label, color=(transcolors[
colorargs[i] % len(transcolors)] / 255), marker=".",
markersize=markersize, linestyle="None")
graph.legend(loc=cf.settings().value("reactivity/labelloc", type=float))
legend = graph.legend(
loc=cf.settings().value("reactivity/labelloc", type=float))
[lh._legmarker.set_alpha(1) for lh in legend.legendHandles]
graph.autoscale(True)
graph.figure.canvas.draw()
......@@ -164,59 +206,29 @@ def main_window(parent, augCanvas, update_signal, drls):
parlabel = QtWidgets.QLabel("Parameter: ")
parselect = QtWidgets.QComboBox()
parint = parselect.currentIndex()
update_parselect(augCanvas, parselect)
parselect.currentIndexChanged.connect(lambda x:
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)")
xannlayout = reactivityParam(parselect, str, "xlabel", "x axis label:")
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.dial.textChanged.connect(changevalue)
xannlayout.addStretch()
translayout = QtWidgets.QHBoxLayout()
translabel = QtWidgets.QLabel("Transparency (0-255): ")
transbox = QtWidgets.QSpinBox(minimum=0, maximum=255)
transbox.setValue(cf.settings().value(
"reactivity/transparency", type=int))
transbox.valueChanged.connect(lambda x:
cf.settings().setValue("reactivity/transparency", x))
[translayout.addWidget(i) for i in [translabel, transbox]]
translayout = reactivityParam(
parselect, int, "transparency", "Transparency (0-255): ", 0, 255)
translayout.addStretch()
labelloclayout = QtWidgets.QHBoxLayout()
labelloclabel = QtWidgets.QLabel("Label location (0-10): ")
labellocbox = QtWidgets.QSpinBox(minimum=0, maximum=10)
labellocbox.setValue(cf.settings().value(
"reactivity/labelloc", type=int))
labellocbox.valueChanged.connect(lambda x:
cf.settings().setValue("reactivity/labelloc", x))
[labelloclayout.addWidget(i) for i in [labelloclabel, labellocbox]]
labelloclayout.addStretch()
labelloclayout = reactivityParam(
parselect, int, "labelloc", "Label location (0-10): ", 0, 10)
layouts = [xannlayout, translayout, labelloclayout]
valnames = ["markersize", "coef1", "coef2"]
valtexts = ["dot size: ", "a: ", "b: "]
coefs = []
for i in range(len(valnames)):
newlayout = QtWidgets.QHBoxLayout()
label = QtWidgets.QLabel(valtexts[i], alignment=130)
coef = QtWidgets.QDoubleSpinBox(
decimals=4, minimum=float("-inf"), maximum=float("inf"))
coef.setValue(cf.settings().value(
"reactivity/{}".format(valnames[i]), type=float))
coefs.append(coef)
newlayout.addWidget(label)
newlayout.addWidget(coef, stretch=1)
layouts.append(newlayout)
list(map(lambda i: coefs[i].valueChanged.connect(lambda x:
cf.settings().setValue("reactivity/{}".format(valnames[i]), x)),
range(len(valnames))))
layouts.append(reactivityParam(
parselect, float, "markersize", "dot size: ", 0))
layouts.append(reactivityParam(parselect, float, "coef_a", "a: "))
layouts.append(reactivityParam(parselect, float, "coef_b", "b: "))
pushbtn = QtWidgets.QPushButton("Recalculate")
pushbtn.clicked.connect(lambda: pop_dial(
......
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