Update of /cvsroot/freevo/freevo/src/image
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13402

Modified Files:
        __init__.py imageitem.py viewer.py 
Added Files:
        interface.py 
Log Message:
last cleanups for the image module in Freevo

--- NEW FILE: interface.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# interface.py - interface between mediamenu and image
# -----------------------------------------------------------------------
# $Id: interface.py,v 1.5 2004/09/13 18:00:50 dischi Exp $
#
# This file defines the PluginInterface for the image module
# of Freevo. It is loaded by __init__.py and will activate the
# mediamenu for images.
#
# Notes:
# Todo:
#
# -----------------------------------------------------------------------
# $Log: interface.py,v $
# Revision 1.5  2004/09/13 18:00:50  dischi
# last cleanups for the image module in Freevo
#
#
# -----------------------------------------------------------------------
# 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
#
# ----------------------------------------------------------------------- */

# only export 'PluginInterface' to the outside. This will be used
# with plugin.activate('image') and everything else should be handled
# by using plugin.mimetype()
__all__ = [ 'PluginInterface' ]

# Python imports
import os

# Add support for bins album files
from mmpython.image import bins

# Freevo imports
import config
import util
import plugin

from imageitem import ImageItem
from playlist import Playlist

class PluginInterface(plugin.MimetypePlugin):
    """
    Plugin to handle all kinds of image items
    """
    def __init__(self):
        plugin.MimetypePlugin.__init__(self)
        self.display_type = [ 'image' ]

        # register the callbacks
        plugin.register_callback('fxditem', ['image'], 'slideshow',
                                 self.fxdhandler)

        # activate the mediamenu for image
        level = plugin.is_active('image')[2]
        plugin.activate('mediamenu', level=level, args='image')


    def suffix(self):
        """
        return the list of suffixes this class handles
        """
        return config.IMAGE_SUFFIX


    def get(self, parent, files):
        """
        return a list of items based on the files
        """
        items = []
        for file in util.find_matches(files, config.IMAGE_SUFFIX):
            items.append(ImageItem(file, parent))
            files.remove(file)
        return items


    def dirinfo(self, diritem):
        """
        set informations for a diritem based on album.xml
        """
        if vfs.isfile(diritem.dir + '/album.xml'):
            # Add album.xml information from bins to the
            # directory informations
            info  = bins.get_bins_desc(diritem.dir)
            if not info.has_key('desc'):
                return

            info = info['desc']
            if info.has_key('sampleimage') and info['sampleimage']:
                # Check if the album.xml defines a sampleimage.
                # If so, use it as image for the directory
                image = vfs.join(diritem.dir, info['sampleimage'])
                if vfs.isfile(image):
                    diritem.image = image

            # set the title from album.xml
            if info.has_key('title') and info['title']:
                diritem.name = info['title']


    def fxdhandler(self, fxd, node):
        """
        parse image specific stuff from fxd files

        <?xml version="1.0" ?>
        <freevo>
          <slideshow title="foo" random="1|0" repeat="1|0">
            <cover-img>foo.jpg</cover-img>
            <background-music random="1|0">
              <directory recursive="1|0">path</directory>
              <file>filename</file>
            </background-music>
            <files>
              <directory recursive="1|0" duration="10">path</directory>
              <file duration="0">filename</file>
            </files>
            <info>
              <description>A nice description</description>
            </info>
          </slideshow>
        </freevo>
        """
        items = []
        dirname = os.path.dirname(fxd.getattr(None, 'filename', ''))
        children = fxd.get_children(node, 'files')
        if children:
            children = children[0].children

        # Create a list of all images for the slideshow
        for child in children:
            try:
                citems = []
                fname  = os.path.join(dirname, String(fxd.gettext(child)))
                if child.name == 'directory':
                    # for directories add all files in it
                    if fxd.getattr(child, 'recursive', 0):
                        f = util.match_files_recursively(fname, self.suffix())
                    else:
                        f = util.match_files(fname, self.suffix())
                    citems = self.get(None, f)

                elif child.name == 'file':
                    # add the given filename
                    citems = self.get(None, [ fname ])

                # set duration until the next images comes up
                duration = fxd.getattr(child, 'duration', 0)
                if duration:
                    for i in citems:
                        i.duration = duration
                items += citems

            except OSError, e:
                print 'slideshow error:'
                print e

        # create the playlist based on the parsed file list
        pl = Playlist('', items, fxd.getattr(None, 'parent', None),
                      random=fxd.getattr(node, 'random', 0),
                      repeat=fxd.getattr(node, 'repeat', 0))
        pl.autoplay = True
        pl.name = fxd.getattr(node, 'title')
        pl.image = fxd.childcontent(node, 'cover-img')
        if pl.image:
            pl.image = vfs.join(vfs.dirname(fxd.filename), pl.image)


        # background music
        children = fxd.get_children(node, 'background-music')
        if children:
            random   = fxd.getattr(children[0], 'random', 0)
            children = children[0].children

        files  = []
        suffix = []
        for p in plugin.mimetype('audio'):
            suffix += p.suffix()

        for child in children:
            try:
                fname  = os.path.join(dirname, fxd.gettext(child))
                if child.name == 'directory':
                    if fxd.getattr(child, 'recursive', 0):
                        files += util.match_files_recursively(fname, suffix)
                    else:
                        files += util.match_files(fname, suffix)
                elif child.name == 'file':
                    files.append(fname)
            except OSError, e:
                print 'playlist error:'
                print e

        if files:
            bg = Playlist(playlist=files, random = random,
                          repeat=True, display_type='audio')
            pl.background_playlist = bg

        # add item to list
        fxd.parse_info(fxd.get_children(node, 'info', 1), pl)
        fxd.getattr(None, 'items', []).append(pl)

Index: viewer.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/image/viewer.py,v
retrieving revision 1.69
retrieving revision 1.70
diff -C2 -d -r1.69 -r1.70
*** viewer.py   12 Sep 2004 21:19:36 -0000      1.69
--- viewer.py   13 Sep 2004 18:00:50 -0000      1.70
***************
*** 10,13 ****
--- 10,16 ----
  # -----------------------------------------------------------------------
  # $Log$
+ # Revision 1.70  2004/09/13 18:00:50  dischi
+ # last cleanups for the image module in Freevo
+ #
  # Revision 1.69  2004/09/12 21:19:36  mikeruelle
  # for those of us without idlebars
***************
*** 280,284 ****
  
          # start timer
!         if self.fileitem.duration and self.slideshow and not self.signal_registered:
              rc.register(self.signalhandler, False, self.fileitem.duration*100)
              self.signal_registered = True
--- 283,288 ----
  
          # start timer
!         if self.fileitem.duration and self.slideshow and \
!                not self.signal_registered:
              rc.register(self.signalhandler, False, self.fileitem.duration*100)
              self.signal_registered = True
***************
*** 485,489 ****
          if newosd:
              # show the idlebar but not update the screen now
!             plugin.getbyname('idlebar').show(False)
              # get y movement value
              move_y = self.osd_box.get_size()[1]
--- 489,494 ----
          if newosd:
              # show the idlebar but not update the screen now
!             if plugin.getbyname('idlebar'):
!                 plugin.getbyname('idlebar').show(False)
              # get y movement value
              move_y = self.osd_box.get_size()[1]

Index: imageitem.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/image/imageitem.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** imageitem.py        7 Sep 2004 18:57:43 -0000       1.29
--- imageitem.py        13 Sep 2004 18:00:49 -0000      1.30
***************
*** 5,8 ****
--- 5,11 ----
  # $Id$
  #
+ # An ImageItem is an Item handling image files for Freevo. It will
+ # use the viewer in viewer.py to display the image
+ #
  # Notes:
  # Todo:
***************
*** 10,13 ****
--- 13,19 ----
  # -----------------------------------------------------------------------
  # $Log$
+ # Revision 1.30  2004/09/13 18:00:49  dischi
+ # last cleanups for the image module in Freevo
+ #
  # Revision 1.29  2004/09/07 18:57:43  dischi
  # image viwer auto slideshow
***************
*** 59,63 ****
      An item for image files
      """
!     def __init__(self, url, parent, name = None, duration = 
config.IMAGEVIEWER_DURATION):
          # set autovars to 'rotation' so that this value is
          # stored between Freevo sessions
--- 65,70 ----
      An item for image files
      """
!     def __init__(self, url, parent, name = None,
!                  duration = config.IMAGEVIEWER_DURATION):
          # set autovars to 'rotation' so that this value is
          # stored between Freevo sessions
***************
*** 107,111 ****
          return a list of possible actions on this item.
          """
!         return [ ( self.view, _('View Image') ) ]
  
  
--- 114,118 ----
          return a list of possible actions on this item.
          """
!         return [ ( self.play, _('View Image') ) ]
  
  
***************
*** 117,121 ****
  
  
!     def view(self, arg=None, menuw=None):
          """
          view the image
--- 124,128 ----
  
  
!     def play(self, arg=None, menuw=None):
          """
          view the image
***************
*** 131,135 ****
  
  
!     def stop(self):
          """
          stop viewing this item
--- 138,142 ----
  
  
!     def stop(self, arg=None, menuw=None):
          """
          stop viewing this item

Index: __init__.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/image/__init__.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** __init__.py 27 Aug 2004 14:21:50 -0000      1.21
--- __init__.py 13 Sep 2004 18:00:49 -0000      1.22
***************
*** 1,8 ****
  # -*- coding: iso-8859-1 -*-
  # -----------------------------------------------------------------------
! # __init__.py - interface between mediamenu and image
  # -----------------------------------------------------------------------
  # $Id$
  #
  # Notes:
  # Todo:
--- 1,14 ----
  # -*- coding: iso-8859-1 -*-
  # -----------------------------------------------------------------------
! # __init__.py
  # -----------------------------------------------------------------------
  # $Id$
  #
+ # This file imports everything needed to use this image module.
+ # There is  only one class provided for images, the PluginInterface
+ # from interface.py. It is a MimetypePlugin that can be accessed
+ # from plugin.mimetype(). It will also register an fxd handler for the
+ # <slideshow> tag.
+ #
  # Notes:
  # Todo:
***************
*** 10,17 ****
  # -----------------------------------------------------------------------
  # $Log$
! # Revision 1.21  2004/08/27 14:21:50  dischi
! # The complete image code is working again and should not crash. The zoom
! # handling got a complete rewrite. Only the gphoto plugin is not working
! # yet because my camera is a storage device.
  #
  #
--- 16,21 ----
  # -----------------------------------------------------------------------
  # $Log$
! # Revision 1.22  2004/09/13 18:00:49  dischi
! # last cleanups for the image module in Freevo
  #
  #
***************
*** 37,210 ****
  # ----------------------------------------------------------------------- */
  
! 
! import os
! 
! # Add support for bins album files
! from mmpython.image import bins
! 
! import config
! import util
! import plugin
! 
! from imageitem import ImageItem
! from playlist import Playlist
! 
! class PluginInterface(plugin.MimetypePlugin):
!     """
!     Plugin to handle all kinds of image items
!     """
!     def __init__(self):
!         plugin.MimetypePlugin.__init__(self)
!         self.display_type = [ 'image' ]
! 
!         # register the callbacks
!         plugin.register_callback('fxditem', ['image'], 'slideshow',
!                                  self.fxdhandler)
! 
!         # activate the mediamenu for image
!         level = plugin.is_active('image')[2]
!         plugin.activate('mediamenu', level=level, args='image')
! 
! 
!     def suffix(self):
!         """
!         return the list of suffixes this class handles
!         """
!         return config.IMAGE_SUFFIX
! 
! 
!     def get(self, parent, files):
!         """
!         return a list of items based on the files
!         """
!         items = []
!         for file in util.find_matches(files, config.IMAGE_SUFFIX):
!             items.append(ImageItem(file, parent))
!             files.remove(file)
!         return items
! 
! 
!     def dirinfo(self, diritem):
!         """
!         set informations for a diritem based on album.xml
!         """
!         if vfs.isfile(diritem.dir + '/album.xml'):
!             # Add album.xml information from bins to the
!             # directory informations
!             info  = bins.get_bins_desc(diritem.dir)
!             if not info.has_key('desc'):
!                 return
! 
!             info = info['desc']
!             if info.has_key('sampleimage') and info['sampleimage']:
!                 # Check if the album.xml defines a sampleimage.
!                 # If so, use it as image for the directory
!                 image = vfs.join(diritem.dir, info['sampleimage'])
!                 if vfs.isfile(image):
!                     diritem.image = image
! 
!             # set the title from album.xml
!             if info.has_key('title') and info['title']:
!                 diritem.name = info['title']
! 
! 
!     def fxdhandler(self, fxd, node):
!         """
!         parse image specific stuff from fxd files
! 
!         <?xml version="1.0" ?>
!         <freevo>
!           <slideshow title="foo" random="1|0" repeat="1|0">
!             <cover-img>foo.jpg</cover-img>
!             <background-music random="1|0">
!               <directory recursive="1|0">path</directory>
!               <file>filename</file>
!             </background-music>
!             <files>
!               <directory recursive="1|0" duration="10">path</directory>
!               <file duration="0">filename</file>
!             </files>
!             <info>
!               <description>A nice description</description>
!             </info>
!           </slideshow>
!         </freevo>
!         """
!         items = []
!         dirname = os.path.dirname(fxd.getattr(None, 'filename', ''))
!         children = fxd.get_children(node, 'files')
!         if children:
!             children = children[0].children
! 
!         # Create a list of all images for the slideshow
!         for child in children:
!             try:
!                 citems = []
!                 fname  = os.path.join(dirname, String(fxd.gettext(child)))
!                 if child.name == 'directory':
!                     # for directories add all files in it
!                     if fxd.getattr(child, 'recursive', 0):
!                         f = util.match_files_recursively(fname, self.suffix())
!                     else:
!                         f = util.match_files(fname, self.suffix())
!                     citems = self.get(None, f)
! 
!                 elif child.name == 'file':
!                     # add the given filename
!                     citems = self.get(None, [ fname ])
! 
!                 # set duration until the next images comes up
!                 duration = fxd.getattr(child, 'duration', 0)
!                 if duration:
!                     for i in citems:
!                         i.duration = duration
!                 items += citems
! 
!             except OSError, e:
!                 print 'slideshow error:'
!                 print e
! 
!         # create the playlist based on the parsed file list
!         pl = Playlist('', items, fxd.getattr(None, 'parent', None),
!                       random=fxd.getattr(node, 'random', 0),
!                       repeat=fxd.getattr(node, 'repeat', 0))
!         pl.autoplay = True
!         pl.name = fxd.getattr(node, 'title')
!         pl.image = fxd.childcontent(node, 'cover-img')
!         if pl.image:
!             pl.image = vfs.join(vfs.dirname(fxd.filename), pl.image)
! 
! 
!         # background music
!         children = fxd.get_children(node, 'background-music')
!         if children:
!             random   = fxd.getattr(children[0], 'random', 0)
!             children = children[0].children
! 
!         files  = []
!         suffix = []
!         for p in plugin.mimetype('audio'):
!             suffix += p.suffix()
! 
!         for child in children:
!             try:
!                 fname  = os.path.join(dirname, fxd.gettext(child))
!                 if child.name == 'directory':
!                     if fxd.getattr(child, 'recursive', 0):
!                         files += util.match_files_recursively(fname, suffix)
!                     else:
!                         files += util.match_files(fname, suffix)
!                 elif child.name == 'file':
!                     files.append(fname)
!             except OSError, e:
!                 print 'playlist error:'
!                 print e
! 
!         if files:
!             bg = Playlist(playlist=files, random = random,
!                           repeat=True, display_type='audio')
!             pl.background_playlist = bg
! 
!         # add item to list
!         fxd.parse_info(fxd.get_children(node, 'info', 1), pl)
!         fxd.getattr(None, 'items', []).append(pl)
--- 41,43 ----
  # ----------------------------------------------------------------------- */
  
! from interface import *



-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM. 
Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to