takes a screenshot of the users desktop (Currently Win only)
9065
def screenshot(fname):
    
    try:
        im = ImageGrab.grab()
        im.save(fname)
    except Exception as ex:
        print('image_tools.screenshot:cant create screenshot ' + str(ex))
219001
def take_reference_screenshot(webdriver, file_name):
        
        folder_location = os.path.join(ProjectUtils.get_project_root(),
                                       WebScreenShotUtil.REFERENCE_SCREEN_SHOT_LOCATION)

        WebScreenShotUtil.__capture_screenshot(
            webdriver, folder_location, file_name + ".png")
1252704
def desktop_interface(name,
                      user=None,
                      automatic_mnemonics=None,
                      buttons_have_icons=None,
                      can_change_accels=None,
                      clock_format=None,
                      clock_show_date=None,
                      clock_show_seconds=None,
                      cursor_blink=None,
                      cursor_blink_time=None,
                      cursor_blink_timeout=None,
                      cursor_size=None,
                      cursor_theme=None,
                      document_font_name=None,
                      enable_animations=None,
                      font_name=None,
                      gtk_color_palette=None,
                      gtk_color_scheme=None,
                      gtk_im_module=None,
                      gtk_im_preedit_style=None,
                      gtk_im_status_style=None,
                      gtk_key_theme=None,
                      gtk_theme=None,
                      gtk_timeout_initial=None,
                      gtk_timeout_repeat=None,
                      icon_theme=None,
                      menubar_accel=None,
                      menubar_detachable=None,
                      menus_have_icons=None,
                      menus_have_tearoff=None,
                      monospace_font_name=None,
                      show_input_method_menu=None,
                      show_unicode_menu=None,
                      text_scaling_factor=None,
                      toolbar_detachable=None,
                      toolbar_icons_size=None,
                      toolbar_style=None,
                      toolkit_accessibility=None,
                      **kwargs):
    '''
    
    '''
    gnome_kwargs = {
        'user': user,
        'schema': 'org.gnome.desktop.interface'
    }

    preferences = ['automatic_mnemonics', 'buttons_have_icons',
            'can_change_accels', 'clock_format', 'clock_show_date',
            'clock_show_seconds', 'cursor_blink', 'cursor_blink_time',
            'cursor_blink_timeout', 'cursor_size', 'cursor_theme',
            'document_font_name', 'enable_animations', 'font_name',
            'gtk_color_palette', 'gtk_color_scheme', 'gtk_im_module',
            'gtk_im_preedit_style', 'gtk_im_status_style', 'gtk_key_theme',
            'gtk_theme', 'gtk_timeout_initial', 'gtk_timeout_repeat',
            'icon_theme', 'menubar_accel', 'menubar_detachable',
            'menus_have_icons', 'menus_have_tearoff', 'monospace_font_name',
            'show_input_method_menu', 'show_unicode_menu',
            'text_scaling_factor', 'toolbar_detachable', 'toolbar_icons_size',
            'toolbar_style', 'toolkit_accessibility']

    preferences_hash = {}
    for pref in preferences:
        if pref in locals() and locals()[pref] is not None:
            key = re.sub('_', '-', pref)
            preferences_hash[key] = locals()[pref]

    return _do(name, gnome_kwargs, preferences_hash)
1316333
def _take_screenshot(self, screenshot=False, name_prefix='unknown'):
        
        if isinstance(screenshot, bool):
            if not screenshot:
                return
            return self._save_screenshot(name_prefix=name_prefix)
        if isinstance(screenshot, Image.Image):
            return self._save_screenshot(screen=screenshot, name_prefix=name_prefix)

        raise TypeError("invalid type for func _take_screenshot: "+ type(screenshot))
158822
def grant_winsta_and_desktop(th):
    '''
    
    '''
    current_sid = win32security.GetTokenInformation(th, win32security.TokenUser)[0]
    # Add permissions for the sid to the current windows station and thread id.
    # This prevents windows error 0xC0000142.
    winsta = win32process.GetProcessWindowStation()
    set_user_perm(winsta, WINSTA_ALL, current_sid)
    desktop = win32service.GetThreadDesktop(win32api.GetCurrentThreadId())
    set_user_perm(desktop, DESKTOP_ALL, current_sid)
48878
static Screenshot getScreenshot(File screenshot, File output) {
    String relativePath = createRelativeUri(screenshot, output);
    String caption = screenshot.getName();
    return new Screenshot(relativePath, caption);
  }
900190
def capture_guest(userid):
    
    # check power state, if down, start it
    ret = sdk_client.send_request('guest_get_power_state', userid)
    power_status = ret['output']
    if power_status == 'off':
        sdk_client.send_request('guest_start', userid)
        # TODO: how much time?
        time.sleep(1)

    # do capture
    image_name = 'image_captured_%03d' % (time.time() % 1000)
    sdk_client.send_request('guest_capture', userid, image_name,
                            capture_type='rootonly', compress_level=6)
    return image_name
747858
def get_current_desktop(self):
        
        desktop = ctypes.c_long(0)
        _libxdo.xdo_get_current_desktop(self._xdo, ctypes.byref(desktop))
        return desktop.value
608647
def take_quality_screenshot(self, screenshot_name):
        
        self.info_log("Taking a quality screenshot...")

        if self.test_instance._runner_dir:
            _screenshot_name = '%s.png' % string_to_filename(screenshot_name)
            relative_path = os.path.join(
                    self.test_instance._quality_screenshot_relative_dir,
                    _screenshot_name
                )

            full_path = os.path.join(
                    self.test_instance._quality_screenshot_dir,
                    _screenshot_name
                )
            self._driver.save_screenshot(
                full_path
            )

            with DbSessionContext(BROME_CONFIG['database']['mongo_database_name']) as session:  # noqa
                capabilities = {
                    'browserName': self.capabilities['browserName'],
                    'platform': self.capabilities['platform'],
                    'version': self.capabilities['version']
                }
                quality_screenshot = Testqualityscreenshot()
                quality_screenshot.timestamp = utcnow()
                quality_screenshot.browser_capabilities = capabilities
                quality_screenshot.browser_id = self.get_id()
                quality_screenshot.file_path = relative_path
                # TODO support s3
                quality_screenshot.location = 'local_file_system'
                quality_screenshot.root_path = self.test_instance._runner.root_test_result_dir  # noqa
                quality_screenshot.extra_data = {}
                quality_screenshot.title = screenshot_name
                quality_screenshot.test_instance_id = self.test_instance._test_instance_id  # noqa
                quality_screenshot.test_batch_id = self.test_instance._test_batch_id  # noqa

                session.save(quality_screenshot, safe=True)

            self.debug_log("Quality screenshot taken (%s)" % full_path)
1037769
def web_screenshot(url, outfile, browser=None):
    """"""

    valid_browsers = ['firefox', 'chromium-browser']
    available_browsers = [ b for b in valid_browsers if which(b) ]

    if not available_browsers:
        print("You don't have firefox or chromium-browser in your PATH".format(browser), file=sys.stderr)
        return False

    if not browser:
        browser = available_browsers[0]

    if browser not in available_browsers:
        print("You don't have {} in your PATH".format(browser), file=sys.stderr)
        return False

    #screenshot_cmd = ''
    #profile_firefox = shlex.split('firefox --new-instance --CreateProfile habu.web.screenshot')
    #screenshot_firefox = shlex.split('firefox --new-instance --headless -P habu.web.screenshot --screenshot {} {}'.format(outfile, url))
    #screenshot_chromium = shlex.split('chromium-browser --headless --disable-gpu --window-size=1440,900 --screenshot={} {}'.format(outfile, url))

    if browser == 'firefox':
        profile_firefox = shlex.split('firefox --new-instance --CreateProfile habu.web.screenshot')
        subprocess.Popen(profile_firefox, stderr=subprocess.DEVNULL)
        screenshot_cmd = shlex.split('firefox --new-instance --headless -P habu.web.screenshot --screenshot {} {}'.format(outfile, url))

    if browser == 'chromium-browser':
        screenshot_cmd = shlex.split('chromium-browser --headless --disable-gpu --window-size=1440,900 --screenshot={} {}'.format(outfile, url))

    outfile = Path(outfile)
    if outfile.is_file():
        outfile.unlink()

    with subprocess.Popen(screenshot_cmd, stderr=subprocess.DEVNULL) as proc:

        for count in range(DURATION):

            sleep(1)

            if outfile.is_file():
                break

            if count == DURATION - 1:
                print("Unable to create screenshot", file=sys.stderr)
                break

        proc.kill()

    return True
601150
def screenshot(self, filename=None):
        
        tmpfile = tempfile.mktemp(prefix='atx-screencap-', suffix='.tiff')
        try:
            idevice("screenshot", "--udid", self.udid, tmpfile)
        except subprocess.CalledProcessError as e:
            sys.exit(e.message)

        try:
            image = Image.open(tmpfile)
            image.load()
            if filename:
                image.save(filename)
            return image
        finally:
            if os.path.exists(tmpfile):
                os.unlink(tmpfile)
1288850
def run(self):
        """"""
        self.state = True
        if self.capture:
            self.display2.screen().root.grab_keyboard(X.KeyPressMask | X.KeyReleaseMask, X.GrabModeAsync, X.GrabModeAsync, X.CurrentTime)

        self.display2.record_enable_context(self.ctx, self.handler)
        self.display2.record_free_context(self.ctx)
669177
def clean():
        """"""
        screenshot_dir = settings.SELENIUM_SCREENSHOT_DIR
        if screenshot_dir and os.path.isdir(screenshot_dir):
            rmtree(screenshot_dir, ignore_errors=True)
391522
def _redraw_screen(self, stdscr):
        """"""
        with self._lock:
            stdscr.clear()
            stdscr.addstr(
                0, 0, "workflows service monitor -- quit with Ctrl+C", curses.A_BOLD
            )
            stdscr.refresh()
            self.message_box = self._boxwin(
                5, curses.COLS, 2, 0, title="last seen message", color_pair=1
            )
            self.message_box.scrollok(True)
            self.cards = []
187360
def screensaver():
    '''
    
    '''
    cmd = 'open /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app'
    call = __salt__['cmd.run_all'](
        cmd,
        output_loglevel='debug',
        python_shell=False
    )
    _check_cmd(call)

    return True
637210
def set_win_wallpaper(img):
    """"""
    # There's a different command depending on the architecture
    # of Windows. We check the PROGRAMFILES envar since using
    # platform is unreliable.
    if "x86" in os.environ["PROGRAMFILES"]:
        ctypes.windll.user32.SystemParametersInfoW(20, 0, img, 3)
    else:
        ctypes.windll.user32.SystemParametersInfoA(20, 0, img, 3)
813645
def __capture_screenshot(webdriver, folder_location, file_name):
        ""
        # Check folder location exists.
        if not os.path.exists(folder_location):
            os.makedirs(folder_location)

        file_location = os.path.join(folder_location, file_name)

        if isinstance(webdriver, remote.webdriver.WebDriver):
            # If this is a remote webdriver.  We need to transmit the image data
            # back across system boundries as a base 64 encoded string so it can
            # be decoded back on the local system and written to disk.
            base64_data = webdriver.get_screenshot_as_base64()
            screenshot_data = base64.decodestring(base64_data)
            screenshot_file = open(file_location, "wb")
            screenshot_file.write(screenshot_data)
            screenshot_file.close()
        else:
            webdriver.save_screenshot(file_location)