How to use the pycaption.geometry.Layout function in pycaption

To help you get started, we’ve selected a few pycaption examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pbs / pycaption / tests / test_geometry.py View on Github external
size_percent = Size(30, UnitEnum.PERCENT)
        size_percent2 = Size(30, UnitEnum.PERCENT)

        point_abs = Point(size_px, size_px2)
        point_rel = Point(size_percent, size_percent2)

        stretch_abs = Stretch(size_px, size_px2)
        stretch_rel = Stretch(size_percent, size_percent2)

        layout_abs = Layout(
            origin=point_abs,
            extent=stretch_abs,
            padding=None
        )

        layout_mix = Layout(
            origin=point_abs,
            extent=stretch_rel,
            padding=None
        )

        layout_rel = Layout(
            origin=point_rel,
            extent=stretch_rel,
            padding=None
        )

        self.assertFalse(layout_abs.is_relative())
        self.assertFalse(layout_mix.is_relative())
        self.assertTrue(layout_rel.is_relative())
github pbs / pycaption / tests / test_geometry.py View on Github external
def test_layout_is_relative(self):
        empty_layout = Layout()

        self.assertTrue(empty_layout.is_relative())

        size_px = Size(30, UnitEnum.PIXEL)
        size_px2 = Size(30, UnitEnum.PIXEL)

        size_percent = Size(30, UnitEnum.PERCENT)
        size_percent2 = Size(30, UnitEnum.PERCENT)

        point_abs = Point(size_px, size_px2)
        point_rel = Point(size_percent, size_percent2)

        stretch_abs = Stretch(size_px, size_px2)
        stretch_rel = Stretch(size_percent, size_percent2)

        layout_abs = Layout(
github pbs / pycaption / tests / test_dfxp_extras.py View on Github external
def test_only_the_custom_region_is_created(self):
        caption_set = DFXPReader().read(
            SAMPLE_DFXP_TO_RENDER_WITH_ONLY_DEFAULT_POSITIONING_INPUT)

        new_region = Layout(
            alignment=Alignment(
                HorizontalAlignmentEnum.LEFT, VerticalAlignmentEnum.TOP
            )
        )

        dfxp = SinglePositioningDFXPWriter(new_region).write(caption_set)
        # Using a different parser, because this preserves letter case
        # The output file is ok, but when parsing it, the "regular" parses
        # loses letter case.
        layout = BeautifulSoup(dfxp, features='xml').findChild('layout')

        self.assertEqual(len(layout.findChildren('region')), 1)

        region = layout.findChild('region')
        text_align = region['tts:textAlign']
        display_align = region['tts:displayAlign']
github pbs / pycaption / pycaption / dfxp / base.py View on Github external
def _get_layout_class():
        """Hook method for providing the Layout class to use
        """
        return Layout
github pbs / pycaption / pycaption / webvtt.py View on Github external
m = TIMING_LINE_PATTERN.search(line)
        if not m:
            raise CaptionReadSyntaxError(
                'Invalid timing format.')

        start = self._parse_timestamp(m.group(1))
        end = self._parse_timestamp(m.group(2))

        cue_settings = m.group(3)

        if not self.ignore_timing_errors:
            self._validate_timings(start, end, last_start_time)

        layout_info = None
        if cue_settings:
            layout_info = Layout(webvtt_positioning=cue_settings)

        return start, end, layout_info
github pbs / pycaption / pycaption / sami.py View on Github external
captions[-1].end = milliseconds * 1000

            if p.get_text().strip():
                self.first_alignment = None
                styles = self._translate_attrs(p)
                layout_info = self._build_layout(styles,
                                                 inherit_from=parent_layout)
                self.line = []

                self._translate_tag(p, layout_info)
                caption_layout = self._get_layout_class()(
                    alignment=self.first_alignment,
                    inherit_from=layout_info
                )
                for node in self.line:
                    node.layout_info = Layout(
                        alignment=self.first_alignment,
                        inherit_from=node.layout_info
                    )
                self.first_alignment = None

                caption = Caption(start, end, self.line, styles, caption_layout)
                captions.append(caption)

        if captions and captions[-1].end == 0:
            # Arbitrarily make this last 4 seconds. Not ideal...
            captions[-1].end = (milliseconds + 4000) * 1000

        return captions
github pbs / pycaption / pycaption / geometry.py View on Github external
def as_percentage_of(self, video_width, video_height):
        params = {'alignment': self.alignment}
        # We don't need to preserve webvtt_positioning on Layout
        # transformations because, if it is set, the WebVTT writer
        # returns as soon as it's found and the transformations are
        # never triggered.
        for attr_name in ['origin', 'extent', 'padding']:
            attr = getattr(self, attr_name)
            if attr:
                params[attr_name] = attr.as_percentage_of(video_width,
                                                          video_height)
        return Layout(**params)