Commit 0849d933 authored by John Stowers's avatar John Stowers

Can configure extension prefs

parent 4459fafe
3.5.x
* Can configure extension preferences
3.5.5
* Now appear as "Tweak Tool" in (bug 678778)
* Fix incompatibility with new gnome-shell extensions (Alban Browaeys, bug 678778)
......
......@@ -15,10 +15,10 @@
# 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/>.
import subprocess
import logging
import gtweak
import gtweak.utils
from gi.repository import GConf
......@@ -34,11 +34,8 @@ class GConfSetting:
def _run_gconftool(self, command):
if command not in self._cmd_cache:
p = subprocess.Popen(
["gconftool-2", command, self._key],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)
stdout, stderr = p.communicate()
if p.returncode == 0:
stdout, stderr, returncode = gtweak.utils.execute_subprocess(["gconftool-2", command, self._key], block=True)
if returncode == 0:
self._cmd_cache[command] = stdout.strip()
else:
self._cmd_cache[command] = "ERROR: %s" % stderr.strip()
......
......@@ -77,6 +77,7 @@ class GnomeShell:
}
DATA_DIR = os.path.join(GLib.get_user_data_dir(), "gnome-shell")
EXTENSION_DIR = os.path.join(GLib.get_user_data_dir(), "gnome-shell", "extensions")
def __init__(self, shellproxy, shellsettings):
self._proxy = shellproxy
......@@ -102,6 +103,7 @@ class GnomeShell32(GnomeShell):
EXTENSION_ENABLED_KEY = "enabled-extensions"
EXTENSION_NEED_RESTART = False
SUPPORTS_EXTENSION_PREFS = False
def list_extensions(self):
return self._proxy.proxy.ListExtensions()
......@@ -118,6 +120,8 @@ class GnomeShell32(GnomeShell):
class GnomeShell34(GnomeShell32):
SUPPORTS_EXTENSION_PREFS = True
def restart(self):
logging.warning("Restarting Shell Not Supported")
......
......@@ -7,10 +7,10 @@ import json
from gi.repository import Gtk
from gi.repository import GLib
from gtweak.utils import extract_zip_file
from gtweak.utils import extract_zip_file, execute_subprocess
from gtweak.gshellwrapper import GnomeShell, GnomeShellFactory
from gtweak.tweakmodel import Tweak, TweakGroup
from gtweak.widgets import ZipFileChooserButton, build_label_beside_widget, build_horizontal_sizegroup, UI_BOX_SPACING
from gtweak.widgets import ZipFileChooserButton, build_label_beside_widget, build_horizontal_sizegroup, build_tight_button, UI_BOX_SPACING
class _ShellExtensionTweak(Tweak):
......@@ -19,10 +19,11 @@ class _ShellExtensionTweak(Tweak):
self._shell = shell
state = ext.get("state")
uuid = ext["uuid"]
sw = Gtk.Switch()
sw.set_active(self._shell.extension_is_active(state, ext["uuid"]))
sw.connect('notify::active', self._on_extension_toggled, ext["uuid"])
sw.set_active(self._shell.extension_is_active(state, uuid))
sw.connect('notify::active', self._on_extension_toggled, uuid)
info = None
warning = None
......@@ -42,12 +43,25 @@ class _ShellExtensionTweak(Tweak):
logging.critical(warning)
sw.set_sensitive(sensitive)
widgets = []
if self._shell.SUPPORTS_EXTENSION_PREFS:
prefs = os.path.join(self._shell.EXTENSION_DIR, uuid, "prefs.js")
if os.path.exists(prefs):
cfg = build_tight_button(Gtk.STOCK_PREFERENCES)
cfg.connect("clicked", self._on_configure_clicked, uuid)
widgets.append(cfg)
widgets.append(sw)
self.widget = build_label_beside_widget(
_("%s Extension") % ext["name"],
sw,
*widgets,
warning=warning)
self.widget_for_size_group = None
def _on_configure_clicked(self, btn, uuid):
execute_subprocess(['gnome-shell-extension-prefs', uuid], block=False)
def _on_extension_toggled(self, sw, active, uuid):
if not sw.get_active():
self._shell.disable_extension(uuid)
......@@ -62,8 +76,6 @@ class _ShellExtensionTweak(Tweak):
class _ShellExtensionInstallerTweak(Tweak):
EXTENSION_DIR = os.path.join(GLib.get_user_data_dir(), "gnome-shell", "extensions")
def __init__(self, shell, **options):
Tweak.__init__(self, _("Install Shell Extension"), "", **options)
......@@ -118,7 +130,7 @@ class _ShellExtensionInstallerTweak(Tweak):
ok, updated = extract_zip_file(
z,
"/".join(fragment),
os.path.join(self.EXTENSION_DIR, extension_uuid))
os.path.join(self._shell.EXTENSION_DIR, extension_uuid))
if ok:
if updated:
......
......@@ -19,6 +19,7 @@ import os.path
import logging
import tempfile
import shutil
import subprocess
import gtweak
from gtweak.gsettings import GSettingsSetting
......@@ -102,6 +103,14 @@ def extract_zip_file(z, members_path, dest):
return ok, updated
def execute_subprocess(cmd_then_args, block=True):
p = subprocess.Popen(
cmd_then_args,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)
if block:
stdout, stderr = p.communicate()
return stdout, stderr, p.returncode
class AutostartManager:
def __init__(self, desktop_filename, autostart_desktop_filename="", exec_cmd="", extra_exec_args=""):
self.desktop_filename = desktop_filename
......
......@@ -99,6 +99,25 @@ def build_horizontal_sizegroup():
sg.props.ignore_hidden = True
return sg
def build_tight_button(stock_id):
button = Gtk.Button()
button.set_relief(Gtk.ReliefStyle.NONE)
button.set_focus_on_click(False)
button.add(Gtk.Image.new_from_stock(stock_id, Gtk.IconSize.MENU))
data = ".button {\n" \
"-GtkButton-default-border : 0px;\n" \
"-GtkButton-default-outside-border : 0px;\n" \
"-GtkButton-inner-border: 0px;\n" \
"-GtkWidget-focus-line-width : 0px;\n" \
"-GtkWidget-focus-padding : 0px;\n" \
"padding: 0px;\n" \
"}"
provider = Gtk.CssProvider()
provider.load_from_data(data)
# 600 = GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
button.get_style_context().add_provider(provider, 600)
return button
class _GSettingsTweak(Tweak):
def __init__(self, schema_name, key_name, **options):
self.schema_name = schema_name
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment