Commit 121fd44f authored by Thibault Saunier's avatar Thibault Saunier

timeline: Disable previewers while removing clips

Without that we will go crazy about starting/stoping preview generation
while removing clips.
Reviewed-by: 's avatarAlex Băluț <&lt;alexandru.balut@gmail.com&gt;>
Differential Revision: https://phabricator.freedesktop.org/D1877
parent d6df416f
......@@ -17,6 +17,7 @@
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
"""Previewers for the timeline."""
import contextlib
import os
import random
import sqlite3
......@@ -330,10 +331,10 @@ class PreviewGeneratorManager():
previewer.connect("done", self.__previewer_done_cb)
previewer.startGeneration()
def start_flushing(self):
"""Flushes all previewers and start ignoring any update."""
if self._running:
self._running = False
@contextlib.contextmanager
def paused(self, interrupt=False):
"""Pauses (and flushes if interrupt=True) managed previewers."""
if interrupt:
for previewer in list(self._current_previewers.values()):
previewer.stopGeneration()
......@@ -341,12 +342,21 @@ class PreviewGeneratorManager():
for previewer in previewers:
previewer.stopGeneration()
def stop_flushing(self):
"""Stop ignoring managed previewers updates."""
self._running = True
try:
self._running = False
yield
except:
self.warning("An exception occurred while the previewer was paused")
raise
finally:
self._running = True
for track_type in self._previewers:
self.__start_next_previewer(track_type)
def __previewer_done_cb(self, previewer):
track_type = previewer.track_type
self.__start_next_previewer(previewer.track_type)
def __start_next_previewer(self, track_type):
next_previewer = self._current_previewers.pop(track_type, None)
if next_previewer:
next_previewer.disconnect_by_func(self.__previewer_done_cb)
......
......@@ -438,26 +438,25 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
def setProject(self, project):
"""Connects to the GES.Timeline holding the project."""
# Avoid starting/closing preview generation like crazy while tearing down project
Previewer.manager.start_flushing()
if self.ges_timeline is not None:
self.disconnect_by_func(self._button_press_event_cb)
self.disconnect_by_func(self._button_release_event_cb)
self.disconnect_by_func(self._motion_notify_event_cb)
self.ges_timeline.disconnect_by_func(self._durationChangedCb)
self.ges_timeline.disconnect_by_func(self._layer_added_cb)
self.ges_timeline.disconnect_by_func(self._layer_removed_cb)
self.ges_timeline.disconnect_by_func(self._snapCb)
self.ges_timeline.disconnect_by_func(self._snapEndedCb)
for ges_layer in self.ges_timeline.get_layers():
self._remove_layer(ges_layer)
self.ges_timeline.ui = None
self.ges_timeline = None
if self._project:
self._project.pipeline.disconnect_by_func(self._positionCb)
Previewer.manager.stop_flushing()
with Previewer.manager.paused(True):
if self.ges_timeline is not None:
self.disconnect_by_func(self._button_press_event_cb)
self.disconnect_by_func(self._button_release_event_cb)
self.disconnect_by_func(self._motion_notify_event_cb)
self.ges_timeline.disconnect_by_func(self._durationChangedCb)
self.ges_timeline.disconnect_by_func(self._layer_added_cb)
self.ges_timeline.disconnect_by_func(self._layer_removed_cb)
self.ges_timeline.disconnect_by_func(self._snapCb)
self.ges_timeline.disconnect_by_func(self._snapEndedCb)
for ges_layer in self.ges_timeline.get_layers():
self._remove_layer(ges_layer)
self.ges_timeline.ui = None
self.ges_timeline = None
if self._project:
self._project.pipeline.disconnect_by_func(self._positionCb)
self._project = project
if self._project:
......@@ -1612,14 +1611,15 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
def _deleteSelected(self, unused_action, unused_parameter):
if self.ges_timeline:
with self.app.action_log.started("delete clip",
finalizing_action=CommitTimelineFinalizingAction(self._project.pipeline),
toplevel=True):
for clip in self.timeline.selection:
layer = clip.get_layer()
if isinstance(clip, GES.TransitionClip):
continue
layer.remove_clip(clip)
with Previewer.manager.paused():
with self.app.action_log.started("delete clip",
finalizing_action=CommitTimelineFinalizingAction(self._project.pipeline),
toplevel=True):
for clip in self.timeline.selection:
layer = clip.get_layer()
if isinstance(clip, GES.TransitionClip):
continue
layer.remove_clip(clip)
self.timeline.selection.setSelection([], SELECT)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment