Commit 782602e5 authored by Philipp Hörist's avatar Philipp Hörist

Settings: Add default_text argument for bind_signal()

default_text is returned if the value of the setting is an empty string
parent 2e1252c4
......@@ -104,14 +104,15 @@ class _Settings:
func_name,
account=None,
jid=None,
inverted=False):
inverted=False,
default_text=None):
callbacks = self._callbacks[(setting, account, jid)]
func = getattr(widget, func_name)
callbacks.append((func, inverted))
callbacks.append((func, inverted, default_text))
def _on_destroy(*args):
callbacks.remove((func, inverted))
callbacks.remove((func, inverted, default_text))
widget.connect('destroy', _on_destroy)
......@@ -121,10 +122,13 @@ class _Settings:
callbacks = self._callbacks[(setting, account, jid)]
for func in list(callbacks):
if isinstance(func, tuple):
func, inverted = func
if inverted:
func, inverted, default_text = func
if isinstance(value, bool) and inverted:
value = not value
if value == '' and default_text is not None:
value = default_text
try:
func(value)
except Exception:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment