Added Window class.

This commit is contained in:
Cory Walker 2011-06-30 17:30:36 -04:00
parent 1eb75708a9
commit 2018a7d18b
2 changed files with 57 additions and 0 deletions

View File

@ -1,8 +1,13 @@
from py_xdotool import * from py_xdotool import *
from time import sleep from time import sleep
print getactivewindow()
print search(name="System Monitor")
print search(name="System Monitor", onlyvisible=True)[0].get_name()
'''
mousemove(0, 0) mousemove(0, 0)
sleep(1) sleep(1)
click_at(100, 100, 3) click_at(100, 100, 3)
sleep(1) sleep(1)
click_at(500, 100, 1) click_at(500, 100, 1)
'''

View File

@ -1,5 +1,57 @@
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
class Window:
def __init__(self, wid):
assert type(wid) == int
self.wid = wid
def get_wid(self):
return self.wid
def get_pid(self):
c = "getwindowpid %d" % self.wid
return int(run_command(c))
def get_name(self):
c = "getwindowname %d" % self.wid
return run_command(c)
def activate(self):
c = "windowactivate %d" % self.wid
return run_command(c)
def focus(self):
c = "windowfocus %d" % self.wid
return run_command(c)
def getactivewindow():
c = "getactivewindow"
wid = int(run_command(c))
return Window(wid)
def get_windows(wids):
windows = []
for wid in wids:
windows.append(Window(wid))
return windows
def search(**kwargs):
c = "search"
noargs = ["onlyvisible", "class", "classname", "all", "any", "sync"]
for arg in noargs:
if arg in kwargs:
if kwargs[arg]:
c += " --%s" % arg
if "name" in kwargs:
c += ' --name "%s"' % kwargs['name']
if "pid" in kwargs:
c += " --pid %s" % kwargs['pid']
str_wids = run_command(c).split()
wids = []
for str_wid in str_wids:
wids.append(int(str_wid))
return get_windows(wids)
def mousemove(x, y): def mousemove(x, y):
c = "mousemove %d %d" % (x, y) c = "mousemove %d %d" % (x, y)
return run_command(c) return run_command(c)