Commits

Aleš Erjavec committed 2fd3f5e

Added settings context handler for Annotation widget.

  • Participants
  • Parent commits 39ea399

Comments (0)

Files changed (1)

File _textable/widgets/OWTextableAnnotation.py

 
     """Orange widget for tabulating annotation information"""
 
+    contextHandlers = {
+        "": SegmentationListContextHandler(
+            "", [ContextInputListField("segmentations"),
+                 ContextInputIndex("units"),
+                 ContextInputIndex("contexts"),
+                 "unitAnnotationKey",
+                 "contextAnnotationKey",
+                 "mode"]
+            )
+    }
     settingsList = [
             'autoSend',
             'sequenceLength',
             'sortReverse',
             'keepOnlyFirst',
             'valueDelimiter',
-            'savedUnitSenderUuid',                                                  
-            'savedUnitAnnotationKey',                                               
-            'savedContextSenderUuid',                                               
-            'savedContextAnnotationKey',                                            
     ]
 
     def __init__(self, parent=None, signalManager=None):
         self.sortReverse            = True
         self.keepOnlyFirst          = True
         self.valueDelimiter         = u'|'
-        self.savedUnitSenderUuid        = None                                      
-        self.savedUnitAnnotationKey     = None                                      
-        self.savedContextSenderUuid     = None                                      
-        self.savedContextAnnotationKey  = None                                      
         self.loadSettings()
 
         # Other attributes...
 
     def inputData(self, newItem, newId=None):
         """Process incoming data."""
+        self.closeContext("")
         updateMultipleInputs(
                 self.segmentations,
                 newItem,
 
         self.adjustSize()
 
-
-
     def handleNewSignals(self):
         """Overridden: called after multiple signals have been added"""
-        try:
-            self.restoreSettings()
-        except AttributeError:
-            pass
-
-    def getSettings(self, alsoContexts = True, globalContexts=False):
-        """Overridden: called when a file is saved (among other situations)"""
-        try:
-            self.storeSettings()
-        except AttributeError:
-            pass
-        return super(type(self), self).getSettings(
-                alsoContexts = True, globalContexts=False
-        )
-
-    def restoreSettings(self):
-        """When a scheme file is opened, restore those settings that depend
-        on the particular segmentations that enter this widget.
-        """
-        if not self.settingsRestored:
-            self.settingsRestored = True
-            for segIndex in xrange(len(self.segmentations)):
-                segmentation = self.segmentations[segIndex]
-                if segmentation[0][2].uuid == self.savedUnitSenderUuid:
-                    self.units = segIndex
-                if segmentation[0][2].uuid == self.savedContextSenderUuid:
-                    self.contexts = segIndex
-            self.updateGUI()
-            if self.units is not None:
-                segmentation       = self.segmentations[self.units]
-                unitAnnotationKeys = [u'(none)']
-                unitAnnotationKeys.extend(
-                        segmentation[1].get_annotation_keys()
-                )
-                for key in unitAnnotationKeys:
-                    if key == self.savedUnitAnnotationKey:
-                        self.unitAnnotationKey = key
-                        break
-            if self.contexts is not None:
-                segmentation          = self.segmentations[self.contexts]
-                contextAnnotationKeys = [u'(none)']
-                contextAnnotationKeys.extend(
-                        segmentation[1].get_annotation_keys()
-                )
-                for key in contextAnnotationKeys:
-                    if key == self.savedContextAnnotationKey:
-                        self.contextAnnotationKey = key
-                        break
-            self.sendButton.sendIf()
-
-    def storeSettings(self):
-        """When a scheme file is saved, store those settings that depend
-        on the particular segmentations that enter this widget.
-        """
-        if self.settingsRestored:
-            if self.units is not None:
-                segmentation                = self.segmentations[self.units]
-                self.savedUnitSenderUuid    = segmentation[0][2].uuid
-                self.savedUnitAnnotationKey = self.unitAnnotationKey
-            else:
-                self.savedUnitSenderUuid    = None
-                self.savedUnitAnnotationKey = None
-            if self.contexts is not None:
-                segmentation               = self.segmentations[self.contexts]
-                self.savedContextSenderUuid    = segmentation[0][2].uuid
-                self.savedContextAnnotationKey = self.contextAnnotationKey
-            else:
-                self.savedContextSenderUuid    = None
-                self.savedContextAnnotationKey = None
-
+        self.openContext("", self.segmentations)
+        self.updateGUI()
+        self.sendButton.sendIf()
 
 
 if __name__ == '__main__':