Skip to content

Commit

Permalink
enh: use QuickView selection to navigate AnalysisView slots and filters
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jan 18, 2025
1 parent 018ed10 commit 2c30dd6
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
2.21.2
- fix: signal race condition when editing filters in AnalysisView (#148)
- fix: signal race condition when editing plots in AnalysisView (#172)
- enh: use QuickView selection to navigate AnalysisView slots and filters
- enh: when batch-loading datasets, allow individual files to fail
- enh: auto-select logs in AnalysisView
- enh: improve table graph selection (remember graph, clear if unavailable)
Expand Down
7 changes: 5 additions & 2 deletions shapeout2/gui/analysis/ana_basins.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def on_select_basin(self, current, previous=None):
def set_pipeline(self, pipeline):
self._pipeline = pipeline

def update_content(self, event=None, filt_index=None):
def update_content(self, slot_index=None, **kwargs):
if self._pipeline and self._pipeline.slots:
self.setEnabled(True)
self.setUpdatesEnabled(False)
Expand All @@ -100,7 +100,10 @@ def update_content(self, event=None, filt_index=None):
for slot in self._pipeline.slots:
self.listWidget_dataset.addItem(slot.name)
self.setUpdatesEnabled(True)
self.listWidget_dataset.setCurrentRow(0)
if slot_index is None or slot_index < 0:
slot_index = max(0, self.listWidget_dataset.currentRow())
slot_index = min(slot_index, self._pipeline.num_slots - 1)
self.listWidget_dataset.setCurrentRow(slot_index)
else:
self.setEnabled(False)
self.listWidget_dataset.clear()
Expand Down
7 changes: 5 additions & 2 deletions shapeout2/gui/analysis/ana_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def on_select_log(self, log_index):
def set_pipeline(self, pipeline):
self._pipeline = pipeline

def update_content(self, event=None, filt_index=None):
def update_content(self, slot_index=None, **kwargs):
if self._pipeline and self._pipeline.slots:
self.setEnabled(True)
self.setUpdatesEnabled(False)
Expand All @@ -111,7 +111,10 @@ def update_content(self, event=None, filt_index=None):
for slot in self._pipeline.slots:
self.listWidget_dataset.addItem(slot.name)
self.setUpdatesEnabled(True)
self.listWidget_dataset.setCurrentRow(0)
if slot_index is None or slot_index < 0:
slot_index = max(0, self.listWidget_dataset.currentRow())
slot_index = min(slot_index, self._pipeline.num_slots - 1)
self.listWidget_dataset.setCurrentRow(slot_index)
else:
self.setEnabled(False)
self.listWidget_dataset.clear()
Expand Down
10 changes: 5 additions & 5 deletions shapeout2/gui/analysis/ana_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ def update_info_box(self, group_box, config, section):
group_box.hide()
self.update()

def update_content(self, event=None, slot_index=None):
def update_content(self, slot_index=None, **kwargs):
if self.slot_ids:
self.setEnabled(True)
# update combobox
self.comboBox_slots.blockSignals(True)
if slot_index is None:
slot_index = self.comboBox_slots.currentIndex()
if slot_index > len(self.slot_ids) - 1 or slot_index < 0:
slot_index = len(self.slot_ids) - 1
if slot_index is None or slot_index < 0:
slot_index = max(0, self.comboBox_slots.currentIndex())
slot_index = min(slot_index, len(self.slot_ids) - 1)

self.comboBox_slots.clear()
self.comboBox_slots.addItems(self.slot_names)
self.comboBox_slots.setCurrentIndex(slot_index)
Expand Down
23 changes: 12 additions & 11 deletions shapeout2/gui/analysis/ana_slot.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,20 @@ def set_pipeline(self, pipeline):
def show_slot(self, slot_id):
self.update_content(slot_index=self.slot_ids.index(slot_id))

def update_content(self, event=None, slot_index=None):
def update_content(self, slot_index=None, **kwargs):
if self.slot_ids:
# remember the previous slot index and make sure it is sane
prev_index = self.comboBox_slots.currentIndex()
if prev_index is None or prev_index < 0:
prev_index = len(self.slot_ids) - 1

self.setEnabled(True)
# update combobox
self.comboBox_slots.blockSignals(True)
if slot_index is None:
slot_index = self.comboBox_slots.currentIndex()
if slot_index > len(self.slot_ids) - 1 or slot_index < 0:
slot_index = len(self.slot_ids) - 1
if slot_index is None or slot_index < 0:
slot_index = prev_index
slot_index = min(slot_index, len(self.slot_ids) - 1)

self.comboBox_slots.clear()
self.comboBox_slots.addItems(self.slot_names)
self.comboBox_slots.setCurrentIndex(slot_index)
Expand All @@ -493,11 +498,7 @@ def update_content(self, event=None, slot_index=None):

def write_slot(self):
"""Update the shapeout2.pipeline.Dataslot instance"""
# get current index
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.
slot.__setstate__(slot_state)
self.update_content() # update slot combobox and visible fl names
# this signal will update the main pipeline which will trigger
# a call to `set_pipeline` and `update_content`.
self.slot_changed.emit(slot_state)
7 changes: 5 additions & 2 deletions shapeout2/gui/analysis/ana_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def show_raw_data(self, graph_list):
np.savetxt(s, data, delimiter="\t", fmt="%.5g", header=text)
self.plainTextEdit_raw.setPlainText(s.getvalue())

def update_content(self, event=None, filt_index=None):
def update_content(self, slot_index=None, **kwargs):
if self._pipeline and self._pipeline.slots:
self.setEnabled(True)
self.setUpdatesEnabled(False)
Expand All @@ -205,7 +205,10 @@ def update_content(self, event=None, filt_index=None):
for slot in self._pipeline.slots:
self.listWidget_dataset.addItem(slot.name)
self.setUpdatesEnabled(True)
self.listWidget_dataset.setCurrentRow(0)
if slot_index is None or slot_index < 0:
slot_index = max(0, self.listWidget_dataset.currentRow())
slot_index = min(slot_index, self._pipeline.num_slots - 1)
self.listWidget_dataset.setCurrentRow(slot_index)
else:
self.setEnabled(False)
self.listWidget_dataset.clear()
Expand Down
18 changes: 17 additions & 1 deletion shapeout2/gui/analysis/ana_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def __init__(self, *args, **kwargs):
with importlib.resources.as_file(ref) as path_ui:
uic.loadUi(path_ui, self)

self._quickview_slot_index = 0
self._quickview_filt_index = 0

self.page_widgets = [
self.widget_basins,
self.widget_meta,
Expand All @@ -39,7 +42,18 @@ def __init__(self, *args, **kwargs):
self.tabWidget.setCurrentIndex(0)
self.tabWidget.currentChanged.connect(self.update_content)

@QtCore.pyqtSlot(int, int)
def on_quickview(self, slot_index, filt_index):
"""Signal from the block matrix"""
self._quickview_filt_index = filt_index
self._quickview_slot_index = slot_index
self.update_content()

def set_pipeline(self, pipeline):
self._quickview_filt_index = min(self._quickview_filt_index,
len(pipeline.filters) - 1)
self._quickview_slot_index = min(self._quickview_slot_index,
len(pipeline.slots) - 1)
for widget in self.page_widgets:
widget.set_pipeline(pipeline)
self.update_content()
Expand All @@ -49,5 +63,7 @@ def update_content(self):
cur_page = self.tabWidget.currentWidget()
for widget in self.page_widgets:
if widget.parent() is cur_page:
widget.update_content()
widget.update_content(
slot_index=self._quickview_slot_index,
filt_index=self._quickview_filt_index)
break
10 changes: 8 additions & 2 deletions shapeout2/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ def init_analysis_view(self):
self.subwindows["analysis_view"] = sub
# signals
self.toolButton_ana_view.clicked.connect(sub.setVisible)
self.block_matrix.quickviewed.connect(
self.widget_ana_view.on_quickview)
# applying a new filter triggers updating QuickView
self.widget_ana_view.widget_filter.pushButton_apply.clicked.connect(
self.on_quickview_refresh)
Expand Down Expand Up @@ -992,8 +994,10 @@ def on_quickview_refresh(self):

@widgets.show_wait_cursor
@QtCore.pyqtSlot(int, int)
def on_quickview_show_dataset(self, slot_index, filt_index,
update_ana_filter=True):
def on_quickview_show_dataset(self,
slot_index: int,
filt_index: int,
update_ana_filter: bool = True):
"""Update QuickView dataset (User selected new dataset)
Parameters
Expand All @@ -1008,6 +1012,8 @@ def on_quickview_show_dataset(self, slot_index, filt_index,
the one where QuickView is currently set active. If
False, nothing is changed.
"""
if slot_index < 0 or filt_index < 0:
return
ds = self.pipeline.get_dataset(slot_index=slot_index,
filt_index=filt_index,
apply_filter=True)
Expand Down
8 changes: 6 additions & 2 deletions shapeout2/gui/matrix/data_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,12 @@ def changed_element(self):

def changed_quickview(self):
slot_index_qv, filt_index_qv = self.get_quickview_indices()
if slot_index_qv is not None and filt_index_qv is not None:
self.quickviewed.emit(slot_index_qv, filt_index_qv)
# events must be integer, use -1 to indicate None
if slot_index_qv is None:
slot_index_qv = -1
if filt_index_qv is None:
filt_index_qv = -1
self.quickviewed.emit(slot_index_qv, filt_index_qv)

def enable_quickview(self, b=True):
if b:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_gui_emodulus.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def test_switch_and_update_chip_region(qtbot):
em1 = mw.block_matrix.get_widget(slot_id=slot_id1)
em2 = mw.block_matrix.get_widget(slot_id=slot_id2)
qtbot.mouseClick(em1.toolButton_modify, QtCore.Qt.MouseButton.LeftButton)
QtWidgets.QApplication.processEvents(
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 300)
assert wsl.comboBox_slots.currentIndex() == 0
# set temperature manually
idm = wsl.comboBox_temp.findData("manual")
wsl.comboBox_temp.setCurrentIndex(idm)
Expand All @@ -207,6 +210,7 @@ def test_switch_and_update_chip_region(qtbot):

# switch to the second (reservoir) measurement
qtbot.mouseClick(em2.toolButton_modify, QtCore.Qt.MouseButton.LeftButton)
assert wsl.comboBox_slots.currentIndex() == 1
assert not wsl.groupBox_emod.isVisible()
# now switch back
qtbot.mouseClick(em1.toolButton_modify, QtCore.Qt.MouseButton.LeftButton)
Expand Down

0 comments on commit 2c30dd6

Please sign in to comment.