[orca] Ensure a script only registers one signal handler for clipboard changes



commit 13114330b73fce54132bd01469642f6f487aef39
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Tue Jun 7 05:33:26 2016 -0400

    Ensure a script only registers one signal handler for clipboard changes

 src/orca/script_utilities.py |   14 +++++++++++++-
 src/orca/scripts/default.py  |    4 ++++
 2 files changed, 17 insertions(+), 1 deletions(-)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index 7b4b7df..4b93e55 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -97,6 +97,7 @@ class Utilities:
 
         self._script = script
         self._activeProgressBars = {}
+        self._clipboardHandlerId = None
 
     #########################################################################
     #                                                                       #
@@ -3704,8 +3705,19 @@ class Utilities:
         script.onClipboardContentsChanged(*args)
 
     def connectToClipboard(self):
+        if self._clipboardHandlerId is not None:
+            return
+
+        clipboard = Gtk.Clipboard.get(Gdk.Atom.intern("CLIPBOARD", False))
+        self._clipboardHandlerId = clipboard.connect(
+            'owner-change', self.onClipboardContentsChanged)
+
+    def disconnectFromClipboard(self):
+        if self._clipboardHandlerId is None:
+            return
+
         clipboard = Gtk.Clipboard.get(Gdk.Atom.intern("CLIPBOARD", False))
-        clipboard.connect('owner-change', self.onClipboardContentsChanged)
+        clipboard.disconnect(self._clipboardHandlerId)
 
     def getClipboardContents(self):
         clipboard = Gtk.Clipboard.get(Gdk.Atom.intern("CLIPBOARD", False))
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index bb9266c..f24f1b4 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -722,6 +722,10 @@ class Script(script.Script):
         super().registerEventListeners()
         self.utilities.connectToClipboard()
 
+    def deregisterEventListeners(self):
+        super().deregisterEventListeners()
+        self.utilities.disconnectFromClipboard()
+
     def _saveFocusedObjectInfo(self, obj):
         """Saves some basic information about obj. Note that this method is
         intended to be called primarily (if not only) by locusOfFocusChanged().


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]