How to get icon/icon's path of running app in linux/windows?

谁说胖子不能爱 提交于 2019-12-24 10:10:02

问题


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.

Please, help :)


回答1:


You can use the module wnck and gtk.

For instance:

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()
    ...

Where name is a string and icon is a GdkPixbuf.

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 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



来源:https://stackoverflow.com/questions/5810399/how-to-get-icon-icons-path-of-running-app-in-linux-windows

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