mirror of
https://github.com/libratbag/piper.git
synced 2026-04-25 16:58:34 -04:00
RatbagdDevice: add active_profile property
This commit is contained in:
committed by
Peter Hutterer
parent
da3efd0374
commit
04b69f0eef
@@ -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))
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user