Author: duncan
Date: Tue Jan 30 20:22:46 2007
New Revision: 9109

Added:
   branches/rel-1/freevo/src/plugins/screensaver/
   branches/rel-1/freevo/src/plugins/screensaver/__init__.py   (contents, props 
changed)
   branches/rel-1/freevo/src/plugins/screensaver/balls.py   (contents, props 
changed)
   branches/rel-1/freevo/src/plugins/screensaver/bouncing_freevo.py   
(contents, props changed)
Modified:
   branches/rel-1/freevo/ChangeLog
   branches/rel-1/freevo/Docs/CREDITS

Log:
[ 1647485 ] Python based Screensaver
Plugin from Adam Charrett added


Modified: branches/rel-1/freevo/ChangeLog
==============================================================================
--- branches/rel-1/freevo/ChangeLog     (original)
+++ branches/rel-1/freevo/ChangeLog     Tue Jan 30 20:22:46 2007
@@ -31,6 +31,7 @@
  * New Music Player Daemon (mpd) plug-in (F#1623023)
  * New record server commerical detection and removal (F#1633567)
  * New RSS server, for getting podcasts, etc. (F#1580407)
+ * New screensaver plug-in (F#1647485)
  * New Shuttle VFD plug-in (F#1619761)
  * New support for anamorphic skins (F#1625752)
  * New XM online plugin (F#1580412)
@@ -64,6 +65,7 @@
  * Fixed auto shutdown not calling the mount command (B#1632754)
  * Fixed manual record when month is December (B#1621615)
  * Fixed shopping cart for items with two or more subitems (B#1620425)
+ * Fixed shopping cart for when copying directories (B#1645468)
  * Fixed video thumbnails not being shown with subitems (B#1620452)
  * Fixed video thumbnails not being shown for playlists (B#1623905)
  * Fixed webserver 'genre' module generated html (B#1622456)

Modified: branches/rel-1/freevo/Docs/CREDITS
==============================================================================
--- branches/rel-1/freevo/Docs/CREDITS  (original)
+++ branches/rel-1/freevo/Docs/CREDITS  Tue Jan 30 20:22:46 2007
@@ -62,6 +62,7 @@
 
 Adam Charrett <[EMAIL PROTECTED]>
 o Buttonbar plug-in
+o Screensaver plug-in
 
 Andrew Flegg <[EMAIL PROTECTED]>
 o Skin additions, anamorphic and past

Added: branches/rel-1/freevo/src/plugins/screensaver/__init__.py
==============================================================================
--- (empty file)
+++ branches/rel-1/freevo/src/plugins/screensaver/__init__.py   Tue Jan 30 
20:22:46 2007
@@ -0,0 +1,208 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------
+# screensaver/__init__.py - the Freevo Screensaver
+# -----------------------------------------------------------------------
+# $Id$
+#
+# Notes:
+#
+# Todo:
+#
+#
+# -----------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002 Krister Lagerstrom, et al.
+# Please see the file freevo/Docs/CREDITS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# ----------------------------------------------------------------------- */
+
+
+import time
+import os
+import random 
+import thread
+import traceback
+import pygame
+
+import config
+import plugin
+import rc
+
+from event import Event
+import osd
+import skin
+
+# Set to 1 for debug output
+DEBUG = config.DEBUG
+
+osd = osd.get_singleton()
+skin = skin.get_singleton()
+
+class PluginInterface(plugin.DaemonPlugin):
+    """
+    """
+    def __init__(self):
+        plugin.DaemonPlugin.__init__(self)
+        self.event_listener = True
+        self.poll_menu_only = True
+        
+        self.last_event = time.time()
+        self.screensaver_showing = False
+        self.menuw = None
+        self.start_delay = config.SCREENSAVER_DELAY
+        self.cycle_time = config.SCREENSAVER_CYCLE_TIME
+        self.plugins = None   
+        _debug_('Screensaver install (delay = %d)' % self.start_delay)
+
+
+    def config(self):
+        return [ ('SCREENSAVER_DELAY', 300, '# of seconds to wait to start 
saver.'),
+                  ('SCREENSAVER_CYCLE_TIME', 60, '# of seconds to run a 
screensaver before starting another saver.')
+                ]
+
+    def eventhandler(self, event = None, menuw=None, arg=None):
+        """
+        eventhandler to handle the events. Always return False since we
+        are just a listener and really can't send back True.
+        """
+        _debug_("Saver saw %s" % event.name)
+        if menuw:
+            self.menuw = menuw
+
+        if event.name == 'SCREENSAVER_START':
+            if not self.screensaver_showing:
+                self.start_saver()
+            return True
+
+        if event.name == 'SCREENSAVER_STOP' and self.screensaver_showing :
+            self.stop_saver()
+            return True
+
+        # gotta ignore these or video screensavers shutoff before they begin
+        if event.name == 'VIDEO_START' or event.name == 'PLAY_START' or 
event.name == 'VIDEO_END' or event.name == 'PLAY_END':
+            return False
+
+        if not event.name == 'IDENTIFY_MEDIA':
+            self.last_event = time.time()
+            
+        if self.screensaver_showing :
+            self.stop_saver()
+            return True
+
+        return False
+
+    def poll(self):
+        #_debug_("Saver got polled %f" % time.time())
+        time_diff = time.time() - self.last_event
+        if not self.screensaver_showing and  time_diff > self.start_delay :
+            rc.post_event(Event("SCREENSAVER_START"))
+
+    def start_saver (self):
+        _debug_("start screensaver")
+        self.screensaver_showing = True
+        if self.plugins is None:
+            self.plugins = plugin.get('screensaver')
+            print 'Plugins =', self.plugins
+        skin.clear()
+        # Start Screensaver thread
+        self.stop_screensaver = False
+        thread.start_new_thread(self.__run__,())
+
+    def stop_saver (self):
+        _debug_("stop screensaver")
+        self.stop_screensaver = True
+
+    def __run__(self):
+        _debug_('Screensaver thread started')
+        current_saver = None
+        while not self.stop_screensaver:
+            # No current screensaver so select one of the installed screensaver
+            # plugins at random
+            if current_saver is None:
+                if len(self.plugins) == 1:
+                    current_saver = self.plugins[0]
+                elif len(self.plugins) > 1:
+                    index = random.randint(0, len(self.plugins) - 1)
+                    current_saver = self.plugins[index]
+            
+            # No screensaver found just sleep for 200ms
+            if current_saver is None:
+                time.sleep(0.200)
+            else:
+                self.__run_screensaver__(current_saver)
+
+        self.screensaver_showing = False
+        skin.redraw()
+        _debug_('Screensaver thread stopped')
+        
+    def __run_screensaver__(self, screensaver):
+        _debug_('Running %s' % screensaver.plugin_name)
+        try:
+            fps = screensaver.start(osd.width, osd.height)
+            
+            max_iterations = int(self.cycle_time / (1.0 / fps))
+            iteration = 0
+            clock = pygame.time.Clock()
+            
+            while (not self.stop_screensaver) and (iteration < max_iterations):
+                # Draw the screen and update the display
+                screensaver.draw(osd.screen)
+                pygame.display.flip()
+                
+                clock.tick(fps)
+                iteration += 1
+                
+            screensaver.stop()
+        except:
+            print 'Screensaver %s crashed!' % screensaver.plugin_name
+            traceback.print_exc()
+            # Remove the broken screensaver so we don't try to run it again
+            self.plugins.remove(screensaver)
+            
+        osd.clearscreen(osd.COL_BLACK)
+        pygame.display.flip()
+            
+
+
+class ScreenSaverPlugin(plugin.Plugin):
+    def __init__(self):
+        plugin.Plugin.__init__(self)
+        self._type = 'screensaver'
+
+
+    def start(self, width, height):
+        """
+        Initialise the screensaver before each run.
+        Returns the number of frames per second the saver
+        wants to run at.
+        """
+        return 25
+
+    
+    def stop(self):
+        """
+        Deinitialise the screensaver after each run.
+        """
+        pass
+
+    
+    def draw(self, surface):
+        """
+        Draw a frame onto the supplied surface called
+        every 1/fps seconds (where fps was returned by start())
+        """
+        pass

Added: branches/rel-1/freevo/src/plugins/screensaver/balls.py
==============================================================================
--- (empty file)
+++ branches/rel-1/freevo/src/plugins/screensaver/balls.py      Tue Jan 30 
20:22:46 2007
@@ -0,0 +1,166 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------
+# screensaver/balls.py - the Freevo Screensaver
+# -----------------------------------------------------------------------
+# $Id$
+#
+# Notes:
+#
+# Todo:
+#
+#
+# -----------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002 Krister Lagerstrom, et al.
+# Please see the file freevo/Docs/CREDITS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# ----------------------------------------------------------------------- */
+
+from random import randint
+import pygame
+
+# freevo modules
+import config
+from plugins.screensaver import ScreenSaverPlugin
+
+
+class PluginInterface(ScreenSaverPlugin):
+    def __init__(self):
+        ScreenSaverPlugin.__init__(self)
+        self.plugin_name = 'screensaver.balls'
+        self.fps = config.BALLS_FPS
+    
+    def config(self):
+        return [ ('BALLS_FPS', 15, 'Frames per second'),
+                       ('BALLS_MAX_BALLS', 100, 'Maximum number of balls'),
+                       ('BALLS_MIN_BALLS', 1, 'Minimum number of balls')]
+
+
+    def start(self, width, height):
+        self.width = width
+        self.height = height
+        ballcount = randint(1, 100)
+        self.balls = []
+        
+        for i in range(0,ballcount):
+            ball = Ball()
+            
+            ball.name = "ball " + str(i)
+            ball.color = (randint(5, 255), randint(5,255), randint(5,255))
+            ball.x = randint(0, width - ball.w)
+            ball.y = randint(0, height - ball.h)
+            ball.w = ball.h = randint(20,40)
+            
+            self.balls.append(ball)
+        
+        return self.fps
+    
+    def draw(self, screen):
+        black = (0,0,0)
+        dirty = []
+        screen.lock()
+        for ball in self.balls:
+            ball.clear(screen, black)
+            dirty.append(ball.rectangle())
+            
+        for ball in self.balls:
+            ball.update(self.width, self.height, 0.9, 0.9)
+            ball.draw(screen)
+            dirty.append(ball.rectangle())
+        
+        screen.unlock()
+
+class Ball:
+    def __init__(self):
+        self.name = "ball"
+        self.x = 100.0
+        self.y = 100.0
+        self.w = 40
+        self.h = 40
+        self.color = (255,0,0)
+        
+        self.hspeed = randint(-4,4)
+        self.haccel = 0
+        
+        self.vspeed = randint(-4,4)
+        self.vaccel = 0.7
+        
+        self.stopped_count = 0
+        self.kick_threshold = 50
+    
+    def draw(self, screen):
+        pygame.draw.ellipse(screen, self.color, (int(self.x), int(self.y), 
self.w, self.h))
+        pygame.draw.ellipse(screen, (255,255,255), (int(self.x), int(self.y), 
self.w, self.h), 1)
+    
+    def clear(self, screen, color):
+        pygame.draw.ellipse(screen, color, (int(self.x), int(self.y), self.w, 
self.h))
+        pygame.draw.ellipse(screen, color, (int(self.x), int(self.y), self.w, 
self.h), 1)
+    
+    def update(self, width, height, walldeccel, floordeccel):
+        # Update ball velocity
+        self.hspeed = self.hspeed + self.haccel
+        self.vspeed = self.vspeed + self.vaccel
+        
+        # Update ball position
+        self.x = self.x + self.hspeed
+        self.y = self.y + self.vspeed
+        
+        if int(self.x + self.w) >= width:
+            self.hspeed = (self.hspeed * -1.0) * walldeccel
+            self.x = width - self.w
+            #self.w = self.w - 2
+            #self.h = self.h + 2
+            
+        elif int(self.x) <= 0:
+            self.hspeed = (self.hspeed * -1.0) * walldeccel
+            self.x = 0
+        
+        if int(self.y + self.h) >= height:
+            self.vspeed = (self.vspeed * -1.0) * floordeccel
+            self.y = height - self.h
+        elif int(self.y) <= 0:
+            self.vspeed = (self.vspeed * -1.0) * floordeccel
+            self.y = 0
+
+        # If we loose all speed kick the ball :-)
+        if ((self.hspeed < 0.35) and (self.hspeed > -0.35)) or ((self.vspeed < 
0.35) and (self.vspeed > -0.35)):
+            self.stopped_count = self.stopped_count + 1
+            
+            if self.stopped_count > self.kick_threshold:
+                kick_drop = True # randint(0,1)
+                
+                if kick_drop:
+                    if self.hspeed < 0.0:
+                        self.hspeed = - randint(5, 20)
+                    else:
+                        self.hspeed = randint(5, 20)
+    
+                    if self.vspeed < 0.0:
+                        self.vspeed = -randint(5, 20)
+                    else:
+                        self.vspeed = randint(5, 20)
+                    
+                else:
+                    self.y = randint(0, height / 2)
+                
+                # Reset stopped count
+                self.stopped_count = 0
+        else:
+            self.stopped_count = 0
+    
+    def rectangle(self):
+        return (int(self.x), int(self.y), self.w, self.h)

Added: branches/rel-1/freevo/src/plugins/screensaver/bouncing_freevo.py
==============================================================================
--- (empty file)
+++ branches/rel-1/freevo/src/plugins/screensaver/bouncing_freevo.py    Tue Jan 
30 20:22:46 2007
@@ -0,0 +1,93 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------
+# screensaver/bouncing_freevo.py - the Freevo Screensaver
+# -----------------------------------------------------------------------
+# $Id$
+#
+# Notes:
+#
+# Todo:
+#
+#
+# -----------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002 Krister Lagerstrom, et al.
+# Please see the file freevo/Docs/CREDITS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# ----------------------------------------------------------------------- */
+import os
+from random import randint
+import pygame
+
+# freevo modules
+import config
+import osd
+from plugins.screensaver import ScreenSaverPlugin
+
+osd = osd.get_singleton()
+
+class PluginInterface(ScreenSaverPlugin):
+    def __init__(self):
+        ScreenSaverPlugin.__init__(self)
+        self.plugin_name = 'screensaver.bouncing_freevo'
+        self.fps = config.BOUNCING_FREEVO_FPS
+        self.image = osd.loadbitmap(os.path.join(config.IMAGE_DIR,'logo.png'))
+        self.image_width = 200
+        self.image_height = 98
+
+    
+    def config(self):
+        return [ ('BOUNCING_FREEVO_FPS', 10, 'Frames per second')]
+
+
+    def start(self, width, height):
+        self.width = width
+        self.height = height
+        
+        self.x = randint(0, width - self.image_width)
+        self.y = randint(0, height - self.image_height)
+        self.x_speed = randint(5,10)
+        self.y_speed = randint(5,10)
+        
+        return self.fps
+
+    
+    def draw(self, screen):
+        black = (0,0,0)
+        dirty = []
+        # Clear the old image
+        screen.fill(black, (self.x,self.y, self.image_width, 
self.image_height))
+
+        # Move the image
+        self.x += self.x_speed
+        if self.x < 0:
+            self.x = 0
+            self.x_speed *= -1
+        if (self.x + self.image_width) > self.width:
+            self.x = self.width - self.image_width
+            self.x_speed *= -1
+
+        self.y += self.y_speed
+        if self.y < 0:
+            self.y = 0
+            self.y_speed *= -1
+
+        if (self.y + self.image_height) > self.height:
+            self.y = self.height - self.image_height
+            self.y_speed *= -1
+        
+        screen.blit(self.image, (self.x, self.y))

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to