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 desktop!
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 desktop!
You probably want to use libwnck:
http://library.gnome.org/devel/libwnck/stable/
I believe there are python bindings in python-gnome or some similar package.
Once you have the GTK+ mainloop running, you can do the following:
Some interesting methods on a window from that list are get_name() and activate().
This will print the names of windows to the console when you click the button. But for some reason I had to click the button twice. This is my first time using libwnck so I'm probably missing something. :-)
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: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 correspondinggir
binding out of the box, but if you need to install them:This will also install
libwnck-3-dev
, which is not necessary but will install useful documentation you can read using DevHelpFor whatever reason, I can't post a comment, but I'd like to add this as an addendum to Sandy's answer.
Here's a chunk of code that lists the current windows on the console:
Thanks Sandy!
Parsing command line output is usually not the best way, you are dependent on that programs output not changing, which could vary from version or platfrom. Here is how to do it using Xlib:
Note that this list will contain windows that you wouldn't normally classify as 'windows', but that doesn't matter for what you are trying to do.
From the PyGTK reference:
I really don't know how to check if a window is a GTK one. But if you want to check how many windows are currently open try "wmctrl -l". Install it first of course.