More typing

This commit is contained in:
Jamie Hardt
2023-05-31 18:10:44 -07:00
parent a6f042c76f
commit 51ed92f5df
4 changed files with 41 additions and 36 deletions

View File

@@ -2,7 +2,7 @@
# (c) 2018 Jamie Hardt # (c) 2018 Jamie Hardt
from re import (compile, match) from re import (compile, match)
from typing import Dict, Tuple from typing import Dict, Tuple, Generator
class ChannelMap: class ChannelMap:
""" """
@@ -24,62 +24,62 @@ class ChannelMap:
self.v = v self.v = v
@property @property
def video(self): def video(self) -> bool:
'True if video is included' 'True if video is included'
return self.v return self.v
@property @property
def audio(self): def audio(self) -> bool:
'True if an audio channel is included' 'True if an audio channel is included'
return len(self._audio_channel_set) > 0 return len(self._audio_channel_set) > 0
@property @property
def channels(self): def channels(self) -> Generator[int, None, None]:
'A generator for each audio channel' 'A generator for each audio channel'
for c in self._audio_channel_set: for c in self._audio_channel_set:
yield c yield c
@property @property
def a1(self): def a1(self) -> bool:
"""True if A1 is included""" """True if A1 is included"""
return self.get_audio_channel(1) return self.get_audio_channel(1)
@a1.setter @a1.setter
def a1(self,val): def a1(self, val: bool):
self.set_audio_channel(1,val) self.set_audio_channel(1,val)
@property @property
def a2(self): def a2(self) -> bool:
"""True if A2 is included""" """True if A2 is included"""
return self.get_audio_channel(2) return self.get_audio_channel(2)
@a2.setter @a2.setter
def a2(self,val): def a2(self, val: bool):
self.set_audio_channel(2,val) self.set_audio_channel(2,val)
@property @property
def a3(self): def a3(self) -> bool:
"""True if A3 is included""" """True if A3 is included"""
return self.get_audio_channel(3) return self.get_audio_channel(3)
@a3.setter @a3.setter
def a3(self,val): def a3(self, val: bool):
self.set_audio_channel(3,val) self.set_audio_channel(3,val)
@property @property
def a4(self): def a4(self) -> bool:
"""True if A4 is included""" """True if A4 is included"""
return self.get_audio_channel(4) return self.get_audio_channel(4)
@a4.setter @a4.setter
def a4(self,val): def a4(self,val: bool):
self.set_audio_channel(4,val) self.set_audio_channel(4,val)
def get_audio_channel(self,chan_num): def get_audio_channel(self, chan_num) -> bool:
"""True if chan_num is included""" """True if chan_num is included"""
return (chan_num in self._audio_channel_set) return (chan_num in self._audio_channel_set)
def set_audio_channel(self,chan_num,enabled): def set_audio_channel(self,chan_num, enabled: bool):
"""If enabled is true, chan_num will be included""" """If enabled is true, chan_num will be included"""
if enabled: if enabled:
self._audio_channel_set.add(chan_num) self._audio_channel_set.add(chan_num)

View File

@@ -1,20 +1,19 @@
# pycmx # pycmx
# (c) 2018 Jamie Hardt # (c) 2018 Jamie Hardt
from collections import namedtuple # from collections import namedtuple
from .parse_cmx_statements import (parse_cmx3600_statements, StmtEvent,StmtFCM ) from .parse_cmx_statements import (parse_cmx3600_statements)
from .edit_list import EditList from .edit_list import EditList
def parse_cmx3600(f): from typing import TextIO
def parse_cmx3600(f: TextIO):
""" """
Parse a CMX 3600 EDL. Parse a CMX 3600 EDL.
Args: :param TextIO f: a file-like object, anything that's readlines-able.
f : a file-like object, anything that's readlines-able. :returns: An :class:`pycmx.edit_list.EditList`.
Returns:
An :class:`pycmx.edit_list.EditList`.
""" """
statements = parse_cmx3600_statements(f) statements = parse_cmx3600_statements(f)
return EditList(statements) return EditList(statements)

View File

@@ -5,6 +5,8 @@ import re
import sys import sys
from collections import namedtuple from collections import namedtuple
from itertools import count from itertools import count
from typing import TextIO, List
from .util import collimate from .util import collimate
@@ -18,12 +20,12 @@ StmtSourceFile = namedtuple("SourceFile",["filename","line_number"])
StmtRemark = namedtuple("Remark",["text","line_number"]) StmtRemark = namedtuple("Remark",["text","line_number"])
StmtEffectsName = namedtuple("EffectsName",["name","line_number"]) StmtEffectsName = namedtuple("EffectsName",["name","line_number"])
StmtSourceUMID = namedtuple("Source",["name","umid","line_number"]) StmtSourceUMID = namedtuple("Source",["name","umid","line_number"])
StmtSplitEdit = namedtuple("SplitEdit",["video","magnitue", "line_number"]) StmtSplitEdit = namedtuple("SplitEdit",["video","magnitude", "line_number"])
StmtMotionMemory = namedtuple("MotionMemory",["source","fps"]) # FIXME needs more fields StmtMotionMemory = namedtuple("MotionMemory",["source","fps"]) # FIXME needs more fields
StmtUnrecognized = namedtuple("Unrecognized",["content","line_number"]) StmtUnrecognized = namedtuple("Unrecognized",["content","line_number"])
def parse_cmx3600_statements(file): def parse_cmx3600_statements(file: TextIO) -> List[object]:
""" """
Return a list of every statement in the file argument. Return a list of every statement in the file argument.
""" """
@@ -109,7 +111,7 @@ def _parse_extended_audio_channels(line, line_number):
else: else:
return StmtUnrecognized(content=line, line_number=line_number) return StmtUnrecognized(content=line, line_number=line_number)
def _parse_remark(line, line_number): def _parse_remark(line, line_number) -> object:
if line.startswith("FROM CLIP NAME:"): if line.startswith("FROM CLIP NAME:"):
return StmtClipName(name=line[15:].strip() , affect="from", line_number=line_number) return StmtClipName(name=line[15:].strip() , affect="from", line_number=line_number)
elif line.startswith("TO CLIP NAME:"): elif line.startswith("TO CLIP NAME:"):
@@ -119,7 +121,7 @@ def _parse_remark(line, line_number):
else: else:
return StmtRemark(text=line, line_number=line_number) return StmtRemark(text=line, line_number=line_number)
def _parse_effects_name(line, line_number): def _parse_effects_name(line, line_number) -> StmtEffectsName:
name = line[16:].strip() name = line[16:].strip()
return StmtEffectsName(name=name, line_number=line_number) return StmtEffectsName(name=name, line_number=line_number)

View File

@@ -1,5 +1,7 @@
# pycmx # pycmx
# (c) 2018 Jamie Hardt # (c) 2023 Jamie Hardt
from typing import Optional
class Transition: class Transition:
""" """
@@ -19,7 +21,7 @@ class Transition:
self.name = name self.name = name
@property @property
def kind(self): def kind(self) -> Optional[str]:
""" """
Return the kind of transition: Cut, Wipe, etc Return the kind of transition: Cut, Wipe, etc
""" """
@@ -37,22 +39,22 @@ class Transition:
return Transition.KeyOut return Transition.KeyOut
@property @property
def cut(self): def cut(self) -> bool:
"`True` if this transition is a cut." "`True` if this transition is a cut."
return self.transition == 'C' return self.transition == 'C'
@property @property
def dissolve(self): def dissolve(self) -> bool:
"`True` if this traansition is a dissolve." "`True` if this traansition is a dissolve."
return self.transition == 'D' return self.transition == 'D'
@property @property
def wipe(self): def wipe(self) -> bool:
"`True` if this transition is a wipe." "`True` if this transition is a wipe."
return self.transition.startswith('W') return self.transition.startswith('W')
@property @property
def effect_duration(self): def effect_duration(self) -> int:
"""The duration of this transition, in frames of the record target. """The duration of this transition, in frames of the record target.
In the event of a key event, this is the duration of the fade in. In the event of a key event, this is the duration of the fade in.
@@ -60,7 +62,7 @@ class Transition:
return int(self.operand) return int(self.operand)
@property @property
def wipe_number(self): def wipe_number(self) -> Optional[int]:
"Wipes are identified by a particular number." "Wipes are identified by a particular number."
if self.wipe: if self.wipe:
return int(self.transition[1:]) return int(self.transition[1:])
@@ -68,19 +70,21 @@ class Transition:
return None return None
@property @property
def key_background(self): def key_background(self) -> bool:
"`True` if this edit is a key background." "`True` if this edit is a key background."
return self.transition == Transition.KeyBackground return self.transition == Transition.KeyBackground
@property @property
def key_foreground(self): def key_foreground(self) -> bool:
"`True` if this edit is a key foreground." "`True` if this edit is a key foreground."
return self.transition == Transition.Key return self.transition == Transition.Key
@property @property
def key_out(self): def key_out(self) -> bool:
""" """
`True` if this edit is a key out. This material will removed from `True` if this edit is a key out. This material will removed from
the key foreground and replaced with the key background. the key foreground and replaced with the key background.
""" """
return self.transition == Transition.KeyOut return self.transition == Transition.KeyOut