Skip to content

Commit f90f104

Browse files
committed
OWMergeData: make chosen attr schema-only settings
1 parent 564664e commit f90f104

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

Orange/widgets/data/owmergedata.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ class OWMergeData(widget.OWWidget):
2727
outputs = [("Merged Data A+B", Orange.data.Table, ),
2828
("Merged Data B+A", Orange.data.Table, )]
2929

30-
settingsHandler = settings.DomainContextHandler()
31-
32-
attr_a = settings.ContextSetting('')
33-
attr_b = settings.ContextSetting('')
30+
attr_a = settings.Setting('', schema_only=True)
31+
attr_b = settings.Setting('', schema_only=True)
3432

3533
want_main_area = False
3634

@@ -82,36 +80,41 @@ def __init__(self):
8280

8381
gui.rubber(self)
8482

85-
def setAttrs(self):
86-
add = ()
87-
if self.dataA is not None and self.dataB is not None \
88-
and len(numpy.intersect1d(self.dataA.ids, self.dataB.ids)):
89-
add = (INSTANCEID,)
90-
if self.dataA is not None:
91-
self.attrModelA[:] = add + allvars(self.dataA)
92-
else:
93-
self.attrModelA[:] = []
94-
if self.dataB is not None:
95-
self.attrModelB[:] = add + allvars(self.dataB)
96-
else:
97-
self.attrModelB[:] = []
83+
def _setAttrs(self, model, data, othermodel, otherdata):
84+
model[:] = allvars(data) if data is not None else []
85+
86+
if data is not None and otherdata is not None and \
87+
len(numpy.intersect1d(data.ids, otherdata.ids)):
88+
for model_ in (model, othermodel):
89+
if len(model_) and model_[0] != INSTANCEID:
90+
model_.insert(0, INSTANCEID)
9891

9992
@check_sql_input
10093
def setDataA(self, data):
10194
self.dataA = data
102-
self.setAttrs()
103-
self.closeContext()
104-
self.attr_a = next(iter(self.attrModelA), '')
105-
self.openContext(self.dataA)
95+
self._setAttrs(self.attrModelA, data, self.attrModelB, self.dataB)
96+
curr_index = -1
97+
if self.attr_a:
98+
curr_index = next((i for i, val in enumerate(self.attrModelA)
99+
if str(val) == self.attr_a), -1)
100+
if curr_index != -1:
101+
self.attrViewA.setCurrentIndex(curr_index)
102+
else:
103+
self.attr_a = INDEX
106104
self.infoBoxDataA.setText(self.dataInfoText(data))
107105

108106
@check_sql_input
109107
def setDataB(self, data):
110108
self.dataB = data
111-
self.setAttrs()
112-
self.closeContext()
113-
self.attr_b = next(iter(self.attrModelB), '')
114-
self.openContext(self.dataB)
109+
self._setAttrs(self.attrModelB, data, self.attrModelA, self.dataA)
110+
curr_index = -1
111+
if self.attr_b:
112+
curr_index = next((i for i, val in enumerate(self.attrModelB)
113+
if str(val) == self.attr_b), -1)
114+
if curr_index != -1:
115+
self.attrViewB.setCurrentIndex(curr_index)
116+
else:
117+
self.attr_b = INDEX
115118
self.infoBoxDataB.setText(self.dataInfoText(data))
116119

117120
def handleNewSignals(self):

0 commit comments

Comments
 (0)