Commit 7f3a8c75 authored by Frank Scholz's avatar Frank Scholz
Browse files

source tree reorganisation

parent c9f2fbf6
......@@ -27,10 +27,7 @@ import louie
SCREENRECT = Rect(0, 0, 800, 480)
SCREENDEPTH = 32
class MainBackground(object):
topx = 10
topy = 7
rect = Rect(10, 7 , 750, 450)
class Background(object):
def __init__(self, screen, screenrect):
......@@ -43,7 +40,7 @@ class MainBackground(object):
self.screen = screen
self.background = pygame.Surface(screenrect.size).convert()
self.background = screen.subsurface(screenrect).convert()
self.makebg()
def makebg(self):
......@@ -56,19 +53,23 @@ class MainBackground(object):
self.screen.blit(self.background, (0, 0))
def clear_part(self, rect):
#print "background clear part", rect
print "background clear part", rect
self.screen.blit(self.background, rect, rect)
class Menu(object):
def __init__(self, location, buttons, screen, background):
def __init__(self, controller, location, buttons):
self.image = pygame.image.load(os.path.join('data','menu-frame-%s.png' % location)).convert()
self.image.set_colorkey((0,0,0), pygame.RLEACCEL)
self.rect = self.image.get_rect()
self.offset = 0
self.x_offset = 0
if location == 'right':
self.offset = 705
self.rect[0] = self.offset
self.x_offset = 705
self.rect[0] = self.x_offset
self.y_offset = 0
if location == 'bottom':
self.y_offset = 410
self.rect[1] = self.y_offset
self.select_frame = pygame.image.load(os.path.join('data','button-selected.png')).convert()
self.select_frame.set_colorkey((255,255,255), pygame.RLEACCEL)
......@@ -79,8 +80,7 @@ class Menu(object):
self.pressed_frame = pygame.image.load(os.path.join('data','button-pressed.png')).convert()
self.pressed_frame.set_colorkey((255,255,255), pygame.RLEACCEL)
self.screen = screen
self.background = background
self.controller = controller
self.visible = False
self.buttons = []
......@@ -89,49 +89,62 @@ class Menu(object):
self.buttons.append(button)
self.image.blit(button.image,button.rect)
def show(self, pos):
if self.visible == False:
self.visible = True
self.screen.blit(self.image,self.rect)
pygame.display.update(self.rect)
def redraw(self,pos=None):
#print "menu redraw", pos
if self.visible == True:
self.controller.display_redraw_part(self.image,self.rect)
selected = None
for b in self.buttons:
if b.selected == True:
selected = b
#print "selected", selected.rect
for b in self.buttons:
if b.rect.collidepoint(pos[0]-self.rect[0],pos[1]):
if b.action == None:
if pos is not None:
for b in self.buttons:
if b.rect.collidepoint(pos[0]-self.rect[0],pos[1]):
if b.action == None:
return
#print "we have a touchdown"
if selected is not b:
#print "selected is not b"
if selected is not None:
#print "remove old select frame"
selected.selected = False
selected.transit = False
self.controller.display_redraw_part(self.unselect_frame,(selected.rect[0]+self.x_offset-3,selected.rect[1]+self.y_offset-3,54,54))
#print "draw new selected frame"
self.controller.display_redraw_part(self.select_frame,(b.rect[0]+self.x_offset-3,b.rect[1]+self.y_offset-3,54,54))
b.selected = True
return
#print "we have a touchdown"
if selected is not b:
#print "selected is not b"
if selected is not None:
#print "remove old select frame"
self.image.blit(self.unselect_frame,(selected.rect[0]-3,selected.rect[1]-3,54,54))
self.screen.blit(self.unselect_frame,(selected.rect[0]+self.offset-3,selected.rect[1]-3,54,54))
pygame.display.update((selected.rect[0]+self.offset-3,selected.rect[1]-3,54,54))
#print "draw new select frame"
self.image.blit(self.select_frame,(b.rect[0]-3,b.rect[1]-3,54,54))
self.screen.blit(self.select_frame,(b.rect[0]+self.offset-3,b.rect[1]-3,54,54))
pygame.display.update((b.rect[0]+self.offset-3,b.rect[1]-3,54,54))
b.selected = True
return
if selected is not None:
#print "clear old select frame"
self.image.blit(self.unselect_frame,(selected.rect[0]-3,selected.rect[1]-3,54,54))
self.screen.blit(self.unselect_frame,(selected.rect[0]+self.offset-3,selected.rect[1]-3,54,54))
pygame.display.update((selected.rect[0]+self.offset-3,selected.rect[1]-3,54,54))
selected.selected = False
if selected is not None:
#print "clear old select frame"
self.controller.display_redraw_part(self.unselect_frame,(selected.rect[0]+self.x_offset-3,selected.rect[1]+self.y_offset-3,54,54))
selected.selected = False
selected.transit = False
else:
#print "redraw selected frame"
if selected.transit == True:
frame = self.pressed_frame
else:
frame = self.selected_frame
self.controller.display_redraw_part(frame,(selected.rect[0]+self.x_offset-3,selected.rect[1]+self.y_offset-3,54,54))
def show(self, pos):
if self.visible == False:
self.visible = True
self.redraw(pos)
def hide(self):
if self.visible == True:
self.visible = False
self.background.clear_part(self.rect)
pygame.display.update(self.rect)
#self.controller.background.clear_part(self.rect)
#if self.controller.current_image is not None:
# self.controller.screen.blit(self.controller.current_image,self.controller.displaying,self.rect)
#pygame.display.update(self.rect)
self.controller.display_clear_part(self.rect)
for b in self.buttons:
if b.selected == True:
b.selected = False
b.transit = False
self.image.blit(self.unselect_frame,(b.rect[0]-3,b.rect[1]-3,54,54))
......@@ -141,25 +154,29 @@ class Menu(object):
def clear_pressed(pressed):
if pressed.selected == True:
self.image.blit(self.select_frame,(pressed.rect[0]-3,pressed.rect[1]-3,54,54))
self.screen.blit(self.select_frame,(pressed.rect[0]+self.offset-3,pressed.rect[1]-3,54,54))
pygame.display.update((pressed.rect[0]+self.offset-3,pressed.rect[1]-3,54,54))
#print "clear_pressed"
pressed.transit = False
if self.visible == True:
self.controller.display_redraw_part(self.select_frame,
(pressed.rect[0]+self.x_offset-3,pressed.rect[1]+self.y_offset-3,54,54))
for b in self.buttons:
if( b.rect.collidepoint(pos[0]-self.rect[0],pos[1]) and
b.action is not None):
self.image.blit(self.pressed_frame,(b.rect[0]-3,b.rect[1]-3,54,54))
self.screen.blit(self.pressed_frame,(b.rect[0]+self.offset-3,b.rect[1]-3,54,54))
pygame.display.update((b.rect[0]+self.offset-3,b.rect[1]-3,54,54))
if b.transit == True:
return
self.controller.display_redraw_part(self.pressed_frame,(b.rect[0]+self.x_offset-3,b.rect[1]+self.y_offset-3,54,54))
b.transit = True
reactor.callLater(2,clear_pressed, b)
b.call()
def toggle(self, image, rect):
self.background.clear_part((rect[0]+self.offset,rect[1],rect[2],rect[3]))
self.image.blit(self.background.background,rect,(rect[0]+self.offset,rect[1],rect[2],rect[3]))
#self.controller.background.clear_part((rect[0]+self.x_offset,rect[1]+self.y_offset,rect[2],rect[3]))
self.controller.clear_part((rect[0]+self.x_offset,rect[1]+self.y_offset,rect[2],rect[3]))
self.image.blit(self.controller.background.background,rect,(rect[0]+self.x_offset,rect[1]+self.y_offset,rect[2],rect[3]))
self.image.blit(image,rect)
self.screen.blit(self.image,(rect[0]+self.offset,rect[1],rect[2],rect[3]), rect)
pygame.display.update((rect[0]+self.offset,rect[1],rect[2],rect[3]))
self.controller.display_redraw_part(self.image,(rect[0]+self.x_offset,rect[1]+self.y_offset,rect[2],rect[3]), rect)
#pygame.display.update((rect[0]+self.x_offset,rect[1]+self.y_offset,rect[2],rect[3]))
def set_button_action(self, name, action):
for b in self.buttons:
......@@ -178,6 +195,7 @@ class Button(object):
self.rect[1] = position[1]
self.action = action
self.selected = False
self.transit = False
if alt_imagefile is not None:
self.alt_image = pygame.image.load(os.path.join('data',alt_imagefile)).convert()
......@@ -202,27 +220,42 @@ class MediaRenderer(object):
self.fullscreen = fullscreen
self.bestdepth = pygame.display.mode_ok(SCREENRECT.size, fullscreen, SCREENDEPTH)
self.screen = pygame.display.set_mode(SCREENRECT.size, fullscreen, self.bestdepth)
self.display = pygame.display.set_mode(SCREENRECT.size, fullscreen, self.bestdepth)
if platform.uname()[1].startswith('Nokia'):
pygame.mouse.set_visible(False)
# decorate the game window
pygame.display.set_caption('Coherence MediaRenderer')
self.mainbg = MainBackground(self.screen, SCREENRECT)
self.mainbg.clear_screen()
self.images_screen = pygame.Surface((SCREENRECT.width,SCREENRECT.height))
self.audio_screen = pygame.Surface((SCREENRECT.width,SCREENRECT.height))
self.main_screen = pygame.Surface((SCREENRECT.width,SCREENRECT.height))
self.screen = self.images_screen
buttons = (('return',(4,50),None,None),
('server-scan',(22,216),None,None),
self.background = Background(self.screen, SCREENRECT)
self.background.clear_screen()
self.menus = []
# buttons = (('return',(4,50),None,None),
# ('server-scan',(22,216),None,None),
# ('exit',(4,380),self.quit,None))
buttons = (('audio',(16,140),self.switch_to_audio,None),
('images',(22,216),self.switch_to_images,None),
('exit',(4,380),self.quit,None))
self.left_menu = Menu('left', buttons,
self.screen, self.mainbg)
self.left_menu = Menu(self, 'left', buttons)
self.menus.append(self.left_menu)
buttons = (('save',(44,50),None,None),
('backward',(31,140),self.proceed_to_previous_image,None),
('pause',(31,216),self.pause,'play.png'),
('forward',(31,300),self.proceed_to_next_image,None),
('mark-junk',(44,380),self.mark_junk,None))
self.right_menu = Menu('right', buttons, self.screen, self.mainbg)
self.right_menu = Menu(self, 'right', buttons)
self.menus.append(self.right_menu)
self.top_menu = Menu(self, 'top', ())
self.menus.append(self.top_menu)
config = {}
config['logmode'] = 'info'
......@@ -238,6 +271,7 @@ class MediaRenderer(object):
self.display_loop = task.LoopingCall(self.proceed_to_next_image,skip_junk=True)
self.images = []
self.albums = {}
self.container_watch = []
self.image_index = -1
self.displaying = None
......@@ -245,10 +279,68 @@ class MediaRenderer(object):
self.client = {}
self.local_store = None
self.mode = 1 # 0 = audio
# 1 = images
def quit(self):
reactor.stop()
def loop_start(self, x, now=False):
def display_redraw_part(self, part, rect, from_rect=None):
if from_rect == None:
from_rect = part.get_rect()
#print "display redraw_part", rect, from_rect
self.display.blit(part, rect, from_rect)
pygame.display.update(rect)
def display_clear_part(self,rect):
#print "display clear_part", rect
self.display.blit(self.screen, rect, rect)
pygame.display.update(rect)
def redraw_part(self, part, rect, from_rect=None, screen=None):
#print "screen redraw_part part", rect, from_rect
if from_rect == None:
from_rect = part.get_rect()
if screen == None:
screen = self.screen
#print "screen redraw_part part", rect, from_rect
self.screen.blit(part,rect,from_rect)
self.display_redraw_part(screen, rect, rect)
def redraw(self):
#print "screen redraw"
self.display.blit(self.screen, (0,0))
for m in self.menus:
m.redraw()
pygame.display.update(self.screen.get_rect())
def clear_part(self,rect):
self.screen.blit(self.background.background, rect, rect)
self.display.blit(self.screen,rect,rect)
pygame.display.update(rect)
def clear(self):
self.background.clear_screen()
pygame.display.update(self.screen.get_rect())
def switch_to_images(self):
if self.mode == 1:
return
self.mode = 1
self.screen = self.images_screen
self.redraw()
self.loop_start()
def switch_to_audio(self):
if self.mode == 0:
return
if self.mode == 1:
self.loop_stop()
self.mode = 0
self.screen = self.audio_screen
self.redraw()
def loop_start(self, x=None, now=False):
if len(self.images) and not self.display_loop.running:
self.display_loop.start(20, now)
......@@ -301,10 +393,10 @@ class MediaRenderer(object):
else:
self.fullscreen = 1
self.screen = pygame.display.set_mode(SCREENRECT.size, self.fullscreen, self.bestdepth)
self.mainbg.clear_screen()
self.background.clear_screen()
pygame.display.update(self.displaying)
self.displaying = self.current_image.get_rect(center=((self.screen.get_width()/2)-1,(self.screen.get_height()/2)-1))
self.screen.blit(self.current_image,self.displaying)
self.screen.blit(self.current_image,self.displaying, (0,0,self.displaying.width,self.displayin.height))
pygame.display.update(self.displaying)
def proceed_to_next_image(self, skip_junk=False):
......@@ -395,11 +487,9 @@ class MediaRenderer(object):
self.current_image = pygame.transform.scale(self.current_image, transform)
if self.displaying is not None:
#print "clear old image", self.displaying
self.mainbg.clear_part(self.displaying)
pygame.display.update(self.displaying)
self.displaying = self.current_image.get_rect(center=((self.screen.get_width()/2)-1,(self.screen.get_height()/2)-1))
self.screen.blit(self.current_image,self.displaying)
pygame.display.update(self.displaying)
self.clear_part(self.displaying)
self.displaying = self.current_image.get_rect(center=((self.screen.get_width()/2),(self.screen.get_height()/2)))
self.redraw_part(self.current_image,self.displaying, screen=self.images_screen)
pygame.display.set_caption('Coherence MediaRenderer - %s' % title)
def process_media_server_browse( self, results, usn):
......@@ -439,8 +529,28 @@ class MediaRenderer(object):
if(values['upnp_class'].startswith('object.container') and
values['title'] == 'images'):
print "found object id", values['id'], "as storage point"
self.right_menu.set_button_action('save',self.store_locally)
if hasattr(self,'right_menu'):
self.right_menu.set_button_action('save',self.store_locally)
self.local_store = (self.local_store,values['id'])
if(values['upnp_class'].startswith('object.container') and
values['title'] == 'audio'):
print "found object id", values['id'], "as audio container"
d = self.client[usn].content_directory.browse(id, browse_flag='BrowseDirectChildren',
backward_compatibility=False)
d.addCallback( self.process_audio_server_browse, usn)
def process_audio_server_browse( self, results, usn):
for k,v in results.iteritems():
#print k, v
if k == 'items':
for id, values in v.iteritems():
print values
if values['upnp_class'].startswith('object.container'):
id = values['id']
title = values.get('title', 'untitled')
cover = values.get('album_art_uri', None)
self.albums['id'] = {'id': id, 'title': title, 'cover':cover}
print "album found", id, title, cover
def media_server_found(self, client, usn):
print "media_server_found", client.device.get_friendly_name()
......@@ -498,6 +608,11 @@ class MediaRenderer(object):
backward_compatibility=False)
d.addCallback( self.process_media_server_browse, usn)
def hide_menus(self,keep=None):
for m in self.menus:
if m != keep:
m.hide()
def pygame_loop(self):
for event in pygame.event.get():
#print event
......@@ -509,23 +624,27 @@ class MediaRenderer(object):
if event.type == MOUSEMOTION:
if event.pos[0] <= 70:
"""left hotspot """
self.hide_menus(self.left_menu)
self.left_menu.show(event.pos)
elif event.pos[0] > 730:
"""right hotspot """
self.hide_menus(self.right_menu)
self.right_menu.show(event.pos)
elif event.pos[1] <= 70:
"""top hotspot """
self.hide_menus(self.top_menu)
self.top_menu.show(event.pos)
else:
self.right_menu.hide()
self.left_menu.hide()
self.hide_menus()
if event.type == ACTIVEEVENT:
if event.state == 1 and event.gain == 0:
""" focus lost """
self.right_menu.hide()
self.left_menu.hide()
self.hide_menus()
if event.type == MOUSEBUTTONUP:
self.left_menu.check(event.button, event.pos)
self.right_menu.check(event.button, event.pos)
for m in self.menus:
m.check(event.button,event.pos)
if((event.type == KEYDOWN and event.key == K_ESCAPE) or
event.type == QUIT):
......
from setuptools import setup, find_packages
__version__ = '0.0.3'
from mediarenderer import version
setup(
name="MediaRenderer",
......@@ -12,7 +12,7 @@ setup(
author_email='coherence@beebits.net',
license = "MIT",
packages = find_packages(),
scripts = ['mediarenderer'],
scripts = ['bin/mediarenderer'],
url = "http://coherence.beebits.net",
download_url = 'https://coherence.beebits.net/download/MediaRenderer-%s.tar.gz' % __version__,
keywords=['UPnP', 'DLNA', 'multimedia', 'gstreamer'],
......
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