Thread pain
This commit is contained in:
parent
a264a2c5f2
commit
cd455a6fab
|
@ -1,4 +1,6 @@
|
|||
import time
|
||||
import gobject
|
||||
from myth.MythMySQL import mythDB
|
||||
from modules.music_player.music_objects.song import song
|
||||
from modules.music_player.music_objects.artist import artist
|
||||
from modules.music_player.music_objects.album import album
|
||||
|
@ -7,19 +9,40 @@ from modules.music_player.music_objects.album import album
|
|||
# This is the backend for the regular MythMusic backend.
|
||||
# Information is pulled from the 'mythconverg' mysql db
|
||||
#############################################################
|
||||
class Backend:
|
||||
class Backend(gobject.GObject):
|
||||
#Setup signals
|
||||
__gsignals__ = {
|
||||
"query-complete": (
|
||||
gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []),
|
||||
"deselected": (
|
||||
gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [])
|
||||
}
|
||||
|
||||
def __init__(self, music_player):
|
||||
gobject.GObject.__init__(self)
|
||||
|
||||
self.music_player = music_player
|
||||
self.dbMgr = music_player.dbMgr
|
||||
|
||||
self.cache_artists = []
|
||||
self.cache_albums_by_artistID = {}
|
||||
self.cache_songs_by_albumID = {}
|
||||
|
||||
|
||||
#Returns a list of artist objects
|
||||
def get_artists(self):
|
||||
def get_artists(self, no_cache = False):
|
||||
#Check cache
|
||||
if (not no_cache) and (len(self.cache_artists) > 0):
|
||||
return self.cache_artists
|
||||
|
||||
#Load the videos into the cover viewer
|
||||
sql = "SELECT * FROM music_artists ORDER BY artist_name"
|
||||
if self.music_player.glossMgr.debug: print "Music Artist SQL: " + sql
|
||||
|
||||
results = self.dbMgr.run_sql(sql)
|
||||
#results = self.dbMgr.run_sql(sql)
|
||||
dbMgr = mythDB()
|
||||
results = dbMgr.run_sql(sql)
|
||||
dbMgr.close_db()
|
||||
|
||||
#Check for null return
|
||||
if results == None:
|
||||
|
@ -36,15 +59,23 @@ class Backend:
|
|||
#self.artistImageRow.add_object(tempArtist)
|
||||
time.sleep(0.01) #Arbitary sleep time to avoid CPU bound status
|
||||
|
||||
self.cache_artists = artists
|
||||
return artists
|
||||
|
||||
#Given an artistID, returns a list of albums for them
|
||||
def get_albums_by_artistID(self, id):
|
||||
def get_albums_by_artistID(self, id, no_cache = False):
|
||||
#Check cache
|
||||
if (not no_cache) and (self.cache_albums_by_artistID.has_key(str(id))):
|
||||
return self.cache_albums_by_artistID[str(id)]
|
||||
|
||||
#Generate some SQL
|
||||
sql = "SELECT * FROM music_albums where artist_id='%s'" % (str(id))
|
||||
if self.music_player.glossMgr.debug: print "Music Album SQL: " + sql
|
||||
|
||||
results = self.dbMgr.run_sql(sql)
|
||||
#results = self.dbMgr.run_sql(sql)
|
||||
dbMgr = mythDB()
|
||||
results = dbMgr.run_sql(sql)
|
||||
dbMgr.close_db()
|
||||
|
||||
#Check for null return
|
||||
if results == None:
|
||||
|
@ -52,22 +83,33 @@ class Backend:
|
|||
return None
|
||||
|
||||
pixbuf = None
|
||||
artists = []
|
||||
albums = []
|
||||
#Else add the entries in
|
||||
for record in results:
|
||||
tempAlbum = album(self.music_player)
|
||||
tempAlbum.import_from_mythObject(record)
|
||||
artists.append(tempAlbum)
|
||||
albums.append(tempAlbum)
|
||||
#self.artistImageRow.add_object(tempArtist)
|
||||
return artists
|
||||
|
||||
self.emit("query-complete")
|
||||
self.cache_albums_by_artistID[str(id)] = albums
|
||||
return albums
|
||||
|
||||
#Given an albumID, returns a list of songs on the album
|
||||
def get_songs_by_albumID(self, id):
|
||||
def get_songs_by_albumID(self, id, no_cache = False):
|
||||
#Check cache
|
||||
if (not no_cache) and (self.cache_songs_by_albumID.has_key(str(id))):
|
||||
return self.cache_songs_by_albumID[str(id)]
|
||||
|
||||
|
||||
#Generate some SQL
|
||||
sql = "SELECT * FROM music_songs where album_id='%s'" % (str(id))
|
||||
if self.music_player.glossMgr.debug: print "Music Song SQL: " + sql
|
||||
|
||||
results = self.dbMgr.run_sql(sql)
|
||||
#results = self.dbMgr.run_sql(sql)
|
||||
dbMgr = mythDB()
|
||||
results = dbMgr.run_sql(sql)
|
||||
dbMgr.close_db()
|
||||
|
||||
#Check for null return
|
||||
if results == None:
|
||||
|
@ -82,5 +124,7 @@ class Backend:
|
|||
tempSong.import_from_mythObject(record)
|
||||
songs.append(tempSong)
|
||||
#self.artistImageRow.add_object(tempArtist)
|
||||
self.emit("query-complete")
|
||||
self.cache_songs_by_albumID[str(id)] = songs
|
||||
return songs
|
||||
|
|
@ -33,22 +33,25 @@ class MusicObjectRow(ImageRow):
|
|||
#self.timeline.connect('completed', self.restart_cb)
|
||||
#time.sleep(self.music_player.sleep_time)
|
||||
|
||||
if as_thread: clutter.threads_enter()
|
||||
|
||||
if pixbuf == object.PENDING_DOWNLOAD:
|
||||
#Get the temporary image
|
||||
if as_thread: clutter.threads_enter()
|
||||
pixbuf = object.get_default_image()
|
||||
tmpImage = ImageFrame(pixbuf, self.image_size, use_reflection = True, quality = ImageFrame.QUALITY_FAST) #clutter.Texture()
|
||||
object.connect("image-found", self.set_image_cb, object, tmpImage)
|
||||
if as_thread: clutter.threads_leave()
|
||||
elif not pixbuf is None:
|
||||
#If we're performing this loading as a seperate thread, we need to lock the Clutter threads
|
||||
|
||||
if as_thread: clutter.threads_enter()
|
||||
tmpImage = ImageFrame(pixbuf, self.image_size, use_reflection=True, quality = ImageFrame.QUALITY_FAST)
|
||||
|
||||
if as_thread: clutter.threads_leave()
|
||||
else:
|
||||
if as_thread: clutter.threads_enter()
|
||||
pixbuf = object.get_default_image()
|
||||
tmpImage = ImageFrame(pixbuf, self.image_size, use_reflection = True, quality = ImageFrame.QUALITY_FAST) #clutter.Texture()
|
||||
if as_thread: clutter.threads_leave()
|
||||
|
||||
if as_thread: clutter.threads_leave()
|
||||
self.add_texture_group(tmpImage)
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import pygtk
|
||||
import gobject
|
||||
import gtk
|
||||
import clutter
|
||||
#import thread, time
|
||||
import thread
|
||||
from modules.music_player.backends.myth_music import Backend
|
||||
from modules.music_player.lastFM_interface import lastFM_interface
|
||||
from modules.music_player.music_object_row import MusicObjectRow
|
||||
|
@ -41,6 +42,8 @@ class Module:
|
|||
self.is_playing = False
|
||||
#self.load_albums()
|
||||
self.artists = self.backend.get_artists()
|
||||
|
||||
self.timeout_id = 0
|
||||
#thread.start_new_thread(self.load_artists, ())
|
||||
|
||||
|
||||
|
@ -80,9 +83,12 @@ class Module:
|
|||
#React based on the current input context
|
||||
if self.current_context == self.CONTEXT_ROW:
|
||||
if (event.keyval == clutter.keysyms.Left) or (event.keyval == clutter.keysyms.Right):
|
||||
duration = float(MusicObjectRow.frames) / float(MusicObjectRow.fps)
|
||||
#First check if there's any current timeouts and if there is, clear it
|
||||
#if not self.timeout_id == 0: gobject.source_remove(self.timeout_id)
|
||||
|
||||
self.artistImageRow.input_queue.input(event)
|
||||
self.artistImageRow.input_queue.connect("queue-flushed", self.load_albums)
|
||||
#self.artistImageRow.input_queue.connect("queue-flushed", self.start_delay, self.load_albums, None)
|
||||
self.queue_id = self.artistImageRow.input_queue.connect("queue-flushed", self.load_albums)
|
||||
self.artistImageRow.sleep = True
|
||||
|
||||
|
||||
|
@ -112,15 +118,24 @@ class Module:
|
|||
self.list2.display()
|
||||
|
||||
#Simple delay
|
||||
def start_delay(self, function, args):
|
||||
gobject.timeout_add((self.delay * 1000), function, args)
|
||||
def start_delay(self, queue, function, args):
|
||||
self.timeout_id = gobject.timeout_add((self.delay * 1000), function, args)
|
||||
|
||||
#Loads albums into List1
|
||||
def load_albums(self, queue):
|
||||
#Just a little test code
|
||||
return
|
||||
self.artistImageRow.input_queue.disconnect(self.queue_id)
|
||||
#Just a little test code
|
||||
artist = self.artistImageRow.get_current_object()
|
||||
thread.start_new_thread(self.backend.get_albums_by_artistID, (artist.artistID,))
|
||||
self.conn_id = self.backend.connect("query-complete", self.update_for_albums, artist)
|
||||
|
||||
def update_for_albums(self, data, artist = None):
|
||||
self.backend.disconnect(self.conn_id)
|
||||
|
||||
if artist is None: self.artistImageRow.get_current_object()
|
||||
albums = self.backend.get_albums_by_artistID(artist.artistID)
|
||||
|
||||
clutter.threads_enter()
|
||||
self.list1.clear()
|
||||
for album in albums:
|
||||
tmpItem = self.list1.add_item(album.name)
|
||||
|
@ -131,7 +146,7 @@ class Module:
|
|||
pixbuf = albums[0].get_image()
|
||||
if not pixbuf is None:
|
||||
self.main_img.set_pixbuf(pixbuf)
|
||||
|
||||
clutter.threads_leave()
|
||||
|
||||
def begin(self, glossMgr):
|
||||
|
||||
|
@ -159,11 +174,11 @@ class Module:
|
|||
|
||||
#Just a nasty temp label for outputting stuff
|
||||
self.list1 = LabelList(5)
|
||||
self.list1.set_position(self.stage.get_width()/2, 350)
|
||||
self.list1.set_position(self.stage.get_width()/3, 350)
|
||||
self.stage.add(self.list1)
|
||||
|
||||
self.list2 = LabelList(5)
|
||||
self.list2.set_position( (self.list1.get_x() + self.list1.get_width()), 350)
|
||||
self.list2.set_position( (self.stage.get_width()/2 + self.list1.get_width()), 350)
|
||||
self.stage.add(self.list2)
|
||||
"""
|
||||
self.tmpLabel = clutter.Label()
|
||||
|
|
|
@ -175,6 +175,7 @@ class ImageRow(clutter.Group):
|
|||
self.currentSelection = incomingItem
|
||||
|
||||
self.timeline.start()
|
||||
|
||||
|
||||
def select_first(self):
|
||||
self.timeline = clutter.Timeline(self.frames, self.fps)
|
||||
|
@ -217,7 +218,6 @@ class ImageRow(clutter.Group):
|
|||
def remove_item(self, timeline = None, itemNo = None):
|
||||
self.textureLibrary[itemNo].set_opacity(0)
|
||||
self.textureLibrary[itemNo].hide()
|
||||
self.textureLibrary[itemNo].unrealize()
|
||||
self.images_group.remove(self.textureLibrary[itemNo])
|
||||
|
||||
|
||||
|
|
|
@ -244,8 +244,10 @@ class ListItem(clutter.Group):
|
|||
|
||||
#Text is actually scaled down in 'regular' position so that it doesn't get jaggies when zoomed in
|
||||
#self.set_scale(self.zoomLevel, self.zoomLevel)
|
||||
self.currentZoom = 0
|
||||
|
||||
self.currentZoom = self.scale_step_medium
|
||||
self.currentOpacity = self.opacity_step_medium
|
||||
self.set_scale(self.currentZoom, self.currentZoom)
|
||||
self.set_opacity(self.currentOpacity)
|
||||
"""
|
||||
#(label_width, label_height) = self.label.get_size()
|
||||
label_x = 0 #x #self.stage.get_width() - label_width - 50
|
||||
|
|
Loading…
Reference in New Issue