Commits

Aleš Erjavec committed de4e035

Added context settings to Count widget.

Comments (0)

Files changed (1)

_textable/widgets/OWTextableCount.py

 
     """Orange widget for counting text units"""
 
+    contextHandlers = {
+        "": SegmentationListContexHandler(
+            "", [ContextInputListField("segmentations"),
+                 ContextInputIndex("units"),
+                 ContextInputIndex("contexts"),
+                 "mode",
+                 "unitAnnotationKey",
+                 "contextAnnotationKey"]
+        )
+    }
     settingsList = [
             'autoSend',
             'sequenceLength',
             'leftContextSize',
             'rightContextSize',
             'unitPosMarker',
-            'savedUnitSenderUuid',                                                  
-            'savedUnitAnnotationKey',                                               
-            'savedContextSenderUuid',                                               
-            'savedContextAnnotationKey',                                            
-            'savedMode',                                                            
     ]
 
     def __init__(self, parent=None, signalManager=None):
         self.leftContextSize            = 0
         self.rightContextSize           = 0
         self.unitPosMarker              = u'_'
-        self.savedUnitSenderUuid        = None                                      
-        self.savedUnitAnnotationKey     = None                                      
-        self.savedContextSenderUuid     = None                                      
-        self.savedContextAnnotationKey  = None                                      
-        self.savedMode                  = None                                      
         self.loadSettings()
 
         # Other attributes...
         self.unitAnnotationKey      = None
         self.contexts               = None
         self.contextAnnotationKey   = None
-        self.settingsRestored       = False                                         
         self.infoBox                = InfoBox(
                 widget          = self.controlArea,
                 stringClickSend = u"Please click 'Compute' when ready.",
 
     def inputData(self, newItem, newId=None):
         """Process incoming data."""
+        self.closeContext()
         updateMultipleInputs(
                 self.segmentations,
                 newItem,
             self.contextAnnotationKey = self.contextAnnotationKey
             
         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
-            self.mode             = self.savedMode
-            for segIndex in xrange(len(self.segmentations)):
-                segmentation = self.segmentations[segIndex]
-                if segmentation[0][2].uuid == self.savedUnitSenderUuid:
-                    self.units = segIndex
-                if self.mode == u'Containing segmentation':
-                    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.mode == u'Containing segmentation':
-                    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:
-            self.savedMode                  = self.mode
-            if self.units is not None:
-                segmentation                = self.segmentations[self.units]
-                self.savedUnitSenderUuid    = segmentation[0][2].uuid
-                self.savedUnitAnnotationKey = self.unitAnnotationKey
-                if          self.mode == u'Containing segmentation' \
-                        and 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
-            else:
-                self.savedUnitSenderUuid    = None
-                self.savedUnitAnnotationKey = None
+        self.updateGUI()
+        self.openContext("", self.segmentations)
+        self.updateGUI()
+        self.sendButton.sendIf()
+
+#     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
+#             self.mode             = self.savedMode
+#             for segIndex in xrange(len(self.segmentations)):
+#                 segmentation = self.segmentations[segIndex]
+#                 if segmentation[0][2].uuid == self.savedUnitSenderUuid:
+#                     self.units = segIndex
+#                 if self.mode == u'Containing segmentation':
+#                     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.mode == u'Containing segmentation':
+#                     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:
+#             self.savedMode                  = self.mode
+#             if self.units is not None:
+#                 segmentation                = self.segmentations[self.units]
+#                 self.savedUnitSenderUuid    = segmentation[0][2].uuid
+#                 self.savedUnitAnnotationKey = self.unitAnnotationKey
+#                 if          self.mode == u'Containing segmentation' \
+#                         and 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
+#             else:
+#                 self.savedUnitSenderUuid    = None
+#                 self.savedUnitAnnotationKey = None