1. Aleš Erjavec
  2. orange-textable

Commits

Aleš Erjavec  committed dd61811

Added receiving widget uuid to the encoded context.

  • Participants
  • Parent commits 5e9bb07
  • Branches master

Comments (0)

Files changed (1)

File _textable/widgets/TextableUtils.py

View file
         if findImperfect != False:
             raise ValueError("'findImperfect' is disabled")
 
-        OWContexts.ContextHandler.__init__(self, contextName,
-                                           findImperfect=False, **kwargs)
+        OWContexts.ContextHandler.__init__(
+            self, contextName, findImperfect=False, syncWithGlobal=False,
+            contextDataVersion=2, **kwargs
+        )
 
         fields = [ContextField(field) if isinstance(field, str) else field
                   for field in fields]
             raise ValueError("Only one 'ContextInputListField' is allowed")
 
     def findOrCreateContext(self, widget, items):
-        encoded = self.encode(items)
+        encoded = self.encode(widget, items)
         context, isnew = OWContexts.ContextHandler.findOrCreateContext(
             self, widget, encoded)
 
 
         return context, isnew
 
-    def encode(self, segmentationlist):
+    def encode(self, widget, segmentationlist):
         """
-        Encode a list of input segmentations.
+        Encode a list of input segmentations for the receiving widget.
+
+        Return a tuple of ```(widget.uuid, encoded_input)```.
+        `encoded_input` is a list of  ```(label, annotations, uuid)```
+        tuples where `label` is the segmentation label, `annotations` is
+        a sorted tuple of segmentation annotation keys and `uuid` is the
+        unique identifier if the unique input (source) widget.
 
-        Return a list of ```(label, annotations, uuid)``` tuples where
-        `label` is the segmentation label, `annotations` is a sorted tuple
-        of segmentation annotation keys and `uuid` is the unique input
-        widget identifier.
+        .. note::
+            If the receiving widget does not have a uuid then the first
+            element of the returned tuple (`widget.uuid`) will be None.
 
+        :param OWWidget widget:
+            Widget receiving the input.
         :param list segmentationlist:
             List of (inputid, Segmentation) tuples.
 
             annot = tuple(sorted(segmentation.get_annotation_keys()))
             uuid = getattr(inputid[2], "uuid", None)
             encoded.append((label, annot, uuid))
-        return encoded
 
-    def match(self, context, imperfect, encodedlist):
+        return (getattr(widget, "uuid", None), encoded)
+
+    def match(self, context, imperfect, encoded):
         """
-        Match the `context` to the encoded segmentations list
+        Match the `context` to the encoded input segmentations.
 
-        Two contexts match if one encoding is a reordering of the other.
+        Two contexts match if the receiving widget uuid matches the
+        stored one and one input list encoding is a reordering of the
+        other.
 
         """
-        stored = context.encoded
+        widget_uuid, inputs = encoded
+        stored_uuid, stored_inputs = context.encoded
+
+        if stored_uuid != widget_uuid:
+            # Receiving widget uuid does not match the stored context
+            return 0
 
-        if len(stored) == len(encodedlist):
-            if set(stored) == set(encodedlist):
-                # Perfect match
+        if len(stored_inputs) == len(inputs):
+            if set(stored_inputs) == set(inputs):
+                # Perfect match on the inputs
                 return 2
         # No match
         return 0
             # find the permutation of the current input list so it matches
             # the stored one
             inputs = widget.getdeepattr(self.inputListField.name)
-            encoded = self.encode(inputs)
-            stored = context.values[self.inputListField.name]
+            _, encoded = self.encode(widget, inputs)
+            _, stored = context.values[self.inputListField.name]
 
             def uuids(seq):
                 return [uuid for _, _, uuid in seq]
 
         if self.inputListField:
             inputs = self.encode(
-                widget.getdeepattr(self.inputListField.name))
+                widget, widget.getdeepattr(self.inputListField.name))
             context.values[self.inputListField.name] = inputs
 
         for field in self.fields: