Renders and saves a screen-sized picture of the current position.

    :param cb: Cursebox instance.
    :type cb: cursebox.Cursebox
    :param params: Current application parameters.
    :type params: params.Params
195951
def capture(cb, pool, params):
    
    w, h = screen_resolution()

    # Re-adapt dimensions to match current plane ratio
    old_ratio = w / h
    new_ratio = params.plane_ratio
    if old_ratio > new_ratio:
        w = int(h * new_ratio)
    else:
        h = int(w / new_ratio)

    image = Image.new("RGB", (w, h), "white")
    pixels = image.load()

    # FIXME: refactor common code to get_palette(params)
    palette = PALETTES[params.palette][1]
    if params.reverse_palette:
        palette = palette[::-1]

    # All coordinates to be computed as single arguments for processes
    coords = [(x, y, w, h, params) for x in range(w) for y in range(h)]

    results = []
    # Dispatch work to pool and draw results as they come in
    for i, result in enumerate(pool.imap_unordered(compute_capture, coords, chunksize=256)):
        results.append(result)
        if i % 2000 == 0:
            draw_progress_bar(cb, "Capturing current scene...", i, w * h)
            cb.refresh()

    min_value = 0.0
    max_value = params.max_iterations
    max_iterations = params.max_iterations

    if params.adaptive_palette:
        from operator import itemgetter
        min_value = min(results, key=itemgetter(2))[2]
        max_value = max(results, key=itemgetter(2))[2]

    # Draw pixels
    for result in results:
        value = result[2]
        if params.adaptive_palette:
            # Remap values from (min_value, max_value) to (0, max_iterations)
            if max_value - min_value > 0:
                value = ((value - min_value) / (max_value - min_value)) * max_iterations
            else:
                value = max_iterations
        pixels[result[0], result[1]] = get_color(value, params.max_iterations, palette)

    if not os.path.exists("captures/"):
        os.makedirs("captures/")

    ts = datetime.datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d_%H-%M-%S")
    filename = "captures/almonds_%s.png" % ts
    image.save(filename, "PNG")
    params.log("Current scene captured!")
    params.log("(Used %d processes)" % pool._processes)

    open_file(filename)
274433
def _take_screenshot(self):
        
        raw_png = self._wda.screenshot()
        img = Image.open(BytesIO(raw_png))
        return img
9065
def screenshot(fname):
    
    try:
        im = ImageGrab.grab()
        im.save(fname)
    except Exception as ex:
        print('image_tools.screenshot:cant create screenshot ' + str(ex))
634512
def save_cb(self):
        """"""

        # This just defines the basename.
        # Extension has to be explicitly defined or things can get messy.
        w = Widgets.SaveDialog(title='Save plot')
        target = w.get_path()
        if target is None:
            # Save canceled
            return

        plot_ext = self.settings.get('file_suffix', '.png')

        if not target.endswith(plot_ext):
            target += plot_ext

        # TODO: This can be a user preference?
        fig_dpi = 100

        try:
            fig = self.tab_plot.get_figure()
            fig.savefig(target, dpi=fig_dpi)

        except Exception as e:
            self.logger.error(str(e))
        else:
            self.logger.info('Table plot saved as {0}'.format(target))
726663
def render(self, cli, layout, is_done=False):
        
        output = self.output

        # Enter alternate screen.
        if self.use_alternate_screen and not self._in_alternate_screen:
            self._in_alternate_screen = True
            output.enter_alternate_screen()

        # Enable bracketed paste.
        if not self._bracketed_paste_enabled:
            self.output.enable_bracketed_paste()
            self._bracketed_paste_enabled = True

        # Enable/disable mouse support.
        needs_mouse_support = self.mouse_support(cli)

        if needs_mouse_support and not self._mouse_support_enabled:
            output.enable_mouse_support()
            self._mouse_support_enabled = True

        elif not needs_mouse_support and self._mouse_support_enabled:
            output.disable_mouse_support()
            self._mouse_support_enabled = False

        # Create screen and write layout to it.
        size = output.get_size()
        screen = Screen()
        screen.show_cursor = False  # Hide cursor by default, unless one of the
                                    # containers decides to display it.
        mouse_handlers = MouseHandlers()

        if is_done:
            height = 0  # When we are done, we don't necessary want to fill up until the bottom.
        else:
            height = self._last_screen.height if self._last_screen else 0
            height = max(self._min_available_height, height)

        # When te size changes, don't consider the previous screen.
        if self._last_size != size:
            self._last_screen = None

        # When we render using another style, do a full repaint. (Forget about
        # the previous rendered screen.)
        # (But note that we still use _last_screen to calculate the height.)
        if self.style.invalidation_hash() != self._last_style_hash:
            self._last_screen = None
            self._attrs_for_token = None
        if self._attrs_for_token is None:
            self._attrs_for_token = _TokenToAttrsCache(self.style.get_attrs_for_token)
        self._last_style_hash = self.style.invalidation_hash()

        layout.write_to_screen(cli, screen, mouse_handlers, WritePosition(
            xpos=0,
            ypos=0,
            width=size.columns,
            height=(size.rows if self.use_alternate_screen else height),
            extended_height=size.rows,
        ))

        # When grayed. Replace all tokens in the new screen.
        if cli.is_aborting or cli.is_exiting:
            screen.replace_all_tokens(Token.Aborted)

        # Process diff and write to output.
        self._cursor_pos, self._last_token = _output_screen_diff(
            output, screen, self._cursor_pos,
            self._last_screen, self._last_token, is_done,
            use_alternate_screen=self.use_alternate_screen,
            attrs_for_token=self._attrs_for_token,
            size=size,
            previous_width=(self._last_size.columns if self._last_size else 0))
        self._last_screen = screen
        self._last_size = size
        self.mouse_handlers = mouse_handlers

        # Write title if it changed.
        new_title = cli.terminal_title

        if new_title != self._last_title:
            if new_title is None:
                self.output.clear_title()
            else:
                self.output.set_title(new_title)
            self._last_title = new_title

        output.flush()
470355
def screenshot(self, *args):
        """"""
        from mss import mss
        if not os.path.exists("screenshots"):
            os.makedirs("screenshots")
        box = {
            "top": self.winfo_y(),
            "left": self.winfo_x(),
            "width": self.winfo_width(),
            "height": self.winfo_height()
        }
        screenshot = mss().grab(box)
        screenshot = Image.frombytes("RGB", screenshot.size, screenshot.rgb)
        screenshot.save("screenshots/{}.png".format(ttk.Style(self).theme_use()))
773446
function toy(frag, cb) {
  const canvas = document.body.appendChild(document.createElement('canvas'))
  const gl     = context(canvas, render)
  const shader = Shader(gl, vert, frag)
  const fitter = fit(canvas)

  render.update = update
  render.resize = fitter
  render.shader = shader
  render.canvas = canvas
  render.gl     = gl

  window.addEventListener('resize', fitter, false)
  return render

  function render() {
    const width  = gl.drawingBufferWidth
    const height = gl.drawingBufferHeight
    gl.viewport(0, 0, width, height)

    shader.bind()
    cb(gl, shader)
    triangle(gl)
  }

  function update(frag) {
    shader.update(vert, frag)
  }
}
21125
def update_screen(image)
      if @show_prompt
        MiniTerm.print("\r#{prompt.text}\r")
        @show_prompt = false
      end

      (0...active_width).each do |index|
        if (image_char = image[index]) != window_buffer[index]
          MiniTerm.set_posn(column: prompt.length + index)
          MiniTerm.print(image_char)
        end
      end
    end
441487
def screenshot(self, filename=None):
        
        if self.__keep_screen:
            return self.__last_screen
        try:
            screen = self._take_screenshot()
        except IOError:
            # try taks screenshot again
            log.warn("warning, screenshot failed [2/1], retry again")
            screen = self._take_screenshot()
        self.__last_screen = screen
        if filename:
            save_dir = os.path.dirname(filename) or '.'
            if not os.path.exists(save_dir):
                os.makedirs(save_dir)
            screen.save(filename)
        return screen
1064429
def pull_screencap(self, remote: _PATH = '/sdcard/screencap.png', local: _PATH = 'screencap.png') -> None:
        ''''''
        self.screencap(remote)
        self.pull(remote, local)
740021
def saveScreenCapture(self, path=None, name=None):
        
        bitmap = self.getBitmap()
        target_file = None
        if path is None and name is None:
            _, target_file = tempfile.mkstemp(".png")
        elif name is None:
            _, tpath = tempfile.mkstemp(".png")
            target_file = os.path.join(path, tfile)
        else:
            target_file = os.path.join(path, name+".png")
        cv2.imwrite(target_file, bitmap)
        return target_file
459308
def display(self, image):
        
        assert(image.mode == self.mode)
        assert(image.size == self.size)

        image = self.preprocess(image)

        if self.framebuffer.redraw_required(image):
            left, top, right, bottom = self._apply_offsets(self.framebuffer.bounding_box)
            width = right - left
            height = bottom - top

            self._set_position(top, right, bottom, left)

            i = 0
            buf = bytearray(width * height * 2)
            for r, g, b in self.framebuffer.getdata():
                if not(r == g == b == 0):
                    # 65K format 1
                    buf[i] = r & 0xF8 | g >> 5
                    buf[i + 1] = g << 3 & 0xE0 | b >> 3
                i += 2

            self.data(list(buf))
1370711
def print_page_cb(self, print_op, print_context, page_nb, keep_refs={}):
        
        self.pages[page_nb].print_page_cb(print_op, print_context,
                                          keep_refs=keep_refs)
251054
def _game_image_from_screen(self, game_type):
        
        # screen
        screen_img = self._screen_shot()
        # game image
        game_rect = self._game_finders[game_type].locate_in(screen_img)
        if game_rect is None:
            return
        t, l, b, r = game_rect
        game_img = screen_img[t:b, l:r]
        return game_img
754757
def take_screenshot(self):
    """"""

    if not self.failed:
        return

    browser = getattr(world, 'browser', None)
    if not browser:
        return

    try:
        scenario_name = self.scenario.name
        scenario_index = \
            self.scenario.feature.scenarios.index(self.scenario) + 1
    except AttributeError:
        scenario_name = self.background.keyword
        scenario_index = 0

    if self.outline is None:
        outline_index_str = ''
    else:
        outline_index = self.scenario.outlines.index(self.outline) + 1
        outline_index_str = '_{}'.format(outline_index)

    base_name = FORMAT.format(
        feature_file=os.path.relpath(self.feature.filename),
        scenario_index=scenario_index,
        scenario_name=scenario_name,
        outline_index=outline_index_str,
    )
    base_name = re.sub(r'\W', '_', base_name, flags=re.UNICODE)
    base_name = os.path.join(DIRECTORY, base_name)

    world.browser.save_screenshot('{}.png'.format(base_name))

    with open('{}.html'.format(base_name), 'w') as page_source_file:
        page_source_file.write(world.browser.page_source)
1167397
def rgbmap_cb(self, rgbmap, channel):
        
        if not self.gui_up:
            return
        fitsimage = channel.fitsimage
        if fitsimage != self.fv.getfocus_fitsimage():
            return False
        self.change_cbar(self.fv, channel)
168577
def __create_preview_object_base(self, dct):
        
        if dct.get("_id"):
            del dct["_id"]

        preview_object_id = yield self.previews.insert(dct)

        raise Return(preview_object_id)