Focando uma instância específica do aplicativo por código?

0

Estou escrevendo um aplicativo usando Python e GTK3. Este aplicativo abrirá instâncias de outros aplicativos, como o GEdit. Agora, também quero que meu aplicativo seja capaz de focar cada uma dessas instâncias. Meu aplicativo é especificamente direcionado ao Unity.

Como faço isso?

    
por Jo-Erlend Schinstad 14.03.2012 / 02:15

1 resposta

1

Ok, acontece que a troca de janelas é muito fácil.

#!/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())

Vou melhorar essa resposta conforme aprendo.

    
por Jo-Erlend Schinstad 20.03.2012 / 18:35