Skip to content

Commit 6b25402

Browse files
committed
Add proxy.remove_object() method for selective object deletion
Fixes #264
1 parent 134a7af commit 6b25402

7 files changed

Lines changed: 65 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
See DataLab [roadmap page](https://datalab-platform.com/en/contributing/roadmap.html) for future and past milestones.
44

5+
## DataLab Version 1.1.0 (unreleased) ##
6+
7+
### ✨ New Features ###
8+
9+
**Proxy API:**
10+
11+
* Added `remove_object()` method to proxy interface (local and remote) for selective object deletion
12+
* Removes currently selected object from active panel
13+
* Optional `force` parameter to skip confirmation dialog
14+
* Complements existing `reset_all()` method which removes all objects
15+
516
## DataLab Version 1.0.2 (unreleased) ##
617

718
### 🛠️ Bug Fixes ###

datalab/control/baseproxy.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ def set_current_panel(self, panel: str) -> None:
127127
def reset_all(self) -> None:
128128
"""Reset all application data"""
129129

130+
@abc.abstractmethod
131+
def remove_object(self, force: bool = False) -> None:
132+
"""Remove current object from current panel.
133+
134+
Args:
135+
force: if True, remove object without confirmation. Defaults to False.
136+
"""
137+
130138
@abc.abstractmethod
131139
def toggle_auto_refresh(self, state: bool) -> None:
132140
"""Toggle auto refresh state.
@@ -559,6 +567,14 @@ def reset_all(self) -> None:
559567
"""Reset all application data"""
560568
self._datalab.reset_all()
561569

570+
def remove_object(self, force: bool = False) -> None:
571+
"""Remove current object from current panel.
572+
573+
Args:
574+
force: if True, remove object without confirmation. Defaults to False.
575+
"""
576+
self._datalab.remove_object(force)
577+
562578
def toggle_auto_refresh(self, state: bool) -> None:
563579
"""Toggle auto refresh state.
564580

datalab/control/remote.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class RemoteServer(QC.QThread):
8181
SIG_TOGGLE_AUTO_REFRESH = QC.Signal(bool)
8282
SIG_TOGGLE_SHOW_TITLES = QC.Signal(bool)
8383
SIG_RESET_ALL = QC.Signal()
84+
SIG_REMOVE_OBJECT = QC.Signal(bool)
8485
SIG_SAVE_TO_H5 = QC.Signal(str)
8586
SIG_OPEN_H5 = QC.Signal(list, bool, bool)
8687
SIG_IMPORT_H5 = QC.Signal(str, bool)
@@ -111,6 +112,7 @@ def __init__(self, win: DLMainWindow) -> None:
111112
self.SIG_TOGGLE_AUTO_REFRESH.connect(win.toggle_auto_refresh)
112113
self.SIG_TOGGLE_SHOW_TITLES.connect(win.toggle_show_titles)
113114
self.SIG_RESET_ALL.connect(win.reset_all)
115+
self.SIG_REMOVE_OBJECT.connect(win.remove_object)
114116
self.SIG_SAVE_TO_H5.connect(win.save_to_h5_file)
115117
self.SIG_OPEN_H5.connect(win.open_h5_files)
116118
self.SIG_IMPORT_H5.connect(win.import_h5_file)
@@ -230,6 +232,15 @@ def reset_all(self) -> None:
230232
"""Reset all application data"""
231233
self.SIG_RESET_ALL.emit()
232234

235+
@remote_call
236+
def remove_object(self, force: bool = False) -> None:
237+
"""Remove current object from current panel.
238+
239+
Args:
240+
force: if True, remove object without confirmation. Defaults to False.
241+
"""
242+
self.SIG_REMOVE_OBJECT.emit(force)
243+
233244
@remote_call
234245
def save_to_h5_file(self, filename: str) -> None:
235246
"""Save to a DataLab HDF5 file.

datalab/gui/main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,16 @@ def reset_all(self) -> None:
15271527
if panel is not None:
15281528
panel.remove_all_objects()
15291529

1530+
@remote_controlled
1531+
def remove_object(self, force: bool = False) -> None:
1532+
"""Remove current object from current panel.
1533+
1534+
Args:
1535+
force: if True, remove object without confirmation. Defaults to False.
1536+
"""
1537+
panel = self.__get_current_basedatapanel()
1538+
panel.remove_object(force)
1539+
15301540
@staticmethod
15311541
def __check_h5file(filename: str, operation: str) -> str:
15321542
"""Check HDF5 filename"""

datalab/tests/backbone/main_app_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ def test_main_app():
5454
# Add signals to signal panel
5555
sig1 = create_paracetamol_signal(500)
5656
panel.add_object(sig1)
57+
nobj0 = len(panel)
58+
win.remove_object(force=True) # Test remove object method, then add it back
59+
assert len(panel) == nobj0 - 1, "One object should have been removed"
60+
panel.add_object(sig1)
5761
panel.rename_selected_object_or_group("Paracetamol Signal 1")
5862
panel.processor.run_feature(sips.derivative)
5963
panel.processor.run_feature(sips.wiener)

datalab/tests/features/common/misc_app_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ def __misc_unit_function(win: DLMainWindow) -> None:
164164
group_id=get_uuid(gp2),
165165
set_current=False,
166166
)
167+
sig = win.get_object() # Get the last added signal
168+
nobj0 = len(win.signalpanel)
169+
win.remove_object(force=True) # Test the remove object method, then add it back
170+
assert len(win.signalpanel) == nobj0 - 1, "One object should have been removed"
171+
win.add_object(sig)
167172

168173
# Add image
169174
__print_test_result("Add image")

datalab/tests/features/control/embedded1_unit_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ def add_signals(self):
164164
obj = func(title=self.sigtitle)
165165
self.add_object(obj)
166166
self.host.log(f"Added signal: {obj.title}")
167+
# Remove last added signal to test remove_object
168+
nobj0 = len(self.datalab.get_object_titles())
169+
sig = self.datalab.get_object() # Get the last added signal
170+
self.datalab.remove_object(force=True) # Test remove object method
171+
assert len(self.datalab.get_object_titles()) == nobj0 - 1, (
172+
"One object should have been removed"
173+
)
174+
self.add_object(sig) # Add it back
167175

168176
def add_images(self):
169177
"""Add images to DataLab"""

0 commit comments

Comments
 (0)