[gnome-tweak-tool] power: Convert Power Button tweak to ListBox



commit 2d684a2b71f8a31bce925f6fdf366c5c44db1e27
Author: Jeremy Bicha <jbicha ubuntu com>
Date:   Mon Jun 12 15:55:35 2017 -0400

    power: Convert Power Button tweak to ListBox

 gtweak/tweaks/tweak_group_power.py |  122 +++++++++++++++++++++++++++++++++++-
 1 files changed, 119 insertions(+), 3 deletions(-)
---
diff --git a/gtweak/tweaks/tweak_group_power.py b/gtweak/tweaks/tweak_group_power.py
index facb15e..99a0d7a 100644
--- a/gtweak/tweaks/tweak_group_power.py
+++ b/gtweak/tweaks/tweak_group_power.py
@@ -16,12 +16,14 @@
 # You should have received a copy of the GNU General Public License
 # along with gnome-tweak-tool.  If not, see <http://www.gnu.org/licenses/>.
 
-from gi.repository import Gio, GLib
+from gi.repository import Gio, GLib, Gtk
 
 import gtweak
-from gtweak.widgets import ListBoxTweakGroup, GSettingsComboEnumTweak, GSettingsSwitchTweak, 
GetterSetterSwitchTweak, build_horizontal_sizegroup, Title, _GSettingsTweak
+from gtweak.tweakmodel import Tweak
+from gtweak.widgets import ListBoxTweakGroup, GetterSetterSwitchTweak, build_horizontal_sizegroup, Title
 from gtweak.utils import AutostartFile
 
+
 class IgnoreLidSwitchTweak(GetterSetterSwitchTweak):
     def __init__(self, **options):
         self._inhibitor_name = "gnome-tweak-tool-lid-inhibitor"
@@ -54,11 +56,125 @@ class IgnoreLidSwitchTweak(GetterSetterSwitchTweak):
                      None, 0, -1, None)
             return False
 
+
+class PowerButtonTweak(Gtk.ListBox, Tweak):
+
+    def __init__(self, **options):
+        Gtk.ListBox.__init__(self)
+        Tweak.__init__(self, _("Power Button Behavior"), "")
+
+        self.settings = Gio.Settings("org.gnome.settings-daemon.plugins.power")
+        self.key_name = "power-button-action"
+
+        self.set_selection_mode(Gtk.SelectionMode.NONE)
+
+        # Needs other page elements to get margins too
+        # self.props.margin_left = 50
+        # self.props.margin_right = 50
+
+        row = Gtk.ListBoxRow()
+        hbox = Gtk.Box()
+        hbox.props.margin = 10
+        row.add(hbox)
+
+        lbl = Gtk.Label(_("Suspend"), xalign=0)
+        lbl.props.xalign = 0.0
+
+        self.check_suspend = Gtk.Image.new_from_icon_name("object-select-symbolic", 
Gtk.IconSize.SMALL_TOOLBAR);
+        self.check_suspend.set_no_show_all(True)
+        self.check_suspend.set_visible(self.settings[self.key_name] == "suspend")
+
+        hbox.pack_start(lbl, False, False, 0)
+        hbox.pack_end(self.check_suspend, False, False, 0)
+
+        self.add(row)
+
+        row = Gtk.ListBoxRow()
+        hbox = Gtk.Box()
+        hbox.props.margin = 10
+        row.add(hbox)
+
+        lbl = Gtk.Label(_("Hibernate"), xalign=0)
+        lbl.props.xalign = 0.0
+
+        self.check_hibernate = Gtk.Image.new_from_icon_name("object-select-symbolic", 
Gtk.IconSize.SMALL_TOOLBAR);
+        self.check_hibernate.set_no_show_all(True)
+        self.check_hibernate.set_visible(self.settings[self.key_name] == "hibernate")
+
+        hbox.pack_start(lbl, False, False, 0)
+        hbox.pack_end(self.check_hibernate, False, False, 0)
+
+        self.add(row)
+
+        row = Gtk.ListBoxRow()
+        hbox = Gtk.Box()
+        hbox.props.margin = 10
+        row.add(hbox)
+
+        lbl = Gtk.Label(_("Power Off"), xalign=0)
+        lbl.props.xalign = 0.0
+
+        self.check_poweroff = Gtk.Image.new_from_icon_name("object-select-symbolic", 
Gtk.IconSize.SMALL_TOOLBAR);
+        self.check_poweroff.set_no_show_all(True)
+        self.check_poweroff.set_visible(self.settings[self.key_name] == "interactive" or 
self.settings[self.key_name] == "shutdown")
+
+        hbox.pack_start(lbl, False, False, 0)
+        hbox.pack_end(self.check_poweroff, False, False, 0)
+
+        # Distros that have re-enabled the "interactive" option can uncomment this:
+        # self.add(row)
+
+        row = Gtk.ListBoxRow()
+        hbox = Gtk.Box()
+        hbox.props.margin = 10
+        row.add(hbox)
+
+        lbl = Gtk.Label(_("No Action"), xalign=0)
+        lbl.props.xalign = 0.0
+
+        self.check_noaction = Gtk.Image.new_from_icon_name("object-select-symbolic", 
Gtk.IconSize.SMALL_TOOLBAR);
+        self.check_noaction.set_no_show_all(True)
+        self.check_noaction.set_visible(self.settings[self.key_name] == "nothing")
+
+        hbox.pack_start(lbl, False, False, 0)
+        hbox.pack_end(self.check_noaction, False, False, 0)
+
+        self.add(row)
+
+        self.connect('row-activated', self.on_row_clicked)
+
+    def on_row_clicked(self, box, row):
+        if row.get_index() == 0:
+            self.settings[self.key_name] = "suspend"
+            self.check_suspend.show()
+            self.check_hibernate.hide()
+            self.check_poweroff.hide()
+            self.check_noaction.hide()
+        elif row.get_index() == 1:
+            self.settings[self.key_name] = "hibernate"
+            self.check_suspend.hide()
+            self.check_hibernate.show()
+            self.check_poweroff.hide()
+            self.check_noaction.hide()
+        elif row.get_index() == 2:
+            self.settings[self.key_name] = "interactive"
+            self.check_suspend.hide()
+            self.check_hibernate.hide()
+            self.check_poweroff.show()
+            self.check_noaction.hide()
+        else:
+            self.settings[self.key_name] = "nothing"
+            self.check_suspend.hide()
+            self.check_hibernate.hide()
+            self.check_poweroff.hide()
+            self.check_noaction.show()
+
 sg = build_horizontal_sizegroup()
 
 TWEAK_GROUPS = [
     ListBoxTweakGroup(_("Power"),
         IgnoreLidSwitchTweak(),
-        GSettingsComboEnumTweak(_("Power Button Behavior"), "org.gnome.settings-daemon.plugins.power", 
"power-button-action", size_group=sg),
+        Title(_("Power Button Behavior"), "", uid="title-theme"),
+        PowerButtonTweak(),
     ),
 ]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]