From fc8917f6d20205a11cd8d8ab3161b236929cb2a9 Mon Sep 17 00:00:00 2001 From: Richard Taylor Date: Wed, 5 Aug 2009 18:29:21 +0000 Subject: [PATCH] Fix for OS X Scratchpad issue 3089: clipboard broken in Mac port svn: r12882 --- src/ScratchPad.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/ScratchPad.py b/src/ScratchPad.py index 3dc0d5c80..503445f9e 100644 --- a/src/ScratchPad.py +++ b/src/ScratchPad.py @@ -51,6 +51,7 @@ import DateHandler import GrampsDisplay import ManagedWindow from TransUtils import sgettext as _ +from Utils import mac from glade import Glade from DdTargets import DdTargets @@ -1086,15 +1087,35 @@ class ScratchPadListView(object): return # Find a wrapper class - possible_wrappers = [target for target in context.targets \ - if target in self._target_type_to_wrapper_class_map] + possible_wrappers = [] + if mac(): + # context is empty on mac due to a bug, work around this + # Note that this workaround code works fine in linux too as + # we know very well inside of GRAMPS what sel_data can be, so + # we can anticipate on it, instead of letting the wrapper handle + # it. This is less clean however ! + # See http://www.gramps-project.org/bugs/view.php?id=3089 for + # an explaination of why this is required. + dragtype = None + try: + dragtype = pickle.loads(sel_data)[0] + except pickle.UnpicklingError, msg : + # not a pickled object, probably text + if isinstance(sel_data, basestring): + dragtype = DdTargets.TEXT.drag_type + if dragtype in self._target_type_to_wrapper_class_map: + possible_wrappers = [dragtype] + else: + possible_wrappers = [target for target in context.targets \ + if target in self._target_type_to_wrapper_class_map] if len(possible_wrappers) == 0: # No wrapper for this class return # Just select the first match. - wrapper_class = self._target_type_to_wrapper_class_map[str(possible_wrappers[0])] + wrapper_class = self._target_type_to_wrapper_class_map[ + str(possible_wrappers[0])] o = wrapper_class(self.dbstate,sel_data) # try: