|
1 | 1 | from collections import namedtuple |
2 | 2 | from itertools import chain, product |
3 | 3 |
|
| 4 | +import numpy as np |
| 5 | + |
4 | 6 | from AnyQt.QtCore import pyqtSignal as Signal |
5 | 7 | from AnyQt.QtWidgets import QApplication, QStyle, QWidget, \ |
6 | 8 | QLabel, QComboBox, QPushButton, QVBoxLayout, QHBoxLayout |
7 | 9 |
|
8 | | -import numpy as np |
9 | | - |
10 | 10 | import Orange |
11 | 11 | from Orange.data import StringVariable, ContinuousVariable, Variable |
12 | 12 | from Orange.data.util import hstack |
@@ -160,7 +160,7 @@ class Outputs: |
160 | 160 | "Find matching pairs of rows", |
161 | 161 | "Concatenate tables") |
162 | 162 |
|
163 | | - attr_pairs = Setting('', schema_only=True) |
| 163 | + attr_pairs = Setting(None, schema_only=True) |
164 | 164 | merging = Setting(LeftJoin) |
165 | 165 | auto_apply = Setting(True) |
166 | 166 | settings_version = 1 |
@@ -220,9 +220,6 @@ def __init__(self): |
220 | 220 | box.vars_changed.connect(self.commit) # connect after auto_commit! |
221 | 221 | self.settingsAboutToBePacked.connect(self.store_combo_state) |
222 | 222 |
|
223 | | - def store_combo_state(self): |
224 | | - self.attr_pairs = self.attr_boxes.current_state() |
225 | | - |
226 | 223 | def change_merging(self): |
227 | 224 | self.commit() |
228 | 225 |
|
@@ -280,13 +277,33 @@ def _restore_combo_current_items(self, side, prev_settings): |
280 | 277 | self._try_set_combo( |
281 | 278 | [row.left_combo, row.right_combo][side], pair[side]) |
282 | 279 |
|
| 280 | + def store_combo_state(self): |
| 281 | + self.attr_pairs = ( |
| 282 | + self.data is not None, |
| 283 | + self.extra_data is not None, |
| 284 | + [[[INDEX, INSTANCEID].index(x) if isinstance(x, str) else x.name |
| 285 | + for x in row] |
| 286 | + for row in self.attr_boxes.current_state()]) |
| 287 | + |
283 | 288 | def handleNewSignals(self): |
284 | | - if self.attr_pairs and self.data: |
285 | | - # TODO: This doesn't work, but should after #3925 (remove make) |
286 | | - self.attr_boxes.set_state(self.attr_pairs) |
| 289 | + if self.attr_pairs \ |
| 290 | + and self.attr_pairs[:2] == (self.data is not None, |
| 291 | + self.extra_data is not None): |
| 292 | + def unpack(x, data): |
| 293 | + if isinstance(x, int): |
| 294 | + return [INDEX, INSTANCEID][x] |
| 295 | + if data is not None and x in data.domain: |
| 296 | + return data.domain[x] |
| 297 | + else: |
| 298 | + return INDEX |
| 299 | + |
| 300 | + state = [ |
| 301 | + [unpack(row[0], self.data), unpack(row[1], self.extra_data)] |
| 302 | + for row in self.attr_pairs[2]] |
| 303 | + self.attr_boxes.set_state(state) |
287 | 304 | # This is schema-only setting, so it should be single-shot |
288 | 305 | # More complicated alternative: make it a context setting |
289 | | - self.attr_pairs = [] |
| 306 | + self.attr_pairs = None |
290 | 307 | self._find_best_match() |
291 | 308 | box = self.attr_boxes |
292 | 309 |
|
@@ -516,8 +533,10 @@ def migrate_settings(settings, version=None): |
516 | 533 | if not version: |
517 | 534 | operations = ("augment", "merge", "combine") |
518 | 535 | oper = [settings["merging"]] |
519 | | - settings["attr_pairs"] = [(settings[f"attr_{oper}_data"], |
520 | | - settings[f"attr_{oper}_extra"])] |
| 536 | + settings["attr_pairs"] = ( |
| 537 | + True, True, |
| 538 | + [(settings[f"attr_{oper}_data"], |
| 539 | + settings[f"attr_{oper}_extra"])]) |
521 | 540 | for oper in operations: |
522 | 541 | del settings[f"attr_{oper}_data"] |
523 | 542 | del settings[f"attr_{oper}_extra"] |
|
0 commit comments