Skip to content
Snippets Groups Projects
Commit 3befd602 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Settings: Allow bind_signal() to be inverted

parent 7cfe520a
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,6 @@
from collections import namedtuple
from collections import defaultdict
from gi.module import FunctionInfo
from gi.repository import GLib
from gajim import IS_PORTABLE
......@@ -93,19 +92,26 @@ def connect_signal(self, setting, func, account=None, jid=None):
def disconnect_signals(self, object_):
for _, handlers in self._callbacks.items():
for handler in list(handlers):
if isinstance(handler, FunctionInfo):
if isinstance(handler, tuple):
continue
func = handler()
if func is None or func.__self__ is object_:
handlers.remove(handler)
def bind_signal(self, setting, widget, func_name, account=None, jid=None):
def bind_signal(self,
setting,
widget,
func_name,
account=None,
jid=None,
inverted=False):
callbacks = self._callbacks[(setting, account, jid)]
func = getattr(widget, func_name)
callbacks.append(func)
callbacks.append((func, inverted))
def _on_destroy(*args):
callbacks.remove(func)
callbacks.remove((func, inverted))
widget.connect('destroy', _on_destroy)
......@@ -114,7 +120,11 @@ def _notify(self, value, setting, account=None, jid=None):
callbacks = self._callbacks[(setting, account, jid)]
for func in list(callbacks):
if isinstance(func, FunctionInfo):
if isinstance(func, tuple):
func, inverted = func
if inverted:
value = not value
try:
func(value)
except Exception:
......
......@@ -195,16 +195,17 @@ def _bind_sensitive_state(self):
if self.bind is None:
return
app.settings.connect_signal(self.bind,
self._on_setting_changed,
account=self.account)
value = app.settings.get_account_setting(self.account, self.bind)
if self.inverted:
value = not value
self.set_sensitive(value)
app.settings.bind_signal(self.bind,
self,
'set_sensitive',
account=self.account,
inverted=self.inverted)
if self.account is not None:
value = app.settings.get_account_setting(self.account, self.bind)
else:
value = app.settings.get(self.bind)
def _on_setting_changed(self, value, *args):
if self.inverted:
value = not value
self.set_sensitive(value)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment