1# This file is part of ReText 2# Copyright: 2015-2016 Dmitry Shachnev 3# 4# This program is free software: you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation, either version 2 of the License, or 7# (at your option) any later version. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17def get_from_xsettings(): 18 from ReText.xsettings import get_xsettings, XSettingsError 19 try: 20 xsettings = get_xsettings() 21 except XSettingsError: 22 return 23 if b'Net/IconThemeName' in xsettings: 24 return xsettings[b'Net/IconThemeName'].decode() 25 if b'Net/FallbackIconTheme' in xsettings: 26 return xsettings[b'Net/FallbackIconTheme'].decode() 27 28def get_from_gsettings(): 29 try: 30 from gi.repository import Gio 31 except ImportError: 32 return 33 schema = 'org.gnome.desktop.interface' 34 if schema in Gio.Settings.list_schemas(): 35 settings = Gio.Settings.new(schema) 36 return settings.get_string('icon-theme') 37 38def get_from_gtk(): 39 try: 40 from gi import require_version 41 require_version('Gtk', '3.0') 42 from gi.repository import Gtk 43 except (ImportError, ValueError): 44 return 45 settings = Gtk.Settings.get_default() 46 return settings.get_property('gtk-icon-theme-name') 47 48def get_icon_theme(): 49 return (get_from_xsettings() 50 or get_from_gsettings() 51 or get_from_gtk()) 52