Philipp Hörist pushed to branch master at gajim / gajim
Commits: a8ee4a71 by lovetox at 2020-09-05T00:32:08+02:00 Remove print statement
- - - - - 86767c0f by lovetox at 2020-09-05T16:40:35+02:00 Settings: Bind sensitive state to setting signal
- - - - -
4 changed files:
- gajim/common/settings.py - gajim/gtk/accounts.py - gajim/gtk/const.py - gajim/gtk/settings.py
Changes:
===================================== gajim/common/settings.py ===================================== @@ -93,7 +93,6 @@ class _Settings: for handler in list(handlers): func = handler() if func is None or func.__self__ is object_: - print('remove handler', handler) handlers.remove(handler)
def _notify(self, value, setting, account=None, jid=None):
===================================== gajim/gtk/accounts.py ===================================== @@ -610,6 +610,8 @@ class GeneralPage(GenericSettingPage): desc=_('Recognize your account by color')),
Setting(SettingKind.LOGIN, _('Login'), SettingType.DIALOG, + bind='anonymous_auth', + inverted=True, props={'dialog': LoginDialog}),
Setting(SettingKind.ACTION, _('Import Contacts'), @@ -800,12 +802,15 @@ class PriorityDialog(SettingsDialog):
settings = [ Setting(SettingKind.SWITCH, _('Adjust to status'), - SettingType.ACCOUNT_CONFIG, 'adjust_priority_with_status', - 'adjust'), + SettingType.ACCOUNT_CONFIG, + 'adjust_priority_with_status'),
Setting(SettingKind.SPIN, _('Priority'), - SettingType.ACCOUNT_CONFIG, 'priority', - enabledif=('adjust', False), props={'range_': range_}), + SettingType.ACCOUNT_CONFIG, + 'priority', + bind='adjust_priority_with_status', + inverted=True, + props={'range_': range_}), ]
SettingsDialog.__init__(self, parent, _('Priority'), @@ -830,19 +835,19 @@ class CutstomHostnameDialog(SettingsDialog): settings = [ Setting(SettingKind.SWITCH, _('Enable'), SettingType.ACCOUNT_CONFIG, - 'use_custom_host', name='custom'), + 'use_custom_host'),
Setting(SettingKind.ENTRY, _('Hostname'), SettingType.ACCOUNT_CONFIG, 'custom_host', - enabledif=('custom', True)), + bind='use_custom_host'),
Setting(SettingKind.ENTRY, _('Port'), SettingType.ACCOUNT_CONFIG, 'custom_port', - enabledif=('custom', True)), + bind='use_custom_host'),
Setting(SettingKind.COMBO, _('Type'), SettingType.ACCOUNT_CONFIG, 'custom_type', - enabledif=('custom', True), + bind='use_custom_host', props={'combo_items': type_values}), ]
@@ -871,11 +876,11 @@ class LoginDialog(SettingsDialog):
settings = [ Setting(SettingKind.ENTRY, _('Password'), - SettingType.ACCOUNT_CONFIG, 'password', name='password', - enabledif=('savepass', True)), + SettingType.ACCOUNT_CONFIG, 'password', + bind='savepass'),
Setting(SettingKind.SWITCH, _('Save Password'), - SettingType.ACCOUNT_CONFIG, 'savepass', name='savepass'), + SettingType.ACCOUNT_CONFIG, 'savepass'),
Setting(SettingKind.CHANGEPASSWORD, _('Change Password'), SettingType.DIALOG, callback=self.on_password_change,
===================================== gajim/gtk/const.py ===================================== @@ -22,7 +22,7 @@ from enum import unique Filter = namedtuple('Filter', 'name pattern default')
Setting = namedtuple('Setting', 'kind label type value name callback data desc ' - 'enabledif enabled_func props') + 'bind inverted enabled_func props') Setting.__new__.__defaults__ = (None,) * len(Setting._fields) # type: ignore
@unique
===================================== gajim/gtk/settings.py ===================================== @@ -17,7 +17,6 @@ from gi.repository import Gtk from gi.repository import GLib from gi.repository import Gdk -from gi.repository import GObject from gi.repository import Pango
from gajim.common import app @@ -114,7 +113,7 @@ class SettingsBox(Gtk.ListBox): self.account, *setting[1:-1], **setting.props) else: listitem = self.map[setting.kind](self.account, *setting[1:-1]) - listitem.connect('notify::setting-value', self.on_setting_changed) + if setting.name is not None: self.named_settings[setting.name] = listitem self.add(listitem) @@ -123,28 +122,23 @@ class SettingsBox(Gtk.ListBox): return self.named_settings[name]
def update_states(self): - values = [] - values.append((None, None)) - for row in self.get_children(): - name = row.name - if name is None: - continue - value = row.get_property('setting-value') - values.append((name, value)) - - for name, value in values: - for row in self.get_children(): - row.update_activatable(name, value) - - def on_setting_changed(self, widget, *args): - value = widget.get_property('setting-value') for row in self.get_children(): - row.update_activatable(widget.name, value) + row.update_activatable()
class GenericSetting(Gtk.ListBoxRow): - def __init__(self, account, label, type_, value, - name, callback, data, desc, enabledif, enabled_func): + def __init__(self, + account, + label, + type_, + value, + name, + callback, + data, + desc, + bind, + inverted, + enabled_func): Gtk.ListBoxRow.__init__(self) self._grid = Gtk.Grid() self._grid.set_size_request(-1, 30) @@ -157,7 +151,8 @@ class GenericSetting(Gtk.ListBoxRow): self.label = label self.account = account self.name = name - self.enabledif = enabledif + self.bind = bind + self.inverted = inverted self.enabled_func = enabled_func self.setting_value = self.get_value()
@@ -193,16 +188,26 @@ class GenericSetting(Gtk.ListBoxRow): self._grid.add(self.setting_box) self.add(self._grid)
- def do_get_property(self, prop): - if prop.name == 'setting-value': - return self.setting_value - raise AttributeError('unknown property %s' % prop.name) + self.connect('destroy', self._on_destroy) + self._bind_sensitive_state()
- def do_set_property(self, prop, value): - if prop.name == 'setting-value': - self.setting_value = value - else: - raise AttributeError('unknown property %s' % prop.name) + 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) + + def _on_setting_changed(self, value, *args): + if self.inverted: + value = not value + self.set_sensitive(value)
def get_value(self): return self.__get_value(self.type_, self.value, self.account) @@ -249,8 +254,6 @@ class GenericSetting(Gtk.ListBoxRow): if self.callback is not None: self.callback(state, self.data)
- self.set_property('setting-value', state) - @staticmethod def set_no_log_for(account, state): no_log = app.settings.get_account_setting(account, 'no_log_for').split() @@ -265,25 +268,20 @@ class GenericSetting(Gtk.ListBoxRow): def on_row_activated(self): raise NotImplementedError
- def update_activatable(self, name, value): - enabled_func_value = True - if self.enabled_func is not None: - enabled_func_value = self.enabled_func() + def update_activatable(self): + if self.enabled_func is None: + return
- enabledif_value = True - if self.enabledif is not None and self.enabledif[0] == name: - enabledif_value = (name, value) == self.enabledif + enabled_func_value = self.enabled_func() + self.set_activatable(enabled_func_value) + self.set_sensitive(enabled_func_value)
- self.set_activatable(enabled_func_value and enabledif_value) - self.set_sensitive(enabled_func_value and enabledif_value) + def _on_destroy(self, *args): + if self.bind is not None: + app.settings.disconnect_signals(self)
class SwitchSetting(GenericSetting): - - __gproperties__ = { - "setting-value": (bool, 'Switch Value', '', False, - GObject.ParamFlags.READWRITE),} - def __init__(self, *args): GenericSetting.__init__(self, *args)
@@ -327,11 +325,6 @@ class SwitchSetting(GenericSetting):
class EntrySetting(GenericSetting): - - __gproperties__ = { - "setting-value": (str, 'Entry Value', '', '', - GObject.ParamFlags.READWRITE),} - def __init__(self, *args): GenericSetting.__init__(self, *args)
@@ -358,12 +351,6 @@ class EntrySetting(GenericSetting):
class ColorSetting(GenericSetting): - - __gproperties__ = { - "setting-value": (str, 'Color Value', '', '', - GObject.ParamFlags.READWRITE), - } - def __init__(self, *args): GenericSetting.__init__(self, *args)
@@ -389,11 +376,6 @@ class ColorSetting(GenericSetting):
class DialogSetting(GenericSetting): - - __gproperties__ = { - "setting-value": (str, 'Dummy', '', '', - GObject.ParamFlags.READWRITE),} - def __init__(self, *args, dialog): GenericSetting.__init__(self, *args) self.dialog = dialog @@ -422,11 +404,6 @@ class DialogSetting(GenericSetting):
class SpinSetting(GenericSetting): - - __gproperties__ = { - "setting-value": (int, 'Priority', '', -128, 127, 0, - GObject.ParamFlags.READWRITE),} - def __init__(self, *args, range_): GenericSetting.__init__(self, *args)
@@ -460,11 +437,6 @@ class SpinSetting(GenericSetting):
class FileChooserSetting(GenericSetting): - - __gproperties__ = { - "setting-value": (str, 'Certificate Path', '', '', - GObject.ParamFlags.READWRITE),} - def __init__(self, *args, filefilter): GenericSetting.__init__(self, *args)
@@ -510,11 +482,6 @@ class FileChooserSetting(GenericSetting):
class CallbackSetting(GenericSetting): - - __gproperties__ = { - "setting-value": (str, 'Dummy', '', '', - GObject.ParamFlags.READWRITE),} - def __init__(self, *args, callback): GenericSetting.__init__(self, *args) self.callback = callback @@ -525,11 +492,6 @@ class CallbackSetting(GenericSetting):
class ActionSetting(GenericSetting): - - __gproperties__ = { - "setting-value": (str, 'Dummy', '', '', - GObject.ParamFlags.READWRITE),} - def __init__(self, *args, account): GenericSetting.__init__(self, *args) action_name = '%s%s' % (account, self.value) @@ -556,18 +518,8 @@ class LoginSetting(DialogSetting): jid = app.get_jid_from_account(self.account) return jid
- def update_activatable(self, name, value): - super().update_activatable(name, value) - anonym = app.settings.get_account_setting(self.account, 'anonymous_auth') - self.set_activatable(not anonym) -
class PopoverSetting(GenericSetting): - - __gproperties__ = { - "setting-value": (str, 'Dummy', '', '', - GObject.ParamFlags.READWRITE),} - def __init__(self, *args, entries): GenericSetting.__init__(self, *args)
@@ -650,11 +602,6 @@ class PopoverRow(Gtk.ListBoxRow):
class ComboSetting(GenericSetting): - - __gproperties__ = { - "setting-value": (str, 'Proxy', '', '', - GObject.ParamFlags.READWRITE),} - def __init__(self, *args, combo_items): GenericSetting.__init__(self, *args)
@@ -683,11 +630,6 @@ class ComboSetting(GenericSetting):
class ProxyComboSetting(GenericSetting): - - __gproperties__ = { - "setting-value": (str, 'Proxy', '', '', - GObject.ParamFlags.READWRITE),} - def __init__(self, *args): GenericSetting.__init__(self, *args)
@@ -756,7 +698,8 @@ class CutstomHostnameSetting(DialogSetting): DialogSetting.__init__(self, *args, **kwargs)
def get_setting_value(self): - custom = app.settings.get_account_setting(self.account, 'use_custom_host') + custom = app.settings.get_account_setting(self.account, + 'use_custom_host') return Q_('?switch:On') if custom else Q_('?switch:Off')
@@ -768,7 +711,7 @@ class ChangePasswordSetting(DialogSetting): parent.destroy() open_window('ChangePassword', account=self.account)
- def update_activatable(self, name, value): + def update_activatable(self): activatable = False if self.account in app.connections: con = app.connections[self.account]
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/f328789220f19abde2d9b201cec24811...