[jokosher-devel] [PATCH] Use sensible minor ticks in the MM:SS timeline



The timeline in MM:SS mode always has 5 minor ticks between each
numbered tick. When the numbered ticks are 1:00, then each minor tick is
12s, which is an awful number.

In addition, the numbered ticks get very far apart when zooming in and out.

This patch against svn 1464 does the following:

* ensures that there are 6 minor ticks between numbered ticks when the
numbered ticks are 1:00
* adds a few intermediate scale factors so that the numbered ticks do
not get too far apart
* reduces the minimum whitespace between numbered ticks so that numbered
ticks do not get too far apart
* changes the millisecond format separator from ':' to '.'
* ensure that the calculation of when to use millisecond format agrees
with flag returned

The implementation is a bit hacky:

* should use tuples for (factor, numLines) pairs, rather than two
parallel arrays
* there is lots of repeated code to calculate index, factor and numLines

Perhaps I should make these changes before submitting the patch?

Is this the right format to submit a patch?

Stephen


=======================================================================
This email, including any attachments, is only for the intended
addressee.  It is subject to copyright, is confidential and may be
the subject of legal or other privilege, none of which is waived or
lost by reason of this transmission.
If the receiver is not the intended addressee, please accept our
apologies, notify us by return, delete all copies and perform no
other act on the email.
Unfortunately, we cannot warrant that the email has not been
 altered or corrupted during transmission.
=======================================================================

Index: TimeLine.py
===================================================================
--- TimeLine.py	(revision 1464)
+++ TimeLine.py	(working copy)
@@ -30,13 +30,7 @@
 	""" GTK widget name """
 	__gtype_name__ = 'TimeLine'
 	
-	""" Number of 'short' lines + 1 (Used for the MODE_HOURS_MINS_SECS timeline)
-	Like this:	|				|		   	|
-				|  |1 |2 |3 |4 	|  |  |  |  | etc
 	"""
-	_NUM_LINES = 5
-	
-	"""
 	Various color configurations:
 	   ORGBA = Offset, Red, Green, Blue, Alpha
 	   RGBA = Red, Green, Blue, Alpha
@@ -265,7 +259,7 @@
 			# Working in milliseconds here. Using seconds gives modulus problems because they're floats
 			viewScale = self.project.viewScale / 1000.
 			viewStart = int(self.project.viewStart * 1000)
-			factor, displayMilliseconds = self.GetZoomFactor(viewScale)
+			factor, numLines, displayMilliseconds = self.GetZoomFactor(viewScale)
 			
 			# Calculate our scroll offset
 			# sec : viewStart, truncated to 1000ms; the second that has past just before the beginning of our surface
@@ -290,7 +284,7 @@
 			while x < self.get_allocation().width:
 				ix = int(x)
 				
-				if msec % (self._NUM_LINES * factor):
+				if msec % (numLines * factor):
 					lineHeight = int(self.get_allocation().height/1.2)
 				else:
 					lineHeight = int(self.get_allocation().height/2)
@@ -298,7 +292,7 @@
 					# Draw the bar number
 					if displayMilliseconds:
 						#Should use transportmanager for this...
-						number = "%d:%02d:%03d"%((msec/1000) / 60, (msec/1000) % 60, msec%1000)
+						number = "%d:%02d.%03d"%((msec/1000) / 60, (msec/1000) % 60, msec%1000)
 					else:
 						number = "%d:%02d"%((msec/1000) / 60, (msec/1000) % 60)
 						
@@ -487,19 +481,32 @@
 		shortTextWidth = 28 # for '0:00' notation
 		longTextWidth = 56 # for '0:00:000' notation
 		textWidth = shortTextWidth
-		whiteSpace = 50
+		whiteSpace = 32
+
+		#              0    1    2     3     4     5      6      7
+		zoomLevels = [20, 100, 200, 1000, 2000, 5000, 10000, 60000]
+		numLines   = [ 5,   5,   5,    5,    5,    6,     6,     5]
+
 		factor = 1000 # Default factor is 1 second for 1 line
-		zoomLevels = [20, 100, 200, 1000, 4000, 12000, 60000]
-		if (textWidth + whiteSpace) > (self._NUM_LINES * factor * viewScale):
-			factor = zoomLevels[zoomLevels.index(factor) + 1]
-			while (textWidth + whiteSpace) > (self._NUM_LINES * factor * viewScale) and factor != zoomLevels[-1]:
-				factor = zoomLevels[zoomLevels.index(factor) + 1]
+		index = zoomLevels.index(factor)
+		nlines = numLines[index]
+
+		if (textWidth + whiteSpace) > (nlines * factor * viewScale):
+			index = index + 1
+			factor = zoomLevels[index]
+			nlines = numLines[index]
+			while (textWidth + whiteSpace) > (nlines * factor * viewScale) and factor != zoomLevels[-1]:     # index != 7 (currently)
+				index = index + 1
+				factor = zoomLevels[index]
+				nlines = numLines[index]
 		else:
 			while (textWidth + whiteSpace) < (factor * viewScale) and factor != zoomLevels[0]:
-				factor = zoomLevels[zoomLevels.index(factor) - 1]
-				if factor == 200:
+				index = index - 1
+				factor = zoomLevels[index]
+				nlines = numLines[index]
+				if factor < 200:
 					textWidth = longTextWidth
-		return factor, (factor < 200) # 0.2 * 5 = 1.0 second, if the interval is smaller, milliseconds are needed
+		return factor, nlines, (factor < 200)   # 0.2 * 5 = 1.0 second, if the interval is smaller, milliseconds are needed
 	
 	#_____________________________________________________________________
 	

=======================================================================
This email, including any attachments, is only for the intended
addressee.  It is subject to copyright, is confidential and may be
the subject of legal or other privilege, none of which is waived or
lost by reason of this transmission.
If the receiver is not the intended addressee, please accept our
apologies, notify us by return, delete all copies and perform no
other act on the email.
Unfortunately, we cannot warrant that the email has not been
 altered or corrupted during transmission.
=======================================================================



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