[gnome-tweak-tool] keymouse: Move Compose tweak to main Keyboard section



commit 3df041b4f747227dc008f6029a8aa39b60378e2c
Author: Jeremy Bicha <jbicha ubuntu com>
Date:   Sun Jun 11 13:25:38 2017 -0400

    keymouse: Move Compose tweak to main Keyboard section
    
    https://raw.githubusercontent.com/gnome-design-team/gnome-mockups/master/tweak-tool/tweak-tool-wires.png
    
    https://bugzilla.gnome.org/show_bug.cgi?id=783176

 gtweak/tweaks/tweak_group_keymouse.py |  157 ++++++++++++++++++++++++++++++++-
 gtweak/tweaks/tweak_group_xkb.py      |    2 +-
 2 files changed, 156 insertions(+), 3 deletions(-)
---
diff --git a/gtweak/tweaks/tweak_group_keymouse.py b/gtweak/tweaks/tweak_group_keymouse.py
index 4c87f7d..2b9fbb2 100644
--- a/gtweak/tweaks/tweak_group_keymouse.py
+++ b/gtweak/tweaks/tweak_group_keymouse.py
@@ -20,9 +20,11 @@ import os.path
 from gi.repository import GLib, Gtk, Gdk
 
 import gtweak
-from gtweak.widgets import ListBoxTweakGroup, GSettingsSwitchTweak, GSettingsSwitchTweakValue, 
_GSettingsTweak, Title, GSettingsComboEnumTweak, build_label_beside_widget, Tweak
+from gtweak.widgets import ListBoxTweakGroup, GSettingsSwitchTweak, GSettingsSwitchTweakValue, 
_GSettingsTweak, Title, GSettingsComboEnumTweak, build_label_beside_widget, Tweak, UI_BOX_SPACING
 
 from gtweak.tweaks.tweak_group_xkb import TypingTweakGroup
+from gtweak.gsettings import GSettingsSetting
+
 
 class KeyThemeSwitcher(GSettingsSwitchTweakValue):
     def __init__(self, **options):
@@ -41,6 +43,156 @@ class KeyThemeSwitcher(GSettingsSwitchTweakValue):
         else:
             self.settings.set_string(self.key_name, "Default")
 
+
+class ComposeDialogLauncher(Gtk.Box, _GSettingsTweak):
+
+    def __init__(self, **options):
+        name = _("Compose Key")
+        Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=18)
+        _GSettingsTweak.__init__(self, name, "org.gnome.desktop.input-sources", "xkb-options", **options)
+
+        key_values = ["compose:sclk", "compose:prsc", "compose:menu", "compose:ralt", "compose:rctrl", 
"compose:rwin", "compose:caps", "compose:lctrl"]
+        key_names = [_("Scroll Lock"), _("PrtScn"), _("Menu"), _("Right Alt"), _("Right Ctrl"), _("Right 
Super"), _("Caps Lock"), _("Left Ctrl")]
+
+        button = Gtk.Button(_("Disabled"), halign=Gtk.Align.END)
+        button.set_relief(Gtk.ReliefStyle.NONE)
+        button.connect("clicked", self.on_button_clicked, self.settings)
+
+        desc = _("Allows entering additional characters.")
+
+        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+        vbox.props.spacing = UI_BOX_SPACING
+
+        lbl = Gtk.Label(name)
+        lbl.props.xalign = 0.0
+        lbl_desc = Gtk.Label()
+        lbl_desc.set_line_wrap(True)
+        lbl_desc.get_style_context().add_class("dim-label")
+        lbl_desc.set_markup("<span size='small'>"+GLib.markup_escape_text(desc)+"</span>")
+
+        vbox.pack_start(lbl, False, False, 0)
+        vbox.pack_start(lbl_desc, False, False, 0)
+        self.pack_start(vbox, False, False, 0)
+        self.pack_end(button, True, True, 0)
+
+        for index, item in enumerate(key_values):
+            if self.settings.setting_is_in_list("xkb-options", item):
+                button.set_label(key_names[index])
+                # We only support one Compose key so drop any one other set keys
+                for extra in key_values:
+                    self.settings.setting_remove_from_list("xkb-options", extra)
+                self.settings.setting_add_to_list("xkb-options", item)
+
+    def on_button_clicked(self, widget, settings):
+        a = ComposeDialog(self.main_window, widget, settings)
+        a.show_all()
+        resp = a.run()
+        a.destroy()
+
+
+class ComposeDialog(Gtk.Dialog, Gtk.Button):
+    key_values = ["compose:sclk", "compose:prsc", "compose:menu", "compose:ralt", "compose:rctrl", 
"compose:rwin", "compose:caps", "compose:lctrl"]
+    key_names = [_("Scroll Lock"), _("PrtScn"), _("Menu"), _("Right Alt"), _("Right Ctrl"), _("Right 
Super"), _("Caps Lock"), _("Left Ctrl")]
+    btn_sclk = Gtk.RadioButton.new_with_label_from_widget(None, _("Scroll Lock"))
+    btn_prsc = Gtk.RadioButton.new_with_label_from_widget(btn_sclk, _("PrtScn"))
+    btn_menu = Gtk.RadioButton.new_with_label_from_widget(btn_sclk, _("Menu"))
+    btn_ralt = Gtk.RadioButton.new_with_label_from_widget(btn_sclk, _("Right Alt"))
+    btn_rctrl = Gtk.RadioButton.new_with_label_from_widget(btn_sclk, _("Right Ctrl"))
+    btn_rwin = Gtk.RadioButton.new_with_label_from_widget(btn_sclk, _("Right Super"))
+    btn_caps = Gtk.RadioButton.new_with_label_from_widget(btn_sclk, _("Caps Lock"))
+    btn_lctrl = Gtk.RadioButton.new_with_label_from_widget(btn_sclk, _("Left Ctrl"))
+    compose_buttons= [btn_sclk, btn_prsc, btn_menu, btn_ralt, btn_rctrl, btn_rwin, btn_caps, btn_lctrl]
+
+    def __init__(self, parent, parent_button, settings):
+        Gtk.Dialog.__init__(self)
+
+        geometry = Gdk.Geometry()
+        geometry.max_width = 500
+        self.set_geometry_hints(None, geometry, Gdk.WindowHints.MAX_SIZE)
+        self.set_modal(True)
+        self.set_transient_for(parent)
+        self.set_size_request(500,-1)
+
+        hb = Gtk.HeaderBar()
+        hb.set_show_close_button(True)
+        hb.props.title = _("Compose Key")
+        self.set_titlebar(hb)
+
+        switch = Gtk.Switch()
+        compose_enabled = False
+        for item in self.key_values:
+            if settings.setting_is_in_list("xkb-options", item):
+                 compose_enabled = True
+        switch.set_active(compose_enabled)
+        for button in self.compose_buttons:
+           button.set_sensitive(compose_enabled)
+        switch.connect("notify::active", self._on_switch_changed, parent_button, settings)
+
+        hb.pack_start(switch)
+
+        grid = Gtk.Grid()
+        grid.props.border_width = 18
+        label = Gtk.Label(None)
+        label.set_markup(_("The compose key allows a wide variety of characters to be entered. To use it, 
press the compose key and then a sequence of characters.\n\n"
+            "Many unusual characters can be entered by combining standard ones. For example, compose key 
followed by <b>C</b> and <b>o</b> will enter <b>©</b>, <b>a</b> followed by <b>'</b> will enter <b>á</b>.\n"))
+        label.set_line_wrap(True)
+        self.get_content_area().pack_start(grid, True, True, 0)
+
+        grid.attach(label, 0, 0, 4, 1)
+        grid.attach(self.btn_sclk, 1, 1, 1, 1)
+        grid.attach(self.btn_prsc, 1, 2, 1, 1)
+        grid.attach(self.btn_menu, 1, 3, 1, 1)
+        grid.attach(self.btn_ralt, 2, 1, 1, 1)
+        grid.attach(self.btn_rctrl, 2, 2, 1, 1)
+        grid.attach(self.btn_rwin, 2, 3, 1, 1)
+        grid.attach(self.btn_caps, 3, 1, 1, 1)
+        grid.attach(self.btn_lctrl, 3, 2, 1, 1)
+
+        if settings.setting_is_in_list("xkb-options", "compose:sclk"):
+            self.btn_sclk.set_active(True)
+        elif settings.setting_is_in_list("xkb-options", "compose:prsc"):
+            self.btn_prsc.set_active(True)
+        elif settings.setting_is_in_list("xkb-options", "compose:menu"):
+            self.btn_menu.set_active(True)
+        elif settings.setting_is_in_list("xkb-options", "compose:ralt"):
+            self.btn_ralt.set_active(True)
+        elif settings.setting_is_in_list("xkb-options", "compose:rctrl"):
+            self.btn_rctrl.set_active(True)
+        elif settings.setting_is_in_list("xkb-options", "compose:rwin"):
+            self.btn_rwin.set_active(True)
+        elif settings.setting_is_in_list("xkb-options", "compose:caps"):
+            self.btn_caps.set_active(True)
+        elif settings.setting_is_in_list("xkb-options", "compose:lctrl"):
+            self.btn_lctrl.set_active(True)
+
+        for index, button in enumerate(self.compose_buttons):
+           button.set_sensitive(compose_enabled)
+           button.connect("toggled", self.on_button_toggled, index, parent_button, settings)
+
+        self.show_all()
+
+    def on_button_toggled(self, button, index, parent_button, settings):
+        for item in self.key_values:
+            settings.setting_remove_from_list("xkb-options", item)
+        settings.setting_add_to_list("xkb-options", self.key_values[index])
+        parent_button.set_label(self.key_names[index])
+
+    def _on_switch_changed(self, switch, param, parent_button, settings):
+        compose_enabled = switch.get_active()
+        for button in self.compose_buttons:
+           button.set_sensitive(compose_enabled)
+        # Until we implement storing the old Compose key setting somewhere,
+        # just force the key to Scroll Lock since it's first in the list.
+        if compose_enabled:
+            settings.setting_add_to_list("xkb-options", "compose:sclk")
+            parent_button.set_label(_("Scroll Lock"))
+        else:
+            self.btn_sclk.set_active(True)
+            for item in self.key_values:
+                settings.setting_remove_from_list("xkb-options", item)
+            parent_button.set_label(_("Disabled"))
+
+
 class OverviewShortcutTweak(Gtk.Box, _GSettingsTweak):
 
     def __init__(self, **options):
@@ -76,7 +228,7 @@ class AdditionalLayoutButton(Gtk.Box, Tweak):
     def __init__(self):
         Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=18,
                                valign=Gtk.Align.CENTER)
-        Tweak.__init__(self, 'extensions', '')
+        Tweak.__init__(self, "extensions", "")
 
         btn = Gtk.Button(label=_("Additional Layout Options"),halign=Gtk.Align.END)
         btn.connect("clicked", self._on_browse_clicked)
@@ -114,6 +266,7 @@ TWEAK_GROUPS = [
                               desc=_("Increases the choice of input sources in the Settings application."),
                               logout_required=True,),
         KeyThemeSwitcher(),
+        ComposeDialogLauncher(),
         OverviewShortcutTweak(),
         AdditionalLayoutButton(),
         Title(_("Mouse"), ""),
diff --git a/gtweak/tweaks/tweak_group_xkb.py b/gtweak/tweaks/tweak_group_xkb.py
index 3386466..c58e042 100644
--- a/gtweak/tweaks/tweak_group_xkb.py
+++ b/gtweak/tweaks/tweak_group_xkb.py
@@ -152,7 +152,7 @@ class TypingTweakGroup(Gtk.Box):
     XKB_GSETTINGS_SCHEMA = "org.gnome.desktop.input-sources"
     XKB_GSETTINGS_NAME = "xkb-options"
     # grp_led is unsupported
-    XKB_OPTIONS_BLACKLIST = {"grp_led"}
+    XKB_OPTIONS_BLACKLIST = {"grp_led", "Compose key"}
 
     def __init__(self):
         Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=3)


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