Commit 52a4ad17 authored by Frank Scholz's avatar Frank Scholz
Browse files

added left and right menu-panels based on icons from the...

added left and right menu-panels based on icons from the [http://tango.freedesktop.org/Tango Desktop Project] and wired some first functions
parent 99670eb4
data/pause.png

909 Bytes

......@@ -33,7 +33,7 @@ class MainBackground(object):
def __init__(self, screen, screenrect):
bgimagelocation='data/bg.png'
bgimagelocation=os.path.join('data','bg.png')
if os.path.exists(bgimagelocation):
self.image = pygame.image.load(bgimagelocation).convert()
self.image.set_colorkey((255,0,0), pygame.RLEACCEL)
......@@ -56,6 +56,79 @@ class MainBackground(object):
def clear_part(self, rect):
self.screen.blit(self.background, rect)
class Menu(object):
def __init__(self, location, buttons, screen, background):
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
if location == 'right':
self.offset = 720
self.rect[0] = self.offset
self.screen = screen
self.background = background
self.visible = False
self.buttons = []
for args in buttons:
button = Button(self,*args)
self.buttons.append(button)
self.image.blit(button.image,button.rect)
def show(self):
if self.visible == False:
self.visible = True
self.screen.blit(self.image,self.rect)
pygame.display.update(self.rect)
def hide(self):
if self.visible == True:
self.visible = False
self.background.clear_part(self.rect)
pygame.display.update(self.rect)
def check(self, button, pos):
if self.visible == False:
return None
for b in self.buttons:
if b.rect.collidepoint(pos[0]-self.rect[0],pos[1]):
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.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]))
class Button(object):
def __init__(self, menu, imagefile, position, action,alt_imagefile):
self.menu = menu
self.image = pygame.image.load(os.path.join('data',imagefile)).convert()
self.image.set_colorkey((0,0,0), pygame.RLEACCEL)
self.rect = self.image.get_rect()
self.rect[0] = position[0]
self.rect[1] = position[1]
self.action = action
if alt_imagefile is not None:
self.alt_image = pygame.image.load(os.path.join('data',alt_imagefile)).convert()
self.alt_image.set_colorkey((0,0,0), pygame.RLEACCEL)
self.toggle=self.alt_image
def call(self):
if self.action is not None:
self.action()
if hasattr(self,'toggle'):
self.menu.toggle(self.toggle, self.rect)
if self.toggle == self.image:
self.toggle = self.alt_image
else:
self.toggle = self.image
class MediaRenderer(object):
......@@ -74,6 +147,18 @@ class MediaRenderer(object):
self.mainbg = MainBackground(self.screen, SCREENRECT)
self.mainbg.clear_screen()
buttons = (('return.png',(2,50),None,None),
('server-scan.png',(16,216),None,None),
('exit.png',(0,380),self.quit,None))
self.left_menu = Menu('left', buttons,
self.screen, self.mainbg)
buttons = (('save.png',(30,50),None,None),
('backward.png',(16,140),self.proceed_to_previous_image,None),
('pause.png',(16,216),self.pause,'play.png'),
('forward.png',(16,300),self.proceed_to_next_image,None),
('trash.png',(30,380),None,None))
self.right_menu = Menu('right', buttons, self.screen, self.mainbg)
config = {}
config['logmode'] = 'info'
......@@ -90,10 +175,19 @@ class MediaRenderer(object):
self.images = []
self.container_watch = []
self.image_index = 0
self.image_index = -1
self.displaying = None
self.current_image = None
self.client = {}
def quit(self):
reactor.stop()
def pause(self):
if self.display_loop.running:
self.display_loop.stop()
elif len(self.images):
self.display_loop.start(20, now=True)
def toggle_fullscreen(self):
if self.fullscreen == 1:
......@@ -101,19 +195,32 @@ class MediaRenderer(object):
else:
self.fullscreen = 1
self.screen = pygame.display.set_mode(SCREENRECT.size, self.fullscreen, self.bestdepth)
self.mainbg.clear_screen()
self.mainbg.clear_part()
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.flip()
pygame.display.update(self.displaying)
def proceed_to_next_image(self):
if len(self.images)>0:
try:
self.image_index += 1
image_url, image_title = self.images[self.image_index]
except IndexError:
self.image_index = 0
image_url, image_title = self.images[self.image_index]
self.image_index += 1
d = client.getPage(image_url)
d.addCallback(self.got_image, image_title)
d.addErrback(self.got_error, image_url)
def proceed_to_previous_image(self):
if len(self.images)>0:
try:
self.image_index -= 1
image_url, image_title = self.images[self.image_index]
except IndexError:
self.image_index = len(self.images)-1
image_url, image_title = self.images[self.image_index]
d = client.getPage(image_url)
d.addCallback(self.got_image, image_title)
d.addErrback(self.got_error, image_url)
......@@ -134,8 +241,6 @@ class MediaRenderer(object):
size = self.current_image.get_size()
os.unlink(tmp_path)
if self.displaying is not None:
self.mainbg.clear_part(self.displaying)
transform = None
if size[0] > self.screen.get_width():
new_width = self.screen.get_width()
......@@ -154,9 +259,12 @@ class MediaRenderer(object):
transform =(new_width,new_height)
if transform is not None:
self.current_image = pygame.transform.scale(self.current_image, transform)
if self.displaying is not None:
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.flip()
pygame.display.update(self.displaying)
pygame.display.set_caption('Coherence MediaRenderer - %s' % title)
def got_error(self, failure, url):
......@@ -233,13 +341,28 @@ class MediaRenderer(object):
for event in pygame.event.get():
#print event
if (event.type == KEYDOWN and event.key == K_F6):
if(event.type == KEYDOWN and event.key == K_F6):
"""switch between fullscreen and app mode """
self.toggle_fullscreen()
if event.type == MOUSEMOTION:
if event.pos[0] <= 70:
"""left hotspot """
self.left_menu.show()
elif event.pos[0] > 730:
"""right hotspot """
self.right_menu.show()
else:
self.right_menu.hide()
self.left_menu.hide()
if event.type == MOUSEBUTTONUP:
self.left_menu.check(event.button, event.pos)
self.right_menu.check(event.button, event.pos)
if((event.type == KEYDOWN and event.key == K_ESCAPE) or
event.type == QUIT):
reactor.stop()
self.quit()
def main():
......
from setuptools import setup, find_packages
__version__ = '0.0.1'
__version__ = '0.0.2'
setup(
name="MediaRenderer",
......
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