Aleš Erjavec avatar Aleš Erjavec committed 0bfbff1

Added context dependent settings for Context widget

Comments (0)

Files changed (1)

_textable/widgets/OWTextableContext.py

 
     """Orange widget for building concordances and studying collocations"""
 
+    contextHandlers = {
+        "": SegmentationListContexHandler(
+            "", [ContextInputListField("segmentations"),
+                 ContextInputIndex("units"),
+                 ContextInputIndex("contexts"),
+                "unitAnnotationKey",
+                "contextAnnotationKey"
+                 ]
+        )
+    }
+
     settingsList = [
             'autoSend',
             'mode',
             'maxDistance',
             'minFrequency',
             'useCollocationFormat',
-            'savedUnitSenderUuid',
-            'savedUnitAnnotationKey',
-            'savedContextSenderUuid',
-            'savedContextAnnotationKey',
     ]
 
     def __init__(self, parent=None, signalManager=None):
         self.applyMaxLength             = True
         self.applyMaxDistance           = True
         self.useCollocationFormat       = False
-        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
-            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__':
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.