From 3f030242593d99157a20e9fe4133178d4bf73dee Mon Sep 17 00:00:00 2001 From: Yaroslav Chvanov Date: Sun, 5 Mar 2023 14:55:30 +0300 Subject: [PATCH] mouseperspective: update profile list when a profile is set to active This fixes profile list becoming wrong when you change active profile with ratbagctl. --- piper/mouseperspective.py | 16 ++++++++++------ piper/profilerow.py | 4 ++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/piper/mouseperspective.py b/piper/mouseperspective.py index 90373f4..be0aa80 100644 --- a/piper/mouseperspective.py +++ b/piper/mouseperspective.py @@ -83,10 +83,6 @@ class MousePerspective(Gtk.Overlay): self._set_profile(active_profile) self.button_profile.set_visible(len(device.profiles) > 1) - name = active_profile.name - if not name: - name = f"Profile {active_profile.index}" - self.label_profile.set_label(name) # Find the first profile that is enabled. If there is none, disable the # add button. @@ -103,12 +99,21 @@ class MousePerspective(Gtk.Overlay): ) row = ProfileRow(profile) self.listbox_profiles.insert(row, profile.index) - if profile is active_profile: + + self._select_profile_row(self._profile) + + def _select_profile_row(self, profile: RatbagdProfile) -> None: + for row in self.listbox_profiles.get_children(): + if row.profile is profile: self.listbox_profiles.select_row(row) + self.label_profile.set_label(row.name) + break def _set_profile(self, profile: RatbagdProfile) -> None: assert self._device is not None + self._select_profile_row(profile) + self._profile = profile self.stack.foreach(Gtk.Widget.destroy) @@ -165,7 +170,6 @@ class MousePerspective(Gtk.Overlay): self, listbox: Gtk.ListBox, row: Gtk.ListBoxRow ) -> None: row.set_active() - self.label_profile.set_label(row.name) @Gtk.Template.Callback("_on_add_profile_button_clicked") def _on_add_profile_button_clicked(self, button: Gtk.Button) -> None: diff --git a/piper/profilerow.py b/piper/profilerow.py index 3e0f2c4..f20c4c8 100644 --- a/piper/profilerow.py +++ b/piper/profilerow.py @@ -51,3 +51,7 @@ class ProfileRow(Gtk.ListBoxRow): @GObject.Property def name(self) -> str: return self.title.get_text() + + @GObject.Property + def profile(self) -> RatbagdProfile: + return self._profile