Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Offload work to a separate thread #3627

Merged
merged 3 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Orange/projection/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import inspect
import threading

Expand Down Expand Up @@ -135,6 +136,7 @@ def proj_variable(i, name):

super().__init__(proj=proj)
self.orig_domain = domain
self.n_components = n_components
var_names = self._get_var_names(n_components)
self.domain = Orange.data.Domain(
[proj_variable(i, var_names[i]) for i in range(n_components)],
Expand All @@ -145,6 +147,13 @@ def _get_var_names(self, n):
names = [f"{self.var_prefix}-{postfix}" for postfix in postfixes]
return get_unique_names(self.orig_domain, names)

def copy(self):
proj = copy.deepcopy(self.proj)
model = type(self)(proj, self.domain.copy(), self.n_components)
model.pre_domain = self.pre_domain.copy()
model.name = self.name
return model


class LinearProjector(Projector):
name = "Linear Projection"
Expand Down
13 changes: 11 additions & 2 deletions Orange/widgets/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,10 +857,13 @@ def _compare_selected_annotated_domains(self, selected, annotated):
annotated_vars = annotated.domain.variables
self.assertLessEqual(set(selected_vars), set(annotated_vars))

def test_setup_graph(self):
def test_setup_graph(self, timeout=DEFAULT_TIMEOUT):
"""Plot should exist after data has been sent in order to be
properly set/updated"""
self.send_signal(self.widget.Inputs.data, self.data)
if self.widget.isBlocking():
spy = QSignalSpy(self.widget.blockingStateChanged)
self.assertTrue(spy.wait(timeout))
self.assertIsNotNone(self.widget.graph.scatterplot_item)

def test_default_attrs(self, timeout=DEFAULT_TIMEOUT):
Expand Down Expand Up @@ -1013,12 +1016,18 @@ def test_invalidated_embedding(self, timeout=DEFAULT_TIMEOUT):
self.widget.graph.update_coordinates.assert_not_called()
self.widget.graph.update_point_props.assert_called_once()

def test_saved_selection(self):
def test_saved_selection(self, timeout=DEFAULT_TIMEOUT):
self.send_signal(self.widget.Inputs.data, self.data)
if self.widget.isBlocking():
spy = QSignalSpy(self.widget.blockingStateChanged)
self.assertTrue(spy.wait(timeout))
self.widget.graph.select_by_indices(list(range(0, len(self.data), 10)))
settings = self.widget.settingsHandler.pack_data(self.widget)
w = self.create_widget(self.widget.__class__, stored_settings=settings)
self.send_signal(self.widget.Inputs.data, self.data, widget=w)
if w.isBlocking():
spy = QSignalSpy(w.blockingStateChanged)
self.assertTrue(spy.wait(timeout))
self.assertEqual(np.sum(w.graph.selection), 15)
np.testing.assert_equal(self.widget.graph.selection, w.graph.selection)

Expand Down
Loading