pitivi r1130 - in branches/SOC_2008_BLEWIS: . pitivi/ui



Author: blewis
Date: Mon Jun  2 02:41:49 2008
New Revision: 1130
URL: http://svn.gnome.org/viewvc/pitivi?rev=1130&view=rev

Log:
* pitivi/ui/timelineobjects.py:
removed gtk.Layout() cruft. gutted composition callbacks. partially
uncommeted dnd callbacks
* pitivi/ui/util.py:
added new methods to HList(): remove_all() and point_to_index()
added new global function pixel_coords()


Modified:
   branches/SOC_2008_BLEWIS/ChangeLog
   branches/SOC_2008_BLEWIS/pitivi/ui/timelineobjects.py
   branches/SOC_2008_BLEWIS/pitivi/ui/util.py

Modified: branches/SOC_2008_BLEWIS/pitivi/ui/timelineobjects.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/ui/timelineobjects.py	(original)
+++ branches/SOC_2008_BLEWIS/pitivi/ui/timelineobjects.py	Mon Jun  2 02:41:49 2008
@@ -133,15 +133,13 @@
 #        self.childheight = int(DEFAULT_SIMPLE_ELEMENT_HEIGHT)
 #        self.childwidth = int(DEFAULT_SIMPLE_ELEMENT_WIDTH)
         self.set_size_request(int(MINIMUM_WIDTH), int(MINIMUM_HEIGHT))
-
         # drag and drop
-        self.drag_dest_set(gtk.DEST_DEFAULT_DROP | gtk.DEST_DEFAULT_MOTION,
-                           [dnd.FILESOURCE_TUPLE],
-                           gtk.gdk.ACTION_COPY)
+        self.drag_dest_set(gtk.DEST_DEFAULT_DROP | 
+            gtk.DEST_DEFAULT_MOTION, [dnd.FILESOURCE_TUPLE],
+            gtk.gdk.ACTION_COPY)
         self.connect("drag-data-received", self._dragDataReceivedCb)
         self.connect("drag-leave", self._dragLeaveCb)
         self.connect("drag-motion", self._dragMotionCb)
-        self.slotposition = -1
         self.draggedelement = None
 
     def _request_size(self, item, prop):
@@ -159,12 +157,6 @@
             self.set_scale(self.scale)
         return True
 
-    def add(self, child):
-        self.items.add_child(child)
-
-    def remove(self, child):
-        self.items.remove(child)
-
     ## Project callbacks
 
     def _connectToTimeline(self, timeline):
@@ -183,11 +175,8 @@
         #now we connect to the new project, so we can receive any
         #signals that might be emitted while the project is loading
         self._connectToTimeline(project.timeline)
-        #TODO: display final state of project now that loading has
-        #completed. this callback doesn't do do much else
-
-        #LOAD THE TIMELINE !!!
-        self._condensedListChangedCb(None, self.timeline.videocomp.condensed)
+        self._condensedListChangedCb(None, 
+            self.timeline.videocomp.condensed)
 
     def _newProjectFailedCb(self, unused_inst, unused_reason, unused_uri):
         # oops the project failed to load
@@ -196,137 +185,51 @@
     def _clearTimeline(self):
         self.switchToNormalMode()
         self.project_signals.disconnectAll()
-        self.items.remove()
-        self.items = HList()
-        self.root.add_child(self.items)
+        self.items.remove_all()
 
     def _projectClosedCb(self, unused_pitivi, unused_project):
         self._clearTimeline()
 
-#    ## Timeline callbacks
-#
-#    def _condensedListChangedCb(self, unused_videocomp, clist):
-#        """ add/remove the widgets """
-#        gst.debug("condensed list changed in videocomp")
-#
-#        current = self.widgets.keys()
-#        self.condensed = clist
-#
-#        new = [x for x in clist if not x in current]
-#        removed = [x for x in current if not x in clist]
-#
-#        # new elements
-#        for element in new:
-#            # add the widget to self.widget
-#            gst.debug("Adding new element to the layout")
-#            if isinstance(element, TimelineFileSource):
-#                widget = SimpleSourceWidget(element)
-#                widget.connect("delete-me", self._sourceDeleteMeCb, element)
-#                widget.connect("edit-me", self._sourceEditMeCb, element)
-#                widget.connect("drag-begin", self._sourceDragBeginCb, element)
-#                widget.connect("drag-end", self._sourceDragEndCb, element)
-#            else:
-#                widget = SimpleTransitionWidget(element)
-#            self.widgets[element] = widget
-#            self.put(widget, 0, 0)
-#            widget.show()
-#
-#        # removed elements
-#        for element in removed:
-#            self.remove(self.widgets[element])
-#            del self.widgets[element]
-#
-#        self._resizeChildrens()
-#
-#
-#    ## Utility methods
-#
-#    def _getNearestSourceSlot(self, x):
-#        """
-#        returns the nearest file slot position available for the given position
-#        Returns the value in condensed list position
-#        Returns n , the element before which it should go
-#        Return -1 if it's meant to go last
-#        """
-#        if not self.condensed or x < 0:
-#            return 0
-#        if x > self.width - DEFAULT_SIMPLE_SPACING:
-#            return -1
-#
-#        pos = DEFAULT_SIMPLE_SPACING
-#        order = 0
-#        # TODO Need to avoid getting position between source and transition
-#        for source in self.condensed:
-#            if isinstance(source, TimelineSource):
-#                spacing = self.childwidth
-#            elif isinstance(source, TimelineTransition):
-#                spacing = self.childwidth / 2
-#            else:
-#                # this shouldn't happen !! The condensed list only contains
-#                # sources and/or transitions
-#                pass
-#            if x <= pos + spacing / 2:
-#                return order
-#            pos = pos + spacing + DEFAULT_SIMPLE_SPACING
-#            order = order + 1
-#        return -1
-#
-#    def _getNearestSourceSlotPixels(self, x):
-#        """
-#        returns the nearest file slot position available for the given position
-#        Returns the value in pixels
-#        """
-#        if not self.condensed or x < 0:
-#            return DEFAULT_SIMPLE_SPACING
-#        if x > self.width - DEFAULT_SIMPLE_SPACING:
-#            return self.width - 2 * DEFAULT_SIMPLE_SPACING
-#
-#        pos = DEFAULT_SIMPLE_SPACING
-#        # TODO Need to avoid getting position between source and transition
-#        for source in self.condensed:
-#            if isinstance(source, TimelineSource):
-#                spacing = self.childwidth
-#            elif isinstance(source, TimelineTransition):
-#                spacing = self.childwidth / 2
-#            else:
-#                # this shouldn't happen !! The condensed list only contains
-#                # sources and/or transitions
-#                pass
-#            if x <= pos + spacing / 2:
-#                return pos
-#            pos = pos + spacing + DEFAULT_SIMPLE_SPACING
-#        return pos
-#
-#
-#    ## Drawing
-#
-#    def _drawDragSlot(self):
-#        if self.slotposition == -1:
-#            return
-#        self.bin_window.draw_rectangle(self.style.black_gc, True,
-#                                       self.slotposition, DEFAULT_SIMPLE_SPACING,
-#                                       DEFAULT_SIMPLE_SPACING, self.childheight)
-#
-#    def _eraseDragSlot(self):
-#        if self.slotposition == -1:
-#            return
-#        self.bin_window.draw_rectangle(self.style.white_gc, True,
-#                                       self.slotposition, DEFAULT_SIMPLE_SPACING,
-#                                       DEFAULT_SIMPLE_SPACING, self.childheight)
-#
-#    def _gotFileFactory(self, filefactory, x, unused_y):
-#        """ got a filefactory at the given position """
-#        # remove the slot
-#        self._eraseDragSlot()
-#        self.slotposition = -1
-#        if not filefactory or not filefactory.is_video:
-#            return
-#        pos = self._getNearestSourceSlot(x)
-#
-#        gst.debug("_got_filefactory pos : %d" % pos)
-#
-#        # we just add it here, the drawing will be done in the condensed_list
-#        # callback
+    ## Timeline callbacks
+
+    def _condensedListChangedCb(self, unused_videocomp, clist):
+        """ add/remove the widgets """
+        gst.debug("condensed list changed in videocomp")
+
+        current = self.condensed
+        self.condensed = clist
+
+        new = [x for x in clist if not x in current]
+        removed = [x for x in current if not x in clist]
+
+        # new elements
+        for element in new:
+            # add the widget to self.widget
+            gst.debug("Adding new element to the layout")
+            if isinstance(element, TimelineFileSource):
+                widget = SimpleSourceWidget(element)
+                widget.connect("delete-me", self._sourceDeleteMeCb, element)
+                widget.connect("edit-me", self._sourceEditMeCb, element)
+            else:
+                widget = SimpleTransitionWidget(element)
+            self.widgets[element] = goocanvas.Widget(widget=widget)
+            self.items.add_child(self.widgets[element])
+
+        # removed elements
+        for element in removed:
+            self.items.remove(self.widgets[element])
+            del self.widgets[element]
+
+    def _gotFileFactory(self, filefactory, x, y):
+        """ got a filefactory at the given position """
+        # remove the slot
+        if not filefactory or not filefactory.is_video:
+            return
+        pos_ = self.items.point_to_index(pixel_coords(self, (x, y)))
+        gst.debug("_got_filefactory pos : %d" % pos_)
+
+        # we just add it here, the drawing will be done in the condensed_list
+        # callback
 #        source = TimelineFileSource(factory=filefactory,
 #                                    media_type=MEDIA_TYPE_VIDEO,
 #                                    name=filefactory.name)
@@ -355,89 +258,42 @@
 #        self.timeline.videocomp.moveSource(element, pos)
 
 #    ## Drag and Drop callbacks
-#
-    def _dragMotionCb(self, unused_layout, unused_context, x, unused_y,
-                      unused_timestamp):
-        # TODO show where the dragged item would go
-#        pos = self._getNearestSourceSlotPixels(x + (self.hadjustment.get_value()))
-#        rpos = self._getNearestSourceSlot(x + self.hadjustment.get_value())
+
+    def _dragMotionCb(self, unused_layout, unused_context, x, y, 
+        unused_timestamp):
         gst.log("SimpleTimeline x:%d , source would go at %d" % (x, 0))
-#        if not pos == self.slotposition:
-#            if not self.slotposition == -1:
-#                # erase previous slot position
-#                self._eraseDragSlot()
-#            # draw new slot position
-#            self.slotposition = pos
-#            self._drawDragSlot()
-#
-    def _dragLeaveCb(self, unused_layout, unused_context, unused_timestamp):
+
+    def _dragLeaveCb(self, unused_layout, unused_context, unused_tstamp):
         gst.log("SimpleTimeline")
-#        self._eraseDragSlot()
-#        self.slotposition = -1
-#        # TODO remove the drag emplacement
-#
-    def _dragDataReceivedCb(self, unused_layout, context, x, y, selection,
-                            targetType, timestamp):
-        gst.log("SimpleTimeline, targetType:%d, selection.data:%s" % (targetType, selection.data))
-#        if targetType == dnd.TYPE_PITIVI_FILESOURCE:
-#            uri = selection.data
-#        else:
-#            context.finish(False, False, timestamp)
-#        x = x + int(self.hadjustment.get_value())
-#        if self.draggedelement:
-#            self._moveElement(self.draggedelement, x)
-#        else:
-#            self._gotFileFactory(instance.PiTiVi.current.sources[uri], x, y)
-#        context.finish(True, False, timestamp)
-#        instance.PiTiVi.playground.switchToTimeline()
-#
-#
-#    ## Drawing
-#
-#    def _realizeCb(self, unused_layout):
-#        self.modify_bg(gtk.STATE_NORMAL, self.style.white)
-#
-#    def _areaIntersect(self, x, y, w, h, x2, y2, w2, h2):
-#        """ returns True if the area intersects, else False """
-#        # is zone to the left of zone2
-#        z1 = gtk.gdk.Rectangle(x, y, w, h)
-#        z2 = gtk.gdk.Rectangle(x2, y2, w2, h2)
-#        r = z1.intersect(z2)
-#        a, b, c, d = r
-#        if a or b or c or d:
-#            return True
-#        return False
-#
-#    def _exposeEventCb(self, unused_layout, event):
-#        x, y, w, h = event.area
-#        # redraw the slot rectangle if there's one
-#        if not self.slotposition == -1:
-#            if self._areaIntersect(x, y, w, h,
-#                                   self.slotposition, DEFAULT_SIMPLE_SPACING,
-#                                   DEFAULT_SIMPLE_SPACING, self.childheight):
-#                self.bin_window.draw_rectangle(self.style.black_gc, True,
-#                                               self.slotposition, DEFAULT_SIMPLE_SPACING,
-#                                               DEFAULT_SIMPLE_SPACING, self.childheight)
-#
-#        return False
-#
-#    def _sizeAllocateCb(self, unused_layout, allocation):
-#        if not self.height == allocation.height:
-#            self.height = allocation.height
-#            self.childheight = self.height - 2 * DEFAULT_SIMPLE_SPACING
-#            self.childwidth = int(self.height / DEFAULT_SIMPLE_SIZE_RATIO)
-#            self._resizeChildrens()
-#        self.realWidth = allocation.width
-#        if self._editingMode:
-#            self.editingWidget.set_size_request(self.realWidth - 20,
-#                                                self.height - 20)
-#
 
-#    ## Child callbacks
+    def _dragDataReceivedCb(self, unused_layout, context, x, y, 
+        selection, targetType, timestamp):
+        gst.log("SimpleTimeline, targetType:%d, selection.data:%s" % 
+            (targetType, selection.data))
+        if targetType == dnd.TYPE_PITIVI_FILESOURCE:
+            uri = selection.data
+        else:
+            self._gotFileFactory(instance.PiTiVi.current.sources[uri], 
+                x, y)
+        context.finish(True, False, timestamp)
+        instance.PiTiVi.playground.switchToTimeline()
 #
-#    def _sourceDeleteMeCb(self, unused_widget, element):
-#        # remove this element from the timeline
-#        self.timeline.videocomp.removeSource(element, collapse_neighbours=True)
+    def _areaIntersect(self, x, y, w, h, x2, y2, w2, h2):
+        """ returns True if the area intersects, else False """
+        # is zone to the left of zone2
+        z1 = gtk.gdk.Rectangle(x, y, w, h)
+        z2 = gtk.gdk.Rectangle(x2, y2, w2, h2)
+        r = z1.intersect(z2)
+        a, b, c, d = r
+        if a or b or c or d:
+            return True
+        return False
+    ## Child callbacks
+
+    def _sourceDeleteMeCb(self, unused_widget, element):
+        # remove this element from the timeline
+        self.timeline.videocomp.removeSource(element, 
+            collapse_neighbours=True)
 #
     def _sourceEditMeCb(self, unused_widget, element):
         self.switchToEditingMode(element)
@@ -453,7 +309,8 @@
         gst.log("source:%s , mode:%s" % (source, mode))
 
         if self._editingMode == mode:
-            gst.warning("We were already in the correct editing mode : %s" % mode)
+            gst.warning("We were already in correct editing mode : %s" % 
+                mode)
             return
 
         if mode and not source:

Modified: branches/SOC_2008_BLEWIS/pitivi/ui/util.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/ui/util.py	(original)
+++ branches/SOC_2008_BLEWIS/pitivi/ui/util.py	Mon Jun  2 02:41:49 2008
@@ -27,8 +27,12 @@
 
 def event_coords(canvas, event):
     """returns the coordinates of an event"""
-    sx, sy = (canvas.props.scale_x, canvas.props.scale_y)
-    return canvas.convert_from_pixels(sx * event.x, sy * event.y)
+    return canvas.convert_from_pixels(canvas.props.scale_x * event.x, 
+        canvas.props.scale_y * event.y)
+
+def pixel_coords(canvas, point):
+    return canvas.convert_from_pixels(canvas.props.scale_x * point[0], 
+        canvas.props.scale_y * point[1])
 
 def point_difference(p1, p2):
     """Returns the 2-dvector difference p1 - p2"""
@@ -319,6 +323,12 @@
     def index(self, child):
         return child.get_data("index")
 
+    def point_to_index(self, point):
+        x, y = point
+        bounds = goocanvas.Bounds(x, y, x, y)
+        return [i for i in self.canvas.get_items_in_area(bounds, 
+            True, True, True) if i.get_data("index")]
+
     def _reorder(self, new_order):
         order = []
         for index in new_order:
@@ -396,6 +406,10 @@
         if self.reorderable:
             self.unmake_reorderable(child)
         self.tidy()
+
+    def remove_all(self):
+        while len(self.order):
+            self.remove_child(self.order.pop())
     
     def make_reorderable(self, child):
         make_dragable(self.canvas, child, self._child_drag,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]