Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
could be very helpful. combine the two - stackoverflow.com/questions/3332043/… ... stackoverflow.com/questions/151407/… –  hbdgaf Mar 14 '12 at 4:28

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.