def _get_valid_key_themes(self): dirs = ( os.path.join(gtweak.DATA_DIR, "themes"), os.path.join(os.path.expanduser("~"), ".themes")) valid = walk_directories(dirs, lambda d: os.path.isfile(os.path.join(d, "gtk-3.0", "gtk-keys.css")) and \ os.path.isfile(os.path.join(d, "gtk-2.0-key", "gtkrc"))) return valid
def _get_valid_cursor_themes(self): dirs = ( os.path.join(gtweak.DATA_DIR, "icons"), os.path.join(os.path.expanduser("~"), ".icons")) valid = walk_directories(dirs, lambda d: os.path.isdir(d) and \ os.path.exists(os.path.join(d, "cursors"))) return valid
def _get_valid_cursor_themes(self): dirs = (os.path.join(gtweak.DATA_DIR, "icons"), os.path.join(GLib.get_user_data_dir(), "icons"), os.path.join(os.path.expanduser("~"), ".icons")) valid = walk_directories(dirs, lambda d: os.path.isdir(d) and \ os.path.exists(os.path.join(d, "cursors"))) return valid
def _get_valid_key_themes(self): dirs = (os.path.join(gtweak.DATA_DIR, "themes"), os.path.join(GLib.get_user_data_dir(), "themes"), os.path.join(os.path.expanduser("~"), ".themes")) valid = walk_directories(dirs, lambda d: os.path.isfile(os.path.join(d, "gtk-3.0", "gtk-keys.css")) and \ os.path.isfile(os.path.join(d, "gtk-2.0-key", "gtkrc"))) return valid
def _get_valid_icon_themes(self): dirs = ( os.path.join(gtweak.DATA_DIR, "icons"), os.path.join(GLib.get_user_data_dir(), "icons"), os.path.join(os.path.expanduser("~"), ".icons")) valid = walk_directories(dirs, lambda d: os.path.isdir(d) and \ os.path.exists(os.path.join(d, "index.theme"))) return valid
def _get_valid_themes(self): """ Only shows themes that have variations for gtk+-3 and gtk+-2 """ dirs = ( os.path.join(gtweak.DATA_DIR, "themes"), os.path.join(os.path.expanduser("~"), ".themes")) valid = walk_directories(dirs, lambda d: os.path.exists(os.path.join(d, "gtk-2.0")) and \ os.path.exists(os.path.join(d, "gtk-3.0"))) return valid
def _get_valid_themes(self): """ Only shows themes that have variations for gtk+-3 and gtk+-2 """ dirs = ( os.path.join(gtweak.DATA_DIR, "themes"), os.path.join(GLib.get_user_data_dir(), "themes"), os.path.join(os.path.expanduser("~"), ".themes")) valid = walk_directories(dirs, lambda d: os.path.exists(os.path.join(d, "gtk-2.0")) and \ os.path.exists(os.path.join(d, "gtk-3.0"))) return valid
def _get_valid_themes(self): """ Only shows themes that have variations for gtk3""" gtk_ver = Gtk.MINOR_VERSION if gtk_ver % 2: # Want even number gtk_ver += 1 valid = ['Adwaita', 'HighContrast', 'HighContrastInverse'] valid += walk_directories(get_resource_dirs("themes"), lambda d: os.path.exists(os.path.join(d, "gtk-3.0", "gtk.css")) or \ os.path.exists(os.path.join(d, "gtk-3.{}".format(gtk_ver)))) return set(valid)
def _get_valid_themes(self): """ Only shows themes that have variations for gtk+-3 and gtk+-2 """ gtk_ver = Gtk.MINOR_VERSION if gtk_ver % 2: # Want even number gtk_ver += 1 dirs = (os.path.join(gtweak.DATA_DIR, "themes"), os.path.join(GLib.get_user_data_dir(), "themes"), os.path.join(os.path.expanduser("~"), ".themes")) valid = walk_directories(dirs, lambda d: os.path.exists(os.path.join(d, "gtk-2.0")) and \ (os.path.exists(os.path.join(d, "gtk-3.0")) or \ os.path.exists(os.path.join(d, "gtk-3.{}".format(gtk_ver))))) return valid
def _get_valid_themes(self): """ Only shows themes that have variations for gtk+-3 and gtk+-2 """ gtk_ver = Gtk.MINOR_VERSION if gtk_ver % 2: # Want even number gtk_ver += 1 dirs = ( os.path.join(gtweak.DATA_DIR, "themes"), os.path.join(GLib.get_user_data_dir(), "themes"), os.path.join(os.path.expanduser("~"), ".themes")) valid = walk_directories(dirs, lambda d: os.path.exists(os.path.join(d, "gtk-2.0")) and \ (os.path.exists(os.path.join(d, "gtk-3.0")) or \ os.path.exists(os.path.join(d, "gtk-3.{}".format(gtk_ver))))) return valid
class ShellThemeTweak(Gtk.Box, Tweak): THEME_EXT_NAME = "*****@*****.**" THEME_GSETTINGS_SCHEMA = "org.gnome.shell.extensions.user-theme" THEME_GSETTINGS_NAME = "name" THEME_GSETTINGS_DIR = os.path.join(GLib.get_user_data_dir(), "gnome-shell", "extensions", THEME_EXT_NAME, "schemas") LEGACY_THEME_DIR = os.path.join(GLib.get_home_dir(), ".themes") THEME_DIR = os.path.join(GLib.get_user_data_dir(), "themes") def __init__(self, **options): Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL) Tweak.__init__(self, _("Shell theme"), _("Install custom or user themes for gnome-shell"), **options) #check the shell is running and the usertheme extension is present error = _("Unknown error") self._shell = _shell if self._shell is None: logging.warning("Shell not running", exc_info=True) error = _("Shell not running") else: try: extensions = self._shell.list_extensions() if ShellThemeTweak.THEME_EXT_NAME in extensions and extensions[ ShellThemeTweak.THEME_EXT_NAME]["state"] == 1: #check the correct gsettings key is present try: if os.path.exists(ShellThemeTweak.THEME_GSETTINGS_DIR): self._settings = GSettingsSetting( ShellThemeTweak.THEME_GSETTINGS_SCHEMA, schema_dir=ShellThemeTweak.THEME_GSETTINGS_DIR) else: self._settings = GSettingsSetting( ShellThemeTweak.THEME_GSETTINGS_SCHEMA) name = self._settings.get_string( ShellThemeTweak.THEME_GSETTINGS_NAME) ext = extensions[ShellThemeTweak.THEME_EXT_NAME] logging.debug("Shell user-theme extension\n%s" % pprint.pformat(ext)) error = None except: logging.warning( "Could not find user-theme extension in %s" % ','.join(extensions.keys()), exc_info=True) error = _( "Shell user-theme extension incorrectly installed") else: error = _("Shell user-theme extension not enabled") except Exception, e: logging.warning("Could not list shell extensions", exc_info=True) error = _("Could not list shell extensions") if error: cb = build_combo_box_text(None) build_label_beside_widget(self.name, cb, warning=error, hbox=self) self.widget_for_size_group = cb else: #include both system, and user themes #note: the default theme lives in /system/data/dir/gnome-shell/theme # and not themes/, so add it manually later dirs = [ os.path.join(d, "themes") for d in GLib.get_system_data_dirs() ] dirs += [ShellThemeTweak.THEME_DIR] dirs += [ShellThemeTweak.LEGACY_THEME_DIR] valid = walk_directories(dirs, lambda d: os.path.exists(os.path.join(d, "gnome-shell")) and \ os.path.exists(os.path.join(d, "gnome-shell", "gnome-shell.css"))) #the default value to reset the shell is an empty string valid.extend(("", )) #build a combo box with all the valid theme options #manually add Adwaita to represent the default cb = build_combo_box_text( self._settings.get_string( ShellThemeTweak.THEME_GSETTINGS_NAME), *make_combo_list_with_default( valid, "", default_text=_("<i>Default</i>"))) cb.connect('changed', self._on_combo_changed) self._combo = cb #a filechooser to install new themes chooser = FileChooserButton(_("Select a theme"), True, ["application/zip"]) chooser.connect("file-set", self._on_file_set) build_label_beside_widget(self.name, chooser, cb, hbox=self) self.widget_for_size_group = cb
def _get_valid_themes(self): dirs = ( os.path.join(gtweak.DATA_DIR, "themes"), os.path.join(os.path.expanduser("~"), ".themes")) valid = walk_directories(dirs, lambda d: os.path.exists(os.path.join(d, "metacity-1"))) return valid
def _get_valid_themes(self): dirs = ( os.path.join(gtweak.DATA_DIR, "themes"), os.path.join(GLib.get_user_data_dir(), "themes")) valid = walk_directories(dirs, lambda d: os.path.exists(os.path.join(d, "metacity-1"))) return valid
def _get_valid_cursor_themes(self): valid = walk_directories(get_resource_dirs("icons"), lambda d: os.path.isdir(d) and \ os.path.exists(os.path.join(d, "cursors"))) return set(valid)