Skip to content

Commit

Permalink
reg: fix tests (wrong indices in analysis view) and ref: do not use Q…
Browse files Browse the repository at this point in the history
…tWidgets getters and setters
  • Loading branch information
paulmueller committed Jan 6, 2025
1 parent 65ee0fb commit 0bb51b9
Show file tree
Hide file tree
Showing 22 changed files with 174 additions and 135 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- setup: pygments (for json formatting) is now an explicit dependency
- setup: bump dclab to 0.62.9
- ref: simplify logic in Analysis View
- ref: do not override `QtWidgets`' `__setstate__` and `__getstate__`;
use `write_pipeline_state` and `read_pipeline_state` instead
2.20.1
- fix: regression TypeError when trying to plot contour data
2.20.0
Expand Down
3 changes: 2 additions & 1 deletion shapeout2/gui/analysis/ana_basins.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class BasinsPanel(QtWidgets.QWidget):
Visualizes tables stored in the .rtdc file
"""

def __init__(self, *args, **kwargs):
super(BasinsPanel, self).__init__(*args, **kwargs)
ref = importlib.resources.files(
Expand Down Expand Up @@ -75,7 +76,7 @@ def on_select_basin(self, current, previous):
formatters.HtmlFormatter(full=True,
noclasses=True,
nobackground=True))
)
)

if available and bn is not None and not current.childCount():
# Add child tree nodes
Expand Down
18 changes: 9 additions & 9 deletions shapeout2/gui/analysis/ana_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, *args, **kwargs):
self.update_content()
self.setUpdatesEnabled(True)

def __getstate__(self):
def read_pipeline_state(self):
state = {
"filter used": self.checkBox_enable.isChecked(),
"identifier": self.current_filter.identifier,
Expand All @@ -66,7 +66,7 @@ def __getstate__(self):
box = {}
for feat in self.active_box_features:
rc = self._box_range_controls[feat]
box[feat] = rc.__getstate__()
box[feat] = rc.read_pipeline_state()
state["box filters"] = box
# polygon filters
pflist = []
Expand All @@ -76,7 +76,7 @@ def __getstate__(self):
state["polygon filters"] = pflist
return state

def __setstate__(self, state):
def write_pipeline_state(self, state):
if self.current_filter.identifier != state["identifier"]:
raise ValueError("Filter identifier mismatch!")
self.checkBox_enable.setChecked(state["filter used"])
Expand All @@ -90,7 +90,7 @@ def __setstate__(self, state):
rc = self._box_range_controls[feat]
if feat in box:
rc.show()
rc.__setstate__(box[feat])
rc.write_pipeline_state(box[feat])
else:
rc.setActive(False) # uncheck range control (#67)
rc.hide()
Expand Down Expand Up @@ -193,7 +193,7 @@ def get_features_labels(self):

def on_duplicate_filter(self):
# determine the new filter state
filt_state = self.__getstate__()
filt_state = self.read_pipeline_state()
new_state = copy.deepcopy(filt_state)
new_filt = Filter()
new_state["identifier"] = new_filt.identifier
Expand All @@ -206,7 +206,7 @@ def on_duplicate_filter(self):
self.pipeline_changed.emit(state)

def on_remove_filter(self):
filt_state = self.__getstate__()
filt_state = self.read_pipeline_state()
self.pipeline.remove_filter(filt_state["identifier"])
state = self.pipeline.__getstate__()
self.pipeline_changed.emit(state)
Expand Down Expand Up @@ -267,7 +267,7 @@ def update_content(self, event=None, filt_index=None):
# populate content
filt = Filter.get_filter(identifier=self.filter_ids[filt_index])
state = filt.__getstate__()
self.__setstate__(state)
self.write_pipeline_state(state)
self.update_box_ranges()
else:
self.setEnabled(False)
Expand Down Expand Up @@ -324,11 +324,11 @@ def update_polygon_filters(self, update_state=True):
self.verticalLayout_poly.addWidget(button)
# update current filters
if update_state and self.current_filter is not None:
self.__setstate__(self.current_filter.__getstate__())
self.write_pipeline_state(self.current_filter.__getstate__())

def write_filter(self):
"""Update the shapeout2.pipeline.Filter instance"""
# get current index
filter_state = self.__getstate__()
filter_state = self.read_pipeline_state()
self.filter_changed.emit(filter_state)
self.update_content() # update filter selection combobox
1 change: 1 addition & 0 deletions shapeout2/gui/analysis/ana_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class LogPanel(QtWidgets.QWidget):
Visualizes logs stored in the .rtdc file
"""

def __init__(self, *args, **kwargs):
super(LogPanel, self).__init__(*args, **kwargs)
ref = importlib.resources.files(
Expand Down
48 changes: 24 additions & 24 deletions shapeout2/gui/analysis/ana_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ def __init__(self, *args, **kwargs):
# automatically set spacing
self.toolButton_spacing_auto.clicked.connect(self.on_spacing_auto)

def __getstate__(self):
rx = self.widget_range_x.__getstate__()
ry = self.widget_range_y.__getstate__()
def read_pipeline_state(self):
rx = self.widget_range_x.read_pipeline_state()
ry = self.widget_range_y.read_pipeline_state()

# hue min/max
marker_hue = self.comboBox_marker_hue.currentData()
if marker_hue == "kde":
hmin = 0
hmax = 1
elif marker_hue == "feature":
rstate = self.widget_range_feat.__getstate__()
rstate = self.widget_range_feat.read_pipeline_state()
hmin = rstate["start"]
hmax = rstate["end"]
else:
Expand Down Expand Up @@ -132,7 +132,7 @@ def __getstate__(self):
}
return state

def __setstate__(self, state):
def write_pipeline_state(self, state):
if self.current_plot.identifier != state["identifier"]:
raise ValueError("Plot identifier mismatch!")
toblock = [
Expand Down Expand Up @@ -279,10 +279,10 @@ def _set_range_feat_state(self, feat, fmin=None, fmax=None):
fmin = lim[0]
if fmax is None:
fmax = lim[1]
self.widget_range_feat.__setstate__({"active": True,
"start": fmin,
"end": fmax,
})
self.widget_range_feat.write_pipeline_state({"active": True,
"start": fmin,
"end": fmax,
})

def _set_range_xy_state(self, axis_x=None, range_x=None,
axis_y=None, range_y=None):
Expand Down Expand Up @@ -310,10 +310,10 @@ def _set_range_xy_state(self, axis_x=None, range_x=None,
rang = self.pipeline.get_min_max(feat=axis,
plot_id=plot_id,
margin=0.05)
rc.__setstate__({"active": True,
"start": rang[0],
"end": rang[1],
})
rc.write_pipeline_state({"active": True,
"start": rang[0],
"end": rang[1],
})

def _set_contour_spacing(self, spacing_x=None, spacing_y=None):
"""Set the contour spacing in the spin boxes
Expand Down Expand Up @@ -426,7 +426,7 @@ def get_features(self):

@QtCore.pyqtSlot()
def on_axis_changed(self):
gen = self.__getstate__()["general"]
gen = self.read_pipeline_state()["general"]
if self.sender() == self.comboBox_axis_x:
self._set_range_xy_state(axis_x=gen["axis x"])
self._set_contour_spacing_auto(axis_x=gen["axis x"])
Expand Down Expand Up @@ -455,7 +455,7 @@ def on_column_num_changed(self):
old_ncol, old_nrow = self.pipeline.get_plot_col_row_count(plot_id)
# new parameters
new_pipeline_state = self.pipeline.__getstate__()
new_pipeline_state["plots"][plot_index] = self.__getstate__()
new_pipeline_state["plots"][plot_index] = self.read_pipeline_state()
new_ncol, new_nrow = self.pipeline.get_plot_col_row_count(
plot_id, new_pipeline_state)
# size x (minimum of 400)
Expand Down Expand Up @@ -495,12 +495,12 @@ def on_hue_selected(self):
@QtCore.pyqtSlot()
def on_plot_duplicated(self):
# determine the new filter state
plot_state = self.__getstate__()
plot_state = self.read_pipeline_state()
new_state = copy.deepcopy(plot_state)
new_plot = Plot()
new_state["identifier"] = new_plot.identifier
new_state["layout"]["name"] = new_plot.name
new_plot.__setstate__(new_state)
new_plot.write_pipeline_state(new_state)
# determine the filter position
pos = self.pipeline.plot_ids.index(plot_state["identifier"])
self.pipeline.add_plot(new_plot, index=pos+1)
Expand All @@ -509,7 +509,7 @@ def on_plot_duplicated(self):

@QtCore.pyqtSlot()
def on_plot_removed(self):
plot_state = self.__getstate__()
plot_state = self.read_pipeline_state()
self.pipeline.remove_plot(plot_state["identifier"])
state = self.pipeline.__getstate__()
self.pipeline_changed.emit(state)
Expand All @@ -522,15 +522,15 @@ def on_spacing_auto(self):
plot_id = self.current_plot.identifier
# Get all datasets belonging to this plot.
datasets, _ = self.pipeline.get_plot_datasets(plot_id)
state = self.__getstate__()
state = self.read_pipeline_state()
gen = state["general"]
# initial guess
# sensible start parameters
self._set_contour_spacing_auto(axis_x=gen["axis x"],
axis_y=gen["axis y"])

# retrieve state with updated spacings
state = self.__getstate__()
state = self.read_pipeline_state()
phi_conv = np.deg2rad(23)

for ii in range(15): # hard-limit is 15 iterations
Expand Down Expand Up @@ -562,10 +562,10 @@ def on_spacing_auto(self):
"Could not automatically determine contour spacing")

# set the final spacing
new_state = self.__getstate__()
new_state = self.read_pipeline_state()
new_state["contour"]["spacing x"] = state["contour"]["spacing x"]
new_state["contour"]["spacing y"] = state["contour"]["spacing y"]
self.__setstate__(new_state)
self.write_pipeline_state(new_state)

@QtCore.pyqtSlot()
def on_range_changed(self):
Expand Down Expand Up @@ -619,7 +619,7 @@ def update_content(self, event=None, plot_index=None):
# populate content
plot = Plot.get_plot(identifier=self.plot_ids[plot_index])
state = plot.__getstate__()
self.__setstate__(state)
self.write_pipeline_state(state)
else:
self.setEnabled(False)

Expand All @@ -628,7 +628,7 @@ def write_plot(self):
# get current index
plot_index = self.comboBox_plots.currentIndex()
plot = Plot.get_plot(identifier=self.plot_ids[plot_index])
plot_state = self.__getstate__()
plot_state = self.read_pipeline_state()
plot.__setstate__(plot_state)
self.update_content() # update plot selection combobox
self.plot_changed.emit(plot_state)
16 changes: 8 additions & 8 deletions shapeout2/gui/analysis/ana_slot.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, *args, **kwargs):

self.update_content()

def __getstate__(self):
def read_pipeline_state(self):
slot_state = self.current_slot_state
if self.comboBox_temp.currentData() in ["manual", "config"]:
emod_temp = self.doubleSpinBox_temp.value()
Expand Down Expand Up @@ -100,7 +100,7 @@ def __getstate__(self):
}
return state

def __setstate__(self, state):
def write_pipeline_state(self, state):
cur_state = self.current_slot_state
if cur_state["identifier"] != state["identifier"]:
raise ValueError("Slot identifier mismatch!")
Expand Down Expand Up @@ -344,7 +344,7 @@ def get_dataset(self):

@QtCore.pyqtSlot()
def on_anew_slot(self):
slot_state = self.__getstate__()
slot_state = self.read_pipeline_state()
new_slot = Dataslot(slot_state["path"])
pos = self.pipeline.slot_ids.index(slot_state["identifier"])
self.pipeline.add_slot(new_slot, index=pos + 1)
Expand All @@ -354,7 +354,7 @@ def on_anew_slot(self):
@QtCore.pyqtSlot()
def on_duplicate_slot(self):
# determine the new filter state
slot_state = self.__getstate__()
slot_state = self.read_pipeline_state()
new_state = copy.deepcopy(slot_state)
new_slot = Dataslot(slot_state["path"])
new_state["identifier"] = new_slot.identifier
Expand All @@ -368,7 +368,7 @@ def on_duplicate_slot(self):

@QtCore.pyqtSlot()
def on_remove_slot(self):
slot_state = self.__getstate__()
slot_state = self.read_pipeline_state()
self.pipeline.remove_slot(slot_state["identifier"])
state = self.pipeline.__getstate__()
self.pipeline_changed.emit(state)
Expand Down Expand Up @@ -419,7 +419,7 @@ def on_ui_changed(self):
# For user convenience, also show the viscosity
if medium in KNOWN_MEDIA and not np.isnan(temperature):
# compute viscosity
state = self.__getstate__()
state = self.read_pipeline_state()
cfg = meta_tool.get_rtdc_config(state["path"])
with warnings.catch_warnings(record=True) as w:
# Warn the user if the temperature is out-of-range
Expand Down Expand Up @@ -486,15 +486,15 @@ def update_content(self, event=None, slot_index=None):
self.comboBox_slots.blockSignals(False)
# populate content
slot_state = self.pipeline.slots[slot_index].__getstate__()
self.__setstate__(slot_state)
self.write_pipeline_state(slot_state)
self.on_ui_changed()
else:
self.setEnabled(False)

def write_slot(self):
"""Update the shapeout2.pipeline.Dataslot instance"""
# get current index
slot_state = self.__getstate__()
slot_state = self.read_pipeline_state()
slot = self.pipeline.get_slot(slot_state["identifier"])
# This is important, otherwise update_content will not have the
# latest state.
Expand Down
3 changes: 2 additions & 1 deletion shapeout2/gui/analysis/ana_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class TablesPanel(QtWidgets.QWidget):
Visualizes tables stored in the .rtdc file
"""

def __init__(self, *args, **kwargs):
super(TablesPanel, self).__init__(*args, **kwargs)
ref = importlib.resources.files(
Expand Down Expand Up @@ -149,7 +150,7 @@ def show_graph(self, x_vals, graph_list):
x=x_vals["data"],
y=item["data"],
name=item["name"],
)
)

self.legend.addItem(pl, item["name"])
self.graphicsView.plotItem.setLabels(bottom=x_vals["name"])
Expand Down
9 changes: 6 additions & 3 deletions shapeout2/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,8 @@ def on_new_polygon_filter(self):
@widgets.show_wait_cursor
@QtCore.pyqtSlot(str)
def on_modify_filter(self, filt_id):
self.widget_ana_view.tabWidget.setCurrentIndex(2)
self.widget_ana_view.tabWidget.setCurrentWidget(
self.widget_ana_view.tab_filter)
self.widget_ana_view.widget_filter.show_filter(filt_id)
# finally, check the button
self.toolButton_ana_view.setChecked(True)
Expand All @@ -923,7 +924,8 @@ def on_modify_filter(self, filt_id):
@widgets.show_wait_cursor
@QtCore.pyqtSlot(str)
def on_modify_plot(self, plot_id):
self.widget_ana_view.tabWidget.setCurrentIndex(3)
self.widget_ana_view.tabWidget.setCurrentWidget(
self.widget_ana_view.tab_plot)
self.widget_ana_view.widget_plot.show_plot(plot_id)
# finally, check the button
self.toolButton_ana_view.setChecked(True)
Expand All @@ -935,7 +937,8 @@ def on_modify_plot(self, plot_id):
@widgets.show_wait_cursor
@QtCore.pyqtSlot(str)
def on_modify_slot(self, slot_id):
self.widget_ana_view.tabWidget.setCurrentIndex(1)
self.widget_ana_view.tabWidget.setCurrentWidget(
self.widget_ana_view.tab_slot)
self.widget_ana_view.widget_slot.show_slot(slot_id)
# finally, check the button
self.toolButton_ana_view.setChecked(True)
Expand Down
Loading

0 comments on commit 0bb51b9

Please sign in to comment.