From cdd1be7095a22091350bd7ebec6538ea8d0796eb Mon Sep 17 00:00:00 2001 From: Yaroslav Chvanov Date: Sat, 4 Mar 2023 17:43:24 +0300 Subject: [PATCH] Move report rate changing from ResolutionsPage to AdvancedPage Not a setting people change often and it's also just weird to have it together with resolutions. --- data/ui/AdvancedPage.ui | 126 +++++++++++++++++++++++++++++++- data/ui/ResolutionsPage.ui | 146 ------------------------------------- piper/advancedpage.py | 38 ++++++++++ piper/resolutionspage.py | 43 ----------- 4 files changed, 162 insertions(+), 191 deletions(-) diff --git a/data/ui/AdvancedPage.ui b/data/ui/AdvancedPage.ui index 8d4b4ce..e45779a 100644 --- a/data/ui/AdvancedPage.ui +++ b/data/ui/AdvancedPage.ui @@ -19,6 +19,128 @@ center vertical 20 + + + True + False + center + 20 + + + True + False + end + Report rate + right + False + + + + False + True + 0 + + + + + True + False + Change the profile’s report rate + True + expand + + + 125 + True + True + False + False + rate_250 + + + True + True + 0 + + + + + 250 + True + True + False + False + rate_125 + + + True + True + 1 + + + + + 500 + True + True + False + False + rate_125 + + + True + True + 2 + + + + + 1000 + True + True + False + False + rate_125 + + + True + True + 3 + + + + + False + True + 1 + + + + + True + False + start + Hz + False + + + + False + True + 2 + + + + + False + True + 0 + + True @@ -74,7 +196,7 @@ False True - 0 + 1 @@ -116,7 +238,7 @@ False True - 1 + 2 diff --git a/data/ui/ResolutionsPage.ui b/data/ui/ResolutionsPage.ui index 02c2bd9..9f7807c 100644 --- a/data/ui/ResolutionsPage.ui +++ b/data/ui/ResolutionsPage.ui @@ -12,152 +12,6 @@ False 20 vertical - - - True - False - 0 - none - - - True - False - center - 12 - 12 - 12 - 12 - 20 - - - True - False - end - Report rate - right - False - - - - False - True - 0 - - - - - True - False - Change the profile’s report rate - True - expand - - - 125 - True - True - False - False - rate_250 - - - True - True - 0 - - - - - 250 - True - True - False - False - rate_125 - - - True - True - 1 - - - - - 500 - True - True - False - False - rate_125 - - - True - True - 2 - - - - - 1000 - True - True - False - True - False - rate_125 - - - True - True - 3 - - - - - False - True - 1 - - - - - True - False - start - Hz - False - - - - False - True - 2 - - - - - - - True - False - Sensitivity - False - - - - - - - - False - True - 0 - - True diff --git a/piper/advancedpage.py b/piper/advancedpage.py index 39e3e49..8648e56 100644 --- a/piper/advancedpage.py +++ b/piper/advancedpage.py @@ -19,6 +19,11 @@ class AdvancedPage(Gtk.Box): angle_snapping: Gtk.Switch = Gtk.Template.Child() # type: ignore debounce: Gtk.ComboBox = Gtk.Template.Child() # type: ignore + rate_1000: Gtk.RadioButton = Gtk.Template.Child() # type: ignore + rate_125: Gtk.RadioButton = Gtk.Template.Child() # type: ignore + rate_250: Gtk.RadioButton = Gtk.Template.Child() # type: ignore + rate_500: Gtk.RadioButton = Gtk.Template.Child() # type: ignore + rate_button_box: Gtk.ButtonBox = Gtk.Template.Child() # type: ignore def __init__( self, device: RatbagdDevice, profile: RatbagdProfile, *args, **kwargs @@ -35,6 +40,33 @@ class AdvancedPage(Gtk.Box): "state-set", self._on_snapping_state_set ) + self.rate_125.set_active(profile.report_rate == 125) + self.rate_250.set_active(profile.report_rate == 250) + self.rate_500.set_active(profile.report_rate == 500) + self.rate_1000.set_active(profile.report_rate == 1000) + + are_report_rates_supported = ( + profile.report_rate != 0 and len(profile.report_rates) != 0 + ) + self.rate_button_box.set_sensitive(are_report_rates_supported) + self.rate_125.set_sensitive(125 in profile.report_rates) + self.rate_250.set_sensitive(250 in profile.report_rates) + self.rate_500.set_sensitive(500 in profile.report_rates) + self.rate_1000.set_sensitive(1000 in profile.report_rates) + + self._handler_125 = self.rate_125.connect( + "toggled", self._on_report_rate_toggled, 125 + ) + self._handler_250 = self.rate_250.connect( + "toggled", self._on_report_rate_toggled, 250 + ) + self._handler_500 = self.rate_500.connect( + "toggled", self._on_report_rate_toggled, 500 + ) + self._handler_1000 = self.rate_1000.connect( + "toggled", self._on_report_rate_toggled, 1000 + ) + profile = self._profile self._mousemap = MouseMap("#Buttons", device, spacing=20, border_width=20) @@ -71,3 +103,9 @@ class AdvancedPage(Gtk.Box): def _on_snapping_state_set(self, button: Gtk.Switch, state: bool) -> None: profile = self._profile profile.angle_snapping = 1 if state else 0 + + def _on_report_rate_toggled(self, button: Gtk.RadioButton, rate: int) -> None: + if not button.get_active(): + return + profile = self._profile + profile.report_rate = rate diff --git a/piper/resolutionspage.py b/piper/resolutionspage.py index 226cc24..ed9d7d9 100644 --- a/piper/resolutionspage.py +++ b/piper/resolutionspage.py @@ -30,11 +30,6 @@ class ResolutionsPage(Gtk.Box): add_resolution_row: Gtk.ListBoxRow = Gtk.Template.Child() # type: ignore listbox: Gtk.ListBox = Gtk.Template.Child() # type: ignore - rate_1000: Gtk.RadioButton = Gtk.Template.Child() # type: ignore - rate_125: Gtk.RadioButton = Gtk.Template.Child() # type: ignore - rate_250: Gtk.RadioButton = Gtk.Template.Child() # type: ignore - rate_500: Gtk.RadioButton = Gtk.Template.Child() # type: ignore - rate_button_box: Gtk.ButtonBox = Gtk.Template.Child() # type: ignore def __init__( self, ratbagd_device: RatbagdDevice, profile: RatbagdProfile, *args, **kwargs @@ -50,19 +45,6 @@ class ResolutionsPage(Gtk.Box): self._last_activated_row = None self._profile = profile - self._handler_125 = self.rate_125.connect( - "toggled", self._on_report_rate_toggled, 125 - ) - self._handler_250 = self.rate_250.connect( - "toggled", self._on_report_rate_toggled, 250 - ) - self._handler_500 = self.rate_500.connect( - "toggled", self._on_report_rate_toggled, 500 - ) - self._handler_1000 = self.rate_1000.connect( - "toggled", self._on_report_rate_toggled, 1000 - ) - mousemap = MouseMap("#Buttons", self._device, spacing=20, border_width=20) self.pack_start(mousemap, True, True, 0) # Place the MouseMap on the left @@ -78,36 +60,11 @@ class ResolutionsPage(Gtk.Box): mousemap.add(label, f"#button{button.index}") mousemap.show_all() - are_report_rates_supported = ( - profile.report_rate != 0 and len(profile.report_rates) != 0 - ) - self.rate_button_box.set_sensitive(are_report_rates_supported) - self.rate_125.set_sensitive(125 in profile.report_rates) - self.rate_250.set_sensitive(250 in profile.report_rates) - self.rate_500.set_sensitive(500 in profile.report_rates) - self.rate_1000.set_sensitive(1000 in profile.report_rates) - self.listbox.foreach(Gtk.Widget.destroy) for resolution in profile.resolutions: row = ResolutionRow(resolution) self.listbox.insert(row, resolution.index) - # Updates report rate to reflect the new active profile's report rate. - with self.rate_125.handler_block(self._handler_125): - self.rate_125.set_active(profile.report_rate == 125) - with self.rate_250.handler_block(self._handler_250): - self.rate_250.set_active(profile.report_rate == 250) - with self.rate_500.handler_block(self._handler_500): - self.rate_500.set_active(profile.report_rate == 500) - with self.rate_1000.handler_block(self._handler_1000): - self.rate_1000.set_active(profile.report_rate == 1000) - - def _on_report_rate_toggled(self, button: Gtk.RadioButton, rate: int) -> None: - if not button.get_active(): - return - profile = self._profile - profile.report_rate = rate - @Gtk.Template.Callback("_on_row_activated") def _on_row_activated(self, listbox: Gtk.ListBox, row: Gtk.ListBoxRow) -> None: if row is self._last_activated_row: