Skip to content

Commit 21e7f57

Browse files
committed
OWDistanceMap: Store and retrieve selection
1 parent 3154ed7 commit 21e7f57

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Orange/widgets/unsupervised/owdistancemap.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ def selections(self):
225225
range(r.left(), r.right() + 1))
226226
for r in selections]
227227

228+
def set_selections(self, ranges):
229+
self.__clearSelections()
230+
for y, x in ranges:
231+
area = QRectF(x.start, y.start,
232+
x.stop - x.start - 1, y.stop - y.start - 1)
233+
item = DistanceMapItem.SelectionRect(area, self)
234+
item.setPen(QPen(Qt.red, 0))
235+
self.__selections.append((item, area))
236+
self.selectionChanged.emit()
237+
228238
def hoverMoveEvent(self, event):
229239
super().hoverMoveEvent(event)
230240
i, j = self._cellAt(event.pos())
@@ -268,6 +278,7 @@ class Outputs:
268278
color_high = settings.Setting(1.0)
269279

270280
annotation_idx = settings.ContextSetting(0)
281+
pending_selection = settings.Setting(None, schema_only=True)
271282

272283
autocommit = settings.Setting(True)
273284

@@ -393,6 +404,14 @@ def __init__(self):
393404

394405
self.grid_widget.scene().installEventFilter(self)
395406

407+
self.settingsAboutToBePacked.connect(self.pack_settings)
408+
409+
def pack_settings(self):
410+
if self.matrix_item is not None:
411+
self.pending_selection = self.matrix_item.selections()
412+
else:
413+
self.pending_selection = None
414+
396415
@Inputs.distances
397416
def set_distances(self, matrix):
398417
self.closeContext()
@@ -473,6 +492,9 @@ def handleNewSignals(self):
473492
self._update_ordering()
474493
self._setup_scene()
475494
self._update_labels()
495+
if self.pending_selection is not None:
496+
self.matrix_item.set_selections(self.pending_selection)
497+
self.pending_selection = None
476498
self.unconditional_commit()
477499

478500
def _clear_plot(self):

0 commit comments

Comments
 (0)