python文本框焦点设置_python-wnck将焦点设置为窗口(python-wnck set focus to window)

I'm trying to set focus to a window using python-wnck.

The only docs I could find related to this library are from https://developer.gnome.org/libwnck/stable/WnckWindow.html

Using some code I found on another question here at SO, I was able to search for windows using the window title, but I'm not sure how to get a window to focus.

From the above docs I found the function:

wnck_window_activate(WnckWindow *window, guint32 timestamp);

So in python I tried using this function like "window.activate(0)", but this appears to fail, the icon on my taskbar flashed but it doesn't get focus.

In the terminal I get the message:

(windowTest.py:17485): Wnck-WARNING: Received a timestamp of 0; window activation may not function properly

So I think I may actually need to put in a valid timestamp but not sure how to get this.

This is the code Im using sofar:

import pygtk

pygtk.require('2.0')

import gtk

import wnck

import re

import sys

screen = wnck.screen_get_default()

while gtk.events_pending():

gtk.main_iteration()

titlePattern = re.compile('.*Geany.*')

windows = screen.get_windows()

for w in windows:

if titlePattern.match(w.get_name()):

print w.get_name()

w.activate(0)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值