예제 #1
0
    def update_preview(self) -> None:
        selected_style = self._selected_style
        if not selected_style:
            self._preview_box.clear()
            return

        resolution = (self._preview_box.width(), self._preview_box.height())
        if resolution[0] <= 0 or resolution[1] <= 0:
            self._preview_box.clear()
            return

        fake_style = copy(selected_style)
        fake_style.name = "Default"
        if (self._api.video.has_current_stream
                and self._api.video.current_stream.is_ready):
            fake_style.scale(resolution[1] /
                             self._api.video.current_stream.height)
        fake_style_list = AssStyleList()
        fake_style_list.append(fake_style)

        fake_event = AssEvent(
            start=0,
            end=1000,
            text=self.preview_text.replace("\n", "\\N"),
            style_name=fake_style.name,
        )
        fake_event_list = AssEventList()
        fake_event_list.append(fake_event)

        fake_script_info = AssScriptInfo()

        image = PIL.Image.new(mode="RGBA", size=resolution)

        background_path = self._background_combobox.currentData()
        if background_path and background_path.exists():
            background = PIL.Image.open(background_path)
            for y in range(0, resolution[1], background.height):
                for x in range(0, resolution[0], background.width):
                    image.paste(background, (x, y))

        self._renderer.set_source(fake_style_list, fake_event_list,
                                  fake_script_info, resolution)
        try:
            aspect_ratio = self._api.video.current_stream.aspect_ratio
        except ResourceUnavailable:
            aspect_ratio = Fraction(1)
        subs_image = self._renderer.render(
            time=0,
            aspect_ratio=aspect_ratio,
        )
        image = PIL.Image.composite(subs_image, image, subs_image)

        image = PIL.ImageQt.ImageQt(image)
        image = QImage(image)
        self._preview_box.setPixmap(QPixmap.fromImage(image))
예제 #2
0
파일: base.py 프로젝트: zeromind/bubblesub
def create_new_subtitle(api: Api, pts: int, by_end: bool) -> None:
    pts = try_align_pts_to_near_frame(api, pts)

    insertion_point = get_subtitle_insertion_point(api, pts, by_end)

    insertion_point.start = try_align_pts_to_near_frame(
        api, insertion_point.start)
    insertion_point.end = try_align_pts_to_near_frame(api, insertion_point.end)

    api.subs.events.insert(
        insertion_point.idx,
        AssEvent(
            start=insertion_point.start,
            end=insertion_point.end,
            style_name=api.subs.default_style_name,
        ),
    )
    api.subs.selected_indexes = [insertion_point.idx]
예제 #3
0
    async def run(self) -> None:
        indexes = await self.args.origin.get_indexes()
        if self.args.dir == "before":
            idx, start, end = self._insert_before(indexes)
        elif self.args.dir == "after":
            idx, start, end = self._insert_after(indexes)
        else:
            raise AssertionError

        if not self.args.no_align and self.api.video.has_current_stream:
            start = self.api.video.current_stream.align_pts_to_near_frame(
                start)
            end = self.api.video.current_stream.align_pts_to_near_frame(end)

        with self.api.undo.capture():
            self.api.subs.events.insert(
                idx,
                AssEvent(
                    start=start,
                    end=end,
                    style_name=self.api.subs.default_style_name,
                ),
            )
            self.api.subs.selected_indexes = [idx]
예제 #4
0
 def set_subject_text(self, sub: AssEvent, value: str) -> None:
     sub.style = value
예제 #5
0
 def set_subject_text(self, sub: AssEvent, value: str) -> None:
     sub.actor = value
예제 #6
0
 def set_subject_text(self, sub: AssEvent, value: str) -> None:
     sub.note = value.replace("\n", "\\N")