~ubuntu-branches/ubuntu/lucid/pitivi/lucid

« back to all changes in this revision

Viewing changes to pitivi/ui/preview.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2009-05-27 14:22:49 UTC
  • mfrom: (1.2.1 upstream) (3.1.13 experimental)
  • Revision ID: james.westby@ubuntu.com-20090527142249-tj0qnkc37320ylml
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# PiTiVi , Non-linear video editor
 
2
#
 
3
#       pitivi/ui/preview.py
 
4
#
 
5
# Copyright (c) 2006, Edward Hervey <bilboed@bilboed.com>
 
6
#
 
7
# This program is free software; you can redistribute it and/or
 
8
# modify it under the terms of the GNU Lesser General Public
 
9
# License as published by the Free Software Foundation; either
 
10
# version 2.1 of the License, or (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
# Lesser General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU Lesser General Public
 
18
# License along with this program; if not, write to the
 
19
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
20
# Boston, MA 02111-1307, USA.
 
21
 
 
22
"""
 
23
Custom canvas item for timeline object previews. This code is just a thin
 
24
canvas-item wrapper which ensures that the preview is updated appropriately.
 
25
The actual drawing is done by the pitivi.previewer.Previewer class.  """
 
26
 
 
27
import goocanvas
 
28
import gobject
 
29
 
 
30
from pitivi.receiver import receiver, handler
 
31
from pitivi.ui.zoominterface import Zoomable
 
32
import pitivi.ui.previewer as previewer
 
33
 
 
34
def between(a, b, c):
 
35
    return (a <= b) and (b <= c)
 
36
 
 
37
def intersect(b1, b2):
 
38
    return goocanvas.Bounds(max(b1.x1, b2.x1), max(b1.y1, b2.y1),
 
39
        min(b1.x2, b2.x2), min(b1.y2, b2.y2))
 
40
 
 
41
class Preview(goocanvas.ItemSimple, goocanvas.Item, Zoomable):
 
42
 
 
43
    __gtype_name__ = 'Preview'
 
44
 
 
45
    def __init__(self, element, height=50, **kwargs):
 
46
        super(Preview, self).__init__(**kwargs)
 
47
        Zoomable.__init__(self)
 
48
        self.height = float(height)
 
49
        self.element = element
 
50
        self.props.pointer_events = False
 
51
 
 
52
## properties
 
53
 
 
54
    def _get_height(self):
 
55
        return self._height
 
56
    def _set_height (self, value):
 
57
        self._height = value
 
58
        self.changed(True)
 
59
    height = gobject.property(_get_height, _set_height, type=float)
 
60
 
 
61
## element callbacks
 
62
 
 
63
    def _set_element(self):
 
64
        self.previewer = previewer.get_preview_for_object(self.element)
 
65
    element = receiver(setter=_set_element)
 
66
 
 
67
    @handler(element, "in-point-changed")
 
68
    @handler(element, "media-duration-changed")
 
69
    def _media_props_changed(self, obj, unused_start_duration):
 
70
        self.changed(True)
 
71
 
 
72
## previewer callbacks
 
73
 
 
74
    previewer = receiver()
 
75
 
 
76
    @handler(previewer, "update")
 
77
    def _update_preview(self, previewer, segment):
 
78
        self.changed(False)
 
79
 
 
80
## Zoomable interface overries
 
81
 
 
82
    def zoomChanged(self):
 
83
        self.changed(True)
 
84
 
 
85
## goocanvas item methods
 
86
 
 
87
    def do_simple_update(self, cr):
 
88
        cr.identity_matrix()
 
89
        if self.element.factory:
 
90
            self.bounds = goocanvas.Bounds(0, 0,
 
91
            Zoomable.nsToPixel(self.element.duration), self.height)
 
92
 
 
93
    def do_simple_paint(self, cr, bounds):
 
94
        cr.identity_matrix()
 
95
        if self.element.factory:
 
96
            self.previewer.render_cairo(cr, intersect(self.bounds, bounds),
 
97
            self.element, self.bounds.y1)
 
98
 
 
99
    def do_simple_is_item_at(self, x, y, cr, pointer_event):
 
100
        return (between(0, x, self.nsToPixel(self.element.duration)) and
 
101
            between(0, y, self.height))