Core Question:
How to turn mimetype - image/png
in to actual path to an icon file - /usr/share/icons/Menda-Circle/mimetypes/24x24/application-image-png.svg
如何将mimetype - image / png转换为图标文件的实际路径 - /usr/share/icons/Menda-Circle/mimetypes/24x24/application-image-png.svg
while respecting linux distros DE's icon theme set?
尊重Linux发行版DE的图标主题集?
Own Progress:
mimetypes.guess_type() will get me easily mimetype of a file based on the filename which is OKish.
mimetypes.guess_type()会根据文件名很容易地给我一个文件的mimetype。
Whats not so easy is translating that mimetype in to a path that leads to an icon
什么不是那么容易将mimetype转换为导致图标的路径
so far I had no luck progressing with linux own xdg-utils, or pyxdg in detecting icon theme or moving beyond that. PyQt5 seems to have trouble as well, which is understandable when most DEs are not Qt based. Maybe on KDE it will get something.
到目前为止,我没有幸运使用linux自己的xdg-utils,或pyxdg在检测图标主题或超越它。 PyQt5似乎也有问题,当大多数DE不是基于Qt时,这是可以理解的。也许在KDE上会得到一些东西。
So with some googling I can use this to detect icon theme through Gtk
所以通过一些谷歌搜索,我可以使用它通过Gtk检测图标主题
from gi.repository import Gtk
print(Gtk.Settings.get_default().get_property("gtk-icon-theme-name"))
Well thats where I am now, and I guess with some work and adjusting for all cases I could come up with some function to get the icons on most common distros/DE and for most common icon themes. Assuming I figure out the patern translating mimetype in to an icon file name.
那就是我现在所处的位置,我想通过一些工作并调整所有情况,我可以想出一些功能来获取最常见的发行版/ DE和最常见的图标主题上的图标。假设我想出了将模仿类型转换为图标文件名的模式。
But this all feels like it should be done and done already. That its some freedesktop standard and every file manager or any program with a file picker or displaying of files and folders is using this functionality no?
但这一切都感觉应该已经完成并完成了。它的一些freedesktop标准和每个文件管理器或任何带有文件选择器或显示文件和文件夹的程序都使用此功能吗?
Is there some nice elegant way to go about this?
有一些很好的方式来解决这个问题吗?
1 个解决方案
#1
2
Gio's ContentType handles getting a files type and its icon for you:
Gio的ContentType处理为您获取文件类型及其图标:
https://lazka.github.io/pgi-docs/#Gio-2.0/functions.html#Gio.content_type_get_icon
#1
2
Gio's ContentType handles getting a files type and its icon for you:
Gio的ContentType处理为您获取文件类型及其图标:
https://lazka.github.io/pgi-docs/#Gio-2.0/functions.html#Gio.content_type_get_icon