如何在linux / windows中获取运行app的图标/图标路径? [英] How to get icon/icon's path of running app in linux/windows?

查看:472
本文介绍了如何在linux / windows中获取运行app的图标/图标路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个打开的窗口及其图标的列表,并使用python处理它。
我以为我和xprop和wmctrl很接近,但我不能用它来达到我的目的。
我可以使用 wmctrl -l <​​/ code>获取打开的窗口列表,但不知道如何获得任何列出的控件的图标/图标路径。

I'd like to have a list of open windows and its icons and process it with python. I thought I was close with xprop and wmctrl, but I can't use it for my purpose. I can get a list of open windows with wmctrl -l, but no idea how get an icon/icon path for any of the listed controls.

请帮助:)

推荐答案

您可以使用模块wnck和gtk 。

You can use the module wnck and gtk.

例如:

import pygtk  
pygtk.require('2.0')  
import gtk  
import wnck  

screen = wnck.screen_get_default()  

while gtk.events_pending():  
    gtk.main_iteration(False)  

for w in screen.get_windows():  
    name = w.get_name()  
    icon = w.get_icon()
    ...

其中 name 是一个字符串而 icon 是一个GdkPixbuf。

Where name is a string and icon is a GdkPixbuf.

您可以在 libwnck 的API文档.gnome.org / libwnck / stable / WnckWindow.htmlrel =nofollow noreferrer> http://developer.gnome.org/libwnck/stable/WnckWindow.html ,适用于C. H但是,对于Python,您只需要删除前缀wncK_window。如果文档说wnck_window_get_name(),那么在Python中将是my_window.get_name()。

You can read the API documentation for libwnck at http://developer.gnome.org/libwnck/stable/WnckWindow.html, which is for C. However, for Python you only have to remove the prefix wncK_window. If the documentation say wnck_window_get_name(), then in Python would be my_window.get_name().

libwnk 特定于XWindow,因此你可以不要在MS Windows上使用它。在这种情况下,您可以使用其他精确帮助的模块。检查获取Python中打开窗口列表

libwnk is specific to XWindow, hence you can not use it on MS Windows. In that case, you can use other modules that precisely helps on that. Check the answer for Get list of open windows in Python

这篇关于如何在linux / windows中获取运行app的图标/图标路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆