Skip to content

Commit

Permalink
SelectRows: Fix loading of conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
astaric committed Mar 2, 2017
1 parent 7ad7488 commit 6546931
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Orange/widgets/data/owselectrows.py
Expand Up @@ -194,9 +194,7 @@ def add_row(self, attr=None, condition_type=None, condition_value=None):
minimumContentsLength=12,
sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon)
attr_combo.row = row
for var in filter_visible(chain(self.data.domain.class_vars,
self.data.domain.metas,
self.data.domain.attributes)):
for var in self._visible_variables(self.data.domain):
attr_combo.addItem(*gui.attributeItem(var))
attr_combo.setCurrentIndex(attr or 0)
self.cond_list.setCellWidget(row, 0, attr_combo)
Expand All @@ -216,6 +214,13 @@ def add_row(self, attr=None, condition_type=None, condition_value=None):

self.cond_list.resizeRowToContents(row)

@staticmethod
def _visible_variables(domain):
"""Generate variables in order they should be presented in in combos."""
return filter_visible(chain(domain.class_vars,
domain.metas,
domain.attributes))

def add_all(self):
if self.cond_list.rowCount():
Mb = QMessageBox
Expand Down Expand Up @@ -395,8 +400,7 @@ def set_data(self, data):
except Exception:
pass

variables = list(filter_visible(chain(data.domain.variables,
data.domain.metas)))
variables = list(self._visible_variables(self.data.domain))
varnames = [v.name for v in variables]
if self.conditions:
for attr, cond_type, cond_value in self.conditions:
Expand Down
26 changes: 26 additions & 0 deletions Orange/widgets/data/tests/test_owselectrows.py
Expand Up @@ -190,6 +190,32 @@ def test_restores_continuous_filter_in_sl_SI_locale(self):
values = self.widget.conditions[0][2]
self.assertTrue(values[0].startswith("5,2"))

def test_load_settings(self):
iris = Table("iris")[:5]
self.send_signal("Data", iris)

sepal_length, sepal_width = iris.domain[:2]

# Validating with C locale should accept decimal point
self.widget.remove_all_button.click()
self.enterFilter(sepal_width, "is below", "5.2")
self.enterFilter(sepal_length, "is at most", "4")
data = self.widget.settingsHandler.pack_data(self.widget)

w2 = self.create_widget(OWSelectRows, data)
self.send_signal("Data", iris, widget=w2)

var_combo = w2.cond_list.cellWidget(0, 0)
self.assertEquals(var_combo.currentText(), "sepal width")
oper_combo = w2.cond_list.cellWidget(0, 1)
self.assertEquals(oper_combo.currentText(), "is below")

var_combo = w2.cond_list.cellWidget(1, 0)
self.assertEquals(var_combo.currentText(), "sepal length")
oper_combo = w2.cond_list.cellWidget(1, 1)
self.assertEquals(oper_combo.currentText(), "is at most")


def widget_with_context(self, domain, conditions):
ch = SelectRowsContextHandler()
context = ch.new_context(domain, *ch.encode_domain(domain))
Expand Down

0 comments on commit 6546931

Please sign in to comment.