summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <ixce@ed3n-n.aulo.in>2009-07-11 11:20:08 +0200
committerGuillaume Seguin <ixce@ed3n-n.aulo.in>2009-07-11 11:20:08 +0200
commitbcea41367b0b705e725eff65903891611cab5635 (patch)
tree325283a004237a0c7f8d39a2ed71ace530be0a30
parentd460782af4701072b70463329c77333ae3ce4a7f (diff)
downloadpylyricsdisplay-bcea41367b0b705e725eff65903891611cab5635.tar.gz
pylyricsdisplay-bcea41367b0b705e725eff65903891611cab5635.tar.bz2
Make the whole display thing work alright. Yay !
-rw-r--r--pylyricsdisplay.py72
1 files changed, 49 insertions, 23 deletions
diff --git a/pylyricsdisplay.py b/pylyricsdisplay.py
index c35b20a..75d27f7 100644
--- a/pylyricsdisplay.py
+++ b/pylyricsdisplay.py
@@ -27,27 +27,35 @@ pygst.require('0.10')
import gst
import cluttergtk
import clutter
-import gobject, gtk, sys
-import cairo, pango
+import gobject, gtk
+import pango
+import sys
+from datetime import datetime, timedelta
class LyricsDisplay (cluttergtk.Embed):
def __init__ (self, uri):
super (LyricsDisplay, self).__init__ ()
self.set_size_request (800, 400)
+ self.connect_after ("size-allocate", self.update_positions)
self.stage = self.get_stage ()
self.stage.set_color (clutter.Color (0, 0, 0, 255))
self.label = clutter.Label ()
- self.label.set_width (800)
- self.label.set_alignment (pango.ALIGN_CENTER)
- self.label.set_anchor_point_from_gravity (clutter.GRAVITY_CENTER)
- self.label.set_position (400, 200)
- self.label.set_use_markup (True)
- self.label.set_color (clutter.Color (255, 255, 255, 255))
- self.label.show ()
+ self.set_label_properties (self.label, font_size = 25)
self.stage.add (self.label)
+ self.label.show ()
+ self.label_next = clutter.Label ()
+ self.set_label_properties (self.label_next, font_size = 20)
+ self.stage.add (self.label_next)
+ self.label_next.show ()
self.parse (uri)
+ def set_label_properties (self, label, font_size = 25):
+ label.set_font_name ("Sans %d" % font_size)
+ label.set_anchor_point_from_gravity (clutter.GRAVITY_CENTER)
+ label.set_use_markup (True)
+ label.set_color (clutter.Color (255, 255, 255, 255))
+
def start (self):
self.line = 0
self.item = -1
@@ -55,21 +63,38 @@ class LyricsDisplay (cluttergtk.Embed):
self.next_line = 0
self.next_item = 0
if self.bits:
- self.label.set_text (self.get_current_line (0))
+ self.label.set_text (self.get_current_line ())
+ self.label_next.set_text (self.get_next_line ())
+ self.update_positions ()
+
+ def update_positions (self, *args):
+ x = (self.stage.get_width () - self.label.get_width ()) / 2
+ y = self.stage.get_height () / 2
+ self.label.set_position (x, y)
+ x_next = (self.stage.get_width () - self.label_next.get_width ()) / 2
+ y_next = self.stage.get_height () / 2 + self.label_next.get_height () + 10
+ self.label_next.set_position (x_next, y_next)
def reset (self):
pass
- def get_current_line (self, current_timer):
+ def get_current_line (self):
line = ""
- got_current = False
- for timer, content in self.bits[self.line]:
- if not got_current and current_timer >= timer:
- got_current = True
- line += content
+ for i in range (len (self.bits[self.line])):
+ if i == self.item:
+ line += '''<span foreground="yellow">%s</span>''' % self.bits[self.line][i][1]
else:
+ line += self.bits[self.line][i][1]
+ return line.strip ()
+
+ def get_next_line (self):
+ if self.line == len (self.bits) - 1:
+ return ""
+ else:
+ line = ""
+ for timer, content in self.bits[self.line + 1]:
line += content
- return line
+ return line.strip ()
def update (self, timer):
if self.next_line != -1 and timer >= self.next_timer:
@@ -83,10 +108,11 @@ class LyricsDisplay (cluttergtk.Embed):
self.next_item = 0
self.next_timer = self.bits[self.next_line][self.next_item][0]
else:
- self.next_item +=1
+ self.next_item += 1
self.next_timer = self.bits[self.next_line][self.next_item][0]
- print "prout"
- self.label.set_text (self.get_current_line (timer))
+ self.label.set_text (self.get_current_line ())
+ self.label_next.set_text (self.get_next_line ())
+ self.update_positions ()
return
def parse (self, uri):
@@ -148,7 +174,7 @@ class PyLyricsDisplay (object):
self.player.set_state (gst.STATE_PLAYING)
self.display.start ()
self.status_update_timer = gobject.timeout_add (500, self.update_statusbar)
- self.display_update_timer = gobject.timeout_add (100, self.update_display)
+ self.display_update_timer = gobject.timeout_add (10, self.update_display)
widget.set_label ("Stop")
else:
self.player.set_state (gst.STATE_NULL)
@@ -163,7 +189,7 @@ class PyLyricsDisplay (object):
self.display.update (position)
return True
except:
- return False
+ return True
def update_statusbar (self):
try:
@@ -174,7 +200,7 @@ class PyLyricsDisplay (object):
self.set_status ("%s / %s" % (pos_t.strftime ("%H:%M:%S"), dur_t.strftime ("%H:%M:%S")))
return True
except:
- return False
+ return True
def set_status (self, status):
context = self.statusbar.get_context_id ("main")