- Mostly work on ImageRow, but some toying with threads and loading artists

This commit is contained in:
noisymime 2008-03-18 12:46:14 +00:00
parent 97bc2dafe9
commit d4b3a1ed27
3 changed files with 77 additions and 52 deletions

View File

@ -78,6 +78,8 @@ class artist(MusicObject):
return
self.name = self.name.replace("'","")
self.name = self.name.replace("/","_")
self.name = self.name.replace("\\","_")
filename = base_dir + self.name + ".png"
try:
pixbuf.save(filename, "png")

View File

@ -9,7 +9,7 @@ from modules.music_player.lastFM_interface import lastFM_interface
from ui_elements.image_row import ImageRow
from ui_elements.image_frame import ImageFrame
class Module():
class Module:
title = "Music"
num_columns = 6
@ -31,7 +31,8 @@ class Module():
self.is_playing = False
#self.load_albums()
self.load_artists()
#self.load_artists()
thread.start_new_thread(self.load_artists, ())
def setup_ui(self):
@ -64,6 +65,9 @@ class Module():
if event.keyval == clutter.keysyms.q:
clutter.main_quit()
if (event.keyval == clutter.keysyms.Left) or (event.keyval == clutter.keysyms.Right):
self.imageRow.input_queue.input(event)
def begin(self, glossMgr):
#Create a backdrop for the player. In this case we just use the same background as the menus
@ -73,25 +77,37 @@ class Module():
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)
self.backdrop_behaviour = clutter.BehaviourOpacity(opacity_start=0, opacity_end=255, alpha=alpha)
self.timeline_backdrop = clutter.Timeline(10,40)
self.alpha = clutter.Alpha(self.timeline_backdrop, clutter.ramp_inc_func)
self.backdrop_behaviour = clutter.BehaviourOpacity(opacity_start=0, opacity_end=255, alpha=self.alpha)
self.backdrop_behaviour.apply(self.backdrop)
timeline_backdrop.start()
#Load in the initial images:
self.load_image_range(0, self.num_columns)
self.stage.add(self.imageRow)
self.imageRow.set_opacity(0)
self.imageRow.show()
self.backdrop_behaviour.apply(self.imageRow)
self.timeline_backdrop.start()
#Load the rest of the images
thread.start_new_thread(self.load_image_range, (self.num_columns, len(self.artists)-1))
#thread.start_new_thread(self.load_image_range, (self.num_columns, len(self.artists)-1))
#self.timeline_backdrop.connect("completed", self.load_image_range_cb)
#self.load_image_range(self.num_columns, len(self.artists)-1)
self.imageRow.select_first()
#Just a callback function to call 'load_image_range()'
def load_image_range_cb(self, timeline):
thread.start_new_thread(self.load_image_range, (self.num_columns, len(self.artists)-1))
def load_image_range(self, start, end, thread_data = None):
#clutter.threads_init()
for i in range(start, end):
artist = self.artists[i]
print "loading: " + artist.name
pixbuf = artist.get_image()
tmpImage = clutter.Texture()
if pixbuf == artist.PENDING_DOWNLOAD:
@ -99,15 +115,21 @@ class Module():
elif not pixbuf is None:
#tmpImage.set_pixbuf(pixbuf)
tmpImage = ImageFrame(pixbuf, self.imageRow.image_size)
self.imageRow.add_texture_group(tmpImage)
self.imageRow.add_texture_group(tmpImage)
#clutter.threads_leave()
print "Finished threads"
#A simple callback funtion to set the image of an artist/album after it has completed a download
def set_image_cb(self, data, music_object, tmpImage):
#if self.glossMgr.debug:
print "Image for music_obect '%s' downloaded" % (music_object.name)
print "Image for music_object '%s' downloaded" % (music_object.name)
pixbuf = music_object.get_image()
if not pixbuf is None:
tmpImage.set_pixbuf(pixbuf)
clutter.threads_init()
tmpImage.set_pixbuf(pixbuf)
clutter.threads_leave()
def stop(self):
pass

View File

@ -27,15 +27,19 @@ class ImageRow(clutter.Group):
self.images_width = int(width * self.images_size_percent)
self.images_height = int(height * self.images_size_percent)
#Columns must be an odd number
if (columns % 2) == 0: columns += 1
self.num_columns = columns
self.image_size = int(self.images_width / self.num_columns) #A cover will be cover_size * cover_size (X * Y)
self.center = int(columns / 2) + 1
#The viewer actually sits within another group that clips its size
self.images_group_clip = clutter.Group()
self.images_group_clip.add(self.images_group)
#Nasty hack to get around centering problem
self.images_group.set_position(int(self.image_size/2), int(self.image_size/2))
pos_x = int(self.image_size/2) + (self.image_size * (self.center-1))
self.images_group.set_position(pos_x, int(self.image_size/2))
#And setup the clip size and position
scale_amount = int(self.image_size * self.scaleFactor - self.image_size)
clip_width = (self.image_size*columns) + scale_amount #Width is the cover size by the number of colums, plus the additional amount required for scaling
@ -83,7 +87,7 @@ class ImageRow(clutter.Group):
tempGroup.set_position(x, y)
#If we're past the maximum rows, make the pics invistible
if self.num_images > (self.num_columns-1):
if self.num_images > (self.num_columns-self.center):
tempGroup.set_opacity(0)
else:
self.images_group.add(tempGroup)
@ -94,40 +98,41 @@ class ImageRow(clutter.Group):
def select_item(self, incomingItem, outgoingItem):
self.timeline = clutter.Timeline(10,35)
alpha = clutter.Alpha(self.timeline, clutter.smoothstep_inc_func)
self.input_queue.set_timeline(self.timeline)
#Check if the cover is currently not visible
rolling = False
if incomingItem > (self.max_visible_columns-1):
self.rollViewer(self.DIRECTION_LEFT, self.timeline)
rolling = True
if incomingItem < (self.min_visible_columns):
self.rollViewer(self.DIRECTION_RIGHT, self.timeline)
rolling = True
outgoingTexture = self.textureLibrary[outgoingItem]
incomingTexture = self.textureLibrary[incomingItem]
alpha = clutter.Alpha(self.timeline, clutter.smoothstep_inc_func)# clutter.ramp_inc_func)
#Do the stuff for edge cases (ie the textures coming in and going out)
if incomingItem > outgoingItem:
direction = self.DIRECTION_RIGHT
edge_texture_incoming_no = outgoingItem + (self.center)
edge_texture_outgoing_no = outgoingItem - (self.center)
else:
direction = self.DIRECTION_LEFT
edge_texture_incoming_no = outgoingItem - (self.center)
edge_texture_outgoing_no = outgoingItem + (self.center)
edge_texture_incoming = self.textureLibrary[edge_texture_incoming_no]
if edge_texture_outgoing_no >= 0:
edge_texture_outgoing = self.textureLibrary[edge_texture_outgoing_no]
self.timeline.connect('completed', self.remove_item, edge_texture_outgoing_no)
self.images_group.add(edge_texture_incoming)
self.behaviourEdgeIncomingOpacity = clutter.BehaviourOpacity(opacity_start=0, opacity_end=self.inactiveOpacity, alpha=alpha)
self.behaviourEdgeIncomingOpacity.apply(edge_texture_incoming)
#Now do the stuff for selecting the image in the middle
self.behaviourNew_scale = clutter.BehaviourScale(x_scale_start=1, y_scale_start=1, x_scale_end=self.scaleFactor, y_scale_end=self.scaleFactor, alpha=alpha) #clutter.GRAVITY_CENTER)
self.behaviourNew_z = clutter.BehaviourDepth(depth_start=1, depth_end=2, alpha=alpha)
#If we're performing a roll (See above) then the incoming opacity should start at 0 rather than the normal inactive opacity
if rolling:
self.behaviourNew_opacity = clutter.BehaviourOpacity(opacity_start=0, opacity_end=255, alpha=alpha)
else:
self.behaviourNew_opacity = clutter.BehaviourOpacity(opacity_start=self.inactiveOpacity, opacity_end=255, alpha=alpha)
self.behaviourNew_opacity = clutter.BehaviourOpacity(opacity_start=self.inactiveOpacity, opacity_end=255, alpha=alpha)
self.behaviourOld_scale = clutter.BehaviourScale(x_scale_start=self.scaleFactor, y_scale_start=self.scaleFactor, x_scale_end=1, y_scale_end=1, alpha=alpha)
self.behaviourOld_z = clutter.BehaviourDepth(depth_start=2, depth_end=1, alpha=alpha)
self.behaviourOld_opacity = clutter.BehaviourOpacity(opacity_start=255, opacity_end=self.inactiveOpacity, alpha=alpha)
(x, y) = incomingTexture.get_position()
(x, y) = self.images_group.get_position()
anchor_x = incomingTexture.get_width()/2
anchor_y = incomingTexture.get_height()/2
#self.images_group.set_anchor_point(anchor_x, anchor_y)
#incomingTexture.set_anchor_point(anchor_x, anchor_y)
self.behaviourNew_scale.apply(incomingTexture)
self.behaviourNew_z.apply(incomingTexture)
self.behaviourNew_opacity.apply(incomingTexture)
@ -135,16 +140,18 @@ class ImageRow(clutter.Group):
self.behaviourOld_z.apply(outgoingTexture)
self.behaviourOld_opacity.apply(outgoingTexture)
#Set gravities
(x, y) = outgoingTexture.get_position()
anchor_x = outgoingTexture.get_width()/2
anchor_y = outgoingTexture.get_height()/2
#outgoingTexture.set_anchor_point(anchor_x, anchor_y)
#incomingTexture.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER)
#outgoingTexture.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER)
#And finally, moving the whole thing left/right
(x, y) = self.images_group.get_position()
if direction == self.DIRECTION_RIGHT:
(new_x, new_y) = ( (x-(self.image_size+self.image_gap)), y)
else:
(new_x, new_y) = ( (x+(self.image_size+self.image_gap)), y)
knots = (\
(x, y),\
(new_x, new_y)\
)
self.behaviour_path = clutter.BehaviourPath(alpha, knots)
self.behaviour_path.apply(self.images_group)
self.currentSelection = incomingItem
@ -153,12 +160,6 @@ class ImageRow(clutter.Group):
def select_first(self):
self.timeline = clutter.Timeline(20,80)
self.input_queue.set_timeline(self.timeline)
"""
if not len(self.folderLibrary) == 0:
pass
else:
self.current_video_details.set_video(self.videoLibrary[0], self.timeline)
"""
incomingItem = 0
incomingTexture = self.textureLibrary[incomingItem]
@ -242,7 +243,7 @@ class ImageRow(clutter.Group):
self.behaviour_outgoing.apply(self.textureLibrary[incoming])
self.behaviour_incoming.apply(self.textureLibrary[outgoing])
def remove_item(self, itemNo):
def remove_item(self, timeline = None, itemNo = None):
self.images_group.remove(self.textureLibrary[itemNo])
@ -276,7 +277,7 @@ class ImageRow(clutter.Group):
self.move_common(newItem)
def move_right(self):
#This check makes sure that we're not on the last cover already
if not self.currentSelection == (self.num_covers-1):
if not self.currentSelection == (self.num_images-1):
newItem = self.currentSelection + 1
self.move_common(newItem)
def move_common(self, newItem):