How to get list opened windows in PyGTK or GTK in Ubuntu?

前端 未结 6 1927
说谎
说谎 2020-12-30 10:37

How to get list opened windows in PyGTK or GTK or other programming language? in Ubuntu?

edit:

i want get list paths opened directories on

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 11:16

    Welcome to 2013! Here's the code using Wnck and its modern GObject Introspection libraries instead of the now deprecated PyGTK method. You may also check my other answer about wnck:

    from gi.repository import Gtk, Wnck
    
    Gtk.init([])  # necessary only if not using a Gtk.main() loop
    screen = Wnck.Screen.get_default()
    screen.force_update()  # recommended per Wnck documentation
    
    # loop all windows
    for window in screen.get_windows():
        print window.get_name()
        # ... do whatever you want with this window
    
    # clean up Wnck (saves resources, check documentation)
    window = None
    screen = None
    Wnck.shutdown()
    

    As for documentation, check out the Libwnck Reference Manual. It is not specific for python, but the whole point of using GObject Introspection is to have the same API across all languages, thanks to the gir bindings.

    Also, Ubuntu ships with both wnck and its corresponding gir binding out of the box, but if you need to install them:

    sudo apt-get install libwnck-3-* gir1.2-wnck-3.0
    

    This will also install libwnck-3-dev, which is not necessary but will install useful documentation you can read using DevHelp

提交回复
热议问题