Added a ton more functions.
This commit is contained in:
parent
2018a7d18b
commit
cbfdf1356f
2
README
2
README
|
@ -1,4 +1,6 @@
|
|||
py_xdotool is a Python wrapper for the xdotool utility:
|
||||
http://www.semicomplete.com/projects/xdotool/
|
||||
|
||||
Requires: xdotool, python-imaging, python-xlib
|
||||
|
||||
Only a very small subset of the functions are supported. Feel free to add any others!
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
from py_xdotool import *
|
||||
from time import sleep
|
||||
|
||||
print getactivewindow()
|
||||
active = get_active_window()
|
||||
print 'bla', active.get_geometry()
|
||||
|
||||
print get_pixel_color(0, 0)
|
||||
print search(name="System Monitor")
|
||||
print search(name="System Monitor", onlyvisible=True)[0].get_name()
|
||||
print search(name="System Monitor", onlyvisible=True)[0].get_pid()
|
||||
'''
|
||||
mousemove(0, 0)
|
||||
sleep(1)
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
from subprocess import Popen, PIPE
|
||||
import PIL.Image # python-imaging
|
||||
import PIL.ImageStat # python-imaging
|
||||
import Xlib.display # python-xlib
|
||||
|
||||
class Window:
|
||||
def __init__(self, wid):
|
||||
|
@ -15,6 +18,19 @@ class Window:
|
|||
def get_name(self):
|
||||
c = "getwindowname %d" % self.wid
|
||||
return run_command(c)
|
||||
|
||||
def get_geometry(self):
|
||||
# TODO: should be parsed into Python objects
|
||||
c = "getwindowgeometry %d" % self.wid
|
||||
return run_command(c)
|
||||
|
||||
def set_size(self, width, height):
|
||||
c = "windowsize %d %d %d" % (self.wid, width, height)
|
||||
return run_command(c)
|
||||
|
||||
def move(self, x, y):
|
||||
c = "windowmove %d %d %d" % (self.wid, x, y)
|
||||
return run_command(c)
|
||||
|
||||
def activate(self):
|
||||
c = "windowactivate %d" % self.wid
|
||||
|
@ -23,8 +39,33 @@ class Window:
|
|||
def focus(self):
|
||||
c = "windowfocus %d" % self.wid
|
||||
return run_command(c)
|
||||
|
||||
def screen_map(self):
|
||||
c = "windowmap %d" % self.wid
|
||||
return run_command(c)
|
||||
|
||||
def minimize(self):
|
||||
c = "windowminimize %d" % self.wid
|
||||
return run_command(c)
|
||||
|
||||
def kill(self):
|
||||
c = "windowkill %d" % self.wid
|
||||
return run_command(c)
|
||||
|
||||
# Lifted from http://rosettacode.org/wiki/Color_of_a_screen_pixel
|
||||
def get_pixel_color(i_x, i_y):
|
||||
o_x_root = Xlib.display.Display().screen().root
|
||||
o_x_image = o_x_root.get_image(i_x, i_y, 1, 1, Xlib.X.ZPixmap, 0xffffffff)
|
||||
o_pil_image_rgb = PIL.Image.fromstring("RGB", (1, 1), o_x_image.data, "raw", "BGRX")
|
||||
lf_colour = PIL.ImageStat.Stat(o_pil_image_rgb).mean
|
||||
return tuple(map(int, lf_colour))
|
||||
|
||||
def getactivewindow():
|
||||
def get_focused_window():
|
||||
c = "getactivewindow"
|
||||
wid = int(run_command(c))
|
||||
return Window(wid)
|
||||
|
||||
def get_active_window():
|
||||
c = "getactivewindow"
|
||||
wid = int(run_command(c))
|
||||
return Window(wid)
|
||||
|
@ -52,7 +93,7 @@ def search(**kwargs):
|
|||
wids.append(int(str_wid))
|
||||
return get_windows(wids)
|
||||
|
||||
def mousemove(x, y):
|
||||
def mouse_move(x, y):
|
||||
c = "mousemove %d %d" % (x, y)
|
||||
return run_command(c)
|
||||
|
||||
|
@ -61,7 +102,7 @@ def click(btn):
|
|||
return run_command(c)
|
||||
|
||||
def click_at(x, y, btn):
|
||||
mousemove(x, y)
|
||||
mouse_move(x, y)
|
||||
return click(btn)
|
||||
|
||||
def run_command(c):
|
||||
|
|
Loading…
Reference in New Issue