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] Edit Domain: Add an option to change the output table name #4722

Merged
merged 1 commit into from
May 8, 2020
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
12 changes: 11 additions & 1 deletion Orange/widgets/data/oweditdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,7 @@ class Error(widget.OWWidget.Error):
_domain_change_store = settings.ContextSetting({})
_selected_item = settings.ContextSetting(None) # type: Optional[Tuple[str, int]]
_merge_dialog_settings = settings.ContextSetting({})
output_table_name = settings.ContextSetting("")

want_control_area = False

Expand Down Expand Up @@ -1809,6 +1810,10 @@ def __init__(self):

box.layout().addWidget(self._editor)

self.le_output_name = gui.lineEdit(
self.mainArea, self, "output_table_name", "Output table name: ",
box=True, orientation=Qt.Horizontal)

bbox = QDialogButtonBox()
bbox.setStyleSheet(
"button-layout: {:d};".format(QDialogButtonBox.MacLayout))
Expand Down Expand Up @@ -1856,10 +1861,12 @@ def set_data(self, data):
self.info.set_input_summary(len(data),
format_summary_details(data))
self.setup_model(data)
self.le_output_name.setPlaceholderText(data.name)
self.openContext(self.data)
self._editor.set_merge_context(self._merge_dialog_settings)
self._restore()
else:
self.le_output_name.setPlaceholderText("")
self.info.set_input_summary(self.info.NoInput)

self.commit()
Expand Down Expand Up @@ -2054,7 +2061,8 @@ def state(i):
model.data(midx, TransformRole))

state = [state(i) for i in range(model.rowCount())]
if all(tr is None or not tr for _, tr in state):
if all(tr is None or not tr for _, tr in state) \
and self.output_table_name in ("", data.name):
self.Outputs.data.send(data)
self.info.set_output_summary(len(data),
format_summary_details(data))
Expand Down Expand Up @@ -2090,6 +2098,8 @@ def state(i):
Ys = [v for v in Ys if v.is_primitive()]
domain = Orange.data.Domain(Xs, Ys, Ms)
new_data = data.transform(domain)
if self.output_table_name:
new_data.name = self.output_table_name
self.Outputs.data.send(new_data)
self.info.set_output_summary(len(new_data),
format_summary_details(new_data))
Expand Down
5 changes: 5 additions & 0 deletions Orange/widgets/data/tests/test_oweditdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ def test_output_data(self):
np.testing.assert_array_equal(output.Y, self.iris.Y)
self.assertEqual(output.domain, self.iris.domain)

self.widget.output_table_name = "Iris 2"
self.widget.commit()
output = self.get_output(self.widget.Outputs.data)
self.assertEqual(output.name, "Iris 2")

def test_input_from_owcolor(self):
"""Check widget's data sent from OWColor widget"""
owcolor = self.create_widget(OWColor)
Expand Down