[pitivi] ruler: Highlight the different time elements



commit a7cb639b8ac8750edd44125a7ea0a3fd0601a5bf
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Thu Jan 2 15:55:34 2014 +0100

    ruler: Highlight the different time elements
    
    Seems easier to get an idea of the length of the displayed interval and
    the zoom level.

 pitivi/timeline/ruler.py |   34 ++++++++++++++++++++++++++++++++--
 1 files changed, 32 insertions(+), 2 deletions(-)
---
diff --git a/pitivi/timeline/ruler.py b/pitivi/timeline/ruler.py
index fcf2704..17c438d 100644
--- a/pitivi/timeline/ruler.py
+++ b/pitivi/timeline/ruler.py
@@ -1,8 +1,10 @@
+# -*- coding: utf-8 -*-
 # Pitivi video editor
 #
 #       pitivi/timeline/ruler.py
 #
 # Copyright (c) 2006, Edward Hervey <bilboed bilboed com>
+# Copyright (c) 2014, Alex Băluț <alexandru balut gmail com>
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -108,6 +110,16 @@ class ScaleRuler(Gtk.DrawingArea, Zoomable, Loggable):
         self.callback_id_scroll = None
         self.set_size_request(0, 25)
 
+        style = self.get_style_context()
+        color_normal = style.get_color(Gtk.StateFlags.NORMAL)
+        color_insensitive = style.get_color(Gtk.StateFlags.INSENSITIVE)
+        self._color_normal = color_normal
+        self._color_dimmed = Gdk.RGBA(
+            *[(x * 3 + y * 2) / 5
+              for x, y in ((color_normal.red, color_insensitive.red),
+                           (color_normal.green, color_insensitive.green),
+                           (color_normal.blue, color_insensitive.blue))])
+
     def _focusInCb(self, unused_widget, unused_arg):
         self.log("Ruler has grabbed focus")
         self.app.gui.timeline_ui.setActionsSensitivity(True)
@@ -295,13 +307,31 @@ class ScaleRuler(Gtk.DrawingArea, Zoomable, Loggable):
         style = self.get_style_context()
         setCairoColor(context, style.get_color(state))
         y_bearing = context.text_extents("0")[1]
+
+        def split(x):
+            # Seven elements: h : mm : ss . mmm
+            # Using negative indices because the first element (hour)
+            # can have a variable length.
+            return x[:-10], x[-10], x[-9:-7], x[-7], x[-6:-4], x[-4], x[-3:]
+
+        previous_time = split(time_to_string(max(0, seconds - interval)))
         while paintpos < context.get_target().get_width():
-            timevalue = time_to_string(long(seconds))
             context.move_to(int(paintpos), 1 - y_bearing)
-            context.show_text(timevalue)
+            current_time = split(time_to_string(long(seconds)))
+            self._drawTime(context, current_time, previous_time)
+            previous_time = current_time
             paintpos += spacing
             seconds += interval
 
+    def _drawTime(self, context, current, previous):
+        for element, previous_element in zip(current, previous):
+            if element == previous_element:
+                color = self._color_dimmed
+            else:
+                color = self._color_normal
+            setCairoColor(context, color)
+            context.show_text(element)
+
     def drawFrameBoundaries(self, context):
         """
         Draw the alternating rectangles that represent the project frames at


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