Update of /cvsroot/freevo/freevo/src/plugins
In directory sc8-pr-cvs1:/tmp/cvs-serv7444/src/plugins

Added Files:
        lcd.py 
Log Message:
New plugin: LCD
This plugin show the selected menu item and some info about it and info 
about the item being played using a LCD display (using pyLCD: 
http://www.schwarzvogel.de/software-pylcd.shtml)


--- NEW FILE: lcd.py ---
#if 0 /*
# -----------------------------------------------------------------------
# lcd.py - use PyLCD to display menus and music player
# -----------------------------------------------------------------------
# $Id: lcd.py,v 1.1 2003/07/23 07:16:00 gsbarbieri Exp $
#
# Notes:
#    To activate, put the following line in local_conf.py:
#       plugin.activate('lcd')
# Todo:        
#    1) Use Threads. PyLCD is too blocking!
#    2) Have Movie Player, TV Player and Image viewer to use LCD
#    3) Better (and more) LCD screens.
# -----------------------------------------------------------------------
# $Log: lcd.py,v $
# Revision 1.1  2003/07/23 07:16:00  gsbarbieri
# New plugin: LCD
# This plugin show the selected menu item and some info about it and info
# about the item being played using a LCD display (using pyLCD: 
http://www.schwarzvogel.de/software-pylcd.shtml)
#
#
# -----------------------------------------------------------------------
# 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
#
# ----------------------------------------------------------------------- */
#endif

import copy
import pylcd
import time
import plugin
import config

# Configuration: (Should move to freevo_conf.py?)
sep_str = " | " # use as separator between two strings. Like: "Length: 
123<sep_str>Plot: ..."

# menu_info: information to be shown when in menu
# Structure:
#
# menu_info = {
#     <TYPE> : [ ( <ATTRIBUTE>, <FORMAT_STRING> ), ... ],
#    }
# <ATTRIBUTE> is some valid attribute to item.getattr()
menu_info = {
    "main" : [ ],
    "audio" : [ ( "length", "Length: %s" ),
                ( "artist", "Artist: %s" ),
                ( "album", "Album: %s" ),
                ( "year", "Year: %s" ) ],
    "audiocd" : [ ( "len(tracks)", "Tracks: %s" ),
                  ( "artist", "Artist: %s" ),
                  ( "album", "Album: %s" ),
                  ( "year", "Year: %s" ) ],
    "video" : [ ( "length", "Length: %s" ),
                ( "geometry", "Resolution: %s" ),
                ( "aspect", "Aspect: %s" ),
                ( "tagline", "Tagline: %s" ),
                ( "plot", "Plot: %s" ) ],
    "dir" : [ ( "plot", "Plot: %s" ),
              ( "tagline", "Tagline: %s" ) ],
    "image" : [ ( "geometry", "Geometry: %s" ),
                ( "date", "Date: %s" ),
                ( "description", "Description: %s" ) ],
    "playlist" : [ ( "len(playlist)", "%s items" ) ],
    "unknow" : [ ]
    }
# menu_strinfo: will be passed to time.strinfo() and added to the end of info (after 
menu_info)
menu_strinfo = {
    "main" : "%H:%M - %a, %d-%b", # I like time in main menu
    "audio" : None,
    "audiocd" : None,
    "video" : None,
    "image" : None,
    "dir" : None,
    "playlist" : None,
    "unknow" : None
    }


# layouts: dict of layouts (screens and widgets)
# Structure:
#
# layouts = { <#_OF_LINES_IN_DISPLAY> :
#             { <SCREEN_NAME> :
#               <WIDGET_NAME> : ( <WIDGET_TYPE>,
#                                 <WIDGET_PARAMETERS>,
#                                 <PARAMETERS_VALUES> ),
#               ...
#               <MORE_WIDGETS>
#               ...
#             },
#             ...
#             <MORE_SCREENS>
#             ...
#           }
# Note:
#    <PARAMETERS_VALUES>: will be used like this:
#       <WIDGET_PARAMETERS> % eval( <PARAMETERS_VALUES> )
#    There should be at least these screens:
#       welcome: will be the shown during the startup
#          menu: will be used in menu mode
#        player: will be used in player mode
#            tv: will be used in tv mode
# Values should match the ones supported by LCDd (man LCDd)
layouts = { 4 : # 4 lines display
            # Welcome screen
            { "welcome" : 
              { "title"    : ( "title",
                               "Freevo",
                               None ),
                "calendar" : ( "scroller",
                               "1 2 %d 2 h 2 \"Today is %s.\"",
                               "( self.width, time.strftime('%A, %d-%B') )" ),
                "clock"    : ( "string",
                               "%d 3 \"%s\"",
                               "( ( self.width - len( time.strftime('%T') ) ) / 2 + 1 
," + \
                               " time.strftime('%T') )" )
                },

              "menu"    :
              { "title_l"  : ( "string",
                               "1 1 'MENU: '",
                               None ),
                "item_l"   : ( "string",
                               "1 2 'ITEM: '",
                               None ),
                "type_l"   : ( "string",
                               "1 3 'TYPE: '",
                               None ),
                "info_l"   : ( "string",
                               "1 4 'INFO: '",
                               None ),                
                "title_v"  : ( "scroller",
                               "7 1 %d 1 h 2 \"%s\"",
                               "( self.width, menu.heading )" ),
                "item_v"   : ( "scroller",
                               "7 2 %d 2 h 2 \"%s\"",
                               "( self.width, title )" ),
                "type_v"   : ( "scroller",
                               "7 3 %d 3 h 2 \"%s\"",
                               "( self.width, typeinfo )" ),
                "info_v"   : ( "scroller",
                               "7 4 %d 1 h 2 \"%s\"",
                               "( self.width, info )" )
                },

              "audio_player"  :
              { "music_l"   : ( "string",
                                "2 1 'MUSIC: '",
                                None ),
                "album_l"   : ( "string",
                                "2 2 'ALBUM: '",
                                None ),
                "artist_l"  : ( "string",
                                "1 3 'ARTIST: '",
                                None ),
                "music_v"   : ( "scroller",
                                "9 1 %d 1 h 2 \"%s\"",
                                "( self.width, title )" ),
                "album_v"   : ( "scroller",
                                "9 2 %d 2 h 2 \"%s\"",
                                "( self.width, player.getattr('album') )" ),
                "artist_v"  : ( "scroller",
                                "9 3 %d 3 h 2 \"%s\"",
                                "( self.width, player.getattr('artist') )" ),
                "time_v"    : ( "string",
                                "2 4 '% 2d:%02d/% 2d:%02d (% 2d%%)'",
                                "( int(player.length / 60), int(player.length % 60)," +
                                " int(player.elapsed / 60), int(player.elapsed % 60)," 
+
                                " int(player.elapsed * 100 / player.length) )" )
                },
              
              "tv"            :
              { "chan_l"   : ( "string",
                                "1 1 'CHAN: '",
                                None ),
                "prog_l"   : ( "string",
                                "1 2 'PROG: '",
                                None ),
                "time_l"  : ( "string",
                                "1 3 'TIME: '",
                                None ),
                "desc_l"  : ( "string",
                                "1 4 'DESC: '",
                                None ),                
                "chan_v"   : ( "scroller",
                                "7 1 %d 1 h 2 \"%s\"",
                                "( self.width, tv.channel_id )" ),
                "prog_v"   : ( "scroller",
                                "7 2 %d 2 h 2 \"%s\"",
                                "( self.width, tv.title )" ),
                "time_v"  : ( "scroller",
                                "7 3 %d 3 h 2 \"%s-%s\"",
                                "( self.width, tv.start, tv.stop )" ),
                "desc_v"  : ( "scroller",
                                "7 4 %d 4 h 2 \"%s\"",
                                "( self.width, tv.desc )" )
                }              
              }
            }

# poll_widgets: widgets that should be refreshed during the pool
# Structure:
#
# poll_widgets = { <#_OF_LINES_IN_DISPLAY> :
#                  { <SCREEN_NAME> : ( <WIDGET_NAME>, ... ) },
#                  ...
#                }
poll_widgets = { 4 :
                 { "welcome" : [ "clock" ] }
                 }

DEBUG = config.DEBUG

def get_info( item, list ):
    info = ""

    for l in list:

        v = item.getattr( l[ 0 ] )
        if v:
            if info:
                info += sep_str
            info += l[ 1 ] % v

    return info



class PluginInterface( plugin.DaemonPlugin ):
    def __init__( self ):
        """
        init the lcd
        """
        plugin.DaemonPlugin.__init__( self )
        self.lcd = pylcd.client()
        cm = self.lcd.connect()
        if DEBUG > 0:
            print "Connecting to LCD: %s" % cm
            print "Info as know by the module:"
            self.lcd.getinfo()
            print ""
            
        plugin.register( self, "lcd" )

        self.poll_interval = 10
        self.disable = 0
        self.height = self.lcd.d_height
        self.width  = self.lcd.d_width
        self.generate_screens()

        # Show welcome screen:
        for w in self.screens[ "welcome" ]:
            type, param, val = self.screens[ "welcome" ][ w ]            
            if val: param = param % eval( val )
            self.lcd.widget_set( "welcome", w, param )
        self.lcd.screen_set( "welcome", "-priority 192 -duration 2 -heartbeat off" )
        self.last_screen = "welcome"

        self.lsv = { } # will hold last screen value (lsv)

    def close( self ):
        """
        to be called before the plugin exists.
        It terminates the connection with the server
        """
        #self.lcd.send( "bye" )
        
    def draw( self, ( type, object ), osd ):
        """
        'Draw' the information on the LCD display.
        """
        if self.disable: return

        sname = type
        if type == 'menu':   
            menu  = object.menustack[ -1 ]
            title = menu.selected.name
            typeinfo = menu.selected.type
            info = ""

            if menu.selected.getattr( 'type' ):
                typeinfo = menu.selected.getattr( 'type' )

            # get info:
            if menu.selected.type:
                info = get_info( menu.selected, menu_info[ menu.selected.type ] )
                if menu_strinfo[ menu.selected.type ]:
                    if info:
                        info += sep_str
                    info += time.strftime( menu_strinfo[ menu.selected.type ] )

            # specific things related with item type
            if menu.selected.type == 'audio':
                title = menu.selected.getattr( 'title' )
                if menu.selected.getattr( 'trackno' ):
                    title = "%s - %s" % ( menu.selected.getattr( 'trackno' ), title )
                    
        elif type == 'player':
            player = object
            title  = player.getattr( 'title' )
            if player.getattr( 'trackno' ):
                title = "%s - %s" % ( player.getattr( 'trackno' ), title )             
   
            sname  = "%s_%s" % ( player.type, type )

            
        elif type == 'tv':
            tv = copy.copy( object.selected )

            if tv.start == 0:
                tv.start = " 0:00"
                tv.stop  = "23:59" # could also be: '????'
            else:
                tv.start = time.localtime( tv.start )
                tv.stop  = time.localtime( tv.stop )
                
                tv.start = "% 2d:%02d" % ( tv.start[ 3 ], tv.start[ 4 ] )
                tv.stop  = "% 2d:%02d" % ( tv.stop[ 3 ], tv.stop[ 4 ] )

            
        s = self.screens[ sname ]
        for w in s:
            t, param, val = s[ w ]
            try:
                #print "param=%s \tval=%s" % ( param, val )
                if val: param = param % eval( val )
                #print "   -> %s" % param
            except:
                pass
            k = '%s %s' % ( sname, w )
            try:
                if self.lsv[ k ] == param:
                    continue # nothing changed in this widget
            except KeyError:
                pass

            self.lsv[ k ] = param
            self.lcd.widget_set( sname, w, param.encode( 'latin1' ) )

        if self.last_screen != sname:
            self.lcd.screen_set( self.last_screen, "-priority 128" )
            self.lcd.screen_set( sname, "-priority 64" )
            self.last_screen = sname

        
    def poll( self ):
        if self.disable: return

        if not poll_widgets.has_key( self.lines ): return

        screens = poll_widgets[ self.lines ]
        for s in screens:
            widgets = poll_widgets[ self.lines ][ s ]
            
            for w in widgets:
                type, param, val = self.screens[ s ][ w ]
                
                if val: param = param % eval( val )
                self.lcd.widget_set( s, w, param )
        

    def generate_screens( self ):
        screens = None
        l = self.height
        # Find a screen
        while not screens:
            try:
                screens = layouts[ l ]
            except KeyError:
                if DEBUG > 0:
                    print "WARNING: Could not find screens for %d lines LCD!" % l
                l -= 1
                if l < 1:
                    print "ERROR: No screens found!"
                    self.disable = 1
                    return

        self.lines = l
        self.screens = screens
        for s in screens:
            self.lcd.screen_add( s )
            widgets = screens[ s ]
            self.lcd.screen_set( s, "-heartbeat off" )

            for w in widgets:
                type, param, val = screens[ s ][ w ]
                self.lcd.widget_add( s, w, type )
        




-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to