Commit bf1317ae authored by Frank Scholz's avatar Frank Scholz
Browse files

relocation of the images, use...

relocation of the images, use [http://peak.telecommunity.com/DevCenter/PkgResources pkg_resources] to retrieve their location now
parent 86fa98a1
......@@ -20,6 +20,7 @@ from pygame.locals import *
# Coherence
from coherence.base import Coherence
from coherence.upnp.core import DIDLLite
import louie
from mediarenderer.menus import Menu
......@@ -100,7 +101,7 @@ class MediaRenderer(object):
self.menus.append(self.top_menu)
config = {}
config['logmode'] = 'info'
config['logmode'] = 'error'
config['controlpoint'] = 'yes'
louie.connect(self.media_server_found, 'Coherence.UPnP.ControlPoint.MediaServer.detected', louie.Any)
......@@ -166,8 +167,10 @@ class MediaRenderer(object):
if self.mode == 1:
return
self.mode = 1
self.audio.toggle_to = None
self.view = self.images
self.screen = self.images.screen
pygame.display.set_caption('Coherence MediaRenderer - %s' % self.images.current_title)
try:
self.menus.remove(self.right_menu)
except:
......@@ -178,8 +181,6 @@ class MediaRenderer(object):
self.images.loop_start()
def switch_to_audio(self):
if self.mode == 0:
return
if self.mode == 1:
self.images.loop_stop()
self.mode = 0
......@@ -216,6 +217,7 @@ class MediaRenderer(object):
self.toggle_fullscreen()
if event.type == MOUSEMOTION:
#self.screen.react(event.pos)
if event.pos[0] <= 70:
"""left hotspot """
self.hide_menus(self.left_menu)
......
__version_info__ = (0,0,3)
__version__ = '%d.%d.%d' % (__version_info__[0],__version_info__[1],__version_info__[2],)
\ No newline at end of file
__version__ = '%d.%d.%d' % (__version_info__[0],__version_info__[1],__version_info__[2],)
__pgk_name__ = 'mediarenderer'
\ No newline at end of file
......@@ -24,15 +24,62 @@ import louie
from mediarenderer.menus import Menu
class Cover(object):
width=260
height=260
def __init__(self, uri):
self.uri = uri
self.finished = False
self.image = pygame.Surface((self.width,self.height))
self.image.fill((0, 0, 0)) # black
self.rect = self.image.get_rect()
def got_error(f):
self.finished = True
louie.send('MediaRenderer.Cover.finished', None, None)
if self.uri is not None:
d = client.getPage(self.uri)
d.addCallback(self.got_cover)
d.addErrback(got_error)
def got_cover(self, result):
try:
import Image
import StringIO
im = Image.open(StringIO.StringIO(result))
self.image = pygame.image.frombuffer( im.tostring("raw","RGB"), im.size, "RGB")
except ImportError:
import tempfile
tmp_fp, tmp_path = tempfile.mkstemp()
os.write(tmp_fp,result)
os.close(tmp_fp)
self.image = pygame.image.load(tmp_path).convert()
os.unlink(tmp_path)
self.image = pygame.transform.scale(self.image, (self.width,self.height))
self.rect = self.image.get_rect()
self.finished = True
louie.send('MediaRenderer.Cover.finished', None, None)
class TrackView(object):
def __init__(self, client, id):
def __init__(self, client, id, title, cover, width, height):
print "TrackView init", client, id
self.client = client
self.id = id
self.title = title
d = self.client.content_directory.browse(id, browse_flag='BrowseDirectChildren',
backward_compatibility=False)
d.addCallback( self.process_album_browse, client)
self.image = pygame.Surface((width,height))
self.image.fill((0, 0, 0)) # black
self.rect = self.image.get_rect()
self.image.blit(cover.image,(100,70))
def process_album_browse( self, results, client):
for k,v in results.iteritems():
......@@ -46,55 +93,32 @@ class TrackView(object):
artist = values.get('artist', 'unknown')
cover = values.get('album_art_uri', None)
print "track", id, title, artist, cover
louie.send('MediaRenderer.TrackView.ready', None, self)
class Album(object):
width = 100
height = 100
def __init__(self, client, id, title, artist, cover):
def __init__(self, client, id, title, artist, cover_uri):
self.id = id
self.client = client
self.title = title
self.artist = artist
self.cover = cover
self.cover = Cover(cover_uri)
self.image = pygame.Surface((self.width,self.height))
self.image.fill((0, 0, 0)) # black
self.rect = self.image.get_rect()
self.get_cover()
self.finished = False
self.touched = 0
print "album created", id, title, artist, cover
def get_cover(self):
def got_error(f):
self.finished = True
louie.send('MediaRenderer.Album.cover', None, None)
d = client.getPage(self.cover)
d.addCallback(self.got_cover)
d.addErrback(got_error)
def got_cover(self, result):
try:
import Image
import StringIO
im = Image.open(StringIO.StringIO(result))
self.image = pygame.image.frombuffer( im.tostring("raw","RGB"), im.size, "RGB")
except ImportError:
import tempfile
tmp_fp, tmp_path = tempfile.mkstemp()
os.write(tmp_fp,result)
os.close(tmp_fp)
self.image = pygame.image.load(tmp_path).convert()
os.unlink(tmp_path)
print "album created", id, title, artist, cover_uri
louie.connect(self.ready,'MediaRenderer.Cover.finished',louie.Any)
self.image = pygame.transform.scale(self.image, (self.width,self.height))
self.rect = self.image.get_rect()
def ready(self, result):
self.finished = True
self.image = pygame.transform.scale(self.cover.image, (self.width,self.height))
self.rect = self.image.get_rect()
louie.send('MediaRenderer.Album.cover', None, None)
print "cover stored"
class Audio(object):
......@@ -109,6 +133,8 @@ class Audio(object):
self.content = []
self.view = 0 # 0 = albums
# 1 = track list
self.track_view = None
self.toggle_to = None
buttons = (('save',(44,50),None,None),
('backward',(31,140),self.proceed_to_previous_song,None),
......@@ -120,7 +146,8 @@ class Audio(object):
louie.connect(self.media_server_found, 'Coherence.UPnP.ControlPoint.MediaServer.detected', louie.Any)
louie.connect(self.media_server_removed, 'Coherence.UPnP.ControlPoint.MediaServer.removed', louie.Any)
louie.connect(self.ready,'MediaRenderer.Album.cover',louie.Any)
louie.connect(self.album_view_ready,'MediaRenderer.Album.cover',louie.Any)
louie.connect(self.track_view_ready,'MediaRenderer.TrackView.ready',louie.Any)
def check(self, button, pos):
if self.view == 0:
......@@ -131,7 +158,8 @@ class Audio(object):
if album.touched > 0 and t - album.touched < 0.5:
print "double click"
album.touched = 0
TrackView(album.client,album.id)
TrackView(album.client,album.id,album.title,album.cover,
self.screen.get_width(),self.screen.get_height())
else:
album.touched = time.time()
......@@ -141,25 +169,52 @@ class Audio(object):
def clear_screen(self):
self.screen.fill((0,0,0))
def ready(self,r):
def track_view_ready(self,track_view):
self.track_view = track_view
self.draw_track_view()
def draw_track_view(self):
#self.clear_screen()
self.screen.blit( self.track_view.image, (0,0))
self.view = 1
self.toggle_to = 0
louie.send('MediaRenderer.Screen.redraw', None, self.screen)
pygame.display.set_caption('Coherence MediaRenderer - %s' % self.track_view.title)
def album_view_ready(self,r):
for album in self.content[:18]:
if album.finished == False:
return
self.draw_screen()
self.draw_album_view()
def draw_screen(self):
def draw_album_view(self):
self.clear_screen()
column = 0
row = 0
for album in self.content[:18]:
album.rect[0] = self.album_x_offset + (column * album.rect[2])
album.rect[1] = self.album_y_offset + (row * album.rect[3])
self.screen.blit(album.image,album.rect)
column += 1
if column == 6:
row += 1
column = 0
self.view = 0
if self.track_view is not None:
self.toggle_to = 1
louie.send('MediaRenderer.Screen.redraw', None, self.screen)
pygame.display.set_caption('Coherence MediaRenderer - Albums')
def draw_screen(self):
print "audio draw_screen", self.track_view, self.toggle_to
if(self.track_view is not None and
self.toggle_to is not None):
self.view = self.toggle_to
if self.view == 0:
self.draw_album_view()
else:
self.draw_track_view()
def media_server_found(self, client, usn):
print "audio - media_server_found", client.device.get_friendly_name()
......@@ -180,8 +235,6 @@ class Audio(object):
self.local_store = None
self.right_menu.set_button_action('save',None)
if self.client.has_key(usn) == True:
if self.display_loop.running:
self.display_loop.stop()
del self.client[usn]
self.content = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment