diff --git a/app/ui/__init__.py b/app/ui/__init__.py index df4af34e..a7cd2491 100644 --- a/app/ui/__init__.py +++ b/app/ui/__init__.py @@ -76,6 +76,10 @@ def error(window, title, text): m.destroy() +def remove_children(container): + container.foreach(lambda x, _: container.remove(x), None) + + # def find_children(container, *child_names): # assert container is not None # assert isinstance(container, Gtk.Container) diff --git a/app/ui/config_panel.py b/app/ui/config_panel.py index 77412f23..e5f76563 100644 --- a/app/ui/config_panel.py +++ b/app/ui/config_panel.py @@ -6,6 +6,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera from gi.repository import Gtk, GObject +import ui from logitech.unifying_receiver import settings as _settings # @@ -150,6 +151,15 @@ def _update_setting_item(sbox, value): raise NotImplemented control.set_sensitive(True) +# +# +# + +def create(): + b = Gtk.VBox(homogeneous=False, spacing=4) + b.set_property('margin', 8) + return b + def update(frame): box = frame._config_box @@ -159,7 +169,7 @@ def update(frame): if device is None: # remove all settings widgets # if another device gets paired here, it will add its own widgets - box.foreach(lambda x, _: box.remove(x), None) + ui.remove_children(box) return if not box.get_visible(): @@ -172,15 +182,12 @@ def update(frame): force_read = False items = box.get_children() - if not items: + if len(device.settings) != len(items): + ui.remove_children(box) if device.status: items = list(_add_settings(box, device)) assert len(device.settings) == len(items) force_read = True - else: - # don't bother adding settings for offline devices, - # they're useless and might not guess all of them anyway - return device_active = bool(device.status) # if the device just became active, re-read the settings diff --git a/app/ui/main_window.py b/app/ui/main_window.py index 2a2ef6c7..1765835e 100644 --- a/app/ui/main_window.py +++ b/app/ui/main_window.py @@ -218,10 +218,8 @@ def _make_device_box(index): vbox.pack_start(Gtk.HSeparator(), False, False, 0) vbox.pack_start(info_label, False, False, 0) - config_box = Gtk.VBox(homogeneous=False, spacing=4) - config_box.set_property('margin', 8) - vbox.pack_start(config_box, False, False, 0) - frame._config_box = config_box + frame._config_box = _config_panel.create() + vbox.pack_start(frame._config_box, False, False, 0) unpair = Gtk.Button('Unpair') unpair.set_image(Gtk.Image.new_from_icon_name('edit-delete', Gtk.IconSize.BUTTON))