[pitivi] timeline: Fix layer height updating
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] timeline: Fix layer height updating
- Date: Fri, 20 May 2022 02:49:09 +0000 (UTC)
commit 8bd7a0e727300db006e6a865316a5a9e9a2d9919
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Fri May 20 00:15:31 2022 +0200
timeline: Fix layer height updating
There is no guarantee that the clip's children have a track when the `clip-added`
signal is emitted.
Fixes #2581
pitivi/timeline/layer.py | 26 +++++++++----------
pitivi/timeline/timeline.py | 2 +-
tests/common.py | 9 +------
tests/test_timeline_layer.py | 55 +++++++++++++++++++++++++++++++++++++++++
tests/test_timeline_timeline.py | 4 +--
tests/test_utils_timeline.py | 6 ++---
6 files changed, 73 insertions(+), 29 deletions(-)
---
diff --git a/pitivi/timeline/layer.py b/pitivi/timeline/layer.py
index 888b90677..36b02df0e 100644
--- a/pitivi/timeline/layer.py
+++ b/pitivi/timeline/layer.py
@@ -270,7 +270,7 @@ class LayerControls(Gtk.EventBox, Loggable):
def __check_tracks_active(self, tracks):
return all(self.ges_layer.get_active_for_track(t) for t in tracks)
- def update(self, media_types):
+ def update(self, media_types: GES.TrackType):
self.props.height_request = self.ges_layer.ui.props.height_request
has_audio = media_types & GES.TrackType.AUDIO
@@ -353,27 +353,23 @@ class Layer(Gtk.Layout, Zoomable, Loggable):
def check_media_types(self):
if self.timeline.editing_context:
- self.info("Not updating media types as"
- " we are editing the timeline")
+ self.info("Not updating media types as we are editing the timeline")
return
+
old_media_types = self.media_types
- self.media_types = GES.TrackType(0)
+ self.media_types: GES.TrackType = GES.TrackType(0)
ges_clips = self.ges_layer.get_clips()
for ges_clip in ges_clips:
- for child in ges_clip.get_children(False):
- track = child.get_track()
- if not track:
- continue
- self.media_types |= track.props.track_type
- if self.media_types == GES.TrackType.AUDIO | GES.TrackType.VIDEO:
- # Cannot find more types than these.
- break
-
- if (self.media_types & GES.TrackType.AUDIO) and (self.media_types & GES.TrackType.VIDEO):
+ self.media_types |= ges_clip.props.supported_formats
+ if self.media_types & GES.TrackType.AUDIO and self.media_types & GES.TrackType.VIDEO:
+ # Cannot find more types than these.
+ break
+
+ if self.media_types & GES.TrackType.AUDIO and self.media_types & GES.TrackType.VIDEO:
self.props.height_request = LAYER_HEIGHT
else:
# If the layer is empty, set layer's height to default height.
- self.props.height_request = LAYER_HEIGHT / 2
+ self.props.height_request = LAYER_HEIGHT // 2
if hasattr(self.ges_layer, "control_ui") and self.ges_layer.control_ui:
self.ges_layer.control_ui.update(self.media_types)
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 421f39bf0..5eb90d206 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -310,7 +310,7 @@ class LayersLayout(Gtk.Layout, Zoomable, Loggable):
class Timeline(Gtk.EventBox, Zoomable, Loggable):
- """Container for the the layers controls and representation.
+ """Container for the layers controls and representation.
Attributes:
_project (Project): The project.
diff --git a/tests/common.py b/tests/common.py
index 1c9e365db..2d1a0268f 100644
--- a/tests/common.py
+++ b/tests/common.py
@@ -428,7 +428,7 @@ class TestCase(unittest.TestCase, Loggable):
return proj_uri
- def add_clip(self, layer, start, inpoint=0, duration=10, clip_type=GES.TrackType.UNKNOWN):
+ def add_clip(self, layer: GES.Layer, start, inpoint=0, duration=10, clip_type=GES.TrackType.UNKNOWN):
"""Creates a clip on the specified layer."""
asset = GES.UriClipAsset.request_sync(
get_sample_uri("tears_of_steel.webm"))
@@ -635,13 +635,6 @@ def get_sample_uri(sample, samples_dir=None):
return Gst.filename_to_uri(os.path.join(samples_dir, sample))
-def get_sample_clip(sample):
- uri = get_sample_uri(sample)
- asset = GES.UriClipAsset.request_sync(uri)
- clip = asset.extract()
- return clip
-
-
@contextlib.contextmanager
def cloned_sample(*samples):
"""Gets a context manager which commits the transaction at the end."""
diff --git a/tests/test_timeline_layer.py b/tests/test_timeline_layer.py
index 752ab88f5..68aaef965 100644
--- a/tests/test_timeline_layer.py
+++ b/tests/test_timeline_layer.py
@@ -14,6 +14,7 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
+# pylint: disable=protected-access
from unittest import mock
from gi.repository import GES
@@ -21,6 +22,7 @@ from gi.repository import GES
from pitivi.timeline.layer import AUDIO_ICONS
from pitivi.timeline.layer import Layer
from pitivi.timeline.layer import VIDEO_ICONS
+from pitivi.utils.ui import LAYER_HEIGHT
from tests import common
@@ -159,3 +161,56 @@ class TestLayer(common.TestCase):
# height of layer.control_ui, which now it should not be set.
self.assertFalse(hasattr(ges_layer, "control_ui"))
unused_layer = Layer(ges_layer, timeline)
+
+ @common.setup_timeline
+ def test_layer_heights(self):
+ self.check_layer_height(GES.TrackType(0))
+
+ clip_video =
GES.UriClipAsset.request_sync(common.get_sample_uri("one_fps_numeroted_blue.mkv")).extract()
+ self.timeline_container._insert_clips_and_assets([clip_video], 0, self.layer)
+ self.check_layer_height(GES.TrackType.VIDEO)
+
+ clip_audio = GES.UriClipAsset.request_sync(common.get_sample_uri("mp3_sample.mp3")).extract()
+ self.timeline_container._insert_clips_and_assets([clip_audio], 0, self.layer)
+ self.check_layer_height(GES.TrackType.AUDIO | GES.TrackType.VIDEO)
+
+ self.click_clip(clip_video, expect_selected=True)
+ self.timeline_container.delete_action.activate()
+ self.check_layer_height(GES.TrackType.AUDIO)
+
+ self.click_clip(clip_audio, expect_selected=True)
+ self.timeline_container.delete_action.activate()
+ self.check_layer_height(GES.TrackType(0))
+
+ # Undo everything.
+ self.action_log.undo()
+ self.check_layer_height(GES.TrackType.AUDIO)
+
+ self.action_log.undo()
+ self.check_layer_height(GES.TrackType.AUDIO | GES.TrackType.VIDEO)
+
+ self.action_log.undo()
+ self.check_layer_height(GES.TrackType.VIDEO)
+
+ self.action_log.undo()
+ self.check_layer_height(GES.TrackType(0))
+
+ # Redo everything.
+ self.action_log.redo()
+ self.check_layer_height(GES.TrackType.VIDEO)
+
+ self.action_log.redo()
+ self.check_layer_height(GES.TrackType.AUDIO | GES.TrackType.VIDEO)
+
+ self.action_log.redo()
+ self.check_layer_height(GES.TrackType.AUDIO)
+
+ self.action_log.redo()
+ self.check_layer_height(GES.TrackType(0))
+
+ def check_layer_height(self, expected_media_types: GES.TrackType):
+ self.assertEqual(self.timeline_container.timeline.media_types, expected_media_types)
+ if expected_media_types == GES.TrackType.AUDIO | GES.TrackType.VIDEO:
+ self.assertEqual(self.layer.ui.props.height_request, LAYER_HEIGHT)
+ else:
+ self.assertEqual(self.layer.ui.props.height_request, LAYER_HEIGHT // 2)
diff --git a/tests/test_timeline_timeline.py b/tests/test_timeline_timeline.py
index 9a7c1587c..6f874b731 100644
--- a/tests/test_timeline_timeline.py
+++ b/tests/test_timeline_timeline.py
@@ -134,9 +134,9 @@ class TestLayers(common.TestCase):
self.assertEqual(len(timeline.__on_separators), 1,
"The separators must be forgotten only in drag_end()")
+ @common.setup_timeline
def test_media_types(self):
- timeline_container = common.create_timeline_container()
- timeline = timeline_container.timeline
+ timeline = self.timeline_container.timeline
ges_layer_1 = timeline.ges_timeline.append_layer()
ges_layer_2 = timeline.ges_timeline.append_layer()
diff --git a/tests/test_utils_timeline.py b/tests/test_utils_timeline.py
index 99dcfa75c..815e4d3f7 100644
--- a/tests/test_utils_timeline.py
+++ b/tests/test_utils_timeline.py
@@ -135,9 +135,9 @@ class TestEditingContext(common.TestCase):
def test_with_video(self):
"""Checks the value of the with_video field."""
- audio_clip = common.get_sample_clip("mp3_sample.mp3")
- video_clip = common.get_sample_clip("one_fps_numeroted_blue.mkv")
- audio_video_clip = common.get_sample_clip("tears_of_steel.webm")
+ audio_clip = GES.UriClipAsset.request_sync(common.get_sample_uri("mp3_sample.mp3")).extract()
+ video_clip =
GES.UriClipAsset.request_sync(common.get_sample_uri("one_fps_numeroted_blue.mkv")).extract()
+ audio_video_clip =
GES.UriClipAsset.request_sync(common.get_sample_uri("tears_of_steel.webm")).extract()
# Add the clips to a layer so they have TrackElements.
project = common.create_project()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]