2007-08-14 18:10:53 -07:00
|
|
|
import pygtk
|
|
|
|
import gtk
|
|
|
|
import clutter
|
2008-03-02 12:46:41 -08:00
|
|
|
from modules.music_player.music_objects.song import song
|
2008-03-07 05:06:44 -08:00
|
|
|
from modules.music_player.music_objects.artist import artist
|
|
|
|
from modules.music_player.music_objects.album import album
|
2008-03-06 04:22:03 -08:00
|
|
|
from modules.music_player.lastFM_interface import lastFM_interface
|
2008-03-02 12:46:41 -08:00
|
|
|
from ui_elements.image_row import ImageRow
|
2007-08-14 18:10:53 -07:00
|
|
|
|
2007-11-19 03:38:15 -08:00
|
|
|
class Module():
|
|
|
|
title = "Music"
|
2007-08-14 18:10:53 -07:00
|
|
|
|
2008-01-06 04:11:17 -08:00
|
|
|
def __init__(self, glossMgr, dbMgr):
|
|
|
|
self.stage = glossMgr.get_stage()
|
|
|
|
self.glossMgr = glossMgr
|
2008-03-02 12:46:41 -08:00
|
|
|
self.dbMgr = dbMgr
|
2008-01-06 04:11:17 -08:00
|
|
|
self.setup_ui()
|
2008-03-02 12:46:41 -08:00
|
|
|
self.albums = []
|
2008-03-07 05:06:44 -08:00
|
|
|
self.artists = []
|
2008-03-02 12:46:41 -08:00
|
|
|
self.songs = []
|
|
|
|
|
2008-03-07 05:06:44 -08:00
|
|
|
self.imageRow = ImageRow(self.glossMgr, self.stage.get_width(), 100, 10)
|
|
|
|
|
|
|
|
self.lastFM = lastFM_interface()
|
2008-03-02 12:46:41 -08:00
|
|
|
self.base_dir = self.dbMgr.get_setting("MusicLocation")
|
2008-03-07 05:06:44 -08:00
|
|
|
self.images_dir = self.get_images_dir()
|
2008-03-02 12:46:41 -08:00
|
|
|
print "Music Base Dir: " + self.base_dir
|
2007-08-14 18:10:53 -07:00
|
|
|
|
|
|
|
self.is_playing = False
|
2008-03-07 05:06:44 -08:00
|
|
|
#self.load_albums()
|
|
|
|
self.load_artists()
|
2008-03-06 04:22:03 -08:00
|
|
|
|
2007-08-14 18:10:53 -07:00
|
|
|
|
2008-01-06 04:11:17 -08:00
|
|
|
def setup_ui(self):
|
|
|
|
self.menu_image = self.glossMgr.themeMgr.get_texture("music_menu_image", None, None)
|
2008-03-07 05:06:44 -08:00
|
|
|
|
|
|
|
#Get the images dir setting our of the DB
|
|
|
|
#But also creates the setting if it doesn't already exist
|
|
|
|
def get_images_dir(self):
|
|
|
|
images_dir = self.dbMgr.get_setting("GlossMusicImgLocation")
|
|
|
|
|
|
|
|
if images_dir is None:
|
|
|
|
#We need to create the setting
|
|
|
|
#Default value is the same as the music base_dir + covers
|
|
|
|
images_dir = self.base_dir + "/.images/"
|
|
|
|
images_dir = images_dir.replace("//", "/") #Just a silly little check
|
|
|
|
self.dbMgr.set_setting("GlossMusicImgLocation", images_dir)
|
|
|
|
|
|
|
|
return images_dir
|
|
|
|
|
2007-11-19 03:38:15 -08:00
|
|
|
#Action to take when menu item is selected
|
|
|
|
def action(self):
|
|
|
|
return self
|
|
|
|
|
2007-08-14 18:10:53 -07:00
|
|
|
def on_key_press_event (self, stage, event):
|
|
|
|
if event.keyval == clutter.keysyms.p:
|
|
|
|
if self.paused:
|
|
|
|
self.unpause()
|
|
|
|
else:
|
|
|
|
self.pause()
|
|
|
|
if event.keyval == clutter.keysyms.q:
|
|
|
|
clutter.main_quit()
|
|
|
|
|
2008-03-06 04:22:03 -08:00
|
|
|
def begin(self, glossMgr):
|
2007-08-14 18:10:53 -07:00
|
|
|
|
|
|
|
#Create a backdrop for the player. In this case we just use the same background as the menus
|
2008-03-06 04:22:03 -08:00
|
|
|
self.backdrop = glossMgr.get_themeMgr().get_texture("background", None, None)
|
2007-08-14 18:10:53 -07:00
|
|
|
self.backdrop.set_size(self.stage.get_width(), self.stage.get_height())
|
|
|
|
self.backdrop.set_opacity(0)
|
|
|
|
self.backdrop.show()
|
|
|
|
self.stage.add(self.backdrop)
|
|
|
|
#Fade the backdrop in
|
|
|
|
timeline_backdrop = clutter.Timeline(10,40)
|
|
|
|
alpha = clutter.Alpha(timeline_backdrop, clutter.ramp_inc_func)
|
2008-03-06 04:22:03 -08:00
|
|
|
self.backdrop_behaviour = clutter.BehaviourOpacity(opacity_start=0, opacity_end=255, alpha=alpha)
|
|
|
|
self.backdrop_behaviour.apply(self.backdrop)
|
2007-08-14 18:10:53 -07:00
|
|
|
timeline_backdrop.start()
|
|
|
|
|
2008-03-07 05:06:44 -08:00
|
|
|
for artist in self.artists:
|
|
|
|
pixbuf = artist.get_image()
|
|
|
|
if not pixbuf is None:
|
|
|
|
tmpImage = clutter.Texture()
|
|
|
|
tmpImage.set_pixbuf(pixbuf)
|
|
|
|
self.imageRow.add_texture_group(tmpImage)
|
|
|
|
|
|
|
|
|
|
|
|
self.stage.add(self.imageRow)
|
|
|
|
self.imageRow.show()
|
2008-03-06 04:22:03 -08:00
|
|
|
|
2007-08-14 18:10:53 -07:00
|
|
|
def stop(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def pause(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def unpause(self):
|
|
|
|
pass
|
2008-03-02 12:46:41 -08:00
|
|
|
|
|
|
|
def load_albums(self):
|
|
|
|
#Generate some SQL to retrieve videos that were in the final_file_list
|
|
|
|
#Load the videos into the cover viewer
|
|
|
|
sql = "SELECT * FROM music_songs" # WHERE filename IN ("
|
|
|
|
if self.glossMgr.debug: print "Music SQL: " + sql
|
|
|
|
|
|
|
|
results = self.dbMgr.run_sql(sql)
|
|
|
|
|
|
|
|
#Check for null return
|
|
|
|
if results == None:
|
|
|
|
print "MusicPlayer: No connection to DB or no songs found in DB"
|
|
|
|
return None
|
|
|
|
|
2008-03-06 04:22:03 -08:00
|
|
|
pixbuf = None
|
2008-03-02 12:46:41 -08:00
|
|
|
#Else add the entries in
|
|
|
|
for record in results:
|
2008-03-06 04:22:03 -08:00
|
|
|
tempSong = song(self)
|
2008-03-02 12:46:41 -08:00
|
|
|
tempSong.import_from_mythObject(record)
|
|
|
|
self.songs.append(tempSong)
|
2008-03-06 04:22:03 -08:00
|
|
|
|
|
|
|
|
|
|
|
if not tempSong.get_image()is None:
|
|
|
|
pixbuf = tempSong.get_image()
|
|
|
|
break
|
2008-03-02 12:46:41 -08:00
|
|
|
#print filename
|
|
|
|
#tempSong.set_file(filename)
|
2007-08-14 18:10:53 -07:00
|
|
|
|
2008-03-06 04:22:03 -08:00
|
|
|
if not pixbuf is None:
|
|
|
|
loader = gtk.gdk.PixbufLoader()
|
|
|
|
loader.write(pixbuf)
|
|
|
|
loader.close()
|
|
|
|
pixbuf = loader.get_pixbuf()
|
|
|
|
self.tmpImage = clutter.Texture()
|
|
|
|
self.tmpImage.set_pixbuf(pixbuf)
|
2007-08-14 18:10:53 -07:00
|
|
|
|
2008-03-07 05:06:44 -08:00
|
|
|
def load_artists(self):
|
|
|
|
#Generate some SQL to retrieve videos that were in the final_file_list
|
|
|
|
#Load the videos into the cover viewer
|
|
|
|
sql = "SELECT * FROM music_artists" # WHERE filename IN ("
|
|
|
|
if self.glossMgr.debug: print "Music Artist SQL: " + sql
|
|
|
|
|
|
|
|
results = self.dbMgr.run_sql(sql)
|
|
|
|
|
|
|
|
#Check for null return
|
|
|
|
if results == None:
|
|
|
|
print "MusicPlayer: No connection to DB or no artists found in DB"
|
|
|
|
return None
|
|
|
|
|
|
|
|
pixbuf = None
|
|
|
|
#Else add the entries in
|
|
|
|
for record in results:
|
|
|
|
tempArtist = artist(self)
|
|
|
|
tempArtist.import_from_mythObject(record)
|
|
|
|
self.artists.append(tempArtist)
|
|
|
|
|
|
|
|
"""
|
|
|
|
if not tempArtist.get_image()is None:
|
|
|
|
pixbuf = tempArtist.get_image()
|
|
|
|
break
|
|
|
|
"""
|
|
|
|
#print filename
|
|
|
|
#tempSong.set_file(filename)
|
|
|
|
"""
|
|
|
|
if not pixbuf is None:
|
|
|
|
self.tmpImage = clutter.Texture()
|
|
|
|
self.tmpImage.set_pixbuf(pixbuf)
|
|
|
|
"""
|