[pitivi] titleeditor: Avoid traceback when getting values of enum props
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] titleeditor: Avoid traceback when getting values of enum props
- Date: Sun, 6 Oct 2019 23:37:56 +0000 (UTC)
commit 53197932ebd583f377cbcce19024fcc3ccc67749
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Mon Oct 7 00:23:05 2019 +0200
titleeditor: Avoid traceback when getting values of enum props
Traceback (most recent call last):
File "/.../pitivi/pitivi/titleeditor.py", line 277, in _propertyChangedCb
value = self.source.get_child_property(pspec.name)[1]
TypeError: unknown type (null)
pitivi/titleeditor.py | 26 ++++++++++++++++++--------
tests/test_titleeditor.py | 31 ++++++++++++++++++++-----------
tests/test_undo_timeline.py | 4 ++--
3 files changed, 40 insertions(+), 21 deletions(-)
---
diff --git a/pitivi/titleeditor.py b/pitivi/titleeditor.py
index dadbf0d2..dfcd2394 100644
--- a/pitivi/titleeditor.py
+++ b/pitivi/titleeditor.py
@@ -238,7 +238,7 @@ class TitleEditor(Loggable):
self.infobar.hide()
self.editing_box.show()
self._children_props_handler = self.source.connect('deep-notify',
- self._propertyChangedCb)
+ self._source_deep_notify_cb)
else:
self.infobar.show()
self.editing_box.hide()
@@ -259,47 +259,57 @@ class TitleEditor(Loggable):
"halignment": DEFAULT_HALIGNMENT}
for prop, value in properties.items():
res = source.set_child_property(prop, value)
- assert res
- # Select it so the Title editor becomes active.
+ assert res, prop
self._selection.setSelection([title_clip], SELECT)
- def _propertyChangedCb(self, source, unused_gstelement, pspec):
+ def _source_deep_notify_cb(self, source, unused_gstelement, pspec):
+ """Handles updates in the TitleSource backing the current TitleClip."""
if self._setting_props:
self._project.pipeline.commit_timeline()
return
control_binding = self.source.get_control_binding(pspec.name)
if control_binding:
- self.debug("Not handling %s as it is being interpollated",
+ self.debug("Not handling %s as it is being interpolated",
pspec.name)
return
- value = self.source.get_child_property(pspec.name)[1]
if pspec.name == "text":
- value = value or ""
- if self.textbuffer.props.text == value:
+ res, value = self.source.get_child_property(pspec.name)
+ assert res, pspec.name
+ if self.textbuffer.props.text == value or "":
return
self.textbuffer.props.text = value
elif pspec.name in ["x-absolute", "y-absolute"]:
+ res, value = self.source.get_child_property(pspec.name)
+ assert res, pspec.name
if self.settings[pspec.name].get_value() == value:
return
self.settings[pspec.name].set_value(value)
elif pspec.name in ["valignment", "halignment"]:
+ res, value = self.source.get_child_property(pspec.name)
+ assert res, pspec.name
value = value.value_name
if self.settings[pspec.name].get_active_id() == value:
return
self.settings[pspec.name].set_active_id(value)
elif pspec.name == "font-desc":
+ res, value = self.source.get_child_property(pspec.name)
+ assert res, pspec.name
if self.font_button.get_font_desc() == value:
return
font_desc = Pango.FontDescription.from_string(value)
self.font_button.set_font_desc(font_desc)
elif pspec.name == "color":
+ res, value = self.source.get_child_property(pspec.name)
+ assert res, pspec.name
color = argb_to_gdk_rgba(value)
if color == self.foreground_color_button.get_rgba():
return
self.foreground_color_button.set_rgba(color)
elif pspec.name == "foreground-color":
+ res, value = self.source.get_child_property(pspec.name)
+ assert res, pspec.name
color = argb_to_gdk_rgba(value)
if color == self.background_color_button.get_rgba():
return
diff --git a/tests/test_titleeditor.py b/tests/test_titleeditor.py
index 05afdd87..6c07fae8 100644
--- a/tests/test_titleeditor.py
+++ b/tests/test_titleeditor.py
@@ -24,27 +24,36 @@ from gi.repository import GES
from pitivi.titleeditor import TitleEditor
from tests import common
+from tests.test_undo_timeline import BaseTestUndoTimeline
-class TitleEditorTest(common.TestCase):
+class TitleEditorTest(BaseTestUndoTimeline):
"""Tests for the TitleEditor class."""
def test_create(self):
"""Exercise creating a title clip."""
- timeline_container = common.create_timeline_container(titleClipLength=1)
- project = timeline_container._project
- app = timeline_container.app
-
# Wait until the project creates a layer in the timeline.
common.create_main_loop().run(until_empty=True)
- title_editor = TitleEditor(app)
- title_editor._newProjectLoadedCb(None, project)
- project.pipeline.getPosition = mock.Mock(return_value=0)
+ title_editor = TitleEditor(self.app)
+
+ from pitivi.timeline.timeline import TimelineContainer
+ timeline_container = TimelineContainer(self.app)
+ timeline_container.setProject(self.project)
+ self.app.gui.editor.timeline_ui = timeline_container
+
+ title_editor._newProjectLoadedCb(None, self.project)
+ self.project.pipeline.getPosition = mock.Mock(return_value=0)
title_editor._createCb(None)
- layers = timeline_container.ges_timeline.get_layers()
- self.assertEqual(len(layers), 1, layers)
- clips = layers[0].get_clips()
+ clips = self.layer.get_clips()
self.assertEqual(len(clips), 1, clips)
self.assertIsInstance(clips[0], GES.TitleClip)
+
+ self.action_log.undo()
+ clips = self.layer.get_clips()
+ self.assertEqual(len(clips), 0, clips)
+
+ self.action_log.redo()
+ clips = self.layer.get_clips()
+ self.assertEqual(len(clips), 1, clips)
diff --git a/tests/test_undo_timeline.py b/tests/test_undo_timeline.py
index 2c2fe4bf..db109434 100644
--- a/tests/test_undo_timeline.py
+++ b/tests/test_undo_timeline.py
@@ -43,8 +43,8 @@ class BaseTestUndoTimeline(common.TestCase):
def setUp(self):
super(BaseTestUndoTimeline, self).setUp()
self.app = common.create_pitivi()
- project = self.app.project_manager.new_blank_project()
- self.timeline = project.ges_timeline
+ self.project = self.app.project_manager.new_blank_project()
+ self.timeline = self.project.ges_timeline
self.layer = self.timeline.append_layer()
self.action_log = self.app.action_log
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]