mirror of
https://github.com/iluvcapra/pycmx.git
synced 2025-12-31 08:50:54 +00:00
More typing cleanups
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
from .parse_cmx_statements import (StmtEvent, StmtClipName, StmtSourceFile, StmtAudioExt, StmtUnrecognized, StmtEffectsName)
|
from .parse_cmx_statements import (StmtEvent, StmtClipName, StmtSourceFile, StmtAudioExt, StmtUnrecognized, StmtEffectsName)
|
||||||
from .edit import Edit
|
from .edit import Edit
|
||||||
|
|
||||||
from typing import List, Generator
|
from typing import List, Generator, Optional, Tuple, Any
|
||||||
|
|
||||||
class Event:
|
class Event:
|
||||||
"""
|
"""
|
||||||
@@ -32,17 +32,19 @@ class Event:
|
|||||||
clip_names = self._clip_name_statements()
|
clip_names = self._clip_name_statements()
|
||||||
source_files= self._source_file_statements()
|
source_files= self._source_file_statements()
|
||||||
|
|
||||||
the_zip = [edits_audio]
|
the_zip: List[List[Any]] = [edits_audio]
|
||||||
|
|
||||||
if len(edits_audio) == 2:
|
if len(edits_audio) == 2:
|
||||||
cn = [None, None]
|
start_name: Optional[StmtClipName] = None
|
||||||
|
end_name: Optional[StmtClipName] = None
|
||||||
|
|
||||||
for clip_name in clip_names:
|
for clip_name in clip_names:
|
||||||
if clip_name.affect == 'from':
|
if clip_name.affect == 'from':
|
||||||
cn[0] = clip_name
|
start_name = clip_name
|
||||||
elif clip_name.affect == 'to':
|
elif clip_name.affect == 'to':
|
||||||
cn[1] = clip_name
|
end_name = clip_name
|
||||||
|
|
||||||
the_zip.append(cn)
|
the_zip.append([start_name, end_name])
|
||||||
else:
|
else:
|
||||||
if len(edits_audio) == len(clip_names):
|
if len(edits_audio) == len(clip_names):
|
||||||
the_zip.append(clip_names)
|
the_zip.append(clip_names)
|
||||||
@@ -59,13 +61,17 @@ class Event:
|
|||||||
# attach trans name to last event
|
# attach trans name to last event
|
||||||
try:
|
try:
|
||||||
trans_statement = self._trans_name_statements()[0]
|
trans_statement = self._trans_name_statements()[0]
|
||||||
trans_names = [None] * (len(edits_audio) - 1)
|
trans_names: List[Optional[Any]] = [None] * (len(edits_audio) - 1)
|
||||||
trans_names.append(trans_statement)
|
trans_names.append(trans_statement)
|
||||||
the_zip.append(trans_names)
|
the_zip.append(trans_names)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
the_zip.append([None] * len(edits_audio) )
|
the_zip.append([None] * len(edits_audio) )
|
||||||
|
|
||||||
return [ Edit(e1[0],e1[1],n1,s1,u1) for (e1,n1,s1,u1) in zip(*the_zip) ]
|
return [ Edit(edit_statement=e1[0],
|
||||||
|
audio_ext_statement=e1[1],
|
||||||
|
clip_name_statement=n1,
|
||||||
|
source_file_statement=s1,
|
||||||
|
trans_name_statement=u1) for (e1,n1,s1,u1) in zip(*the_zip) ]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unrecognized_statements(self) -> Generator[StmtUnrecognized, None, None]:
|
def unrecognized_statements(self) -> Generator[StmtUnrecognized, None, None]:
|
||||||
@@ -76,19 +82,19 @@ class Event:
|
|||||||
if type(s) is StmtUnrecognized:
|
if type(s) is StmtUnrecognized:
|
||||||
yield s
|
yield s
|
||||||
|
|
||||||
def _trans_name_statements(self):
|
def _trans_name_statements(self) -> List[StmtEffectsName]:
|
||||||
return [s for s in self.statements if type(s) is StmtEffectsName]
|
return [s for s in self.statements if type(s) is StmtEffectsName]
|
||||||
|
|
||||||
def _edit_statements(self):
|
def _edit_statements(self) -> List[StmtEvent]:
|
||||||
return [s for s in self.statements if type(s) is StmtEvent]
|
return [s for s in self.statements if type(s) is StmtEvent]
|
||||||
|
|
||||||
def _clip_name_statements(self):
|
def _clip_name_statements(self) -> List[StmtClipName]:
|
||||||
return [s for s in self.statements if type(s) is StmtClipName]
|
return [s for s in self.statements if type(s) is StmtClipName]
|
||||||
|
|
||||||
def _source_file_statements(self):
|
def _source_file_statements(self) -> List[StmtSourceFile]:
|
||||||
return [s for s in self.statements if type(s) is StmtSourceFile]
|
return [s for s in self.statements if type(s) is StmtSourceFile]
|
||||||
|
|
||||||
def _statements_with_audio_ext(self):
|
def _statements_with_audio_ext(self) -> Generator[Tuple[StmtEvent, Optional[StmtAudioExt]], None, None]:
|
||||||
for (s1, s2) in zip(self.statements, self.statements[1:]):
|
for (s1, s2) in zip(self.statements, self.statements[1:]):
|
||||||
if type(s1) is StmtEvent and type(s2) is StmtAudioExt:
|
if type(s1) is StmtEvent and type(s2) is StmtAudioExt:
|
||||||
yield (s1,s2)
|
yield (s1,s2)
|
||||||
|
|||||||
Reference in New Issue
Block a user