0

I'm writing an application using Python and GTK3. This application will open instances of other applications, such as GEdit. Now, I'd also want my application to be able to focus each of those instances. My application is specifically targeted at Unity.

How do I do this?

1

1 Answer 1

1

Ok, so it turns out that actually switching windows is very easy.

#!/usr/bin/env python

# This code will focus the window with integer id 67108870
# Tips: you can get that with xwininfo -int

# wnck is used for window management
import wnck

# time is needed because wnck requires it
import time

# Get information about windows, workspaces, etc from the X server
wnck.screen_get_default()

# Get a reference to the window we want to focus
# by providing an integer xid
the_win = wnck.window_get(67108870)

# activate the window, providing an int timestamp
the_win.activate(int(time.time())

I'll improve on this answer as I learn.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .