[pitivi] timeline: Start cleaning UI elements when they are removed
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] timeline: Start cleaning UI elements when they are removed
- Date: Sat, 31 Aug 2013 01:22:42 +0000 (UTC)
commit a2cb5fc09db1288a136e1a16b11776310ee14992
Author: Mathieu Duponchelle <mathieu duponchelle epitech eu>
Date: Sat Aug 24 19:48:55 2013 +0200
timeline: Start cleaning UI elements when they are removed
Fixes https://github.com/pitivi/pitivi/issues/105
pitivi/timeline/elements.py | 50 ++++++++++++++++++++++++++++++----------
pitivi/timeline/previewers.py | 8 ++++++
pitivi/timeline/timeline.py | 3 ++
3 files changed, 48 insertions(+), 13 deletions(-)
---
diff --git a/pitivi/timeline/elements.py b/pitivi/timeline/elements.py
index bfd386a..b3c88df 100644
--- a/pitivi/timeline/elements.py
+++ b/pitivi/timeline/elements.py
@@ -31,6 +31,8 @@ import math
import os
from datetime import datetime
+import weakref
+
from gi.repository import Clutter, Gtk, GtkClutter, Cogl, GES, Gdk, Gst, GstController, GLib
from pitivi.utils.timeline import Zoomable, EditingContext, Selection, SELECT, UNSELECT, SELECT_ADD, Selected
from previewers import AudioPreviewer, VideoPreviewer, BORDER_WIDTH
@@ -219,7 +221,7 @@ class TrimHandle(Clutter.Texture):
self.isLeft = isLeft
self.isSelected = False
- self.timelineElement = timelineElement
+ self.timelineElement = weakref.proxy(timelineElement)
self.dragAction = Clutter.DragAction()
self.set_from_file(os.path.join(configure.get_pixmap_dir(), "trimbar-normal.png"))
@@ -240,6 +242,10 @@ class TrimHandle(Clutter.Texture):
self.timelineElement.connect("leave-event", self._elementLeaveEventCb)
self.timelineElement.bElement.selected.connect("selected-changed", self._selectedChangedCb)
+ def cleanup(self):
+ self.timelineElement.disconnect_by_func(self._elementEnterEventCb)
+ self.timelineElement.disconnect_by_func(self._elementLeaveEventCb)
+
#Callbacks
def _enterEventCb(self, actor, event):
@@ -349,7 +355,7 @@ class TimelineElement(Clutter.Actor, Zoomable):
self.timeline = timeline
self.bElement = bElement
self.bElement.selected = Selected()
- self.bElement.ui_element = self
+ self.bElement.ui_element = weakref.proxy(self)
self.track_type = self.bElement.get_track_type() # This won't change
self.isDragged = False
self.lines = []
@@ -357,6 +363,7 @@ class TimelineElement(Clutter.Actor, Zoomable):
self.keyframesVisible = False
self.source = None
self.keyframedElement = None
+ self.rightHandle = None
size = self.bElement.get_duration()
self._createBackground(track)
@@ -386,11 +393,9 @@ class TimelineElement(Clutter.Actor, Zoomable):
self.border.set_easing_duration(600)
self.preview.save_easing_state()
self.preview.set_easing_duration(600)
- try:
+ if self.rightHandle:
self.rightHandle.save_easing_state()
self.rightHandle.set_easing_duration(600)
- except AttributeError: # Element doesnt't have handles
- pass
self.marquee.set_size(width, height)
self.background.props.width = width
@@ -400,19 +405,15 @@ class TimelineElement(Clutter.Actor, Zoomable):
self.props.width = width
self.props.height = height
self.preview.set_size(width, height)
- try:
+ if self.rightHandle:
self.rightHandle.set_position(width - self.rightHandle.props.width, 0)
- except AttributeError: # Element doesnt't have handles
- pass
if ease:
self.background.restore_easing_state()
self.border.restore_easing_state()
self.preview.restore_easing_state()
- try:
+ if self.rightHandle:
self.rightHandle.restore_easing_state()
- except AttributeError: # Element doesnt't have handles
- pass
self.restore_easing_state()
def addKeyframe(self, value, timestamp):
@@ -514,6 +515,20 @@ class TimelineElement(Clutter.Actor, Zoomable):
self.drawLines()
+ def cleanup(self):
+ Zoomable.__del__(self)
+ self.disconnectFromEvents()
+
+ def disconnectFromEvents(self):
+ self.dragAction.disconnect_by_func(self._dragProgressCb)
+ self.dragAction.disconnect_by_func(self._dragBeginCb)
+ self.dragAction.disconnect_by_func(self._dragEndCb)
+ self.remove_action(self.dragAction)
+ self.bElement.selected.disconnect_by_func(self._selectedChangedCb)
+ self.bElement.disconnect_by_func(self._durationChangedCb)
+ self.bElement.disconnect_by_func(self._inpointChangedCb)
+ self.disconnect_by_func(self._clickedCb)
+
# private API
def update(self, ease):
@@ -686,7 +701,7 @@ class Line(Clutter.Actor):
"""
def __init__(self, timelineElement, keyframe, lastKeyframe):
Clutter.Actor.__init__(self)
- self.timelineElement = timelineElement
+ self.timelineElement = weakref.proxy(timelineElement)
self.canvas = Clutter.Canvas()
self.canvas.set_size(1000, KEYFRAME_SIZE)
@@ -840,7 +855,7 @@ class Keyframe(Clutter.Actor):
Clutter.Actor.__init__(self)
self.value = value
- self.timelineElement = timelineElement
+ self.timelineElement = weakref.proxy(timelineElement)
self.has_changable_time = has_changable_time
self.lastClick = datetime.now()
@@ -1118,6 +1133,15 @@ class URISourceElement(TimelineElement):
self._context.editTo(new_start, priority)
self._context.finish()
+ def cleanup(self):
+ if self.preview:
+ self.preview.cleanup()
+ self.leftHandle.cleanup()
+ self.leftHandle = None
+ self.rightHandle.cleanup()
+ self.rightHandle = None
+ TimelineElement.cleanup(self)
+
class TransitionElement(TimelineElement):
def __init__(self, bElement, track, timeline):
diff --git a/pitivi/timeline/previewers.py b/pitivi/timeline/previewers.py
index 2e8cf76..98ab315 100644
--- a/pitivi/timeline/previewers.py
+++ b/pitivi/timeline/previewers.py
@@ -512,6 +512,9 @@ class VideoPreviewer(Clutter.ScrollActor, PreviewGenerator, Zoomable, Loggable):
self.pipeline = None
PreviewGenerator.emit(self, "done")
+ def cleanup(self):
+ Zoomable.__del__(self)
+
class Thumbnail(Clutter.Actor):
def __init__(self, width, height):
@@ -983,3 +986,8 @@ class AudioPreviewer(Clutter.Actor, PreviewGenerator, Zoomable, Loggable):
self.pipeline.set_state(Gst.State.NULL)
self.pipeline.get_state(Gst.CLOCK_TIME_NONE)
PreviewGenerator.emit(self, "done")
+
+ def cleanup(self):
+ self.canvas.disconnect_by_func(self._drawContentCb)
+ self.timeline.disconnect_by_func(self._scrolledCb)
+ Zoomable.__del__(self)
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 6781a98..5bbc669 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -469,13 +469,16 @@ class TimelineStage(Clutter.ScrollActor, Zoomable):
bElement.disconnect_by_func(self._elementStartChangedCb)
bElement.disconnect_by_func(self._elementDurationChangedCb)
bElement.disconnect_by_func(self._elementInPointChangedCb)
+ bElement.disconnect_by_func(self._elementPriorityChangedCb)
for element in self.elements:
if element.bElement == bElement:
break
+ element.cleanup()
self.elements.remove(element)
self.remove_child(element)
+ self.selection.setSelection(set([]), SELECT)
def _setElementX(self, element, ease=True):
if ease:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]