From f82a109c1db0497e62f22bace42f6ccf8db30821 Mon Sep 17 00:00:00 2001 From: Rui Matos Date: Thu, 7 Nov 2013 21:39:47 +0100 Subject: [PATCH 3/6] Add a way to reload tweaks when there are changes after startup --- gtweak/tweakmodel.py | 7 +++++++ gtweak/tweakview.py | 30 ++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/gtweak/tweakmodel.py b/gtweak/tweakmodel.py index faa920b..0fa3053 100644 --- a/gtweak/tweakmodel.py +++ b/gtweak/tweakmodel.py @@ -90,6 +90,7 @@ class TweakGroup: def __init__(self, name, *tweaks): self.name = name self.tweaks = [] + self.model = None self._sg = Gtk.SizeGroup(mode=Gtk.SizeGroupMode.HORIZONTAL) self._sg.props.ignore_hidden = True @@ -165,6 +166,12 @@ class TweakModel(Gtk.ListStore): _iter = self.append([gettext(tweakgroup.name), tweakgroup]) self._tweak_group_names[tweakgroup.name] = tweakgroup self._tweak_group_iters[tweakgroup.name] = _iter + tweakgroup.model = self + + def tweaks_changed(self, group): + _iter = self._tweak_group_iters[group.name] + _path = self.get_path(_iter) + self.row_changed(_path, _iter) def add_tweak_auto_to_group(self, tweak): if not tweak.loaded: diff --git a/gtweak/tweakview.py b/gtweak/tweakview.py index ac8ae45..9de821c 100644 --- a/gtweak/tweakview.py +++ b/gtweak/tweakview.py @@ -73,14 +73,40 @@ class TweakView: ctx.add_provider (provider,6000) #add all tweaks + self._tweak_set = set() self._tweak_vbox = builder.get_object('tweak_vbox') + self.reload_tweaks() + + self._model.connect('row-changed', self._on_model_row_changed) + + #dict of pending notifications, the key is the function to be called + self._notification_functions = {} + + def reload_tweaks(self): + new_tweak_set = set() + for t in sorted(self._model.tweaks, key=_sort_tweak_widgets_by_widget_type): + new_tweak_set.add(t) + if t in self._tweak_set: + continue + t.main_window = self._main_window self._tweak_vbox.pack_start(t.widget, False, False, 0) t.set_notify_cb(self._on_tweak_notify) - #dict of pending notifications, the key is the function to be called - self._notification_functions = {} + self._tweak_set.add(t) + + for t in self._tweak_set - new_tweak_set: + self._tweak_vbox.remove(t.widget) + + self._tweak_set = new_tweak_set + + def _on_model_row_changed(self, model, path, titer): + model, selected = self.treeview.get_selection().get_selected_rows() + self.select_none() + self.reload_tweaks() + if len(selected) > 0: + self.treeview.get_selection().select_path(selected[0]) def run(self): self._main_window.show_all() -- 1.8.3.1