def display_size(): if platform_is_osx(): from Quartz import CGDisplayBounds from Quartz import CGMainDisplayID mainMonitor = CGDisplayBounds(CGMainDisplayID()) return int(mainMonitor.size.width), int(mainMonitor.size.height) if platform_is_win(): from win32api import GetSystemMetrics return int(GetSystemMetrics(0)), int(GetSystemMetrics(1)) if platform_is_linux(): # http://www.cyberciti.biz/faq/how-do-i-find-out-screen-resolution-of-my-linux-desktop/ # xdpyinfo | grep 'dimensions:' screen_width, screen_height = 0, 0 xdpyinfo = EasyProcess("xdpyinfo") xdpyinfo.enable_stdout_log = False if xdpyinfo.call().return_code != 0: raise ValueError("xdpyinfo error: %s" % xdpyinfo) for x in xdpyinfo.stdout.splitlines(): if "dimensions:" in x: screen_width, screen_height = map(int, x.strip().split()[1].split("x")) return screen_width, screen_height
def display_size(): if platform_is_osx(): return display_size_osx() if platform_is_win(): return display_size_win() if platform_is_linux(): return display_size_x()
def backends(childprocess): # the order is based on performance if platform_is_linux(): if use_x_display(): if childprocess: yield ScrotWrapper yield PilWrapper yield MssWrapper else: yield PilWrapper yield MssWrapper yield ScrotWrapper yield MaimWrapper yield ImagemagickWrapper yield Gdk3PixbufWrapper yield WxScreen for x in qt(): yield x yield GnomeDBusWrapper # on screen notification yield KwinDBusWrapper # flash effect yield GnomeScreenshotWrapper yield GrimWrapper elif platform_is_osx(): # first check for X if use_x_display(): pass else: # fast yield MssWrapper # latest version should work yield PilWrapper # alternatives for older pillow versions yield ScreencaptureWrapper yield MacQuartzWrapper # qt has some color difference # does not work: Gdk3, wx, Imagemagick elif platform_is_win(): # fast yield MssWrapper yield PilWrapper else: for x in backend_dict.values(): yield x
def backend_to_check(backend, delay=0): refimgpath = fillscreen.init() backend_ref(backend, childprocess=True, refimgpath=refimgpath, delay=delay) # childprocess=False is tested in a subprocess for isolation cmd = [ sys.executable, __file__.rsplit(".", 1)[0] + ".py", backend if backend else "", refimgpath, str(delay), "--debug", ] p = EasyProcess(cmd).call() assert p.return_code == 0 if platform_is_linux() and prog_check(["Xvfb", "-help"]): check_double_disp(backend)
except ImportError: display = None # https://github.com/python-xlib/python-xlib/blob/master/examples/xrandr.py#L44 def missing_RANDR(): if display: return False disp = display.Display() return not disp.has_extension("RANDR") ok = False if not six.PY2 and check_import("mss"): if platform_is_osx() and not use_x_display(): ok = True if platform_is_linux() and use_x_display(): ok = True if platform_is_win(): ok = True if ok: def test_mss(): if missing_RANDR(): try: backend_to_check("mss") except FailedBackendError: pass else: backend_to_check("mss")
from bt import backend_to_check from pyscreenshot.util import platform_is_linux if not platform_is_linux(): def test_pil(): backend_to_check("pil")
def missing_RANDR(): if not platform_is_linux(): return False disp = display.Display() return not disp.has_extension("RANDR")