Skip to content

Commit

Permalink
fix: QuickView issues when removing datasets (close #25)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Dec 9, 2019
1 parent f497555 commit c06b852
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 23 deletions.
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
notifications:
email: false
sudo: required
addons:
apt:
packages:
# These packages are required for testing PyQT5 applications on linux
- x11-utils
- libxkbcommon-x11-0
matrix:
include:
- os: osx
language: generic
env: MAC_PYTHON_VERSION=3.6
sudo: required
- os: linux
language: python
python: 3.6
before_install:
services: xvfb
install:
# install other dependencies
- source ./.travis/${TRAVIS_OS_NAME}_setup_python.sh $MAC_PYTHON_VERSION
install:
# install binary packages
- travis_retry pip install --upgrade pip
- travis_retry pip install setuptools wheel
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
2.0.0b3
- enh: introduce FilterRay class for caching of hierarchy data (#6)
- fix: minor plot updating issues
- fix: QuickView issues when removing datasets (#25)
2.0.0b2
- feat: support loading sessions with missing dataset paths (#5)
- fix: don't use area_um, deform, and bright_avg box filters by
Expand Down
23 changes: 13 additions & 10 deletions shapeout2/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ def adopt_slot(self, slot_state):
raise ValueError("Slot not in pipeline: {}".format(slot_id))
self.adopt_pipeline(state)

@QtCore.pyqtSlot()
def add_dataslot(self, paths=None):
"""Adds a dataslot to the pipeline"""
if paths is None:
Expand Down Expand Up @@ -404,18 +405,20 @@ def on_action_develop(self, b):
msg.setWindowTitle("Restart Shape-Out")
msg.exec_()

def on_action_clear(self):
buttonReply = QtWidgets.QMessageBox.question(
self, 'Clear Session', "All progress will be lost. Continue?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No)
if buttonReply == QtWidgets.QMessageBox.Yes:
@QtCore.pyqtSlot()
def on_action_clear(self, assume_yes=False):
if assume_yes:
yes = True
else:
buttonReply = QtWidgets.QMessageBox.question(
self, 'Clear Session', "All progress will be lost. Continue?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No)
yes = buttonReply == QtWidgets.QMessageBox.Yes
if yes:
session.clear_session(self.pipeline)
self.adopt_pipeline(self.pipeline.__getstate__())
ret = True
else:
ret = False
return ret
return yes

def on_action_docs(self):
webbrowser.open("https://shapeout2.readthedocs.io")
Expand Down
6 changes: 5 additions & 1 deletion shapeout2/gui/matrix/data_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,11 @@ def get_matrix_indices(self, slot_id, filt_id):
def get_quickview_ids(self):
current = MatrixElement._quick_view_instance
if current is not None:
state = self.__getstate__()
try:
state = self.__getstate__()
except KeyError:
# the state is not valid (issue #25)
return None, None
for slot_id in state["elements"]:
ds_state = state["elements"][slot_id]
for filt_id in ds_state:
Expand Down
39 changes: 30 additions & 9 deletions shapeout2/gui/quick_view/qv_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,14 @@ def __init__(self, *args, **kwargs):

self.setWindowTitle("Quick View (QV)")

# Initially, only show the info about how QuickView works
self.widget_tool.setEnabled(False)
self.widget_scatter.hide()
self._set_initial_ui()

# Set scale options (with data)
for cb in [self.comboBox_xscale, self.comboBox_yscale]:
cb.clear()
cb.addItem("linear", "linear")
cb.addItem("logarithmic", "log")

# Hide settings/events by default
self.widget_event.setVisible(False)
self.widget_settings.setVisible(False)
self.widget_poly.setVisible(False)

# settings button
self.toolButton_event.toggled.connect(self.on_tool)
self.toolButton_poly.toggled.connect(self.on_tool)
Expand Down Expand Up @@ -120,7 +113,7 @@ def __init__(self, *args, **kwargs):
)

# set initial empty dataset
self.rtdc_ds = None
self._rtdc_ds = None

# init events/features table
self.tableWidget_feats.setColumnCount(2)
Expand Down Expand Up @@ -185,6 +178,34 @@ def __setstate__(self, state):
self.checkBox_trace_raw.setChecked(event["trace raw"])
self.checkBox_trace_legend.setChecked(event["trace legend"])

def _set_initial_ui(self):
# Initially, only show the info about how QuickView works
self.widget_tool.setEnabled(False)
self.widget_scatter.hide()
# Hide settings/events by default
self.widget_event.hide()
self.widget_settings.hide()
self.widget_poly.hide()
# show the how-to label
self.label_howto.show()

@property
def rtdc_ds(self):
"""Dataset to plot; set to None initially and if the file is closed"""
if self._rtdc_ds is not None:
if isinstance(self._rtdc_ds, dclab.rtdc_dataset.RTDC_HDF5):
if not self._rtdc_ds._h5:
# the file is closed
self._rtdc_ds = None
# now check again
if self._rtdc_ds is None:
self._set_initial_ui()
return self._rtdc_ds

@rtdc_ds.setter
def rtdc_ds(self, rtdc_ds):
self._rtdc_ds = rtdc_ds

def get_event_image(self, ds, event):
state = self.__getstate__()
imkw = self.imkw.copy()
Expand Down
35 changes: 35 additions & 0 deletions tests/test_gui_quickview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Test of data set functionalities"""
import pathlib

from PyQt5 import QtCore

from shapeout2.gui.main import ShapeOut2


def test_simple(qtbot):
"""Open the main window and close it again"""
main_window = ShapeOut2()
main_window.close()


def test_quickview_issue_25(qtbot):
mw = ShapeOut2()
qtbot.addWidget(mw)

# add a dataslot
path = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc"
mw.add_dataslot(paths=[path])

assert len(mw.pipeline.slot_ids) == 1, "we added that"
assert len(mw.pipeline.filter_ids) == 1, "automatically added"

# activate a dataslot
slot_id = mw.pipeline.slot_ids[0]
filt_id = mw.pipeline.filter_ids[0]
em = mw.block_matrix.get_widget(slot_id, filt_id)
qtbot.mouseClick(em, QtCore.Qt.LeftButton, QtCore.Qt.ShiftModifier)
# did that work?
assert mw.toolButton_quick_view.isChecked()

# now clear the session (this raised the errror in #25)
mw.on_action_clear(assume_yes=True)

0 comments on commit c06b852

Please sign in to comment.