pitivi r1404 - trunk/pitivi/ui
- From: edwardrv svn gnome org
- To: svn-commits-list gnome org
- Subject: pitivi r1404 - trunk/pitivi/ui
- Date: Fri, 28 Nov 2008 17:35:40 +0000 (UTC)
Author: edwardrv
Date: Fri Nov 28 17:35:39 2008
New Revision: 1404
URL: http://svn.gnome.org/viewvc/pitivi?rev=1404&view=rev
Log:
refactored zoom interface so that it is much easier to use
Modified:
trunk/pitivi/ui/ruler.py
trunk/pitivi/ui/timeline.py
trunk/pitivi/ui/timelinecanvas.py
trunk/pitivi/ui/timelineobject.py
trunk/pitivi/ui/track.py
trunk/pitivi/ui/zoominterface.py
Modified: trunk/pitivi/ui/ruler.py
==============================================================================
--- trunk/pitivi/ui/ruler.py (original)
+++ trunk/pitivi/ui/ruler.py Fri Nov 28 17:35:39 2008
@@ -27,7 +27,7 @@
import gtk
import gst
import pitivi.instance as instance
-from complexinterface import Zoomable
+from zoominterface import Zoomable
from pitivi.utils import time_to_string
class ScaleRuler(gtk.Layout, Zoomable):
@@ -47,6 +47,7 @@
def __init__(self, hadj):
gst.log("Creating new ScaleRule")
gtk.Layout.__init__(self)
+ Zoomable.__init__(self)
self.add_events(gtk.gdk.POINTER_MOTION_MASK |
gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK)
self.set_hadjustment(hadj)
@@ -309,7 +310,7 @@
context.save()
- zoomRatio = self.getZoomRatio()
+ zoomRatio = self.zoomratio
# looks better largest tick doesn't run into the text label
interval_sizes = ((60, 0.80), (10, 0.75), (1, 0.5), (0.1, 0.25))
for interval, height in interval_sizes:
Modified: trunk/pitivi/ui/timeline.py
==============================================================================
--- trunk/pitivi/ui/timeline.py (original)
+++ trunk/pitivi/ui/timeline.py Fri Nov 28 17:35:39 2008
@@ -31,12 +31,12 @@
from pitivi.timeline.source import TimelineFileSource
from pitivi.timeline import objects
import ruler
-from zoominterface import Zoomable
import dnd
from gettext import gettext as _
from timelinecanvas import TimelineCanvas
from pitivi.receiver import receiver, handler
+from zoominterface import Zoomable
# tooltip text for toolbar
DELETE = _("Delete Selected")
@@ -96,29 +96,29 @@
gst.log("Creating Timeline")
gtk.VBox.__init__(self)
+ self.timeline = instance.PiTiVi.current.timeline
+ self.instance = instance.PiTiVi
+ self.playground = instance.PiTiVi.playground
+
self._zoom_adj = gtk.Adjustment()
self._zoom_adj.lower = self._computeZoomRatio(0)
self._zoom_adj.upper = self._computeZoomRatio(-1)
self._cur_zoom = 2
- self._zoom_adj.set_value(self._computeZoomRatio(self._cur_zoom))
+ Zoomable.setZoomAdjustment(self._zoom_adj)
+ Zoomable.setZoomRatio(self._computeZoomRatio(self._cur_zoom))
- self.timeline = instance.PiTiVi.current.timeline
- self.instance = instance.PiTiVi
- self.playground = instance.PiTiVi.playground
self._createUI()
def _createUI(self):
self.leftSizeGroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
self.hadj = gtk.Adjustment()
self.ruler = ruler.ScaleRuler(self.hadj)
- self.ruler.setZoomAdjustment(self._zoom_adj)
self.ruler.set_size_request(0, 35)
self.ruler.set_border_width(2)
self.pack_start(self.ruler, expand=False, fill=True)
# List of TimelineCanvas
self.__canvas = TimelineCanvas(self.timeline)
- self.__canvas.setZoomAdjustment(self._zoom_adj)
self.scrolledWindow = gtk.ScrolledWindow(self.hadj)
self.scrolledWindow.set_policy(gtk.POLICY_ALWAYS, gtk.POLICY_AUTOMATIC)
Modified: trunk/pitivi/ui/timelinecanvas.py
==============================================================================
--- trunk/pitivi/ui/timelinecanvas.py (original)
+++ trunk/pitivi/ui/timelinecanvas.py Fri Nov 28 17:35:39 2008
@@ -2,7 +2,6 @@
from point import Point
import goocanvas
from zoominterface import Zoomable
-import pitivi.instance as instance
from pitivi.receiver import receiver, handler
import gtk
@@ -26,6 +25,7 @@
def __init__(self, timeline):
goocanvas.Canvas.__init__(self)
+ Zoomable.__init__(self)
self._selected_sources = []
self.__tracks = []
@@ -166,11 +166,8 @@
## Zoomable Override
def zoomChanged(self):
- instance.PiTiVi.current.timeline.setDeadband(self.pixelToNs(DEADBAND))
-
- def setChildZoomAdjustment(self, adj):
- for track in self.__tracks:
- track.setZoomAdjustment(adj)
+ if self.timeline:
+ self.timeline.setDeadband(self.pixelToNs(DEADBAND))
## Timeline callbacks
@@ -196,7 +193,6 @@
def _trackAdded(self, unused_timeline, comp, position):
track = Track(comp=comp)
self.__tracks.append(track)
- track.setZoomAdjustment(self.getZoomAdjustment())
track.set_canvas(self)
self.tracks.add_child(track)
self._regroup_tracks()
Modified: trunk/pitivi/ui/timelineobject.py
==============================================================================
--- trunk/pitivi/ui/timelineobject.py (original)
+++ trunk/pitivi/ui/timelineobject.py Fri Nov 28 17:35:39 2008
@@ -44,6 +44,7 @@
**kwargs
)
View.__init__(self)
+ Zoomable.__init__(self)
class StartHandle(TrimHandle):
@@ -91,6 +92,7 @@
def __init__(self, element, composition):
goocanvas.Group.__init__(self)
View.__init__(self)
+ Zoomable.__init__(self)
self.element = element
self.comp = composition
@@ -110,23 +112,20 @@
self.start_handle = StartHandle(element,
height=self.__HEIGHT__)
- self.start_handle.setZoomAdjustment(self.getZoomAdjustment())
self.end_handle = EndHandle(element,
height=self.__HEIGHT__)
- self.end_handle.setZoomAdjustment(self.getZoomAdjustment())
for thing in (self.bg, self.start_handle, self.end_handle, self.name):
self.add_child(thing)
+
+ if element:
+ self.zoomChanged()
self.normal()
def zoomChanged(self):
self._start_duration_cb(self.element, self.element.start,
self.element.duration)
- def setChildZoomAdjustment(self, adj):
- self.start_handle.setZoomAdjustment(adj)
- self.end_handle.setZoomAdjustment(adj)
-
@handler(element, "start-duration-changed")
def _start_duration_cb(self, obj, start, duration):
self.set_simple_transform(self.nsToPixel(start), 0, 1, 0)
Modified: trunk/pitivi/ui/track.py
==============================================================================
--- trunk/pitivi/ui/track.py (original)
+++ trunk/pitivi/ui/track.py Fri Nov 28 17:35:39 2008
@@ -14,13 +14,13 @@
def __init__(self, comp=None):
goocanvas.Group.__init__(self)
+ Zoomable.__init__(self)
self.widgets = {}
self.comp = comp
@handler(comp, "source-added")
def _objectAdded(self, unused_timeline, element):
w = TimelineObject(element, self.comp)
- w.setZoomAdjustment(self.getZoomAdjustment())
self.widgets[element] = w
self.add_child(w)
@@ -30,6 +30,3 @@
self.remove_child(w)
del self.widgets[element]
- def setChildZoomAdjustment(self, adj):
- for widget in self.widgets.itervalues():
- widget.setZoomAdjustment(adj)
Modified: trunk/pitivi/ui/zoominterface.py
==============================================================================
--- trunk/pitivi/ui/zoominterface.py (original)
+++ trunk/pitivi/ui/zoominterface.py Fri Nov 28 17:35:39 2008
@@ -21,10 +21,12 @@
# Boston, MA 02111-1307, USA.
"""
-Interfaces for complex view elements
+Interface for managing tranformation between timeline timestamps and UI
+pixels.
"""
import gst
+from pitivi.receiver import receiver, handler
#
# Complex Timeline interfaces v2 (01 Jul 2008)
@@ -39,73 +41,77 @@
# ex : 0.1 = 1 pixel for 10 seconds
# ex : 1.0 = 1 pixel for a second
#
-# Methods:
+# Class Methods
# . setZoomAdjustment(adj)
# . getZoomAdjustment()
-# . setChildZoomAdjustment()
-# . zoomChanged()
-# . setZoomRatio(ratio)
-# . getZoomRatio(ratio)
+# . getZoomRatio
# . pixelToNs(pixels)
# . nsToPixels(time)
+# . setZoomRatio
+# Instance Methods
+# . zoomChanged()
-# FIXME: this might be poor design. while sharing the adjustment
-# does provide an easy way of ensuring that all the UI elements are
-# updated, it's a little bit kludgey when it comes to sharing the
-# adjustment among elements which have children. In general, it migh
-# be better to factor this interface out into a separate Transformation
-# class which can handle the conversion between coordinate systems, for
-# both horizontal and vertical coordinates. This interface only handles
-# the horizontal.
-
-class Zoomable:
-
- zoomratio = 0
- zoom_adj = None
-
- def setZoomAdjustment(self, adjustment):
- if self.zoom_adj:
- self.zoom_adj.disconnect(self._zoom_changed_sigid)
- self.zoom_adj = adjustment
- if adjustment:
- self._zoom_changed_sigid = adjustment.connect("value-changed",
- self._zoom_changed_cb)
- self.zoomratio = adjustment.get_value()
- self.setChildZoomAdjustment(adjustment)
- self.zoomChanged()
-
- def getZoomAdjustment(self):
- return self.zoom_adj
-
- def _zoom_changed_cb(self, adjustment):
- self.zoomratio = adjustment.get_value()
- self.zoomChanged()
-
- def getZoomRatio(self):
- return self.zoomratio
+class Zoomable(object):
- def setZoomRatio(self, ratio):
- self.zoom_adj.set_value(ratio)
+ zoomratio = 10
+ zoom_adjustment = None
+ sigid = None
+ __instances = []
+
+ def __init__(self):
+ object.__init__(self)
+ self.__instances.append(self)
+
+ def __del__(self):
+ if self in Zoomable.__instances:
+ self.__instances.remove(self)
+
+ @classmethod
+ def _zoom_changed_cb(cls, adjustment):
+ cls.zoomratio = adjustment.get_value()
+ cls.__zoomChanged()
+
+ @classmethod
+ def setZoomAdjustment(cls, adjustment):
+ if cls.zoom_adjustment:
+ cls.zoom_adjustment.disconnect(cls.sigid)
+ cls.zoom_adjustment = None
+ if adjustment:
+ cls.sigid = adjustment.connect("value-changed",
+ cls._zoom_changed_cb)
+ cls.zoom_adjustment = adjustment
+ cls._zoom_changed_cb(adjustment)
+
+ @classmethod
+ def getZoomAdjustment(cls):
+ return cls.zoom_adjustment
+
+ @classmethod
+ def setZoomRatio(cls, ratio):
+ cls.zoom_adjustment.set_value(ratio)
- def pixelToNs(self, pixel):
+ @classmethod
+ def pixelToNs(cls, pixel):
"""
Returns the pixel equivalent in nanoseconds according to the zoomratio
"""
- return long(pixel * gst.SECOND / self.zoomratio)
+ return long(pixel * gst.SECOND / cls.zoomratio)
- def nsToPixel(self, duration):
+ @classmethod
+ def nsToPixel(cls, duration):
"""
Returns the pixel equivalent of the given duration, according to the
set zoom ratio
"""
if duration == gst.CLOCK_TIME_NONE:
return 0
- return int((float(duration) / gst.SECOND) * self.zoomratio)
+ return int((float(duration) / gst.SECOND) * cls.zoomratio)
- # Override in subclasses
+ @classmethod
+ def __zoomChanged(cls):
+ for inst in cls.__instances:
+ inst.zoomChanged()
def zoomChanged(self):
pass
- def setChildZoomAdjustment(self, adj):
- pass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]