How to get the current Linux theme with Python?

六月ゝ 毕业季﹏ 提交于 2020-05-29 11:27:06

问题


I need to get the current Icon Theme in the system. The problem is that there are a lot of environments as GNOME, XFCE, MATE...

Please, how could I get the current Icon Theme? I'm thinking that it'll be with Gtk.IconTheme.get_default(), but I didn't get a good result.

Thanks in advance!


回答1:


Unfortunately, there is no universal solution for all systems.

You will need to use different approaches depending on the environment, and then most likely include a switch depending on the present environment. It will take some research... In modern gtk3 environments you can query and change basically any setting quite conveniently via gsettings. For example, in GNOME:

gsettings get org.gnome.desktop.interface icon-theme

will return the current icon-theme.
In Cinnamon, you can query similarly with:

gsettings get org.cinnamon.desktop.interface icon-theme

in Mate, the key icon-theme would be defined in schema org.mate.interface, and under Xfce the available tool is xfconf-query:

xfconf-query -lvc xsettings -p /Net/ThemeName

With window managers you can read the appropriate config files like for example gtk-icon-theme-name= from $HOME/.gtkrc-2.0,
or it might even be defined in ~/.Xresources, or (rather outdated) in $HOME/gtk-3.0/settings.ini, possibly also in $HOME/.config/qt5ct/qt5ct.conf ;) ... and so on :)



来源:https://stackoverflow.com/questions/28779868/how-to-get-the-current-linux-theme-with-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!