diff --git a/piper/ledspage.py b/piper/ledspage.py index 46c49af..0f2b9b5 100644 --- a/piper/ledspage.py +++ b/piper/ledspage.py @@ -42,7 +42,7 @@ class LedsPage(Gtk.Box): self._init_ui() def _init_ui(self): - profile = self._find_active_profile() + profile = self._device.active_profile mousemap = MouseMap("#Leds", self._device, spacing=20, border_width=20) self.pack_start(mousemap, True, True, 0) @@ -57,12 +57,6 @@ class LedsPage(Gtk.Box): mousemap.add(button, "#led{}".format(index)) sizegroup.add_widget(button) - def _find_active_profile(self): - # Finds the active profile, which is guaranteed to be found. - for profile in self._device.profiles: - if profile.is_active: - return profile - def _on_led_mode_changed(self, led, pspec, button): mode = self._mode_to_string(led.mode) button.set_label("LED {}: {}".format(led.index, mode)) diff --git a/piper/ratbagd.py b/piper/ratbagd.py index a341952..97cb9a7 100644 --- a/piper/ratbagd.py +++ b/piper/ratbagd.py @@ -293,6 +293,14 @@ class RatbagdDevice(_RatbagdDBus): """A list of RatbagdProfile objects provided by this device.""" return self._profiles + @GObject.Property + def active_profile(self): + """The currently active profile. This is a non-DBus property computed + over the cached list of profiles.""" + for profile in self._profiles: + if profile.is_active: + return profile + def get_svg(self, theme): """Gets the full path to the SVG for the given theme, or the empty string if none is available. diff --git a/piper/resolutionspage.py b/piper/resolutionspage.py index ecc1881..02421e3 100644 --- a/piper/resolutionspage.py +++ b/piper/resolutionspage.py @@ -53,7 +53,7 @@ class ResolutionsPage(Gtk.Box): self._init_ui() def _init_ui(self): - profile = self._find_active_profile() + profile = self._device.active_profile mousemap = MouseMap("#Buttons", self._device, spacing=20, border_width=20) self.pack_start(mousemap, True, True, 0) @@ -75,19 +75,13 @@ class ResolutionsPage(Gtk.Box): self.listbox.insert(row, resolution.index) def _on_report_rate_toggled(self, button, rate): - profile = self._find_active_profile() # TODO: currently no devices expose CAP_INDIVIDUAL_REPORT_RATE, but if # so then we should check for this here and set it only on the relevant # resolution. + profile = self._device.active_profile for resolution in profile.resolutions: resolution.report_rate = rate - def _find_active_profile(self): - # Finds the active profile, which is guaranteed to be found. - for profile in self._device.profiles: - if profile.is_active: - return profile - def _find_active_resolution(self, profile): # Finds the active resolution in the given profile, which is guaranteed # to be found. diff --git a/piper/window.py b/piper/window.py index 484159e..c8fdb82 100644 --- a/piper/window.py +++ b/piper/window.py @@ -160,9 +160,3 @@ class Window(Gtk.ApplicationWindow): # so that we can reset the sensitivity of the add button. if not profile.enabled and profile == self._device.profiles[-1]: self.add_profile_button.set_sensitive(True) - - def _find_active_profile(self): - # Finds the active profile, which is guaranteed to be found. - for profile in self._device.profiles: - if profile.is_active: - return profile