[pitivi/ges: 190/287] thumbnailing: Move all thumbnailing code to timeline/thumbnailing.py
- From: Jean-FranÃois Fortin Tam <jfft src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi/ges: 190/287] thumbnailing: Move all thumbnailing code to timeline/thumbnailing.py
- Date: Thu, 15 Mar 2012 16:41:48 +0000 (UTC)
commit 047165a6b11b89e8a19464e8ac6dfcdc63070b48
Author: Thibault Saunier <thibault saunier collabora com>
Date: Tue Jan 10 19:51:53 2012 -0300
thumbnailing: Move all thumbnailing code to timeline/thumbnailing.py
pitivi/Makefile.am | 3 +-
pitivi/thumbnailcache.py | 64 ---------------------
pitivi/timeline/Makefile.am | 7 +-
pitivi/{ui/preview.py => timeline/thumbnailer.py} | 52 +++++++++++++++--
pitivi/ui/Makefile.am | 1 -
po/POTFILES.in | 2 +-
tests/test_cache.py | 3 +-
7 files changed, 53 insertions(+), 79 deletions(-)
---
diff --git a/pitivi/Makefile.am b/pitivi/Makefile.am
index 16364ee..b78f02e 100644
--- a/pitivi/Makefile.am
+++ b/pitivi/Makefile.am
@@ -16,8 +16,7 @@ pitivi_PYTHON = \
instance.py \
project.py \
settings.py \
- medialibrary.py \
- thumbnailcache.py
+ medialibrary.py
BUILT_SOURCES=configure.py
diff --git a/pitivi/timeline/Makefile.am b/pitivi/timeline/Makefile.am
index fb79ba4..0f79a25 100644
--- a/pitivi/timeline/Makefile.am
+++ b/pitivi/timeline/Makefile.am
@@ -2,10 +2,11 @@ timelinedir = $(libdir)/pitivi/python/pitivi/timeline
timeline_PYTHON = \
__init__.py \
- timeline.py \
- track.py \
curve.py \
- ruler.py
+ ruler.py \
+ thumbnailer.py \
+ timeline.py \
+ track.py
clean-local:
rm -rf *.pyc *.pyo
diff --git a/pitivi/ui/preview.py b/pitivi/timeline/thumbnailer.py
similarity index 95%
rename from pitivi/ui/preview.py
rename to pitivi/timeline/thumbnailer.py
index f28df28..9cd3b44 100644
--- a/pitivi/ui/preview.py
+++ b/pitivi/timeline/thumbnailer.py
@@ -1,6 +1,6 @@
# PiTiVi , Non-linear video editor
#
-# pitivi/ui/preview.py
+# pitivi/timeline/thumbnailing.py
#
# Copyright (c) 2006, Edward Hervey <bilboed bilboed com>
#
@@ -21,20 +21,21 @@
#FIXME GES port Reimplement me
+"""
+ Handle thumbnails in the UI timeline
+"""
+
import gst
import os
import cairo
import gobject
import goocanvas
+import collections
from gettext import gettext as _
from pitivi.settings import GlobalSettings
from pitivi.configure import get_pixmap_dir
-from pitivi.thumbnailcache import ThumbnailCache
-
-import pitivi.ui.previewer as previewer
-
import pitivi.utils as utils
@@ -120,6 +121,44 @@ PreferencesDialog.addTogglePreference('showWaveforms',
label=_("Enable audio waveforms"),
description=_("Show waveforms on audio clips"))
+
+class ThumbnailCache(object):
+
+ """Caches thumbnails by key using LRU policy, implemented with heapq"""
+
+ def __init__(self, size=100):
+ object.__init__(self)
+ self.queue = collections.deque()
+ self.cache = {}
+ self.hits = 0
+ self.misses = 0
+ self.size = size
+
+ def __contains__(self, key):
+ if key in self.cache:
+ self.hits += 1
+ return True
+ self.misses += 1
+ return False
+
+ def __getitem__(self, key):
+ if key in self.cache:
+ # I guess this is why LRU is considered expensive
+ self.queue.remove(key)
+ self.queue.append(key)
+ return self.cache[key]
+ raise KeyError(key)
+
+ def __setitem__(self, key, value):
+ self.cache[key] = value
+ self.queue.append(key)
+ if len(self.cache) > self.size:
+ self.ejectLRU()
+
+ def ejectLRU(self):
+ key = self.queue.popleft()
+ del self.cache[key]
+
# Previewer -- abstract base class with public interface for UI
# |_DefaultPreviewer -- draws a default thumbnail for UI
# |_LivePreviewer -- draws a continuously updated preview
@@ -130,6 +169,7 @@ PreferencesDialog.addTogglePreference('showWaveforms',
# |_RandomAccessVideoPreviewer -- video-specific pipeline and rendering
# |_StillImagePreviewer -- only uses one segment
+
previewers = {}
@@ -644,7 +684,7 @@ class Preview(goocanvas.ItemSimple, goocanvas.Item, Zoomable):
## element callbacks
def _set_element(self):
- self.previewer = previewer.get_preview_for_object(self.app,
+ self.previewer = get_preview_for_object(self.app,
self.element)
element = receiver(setter=_set_element)
diff --git a/pitivi/ui/Makefile.am b/pitivi/ui/Makefile.am
index e1eb0d0..a25aee6 100644
--- a/pitivi/ui/Makefile.am
+++ b/pitivi/ui/Makefile.am
@@ -8,7 +8,6 @@ ui_PYTHON = \
mainwindow.py \
prefs.py \
preset.py \
- preview.py \
basetabs.py \
startupwizard.py \
viewer.py \
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 395d17e..4fa3221 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -22,6 +22,7 @@ pitivi/medialibrary.py
pitivi/timeline/timeline.py
pitivi/timeline/track.py
+pitivi/timeline/thumbnailer.py
pitivi/ui/basetabs.py
pitivi/ui/clipproperties.py
@@ -29,7 +30,6 @@ pitivi/ui/filechooserpreview.py
pitivi/ui/filelisterrordialog.py
pitivi/ui/mainwindow.py
pitivi/ui/prefs.py
-pitivi/ui/preview.py
pitivi/ui/viewer.py
pitivi/utils/misc.py
diff --git a/tests/test_cache.py b/tests/test_cache.py
index f0e7fdc..5d45598 100644
--- a/tests/test_cache.py
+++ b/tests/test_cache.py
@@ -1,7 +1,6 @@
import unittest
-import pitivi
from common import TestCase
-from pitivi.thumbnailcache import ThumbnailCache
+from pitivi.timeline.thumbnailer import ThumbnailCache
class CacheTest(TestCase):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]