55
66from AnyQt .QtWidgets import (
77 QWidget , QTableWidget , QHeaderView , QComboBox , QLineEdit , QToolButton ,
8- QMessageBox , QMenu , QListView , QGridLayout , QPushButton , QSizePolicy
9- )
8+ QMessageBox , QMenu , QListView , QGridLayout , QPushButton , QSizePolicy ,
9+ QLabel )
1010from AnyQt .QtGui import (
1111 QDoubleValidator , QRegExpValidator , QStandardItemModel , QStandardItem ,
1212 QFontMetrics , QPalette
2424from Orange .widgets .settings import Setting , ContextSetting , DomainContextHandler
2525from Orange .widgets .utils import vartype
2626from Orange .canvas import report
27+ from Orange .widgets .widget import Msg
2728
2829
2930class SelectRowsContextHandler (DomainContextHandler ):
@@ -39,7 +40,7 @@ def encode_setting(self, context, setting, value):
3940 CONTINUOUS = vartype (ContinuousVariable ())
4041 for i , (attr , op , values ) in enumerate (value ):
4142 if context .attributes .get (attr ) == CONTINUOUS :
42- if isinstance (values [0 ], str ):
43+ if values and isinstance (values [0 ], str ):
4344 values = [QLocale ().toDouble (v )[0 ] for v in values ]
4445 value [i ] = (attr , op , values )
4546 return super ().encode_setting (context , setting , value )
@@ -120,6 +121,9 @@ class OWSelectRows(widget.OWWidget):
120121 operator_names = {vtype : [name for _ , name in filters ]
121122 for vtype , filters in Operators .items ()}
122123
124+ class Error (widget .OWWidget .Error ):
125+ parsing_error = Msg ("{}" )
126+
123127 def __init__ (self ):
124128 super ().__init__ ()
125129
@@ -289,7 +293,7 @@ def _get_value_contents(box):
289293 names .append (item .text ())
290294 child .desc_text = ', ' .join (names )
291295 child .set_text ()
292- elif child is None :
296+ elif isinstance ( child , QLabel ) or child is None :
293297 pass
294298 else :
295299 raise TypeError ('Type %s not supported.' % type (child ))
@@ -340,8 +344,10 @@ def add_datetime(contents):
340344 lc = self ._get_lineedit_contents (box ) + lc
341345 oper = oper_combo .currentIndex ()
342346
343- if oper == oper_combo .count () - 1 :
344- self .cond_list .removeCellWidget (oper_combo .row , 2 )
347+ if oper_combo .currentText () == "is defined" :
348+ label = QLabel ()
349+ label .var_type = vartype (var )
350+ self .cond_list .setCellWidget (oper_combo .row , 2 , label )
345351 elif var .is_discrete :
346352 if oper_combo .currentText () == "is one of" :
347353 if selected_values :
@@ -430,6 +436,8 @@ def conditions_changed(self):
430436 pass
431437
432438 def _values_to_floats (self , attr , values ):
439+ if not len (values ):
440+ return values
433441 if not all (values ):
434442 return None
435443 if isinstance (attr , TimeVariable ):
@@ -450,7 +458,7 @@ def _values_to_floats(self, attr, values):
450458 def commit (self ):
451459 matching_output = self .data
452460 non_matching_output = None
453- self .error ()
461+ self .Error . clear ()
454462 if self .data :
455463 domain = self .data .domain
456464 conditions = []
@@ -463,7 +471,7 @@ def commit(self):
463471 try :
464472 floats = self ._values_to_floats (attr , values )
465473 except ValueError as e :
466- self .error (e .args [0 ])
474+ self .Error . parsing_error (e .args [0 ])
467475 return
468476 if floats is None :
469477 continue
@@ -508,7 +516,7 @@ def commit(self):
508516 attr_flags = sum ([Remove .RemoveConstant * purge_attrs ,
509517 Remove .RemoveUnusedValues * purge_attrs ])
510518 class_flags = sum ([Remove .RemoveConstant * purge_classes ,
511- Remove .RemoveUnusedValues * purge_classes ])
519+ Remove .RemoveUnusedValues * purge_classes ])
512520 # same settings used for attributes and meta features
513521 remover = Remove (attr_flags , class_flags , attr_flags )
514522
@@ -532,7 +540,9 @@ def sp(s, capitalize=True):
532540 else :
533541 lab1 .setText (label + "~%s row%s, %s variable%s" %
534542 (sp (data .approx_len ()) +
535- sp (len (data .domain .variables ) + len (data .domain .metas ))))
543+ sp (len (data .domain .variables ) +
544+ len (data .domain .metas )))
545+ )
536546
537547 def send_report (self ):
538548 if not self .data :
0 commit comments