def __init__(self, name: str = '', items: Optional[List[Scene]] = None) -> None: super().__init__() self.name = name self.items = items if items is not None else [] self.main = main_window()
def __init__(self, vs_output: Union[vs.VideoNode, vs.AlphaOutputTuple], index: int) -> None: from vspreview.models import SceningLists from vspreview.utils import main_window from vspreview.widgets import GraphicsImageItem self.main = main_window() # runtime attributes if isinstance(vs_output, vs.AlphaOutputTuple): self.has_alpha = True self.source_vs_output = vs_output.clip self.source_vs_alpha = vs_output.alpha self.vs_alpha = self.prepare_vs_output(self.source_vs_alpha, alpha=True) self.format_alpha = self.source_vs_alpha.format else: self.has_alpha = False self.source_vs_output = vs_output self.index = index self.vs_output = self.prepare_vs_output(self.source_vs_output) self.width = self.vs_output.width self.height = self.vs_output.height self.format = self.source_vs_output.format self.props = self.source_vs_output.get_frame(0).props self.fps_num = self.vs_output.fps.numerator self.fps_den = self.vs_output.fps.denominator self.fps = self.fps_num / self.fps_den self.total_frames = FrameInterval(self.vs_output.num_frames) self.total_time = self.to_time_interval(self.total_frames - FrameInterval(1)) self.end_frame = Frame(int(self.total_frames) - 1) self.end_time = self.to_time(self.end_frame) if self.has_alpha: self.checkerboard = self._generate_checkerboard() # set by load_script() when it prepares graphics scene item # based on last showed frame self.graphics_scene_item: GraphicsImageItem # storable attributes if not hasattr(self, 'name'): self.name = 'Output ' + str(self.index) if (not hasattr(self, 'last_showed_frame') or self.last_showed_frame > self.end_frame): self.last_showed_frame: Frame = Frame(0) if not hasattr(self, 'play_fps'): self.play_fps = self.fps_num / self.fps_den if not hasattr(self, 'frame_to_show'): self.frame_to_show: Optional[Frame] = None
def __setstate__(self, state: Mapping[str, Any]) -> None: from vspreview.utils import main_window try: name = state['name'] if not isinstance(name, str): raise TypeError self.name = name except (KeyError, TypeError): logging.warning( f'Storage loading: output {self.index}: failed to parse name.') try: self.last_showed_frame = state['last_showed_frame'] except (KeyError, TypeError): logging.warning( f'Storage loading: Output: failed to parse last showed frame.') except IndexError: logging.warning( f'Storage loading: Output: last showed frame is out of range.') try: for scening_list in state['scening_lists']: main_window().toolbars.scening.lists.add_list(scening_list) except (KeyError, TypeError): pass try: play_fps = state['play_fps'] if not isinstance(play_fps, float): raise TypeError if play_fps >= 1.0: self.play_fps = play_fps except (KeyError, TypeError): logging.warning( f'Storage loading: Output: play fps weren\'t parsed successfully.' ) try: self.frame_to_show = state['frame_to_show'] except (KeyError, TypeError): logging.warning( f'Storage loading: Output: failed to parse frame to show.')
def __init__(self, init_value: Union[FrameInterval, int, TimeInterval]) -> None: from vspreview.utils import main_window if isinstance(init_value, int): self.value = init_value elif isinstance(init_value, FrameInterval): self.value = init_value.value elif isinstance(init_value, TimeInterval): self.value = main_window().current_output.to_frame_interval( init_value).value else: raise TypeError
def __init__(self, init_value: Optional[Union[Time, timedelta, Frame]] = None, **kwargs: Any): from vspreview.utils import main_window if isinstance(init_value, timedelta): self.value = init_value elif isinstance(init_value, Time): self.value = init_value.value elif isinstance(init_value, Frame): self.value = main_window().current_output.to_time(init_value).value elif any(kwargs): self.value = timedelta(**kwargs) elif init_value is None: self.value = timedelta() else: raise TypeError
def __init__(self, local_storage: Optional[Mapping[str, Output]] = None) -> None: super().__init__() self.items: List[Output] = [] local_storage = local_storage if local_storage is not None else {} if main_window().ORDERED_OUTPUTS: outputs = OrderedDict(sorted(vs.get_outputs().items())) else: outputs = vs.get_outputs() for i, vs_output in outputs.items(): try: output = local_storage[str(i)] output.__init__(vs_output, i) # type: ignore except KeyError: output = Output(vs_output, i) self.items.append(output)
def prepare_vs_output(self, vs_output: vs.VideoNode, alpha: bool = False) -> vs.VideoNode: from vspreview.utils import main_window main = main_window() resizer = main.VS_OUTPUT_RESIZER resizer_kwargs = { 'format': vs.COMPATBGR32, 'matrix_in_s': main.VS_OUTPUT_MATRIX, 'transfer_in_s': main.VS_OUTPUT_TRANSFER, 'primaries_in_s': main.VS_OUTPUT_PRIMARIES, 'range_in_s': main.VS_OUTPUT_RANGE, 'chromaloc_in_s': main.VS_OUTPUT_CHROMALOC, 'prefer_props': main.VS_OUTPUT_PREFER_PROPS, } if not alpha: vs_output = vs.core.std.FlipVertical(vs_output) if vs_output.format == vs.COMPATBGR32: # type: ignore return vs_output is_subsampled = (vs_output.format.subsampling_w != 0 or vs_output.format.subsampling_h != 0) if not is_subsampled: resizer = self.Resizer.Point if vs_output.format.color_family == vs.RGB: del resizer_kwargs['matrix_in_s'] if alpha: if vs_output.format == vs.GRAY8: # type: ignore return vs_output resizer_kwargs['format'] = vs.GRAY8 vs_output = resizer(vs_output, **resizer_kwargs, **main.VS_OUTPUT_RESIZER_KWARGS) return vs_output
def __init__(self, parent: Qt.QWidget) -> None: from vspreview.utils import main_window super().__init__(parent) self.app = Qt.QApplication.instance() self.main = main_window() self._mode = self.Mode.TIME self.rect_f = Qt.QRectF() self.end_t = Time(seconds=1) self.end_f = Frame(1) self.notch_interval_target_x = round(75 * self.main.display_scale) self.notch_height = round(6 * self.main.display_scale) self.font_height = round(10 * self.main.display_scale) self.notch_label_interval = round(-1 * self.main.display_scale) self.notch_scroll_interval = round(2 * self.main.display_scale) self.scroll_height = round(10 * self.main.display_scale) self.setMinimumSize(self.notch_interval_target_x, round(33 * self.main.display_scale)) font = self.font() font.setPixelSize(self.font_height) self.setFont(font) self.cursor_x = 0 # used as a fallback when self.rectF.width() is 0, # so cursorX is incorrect self.cursor_ftx: Optional[Union[Frame, Time, int]] = None # False means that only cursor position'll be recalculated self.need_full_repaint = True self.toolbars_notches: Dict[AbstractToolbar, Notches] = {} self.setAttribute(Qt.Qt.WA_OpaquePaintEvent) self.setMouseTracking(True)
def __init__(self, items: Optional[List[SceningList]] = None) -> None: super().__init__() self.main = main_window() self.items = items if items is not None else []