-
Notifications
You must be signed in to change notification settings - Fork 1
libs.screen
Screen abstraction layer.
-
Most methods accept input arguments in several formats:
-
points can be passed as
do(x, y)
ordo(point)
, wherepoint
is a tuple / list ofx
andy
. -
boxes can be passed as
do(left, top, right, bottom)
ordo(from_point, to_point)
ordo(rect)
, whererect
is a tuple / list ofleft
,top
,right
andbottom
.
-
-
Images returned by methods are instances of Image class.
-
Windows - all methods (need tests) (requires:
PIL
,ctypes
); -
Unix - all methods (requires:
gtk
,PIL
,Xlib
); -
Mac - not supported;
from libs import screen
# dimensions:
print screen.size # > (1440, 900)
print screen.width # > 1440
print screen.height # > 900
print screen.center # > (720, 450)
# retrieving data from screen:
print screen.pixel(100, 100) # > (150, 191, 226)
c = screen.center
print screen.pixel(c) # > (35, 35, 35)
sshot = screen.shot() # capture entire screen
sshot.show() # show it
sshot.save('blabla.png') # save it
print dir(sshot) # show what else it can do
p1 = (c[0] - 100, c[1] - 100) # upper left point > (620, 350)
p2 = (c[0] + 100, c[1] + 100) # lower bottom point > (820, 550)
sshot = screen.shot(p1, p2) # capture 200×200 area
box = p1 + p2 # > (620, 350, 820, 550)
sshot = screen.shot(box) # capture 200×200 area again
# Image API: http://www.pythonware.com/library/pil/handbook/image.htm
# searching on the screen:
color = (150, 191, 226) # we got it earlier in (100, 100)
print screen.find(color) # > (100, 100) - yep, it's still there
print screen.locate(color) # > [(100, 100), (223, 100), (1084, 869)]
print screen.locate(color, p1) # > [(1084, 869)]
print screen.locate(color, p1, p2) # > []
print screen.find(color, box) # > None
# testing:
print screen.test(color, 100, 100) # > True
print screen.test(color, [223, 100]) # > True
print screen.test(color, c) # > False
print screen.test(sshot, p1) # > True
print screen.test(sshot, p2) # > False
-
screen.size
Get current screen size in pixels.
Returns(width, height)
tuple of 2 integers.
Read-only property. -
screen.width
Get current screen width in pixels.
Returns integer.
Read-only property. -
screen.height
Get current screen height in pixels.
Returns integer.
Read-only property. -
screen.center
Get current screen center point.
Returns(x, y)
a tuple of 2 integers.
Read-only property. -
screen.pixel(x, y)
screen.pixel(point)
Get the color of given (x
,y
)-pixel (orpoint
) on the screen.
Returns(r, g, b)
tuple of 3 integers. -
screen.shot([left = 0, top = 0, right = screen.width, bottom = screen.height])
screen.shot([from_point, to_point])
screen.shot([box])
Get screenshot of the screen area.
ReturnsImage
object. -
screen.find(object, [left = 0, top = 0, right = screen.width, bottom = screen.height])
screen.find(object, [from_point, to_point])
screen.find(object, [box])
Ifobject
is(r,g,b)
-color - searches for the pixel of that color on the screen.
Ifobject
isImage
- searches for that image on the screen.
Stops on first match.
Returns position of found object as a tuple(x, y)
of 2 integers if found orNone
if search fails. -
screen.locate(object, [left = 0, top = 0, right = screen.width, bottom = screen.height])
screen.locate(object, [from_point, to_point])
screen.locate(object, [box])
Ifobject
is(r,g,b)
-color - searches for the pixels of that color on the screen.
Ifobject
isImage
- searches for that image on the screen.
Tries to find all occurences.
Returns positions of all found objects in a list of(x, y)
tuples for each occurrence, empty if search fails. -
screen.test(object, x, y)
screen.test(object, point)
Checks if a givenobject
is found in(x, y)
-positon on the screen.
object
can be(r,g,b)
-color orImage
.
ReturnsTrue
if it is,False
otherwise.