Skip to content

Commit 79ffb5c

Browse files
committed
OWMergeData: Improve gui, add tooltips
1 parent b21833c commit 79ffb5c

File tree

1 file changed

+48
-13
lines changed

1 file changed

+48
-13
lines changed

Orange/widgets/data/owmergedata.py

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
import numpy as np
55

6-
from AnyQt.QtCore import pyqtSignal as Signal
7-
from AnyQt.QtWidgets import QApplication, QStyle, QWidget, \
8-
QLabel, QComboBox, QPushButton, QVBoxLayout, QHBoxLayout
6+
from AnyQt.QtCore import Qt, QModelIndex, pyqtSignal as Signal
7+
from AnyQt.QtWidgets import QWidget, QLabel, QComboBox, QPushButton, \
8+
QVBoxLayout, QHBoxLayout
99

1010
import Orange
1111
from Orange.data import StringVariable, ContinuousVariable, Variable
@@ -154,6 +154,20 @@ def emit_list(self):
154154
self.vars_changed.emit(self.current_state())
155155

156156

157+
class DomainModelWithTooltips(DomainModel):
158+
def data(self, index, role=Qt.DisplayRole):
159+
if role == Qt.ToolTipRole \
160+
and isinstance(index, QModelIndex) and index.isValid():
161+
if index.row() == 0:
162+
return "Match rows sequentially"
163+
if index.row() == 1:
164+
return "Re-match rows from tables obtained from the same " \
165+
"source,\n" \
166+
"e.g. data from the same file that was split within " \
167+
"the workflow."
168+
return super().data(index, role)
169+
170+
157171
class OWMergeData(widget.OWWidget):
158172
name = "Merge Data"
159173
description = "Merge datasets based on the values of selected features."
@@ -174,6 +188,25 @@ class Outputs:
174188
OptionNames = ("Append columns from Extra data",
175189
"Find matching pairs of rows",
176190
"Concatenate tables")
191+
OptionDescriptions = (
192+
"The first table may contain, for instance, city names,\n"
193+
"and the second would be a list of cities and their coordinates.\n"
194+
"Columns with coordinates would then be appended to the output.",
195+
196+
"Input tables contain different features describing the same data "
197+
"instances.\n"
198+
"Output contains matched instances. Rows without matches are removed.",
199+
200+
"Input tables contain different features describing the same data "
201+
"instances.\n"
202+
"Output contains all instances. Data from merged instances is "
203+
"merged into single rows."
204+
)
205+
206+
UserAdviceMessages = [
207+
widget.Message(
208+
"Confused about merging options?\nSee the tooltips!",
209+
"merging_types")]
177210

178211
attr_pairs = Setting(None, schema_only=True)
179212
merging = Setting(LeftJoin)
@@ -210,8 +243,8 @@ def __init__(self):
210243
content = [
211244
INDEX, INSTANCEID,
212245
DomainModel.ATTRIBUTES, DomainModel.CLASSES, DomainModel.METAS]
213-
self.model = DomainModel(content)
214-
self.extra_model = DomainModel(content)
246+
self.model = DomainModelWithTooltips(content)
247+
self.extra_model = DomainModelWithTooltips(content)
215248

216249
box = gui.hBox(self.controlArea, box=None)
217250
self.infoBoxData = gui.label(
@@ -221,18 +254,20 @@ def __init__(self):
221254

222255
grp = gui.radioButtons(
223256
self.controlArea, self, "merging", box="Merging",
224-
btnLabels=self.OptionNames, callback=self.change_merging)
257+
btnLabels=self.OptionNames, tooltips=self.OptionDescriptions,
258+
callback=self.change_merging)
225259
grp.layout().setSpacing(8)
226260

227-
self.attr_boxes = box = ConditionBox(
228-
self, self.model, self.extra_model, "where", "matches")
229-
box.add_row()
230-
radio_width = \
231-
QApplication.style().pixelMetric(QStyle.PM_ExclusiveIndicatorWidth)
232-
gui.indentedBox(grp, radio_width).layout().addWidget(box)
261+
self.attr_boxes = ConditionBox(
262+
self, self.model, self.extra_model, "", "matches")
263+
self.attr_boxes.add_row()
264+
box = gui.vBox(self.controlArea, box="Row matching")
265+
box.layout().addWidget(self.attr_boxes)
266+
233267
gui.auto_commit(self.controlArea, self, "auto_apply", "&Apply",
234268
box=False)
235-
box.vars_changed.connect(self.commit) # connect after auto_commit!
269+
# connect after wrapping self.commit with gui.auto_commit!
270+
self.attr_boxes.vars_changed.connect(self.commit)
236271
self.settingsAboutToBePacked.connect(self.store_combo_state)
237272

238273
def change_merging(self):

0 commit comments

Comments
 (0)