diff --git a/picard/ui/options/plugins.py b/picard/ui/options/plugins.py index 64502568f..11eacc1cc 100644 --- a/picard/ui/options/plugins.py +++ b/picard/ui/options/plugins.py @@ -42,6 +42,8 @@ from picard.const import ( USER_PLUGIN_DIR, ) +from picard.util import reconnect + from picard.ui import HashableTreeWidgetItem from picard.ui.options import ( OptionsPage, @@ -427,18 +429,6 @@ class PluginsOptionsPage(OptionsPage): log.debug("Plugin %r enabled: %r", item.plugin.name, item.is_enabled) update_text() - def reconnect(signal, newhandler=None, oldhandler=None): - while True: - try: - if oldhandler is not None: - signal.disconnect(oldhandler) - else: - signal.disconnect() - except TypeError: - break - if newhandler is not None: - signal.connect(newhandler) - reconnect(item.button_enable.clicked, toggle_enable) install_enabled = not item.is_installed or bool(item.new_version) diff --git a/picard/util/__init__.py b/picard/util/__init__.py index 4dda00509..c97fec387 100644 --- a/picard/util/__init__.py +++ b/picard/util/__init__.py @@ -546,3 +546,23 @@ def compare_version_tuples(version1, version2): if test1[x] != test2[x]: return 1 if test1[x] < test2[x] else -1 return 0 + + +def reconnect(signal, newhandler=None, oldhandler=None): + """ + Reconnect an handler to a signal + + It disconnects all previous handlers before connecting new one + + Credits: https://stackoverflow.com/a/21589403 + """ + while True: + try: + if oldhandler is not None: + signal.disconnect(oldhandler) + else: + signal.disconnect() + except TypeError: + break + if newhandler is not None: + signal.connect(newhandler)