Skip to content

Commit

Permalink
Update start/end when splitting scene
Browse files Browse the repository at this point in the history
  • Loading branch information
machinewrapped committed Jun 9, 2024
1 parent cfa68bd commit 7d1fb51
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 17 additions & 1 deletion GUI/ViewModel/SceneItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, scene : SubtitleScene):
self.scene_model = {
'scene': scene.number,
'start': scene.batches[0].txt_start,
'end': scene.batches[-1].srt_end,
'end': scene.batches[-1].txt_end,
'duration': None,
'gap': None,
'summary': scene.summary
Expand Down Expand Up @@ -93,6 +93,7 @@ def AddBatchItem(self, batch_item : BatchItem):
self.insertRow(batch_item.number - 1, batch_item)

self.Remap()
self.UpdateStartAndEnd()

def Update(self, update):
""" Update the scene model with new data """
Expand All @@ -101,6 +102,21 @@ def Update(self, update):

UpdateFields(self.scene_model, update, ['summary', 'start', 'end', 'duration', 'gap'])

def UpdateStartAndEnd(self):
""" Update the start and end times of the scene """
start = None
end = None
for i in range(0, self.rowCount()):
batch_item = self.child(i, 0)
if i == 0:
start = batch_item.start
end = batch_item.end

if start:
self.scene_model['start'] = start
if end:
self.scene_model['end'] = end

def Remap(self):
""" Rebuild the batch number map """
batch_items = {}
Expand Down
5 changes: 5 additions & 0 deletions GUI/ViewModel/ViewModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ def UpdateBatch(self, scene_number, batch_number, batch_update : dict):
def RemoveBatch(self, scene_number, batch_number):
logging.debug(f"Removing batch ({scene_number}, {batch_number})")
scene_item : SceneItem = self.model.get(scene_number)
if not scene_item:
raise ViewModelError(f"Scene {scene_number} not found")

if batch_number not in scene_item.batches.keys():
raise ViewModelError(f"Scene {scene_number} batch {batch_number} does not exist")

Expand All @@ -342,6 +345,8 @@ def RemoveBatch(self, scene_number, batch_number):
logging.debug(f"Removed row {i} from scene {scene_item.number}, rowCount={scene_item.rowCount()}")
break

scene_item.UpdateStartAndEnd()

#############################################################################

def AddLine(self, scene_number, batch_number, line : SubtitleLine):
Expand Down

0 comments on commit 7d1fb51

Please sign in to comment.