Exemple #1
0
def new_sample_video_frame_received(img, width, height, *args, **kwargs):
    """
    Executed when a new image is received, update the centred positions
    and set the gevent so the new image can be sent.
    """
    global SAMPLE_IMAGE

    # Assume that we are gettign a qimage if we are not getting a str,
    # to be able to handle data sent by hardware objects used in MxCuBE 2.x
    # Passed as str in Python 2.7 and bytes in Python 3
    if isinstance(img, str):
        img = img
    elif isinstance(img, bytes):
        img = img
    else:
        rawdata = img.bits().asstring(img.numBytes())
        strbuf = StringIO()
        image = PIL.Image.frombytes("RGBA", (width, height), rawdata)
        (r, g, b, a) = image.split()
        image = PIL.Image.merge("RGB", (b, g, r))
        image.save(strbuf, "JPEG")
        img = strbuf.get_value()

    SAMPLE_IMAGE = img

    blcontrol.beamline.sample_view.camera.new_frame.set()
    blcontrol.beamline.sample_view.camera.new_frame.clear()
Exemple #2
0
    def render(self, output=None, backend="ANSI"):
        """Renders shape contents into a text-output.
          Args:
            - backend (str): currently implemented "ANSI" - output type
            - output(Optional[Union[TextIO, BytesIO]])
          Output:
            ->Optional[Union[str, bytes]]

            Renders shape contents into content that can reprsent the image
            outside terminedia library. That is, if the shape is rendered with "ANSI",
            a text body, with the ESC encoded ANSI sequences for cursor positioning
            embeded will be generated. If this body is subsequnetly printed, the
            image in the Shape is reproduced on the terminal.

            If output is given, it should be a file-like object to which the contents
            of the shape will be written. Binary backends require a binary file. thenmethod returns None.
            If no output is given, the rendered contents are returned.
        """
        backend = backend.upper()
        original_output = output
        if isinstance(output, (str, Path)):
            output = open(
                output,
                "wt")  # FIXME: for some backends a binary file will be needed.
        if not original_output:
            output = StringIO()

        if backend == "ANSI":
            return self._render_using_screen(output, backend)
        if backend == "HTML":
            # FIXME: this somewhat violates some "this module should not know about
            # specific backend stuff (HTML template)."
            # However, the rendering machinnery only knows
            # about incremental rendering, and can't "sandwhich"
            # the final rendering. In any case, the outter HTML template
            # should be configurable in a near term future.
            from terminedia.html import full_body_template

            preamble, post_amble = full_body_template.split("{content}")
            output.write(preamble)
            self._render_using_screen(output, backend)
            output.write(post_amble)
        else:
            raise ValueError(f"Output type {backend!r} not implemented")
        if not original_output:
            return output.get_value()