diff --git a/data/piper.gresource.xml b/data/piper.gresource.xml index a55c336..4f96b0f 100644 --- a/data/piper.gresource.xml +++ b/data/piper.gresource.xml @@ -4,7 +4,6 @@ 404.svg AboutDialog.ui - ui/LedDialog.ui ui/OptionButton.ui ui/ResolutionRow.ui ui/ResolutionsPage.ui diff --git a/data/ui/LedDialog.ui b/data/ui/LedDialog.ui deleted file mode 100644 index ba0a34c..0000000 --- a/data/ui/LedDialog.ui +++ /dev/null @@ -1,440 +0,0 @@ - - - - - - 255 - 1 - 10 - - - 100 - 20000 - 50 - 50 - - - diff --git a/piper/leddialog.py b/piper/leddialog.py deleted file mode 100644 index 9611098..0000000 --- a/piper/leddialog.py +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright (C) 2017 Jente Hidskes -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -from .gi_composites import GtkTemplate -from .ratbagd import RatbagdLed - -import gi -gi.require_version("Gtk", "3.0") -from gi.repository import Gdk, GObject, Gtk - - -@GtkTemplate(ui="/org/freedesktop/Piper/ui/LedDialog.ui") -class LedDialog(Gtk.Dialog): - """A Gtk.Dialog subclass to implement the dialog that shows the - configuration options for the LED effects.""" - - __gtype_name__ = "LedDialog" - - stack = GtkTemplate.Child() - colorchooser = GtkTemplate.Child() - colorbutton = GtkTemplate.Child() - adjustment_brightness = GtkTemplate.Child() - adjustment_effect_rate = GtkTemplate.Child() - - def __init__(self, ratbagd_led, *args, **kwargs): - """Instantiates a new LedDialog. - - @param ratbagd_led The LED to configure, as ratbagd.RatbagdLed. - """ - Gtk.Dialog.__init__(self, *args, **kwargs) - self.init_template() - self._led = ratbagd_led - self._modes = { - "solid": RatbagdLed.MODE_ON, - "cycle": RatbagdLed.MODE_CYCLE, - "breathing": RatbagdLed.MODE_BREATHING, - "off": RatbagdLed.MODE_OFF - } - - mode = self._led.mode - for k, v in self._modes.items(): - if mode == v: - self.stack.set_visible_child_name(k) - rgba = self._get_led_color_as_rgba() - self.colorchooser.set_rgba(rgba) - self.colorbutton.set_rgba(rgba) - self.adjustment_brightness.set_value(self._led.brightness) - self.adjustment_effect_rate.set_value(self._led.effect_rate) - - def _get_led_color_as_rgba(self): - # Helper function to convert ratbagd's 0-255 color range to a Gdk.RGBA - # with a 0.0-1.0 color range. - r, g, b = self._led.color - return Gdk.RGBA(r / 255.0, g / 255.0, b / 255.0, 1.0) - - @GObject.Property - def mode(self): - visible_child = self.stack.get_visible_child_name() - return self._modes[visible_child] - - @GObject.Property - def color(self): - if self.mode == RatbagdLed.MODE_ON: - rgba = self.colorchooser.get_rgba() - else: - rgba = self.colorbutton.get_rgba() - return (rgba.red * 255.0, rgba.green * 255.0, rgba.blue * 255.0) - - @GObject.Property - def brightness(self): - return self.adjustment_brightness.get_value() - - @GObject.Property - def effect_rate(self): - return self.adjustment_effect_rate.get_value() diff --git a/piper/ledspage.py b/piper/ledspage.py deleted file mode 100644 index a473636..0000000 --- a/piper/ledspage.py +++ /dev/null @@ -1,92 +0,0 @@ -# Copyright (C) 2017 Jente Hidskes -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -from gettext import gettext as _ - -from .leddialog import LedDialog -from .mousemap import MouseMap -from .optionbutton import OptionButton -from .ratbagd import RatbagdLed - -import gi -gi.require_version("Gtk", "3.0") -from gi.repository import Gtk - - -class LedsPage(Gtk.Box): - """The third stack page, exposing the LED configuration.""" - - __gtype_name__ = "LedsPage" - - def __init__(self, ratbagd_device, *args, **kwargs): - """Instantiates a new LedsPage. - - @param ratbag_device The ratbag device to configure, as - ratbagd.RatbagdDevice - """ - Gtk.Box.__init__(self, *args, **kwargs) - self._device = ratbagd_device - self._init_ui() - - def _init_ui(self): - profile = self._device.active_profile - - mousemap = MouseMap("#Leds", self._device, spacing=20, border_width=20) - self.pack_start(mousemap, True, True, 0) - - sizegroup = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL) - for led in profile.leds: - index = led.index - mode = self._mode_to_string(led.mode) - button = OptionButton("LED {}: {}".format(index, mode)) - button.connect("clicked", self._on_button_clicked, led) - led.connect("notify::mode", self._on_led_mode_changed, button) - mousemap.add(button, "#led{}".format(index)) - sizegroup.add_widget(button) - - def _on_led_mode_changed(self, led, pspec, button): - mode = self._mode_to_string(led.mode) - button.set_label("LED {}: {}".format(led.index, mode)) - - def _on_button_clicked(self, button, led): - # Presents the LedDialog to configure the LED corresponding to the - # clicked button. - dialog = LedDialog(led, transient_for=self.get_toplevel()) - dialog.connect("response", self._on_dialog_response, button, led) - dialog.present() - - def _on_dialog_response(self, dialog, response, button, led): - # The user either pressed cancel or apply. If it's apply, apply the - # changes before closing the dialog, otherwise just close the dialog. - if response == Gtk.ResponseType.APPLY: - led.mode = dialog.mode - led.color = dialog.color - led.brightness = dialog.brightness - led.effect_rate = dialog.effect_rate - dialog.destroy() - - def _mode_to_string(self, mode): - # Converts a RatbagdLed mode to a string. - if mode == RatbagdLed.MODE_ON: - return _("solid") - elif mode == RatbagdLed.MODE_CYCLE: - return _("cycle") - elif mode == RatbagdLed.MODE_BREATHING: - return _("breathing") - elif mode == RatbagdLed.MODE_OFF: - return _("off") - else: - return _("n/a") diff --git a/piper/window.py b/piper/window.py index f5411f4..b534aab 100644 --- a/piper/window.py +++ b/piper/window.py @@ -19,7 +19,6 @@ from gettext import gettext as _ from .gi_composites import GtkTemplate from .ratbagd import RatbagErrorCode from .resolutionspage import ResolutionsPage -from .ledspage import LedsPage import gi gi.require_version("Gtk", "3.0") @@ -50,7 +49,7 @@ class Window(Gtk.ApplicationWindow): self._device = self._fetch_ratbag_device() self.stack.add_titled(ResolutionsPage(self._device), "resolutions", _("Resolutions")) - self.stack.add_titled(LedsPage(self._device), "leds", _("LEDs")) + self.stack.set_visible_child_name("resolutions") def _fetch_ratbag_device(self): """Get the first ratbag device available. If there are multiple