set integration limits via keyboard; closes #50
This commit is contained in:
parent
76cd4acfb0
commit
3321d85203
@ -1,8 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Form implementation generated from reading ui file '/autohome/dominik/nmreval/src/resources/_ui/integral_widget.ui'
|
# Form implementation generated from reading ui file 'src/resources/_ui/integral_widget.ui'
|
||||||
#
|
#
|
||||||
# Created by: PyQt5 UI code generator 5.15.4
|
# Created by: PyQt5 UI code generator 5.15.9
|
||||||
#
|
#
|
||||||
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
|
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
|
||||||
# run again. Do not edit this file unless you know what you are doing.
|
# run again. Do not edit this file unless you know what you are doing.
|
||||||
@ -26,7 +26,6 @@ class Ui_Form(object):
|
|||||||
self.set_combobox.setObjectName("set_combobox")
|
self.set_combobox.setObjectName("set_combobox")
|
||||||
self.verticalLayout.addWidget(self.set_combobox)
|
self.verticalLayout.addWidget(self.set_combobox)
|
||||||
self.treeWidget = QtWidgets.QTreeWidget(Form)
|
self.treeWidget = QtWidgets.QTreeWidget(Form)
|
||||||
self.treeWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
|
|
||||||
self.treeWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
|
self.treeWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
|
||||||
self.treeWidget.setHeaderHidden(True)
|
self.treeWidget.setHeaderHidden(True)
|
||||||
self.treeWidget.setObjectName("treeWidget")
|
self.treeWidget.setObjectName("treeWidget")
|
||||||
|
@ -42,6 +42,8 @@ class IntegralWidget(QtWidgets.QWidget, Ui_Form):
|
|||||||
self.max_y = inf
|
self.max_y = inf
|
||||||
self.min_y = -inf
|
self.min_y = -inf
|
||||||
|
|
||||||
|
self.treeWidget.itemChanged.connect(self._update_by_tree)
|
||||||
|
|
||||||
def __call__(self, graph_name, items):
|
def __call__(self, graph_name, items):
|
||||||
self.label_2.setText(f'Connected to {graph_name}\nChanging tab will remove all integration limits.')
|
self.label_2.setText(f'Connected to {graph_name}\nChanging tab will remove all integration limits.')
|
||||||
|
|
||||||
@ -77,7 +79,6 @@ class IntegralWidget(QtWidgets.QWidget, Ui_Form):
|
|||||||
for idx, rnge in enumerate(self.ranges):
|
for idx, rnge in enumerate(self.ranges):
|
||||||
self._update_values(idx, rnge)
|
self._update_values(idx, rnge)
|
||||||
|
|
||||||
|
|
||||||
def add(self, pos):
|
def add(self, pos):
|
||||||
x = pos[0]
|
x = pos[0]
|
||||||
self.ranges.append((x, x*1.1))
|
self.ranges.append((x, x*1.1))
|
||||||
@ -108,7 +109,10 @@ class IntegralWidget(QtWidgets.QWidget, Ui_Form):
|
|||||||
item_list = []
|
item_list = []
|
||||||
for text, val in [('Start', pts_i[0]), ('Stop', pts_i[1]), ('Areas', 0), ('Ratio', 1.)]:
|
for text, val in [('Start', pts_i[0]), ('Stop', pts_i[1]), ('Areas', 0), ('Ratio', 1.)]:
|
||||||
child = QtWidgets.QTreeWidgetItem()
|
child = QtWidgets.QTreeWidgetItem()
|
||||||
child.setFlags(QtCore.Qt.NoItemFlags)
|
if text.startswith('S'):
|
||||||
|
child.setFlags(child.flags() | QtCore.Qt.ItemIsEditable)
|
||||||
|
else:
|
||||||
|
child.setFlags(QtCore.Qt.NoItemFlags)
|
||||||
child.setText(0, f'{text}: {val:.5g}')
|
child.setText(0, f'{text}: {val:.5g}')
|
||||||
child.setForeground(0, QtGui.QBrush(QtGui.QColor('black')))
|
child.setForeground(0, QtGui.QBrush(QtGui.QColor('black')))
|
||||||
|
|
||||||
@ -121,8 +125,27 @@ class IntegralWidget(QtWidgets.QWidget, Ui_Form):
|
|||||||
|
|
||||||
self._update_values(len(self.ranges) - 1, pts_i)
|
self._update_values(len(self.ranges) - 1, pts_i)
|
||||||
|
|
||||||
|
def _update_by_tree(self, item: QtWidgets.QTreeWidgetItem) -> None:
|
||||||
|
parent_item = item.parent()
|
||||||
|
idx = self.treeWidget.invisibleRootItem().indexOfChild(parent_item)
|
||||||
|
|
||||||
|
is_left_border = parent_item.indexOfChild(item) == 0
|
||||||
|
current_region = self.lines[idx][0]
|
||||||
|
current_limits = current_region.getRegion()
|
||||||
|
|
||||||
|
new_value = item.text(0)
|
||||||
|
try:
|
||||||
|
new_value = float(new_value)
|
||||||
|
if is_left_border:
|
||||||
|
current_region.setRegion((new_value, current_limits[1]))
|
||||||
|
else:
|
||||||
|
current_region.setRegion((current_limits[0], new_value))
|
||||||
|
except ValueError:
|
||||||
|
self._update_values(idx, current_limits)
|
||||||
|
|
||||||
def _update_integral(self):
|
def _update_integral(self):
|
||||||
idx = None
|
idx = None
|
||||||
|
reg = None
|
||||||
sender = self.sender()
|
sender = self.sender()
|
||||||
for i, (reg, _) in enumerate(self.lines):
|
for i, (reg, _) in enumerate(self.lines):
|
||||||
if sender == reg:
|
if sender == reg:
|
||||||
@ -132,19 +155,20 @@ class IntegralWidget(QtWidgets.QWidget, Ui_Form):
|
|||||||
if idx is None:
|
if idx is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._update_values(idx, sender.getRegion())
|
self._update_values(idx, reg.getRegion())
|
||||||
|
|
||||||
def _update_values(self, idx, new_range):
|
def _update_values(self, idx, new_range):
|
||||||
self.ranges[idx] = new_range
|
self.ranges[idx] = new_range
|
||||||
|
|
||||||
area = self.make_integral(idx, *new_range)
|
area = self.make_integral(idx, *new_range)
|
||||||
|
|
||||||
|
self.treeWidget.blockSignals(True)
|
||||||
|
|
||||||
item = self.treeWidget.topLevelItem(idx)
|
item = self.treeWidget.topLevelItem(idx)
|
||||||
item.child(0).setText(0, f'Start: {new_range[0]:.5g}')
|
item.child(0).setText(0, f'Start: {new_range[0]:.5g}')
|
||||||
item.child(1).setText(0, f'Stop: {new_range[1]:.5g}')
|
item.child(1).setText(0, f'Stop: {new_range[1]:.5g}')
|
||||||
|
|
||||||
if area is not None:
|
if area is not None:
|
||||||
self.areas[idx] = area
|
|
||||||
item.child(2).setText(0, f'Area: {area:.5g}')
|
item.child(2).setText(0, f'Area: {area:.5g}')
|
||||||
if self.max_area > 0:
|
if self.max_area > 0:
|
||||||
self._set_ratios(idx, self.max_area)
|
self._set_ratios(idx, self.max_area)
|
||||||
@ -157,9 +181,12 @@ class IntegralWidget(QtWidgets.QWidget, Ui_Form):
|
|||||||
self._set_ratios(i, curr_max)
|
self._set_ratios(i, curr_max)
|
||||||
self.max_area = curr_max
|
self.max_area = curr_max
|
||||||
|
|
||||||
|
self.treeWidget.blockSignals(False)
|
||||||
|
|
||||||
def _set_ratios(self, idx, max_value):
|
def _set_ratios(self, idx, max_value):
|
||||||
item = self.treeWidget.invisibleRootItem().child(idx)
|
item = self.treeWidget.invisibleRootItem().child(idx)
|
||||||
area_i = self.areas[idx]
|
area_i = self.areas[idx]
|
||||||
|
|
||||||
item.child(3).setText(0, f'Ratio: {area_i / max_value:.3g}')
|
item.child(3).setText(0, f'Ratio: {area_i / max_value:.3g}')
|
||||||
|
|
||||||
integral_line = self.lines[idx][1]
|
integral_line = self.lines[idx][1]
|
||||||
@ -176,7 +203,9 @@ class IntegralWidget(QtWidgets.QWidget, Ui_Form):
|
|||||||
if integral.size != 0:
|
if integral.size != 0:
|
||||||
area = integral[-1, 1]
|
area = integral[-1, 1]
|
||||||
scale = (self.max_y-self.min_y) / area
|
scale = (self.max_y-self.min_y) / area
|
||||||
self.lines[idx][1].setData(x=integral[:, 0], y=integral[:, 1]*scale + self.min_y)
|
self.lines[idx][1].setData(x=integral[:, 0], y=integral[:, 1]*scale + self.min_y)
|
||||||
|
|
||||||
|
self.areas[idx] = area
|
||||||
|
|
||||||
return area
|
return area
|
||||||
|
|
||||||
|
@ -41,9 +41,6 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeWidget" name="treeWidget">
|
<widget class="QTreeWidget" name="treeWidget">
|
||||||
<property name="editTriggers">
|
|
||||||
<set>QAbstractItemView::NoEditTriggers</set>
|
|
||||||
</property>
|
|
||||||
<property name="selectionBehavior">
|
<property name="selectionBehavior">
|
||||||
<enum>QAbstractItemView::SelectRows</enum>
|
<enum>QAbstractItemView::SelectRows</enum>
|
||||||
</property>
|
</property>
|
||||||
|
Loading…
Reference in New Issue
Block a user