Commits

Aleš Erjavec committed 6f61e6b

Added some basic error warning reporting. Minor bug fixes.

Comments (0)

Files changed (1)

widgets/OWQualityControl.py

 
 DEBUG = False
 
+
 @contextmanager
 def widget_disable(widget):
     """A context to disable the widget (enabled property)  
     yield
     widget.setEnabled(True)
     
+    
 @contextmanager
 def disable_updates(widget):
     """
     yield
     widget._disable_updates = False
 
+
 def group_label(splits, groups):
     """Return group label.
     """
     labels = ["{}={}".format(*item) for item in items]
     return " | ".join(labels)
 
+
 def float_if_posible(val):
     """Return val as float if possible otherwise return the value unchanged.
     
     except ValueError:
         return val
     
+    
 def experiment_description(feature):
     """Return experiment description from ``feature.attributes``. 
     """
         text += "<br/>".join(labels)
     return text
 
+
 class OWQualityControl(OWWidget):
     contextHandlers = {"": SetContextHandler("")}
     settingsList = []
         self.distances = None
         self.groups = None
         self.unique_pos = None
-        self.base_index = 0
+        self.base_group_index = 0
 
         ## GUI
         box = OWGUI.widgetBox(self.controlArea, "Info")
         self.info_box = OWGUI.widgetLabel(box, "\n")
 
-        ## Split By box
-        box = OWGUI.widgetBox(self.controlArea, "Split By")
+        ## Separate By box
+        box = OWGUI.widgetBox(self.controlArea, "Separate By")
         self.split_by_model = PyListModel()
         self.split_by_view = QListView()
         self.split_by_view.setSelectionMode(QListView.ExtendedSelection)
         """Set input experiment data.
         """
         self.clear()
+        
+        self.error(0)
+        self.warning(0)
+        
+        if data is not None:
+            keys = self.get_suitable_keys(data)
+            if not keys:
+                self.error(0, "Data has no suitable feature labels.")
+                data = None
+                
         self.data = data
 
     def handleNewSignals(self):
     def selected_base_group_index(self):
         """Return the selected base group index
         """
-        return self.base_index
+        return self.base_group_index
     
     def selected_base_indices(self, base_group_index=None):
         indices = []
         """
         with widget_disable(self):
             if not self._disable_updates:
+                self.base_group_index = 0
                 context = self.currentContexts[""]
                 context.split_by_labels = self.selected_split_by_labels()
                 self.split_and_update()
         """
         with widget_disable(self):
             if not self._disable_updates:
-                self.base_index = 0
+                self.base_group_index = 0
                 context = self.currentContexts[""]
                 context.sort_by_labels = self.selected_sort_by_labels()
                 self.split_and_update()
         sort_by_labels = self.selected_sort_by_labels()
         if sort_by_labels and item.in_group:
             ## The item is part of the group
-            if item.group_index != self.base_index:
-                self.base_index = item.group_index
+            if item.group_index != self.base_group_index:
+                self.base_group_index = item.group_index
                 update = True
             
         else:
         """
         split_labels = self.selected_split_by_labels()
         sort_labels = self.selected_sort_by_labels()
+        
+        self.warning(0)
+        if not split_labels:
+            self.warning(0, "No separate by label selected.")
+            
         self.groups, self.unique_pos = \
                 exp.separate_by(self.data, split_labels,
                                 consider=sort_labels,
                 (mat, set(zip(range(len(attrs)), range(len(attrs)))))
             
         return self._cached_distances[measure]
-            
-            
+        
     def get_cached_distance(self, measure, i, j):
         matrix, computed = self.get_cached_distances(measure)
         key = (i, j) if i < j else (j, i)