1
# PiTiVi , Non-linear video editor
5
# Copyright (c) 2006, Edward Hervey <bilboed@bilboed.com>
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.
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.
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.
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. """
30
from pitivi.receiver import receiver, handler
31
from pitivi.ui.zoominterface import Zoomable
32
import pitivi.ui.previewer as previewer
35
return (a <= b) and (b <= c)
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))
41
class Preview(goocanvas.ItemSimple, goocanvas.Item, Zoomable):
43
__gtype_name__ = 'Preview'
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
54
def _get_height(self):
56
def _set_height (self, value):
59
height = gobject.property(_get_height, _set_height, type=float)
63
def _set_element(self):
64
self.previewer = previewer.get_preview_for_object(self.element)
65
element = receiver(setter=_set_element)
67
@handler(element, "in-point-changed")
68
@handler(element, "media-duration-changed")
69
def _media_props_changed(self, obj, unused_start_duration):
72
## previewer callbacks
74
previewer = receiver()
76
@handler(previewer, "update")
77
def _update_preview(self, previewer, segment):
80
## Zoomable interface overries
82
def zoomChanged(self):
85
## goocanvas item methods
87
def do_simple_update(self, cr):
89
if self.element.factory:
90
self.bounds = goocanvas.Bounds(0, 0,
91
Zoomable.nsToPixel(self.element.duration), self.height)
93
def do_simple_paint(self, cr, bounds):
95
if self.element.factory:
96
self.previewer.render_cairo(cr, intersect(self.bounds, bounds),
97
self.element, self.bounds.y1)
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))