Custom shell/gtk themes

Asked by Costumed Manatee

I want to apply a custom GTK and a custom shell theme (gnome) but I can't find a way to do it.

I download user theme extensions, to be able to change the shell theme.
I download themes from the gnome site and test it on my main machine and they work perfectly.
I put those themes in the /usr/share/themes folder of my custom distro and then I try to update the shell and GTK theme using the correct gsettings command (I try the command on my main machine and it works), but when I boot on the iso themes were not apply by default.

How can I apply them by default ?

Question information

Language:
English Edit question
Status:
Solved
For:
Cubic Edit question
Assignee:
No assignee Edit question
Solved by:
Cubic PPA
Solved:
Last query:
Last reply:
Revision history for this message
Cubic PPA (cubic-wizard) said :
#1

#!/usr/bin/python3

########################################################################
# #
# install-gnome-shell-extension.py #
# #
# In order to prevent the customized default schema files in #
# /usr/share/glib-2.0/schemas from being overridden, remove all #
# distribution specific schema override files in this directory by #
# moving them to a backup directory in /tmp. #
# #
# Copyright (C) 2019 PJ Singh <email address hidden> #
# #
########################################################################

########################################################################
# #
# 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 3 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, see <https://www.gnu.org/licenses>. #
# #
########################################################################

"""
Install the specified gnome shell extension.

Run this program as root or using sudo.

Example:
$ sudo ./install-gnome-shell-extension 307

Args:
    extension_id (int): The extension number.

Returns:
    None
"""

import json
import shutil
import sys
import tempfile
import traceback
import urllib
import urllib.request
import xml.etree.ElementTree as ElementTree
import zipfile

########################################################################
# References
########################################################################

# https://docs.python.org/3/howto/urllib2.html

########################################################################
# Globals & Constants
########################################################################

EXTENSION_INFORMATION_URL_TEMPLATE = 'https://extensions.gnome.org/extension-info/?pk=%i&shell_version=%s'
EXTENSION_DOWNLOAD_URL_TEMPLATE = 'https://extensions.gnome.org%s'
EXTENSION_DIRECTORY_TEMPLATE = '/usr/share/gnome-shell/extensions/%s'
# EXTENSION_DIRECTORY_TEMPLATE = '/home/psingh/Temp/test/%s'

########################################################################
# Functions
########################################################################

#-----------------------------------------------------------------------
# Extension Id
#-----------------------------------------------------------------------

try:
    extension_id = int(sys.argv[1])
    print('Install extension %i...' % extension_id)
except IndexError:
    print('• Error. An extension id number is required.')
    exit()
except ValueError:
    print('• Error. An extension id number is required.')
    exit()

#-----------------------------------------------------------------------
# Gnome Shell Version
#-----------------------------------------------------------------------

version = ''
try:
    filepath = '/usr/share/gnome/gnome-version.xml'
    tree = ElementTree.parse(filepath)
    root = tree.getroot()
    platform = root.find('platform').text
    version = platform
    minor = root.find('minor').text
    version = version + '.' + minor
    try:
        micro = root.find('micro').text
        version = version + '.' + micro
    except AttributeError:
        print('• Ignoring. Unable to get Gnome micro version. The Gnome version is %s.' % version)
except Exception as exception:
    print('• Error. Unable to get the Gnome version. The Gnome version is %s.' % version)
    print('• The exception is %s' % exception)
    # print('• The tracekback is %s' % traceback.format_exc())
    exit()
print('• The Gnome version is %s.' % version)

#-----------------------------------------------------------------------
# Download the Extension
#-----------------------------------------------------------------------

url = EXTENSION_INFORMATION_URL_TEMPLATE % (extension_id, version)
print('• The extension information url is %s' % url)
try:
    with urllib.request.urlopen(url) as response:
        try:
            # Get extension information.
            data = response.read()
            info = json.loads(data)
            name = info.get('name')
            print('• The extension name is %s' % name)
            uuid = info.get('uuid')
            print('• The extension uuid is %s' % uuid)
            # Ex: url = 'https://<email address hidden>?version_tag=15925'
            url = EXTENSION_DOWNLOAD_URL_TEMPLATE % info.get('download_url')
            print('• The extension download url is %s' % url)
            # Download extension.
            try:
                with urllib.request.urlopen(url) as response:
                    try:
                        # Extract the extension
                        # extension_directory = EXTENSION_DIRECTORY_TEMPLATE % uuid
                        # extension_filepath = '%s/test.zip' % extension_directory
                        # with open(extension_filepath, 'wb') as target:
                        # shutil.copyfileobj(response, target)
                        # print('• Saved the extension as %s' % extension_filepath)
                        with tempfile.NamedTemporaryFile(delete=False) as temp_file:
                            shutil.copyfileobj(response, temp_file)
                            extension_directory = EXTENSION_DIRECTORY_TEMPLATE % uuid
                            print('• The extension directory is %s' % extension_directory)
                            try:
                                # Unzip the temporary file to the target directory.
                                with zipfile.ZipFile(temp_file, 'r') as zip_file:
                                    # The extension directory path will be created.
                                    zip_file.extractall(extension_directory)
                                print('• Successfully extracted %s extension %i for Gnome %s to %s' % (uuid, extension_id, version, extension_directory))
                            except Exception as exception:
                                print('• Error. Unable to extract extension to %s' % extension_directory)
                                print('• The exception is %s' % exception)
                                # print('• The tracekback is %s' % traceback.format_exc())
                    except Exception as exception:
                        print('• Error. Unable to save extension as a temporary file from %s' % url)
                        print('• The exception is %s' % exception)
                        # print('• The tracekback is %s' % traceback.format_exc())
            except urllib.error.URLError as exception:
                print('• Error. Unable to access %s' % url)
                print('• The exception is %s' % exception)
                # print('• The tracekback is %s' % traceback.format_exc())
        except Exception as exception:
            print('• Error. Unable to get extension information from %s' % url)
            print('• The exception is %s' % exception)
            # print('• The tracekback is %s' % traceback.format_exc())
except urllib.error.URLError as exception:
    print('• Error. Unable to access %s' % url)
    print('• The exception is %s' % exception)
    # print('• The tracekback is %s' % traceback.format_exc())

Revision history for this message
Cubic PPA (cubic-wizard) said :
#2

Please feel free to use my script, above.

Save the file as `install-gnome-shell-extension.py`.

Make it executable:

    $ chmod +x ./install-gnome-shell-extension.py

Then, execute the script inside the Cubic's Terminal as follows:

    $ ./install-gnome-shell-extension.py <extension_id>

The <extension_id> is the number shown in the URL for the extension you want to install.

For example, the URL for the "User Themes" extension is...

    https://extensions.gnome.org/extension/19/user-themes/

Therefore, you can install the "User Themes" extension by executing:

    $ ./install-gnome-shell-extension.py 19

This will install the extension globally for *all* users.

Afterwards, if you ever need to update this extension in an installed environment, simply execute this same script using sudo:

    $ sudo ./install-gnome-shell-extension.py 19

Revision history for this message
Cubic PPA (cubic-wizard) said :
#3

After you've installed your extension, you will need to configure it.

You can not use gsettings in Cubic's terminal environment to set user preferences.

Gsettings makes changes for the current user, but there is really no "current user" because you haven't installed your system. (Yes, you are a "root" user, but this is only to modify files on the system as you customize it).

To setup default user preferences, create a file called 90_ubuntu-settings.gschema.override and place it in /usr/share/glib-2.0/schemas/ directory in Cubic.

You will need to know the schema, keys, and allowed values for the extension you're configuring.
(You can see what the correct keys and values are using dconf-editor in your host environment).

Here is an example file:

[org.gnome.desktop.background]
picture-uri = 'file:///usr/share/backgrounds/warty-final-ubuntu.png'
show-desktop-icons = false

[org.gnome.desktop.screensaver]
picture-uri = 'file:///usr/share/backgrounds/warty-final-ubuntu.png'

[org.gnome.desktop.wm.preferences]
button-layout = 'close,minimize,maximize:appmenu'
titlebar-font = 'Roboto Regular 10'

[org.gnome.desktop.interface]
document-font-name = 'Roboto Regular 10'
font-name = 'Roboto Regular 10'

[org.gnome.shell]
favorite-apps = ['ubiquity.desktop', 'firefox.desktop', 'org.gnome.Nautilus.desktop', 'org.gnome.gedit.desktop', 'org.gnome.Terminal.desktop', 'meld.desktop', 'libreoffice-writer.desktop', 'libreoffice-calc.desktop', 'org.gnome.Calculator.desktop', 'org.gnome.Screenshot.desktop', 'gnome-system-monitor.desktop']

Then, compile this schema file using:

glib-compile-schemas /usr/share/glib-2.0/schemas/

All users will have the preferences you specified in 90_ubuntu-settings.gschema.override.

Revision history for this message
Costumed Manatee (costumedmanatee) said :
#4

I tried your solution, the GTK theme is applied and the user-theme extension is installed.

But there is still one problem, the user-theme extension is correctly installed bot not enable by default, so my shell theme is not apply by default.

How can I change that ?

Revision history for this message
Best Cubic PPA (cubic-wizard) said :
#5

The key is "enabled-extensions" in gsettings schema "org.gnome.shell".

Add this to your 90_ubuntu-settings.gschema.override file.

You can search find keys on your host machine by using dconf editor.
If you've installed "User Themes" and enabled it on your host machine, you can search for key "enabled-extensions" to see what the actual extension name is.

For example,...

[org.gnome.shell]
enabled-extensions = ['<email address hidden>', '<email address hidden>', '<email address hidden>', '<email address hidden>', '<email address hidden>', '<email address hidden>', '<email address hidden>', '<email address hidden>']

Revision history for this message
Costumed Manatee (costumedmanatee) said :
#6

Thanks Cubic PPA, that solved my question.

Revision history for this message
timekeeper40 (timekeeper40) said :
#7

How do I copy the extension script so cubic can run it?

Revision history for this message
Costumed Manatee (costumedmanatee) said :
#8

It's been a while since I last touch to Gnome but if I understand your question correctly, your gnome extensions just go to /usr/share/gnome-shell/extensions . Hope this will help you !

Revision history for this message
timekeeper40 (timekeeper40) said :
#9

I tried multiple times to user your script for adding extensions and it faults out all the time.
Could please help?

Thanks,