Esempio n. 1
0
def init():
    global refimgpath
    if not refimgpath:
        d = tempfile.mkdtemp(prefix="fillscreen")
        d = Path(d)
        atexit.register(d.rmtree)
        refimgpath = d / "ref.png"

        if not platform_is_win():  # TODO: win image viewer
            im = generate_image()
            im.save(refimgpath)
            cmd = [
                "pqiv",
                "--fullscreen",
                "--hide-info-box",
                "--disable-scaling",
                refimgpath,
            ]
            proc = EasyProcess(cmd).start()
            atexit.register(proc.stop)
            print(refimgpath)
            sleep(5)  # TODO: check image displayed
            if not proc.is_alive():
                raise FillscreenError("pqiv stopped: %s" % proc)

        # if the OS has color correction
        #  then the screenshot has slighly different color than the original image
        # TODO: color correction: linux? win?
        if platform_is_win() or platform_is_osx():
            refimgpath = refimgpath + ".pil.png"
            im = pyscreenshot.grab(backend="pil")
            im.save(refimgpath)
            log.debug("%s saved", refimgpath)

    return refimgpath
Esempio n. 2
0
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
Esempio n. 3
0
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()
Esempio n. 4
0
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
Esempio n. 5
0
def init():
    global refimgpath
    if not refimgpath:
        d = tempfile.mkdtemp(prefix="fillscreen")
        atexit.register(lambda: rmtree(d))
        refimgpath = join(d, "ref.png")

        im = generate_image()
        im.save(refimgpath)

        if platform_is_win():
            cmd = [
                "C:\\Program Files (x86)\\FastStone Image Viewer\\FSViewer.exe",
                refimgpath,
            ]
        else:
            cmd = [
                "pqiv",
                "--fullscreen",
                "--hide-info-box",
                "--disable-scaling",
                refimgpath,
            ]
        proc = EasyProcess(cmd).start()
        atexit.register(proc.stop)
        print(refimgpath)
        sleep(5)  # wait for image displayed
        if not proc.is_alive():
            raise FillscreenError("pqiv stopped: %s" % proc)

        # if the OS has color correction
        #  then the screenshot has slighly different color than the original image
        if platform_is_win() or platform_is_osx():
            refimgpath = refimgpath + ".pil.png"
            im = pyscreenshot.grab(backend="pil")
            im.save(refimgpath)
            log.debug("%s saved", refimgpath)

    return refimgpath
Esempio n. 6
0
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")