Skip to content

Commit

Permalink
ref: introduce FeatureComboBox class for listing features
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Apr 2, 2024
1 parent 2af1f71 commit f2efd8f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
2.15.5
- fix: right-click menu not working for plot widgets (#160)
- ref: introduce `FeatureComboBox` class for listing features
2.15.4
- fix: very small numbers not parsed when showing metadata (#158)
- fix: do not allow question mark "?" in exported file names (#156)
Expand Down
31 changes: 10 additions & 21 deletions shapeout2/gui/quick_view/qv_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def __setstate__(self, state):
idx = cb.findData(plot[key])
idx = idx if idx > 0 else 0
cb.setCurrentIndex(idx)

# isoelastics
self.checkBox_isoelastics.setChecked(plot["isoelastics"])
for tb in self.signal_widgets:
Expand Down Expand Up @@ -255,6 +256,11 @@ def rtdc_ds(self, rtdc_ds):
contains_bg_feat = "image_bg" in rtdc_ds
self.checkBox_image_background.setVisible(contains_bg_feat)

# set the dataset for the FeatureComboBoxes
self.comboBox_x.set_dataset(rtdc_ds, default_choice="area_um")
self.comboBox_y.set_dataset(rtdc_ds, default_choice="deform")
self.comboBox_z_hue.set_dataset(rtdc_ds)

def get_event_image(self, ds, event):
state = self.__getstate__()
imkw = self.imkw.copy()
Expand Down Expand Up @@ -741,11 +747,7 @@ def show_rtdc(self, rtdc_ds, slot):
state.pop("event")

self.slot = slot
# default features (plot axes)
if plot["axis x"] is None:
plot["axis x"] = "area_um"
if plot["axis y"] is None:
plot["axis y"] = "deform"

# check whether axes exist in ds and change them to defaults
# if necessary
ds_features = self.rtdc_ds.features_scalar
Expand Down Expand Up @@ -795,22 +797,9 @@ def update_feature_choices(self):
"""
if self.rtdc_ds is not None:
# axes combobox choices
ds_feats = self.rtdc_ds.features_scalar
ds_labels = [dclab.dfn.get_feature_label(f) for f in ds_feats]
ds_fl = sorted(zip(ds_labels, ds_feats))
for cb in [self.comboBox_x, self.comboBox_y, self.comboBox_z_hue]:
fcur = cb.currentData()
blocked = cb.signalsBlocked() # remember block state
cb.blockSignals(True)
# set features
cb.clear()
for label, feat in ds_fl:
if feat in ds_feats:
cb.addItem(label, feat)
idcur = cb.findData(fcur)
if idcur >= 0:
cb.setCurrentIndex(idcur)
cb.blockSignals(blocked)
self.comboBox_x.update_feature_list(default_choice="area_um")
self.comboBox_y.update_feature_list(default_choice="deform")
self.comboBox_z_hue.update_feature_list()

def update_polygon_panel(self):
"""Update polygon filter combobox etc."""
Expand Down
11 changes: 8 additions & 3 deletions shapeout2/gui/quick_view/qv_main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_x"/>
<widget class="FeatureComboBox" name="comboBox_x"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
Expand All @@ -244,7 +244,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBox_y"/>
<widget class="FeatureComboBox" name="comboBox_y"/>
</item>
<item row="1" column="2">
<widget class="QWidget" name="widget_yrange" native="true">
Expand Down Expand Up @@ -426,7 +426,7 @@
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="comboBox_z_hue"/>
<widget class="FeatureComboBox" name="comboBox_z_hue"/>
</item>
</layout>
</widget>
Expand Down Expand Up @@ -1093,6 +1093,11 @@
<extends>QTableWidget</extends>
<header>shapeout2.gui.widgets</header>
</customwidget>
<customwidget>
<class>FeatureComboBox</class>
<extends>QComboBox</extends>
<header>shapeout2.gui.widgets</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
Expand Down
1 change: 1 addition & 0 deletions shapeout2/gui/widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# flake8: noqa: F401
from .bg_thread import run_async
from .double_spin_box_nan import DoubleSpinBoxNan
from .feature_combobox import FeatureComboBox
from .key_value_table_widget import KeyValueTableWidget
from .mdi_subwindow_wo_close import MDISubWindowWOButtons
from .qrangeslider import QRangeSlider
Expand Down
44 changes: 44 additions & 0 deletions shapeout2/gui/widgets/feature_combobox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import dclab
from PyQt5 import QtCore, QtWidgets


class FeatureComboBox(QtWidgets.QComboBox):
def __init__(self, *args, **kwargs):
"""A DC data aware combobox for displaying DC features
The combobox uses different colors do indicate the
availability of features. Features can be ancillary,
innate, basin-based, etc.
"""
super(FeatureComboBox, self).__init__(*args, **kwargs)
self.rtdc_ds = None

def set_dataset(self, rtdc_ds, default_choice=None):
self.rtdc_ds = rtdc_ds
self.update_feature_list(default_choice=default_choice)

@QtCore.pyqtSlot()
def update_feature_list(self, default_choice=None):
"""Update the colors of all features in the combobox"""
if self.rtdc_ds is None:
raise ValueError("Please call `set_dataset` first!")
# axes combobox choices
ds_feats = self.rtdc_ds.features_scalar
ds_labels = [dclab.dfn.get_feature_label(f) for f in ds_feats]
ds_fl = sorted(zip(ds_labels, ds_feats))

feat_cur = self.currentData() or default_choice # current selection
blocked = self.signalsBlocked() # remember block state
self.blockSignals(True)

# set features
self.clear()
for label, feat in ds_fl:
if feat in ds_feats:
self.addItem(label, feat)

# set previous selection
idx_cur = self.findData(feat_cur)
if idx_cur >= 0:
self.setCurrentIndex(idx_cur)
self.blockSignals(blocked)

0 comments on commit f2efd8f

Please sign in to comment.