diff options
-rw-r--r-- | ranger/ext/signal_dispatcher.py | 23 | ||||
-rw-r--r-- | test/tc_signal.py | 7 |
2 files changed, 23 insertions, 7 deletions
diff --git a/ranger/ext/signal_dispatcher.py b/ranger/ext/signal_dispatcher.py index 2762493b..11e9c955 100644 --- a/ranger/ext/signal_dispatcher.py +++ b/ranger/ext/signal_dispatcher.py @@ -15,6 +15,7 @@ import re import weakref +from types import MethodType class Signal(dict): stopped = False @@ -48,9 +49,17 @@ class SignalDispatcher(object): handlers = self._signals[signal_name] except: handlers = self._signals[signal_name] = [] - nargs = function.__code__.co_argcount - hasattr(function, 'im_func') - if weak: - function = weakref.proxy(function) + nargs = function.__code__.co_argcount + + try: + instance = function.__self__ + except: + if weak: + function = weakref.proxy(function) + else: + nargs -= 1 + if weak: + function = (function.__func__, weakref.proxy(function.__self__)) handler = SignalHandler(signal_name, function, priority, nargs > 0) handlers.append(handler) handlers.sort(key=lambda handler: -handler.priority) @@ -82,10 +91,14 @@ class SignalDispatcher(object): for handler in tuple(handlers): if handler.active: try: + if isinstance(handler.function, tuple): + fnc = MethodType(*handler.function) + else: + fnc = handler.function if handler.pass_signal: - handler.function(signal) + fnc(signal) else: - handler.function() + fnc() if signal.stopped: return except ReferenceError: diff --git a/test/tc_signal.py b/test/tc_signal.py index 639cf7c3..ad04beab 100644 --- a/test/tc_signal.py +++ b/test/tc_signal.py @@ -119,13 +119,16 @@ class TestSignal(unittest.TestCase): self.assertEqual('a', ''.join(alphabet)) sd.signal_bind('mysignal', foo.calc, weak=True) - del foo + print("jambo") sd.signal_emit('mysignal') self.assertEqual('ab', ''.join(alphabet)) self.assertFalse(is_deleted[0]) - del calc + del foo + + sd.signal_emit('mysignal') + self.assertEqual('ab', ''.join(alphabet)) self.assertTrue(is_deleted[0]) |